Resume on interrupted syscalls
diff --git a/common/sockets.cpp b/common/sockets.cpp
index 5e66994..19ba7d2 100644
--- a/common/sockets.cpp
+++ b/common/sockets.cpp
@@ -5,6 +5,9 @@
 #ifndef _WIN32
 void WSACleanup() {}
 int WSAGetLastError() { return errno; }
+int wasInterrupted() { return errno == EINTR; }
+#else
+int wasInterrupted() { return 0; }
 #endif
 
 void CloseSockets( SOCKET otherSock, SOCKET tpmSock)
@@ -22,7 +25,13 @@
     for( bytesRead = 0, length = len; bytesRead != len; length -= iResult, bytesRead += iResult )
     {
         iResult = recv( tpmSock, (char *)&( data[bytesRead] ), length, 0);
-        if ((iResult == SOCKET_ERROR) || (!iResult))
+        if (iResult == SOCKET_ERROR)
+        {
+            if (wasInterrupted())
+                continue;
+            return TSS2_TCTI_RC_IO_ERROR;
+        }
+        else if (!iResult)
             return TSS2_TCTI_RC_IO_ERROR;
     }
 
@@ -38,7 +47,12 @@
     {
         iResult = send( tpmSock, (char *)data, len, MSG_NOSIGNAL );
         if (iResult == SOCKET_ERROR)
-            return TSS2_TCTI_RC_IO_ERROR;
+        {
+            if (wasInterrupted())
+                continue;
+            else
+                return TSS2_TCTI_RC_IO_ERROR;
+        }
     }
 
     return TSS2_RC_SUCCESS;