--- libssh2-0.12/src/packet.c 2006-01-30 18:27:07.000000000 +0100 +++ libssh2-0.12-ced/src/packet.c 2006-02-01 15:50:36.000000000 +0100 @@ -744,10 +744,36 @@ if (should_block) { read_len = libssh2_blocking_read(session, block, blocksize); } else { +#ifdef HAVE_SELECT + fd_set read_socket; + struct timeval timeout; + int retval; + + FD_ZERO(&read_socket); + FD_SET(session->socket_fd, &read_socket); + + timeout.tv_sec = 0; + timeout.tv_usec = 0; + + retval = select(session->socket_fd + 1, &read_socket, NULL, NULL, &timeout); + + if (retval <= 0) + return 0; +#endif read_len = recv(session->socket_fd, block, 1, LIBSSH2_SOCKET_RECV_FLAGS(session)); +#ifdef HAVE_SELECT + /*The return value will be 0 when the peer has performed an orderly shutdown */ + if (read_len == 0) { + session->socket_state = LIBSSH2_SOCKET_DISCONNECTED; + return 0; + } + else if (read_len < 0) + return -1; +#else if (read_len <= 0) { return 0; } +#endif read_len += libssh2_blocking_read(session, block + read_len, blocksize - read_len); } if (read_len < blocksize) { @@ -1176,3 +1202,4 @@ } } /* }}} */ +