Subject: Re: How to detect ssh session shutdown

Re: How to detect ssh session shutdown

From: Henrik Nordström <henrik_at_henriknordstrom.net>
Date: Thu, 13 Oct 2011 04:54:52 +0200

ons 2011-10-12 klockan 17:08 -0700 skrev Pavel Strashkin:
> I don't want to open a new topic so i'll ask here.

Better to open a new topic when asing a new question.

> libssh2 has 2 entities: session and channel, but only channel has
> "eof" or "disconnected" states. I don't see something similar for
> session. The question then is how could i know that session is closed
> without creating a channel?

Normally you always open a channel immediately after the session have
been established. libssh2 currently do not support I/O activity on an
idle session (i.e. between auth and initial channel request) in a clean
manner.

How to detect session close depends on where you are in the SSH sequence

- Inital handshake, libssh2_session_handshake
- auth, libssh2_userauth_... (method dependent)
- channel, using channel I/O primitives or wrappers
- closing, libssh2_session_disconnect

which all returns errors if the transport socket got unexpectedly
closed.

> As i understand, when libssh2 does low-level reading (read or recv
> call) on file handle, it doesn't store information about read/recv
> returned zero bytes (connection closed) or errno value so such
> information can't be used by libssh2 user.

It stores it's own representation of these. The lowlevel transport
details is if very little relevance to the user of libssh2.

Regards
Henrik

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2011-10-13