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> {
};
/// 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);
/// Receives data from `x`.
......@@ -68,7 +68,9 @@ variant<size_t, sec> write(udp_datagram_socket x, span<const byte> buf,
/// Binds given socket to given ip_endpoint.
/// @param x the socket that 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
/// 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,
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);
CAF_NET_SYSCALL("bind", err, !=, 0,
::bind(x.id, reinterpret_cast<sockaddr*>(&addr),
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>
......
......@@ -53,7 +53,7 @@ CAF_TEST_FIXTURE_SCOPE(udp_datagram_socket_test, fixture)
CAF_TEST(send and receive) {
std::vector<byte> buf(1024);
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);
auto sender = unbox(make_socket());
auto receiver = unbox(make_socket());
......@@ -61,8 +61,9 @@ CAF_TEST(send and receive) {
close(socket_cast<net::socket>(sender));
close(socket_cast<net::socket>(receiver));
});
if (auto err = bind(receiver, ep))
CAF_FAIL("unable to bind socket" << err);
auto port = unbox(bind(receiver, ep));
CAF_MESSAGE("socket bound to port " << port);
ep.port(htons(port));
if (nonblocking(socket_cast<net::socket>(receiver), true))
CAF_FAIL("nonblocking failed");
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