wait_socket: make c89 compliant and use two fd_sets for select()
Этот коммит содержится в:
родитель
8ab009c0b0
Коммит
2f9c105ec2
@ -528,6 +528,7 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session)
|
|||||||
/* figure out what to wait for */
|
/* figure out what to wait for */
|
||||||
dir = libssh2_session_block_directions(session);
|
dir = libssh2_session_block_directions(session);
|
||||||
|
|
||||||
|
{
|
||||||
#ifdef HAVE_POLL
|
#ifdef HAVE_POLL
|
||||||
struct pollfd sockets[1];
|
struct pollfd sockets[1];
|
||||||
|
|
||||||
@ -543,7 +544,8 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session)
|
|||||||
|
|
||||||
rc = poll(sockets, 1, seconds_to_next ? seconds_to_next / 1000 : -1);
|
rc = poll(sockets, 1, seconds_to_next ? seconds_to_next / 1000 : -1);
|
||||||
#else
|
#else
|
||||||
fd_set fd;
|
fd_set rfd;
|
||||||
|
fd_set wfd;
|
||||||
fd_set *writefd = NULL;
|
fd_set *writefd = NULL;
|
||||||
fd_set *readfd = NULL;
|
fd_set *readfd = NULL;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
@ -551,21 +553,25 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session)
|
|||||||
tv.tv_sec = seconds_to_next;
|
tv.tv_sec = seconds_to_next;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
FD_ZERO(&fd);
|
if(dir & LIBSSH2_SESSION_BLOCK_INBOUND) {
|
||||||
FD_SET(session->socket_fd, &fd);
|
FD_ZERO(&rfd);
|
||||||
|
FD_SET(session->socket_fd, &rfd);
|
||||||
|
readfd = &rfd;
|
||||||
|
}
|
||||||
|
|
||||||
if(dir & LIBSSH2_SESSION_BLOCK_INBOUND)
|
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) {
|
||||||
readfd = &fd;
|
FD_ZERO(&wfd);
|
||||||
|
FD_SET(session->socket_fd, &wfd);
|
||||||
|
writefd = &wfd;
|
||||||
|
}
|
||||||
|
|
||||||
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
/* Note that this COULD be made to use a timeout that perhaps
|
||||||
writefd = &fd;
|
could be customizable by the app or something... */
|
||||||
|
|
||||||
/* 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,
|
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