Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
actor-incubator
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
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-incubator
Commits
98243583
Commit
98243583
authored
Nov 27, 2019
by
Jakob Otto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unnecessary make_span calls
parent
85ae9170
Changes
20
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
56 additions
and
72 deletions
+56
-72
libcaf_net/caf/net/basp/application.hpp
libcaf_net/caf/net/basp/application.hpp
+0
-1
libcaf_net/caf/net/datagram_transport.hpp
libcaf_net/caf/net/datagram_transport.hpp
+3
-5
libcaf_net/caf/net/packet_writer_decorator.hpp
libcaf_net/caf/net/packet_writer_decorator.hpp
+0
-1
libcaf_net/src/multiplexer.cpp
libcaf_net/src/multiplexer.cpp
+1
-1
libcaf_net/src/pipe_socket.cpp
libcaf_net/src/pipe_socket.cpp
+0
-1
libcaf_net/src/stream_socket.cpp
libcaf_net/src/stream_socket.cpp
+0
-1
libcaf_net/src/udp_datagram_socket.cpp
libcaf_net/src/udp_datagram_socket.cpp
+0
-1
libcaf_net/test/application.cpp
libcaf_net/test/application.cpp
+15
-19
libcaf_net/test/datagram_transport.cpp
libcaf_net/test/datagram_transport.cpp
+1
-1
libcaf_net/test/endpoint_manager.cpp
libcaf_net/test/endpoint_manager.cpp
+6
-6
libcaf_net/test/header.cpp
libcaf_net/test/header.cpp
+1
-1
libcaf_net/test/multiplexer.cpp
libcaf_net/test/multiplexer.cpp
+1
-1
libcaf_net/test/net/basp/worker.cpp
libcaf_net/test/net/basp/worker.cpp
+1
-1
libcaf_net/test/pipe_socket.cpp
libcaf_net/test/pipe_socket.cpp
+2
-3
libcaf_net/test/stream_application.cpp
libcaf_net/test/stream_application.cpp
+9
-9
libcaf_net/test/stream_socket.cpp
libcaf_net/test/stream_socket.cpp
+8
-10
libcaf_net/test/stream_transport.cpp
libcaf_net/test/stream_transport.cpp
+1
-1
libcaf_net/test/string_application.cpp
libcaf_net/test/string_application.cpp
+3
-2
libcaf_net/test/transport_worker.cpp
libcaf_net/test/transport_worker.cpp
+1
-3
libcaf_net/test/udp_datagram_socket.cpp
libcaf_net/test/udp_datagram_socket.cpp
+3
-4
No files found.
libcaf_net/caf/net/basp/application.hpp
View file @
98243583
...
...
@@ -46,7 +46,6 @@
#include "caf/proxy_registry.hpp"
#include "caf/response_promise.hpp"
#include "caf/scoped_execution_unit.hpp"
#include "caf/span.hpp"
#include "caf/unit.hpp"
namespace
caf
::
net
::
basp
{
...
...
libcaf_net/caf/net/datagram_transport.hpp
View file @
98243583
...
...
@@ -30,7 +30,6 @@
#include "caf/net/transport_worker_dispatcher.hpp"
#include "caf/net/udp_datagram_socket.hpp"
#include "caf/sec.hpp"
#include "caf/span.hpp"
namespace
caf
::
net
{
...
...
@@ -81,14 +80,13 @@ public:
bool
handle_read_event
(
endpoint_manager
&
)
override
{
CAF_LOG_TRACE
(
CAF_ARG
(
this
->
handle_
.
id
));
auto
ret
=
read
(
this
->
handle_
,
make_span
(
this
->
read_buf_
)
);
auto
ret
=
read
(
this
->
handle_
,
this
->
read_buf_
);
if
(
auto
res
=
get_if
<
std
::
pair
<
size_t
,
ip_endpoint
>>
(
&
ret
))
{
auto
num_bytes
=
res
->
first
;
CAF_LOG_DEBUG
(
"received "
<<
num_bytes
<<
" bytes"
);
auto
ep
=
res
->
second
;
this
->
read_buf_
.
resize
(
num_bytes
);
this
->
next_layer_
.
handle_data
(
*
this
,
make_span
(
this
->
read_buf_
),
std
::
move
(
ep
));
this
->
next_layer_
.
handle_data
(
*
this
,
this
->
read_buf_
,
std
::
move
(
ep
));
prepare_next_read
();
}
else
{
auto
err
=
get
<
sec
>
(
ret
);
...
...
@@ -183,7 +181,7 @@ private:
while
(
!
packet_queue_
.
empty
())
{
auto
&
packet
=
packet_queue_
.
front
();
auto
ptrs
=
packet
.
get_buffer_ptrs
();
auto
write_ret
=
write
(
this
->
handle_
,
make_span
(
ptrs
)
,
packet
.
id
);
auto
write_ret
=
write
(
this
->
handle_
,
ptrs
,
packet
.
id
);
if
(
auto
num_bytes
=
get_if
<
size_t
>
(
&
write_ret
))
{
CAF_LOG_DEBUG
(
CAF_ARG
(
this
->
handle_
.
id
)
<<
CAF_ARG
(
*
num_bytes
));
CAF_LOG_WARNING_IF
(
*
num_bytes
<
packet
.
size
,
...
...
libcaf_net/caf/net/packet_writer_decorator.hpp
View file @
98243583
...
...
@@ -21,7 +21,6 @@
#include "caf/net/packet_writer.hpp"
#include "caf/byte.hpp"
#include "caf/span.hpp"
namespace
caf
::
net
{
...
...
libcaf_net/src/multiplexer.cpp
View file @
98243583
...
...
@@ -274,7 +274,7 @@ void multiplexer::write_to_pipe(uint8_t opcode, const socket_manager_ptr& mgr) {
{
// Lifetime scope of guard.
std
::
lock_guard
<
std
::
mutex
>
guard
{
write_lock_
};
if
(
write_handle_
!=
invalid_socket
)
res
=
write
(
write_handle_
,
make_span
(
buf
)
);
res
=
write
(
write_handle_
,
buf
);
else
res
=
sec
::
socket_invalid
;
}
...
...
libcaf_net/src/pipe_socket.cpp
View file @
98243583
...
...
@@ -30,7 +30,6 @@
#include "caf/message.hpp"
#include "caf/net/stream_socket.hpp"
#include "caf/sec.hpp"
#include "caf/span.hpp"
#include "caf/variant.hpp"
namespace
caf
::
net
{
...
...
libcaf_net/src/stream_socket.cpp
View file @
98243583
...
...
@@ -24,7 +24,6 @@
#include "caf/detail/socket_sys_includes.hpp"
#include "caf/expected.hpp"
#include "caf/logger.hpp"
#include "caf/span.hpp"
#include "caf/variant.hpp"
#ifdef CAF_POSIX
...
...
libcaf_net/src/udp_datagram_socket.cpp
View file @
98243583
...
...
@@ -27,7 +27,6 @@
#include "caf/ip_endpoint.hpp"
#include "caf/logger.hpp"
#include "caf/net/socket_guard.hpp"
#include "caf/span.hpp"
namespace
caf
::
net
{
...
...
libcaf_net/test/application.cpp
View file @
98243583
...
...
@@ -75,16 +75,16 @@ struct fixture : test_coordinator_fixture<>,
set_input
(
basp
::
header
{
basp
::
message_type
::
handshake
,
static_cast
<
uint32_t
>
(
payload
.
size
()),
basp
::
version
});
REQUIRE_OK
(
app
.
handle_data
(
*
this
,
make_span
(
input
)
));
REQUIRE_OK
(
app
.
handle_data
(
*
this
,
input
));
CAF_CHECK_EQUAL
(
app
.
state
(),
basp
::
connection_state
::
await_handshake_payload
);
REQUIRE_OK
(
app
.
handle_data
(
*
this
,
make_span
(
payload
)
));
REQUIRE_OK
(
app
.
handle_data
(
*
this
,
payload
));
}
void
consume_handshake
()
{
if
(
output
.
size
()
<
basp
::
header_size
)
CAF_FAIL
(
"BASP application did not write a handshake header"
);
auto
hdr
=
basp
::
header
::
from_bytes
(
make_span
(
output
)
);
auto
hdr
=
basp
::
header
::
from_bytes
(
output
);
if
(
hdr
.
type
!=
basp
::
message_type
::
handshake
||
hdr
.
payload_len
==
0
||
hdr
.
operation_data
!=
basp
::
version
)
CAF_FAIL
(
"invalid handshake header"
);
...
...
@@ -158,10 +158,10 @@ protected:
do { \
auto payload = to_buf(__VA_ARGS__); \
set_input(basp::header{kind, static_cast<uint32_t>(payload.size()), op}); \
if (auto err = app.handle_data(*this,
make_span(input)))
\
if (auto err = app.handle_data(*this,
input))
\
CAF_FAIL("application-under-test failed to process header: " \
<< sys.render(err)); \
if (auto err = app.handle_data(*this,
make_span(payload)))
\
if (auto err = app.handle_data(*this,
payload))
\
CAF_FAIL("application-under-test failed to process payload: " \
<< sys.render(err)); \
} while (false)
...
...
@@ -185,22 +185,19 @@ CAF_TEST_FIXTURE_SCOPE(application_tests, fixture)
CAF_TEST
(
missing
handshake
)
{
CAF_CHECK_EQUAL
(
app
.
state
(),
basp
::
connection_state
::
await_handshake_header
);
set_input
(
basp
::
header
{
basp
::
message_type
::
heartbeat
,
0
,
0
});
CAF_CHECK_EQUAL
(
app
.
handle_data
(
*
this
,
make_span
(
input
)),
basp
::
ec
::
missing_handshake
);
CAF_CHECK_EQUAL
(
app
.
handle_data
(
*
this
,
input
),
basp
::
ec
::
missing_handshake
);
}
CAF_TEST
(
version
mismatch
)
{
CAF_CHECK_EQUAL
(
app
.
state
(),
basp
::
connection_state
::
await_handshake_header
);
set_input
(
basp
::
header
{
basp
::
message_type
::
handshake
,
0
,
0
});
CAF_CHECK_EQUAL
(
app
.
handle_data
(
*
this
,
make_span
(
input
)),
basp
::
ec
::
version_mismatch
);
CAF_CHECK_EQUAL
(
app
.
handle_data
(
*
this
,
input
),
basp
::
ec
::
version_mismatch
);
}
CAF_TEST
(
missing
payload
in
handshake
)
{
CAF_CHECK_EQUAL
(
app
.
state
(),
basp
::
connection_state
::
await_handshake_header
);
set_input
(
basp
::
header
{
basp
::
message_type
::
handshake
,
0
,
basp
::
version
});
CAF_CHECK_EQUAL
(
app
.
handle_data
(
*
this
,
make_span
(
input
)),
basp
::
ec
::
missing_payload
);
CAF_CHECK_EQUAL
(
app
.
handle_data
(
*
this
,
input
),
basp
::
ec
::
missing_payload
);
}
CAF_TEST
(
invalid
handshake
)
{
...
...
@@ -210,10 +207,9 @@ CAF_TEST(invalid handshake) {
auto
payload
=
to_buf
(
no_nid
,
no_ids
);
set_input
(
basp
::
header
{
basp
::
message_type
::
handshake
,
static_cast
<
uint32_t
>
(
payload
.
size
()),
basp
::
version
});
REQUIRE_OK
(
app
.
handle_data
(
*
this
,
make_span
(
input
)
));
REQUIRE_OK
(
app
.
handle_data
(
*
this
,
input
));
CAF_CHECK_EQUAL
(
app
.
state
(),
basp
::
connection_state
::
await_handshake_payload
);
CAF_CHECK_EQUAL
(
app
.
handle_data
(
*
this
,
make_span
(
payload
)),
basp
::
ec
::
invalid_handshake
);
CAF_CHECK_EQUAL
(
app
.
handle_data
(
*
this
,
payload
),
basp
::
ec
::
invalid_handshake
);
}
CAF_TEST
(
app
identifier
mismatch
)
{
...
...
@@ -222,9 +218,9 @@ CAF_TEST(app identifier mismatch) {
auto
payload
=
to_buf
(
mars
,
wrong_ids
);
set_input
(
basp
::
header
{
basp
::
message_type
::
handshake
,
static_cast
<
uint32_t
>
(
payload
.
size
()),
basp
::
version
});
REQUIRE_OK
(
app
.
handle_data
(
*
this
,
make_span
(
input
)
));
REQUIRE_OK
(
app
.
handle_data
(
*
this
,
input
));
CAF_CHECK_EQUAL
(
app
.
state
(),
basp
::
connection_state
::
await_handshake_payload
);
CAF_CHECK_EQUAL
(
app
.
handle_data
(
*
this
,
make_span
(
payload
)
),
CAF_CHECK_EQUAL
(
app
.
handle_data
(
*
this
,
payload
),
basp
::
ec
::
app_identifiers_mismatch
);
}
...
...
@@ -237,8 +233,8 @@ CAF_TEST(repeated handshake) {
auto
payload
=
to_buf
(
no_nid
,
no_ids
);
set_input
(
basp
::
header
{
basp
::
message_type
::
handshake
,
static_cast
<
uint32_t
>
(
payload
.
size
()),
basp
::
version
});
CAF_CHECK_EQUAL
(
app
.
handle_data
(
*
this
,
make_span
(
input
)
),
none
);
CAF_CHECK_EQUAL
(
app
.
handle_data
(
*
this
,
make_span
(
payload
)
),
CAF_CHECK_EQUAL
(
app
.
handle_data
(
*
this
,
input
),
none
);
CAF_CHECK_EQUAL
(
app
.
handle_data
(
*
this
,
payload
),
basp
::
ec
::
unexpected_handshake
);
}
...
...
@@ -337,7 +333,7 @@ CAF_TEST(heartbeat message) {
CAF_CHECK_EQUAL
(
app
.
state
(),
basp
::
connection_state
::
await_header
);
auto
bytes
=
to_bytes
(
basp
::
header
{
basp
::
message_type
::
heartbeat
,
0
,
0
});
set_input
(
bytes
);
REQUIRE_OK
(
app
.
handle_data
(
*
this
,
make_span
(
input
)
));
REQUIRE_OK
(
app
.
handle_data
(
*
this
,
input
));
CAF_CHECK_EQUAL
(
app
.
state
(),
basp
::
connection_state
::
await_header
);
}
...
...
libcaf_net/test/datagram_transport.cpp
View file @
98243583
...
...
@@ -83,7 +83,7 @@ struct fixture : test_coordinator_fixture<>, host_fixture {
uint8_t
receive_attempts
=
0
;
variant
<
std
::
pair
<
size_t
,
ip_endpoint
>
,
sec
>
read_ret
;
do
{
read_ret
=
read
(
sock
,
make_span
(
buf
)
);
read_ret
=
read
(
sock
,
buf
);
if
(
auto
read_res
=
get_if
<
std
::
pair
<
size_t
,
ip_endpoint
>>
(
&
read_ret
))
{
buf
.
resize
(
read_res
->
first
);
}
else
if
(
get
<
sec
>
(
read_ret
)
!=
sec
::
unavailable_or_would_block
)
{
...
...
libcaf_net/test/endpoint_manager.cpp
View file @
98243583
...
...
@@ -94,7 +94,7 @@ public:
template
<
class
Manager
>
bool
handle_read_event
(
Manager
&
)
{
auto
res
=
read
(
handle_
,
make_span
(
read_buf_
)
);
auto
res
=
read
(
handle_
,
read_buf_
);
if
(
auto
num_bytes
=
get_if
<
size_t
>
(
&
res
))
{
data_
->
insert
(
data_
->
end
(),
read_buf_
.
begin
(),
read_buf_
.
begin
()
+
*
num_bytes
);
...
...
@@ -109,7 +109,7 @@ public:
auto
&
payload
=
x
->
payload
;
buf_
.
insert
(
buf_
.
end
(),
payload
.
begin
(),
payload
.
end
());
}
auto
res
=
write
(
handle_
,
as_bytes
(
make_span
(
buf_
))
);
auto
res
=
write
(
handle_
,
buf_
);
if
(
auto
num_bytes
=
get_if
<
size_t
>
(
&
res
))
{
buf_
.
erase
(
buf_
.
begin
(),
buf_
.
begin
()
+
*
num_bytes
);
return
buf_
.
size
()
>
0
;
...
...
@@ -168,7 +168,7 @@ CAF_TEST(send and receive) {
auto
buf
=
std
::
make_shared
<
std
::
vector
<
byte
>>
();
auto
sockets
=
unbox
(
make_stream_socket_pair
());
nonblocking
(
sockets
.
second
,
true
);
CAF_CHECK_EQUAL
(
read
(
sockets
.
second
,
make_span
(
read_buf
)
),
CAF_CHECK_EQUAL
(
read
(
sockets
.
second
,
read_buf
),
sec
::
unavailable_or_would_block
);
auto
guard
=
detail
::
make_scope_guard
([
&
]
{
close
(
sockets
.
second
);
});
auto
mgr
=
make_endpoint_manager
(
mpx
,
sys
,
...
...
@@ -183,7 +183,7 @@ CAF_TEST(send and receive) {
CAF_CHECK_EQUAL
(
string_view
(
reinterpret_cast
<
char
*>
(
buf
->
data
()),
buf
->
size
()),
hello_manager
);
CAF_CHECK_EQUAL
(
read
(
sockets
.
second
,
make_span
(
read_buf
)
),
hello_test
.
size
());
CAF_CHECK_EQUAL
(
read
(
sockets
.
second
,
read_buf
),
hello_test
.
size
());
CAF_CHECK_EQUAL
(
string_view
(
reinterpret_cast
<
char
*>
(
read_buf
.
data
()),
hello_test
.
size
()),
hello_test
);
...
...
@@ -200,7 +200,7 @@ CAF_TEST(resolve and proxy communication) {
CAF_CHECK_EQUAL
(
mgr
->
init
(),
none
);
CAF_CHECK_EQUAL
(
mgr
->
mask
(),
operation
::
read_write
);
run
();
CAF_CHECK_EQUAL
(
read
(
sockets
.
second
,
make_span
(
read_buf
)
),
hello_test
.
size
());
CAF_CHECK_EQUAL
(
read
(
sockets
.
second
,
read_buf
),
hello_test
.
size
());
mgr
->
resolve
(
unbox
(
make_uri
(
"test:id/42"
)),
self
);
run
();
self
->
receive
(
...
...
@@ -211,7 +211,7 @@ CAF_TEST(resolve and proxy communication) {
after
(
std
::
chrono
::
seconds
(
0
))
>>
[
&
]
{
CAF_FAIL
(
"manager did not respond with a proxy."
);
});
run
();
auto
read_res
=
read
(
sockets
.
second
,
make_span
(
read_buf
)
);
auto
read_res
=
read
(
sockets
.
second
,
read_buf
);
if
(
!
holds_alternative
<
size_t
>
(
read_res
))
{
CAF_ERROR
(
"read() returned an error: "
<<
sys
.
render
(
get
<
sec
>
(
read_res
)));
return
;
...
...
libcaf_net/test/header.cpp
View file @
98243583
...
...
@@ -45,7 +45,7 @@ CAF_TEST(serialization) {
CAF_CHECK_EQUAL
(
source
(
y
),
none
);
}
CAF_CHECK_EQUAL
(
x
,
y
);
auto
z
=
basp
::
header
::
from_bytes
(
make_span
(
buf
)
);
auto
z
=
basp
::
header
::
from_bytes
(
buf
);
CAF_CHECK_EQUAL
(
x
,
z
);
CAF_CHECK_EQUAL
(
y
,
z
);
}
...
...
libcaf_net/test/multiplexer.cpp
View file @
98243583
...
...
@@ -72,7 +72,7 @@ public:
bool
handle_write_event
()
override
{
if
(
wr_buf_
.
size
()
==
0
)
return
false
;
auto
res
=
write
(
handle
(),
make_span
(
wr_buf_
)
);
auto
res
=
write
(
handle
(),
wr_buf_
);
if
(
auto
num_bytes
=
get_if
<
size_t
>
(
&
res
))
{
CAF_ASSERT
(
*
num_bytes
>
0
);
wr_buf_
.
erase
(
wr_buf_
.
begin
(),
wr_buf_
.
begin
()
+
*
num_bytes
);
...
...
libcaf_net/test/net/basp/worker.cpp
View file @
98243583
...
...
@@ -117,7 +117,7 @@ CAF_TEST(deliver serialized message) {
static_cast
<
uint32_t
>
(
payload
.
size
()),
make_message_id
().
integer_value
()};
CAF_MESSAGE
(
"launch worker"
);
w
->
launch
(
last_hop
,
hdr
,
make_span
(
payload
)
);
w
->
launch
(
last_hop
,
hdr
,
payload
);
sched
.
run_once
();
expect
((
ok_atom
),
from
(
_
).
to
(
testee
));
}
...
...
libcaf_net/test/pipe_socket.cpp
View file @
98243583
...
...
@@ -26,7 +26,6 @@
#include <vector>
#include "caf/byte.hpp"
#include "caf/span.hpp"
using
namespace
caf
;
using
namespace
caf
::
net
;
...
...
@@ -41,8 +40,8 @@ CAF_TEST(send and receive) {
pipe_socket
rd_sock
;
pipe_socket
wr_sock
;
std
::
tie
(
rd_sock
,
wr_sock
)
=
unbox
(
make_pipe
());
CAF_CHECK_EQUAL
(
write
(
wr_sock
,
make_span
(
send_buf
)
),
send_buf
.
size
());
CAF_CHECK_EQUAL
(
read
(
rd_sock
,
make_span
(
receive_buf
)
),
send_buf
.
size
());
CAF_CHECK_EQUAL
(
write
(
wr_sock
,
send_buf
),
send_buf
.
size
());
CAF_CHECK_EQUAL
(
read
(
rd_sock
,
receive_buf
),
send_buf
.
size
());
CAF_CHECK
(
std
::
equal
(
send_buf
.
begin
(),
send_buf
.
end
(),
receive_buf
.
begin
()));
}
...
...
libcaf_net/test/stream_application.cpp
View file @
98243583
...
...
@@ -90,7 +90,7 @@ struct fixture : host_fixture, test_coordinator_fixture<config> {
template
<
class
...
Ts
>
void
mock
(
const
Ts
&
...
xs
)
{
auto
buf
=
to_buf
(
xs
...);
if
(
fetch_size
(
write
(
sock
,
make_span
(
buf
)
))
!=
buf
.
size
())
if
(
fetch_size
(
write
(
sock
,
buf
))
!=
buf
.
size
())
CAF_FAIL
(
"unable to write "
<<
buf
.
size
()
<<
" bytes"
);
run
();
}
...
...
@@ -103,20 +103,20 @@ struct fixture : host_fixture, test_coordinator_fixture<config> {
static_cast
<
uint32_t
>
(
payload
.
size
()),
basp
::
version
});
CAF_CHECK_EQUAL
(
app
->
state
(),
basp
::
connection_state
::
await_handshake_payload
);
write
(
sock
,
make_span
(
payload
)
);
write
(
sock
,
payload
);
run
();
}
void
consume_handshake
()
{
buffer_type
buf
(
basp
::
header_size
);
if
(
fetch_size
(
read
(
sock
,
make_span
(
buf
)
))
!=
basp
::
header_size
)
if
(
fetch_size
(
read
(
sock
,
buf
))
!=
basp
::
header_size
)
CAF_FAIL
(
"unable to read "
<<
basp
::
header_size
<<
" bytes"
);
auto
hdr
=
basp
::
header
::
from_bytes
(
make_span
(
buf
)
);
auto
hdr
=
basp
::
header
::
from_bytes
(
buf
);
if
(
hdr
.
type
!=
basp
::
message_type
::
handshake
||
hdr
.
payload_len
==
0
||
hdr
.
operation_data
!=
basp
::
version
)
CAF_FAIL
(
"invalid handshake header"
);
buf
.
resize
(
hdr
.
payload_len
);
if
(
fetch_size
(
read
(
sock
,
make_span
(
buf
)
))
!=
hdr
.
payload_len
)
if
(
fetch_size
(
read
(
sock
,
buf
))
!=
hdr
.
payload_len
)
CAF_FAIL
(
"unable to read "
<<
hdr
.
payload_len
<<
" bytes"
);
node_id
nid
;
std
::
vector
<
std
::
string
>
app_ids
;
...
...
@@ -149,7 +149,7 @@ struct fixture : host_fixture, test_coordinator_fixture<config> {
std::tuple<unit_t>>::value) { \
auto payload = to_buf(__VA_ARGS__); \
mock(basp::header{kind, static_cast<uint32_t>(payload.size()), op}); \
write(sock,
make_span(payload));
\
write(sock,
payload);
\
} else { \
mock(basp::header{kind, 0, op}); \
} \
...
...
@@ -160,15 +160,15 @@ struct fixture : host_fixture, test_coordinator_fixture<config> {
do { \
CAF_MESSAGE("receive " << msg_type); \
buffer_type buf(basp::header_size); \
if (fetch_size(read(sock,
make_span(buf))) != basp::header_size)
\
if (fetch_size(read(sock,
buf)) != basp::header_size)
\
CAF_FAIL("unable to read " << basp::header_size << " bytes"); \
auto hdr = basp::header::from_bytes(
make_span(buf));
\
auto hdr = basp::header::from_bytes(
buf);
\
CAF_CHECK_EQUAL(hdr.type, msg_type); \
CAF_CHECK_EQUAL(hdr.operation_data, op_data); \
if (!std::is_same<decltype(std::make_tuple(__VA_ARGS__)), \
std::tuple<unit_t>>::value) { \
buf.resize(hdr.payload_len); \
if (fetch_size(read(sock,
make_span(buf))) != size_t{hdr.payload_len})
\
if (fetch_size(read(sock,
buf)) != size_t{hdr.payload_len})
\
CAF_FAIL("unable to read " << hdr.payload_len << " bytes"); \
binary_deserializer source{sys, buf}; \
if (auto err = source(__VA_ARGS__)) \
...
...
libcaf_net/test/stream_socket.cpp
View file @
98243583
...
...
@@ -74,31 +74,29 @@ struct fixture : host_fixture {
CAF_TEST_FIXTURE_SCOPE
(
network_socket_tests
,
fixture
)
CAF_TEST
(
read
on
empty
sockets
)
{
CAF_CHECK_EQUAL
(
read
(
first
,
make_span
(
rd_buf
)),
sec
::
unavailable_or_would_block
);
CAF_CHECK_EQUAL
(
read
(
second
,
make_span
(
rd_buf
)),
sec
::
unavailable_or_would_block
);
CAF_CHECK_EQUAL
(
read
(
first
,
rd_buf
),
sec
::
unavailable_or_would_block
);
CAF_CHECK_EQUAL
(
read
(
second
,
rd_buf
),
sec
::
unavailable_or_would_block
);
}
CAF_TEST
(
transfer
data
from
first
to
second
socket
)
{
std
::
vector
<
byte
>
wr_buf
{
1
_b
,
2
_b
,
4
_b
,
8
_b
,
16
_b
,
32
_b
,
64
_b
};
CAF_MESSAGE
(
"transfer data from first to second socket"
);
CAF_CHECK_EQUAL
(
write
(
first
,
make_span
(
wr_buf
)
),
wr_buf
.
size
());
CAF_CHECK_EQUAL
(
read
(
second
,
make_span
(
rd_buf
)
),
wr_buf
.
size
());
CAF_CHECK_EQUAL
(
write
(
first
,
wr_buf
),
wr_buf
.
size
());
CAF_CHECK_EQUAL
(
read
(
second
,
rd_buf
),
wr_buf
.
size
());
CAF_CHECK
(
std
::
equal
(
wr_buf
.
begin
(),
wr_buf
.
end
(),
rd_buf
.
begin
()));
rd_buf
.
assign
(
rd_buf
.
size
(),
byte
(
0
));
}
CAF_TEST
(
transfer
data
from
second
to
first
socket
)
{
std
::
vector
<
byte
>
wr_buf
{
1
_b
,
2
_b
,
4
_b
,
8
_b
,
16
_b
,
32
_b
,
64
_b
};
CAF_CHECK_EQUAL
(
write
(
second
,
make_span
(
wr_buf
)
),
wr_buf
.
size
());
CAF_CHECK_EQUAL
(
read
(
first
,
make_span
(
rd_buf
)
),
wr_buf
.
size
());
CAF_CHECK_EQUAL
(
write
(
second
,
wr_buf
),
wr_buf
.
size
());
CAF_CHECK_EQUAL
(
read
(
first
,
rd_buf
),
wr_buf
.
size
());
CAF_CHECK
(
std
::
equal
(
wr_buf
.
begin
(),
wr_buf
.
end
(),
rd_buf
.
begin
()));
}
CAF_TEST
(
shut
down
first
socket
and
observe
shutdown
on
the
second
one
)
{
close
(
first
);
CAF_CHECK_EQUAL
(
read
(
second
,
make_span
(
rd_buf
)
),
sec
::
socket_disconnected
);
CAF_CHECK_EQUAL
(
read
(
second
,
rd_buf
),
sec
::
socket_disconnected
);
first
.
id
=
invalid_socket_id
;
}
...
...
@@ -110,7 +108,7 @@ CAF_TEST(transfer data using multiple buffers) {
full_buf
.
insert
(
full_buf
.
end
(),
wr_buf_2
.
begin
(),
wr_buf_2
.
end
());
CAF_CHECK_EQUAL
(
write
(
second
,
{
make_span
(
wr_buf_1
),
make_span
(
wr_buf_2
)}),
full_buf
.
size
());
CAF_CHECK_EQUAL
(
read
(
first
,
make_span
(
rd_buf
)
),
full_buf
.
size
());
CAF_CHECK_EQUAL
(
read
(
first
,
rd_buf
),
full_buf
.
size
());
CAF_CHECK
(
std
::
equal
(
full_buf
.
begin
(),
full_buf
.
end
(),
rd_buf
.
begin
()));
}
...
...
libcaf_net/test/stream_transport.cpp
View file @
98243583
...
...
@@ -194,7 +194,7 @@ CAF_TEST(resolve and proxy communication) {
after
(
std
::
chrono
::
seconds
(
0
))
>>
[
&
]
{
CAF_FAIL
(
"manager did not respond with a proxy."
);
});
run
();
auto
read_res
=
read
(
recv_socket_guard
.
socket
(),
make_span
(
recv_buf
)
);
auto
read_res
=
read
(
recv_socket_guard
.
socket
(),
recv_buf
);
if
(
!
holds_alternative
<
size_t
>
(
read_res
))
CAF_FAIL
(
"read() returned an error: "
<<
sys
.
render
(
get
<
sec
>
(
read_res
)));
recv_buf
.
resize
(
get
<
size_t
>
(
read_res
));
...
...
libcaf_net/test/string_application.cpp
View file @
98243583
...
...
@@ -153,7 +153,8 @@ public:
if
(
data
.
size
()
!=
sizeof
(
header_type
))
CAF_FAIL
(
""
);
binary_deserializer
source
{
nullptr
,
data
};
source
(
header_
);
if
(
auto
err
=
source
(
header_
))
CAF_FAIL
(
"serializing failed: "
<<
err
);
if
(
header_
.
payload
==
0
)
Base
::
handle_packet
(
parent
,
header_
,
span
<
const
byte
>
{});
else
...
...
@@ -215,7 +216,7 @@ CAF_TEST(receive) {
auto
buf
=
std
::
make_shared
<
std
::
vector
<
byte
>>
();
auto
sockets
=
unbox
(
make_stream_socket_pair
());
nonblocking
(
sockets
.
second
,
true
);
CAF_CHECK_EQUAL
(
read
(
sockets
.
second
,
make_span
(
read_buf
)
),
CAF_CHECK_EQUAL
(
read
(
sockets
.
second
,
read_buf
),
sec
::
unavailable_or_would_block
);
CAF_MESSAGE
(
"adding both endpoint managers"
);
auto
mgr1
=
make_endpoint_manager
(
mpx
,
sys
,
...
...
libcaf_net/test/transport_worker.cpp
View file @
98243583
...
...
@@ -202,9 +202,7 @@ CAF_TEST(write_message) {
auto
msg
=
make_message
();
auto
elem
=
make_mailbox_element
(
strong_actor
,
make_message_id
(
12345
),
stack
,
msg
);
auto
test_span
=
make_span
(
reinterpret_cast
<
byte
*>
(
const_cast
<
char
*>
(
hello_test
.
data
())),
hello_test
.
size
());
auto
test_span
=
as_bytes
(
make_span
(
hello_test
));
std
::
vector
<
byte
>
payload
(
test_span
.
begin
(),
test_span
.
end
());
using
message_type
=
endpoint_manager_queue
::
message
;
auto
message
=
detail
::
make_unique
<
message_type
>
(
std
::
move
(
elem
),
nullptr
,
...
...
libcaf_net/test/udp_datagram_socket.cpp
View file @
98243583
...
...
@@ -69,7 +69,7 @@ error read_from_socket(udp_datagram_socket sock, std::vector<byte>& buf) {
uint8_t
receive_attempts
=
0
;
variant
<
std
::
pair
<
size_t
,
ip_endpoint
>
,
sec
>
read_ret
;
do
{
read_ret
=
read
(
sock
,
make_span
(
buf
)
);
read_ret
=
read
(
sock
,
buf
);
if
(
auto
read_res
=
get_if
<
std
::
pair
<
size_t
,
ip_endpoint
>>
(
&
read_ret
))
{
buf
.
resize
(
read_res
->
first
);
}
else
if
(
get
<
sec
>
(
read_ret
)
!=
sec
::
unavailable_or_would_block
)
{
...
...
@@ -106,8 +106,7 @@ CAF_TEST_FIXTURE_SCOPE(udp_datagram_socket_test, fixture)
CAF_TEST
(
read
/
write
using
span
<
byte
>
)
{
if
(
auto
err
=
nonblocking
(
socket_cast
<
net
::
socket
>
(
receive_socket
),
true
))
CAF_FAIL
(
"setting socket to nonblocking failed: "
<<
err
);
CAF_CHECK_EQUAL
(
read
(
receive_socket
,
make_span
(
buf
)),
sec
::
unavailable_or_would_block
);
CAF_CHECK_EQUAL
(
read
(
receive_socket
,
buf
),
sec
::
unavailable_or_would_block
);
CAF_MESSAGE
(
"sending data to "
<<
to_string
(
ep
));
CAF_CHECK_EQUAL
(
write
(
send_socket
,
as_bytes
(
make_span
(
hello_test
)),
ep
),
hello_test
.
size
());
...
...
@@ -127,7 +126,7 @@ CAF_TEST(read / write using span<std::vector<byte>*>) {
std
::
vector
<
byte
>
payload_buf
(
bytes
.
begin
(),
bytes
.
end
());
auto
packet_size
=
hdr_buf
.
size
()
+
payload_buf
.
size
();
std
::
vector
<
std
::
vector
<
byte
>*>
bufs
{
&
hdr_buf
,
&
payload_buf
};
CAF_CHECK_EQUAL
(
write
(
send_socket
,
make_span
(
bufs
)
,
ep
),
packet_size
);
CAF_CHECK_EQUAL
(
write
(
send_socket
,
bufs
,
ep
),
packet_size
);
// receive both as one single packet.
buf
.
resize
(
packet_size
);
CAF_CHECK_EQUAL
(
read_from_socket
(
receive_socket
,
buf
),
none
);
...
...
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