Subject: Re: Setting timeout in blocking mode

Re: Setting timeout in blocking mode

From: Simon Josefsson <simon_at_josefsson.org>
Date: Tue, 09 Mar 2010 14:17:09 +0100

"Sebastien Fricker" <Sebastien.Fricker_at_ipetronik.com> writes:

> Hi,
> I'm currently wondering why there is now wait so specify a timeout when
> working on blocking mode.
>
> If we have a look on _libssh2_wait_socket() we can see that the select
> blocks infinitely, but there is a
> code which should handle the timeout.
>
> Code:
> /* Note that this COULD be made to use a timeout that perhaps could
> be
> customizable by the app or something... */
> rc = select(session->socket_fd + 1, readfd, writefd, NULL, NULL);
>
> if(rc <= 0) {
> /* timeout (or error), bail out with a timeout error */
> session->err_code = LIBSSH2_ERROR_TIMEOUT;
> return LIBSSH2_ERROR_TIMEOUT;
> }
>
> Is there any reason not to add a timeout parameter as follows?:
> rc = select(session->socket_fd + 1, readfd, writefd, NULL,
> session->timeout);
>
> This would only require to add 'timeout' into the session struct and to
> create a function API which permits to set its value.

The simplest solution is to do the select call in your application and
use libssh2 in non-blocking mode. If you don't want to risk libssh2
blocking forever in some situations, I believe you need to do this
anyway. This way your application has full control.

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