projects
/
tinc
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9523069
)
invitation.c: fix socket error checking on Windows
author
Kirill Isakov
<is-kir@ya.ru>
Mon, 5 Jul 2021 04:37:04 +0000
(10:37 +0600)
committer
Kirill Isakov
<is-kir@ya.ru>
Sat, 10 Jul 2021 15:18:14 +0000
(21:18 +0600)
src/invitation.c
patch
|
blob
|
history
src/utils.h
patch
|
blob
|
history
diff --git
a/src/invitation.c
b/src/invitation.c
index
2976968
..
30d100d
100644
(file)
--- a/
src/invitation.c
+++ b/
src/invitation.c
@@
-1076,7
+1076,7
@@
static bool invitation_send(void *handle, uint8_t type, const void *vdata, size_
while(len) {
int result = send(sock, data, len, 0);
while(len) {
int result = send(sock, data, len, 0);
- if(result == -1 &&
errno == EINTR
) {
+ if(result == -1 &&
sockwouldblock(sockerrno)
) {
continue;
} else if(result <= 0) {
return false;
continue;
} else if(result <= 0) {
return false;
@@
-1324,11
+1324,21
@@
next:
while((len = recv(sock, line, sizeof(line), 0))) {
if(len < 0) {
while((len = recv(sock, line, sizeof(line), 0))) {
if(len < 0) {
- if(
errno == EINTR
) {
+ if(
sockwouldblock(sockerrno)
) {
continue;
}
continue;
}
- fprintf(stderr, "Error reading data from %s port %s: %s\n", address, port, strerror(errno));
+#if HAVE_MINGW
+
+ // If socket has been shut down, recv() on Windows returns -1 and sets sockerrno
+ // to WSAESHUTDOWN, while on UNIX-like operating systems recv() returns 0, so we
+ // have to do an explicit check here.
+ if(sockshutdown(sockerrno)) {
+ break;
+ }
+
+#endif
+ fprintf(stderr, "Error reading data from %s port %s: %s\n", address, port, sockstrerror(sockerrno));
return 1;
}
return 1;
}
diff --git
a/src/utils.h
b/src/utils.h
index
4285150
..
25e8cc9
100644
(file)
--- a/
src/utils.h
+++ b/
src/utils.h
@@
-38,6
+38,7
@@
extern const char *winerror(int);
#define sockinprogress(x) ((x) == WSAEINPROGRESS || (x) == WSAEWOULDBLOCK)
#define sockinuse(x) ((x) == WSAEADDRINUSE)
#define socknotconn(x) ((x) == WSAENOTCONN)
#define sockinprogress(x) ((x) == WSAEINPROGRESS || (x) == WSAEWOULDBLOCK)
#define sockinuse(x) ((x) == WSAEADDRINUSE)
#define socknotconn(x) ((x) == WSAENOTCONN)
+#define sockshutdown(x) ((x) == WSAESHUTDOWN)
#else
#define sockerrno errno
#define sockstrerror(x) strerror(x)
#else
#define sockerrno errno
#define sockstrerror(x) strerror(x)