mike-jumper commented on code in PR #643:
URL: https://github.com/apache/guacamole-server/pull/643#discussion_r2980049119


##########
src/libguac/socket-wsa.c:
##########
@@ -134,7 +136,10 @@ static ssize_t guac_socket_wsa_read_handler(guac_socket* 
socket,
     guac_socket_wsa_data* data = (guac_socket_wsa_data*) socket->data;
 
     /* Read from socket */
-    int retval = recv(data->sock, buf, count, 0);
+    int retval;
+    do {
+        retval = recv(data->sock, buf, count, 0);
+    } while (retval < 0 && WSAGetLastError() == WSAEINTR);

Review Comment:
   This should be a `GUAC_RETRY_UNTIL()`.



##########
src/libguac/tcp.c:
##########
@@ -97,20 +97,33 @@ int guac_tcp_connect(const char* hostname, const char* 
port, const int timeout)
             continue;
         }
 
-        /* Structure that stores our timeout setting. */
+        /* Structure that stores our timeout setting. On Linux, select() 
updates
+           timeout with the remaining time on EINTR, so no need to 
reinitialize on
+           retry. */
         struct timeval tv;
         tv.tv_sec = timeout;
         tv.tv_usec = 0;
 
         /* Connect and wait for timeout */
         if ((retval = connect(fd, current_address->ai_addr, 
current_address->ai_addrlen)) < 0) {
-            if (errno == EINPROGRESS) {
-                /* Set up timeout. */
+            /* If connect() is in progress (EINPROGRESS) or interrupted by a 
signal
+             * (EINTR), wait for the socket to become writable and check 
SO_ERROR. */
+            if (errno == EINPROGRESS || errno == EINTR) {
+
+                /* Prevent overflowing fd_set. */
+                if (fd >= FD_SETSIZE) {
+                    guac_error = GUAC_STATUS_INVALID_ARGUMENT;
+                    guac_error_message = "File descriptor exceeds FD_SETSIZE.";
+                    close(fd);
+                    fd = -1;
+                    continue;
+                }
+
                 fd_set fdset;
                 FD_ZERO(&fdset);
                 FD_SET(fd, &fdset);
-                
-                retval = select(fd + 1, NULL, &fdset, NULL, &tv);
+
+                GUAC_RETRY_EINTR(retval, select(fd + 1, NULL, &fdset, NULL, 
&tv));

Review Comment:
   Does the `fd_set` need to be reinitialized here before each retry? (Possibly 
same with the `struct timeval`?)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to