diff --git a/src/session.c b/src/session.c
index 92109b4..7628f0d 100644
--- a/src/session.c
+++ b/src/session.c
@@ -501,7 +501,7 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session)
     fd_set *writefd = NULL;
     fd_set *readfd = NULL;
     int dir;
-    int rc;
+    int rc = 0;
 
     FD_ZERO(&fd);
     FD_SET(session->socket_fd, &fd);
@@ -517,7 +517,8 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session)
 
     /* Note that this COULD be made to use a timeout that perhaps could be
        customizable by the app or something... */
-    rc = select(session->socket_fd + 1, readfd, writefd, NULL, NULL);
+    if(readfd || writefd)
+        rc = select(session->socket_fd + 1, readfd, writefd, NULL, NULL);
 
     if(rc <= 0) {
         /* timeout (or error), bail out with a timeout error */

