Commit b949a591 authored by Joseph Noir's avatar Joseph Noir

Fix UDP unit tests on Windows

parent 5af618ff
...@@ -184,6 +184,9 @@ expected<void> tcp_nodelay(native_socket fd, bool new_value); ...@@ -184,6 +184,9 @@ expected<void> tcp_nodelay(native_socket fd, bool new_value);
/// Enables or disables `SIGPIPE` events from `fd`. /// Enables or disables `SIGPIPE` events from `fd`.
expected<void> allow_sigpipe(native_socket fd, bool new_value); expected<void> allow_sigpipe(native_socket fd, bool new_value);
/// Enables or disables `SIO_UDP_CONNRESET`error on `fd`.
expected<void> allow_udp_connreset(native_socket fd, bool new_value);
/// Get the socket buffer size for `fd`. /// Get the socket buffer size for `fd`.
expected<int> send_buffer_size(native_socket fd); expected<int> send_buffer_size(native_socket fd);
......
...@@ -87,8 +87,8 @@ bool cc_valid_socket(caf::io::network::native_socket fd) { ...@@ -87,8 +87,8 @@ bool cc_valid_socket(caf::io::network::native_socket fd) {
return make_error(sec::network_syscall_failed, \ return make_error(sec::network_syscall_failed, \
fun_name, last_socket_error_as_string()) fun_name, last_socket_error_as_string())
// calls a C functions and calls exit() if `predicate(var)` returns false
#ifdef CAF_WINDOWS #ifdef CAF_WINDOWS
// calls a C functions and calls exit() if `predicate(var)` returns false
#define CALL_CRITICAL_CFUN(var, predicate, funname, expr) \ #define CALL_CRITICAL_CFUN(var, predicate, funname, expr) \
auto var = expr; \ auto var = expr; \
if (!predicate(var)) { \ if (!predicate(var)) { \
...@@ -96,6 +96,10 @@ bool cc_valid_socket(caf::io::network::native_socket fd) { ...@@ -96,6 +96,10 @@ bool cc_valid_socket(caf::io::network::native_socket fd) {
__FILE__, __LINE__, funname, last_socket_error_as_string().c_str());\ __FILE__, __LINE__, funname, last_socket_error_as_string().c_str());\
abort(); \ abort(); \
} static_cast<void>(0) } static_cast<void>(0)
#ifndef SIO_UDP_CONNRESET
#define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR, 12)
#endif
#endif // CAF_WINDOWS #endif // CAF_WINDOWS
} // namespace <anonymous> } // namespace <anonymous>
...@@ -132,6 +136,11 @@ namespace network { ...@@ -132,6 +136,11 @@ namespace network {
return unit; return unit;
} }
expected<void> allow_udp_connreset(native_socket, bool) {
// nop; SIO_UDP_CONNRESET only exists on Windows
return unit;
}
std::pair<native_socket, native_socket> create_pipe() { std::pair<native_socket, native_socket> create_pipe() {
int pipefds[2]; int pipefds[2];
if (pipe(pipefds) != 0) { if (pipe(pipefds) != 0) {
...@@ -178,6 +187,14 @@ namespace network { ...@@ -178,6 +187,14 @@ namespace network {
return unit; return unit;
} }
expected<void> allow_udp_connreset(native_socket fd, bool new_value) {
DWORD bytes_returned = 0;
CALL_CFUN(res, cc_zero, "WSAIoctl",
WSAIoctl(fd, SIO_UDP_CONNRESET, &new_value, sizeof(new_value),
NULL, 0, &bytes_returned, NULL, NULL));
return unit;
}
/**************************************************************************\ /**************************************************************************\
* Based on work of others; * * Based on work of others; *
* original header: * * original header: *
...@@ -1192,6 +1209,7 @@ datagram_handler::datagram_handler(default_multiplexer& backend_ref, ...@@ -1192,6 +1209,7 @@ datagram_handler::datagram_handler(default_multiplexer& backend_ref,
send_buffer_size_(0), send_buffer_size_(0),
ack_writes_(false), ack_writes_(false),
writing_(false) { writing_(false) {
allow_udp_connreset(sockfd, false);
auto es = send_buffer_size(sockfd); auto es = send_buffer_size(sockfd);
if (!es) if (!es)
CAF_LOG_ERROR("cannot determine socket buffer size"); CAF_LOG_ERROR("cannot determine socket buffer size");
......
...@@ -25,19 +25,26 @@ ...@@ -25,19 +25,26 @@
#include "caf/actor_system.hpp" #include "caf/actor_system.hpp"
#include "caf/actor_system_config.hpp" #include "caf/actor_system_config.hpp"
#include "caf/binary_serializer.hpp" #include "caf/binary_serializer.hpp"
#include "caf/binary_deserializer.hpp" #include "caf/binary_deserializer.hpp"
#include "caf/io/middleman.hpp"
#include "caf/io/network/interfaces.hpp" #include "caf/io/network/interfaces.hpp"
#include "caf/io/network/ip_endpoint.hpp" #include "caf/io/network/ip_endpoint.hpp"
using namespace caf; using namespace caf;
using namespace caf::io; using namespace caf::io;
namespace { namespace {
class config : public actor_system_config {
public:
config() {
// this will call WSAStartup for network initialization on Windows
load<io::middleman>();
}
};
struct fixture { struct fixture {
template <class T, class... Ts> template <class T, class... Ts>
...@@ -54,11 +61,11 @@ void deserialize(const std::vector<char>& buf, T& x, Ts&... xs) { ...@@ -54,11 +61,11 @@ void deserialize(const std::vector<char>& buf, T& x, Ts&... xs) {
bd(x, xs...); bd(x, xs...);
} }
fixture() : system(cfg), context(&system) { fixture() : cfg(), system(cfg), context(&system) {
} }
actor_system_config cfg; config cfg;
actor_system system; actor_system system;
scoped_execution_unit context; scoped_execution_unit context;
......
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