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;
while((len = recv(sock, line, sizeof(line), 0))) {
if(len < 0) {
- if(errno == EINTR) {
+ if(sockwouldblock(sockerrno)) {
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;
}
#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)