--- src/session.c	1.2.4
+++ src/session.c	patched
@@ -538,7 +538,17 @@ int _libssh2_wait_socket(LIBSSH2_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 (session->api_timeout > 0) {
+        struct timeval tv_timeout;
+        /* Seconds */
+        tv_timeout.tv_sec = session->api_timeout / 1000;
+        /* Microseconds */
+        tv_timeout.tv_usec = (session->api_timeout % 1000) * 1000;
+
+        rc = select(session->socket_fd + 1, readfd, writefd, NULL, &tv_timeout);
+    } else {
+        rc = select(session->socket_fd + 1, readfd, writefd, NULL, NULL);
+    }
 
     if(rc <= 0) {
         /* timeout (or error), bail out with a timeout error */
@@ -1234,6 +1244,27 @@ libssh2_session_get_blocking(LIBSSH2_SES
     return session->api_block_mode;
 }
 
+/* libssh2_session_set_timeout
+ *
+ * Set a session's timeout (in msec) for blocking mode, 
+ * or 0 to disable timeouts.
+ */
+LIBSSH2_API void
+libssh2_session_set_timeout(LIBSSH2_SESSION * session, long timeout)
+{
+    session->api_timeout = timeout;
+}
+
+/* libssh2_session_get_timeout
+ *
+ * Returns a session's timeout, or 0 if disabled
+ */
+LIBSSH2_API long
+libssh2_session_get_timeout(LIBSSH2_SESSION * session)
+{
+    return session->api_timeout;
+}
+
 /*
  * libssh2_poll_channel_read
  *


