Browse Source

Partial: Handle interruptions to various select calls in util.c

Conflicts:
	util.c
	util.h
Con Kolivas 12 years ago
parent
commit
c8b366fb4b
2 changed files with 13 additions and 2 deletions
  1. 5 2
      util.c
  2. 8 0
      util.h

+ 5 - 2
util.c

@@ -1574,11 +1574,14 @@ static enum send_ret __stratum_send(struct pool *pool, char *s, ssize_t len)
 		struct timeval timeout = {1, 0};
 		ssize_t sent;
 		fd_set wd;
-
+retry:
 		FD_ZERO(&wd);
 		FD_SET(sock, &wd);
-		if (select(sock + 1, NULL, &wd, NULL, &timeout) < 1)
+		if (select(sock + 1, NULL, &wd, NULL, &timeout) < 1) {
+			if (interrupted())
+				goto retry;
 			return SEND_SELECTFAIL;
+		}
 #ifdef __APPLE__
 		sent = send(pool->sock, s + ssent, len, SO_NOSIGPIPE);
 #elif WIN32

+ 8 - 0
util.h

@@ -43,6 +43,10 @@
 	{
 		return (errno == EAGAIN || errno == EWOULDBLOCK);
 	}
+	static inline bool interrupted(void)
+	{
+		return (errno == EINTR);
+	}
 #elif defined WIN32
 	#include <ws2tcpip.h>
 	#include <winsock2.h>
@@ -60,6 +64,10 @@
 	{
 		return (WSAGetLastError() == WSAEWOULDBLOCK);
 	}
+	static inline bool interrupted(void)
+	{
+		return (WSAGetLastError() == WSAEINTR);
+	}
 	#ifndef SHUT_RDWR
 	#define SHUT_RDWR SD_BOTH
 	#endif