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
eba3a1da
Commit
eba3a1da
authored
Jul 07, 2017
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add try-read-data feature to test multiplexer
parent
4d89c25f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
3 deletions
+70
-3
libcaf_io/caf/io/network/test_multiplexer.hpp
libcaf_io/caf/io/network/test_multiplexer.hpp
+6
-0
libcaf_io/src/test_multiplexer.cpp
libcaf_io/src/test_multiplexer.cpp
+64
-3
No files found.
libcaf_io/caf/io/network/test_multiplexer.hpp
View file @
eba3a1da
...
@@ -137,6 +137,12 @@ public:
...
@@ -137,6 +137,12 @@ public:
/// Tries to accept a pending connection.
/// Tries to accept a pending connection.
bool
try_accept_connection
();
bool
try_accept_connection
();
/// Tries to read data on any available scribe.
bool
try_read_data
();
/// Tries to read data from the external input buffer of `hdl`.
bool
try_read_data
(
connection_handle
hdl
);
/// Poll data on all scribes.
/// Poll data on all scribes.
bool
read_data
();
bool
read_data
();
...
...
libcaf_io/src/test_multiplexer.cpp
View file @
eba3a1da
...
@@ -406,6 +406,67 @@ bool test_multiplexer::try_accept_connection() {
...
@@ -406,6 +406,67 @@ bool test_multiplexer::try_accept_connection() {
[](
doorman_data
*
x
)
{
return
x
->
ptr
->
new_connection
();
});
[](
doorman_data
*
x
)
{
return
x
->
ptr
->
new_connection
();
});
}
}
bool
test_multiplexer
::
try_read_data
()
{
CAF_ASSERT
(
std
::
this_thread
::
get_id
()
==
tid_
);
CAF_LOG_TRACE
(
""
);
// scribe_data might change while we traverse it
std
::
vector
<
connection_handle
>
xs
;
xs
.
reserve
(
scribe_data_
.
size
());
for
(
auto
&
kvp
:
scribe_data_
)
xs
.
emplace_back
(
kvp
.
first
);
for
(
auto
x
:
xs
)
if
(
try_read_data
(
x
))
return
true
;
return
false
;
}
bool
test_multiplexer
::
try_read_data
(
connection_handle
hdl
)
{
CAF_ASSERT
(
std
::
this_thread
::
get_id
()
==
tid_
);
CAF_LOG_TRACE
(
CAF_ARG
(
hdl
));
scribe_data
&
sd
=
scribe_data_
[
hdl
];
if
(
sd
.
passive_mode
||
sd
.
ptr
==
nullptr
||
sd
.
ptr
->
parent
()
==
nullptr
||
!
sd
.
ptr
->
parent
()
->
getf
(
abstract_actor
::
is_initialized_flag
))
{
return
false
;
}
switch
(
sd
.
recv_conf
.
first
)
{
case
receive_policy_flag
:
:
exactly
:
if
(
sd
.
vn_buf
.
size
()
>=
sd
.
recv_conf
.
second
)
{
sd
.
rd_buf
.
clear
();
auto
first
=
sd
.
vn_buf
.
begin
();
auto
last
=
first
+
static_cast
<
ptrdiff_t
>
(
sd
.
recv_conf
.
second
);
sd
.
rd_buf
.
insert
(
sd
.
rd_buf
.
end
(),
first
,
last
);
sd
.
vn_buf
.
erase
(
first
,
last
);
if
(
!
sd
.
ptr
->
consume
(
this
,
sd
.
rd_buf
.
data
(),
sd
.
rd_buf
.
size
()))
sd
.
passive_mode
=
true
;
return
true
;
}
break
;
case
receive_policy_flag
:
:
at_least
:
if
(
sd
.
vn_buf
.
size
()
>=
sd
.
recv_conf
.
second
)
{
sd
.
rd_buf
.
clear
();
sd
.
rd_buf
.
swap
(
sd
.
vn_buf
);
if
(
!
sd
.
ptr
->
consume
(
this
,
sd
.
rd_buf
.
data
(),
sd
.
rd_buf
.
size
()))
sd
.
passive_mode
=
true
;
return
true
;
}
break
;
case
receive_policy_flag
:
:
at_most
:
auto
max_bytes
=
static_cast
<
ptrdiff_t
>
(
sd
.
recv_conf
.
second
);
if
(
!
sd
.
vn_buf
.
empty
())
{
sd
.
rd_buf
.
clear
();
auto
xbuf_size
=
static_cast
<
ptrdiff_t
>
(
sd
.
vn_buf
.
size
());
auto
first
=
sd
.
vn_buf
.
begin
();
auto
last
=
(
max_bytes
<
xbuf_size
)
?
first
+
max_bytes
:
sd
.
vn_buf
.
end
();
sd
.
rd_buf
.
insert
(
sd
.
rd_buf
.
end
(),
first
,
last
);
sd
.
vn_buf
.
erase
(
first
,
last
);
if
(
!
sd
.
ptr
->
consume
(
this
,
sd
.
rd_buf
.
data
(),
sd
.
rd_buf
.
size
()))
sd
.
passive_mode
=
true
;
return
true
;
}
}
return
false
;
}
bool
test_multiplexer
::
read_data
()
{
bool
test_multiplexer
::
read_data
()
{
CAF_ASSERT
(
std
::
this_thread
::
get_id
()
==
tid_
);
CAF_ASSERT
(
std
::
this_thread
::
get_id
()
==
tid_
);
CAF_LOG_TRACE
(
""
);
CAF_LOG_TRACE
(
""
);
...
@@ -425,12 +486,12 @@ bool test_multiplexer::read_data() {
...
@@ -425,12 +486,12 @@ bool test_multiplexer::read_data() {
bool
test_multiplexer
::
read_data
(
connection_handle
hdl
)
{
bool
test_multiplexer
::
read_data
(
connection_handle
hdl
)
{
CAF_ASSERT
(
std
::
this_thread
::
get_id
()
==
tid_
);
CAF_ASSERT
(
std
::
this_thread
::
get_id
()
==
tid_
);
CAF_LOG_TRACE
(
CAF_ARG
(
hdl
));
CAF_LOG_TRACE
(
CAF_ARG
(
hdl
));
flush_runnables
();
if
(
passive_mode
(
hdl
))
if
(
passive_mode
(
hdl
))
return
false
;
return
false
;
flush_runnables
();
scribe_data
&
sd
=
scribe_data_
[
hdl
];
scribe_data
&
sd
=
scribe_data_
[
hdl
];
if
(
!
sd
.
ptr
)
{
if
(
sd
.
ptr
==
nullptr
||
sd
.
ptr
->
parent
()
==
nullptr
CAF_LOG_DEBUG
(
"No scribe available yet on"
<<
CAF_ARG
(
hdl
));
||
!
sd
.
ptr
->
parent
()
->
getf
(
abstract_actor
::
is_initialized_flag
))
{
return
false
;
return
false
;
}
}
// count how many data packets we could dispatch
// count how many data packets we could dispatch
...
...
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