Skip to content

Commit 091dc6c

Browse files
committed
Fix many MSVC auto tests failing due to WSAECONNRESET
1 parent d2ef514 commit 091dc6c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

toxcore/network.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@
107107
#endif
108108

109109
#if !defined(OS_WIN32)
110-
#define TOX_EWOULDBLOCK EWOULDBLOCK
110+
111+
static bool should_ignore_recv_error(int err)
112+
{
113+
return err == EWOULDBLOCK;
114+
}
111115

112116
static const char *inet_ntop4(const struct in_addr *addr, char *buf, size_t bufsize)
113117
{
@@ -134,7 +138,12 @@ static int inet_pton6(const char *addrString, struct in6_addr *addrbuf)
134138
#define IPV6_V6ONLY 27
135139
#endif
136140

137-
#define TOX_EWOULDBLOCK WSAEWOULDBLOCK
141+
static bool should_ignore_recv_error(int err)
142+
{
143+
// We ignore WSAECONNRESET as Windows helpfully* sends that error if a
144+
// previously sent UDP packet wasn't delivered.
145+
return err == WSAEWOULDBLOCK || err == WSAECONNRESET;
146+
}
138147

139148
static const char *inet_ntop4(const struct in_addr *addr, char *buf, size_t bufsize)
140149
{
@@ -596,7 +605,7 @@ static int receivepacket(const Logger *log, Socket sock, IP_Port *ip_port, uint8
596605
if (fail_or_len < 0) {
597606
int error = net_error();
598607

599-
if (fail_or_len < 0 && error != TOX_EWOULDBLOCK) {
608+
if (fail_or_len < 0 && !should_ignore_recv_error(error)) {
600609
const char *strerror = net_new_strerror(error);
601610
LOGGER_ERROR(log, "Unexpected error reading from socket: %u, %s", error, strerror);
602611
net_kill_strerror(strerror);

0 commit comments

Comments
 (0)