- Vlad Grachov brought the new function called

libssh2_session_block_directions() which returns a bitmask for what
  directions the connection blocks. It is to be used applications that use
  non-blocking sockets and when a libssh2 function returns
  LIBSSH2_ERROR_EAGAIN this function can be used to figure out in which
  direction the socket would block and thus it can wait for the socket to
  again be ready for communication in that direction before it calls libssh2
  again.
This commit is contained in:
Daniel Stenberg
2008-11-24 13:31:00 +00:00
parent 881b01e522
commit 160f89f42e
8 changed files with 52 additions and 9 deletions

View File

@@ -133,6 +133,8 @@ libssh2_banner_receive(LIBSSH2_SESSION * session)
}
#endif /* WIN32 */
if (errno == EAGAIN) {
session->socket_block_directions =
LIBSSH2_SESSION_BLOCK_INBOUND;
session->banner_TxRx_total_send = banner_len;
return PACKET_EAGAIN;
}
@@ -235,6 +237,8 @@ libssh2_banner_send(LIBSSH2_SESSION * session)
if (ret != (banner_len - session->banner_TxRx_total_send)) {
if ((ret > 0) || ((ret == -1) && (errno == EAGAIN))) {
/* the whole packet could not be sent, save the what was */
session->socket_block_directions =
LIBSSH2_SESSION_BLOCK_OUTBOUND;
session->banner_TxRx_total_send += ret;
return PACKET_EAGAIN;
}
@@ -1536,4 +1540,15 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
return active_fds;
}
/* {{{ libssh2_session_block_direction
* Get blocked direction when a function returns LIBSSH2_ERROR_EAGAIN
* Returns LIBSSH2_SOCKET_BLOCK_INBOUND if recv() blocked
* or LIBSSH2_SOCKET_BLOCK_OUTBOUND if send() blocked
*/
LIBSSH2_API int
libssh2_session_block_directions(LIBSSH2_SESSION *session)
{
return session->socket_block_directions;
}
/* }}} */