Subject: Re: Detecting broken connection

Re: Detecting broken connection

From: Alexander Lamaison <swish_at_lammy.co.uk>
Date: Mon, 12 Jul 2010 15:53:10 +0100

On 12 July 2010 03:06, Neil Gierman <ngierman_at_roadrunn.com> wrote:
>> I keep a pool of connections open long-term.  Recently I've been using
>> them on wifi and realised that i don't handle broken sockets.  What's
>> the best way to do this so that I can resurrect stale sessions as
>> needed?  I want to test the connection somehow before issuing other
>> 'commands' e.g. libssh2_sftp_open_ex.  Currently these return some
>> arbitrary failure (such as "Unable to send FXP_OPEN*" which I can't
>> distinguish from other general errors making ti hard to know when to
>> resurrect the session and when to report a failure.
>>
>> Any advice is very welcome :)
>>
>
> I had this same problem and the only way I was able to address it was to
> move to non-blocking sockets and run select to see of the socket is happy.
> Most of what I did was from the non blocking examples in the source code.

How would non-blocking help here? As I understand it, if I use
non-blocking all I do is filter for EAGAIN in a loop. It doesn't
distinguish other errors from broken connection errors.

I'm not very familiar with select. What would the consequences be of
using it on a socket if libssh2 is in blocking mode?

Thanks.

Alex

--
Swish - Easy SFTP for Windows: http://www.swish-sftp.org
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-07-12