Commit 41311fa2 authored by Jakob Otto's avatar Jakob Otto

Fix test on Linux

parent b563087b
...@@ -42,7 +42,7 @@ struct udp_datagram_socket : abstract_socket<udp_datagram_socket> { ...@@ -42,7 +42,7 @@ struct udp_datagram_socket : abstract_socket<udp_datagram_socket> {
}; };
/// Enables or disables `SIO_UDP_CONNRESET` error on `x`. /// Enables or disables `SIO_UDP_CONNRESET` error on `x`.
/// @relates datagram_socket /// @relates udp_datagram_socket
error allow_connreset(udp_datagram_socket x, bool new_value); error allow_connreset(udp_datagram_socket x, bool new_value);
/// Receives data from `x`. /// Receives data from `x`.
...@@ -68,7 +68,9 @@ variant<size_t, sec> write(udp_datagram_socket x, span<const byte> buf, ...@@ -68,7 +68,9 @@ variant<size_t, sec> write(udp_datagram_socket x, span<const byte> buf,
/// Binds given socket to given ip_endpoint. /// Binds given socket to given ip_endpoint.
/// @param x the socket that should be bound. /// @param x the socket that should be bound.
/// @param ep the endpoint to which the socket should be bound. /// @param ep the endpoint to which the socket should be bound.
error bind(udp_datagram_socket x, ip_endpoint ep); /// @returns The port that was actually bound.
/// @Relates udp_datagram_socket
expected<uint16_t> bind(udp_datagram_socket x, ip_endpoint ep);
/// Converts the result from I/O operation on a ::udp_datagram_socket to either /// Converts the result from I/O operation on a ::udp_datagram_socket to either
/// an error code or a non-zero positive integer. /// an error code or a non-zero positive integer.
......
...@@ -89,12 +89,15 @@ variant<size_t, sec> write(udp_datagram_socket x, span<const byte> buf, ...@@ -89,12 +89,15 @@ variant<size_t, sec> write(udp_datagram_socket x, span<const byte> buf,
return get<sec>(ret); return get<sec>(ret);
} }
error bind(udp_datagram_socket x, ip_endpoint ep) { expected<uint16_t> bind(udp_datagram_socket x, ip_endpoint ep) {
auto addr = to_sockaddr(ep); auto addr = to_sockaddr(ep);
CAF_NET_SYSCALL("bind", err, !=, 0, CAF_NET_SYSCALL("bind", err, !=, 0,
::bind(x.id, reinterpret_cast<sockaddr*>(&addr), ::bind(x.id, reinterpret_cast<sockaddr*>(&addr),
sizeof(sockaddr_in6))); sizeof(sockaddr_in6)));
return none; socklen_t len = sizeof(sockaddr_in6);
CAF_NET_SYSCALL("getsockname", erro, !=, 0,
getsockname(x.id, reinterpret_cast<sockaddr*>(&addr), &len));
return addr.sin6_port;
} }
variant<size_t, sec> variant<size_t, sec>
......
...@@ -53,7 +53,7 @@ CAF_TEST_FIXTURE_SCOPE(udp_datagram_socket_test, fixture) ...@@ -53,7 +53,7 @@ CAF_TEST_FIXTURE_SCOPE(udp_datagram_socket_test, fixture)
CAF_TEST(send and receive) { CAF_TEST(send and receive) {
std::vector<byte> buf(1024); std::vector<byte> buf(1024);
ip_endpoint ep; ip_endpoint ep;
if (auto err = detail::parse("[::1]:55555", ep)) if (auto err = detail::parse("[::1]:0", ep))
CAF_FAIL("unable to parse input: " << err); CAF_FAIL("unable to parse input: " << err);
auto sender = unbox(make_socket()); auto sender = unbox(make_socket());
auto receiver = unbox(make_socket()); auto receiver = unbox(make_socket());
...@@ -61,8 +61,9 @@ CAF_TEST(send and receive) { ...@@ -61,8 +61,9 @@ CAF_TEST(send and receive) {
close(socket_cast<net::socket>(sender)); close(socket_cast<net::socket>(sender));
close(socket_cast<net::socket>(receiver)); close(socket_cast<net::socket>(receiver));
}); });
if (auto err = bind(receiver, ep)) auto port = unbox(bind(receiver, ep));
CAF_FAIL("unable to bind socket" << err); CAF_MESSAGE("socket bound to port " << port);
ep.port(htons(port));
if (nonblocking(socket_cast<net::socket>(receiver), true)) if (nonblocking(socket_cast<net::socket>(receiver), true))
CAF_FAIL("nonblocking failed"); CAF_FAIL("nonblocking failed");
auto test_read_res = read(receiver, make_span(buf)); auto test_read_res = read(receiver, make_span(buf));
......
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