aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2011-01-03 22:51:23 +0100
committerAndreas Schneider <asn@cryptomilk.org>2011-01-22 16:55:36 +0100
commit80ef7d93046cffe174e8a46706e2481f54e7a4aa (patch)
treee141651a01abf9899b7e5e5bf9fdbce79f481e9c
parent84df46f805779d172e281d0a523a3b0d290e6c45 (diff)
downloadlibssh-80ef7d93046cffe174e8a46706e2481f54e7a4aa.tar.gz
libssh-80ef7d93046cffe174e8a46706e2481f54e7a4aa.tar.xz
libssh-80ef7d93046cffe174e8a46706e2481f54e7a4aa.zip
Fix problem with ssh_connect w/ timeout &fd > 1024
Convert that code to ssh_poll (cherry picked from commit b1a65dd25f124bd7d78714b016e8c0e05fc7acd2)
-rw-r--r--src/connect.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/connect.c b/src/connect.c
index 5d04b3fa..ec0a2ca2 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -72,10 +72,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()"
@@ -209,29 +206,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;
ssh_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,
@@ -243,7 +246,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;