aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-11-15 08:47:58 +0100
committerAndreas Schneider <asn@cryptomilk.org>2013-11-15 08:54:18 +0100
commit2bbeebd5056dcc1e06b386ba3d8e561ca7716eaf (patch)
treed523d86a890073432280054251637581c08087ca /src
parentfef32b4c147afa83cfe10072f961318d4dc91ebe (diff)
downloadlibssh-2bbeebd5056dcc1e06b386ba3d8e561ca7716eaf.tar.gz
libssh-2bbeebd5056dcc1e06b386ba3d8e561ca7716eaf.tar.xz
libssh-2bbeebd5056dcc1e06b386ba3d8e561ca7716eaf.zip
socket: Fix connect if we pass in a fd.
BUG: https://red.libssh.org/issues/106 Thanks to Saju Panikulam.
Diffstat (limited to 'src')
-rw-r--r--src/socket.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/socket.c b/src/socket.c
index d7cf5397..fcf52025 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -449,9 +449,19 @@ void ssh_socket_close(ssh_socket s){
* file descriptors
*/
void ssh_socket_set_fd(ssh_socket s, socket_t fd) {
- s->fd_in = s->fd_out = fd;
- if(s->poll_in)
- ssh_poll_set_fd(s->poll_in,fd);
+ s->fd_in = s->fd_out = fd;
+
+ if (s->poll_in) {
+ ssh_poll_set_fd(s->poll_in,fd);
+ } else {
+ s->state = SSH_SOCKET_CONNECTING;
+
+ /* POLLOUT is the event to wait for in a nonblocking connect */
+ ssh_poll_set_events(ssh_socket_get_poll_handle_in(s), POLLOUT);
+#ifdef _WIN32
+ ssh_poll_add_events(ssh_socket_get_poll_handle_in(s), POLLWRNORM);
+#endif
+ }
}
/**
@@ -770,12 +780,6 @@ int ssh_socket_connect(ssh_socket s, const char *host, int port, const char *bin
if(fd == SSH_INVALID_SOCKET)
return SSH_ERROR;
ssh_socket_set_fd(s,fd);
- s->state=SSH_SOCKET_CONNECTING;
- /* POLLOUT is the event to wait for in a nonblocking connect */
- ssh_poll_set_events(ssh_socket_get_poll_handle_in(s),POLLOUT);
-#ifdef _WIN32
- ssh_poll_add_events(ssh_socket_get_poll_handle_in(s),POLLWRNORM);
-#endif
return SSH_OK;
}