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

Re: Questions on threading and networking


On Monday, July 8, 2019 11:17:12 PM CEST Brian Hassink wrote:
> Hi,

Hi Brian,

> I'm brand new to libssh, and trying to understand if it can fit into my use
> case.
> 
> I have an application that runs in a Docker container, and would like to
> embed an SSH server within that application in order to access its Command
> Line Interface (CLI). The application has a specific threading and
> networking model based on ASIO, and I'm trying to determine whether libssh
> can integrate with this model.
> 
> I did see that libssh will accept a socket descriptor from an external
> source, meaning I can provide my own listener.

that's correct.

> But does this mean that
> libssh takes ownership of the socket and associated i/o on it, presumably
> under its own thread, rather than accepting/providing data from/to the
> application on socket read/write events?

libssh will take the ownership and of the socket. However you have control 
over the the accept function libssh provides. This means you can spawn a new 
thread for each incoming connection called a session. One thread per session. 
However we normally suggest to use a prefork model or prefork with threads so 
if there is a crash it won't take down the whole server.

> A good example of the model I'm after is the nghttp2 library, which provides
> an HTTP/2.0 implementation that is fully decoupled from the networking.
> Buffers are passed back and forth via API calls and callbacks between the
> library and the application, allowing the application to manage the
> threading and networking.

You can manage the threading/forking and accepting new connections but not the 
networking.

https://git.libssh.org/projects/libssh.git/tree/examples/ssh_server_fork.c


Best regards,


	Andreas


-- 
Andreas Schneider                 asn@xxxxxxxxxxxxxx
GPG-ID:     8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D



References:
Questions on threading and networkingBrian Hassink <brian.hassink@xxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org