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
2f349827
Commit
2f349827
authored
Sep 12, 2018
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rework newb acceptor creation
parent
8b31104b
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
185 additions
and
175 deletions
+185
-175
libcaf_io/caf/io/network/newb.hpp
libcaf_io/caf/io/network/newb.hpp
+164
-147
libcaf_io/test/newb.cpp
libcaf_io/test/newb.cpp
+21
-28
No files found.
libcaf_io/caf/io/network/newb.hpp
View file @
2f349827
This diff is collapsed.
Click to expand it.
libcaf_io/test/newb.cpp
View file @
2f349827
...
@@ -149,6 +149,7 @@ struct accept_policy_impl : public network::accept_policy {
...
@@ -149,6 +149,7 @@ struct accept_policy_impl : public network::accept_policy {
}
}
};
};
/*
template <class Protocol>
template <class Protocol>
struct dummy_basp_newb_acceptor
struct dummy_basp_newb_acceptor
: public network::newb_acceptor<typename Protocol::message_type> {
: public network::newb_acceptor<typename Protocol::message_type> {
...
@@ -185,6 +186,7 @@ struct dummy_basp_newb_acceptor
...
@@ -185,6 +186,7 @@ struct dummy_basp_newb_acceptor
message_tuple_t msg;
message_tuple_t msg;
std::vector<actor> spawned;
std::vector<actor> spawned;
};
};
*/
class
config
:
public
actor_system_config
{
class
config
:
public
actor_system_config
{
public:
public:
...
@@ -200,13 +202,11 @@ public:
...
@@ -200,13 +202,11 @@ public:
struct
fixture
{
struct
fixture
{
using
newb_t
=
network
::
stateful_newb
<
new_basp_msg
,
test_state
>
;
using
newb_t
=
network
::
stateful_newb
<
new_basp_msg
,
test_state
>
;
using
protocol_t
=
network
::
generic_protocol
<
ordering
<
datagram_basp
>>
;
using
protocol_t
=
network
::
generic_protocol
<
ordering
<
datagram_basp
>>
;
using
acceptor_t
=
dummy_basp_newb_acceptor
<
protocol_t
>
;
config
cfg
;
config
cfg
;
actor_system
sys
;
actor_system
sys
;
default_multiplexer
&
mpx
;
default_multiplexer
&
mpx
;
scheduler
::
test_coordinator
&
sched
;
scheduler
::
test_coordinator
&
sched
;
actor
self
;
actor
test_newb
;
caf
::
intrusive_ptr
<
acceptor_t
>
na
;
fixture
()
fixture
()
:
sys
(
cfg
.
parse
(
test
::
engine
::
argc
(),
test
::
engine
::
argv
())),
:
sys
(
cfg
.
parse
(
test
::
engine
::
argc
(),
test
::
engine
::
argv
())),
...
@@ -217,22 +217,13 @@ struct fixture {
...
@@ -217,22 +217,13 @@ struct fixture {
CAF_REQUIRE
(
esock
);
CAF_REQUIRE
(
esock
);
// Create newb.
// Create newb.
network
::
transport_policy_ptr
pol
{
new
dummy_transport
};
network
::
transport_policy_ptr
pol
{
new
dummy_transport
};
self
=
network
::
spawn_newb
<
protocol_t
>
(
sys
,
dummy_broker
,
test_newb
=
network
::
spawn_newb
<
protocol_t
>
(
sys
,
dummy_broker
,
std
::
move
(
pol
),
esock
->
first
);
std
::
move
(
pol
),
esock
->
first
);
// And another socket.
esock
=
network
::
new_local_udp_endpoint_impl
(
0
,
nullptr
);
CAF_REQUIRE
(
esock
);
// Create acceptor.
auto
&
mpx
=
dynamic_cast
<
default_multiplexer
&>
(
sys
.
middleman
().
backend
());
auto
ptr
=
make_counted
<
acceptor_t
>
(
mpx
,
esock
->
first
);
ptr
->
acceptor
.
reset
(
new
accept_policy_impl
);
na
=
std
::
move
(
ptr
);
}
}
~
fixture
()
{
~
fixture
()
{
anon_send_exit
(
self
,
exit_reason
::
user_shutdown
);
anon_send_exit
(
test_newb
,
exit_reason
::
user_shutdown
);
exec_all
();
exec_all
();
na
->
stop
();
}
}
// -- supporting -------------------------------------------------------------
// -- supporting -------------------------------------------------------------
...
@@ -347,10 +338,10 @@ CAF_TEST(read event) {
...
@@ -347,10 +338,10 @@ CAF_TEST(read event) {
const
basp_header
bhdr
{
0
,
13
,
42
};
const
basp_header
bhdr
{
0
,
13
,
42
};
const
uint32_t
payload
=
1337
;
const
uint32_t
payload
=
1337
;
CAF_MESSAGE
(
"set the expected message"
);
CAF_MESSAGE
(
"set the expected message"
);
anon_send
(
self
,
expect_atom
::
value
,
bhdr
,
payload
);
anon_send
(
test_newb
,
expect_atom
::
value
,
bhdr
,
payload
);
exec_all
();
exec_all
();
CAF_MESSAGE
(
"copy them into the buffer"
);
CAF_MESSAGE
(
"copy them into the buffer"
);
auto
&
dummy
=
deref
<
newb_t
>
(
self
);
auto
&
dummy
=
deref
<
newb_t
>
(
test_newb
);
auto
&
buf
=
dummy
.
transport
->
receive_buffer
;
auto
&
buf
=
dummy
.
transport
->
receive_buffer
;
write_packet
(
buf
,
ohdr
,
bhdr
,
payload
);
write_packet
(
buf
,
ohdr
,
bhdr
,
payload
);
dummy
.
transport
->
received_bytes
=
buf
.
size
();
dummy
.
transport
->
received_bytes
=
buf
.
size
();
...
@@ -373,10 +364,10 @@ CAF_TEST(message passing) {
...
@@ -373,10 +364,10 @@ CAF_TEST(message passing) {
const
basp_header
bhdr
{
0
,
13
,
42
};
const
basp_header
bhdr
{
0
,
13
,
42
};
const
uint32_t
payload
=
1337
;
const
uint32_t
payload
=
1337
;
CAF_MESSAGE
(
"setup read event"
);
CAF_MESSAGE
(
"setup read event"
);
anon_send
(
self
,
expect_atom
::
value
,
bhdr
,
payload
);
anon_send
(
test_newb
,
expect_atom
::
value
,
bhdr
,
payload
);
anon_send
(
self
,
send_atom
::
value
,
ohdr
,
bhdr
,
payload
);
anon_send
(
test_newb
,
send_atom
::
value
,
ohdr
,
bhdr
,
payload
);
exec_all
();
exec_all
();
auto
&
dummy
=
deref
<
newb_t
>
(
self
);
auto
&
dummy
=
deref
<
newb_t
>
(
test_newb
);
dummy
.
handle_event
(
network
::
operation
::
read
);
dummy
.
handle_event
(
network
::
operation
::
read
);
CAF_MESSAGE
(
"check the basp header and payload"
);
CAF_MESSAGE
(
"check the basp header and payload"
);
auto
&
msg
=
dummy
.
state
.
messages
.
front
().
first
;
auto
&
msg
=
dummy
.
state
.
messages
.
front
().
first
;
...
@@ -395,11 +386,11 @@ CAF_TEST(timeouts) {
...
@@ -395,11 +386,11 @@ CAF_TEST(timeouts) {
const
basp_header
bhdr
{
0
,
13
,
42
};
const
basp_header
bhdr
{
0
,
13
,
42
};
const
uint32_t
payload
=
1337
;
const
uint32_t
payload
=
1337
;
CAF_MESSAGE
(
"setup read event"
);
CAF_MESSAGE
(
"setup read event"
);
anon_send
(
self
,
expect_atom
::
value
,
bhdr
,
payload
);
anon_send
(
test_newb
,
expect_atom
::
value
,
bhdr
,
payload
);
anon_send
(
self
,
send_atom
::
value
,
ohdr
,
bhdr
,
payload
);
anon_send
(
test_newb
,
send_atom
::
value
,
ohdr
,
bhdr
,
payload
);
exec_all
();
exec_all
();
CAF_MESSAGE
(
"trigger read event"
);
CAF_MESSAGE
(
"trigger read event"
);
auto
&
dummy
=
deref
<
newb_t
>
(
self
);
auto
&
dummy
=
deref
<
newb_t
>
(
test_newb
);
dummy
.
read_event
();
dummy
.
read_event
();
CAF_CHECK
(
!
dummy
.
state
.
expected
.
empty
());
CAF_CHECK
(
!
dummy
.
state
.
expected
.
empty
());
CAF_MESSAGE
(
"trigger waiting timeouts"
);
CAF_MESSAGE
(
"trigger waiting timeouts"
);
...
@@ -422,10 +413,10 @@ CAF_TEST(message ordering) {
...
@@ -422,10 +413,10 @@ CAF_TEST(message ordering) {
const
basp_header
bhdr_second
{
0
,
12
,
13
};
const
basp_header
bhdr_second
{
0
,
12
,
13
};
const
uint32_t
payload_second
=
101
;
const
uint32_t
payload_second
=
101
;
CAF_MESSAGE
(
"setup read events"
);
CAF_MESSAGE
(
"setup read events"
);
anon_send
(
self
,
expect_atom
::
value
,
bhdr_first
,
payload_first
);
anon_send
(
test_newb
,
expect_atom
::
value
,
bhdr_first
,
payload_first
);
anon_send
(
self
,
expect_atom
::
value
,
bhdr_second
,
payload_second
);
anon_send
(
test_newb
,
expect_atom
::
value
,
bhdr_second
,
payload_second
);
exec_all
();
exec_all
();
auto
&
dummy
=
deref
<
newb_t
>
(
self
);
auto
&
dummy
=
deref
<
newb_t
>
(
test_newb
);
auto
&
buf
=
dummy
.
transport
->
receive_buffer
;
auto
&
buf
=
dummy
.
transport
->
receive_buffer
;
CAF_MESSAGE
(
"read second message first"
);
CAF_MESSAGE
(
"read second message first"
);
write_packet
(
buf
,
ohdr_second
,
bhdr_second
,
payload_second
);
write_packet
(
buf
,
ohdr_second
,
bhdr_second
,
payload_second
);
...
@@ -443,14 +434,15 @@ CAF_TEST(write buf) {
...
@@ -443,14 +434,15 @@ CAF_TEST(write buf) {
const
basp_header
bhdr
{
0
,
13
,
42
};
const
basp_header
bhdr
{
0
,
13
,
42
};
const
uint32_t
payload
=
1337
;
const
uint32_t
payload
=
1337
;
CAF_MESSAGE
(
"setup read event"
);
CAF_MESSAGE
(
"setup read event"
);
anon_send
(
self
,
expect_atom
::
value
,
bhdr
,
payload
);
anon_send
(
test_newb
,
expect_atom
::
value
,
bhdr
,
payload
);
anon_send
(
self
,
send_atom
::
value
,
bhdr
.
from
,
bhdr
.
to
,
payload
);
anon_send
(
test_newb
,
send_atom
::
value
,
bhdr
.
from
,
bhdr
.
to
,
payload
);
exec_all
();
exec_all
();
auto
&
dummy
=
deref
<
newb_t
>
(
self
);
auto
&
dummy
=
deref
<
newb_t
>
(
test_newb
);
dummy
.
handle_event
(
network
::
operation
::
read
);
dummy
.
handle_event
(
network
::
operation
::
read
);
// Message handler will check if the expected message was received.
// Message handler will check if the expected message was received.
}
}
/*
CAF_TEST(newb acceptor) {
CAF_TEST(newb acceptor) {
CAF_MESSAGE("trigger read event on acceptor");
CAF_MESSAGE("trigger read event on acceptor");
na->handle_event(network::operation::read);
na->handle_event(network::operation::read);
...
@@ -460,5 +452,6 @@ CAF_TEST(newb acceptor) {
...
@@ -460,5 +452,6 @@ CAF_TEST(newb acceptor) {
for (actor& d : dummy.spawned)
for (actor& d : dummy.spawned)
anon_send_exit(d, exit_reason::user_shutdown);
anon_send_exit(d, exit_reason::user_shutdown);
}
}
*/
CAF_TEST_FIXTURE_SCOPE_END
()
CAF_TEST_FIXTURE_SCOPE_END
()
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