- 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));