[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Creating a session with a pre-connected socket in 0.5.2
[Thread Prev] | [Thread Next]
- Subject: Re: Creating a session with a pre-connected socket in 0.5.2
- From: Werner Koch <wk@xxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Thu, 20 Sep 2012 13:30:18 +0200
- To: libssh@xxxxxxxxxx
On Sat, 25 Aug 2012 11:38, aris@xxxxxxxxxxxx said: > You are right. We changed the socket handling internals a lot in 0.5 and > adding a pre-connected socket does not set libssh in the good states. > I'll check out today, I think this should be a one-liner. I ran into the same problem today. Find below a patch against 0.5.2. I tested it using using a modified Debian package and ported the changes later to git. Salam-Shalom, Werner
From 4ce7a154161c933a9e99609cf0abc25a42c8b13c Mon Sep 17 00:00:00 2001 From: Werner Koch <wk@xxxxxxxxx> Date: Thu, 20 Sep 2012 13:17:52 +0200 Subject: [PATCH] Fix regression in pre-connected socket setting. * src/socket.c (ssh_socket_pollcallback): Factor some code out to ... (ssh_socket_set_connecting): New. * include/libssh/socket.h (ssh_socket_set_connecting): Add prototype. * src/client.c (ssh_connect): Use new function for a socket set by SSH_OPTIONS_FD. Signed-off-by: Werner Koch <wk@xxxxxxxxx> --- include/libssh/socket.h | 1 + src/client.c | 2 +- src/socket.c | 27 ++++++++++++++++++++------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/libssh/socket.h b/include/libssh/socket.h index 527f52e..c95a2c6 100644 --- a/include/libssh/socket.h +++ b/include/libssh/socket.h @@ -62,6 +62,7 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd, int r struct ssh_poll_handle_struct * ssh_socket_get_poll_handle_in(ssh_socket s); struct ssh_poll_handle_struct * ssh_socket_get_poll_handle_out(ssh_socket s); +void ssh_socket_set_connecting(ssh_socket s, socket_t fd); int ssh_socket_connect(ssh_socket s, const char *host, int port, const char *bind_addr); #endif /* SOCKET_H_ */ diff --git a/src/client.c b/src/client.c index 060f20a..02ccb50 100644 --- a/src/client.c +++ b/src/client.c @@ -664,7 +664,7 @@ int ssh_connect(ssh_session session) { session->socket_callbacks.exception=ssh_socket_exception_callback; session->socket_callbacks.userdata=session; if (session->fd != SSH_INVALID_SOCKET) { - ssh_socket_set_fd(session->socket, session->fd); + ssh_socket_set_connecting(session->socket, session->fd); ret=SSH_OK; #ifndef _WIN32 } else if (session->ProxyCommand != NULL){ diff --git a/src/socket.c b/src/socket.c index 062739a..7eb080f 100644 --- a/src/socket.c +++ b/src/socket.c @@ -701,6 +701,25 @@ int ssh_socket_get_status(ssh_socket s) { return r; } + +/** + * @internal + * @brief Set a socket into the connecting state + * @param s socket handle + * @param fd file descriptor + */ + +void ssh_socket_set_connecting(ssh_socket s, int fd){ + 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 +} + + /** * @internal * @brief Launches a socket connection @@ -729,13 +748,7 @@ int ssh_socket_connect(ssh_socket s, const char *host, int port, const char *bin ssh_log(session,SSH_LOG_PROTOCOL,"Nonblocking connection socket: %d",fd); 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 + ssh_socket_set_connecting(s,fd); leave_function(); return SSH_OK; } -- 1.7.7.1
-- Die Gedanken sind frei. Ausnahmen regelt ein Bundesgesetz.
Re: Creating a session with a pre-connected socket in 0.5.2 | Andreas Schneider <asn@xxxxxxxxxxxxxx> |