Subject: Re: Blocking/non-blocking and session disconnect

Re: Blocking/non-blocking and session disconnect

From: Daniel Stenberg <>
Date: Sat, 26 May 2012 23:02:07 +0200 (CEST)

On Sat, 26 May 2012, Paulo Caetano wrote:

> while (libssh2_session_disconnect(session, "Normal Shutdown, Thank
> you for playing") == LIBSSH2_ERROR_EAGAIN)
> ;

While this works, I hesitate to add this kind of busy-looping into any
examples since it not a good piece of advice. It should rather use
waitsocket() first if LIBSSH2_ERROR_EAGAIN is returned, to avoid 100% CPU
usage during the EAGAIN phase.

> I've added no error cheking. Looking at session_disconnect() in session.c, I
> was left with the impression that it only returns an error if description
> (reason for disconnection) length > 256. Otherwise, it always returns either

Right now that might be true, but all functions that are documented to return
an error code may at some point return an actual error code. Even if the code
flow currently only allows for a single specific return code we may do changes
in the future that can introduce new codes or in some cases it might even have
done so in the past. Thus I don't think anyone should write code that assumes
a certain subset of error codes from a specific function unless that is
explicitly documented to be the only possible outcomes.

Received on 2012-05-26