From 095e9e7b3e340446fd7cb050c736d1ac480baefe Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 9 Nov 2010 13:07:15 +0100 Subject: [PATCH] _libssh2_wait_socket: detect nothing-to-wait-for If _libssh2_wait_socket() gets called but there's no direction set to wait for, this causes a "hang". This code now detects this situation, set a 1 second timeout instead and outputs a debug output about it. --- src/session.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/session.c b/src/session.c index 716c0b7..e8798f5 100644 --- a/src/session.c +++ b/src/session.c @@ -559,6 +559,14 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session) /* figure out what to wait for */ dir = libssh2_session_block_directions(session); + if(!dir) { + _libssh2_debug(session, LIBSSH2_TRACE_SOCKET, + "Nothing to wait for in wait_socket"); + /* To avoid that we hang below just because there's nothing set to + wait for, we timeout on 1 second to also avoid busy-looping + during this condition */ + seconds_to_next = 1; + } { #ifdef HAVE_POLL struct pollfd sockets[1];