Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
4d140253
Commit
4d140253
authored
Nov 29, 2018
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adopt graceful_shutdown for event handlers
parent
f9864512
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
67 additions
and
15 deletions
+67
-15
libcaf_io/caf/io/newb.hpp
libcaf_io/caf/io/newb.hpp
+25
-11
libcaf_io/caf/policy/accept.hpp
libcaf_io/caf/policy/accept.hpp
+7
-1
libcaf_io/caf/policy/newb_tcp.hpp
libcaf_io/caf/policy/newb_tcp.hpp
+7
-0
libcaf_io/caf/policy/newb_udp.hpp
libcaf_io/caf/policy/newb_udp.hpp
+8
-0
libcaf_io/caf/policy/transport.hpp
libcaf_io/caf/policy/transport.hpp
+4
-2
libcaf_io/src/newb_tcp.cpp
libcaf_io/src/newb_tcp.cpp
+5
-0
libcaf_io/src/newb_udp.cpp
libcaf_io/src/newb_udp.cpp
+5
-0
libcaf_io/src/policies.cpp
libcaf_io/src/policies.cpp
+6
-1
No files found.
libcaf_io/caf/io/newb.hpp
View file @
4d140253
...
...
@@ -152,6 +152,15 @@ struct newb : public network::newb_base {
intrusive_ptr_release
(
this
->
ctrl
());
}
void
graceful_shutdown
()
override
{
CAF_LOG_TRACE
(
CAF_ARG2
(
"fd"
,
fd_
));
// Ignore repeated calls.
if
(
state_
.
shutting_down
)
return
;
state_
.
shutting_down
=
true
;
trans
->
shutdown
(
this
,
fd_
);
}
// -- base requirements ------------------------------------------------------
void
start
()
override
{
...
...
@@ -169,9 +178,7 @@ struct newb : public network::newb_base {
void
stop
()
override
{
CAF_PUSH_AID_FROM_PTR
(
this
);
CAF_LOG_TRACE
(
""
);
close_read_channel
();
stop_reading
();
stop_writing
();
graceful_shutdown
();
}
void
io_error
(
network
::
operation
op
,
error
err
)
override
{
...
...
@@ -193,7 +200,7 @@ struct newb : public network::newb_base {
}
switch
(
op
)
{
case
operation
:
:
read
:
stop_reading
();
graceful_shutdown
();
break
;
case
operation
:
:
write
:
stop_writing
();
...
...
@@ -217,13 +224,13 @@ struct newb : public network::newb_base {
void
start_writing
()
override
{
if
(
!
writing_
)
{
event_handler
::
backend
().
add
(
network
::
operation
::
write
,
fd
()
,
this
);
event_handler
::
backend
().
add
(
network
::
operation
::
write
,
fd
_
,
this
);
writing_
=
true
;
}
}
void
stop_writing
()
override
{
event_handler
::
backend
().
del
(
network
::
operation
::
write
,
fd
()
,
this
);
event_handler
::
backend
().
del
(
network
::
operation
::
write
,
fd
_
,
this
);
}
// -- members ----------------------------------------------------------------
...
...
@@ -468,6 +475,15 @@ struct newb_acceptor : network::newb_base {
intrusive_ptr_release
(
this
->
ctrl
());
}
void
graceful_shutdown
()
override
{
CAF_LOG_TRACE
(
CAF_ARG2
(
"fd"
,
fd_
));
// Ignore repeated calls.
if
(
state_
.
shutting_down
)
return
;
state_
.
shutting_down
=
true
;
accept_pol
->
shutdown
(
this
,
fd_
);
}
// -- base requirements ------------------------------------------------------
void
start
()
override
{
...
...
@@ -485,9 +501,7 @@ struct newb_acceptor : network::newb_base {
void
stop
()
override
{
CAF_PUSH_AID_FROM_PTR
(
this
);
CAF_LOG_TRACE
(
""
);
close_read_channel
();
stop_reading
();
stop_writing
();
graceful_shutdown
();
}
void
io_error
(
network
::
operation
op
,
error
err
)
override
{
...
...
@@ -511,13 +525,13 @@ struct newb_acceptor : network::newb_base {
void
start_writing
()
override
{
if
(
!
writing_
)
{
event_handler
::
backend
().
add
(
network
::
operation
::
write
,
fd
()
,
this
);
event_handler
::
backend
().
add
(
network
::
operation
::
write
,
fd
_
,
this
);
writing_
=
true
;
}
}
void
stop_writing
()
override
{
event_handler
::
backend
().
del
(
network
::
operation
::
write
,
fd
()
,
this
);
event_handler
::
backend
().
del
(
network
::
operation
::
write
,
fd
_
,
this
);
}
// -- members ----------------------------------------------------------------
...
...
libcaf_io/caf/policy/accept.hpp
View file @
4d140253
...
...
@@ -19,8 +19,9 @@
#pragma once
#include "caf/config.hpp"
#include "caf/
policy/transport
.hpp"
#include "caf/
expected
.hpp"
#include "caf/io/network/native_socket.hpp"
#include "caf/policy/transport.hpp"
namespace
caf
{
namespace
io
{
...
...
@@ -68,6 +69,11 @@ struct accept {
// nop
}
virtual
void
shutdown
(
io
::
network
::
newb_base
*
,
io
::
network
::
native_socket
)
{
// nop
}
bool
manual_read
;
};
...
...
libcaf_io/caf/policy/newb_tcp.hpp
View file @
4d140253
...
...
@@ -48,6 +48,8 @@ struct tcp_transport : public transport {
connect
(
const
std
::
string
&
host
,
uint16_t
port
,
optional
<
io
::
network
::
protocol
::
network
>
preferred
=
none
)
override
;
void
shutdown
(
io
::
network
::
newb_base
*
,
io
::
network
::
native_socket
)
override
;
// State for reading.
size_t
read_threshold
;
size_t
collected
;
...
...
@@ -81,6 +83,11 @@ struct accept_tcp : public accept<Message> {
void
init
(
io
::
network
::
newb_base
*
,
io
::
newb
<
Message
>&
spawned
)
override
{
spawned
.
start
();
}
void
shutdown
(
io
::
network
::
newb_base
*
,
io
::
network
::
native_socket
sockfd
)
override
{
io
::
network
::
shutdown_both
(
sockfd
);
}
};
template
<
class
T
>
...
...
libcaf_io/caf/policy/newb_udp.hpp
View file @
4d140253
...
...
@@ -55,6 +55,9 @@ struct udp_transport : public transport {
connect
(
const
std
::
string
&
host
,
uint16_t
port
,
optional
<
io
::
network
::
protocol
::
network
>
preferred
=
none
)
override
;
void
shutdown
(
io
::
network
::
newb_base
*
parent
,
io
::
network
::
native_socket
sockfd
)
override
;
// State for reading.
size_t
maximum
;
bool
first_message
;
...
...
@@ -100,6 +103,11 @@ struct accept_udp : public accept<Message> {
spawned
.
trans
->
read_some
(
parent
,
*
spawned
.
proto
.
get
());
spawned
.
start
();
}
void
shutdown
(
io
::
network
::
newb_base
*
parent
,
io
::
network
::
native_socket
)
override
{
parent
->
passivate
();
}
};
template
<
class
T
>
...
...
libcaf_io/caf/policy/transport.hpp
View file @
4d140253
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* | | / _ \ | |_ Actor * | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
...
...
@@ -96,6 +95,9 @@ struct transport {
connect
(
const
std
::
string
&
,
uint16_t
,
optional
<
io
::
network
::
protocol
::
network
>
=
none
);
virtual
void
shutdown
(
io
::
network
::
newb_base
*
parent
,
io
::
network
::
native_socket
sockfd
);
size_t
received_bytes
;
size_t
max_consecutive_reads
;
...
...
libcaf_io/src/newb_tcp.cpp
View file @
4d140253
...
...
@@ -179,6 +179,11 @@ tcp_transport::connect(const std::string& host, uint16_t port,
return
io
::
network
::
new_tcp_connection
(
host
,
port
,
preferred
);
}
void
tcp_transport
::
shutdown
(
io
::
network
::
newb_base
*
,
io
::
network
::
native_socket
sockfd
)
{
io
::
network
::
shutdown_both
(
sockfd
);
}
io
::
network
::
native_socket
get_newb_socket
(
io
::
network
::
newb_base
*
n
)
{
return
n
->
fd
();
}
...
...
libcaf_io/src/newb_udp.cpp
View file @
4d140253
...
...
@@ -181,5 +181,10 @@ udp_transport::connect(const std::string& host, uint16_t port,
return
res
->
first
;
}
void
udp_transport
::
shutdown
(
io
::
network
::
newb_base
*
parent
,
io
::
network
::
native_socket
)
{
parent
->
stop_reading
();
}
}
// namespace policy
}
// namespace caf
libcaf_io/src/policies.cpp
View file @
4d140253
...
...
@@ -73,10 +73,15 @@ byte_buffer& transport::wr_buf() {
expected
<
io
::
network
::
native_socket
>
transport
::
connect
(
const
std
::
string
&
,
uint16_t
,
optional
<
io
::
network
::
protocol
::
network
>
)
{
optional
<
io
::
network
::
protocol
::
network
>
)
{
return
sec
::
bad_function_call
;
}
void
transport
::
shutdown
(
io
::
network
::
newb_base
*
,
io
::
network
::
native_socket
sockfd
)
{
io
::
network
::
shutdown_both
(
sockfd
);
}
// -- protocol_policy_base -----------------------------------------------------
protocol_base
::~
protocol_base
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment