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
554188ee
Commit
554188ee
authored
Sep 01, 2019
by
Jakob Otto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup
parent
687235ee
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
11 deletions
+22
-11
libcaf_net/caf/net/udp_datagram_socket.hpp
libcaf_net/caf/net/udp_datagram_socket.hpp
+8
-6
libcaf_net/src/udp_datagram_socket.cpp
libcaf_net/src/udp_datagram_socket.cpp
+11
-5
libcaf_net/test/udp_datagram_socket.cpp
libcaf_net/test/udp_datagram_socket.cpp
+3
-0
No files found.
libcaf_net/caf/net/udp_datagram_socket.hpp
View file @
554188ee
...
...
@@ -25,7 +25,7 @@
namespace
caf
{
namespace
net
{
/// A
non connection
-oriented network communication endpoint for bidirectional
/// A
datagram
-oriented network communication endpoint for bidirectional
/// byte transmission.
struct
udp_datagram_socket
:
abstract_socket
<
udp_datagram_socket
>
{
using
super
=
abstract_socket
<
udp_datagram_socket
>
;
...
...
@@ -41,11 +41,13 @@ struct udp_datagram_socket : abstract_socket<udp_datagram_socket> {
}
};
/// Creates a `tcp_stream_socket` connected to given remote node.
/// @param node Host and port of the remote node.
/// Creates a `udp_datagram_socket` bound to given port.
/// @param node ip_endpoint that contains the port to bind to. Pass port '0' to
/// bind to any unused port - The endpoint will be updated with the specific
/// port that was bound.
/// @returns The connected socket or an error.
/// @relates
tcp_stre
am_socket
expected
<
udp_datagram_socket
>
make_udp_datagram_socket
(
ip_endpoint
&
node
,
/// @relates
udp_datagr
am_socket
expected
<
udp_datagram_socket
>
make_udp_datagram_socket
(
ip_endpoint
&
ep
,
bool
reuse_addr
=
false
);
/// Enables or disables `SIO_UDP_CONNRESET` error on `x`.
...
...
@@ -63,7 +65,7 @@ error allow_connreset(udp_datagram_socket x, bool new_value);
variant
<
std
::
pair
<
size_t
,
ip_endpoint
>
,
sec
>
read
(
udp_datagram_socket
x
,
span
<
byte
>
buf
);
/// Transmits data from `x` to
its peer
.
/// Transmits data from `x` to
given eendpoint
.
/// @param x udp_datagram_socket.
/// @param buf Points to the message to send.
/// @returns The number of written bytes on success, otherwise an error code.
...
...
libcaf_net/src/udp_datagram_socket.cpp
View file @
554188ee
...
...
@@ -55,27 +55,33 @@ error allow_connreset(udp_datagram_socket x, bool) {
#endif // CAF_WINDOWS
expected
<
udp_datagram_socket
>
make_udp_datagram_socket
(
ip_endpoint
&
node
,
expected
<
udp_datagram_socket
>
make_udp_datagram_socket
(
ip_endpoint
&
ep
,
bool
reuse_addr
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
node
));
auto
addr
=
to_sockaddr
(
node
);
CAF_LOG_TRACE
(
CAF_ARG
(
ep
));
auto
addr
=
to_sockaddr
(
ep
);
CAF_NET_SYSCALL
(
"socket"
,
fd
,
==
,
invalid_socket_id
,
::
socket
(
addr
.
ss_family
,
SOCK_DGRAM
,
0
));
udp_datagram_socket
sock
{
fd
};
auto
sguard
=
make_socket_guard
(
sock
);
socklen_t
len
=
(
addr
.
ss_family
==
AF_INET
)
?
sizeof
(
sockaddr_in
)
:
sizeof
(
sockaddr_in6
);
if
(
reuse_addr
)
{
int
on
=
1
;
CAF_NET_SYSCALL
(
"setsockopt"
,
tmp1
,
!=
,
0
,
setsockopt
(
fd
,
SOL_SOCKET
,
SO_REUSEADDR
,
reinterpret_cast
<
setsockopt_ptr
>
(
&
on
),
static_cast
<
socket_size_type
>
(
sizeof
(
on
))));
}
CAF_NET_SYSCALL
(
"bind"
,
err
,
!=
,
0
,
::
bind
(
sock
.
id
,
reinterpret_cast
<
sockaddr
*>
(
&
addr
),
len
));
CAF_NET_SYSCALL
(
"getsockname"
,
erro
,
!=
,
0
,
getsockname
(
sock
.
id
,
reinterpret_cast
<
sockaddr
*>
(
&
addr
),
&
len
));
CAF_LOG_DEBUG
(
CAF_ARG
(
sock
.
id
));
auto
port
=
addr
.
ss_family
==
AF_INET
?
reinterpret_cast
<
sockaddr_in
*>
(
&
addr
)
->
sin_port
:
reinterpret_cast
<
sockaddr_in6
*>
(
&
addr
)
->
sin6_port
;
node
.
port
(
ntohs
(
port
));
ep
.
port
(
ntohs
(
port
));
return
sguard
.
release
();
}
...
...
libcaf_net/test/udp_datagram_socket.cpp
View file @
554188ee
...
...
@@ -43,6 +43,7 @@ struct fixture : host_fixture {
:
host_fixture
(),
v4_local
{
make_ipv4_address
(
127
,
0
,
0
,
1
)},
v6_local
{{
0
},
{
0x1
}},
// TODO: use local_addresses() when merged
addrs
{
net
::
ip
::
resolve
(
"localhost"
)}
{
}
...
...
@@ -94,6 +95,8 @@ struct fixture : host_fixture {
CAF_TEST_FIXTURE_SCOPE
(
udp_datagram_socket_test
,
fixture
)
CAF_TEST
(
send
and
receive
)
{
// TODO: check which versions exist and test existing versions accordingly
// -> local_addresses()
if
(
contains
(
v4_local
))
{
test_send_receive
(
v4_local
);
}
else
if
(
contains
(
v6_local
))
{
...
...
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