diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-02-07 21:29:00 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-02-07 21:29:00 +0100 |
commit | 7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41 (patch) | |
tree | bfbaed36b7f81688d34ad4bca43d85f1ce182d25 /src/channel.c | |
parent | cb00f039332d3188931035e9d07144546fdea78a (diff) |
patch 7.4.1286v7.4.1286
Problem: ch_open() with a timeout doesn't work correctly.
Solution: Change how select() is used. Don't give an error on timeout.
Add a test for ch_open() failing.
Diffstat (limited to 'src/channel.c')
-rw-r--r-- | src/channel.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/channel.c b/src/channel.c index 1d12ee7224..8e36808a4b 100644 --- a/src/channel.c +++ b/src/channel.c @@ -431,18 +431,16 @@ channel_open(char *hostname, int port_in, int waittime, void (*close_cb)(void)) } } - if (waittime >= 0) + if (waittime >= 0 && ret < 0) { struct timeval tv; - fd_set rfds, wfds; + fd_set wfds; - FD_ZERO(&rfds); FD_ZERO(&wfds); - FD_SET(sd, &rfds); FD_SET(sd, &wfds); tv.tv_sec = waittime / 1000; tv.tv_usec = (waittime % 1000) * 1000; - ret = select((int)sd+1, &rfds, &wfds, NULL, &tv); + ret = select((int)sd + 1, NULL, &wfds, NULL, &tv); if (ret < 0) { SOCK_ERRNO; @@ -452,15 +450,16 @@ channel_open(char *hostname, int port_in, int waittime, void (*close_cb)(void)) sock_close(sd); return -1; } - if (!FD_ISSET(sd, &rfds) && !FD_ISSET(sd, &wfds)) + if (!FD_ISSET(sd, &wfds)) { - errno = ECONNREFUSED; - CHERROR("Cannot connect to port\n", ""); - PERROR(_("E902: Cannot connect to port")); + /* don't give an error, we just timed out. */ sock_close(sd); return -1; } + } + if (waittime >= 0) + { #ifdef _WIN32 val = 0; ioctlsocket(sd, FIONBIO, &val); |