diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2011-01-03 22:51:23 +0100 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2011-01-03 22:51:23 +0100 |
commit | b1a65dd25f124bd7d78714b016e8c0e05fc7acd2 (patch) | |
tree | aa2acd84d98354099f2e211a25af3976b6259e62 | |
parent | e78cc89b521a040cfb506540ba8f5f031d76853f (diff) | |
download | libssh-b1a65dd25f124bd7d78714b016e8c0e05fc7acd2.tar.gz libssh-b1a65dd25f124bd7d78714b016e8c0e05fc7acd2.tar.xz libssh-b1a65dd25f124bd7d78714b016e8c0e05fc7acd2.zip |
Fix problem with ssh_connect w/ timeout &fd > 1024
Convert that code to ssh_poll
-rw-r--r-- | libssh/connect.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/libssh/connect.c b/libssh/connect.c index 811c5ddb..77b656f7 100644 --- a/libssh/connect.c +++ b/libssh/connect.c @@ -67,10 +67,7 @@ #include "libssh/socket.h" #include "libssh/channels.h" #include "libssh/session.h" - -#ifndef HAVE_SELECT -#error "Your system must have select()" -#endif +#include "libssh/poll.h" #ifndef HAVE_GETADDRINFO #error "Your system must have getaddrinfo()" @@ -202,29 +199,35 @@ static int getai(ssh_session session, const char *host, int port, struct addrinf static int ssh_connect_ai_timeout(ssh_session session, const char *host, int port, struct addrinfo *ai, long timeout, long usec, socket_t s) { - struct timeval to; - fd_set set; + int timeout_ms; + ssh_pollfd_t fds; int rc = 0; unsigned int len = sizeof(rc); enter_function(); - to.tv_sec = timeout; - to.tv_usec = usec; + /* I know we're losing some precision. But it's not like poll-like family + * type of mechanisms are precise up to the microsecond. + */ + timeout_ms=timeout * 1000 + usec / 1000; sock_set_nonblocking(s); ssh_log(session, SSH_LOG_RARE, "Trying to connect to host: %s:%d with " - "timeout %ld.%ld", host, port, timeout, usec); + "timeout %d ms", host, port, timeout_ms); /* The return value is checked later */ connect(s, ai->ai_addr, ai->ai_addrlen); freeaddrinfo(ai); - FD_ZERO(&set); - FD_SET(s, &set); + fds.fd=s; + fds.revents=0; + fds.events=POLLOUT; +#ifdef _WIN32 + fds.events |= POLLWRNORM; +#endif + rc = ssh_poll(&fds,1,timeout_ms); - rc = select(s + 1, NULL, &set, NULL, &to); if (rc == 0) { /* timeout */ ssh_set_error(session, SSH_FATAL, @@ -236,7 +239,7 @@ static int ssh_connect_ai_timeout(ssh_session session, const char *host, if (rc < 0) { ssh_set_error(session, SSH_FATAL, - "Select error: %s", strerror(errno)); + "poll error: %s", strerror(errno)); ssh_connect_socket_close(s); leave_function(); return -1; |