Commit 110a49a6 authored by Jakob Otto's avatar Jakob Otto

Fix returned port and add test

parent 37fc6104
...@@ -82,7 +82,7 @@ make_udp_datagram_socket(ip_endpoint ep, bool reuse_addr) { ...@@ -82,7 +82,7 @@ make_udp_datagram_socket(ip_endpoint ep, bool reuse_addr) {
auto port = addr.ss_family == AF_INET auto port = addr.ss_family == AF_INET
? reinterpret_cast<sockaddr_in*>(&addr)->sin_port ? reinterpret_cast<sockaddr_in*>(&addr)->sin_port
: reinterpret_cast<sockaddr_in6*>(&addr)->sin6_port; : reinterpret_cast<sockaddr_in6*>(&addr)->sin6_port;
return std::make_pair(sguard.release(), port); return std::make_pair(sguard.release(), ntohs(port));
} }
variant<std::pair<size_t, ip_endpoint>, sec> read(udp_datagram_socket x, variant<std::pair<size_t, ip_endpoint>, sec> read(udp_datagram_socket x,
......
...@@ -63,7 +63,7 @@ struct fixture : test_coordinator_fixture<>, host_fixture { ...@@ -63,7 +63,7 @@ struct fixture : test_coordinator_fixture<>, host_fixture {
send_socket = send_pair.first; send_socket = send_pair.first;
auto receive_pair = unbox(make_udp_datagram_socket(ep)); auto receive_pair = unbox(make_udp_datagram_socket(ep));
recv_socket = receive_pair.first; recv_socket = receive_pair.first;
ep.port(htons(receive_pair.second)); ep.port(receive_pair.second);
CAF_MESSAGE("sending message to " << CAF_ARG(ep)); CAF_MESSAGE("sending message to " << CAF_ARG(ep));
if (auto err = nonblocking(recv_socket, true)) if (auto err = nonblocking(recv_socket, true))
CAF_FAIL("nonblocking() returned an error: " << err); CAF_FAIL("nonblocking() returned an error: " << err);
......
...@@ -49,7 +49,7 @@ struct fixture : host_fixture { ...@@ -49,7 +49,7 @@ struct fixture : host_fixture {
send_socket = send_pair.first; send_socket = send_pair.first;
auto receive_pair = unbox(make_udp_datagram_socket(ep)); auto receive_pair = unbox(make_udp_datagram_socket(ep));
receive_socket = receive_pair.first; receive_socket = receive_pair.first;
ep.port(ntohs(receive_pair.second)); ep.port(receive_pair.second);
} }
~fixture() { ~fixture() {
...@@ -104,6 +104,15 @@ struct header { ...@@ -104,6 +104,15 @@ struct header {
CAF_TEST_FIXTURE_SCOPE(udp_datagram_socket_test, fixture) CAF_TEST_FIXTURE_SCOPE(udp_datagram_socket_test, fixture)
CAF_TEST(socket creation) {
ip_endpoint ep;
CAF_CHECK_EQUAL(parse("0.0.0.0:0", ep), none);
auto ret = make_udp_datagram_socket(ep);
if (!ret)
CAF_FAIL("socket creation failed: " << ret.error());
CAF_CHECK_EQUAL(local_port(ret->first), ret->second);
}
CAF_TEST(read / write using span<byte>) { CAF_TEST(read / write using span<byte>) {
if (auto err = nonblocking(socket_cast<net::socket>(receive_socket), true)) if (auto err = nonblocking(socket_cast<net::socket>(receive_socket), true))
CAF_FAIL("setting socket to nonblocking failed: " << err); CAF_FAIL("setting socket to nonblocking failed: " << err);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment