Unverified Commit 2c95a660 authored by Dominik Charousset's avatar Dominik Charousset Committed by GitHub

Merge pull request #648

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