Subject: Re: Force deallocate all resources within session

Re: Force deallocate all resources within session

From: Anton Obukhov <anton_at_ubnt.com>
Date: Sun, 3 Mar 2013 16:29:48 +0400

>> Hi, I'm having the following scenario: I manage a bunch of remote
devices,
>> and some of them may sit on a bad connection. Whenever I detect that the
>> connection is unsatisfactory, I want to shutdown all the channels,
session
>> and resources, linked to the session.
>>
>> The problem is - if say the device went down, all the functions
(including
>> libssh2_session_free) return EAGAIN, and I seem to leak a lot of
resources
>> if I keep it as is... So now all I do is I close the socket linked to the
>> session. What I'd like to do is to tell libssh to force close &
deallocate a
>> selected resource (channel, session, etc). Is there a way for it?

> You seem to be using the API in non-blocking mode but not using the
> functions in a non-blocking way.
>
> EAGAIN means that libssh2 hasn't finished executing the API call but
> is returning to let you know so that you can update you UI, or
> whatever, before *calling the same API again* with the same arguments.
> Keep calling this API until you get something other than EAGAIN. All
> libssh2 functions should be called this way in non-blocking mode.
>
> Alternatively, put libssh2 into blocking mode and forget all about the
above.
>
> Alex

>
Thanks for your suggestion Alex, but I'm using the non-blocking API exactly
as you advised: I call libssh2_session_free with the same paramerters
until either it returns something different than EAGAIN, or the timeout
happens. In my case, when the remote device goes down ungracefully, any
amount of seconds wait will result in timeout: I even tried 15 seconds. I
suppose resource destruction should be instant. It looks like libssh is
waiting for something inside there, whereas I want it to just free all
resources...

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2013-03-03