less code duplication in the poll vs select code flows
libssh2_keepalive_send and libssh2_session_block_directions are now used outside of the #ifdef blocks.
Этот коммит содержится в:
родитель
79ee2f339e
Коммит
f514bcac53
@ -519,21 +519,22 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session)
|
|||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
int dir;
|
int dir;
|
||||||
#if HAVE_POLL
|
|
||||||
struct pollfd sockets[1];
|
|
||||||
int seconds_to_next;
|
int seconds_to_next;
|
||||||
|
|
||||||
rc = libssh2_keepalive_send (session, &seconds_to_next);
|
rc = libssh2_keepalive_send (session, &seconds_to_next);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
return rc;
|
return rc;
|
||||||
|
else {
|
||||||
|
/* figure out what to wait for */
|
||||||
|
dir = libssh2_session_block_directions(session);
|
||||||
|
|
||||||
|
#ifdef HAVE_POLL
|
||||||
|
struct pollfd sockets[1];
|
||||||
|
|
||||||
sockets[0].fd = session->socket_fd;
|
sockets[0].fd = session->socket_fd;
|
||||||
sockets[0].events = 0;
|
sockets[0].events = 0;
|
||||||
sockets[0].revents = 0;
|
sockets[0].revents = 0;
|
||||||
|
|
||||||
/* now make sure we wait in the correct direction */
|
|
||||||
dir = libssh2_session_block_directions(session);
|
|
||||||
|
|
||||||
if(dir & LIBSSH2_SESSION_BLOCK_INBOUND)
|
if(dir & LIBSSH2_SESSION_BLOCK_INBOUND)
|
||||||
sockets[0].events |= POLLIN;
|
sockets[0].events |= POLLIN;
|
||||||
|
|
||||||
@ -546,11 +547,6 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session)
|
|||||||
fd_set *writefd = NULL;
|
fd_set *writefd = NULL;
|
||||||
fd_set *readfd = NULL;
|
fd_set *readfd = NULL;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int seconds_to_next;
|
|
||||||
|
|
||||||
rc = libssh2_keepalive_send (session, &seconds_to_next);
|
|
||||||
if (rc < 0)
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
tv.tv_sec = seconds_to_next;
|
tv.tv_sec = seconds_to_next;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
@ -558,9 +554,6 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session)
|
|||||||
FD_ZERO(&fd);
|
FD_ZERO(&fd);
|
||||||
FD_SET(session->socket_fd, &fd);
|
FD_SET(session->socket_fd, &fd);
|
||||||
|
|
||||||
/* now make sure we wait in the correct direction */
|
|
||||||
dir = libssh2_session_block_directions(session);
|
|
||||||
|
|
||||||
if(dir & LIBSSH2_SESSION_BLOCK_INBOUND)
|
if(dir & LIBSSH2_SESSION_BLOCK_INBOUND)
|
||||||
readfd = &fd;
|
readfd = &fd;
|
||||||
|
|
||||||
@ -572,6 +565,7 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session)
|
|||||||
rc = select(session->socket_fd + 1, readfd, writefd, NULL,
|
rc = select(session->socket_fd + 1, readfd, writefd, NULL,
|
||||||
seconds_to_next ? &tv : NULL);
|
seconds_to_next ? &tv : NULL);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if(rc <= 0) {
|
if(rc <= 0) {
|
||||||
/* timeout (or error), bail out with a timeout error */
|
/* timeout (or error), bail out with a timeout error */
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user