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

Re: Blocking/non-blocking and session disconnect

From: Daniel Stenberg <daniel_at_haxx.se>
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
> LIBSSH2_ERROR_EAGAIN or 0.

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.

-- 
  / daniel.haxx.se
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2012-05-26