[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: example of a server

Finally, I've running a simple non-blocking ssh server. Valgrind has
found a memory leak in the libssh code. The attachment contains a
patch for 0.5.2 version fixing the leak. I cannot verify whether the
patch is applicable to the latest source code from the repo. The repo
behaves differently and I've got some other errors during the keys
exchange phase (probably).


On Mon, Apr 16, 2012 at 12:35 PM, Tomasz Mikolajczyk
<tmmikolajczyk@xxxxxxxxx> wrote:
> Hi,
> Recently I started investigation of the libssh capabilities. I
> analyzed tutorial and various examples but couldn't find a sufficient
> example how to implement a non-blocking SSH server. I would like to
> achieve the following:
> 1) listening on a TCP socket on a predefined port
> 2) When there is a new connection on the socket I assume that it is a
> new ssh client's connection. Then I would like to pass the socket fd
> to the libssh saying "handle this connection as the ssh connection".
> Is the following pseudo code correct in order to do that?:
> ssh_bind_struct* b = ssh_bind_new()
> ssh_bind_set_blocking(b, 0)
> ssh_bind_listen(b)
> TCPSocket tcp;
> select(tcp.fd);
> ssh_bind_set_fd(tcp.fd);
> ssh_session_struct* ses = ssh_new()
> ssh_bind_accept(b, ses)
> 3) In the next step I would like to wait on another select and handle
> SSH_REQUEST_CHANNEL and so on, but in the same time I would like to
> check/receive (in a non-blocking mode by waiting on the same select) a
> user-passed data. How to achieve that? The "ssh_message_get" is
> blocking so I cannot use it. I also found an example of
> reading/writing data using ssh_channel_read/ssh_channel_write
> functions, however the examples do not show how to receive user data
> (channel data) and in the same time handle messages such as
> pty-request.
> /Tomek

Attachment: mem_leak.diff
Description: Binary data

example of a serverTomasz Mikolajczyk <tmmikolajczyk@xxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org