Skip to content

Commit

Permalink
save/restore errno before ws2warn, too
Browse files Browse the repository at this point in the history
  • Loading branch information
mirabilos committed Apr 14, 2023
1 parent cb508d0 commit 3426491
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 42 deletions.
21 changes: 3 additions & 18 deletions ws2/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,41 +173,26 @@ do_resolve(const char *host, const char *service)

if ((s = socket(ap->ai_family, ap->ai_socktype,
ap->ai_protocol)) == INVALID_SOCKET) {
#if defined(_WIN32) || defined(WIN32)
putc('\n', stderr);
ws2warn("socket");
#else
i = errno;
putc('\n', stderr);
errno = i;
warn("socket");
#endif
ws2warn("socket");
continue;
}
if (ECNBITS_PREP_FATAL(ecnbits_prep(s, ap->ai_family))) {
#if defined(_WIN32) || defined(WIN32)
putc('\n', stderr);
ws2warn("ecnbits_setup: incoming traffic class");
#else
i = errno;
putc('\n', stderr);
errno = i;
warn("ecnbits_setup: incoming traffic class");
#endif
ws2warn("ecnbits_setup: incoming traffic class");
closesocket(s);
continue;
}

if (connect(s, ap->ai_addr, ap->ai_addrlen)) {
#if defined(_WIN32) || defined(WIN32)
putc('\n', stderr);
ws2warn("connect");
#else
i = errno;
putc('\n', stderr);
errno = i;
warn("connect");
#endif
ws2warn("connect");
closesocket(s);
continue;
}
Expand Down
28 changes: 4 additions & 24 deletions ws2/server/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,60 +237,40 @@ do_resolve(const char *host, const char *service)

if ((s = socket(ap->ai_family, ap->ai_socktype,
ap->ai_protocol)) == INVALID_SOCKET) {
#if defined(_WIN32) || defined(WIN32)
putc('\n', stderr);
ws2warn("socket");
#else
i = errno;
putc('\n', stderr);
errno = i;
warn("socket");
#endif
ws2warn("socket");
continue;
}

#ifdef ECNBITS_REUSEPORT
i = 1;
if (setsockopt(s, SOL_SOCKET, ECNBITS_REUSEPORT,
(const void *)&i, sizeof(i))) {
#if defined(_WIN32) || defined(WIN32)
putc('\n', stderr);
ws2warn("setsockopt");
#else
i = errno;
putc('\n', stderr);
errno = i;
warn("setsockopt");
#endif
ws2warn("setsockopt");
closesocket(s);
continue;
}
#endif

if (ECNBITS_PREP_FATAL(ecnbits_prep(s, ap->ai_family))) {
#if defined(_WIN32) || defined(WIN32)
putc('\n', stderr);
ws2warn("ecnbits_setup: incoming traffic class");
#else
i = errno;
putc('\n', stderr);
errno = i;
warn("ecnbits_setup: incoming traffic class");
#endif
ws2warn("ecnbits_setup: incoming traffic class");
closesocket(s);
continue;
}

if (bind(s, ap->ai_addr, ap->ai_addrlen)) {
#if defined(_WIN32) || defined(WIN32)
putc('\n', stderr);
ws2warn("bind");
#else
i = errno;
putc('\n', stderr);
errno = i;
warn("bind");
#endif
ws2warn("bind");
closesocket(s);
continue;
}
Expand Down

0 comments on commit 3426491

Please sign in to comment.