Fix many MSVC auto tests failing due to WSAECONNRESET

This commit is contained in:
Robin Linden 2022-01-08 19:23:32 +01:00
parent d2ef514569
commit 091dc6c833
No known key found for this signature in database
GPG Key ID: 601A604B7E605776

View File

@ -107,7 +107,11 @@
#endif #endif
#if !defined(OS_WIN32) #if !defined(OS_WIN32)
#define TOX_EWOULDBLOCK EWOULDBLOCK
static bool should_ignore_recv_error(int err)
{
return err == EWOULDBLOCK;
}
static const char *inet_ntop4(const struct in_addr *addr, char *buf, size_t bufsize) static const char *inet_ntop4(const struct in_addr *addr, char *buf, size_t bufsize)
{ {
@ -134,7 +138,12 @@ static int inet_pton6(const char *addrString, struct in6_addr *addrbuf)
#define IPV6_V6ONLY 27 #define IPV6_V6ONLY 27
#endif #endif
#define TOX_EWOULDBLOCK WSAEWOULDBLOCK static bool should_ignore_recv_error(int err)
{
// We ignore WSAECONNRESET as Windows helpfully* sends that error if a
// previously sent UDP packet wasn't delivered.
return err == WSAEWOULDBLOCK || err == WSAECONNRESET;
}
static const char *inet_ntop4(const struct in_addr *addr, char *buf, size_t bufsize) static const char *inet_ntop4(const struct in_addr *addr, char *buf, size_t bufsize)
{ {
@ -596,7 +605,7 @@ static int receivepacket(const Logger *log, Socket sock, IP_Port *ip_port, uint8
if (fail_or_len < 0) { if (fail_or_len < 0) {
int error = net_error(); int error = net_error();
if (fail_or_len < 0 && error != TOX_EWOULDBLOCK) { if (fail_or_len < 0 && !should_ignore_recv_error(error)) {
const char *strerror = net_new_strerror(error); const char *strerror = net_new_strerror(error);
LOGGER_ERROR(log, "Unexpected error reading from socket: %u, %s", error, strerror); LOGGER_ERROR(log, "Unexpected error reading from socket: %u, %s", error, strerror);
net_kill_strerror(strerror); net_kill_strerror(strerror);