Re: [Bug-wget] gnutls_handshake can return GNUTLS_E_INTERRUPTED

2016-06-30 Thread Tim Ruehsen
Thanks, Daniel.

I believe, we already handle that case.
If GNUTLS_E_INTERRUPTED occurs, we restart the loop and re-enter 
gnutls_handshake(). This happens for all non-fatal errors.

That is the while part
while (err && gnutls_error_is_fatal (err) == 0);

Tim

On Thursday 30 June 2016 15:18:18 Daniel Stenberg wrote:
> Hello,
> 
> gnutls_handshake() is documented to possibly return GNUTLS_E_INTERRUPTED as
> well as GNUTLS_E_AGAIN and should probably behave similarly for both return
> codes within wget.
> 
> diff --git a/src/gnutls.c b/src/gnutls.c
> index 63c7c33..44c497b 100644
> --- a/src/gnutls.c
> +++ b/src/gnutls.c
> @@ -463,11 +463,11 @@ _do_handshake (gnutls_session_t session, int fd,
> double timeout)
> /* We don't stop the handshake process for non-fatal errors */
> do
>   {
> err = gnutls_handshake (session);
> 
> -  if (timeout && err == GNUTLS_E_AGAIN)
> +  if (timeout && ((err == GNUTLS_E_AGAIN) || (err ==
> GNUTLS_E_INTERRUPTED))) {
> if (gnutls_record_get_direction (session))
>   {
> /* wait for writeability */
> err = select_fd (fd, timeout, WAIT_FOR_WRITE);

signature.asc
Description: This is a digitally signed message part.


Re: [Bug-wget] gnutls_handshake can return GNUTLS_E_INTERRUPTED

2016-06-30 Thread Daniel Stenberg

On Thu, 30 Jun 2016, Tim Ruehsen wrote:

I believe, we already handle that case. If GNUTLS_E_INTERRUPTED occurs, we 
restart the loop and re-enter gnutls_handshake(). This happens for all 
non-fatal errors.


Right, but then it won't wait for the socket and just busy-loop. The 
gnutls_record_get_direction man page[*] seems to suggest that waiting for the 
socket is the appropriate way:


 This function provides information about the internals of the record protocol
 and is only useful if a prior gnutls function call (e.g. gnutls_handshake())
 was interrupted for some reason, that is, if a function returned
 GNUTLS_E_INTERRUPTED or GNUTLS_E_AGAIN. In such a case, you might want to
 call select() or poll() before calling the interrupted gnutls function again

[*] = http://linux.die.net/man/3/gnutls_record_get_direction

--

 / daniel.haxx.se



Re: [Bug-wget] gnutls_handshake can return GNUTLS_E_INTERRUPTED

2016-07-01 Thread Tim Ruehsen
On Thursday 30 June 2016 17:18:36 Daniel Stenberg wrote:
> On Thu, 30 Jun 2016, Tim Ruehsen wrote:
> > I believe, we already handle that case. If GNUTLS_E_INTERRUPTED occurs, we
> > restart the loop and re-enter gnutls_handshake(). This happens for all
> > non-fatal errors.
> 
> Right, but then it won't wait for the socket and just busy-loop. The
> gnutls_record_get_direction man page[*] seems to suggest that waiting for
> the socket is the appropriate way:
> 
>   This function provides information about the internals of the record
> protocol and is only useful if a prior gnutls function call (e.g.
> gnutls_handshake()) was interrupted for some reason, that is, if a function
> returned GNUTLS_E_INTERRUPTED or GNUTLS_E_AGAIN. In such a case, you might
> want to call select() or poll() before calling the interrupted gnutls
> function again
> 
> [*] = http://linux.die.net/man/3/gnutls_record_get_direction

GNUTLS_E_INTERRUPTED is returned if the process got a signal that interrupts 
blocking I/O (for wget this is SIGUSR1 and SIGHUP). If it is just *one* signal 
(very likely), a successive call to gnutls_handshake() would not return again 
with this value.
If the process gets 'hammered' by signals, we have a busy-loop. But with your 
change, the poll/wait would also immediate return with errno=EINTR - and we 
have a busy-loop as well.

So from what I can judge, your change adds 'complexity' without any gain.

Tim


signature.asc
Description: This is a digitally signed message part.


Re: [Bug-wget] gnutls_handshake can return GNUTLS_E_INTERRUPTED

2016-07-01 Thread Daniel Stenberg

On Fri, 1 Jul 2016, Tim Ruehsen wrote:

GNUTLS_E_INTERRUPTED is returned if the process got a signal that interrupts 
blocking I/O (for wget this is SIGUSR1 and SIGHUP). If it is just *one* 
signal (very likely), a successive call to gnutls_handshake() would not 
return again with this value. If the process gets 'hammered' by signals, we 
have a busy-loop. But with your change, the poll/wait would also immediate 
return with errno=EINTR - and we have a busy-loop as well.


So from what I can judge, your change adds 'complexity' without any gain.


You're free to do what you want with it. I think it follows the spirit of the 
documentation.


--

 / daniel.haxx.se