mirror of
https://github.com/mirror/wget.git
synced 2025-03-29 05:20:18 +08:00
gnutls: honor connect timeout
This commit is contained in:
parent
c78caecbb4
commit
91f0f99e9a
@ -1,3 +1,7 @@
|
|||||||
|
2013-07-11 Tim Ruehsen <tim.ruehsen@gmx.de>
|
||||||
|
|
||||||
|
* gnutls.c (ssl_connect_wget): respect connect timeout.
|
||||||
|
|
||||||
2013-07-11 Tomas Hozza <thozza@redhat.com>
|
2013-07-11 Tomas Hozza <thozza@redhat.com>
|
||||||
|
|
||||||
* ftp.c (ftp_loop): Use ftp_retrieve_glob() also in case
|
* ftp.c (ftp_loop): Use ftp_retrieve_glob() also in case
|
||||||
|
60
src/gnutls.c
60
src/gnutls.c
@ -374,6 +374,9 @@ static struct transport_implementation wgnutls_transport =
|
|||||||
bool
|
bool
|
||||||
ssl_connect_wget (int fd, const char *hostname)
|
ssl_connect_wget (int fd, const char *hostname)
|
||||||
{
|
{
|
||||||
|
#ifdef F_GETFL
|
||||||
|
int flags = 0;
|
||||||
|
#endif
|
||||||
struct wgnutls_transport_context *ctx;
|
struct wgnutls_transport_context *ctx;
|
||||||
gnutls_session_t session;
|
gnutls_session_t session;
|
||||||
int err,alert;
|
int err,alert;
|
||||||
@ -441,11 +444,54 @@ ssl_connect_wget (int fd, const char *hostname)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opt.connect_timeout)
|
||||||
|
{
|
||||||
|
#ifdef F_GETFL
|
||||||
|
flags = fcntl (fd, F_GETFL, 0);
|
||||||
|
if (flags < 0)
|
||||||
|
return flags;
|
||||||
|
if (fcntl (fd, F_SETFL, flags | O_NONBLOCK))
|
||||||
|
return -1;
|
||||||
|
#else
|
||||||
|
/* XXX: Assume it was blocking before. */
|
||||||
|
const int one = 1;
|
||||||
|
if (ioctl (fd, FIONBIO, &one) < 0)
|
||||||
|
return -1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* We don't stop the handshake process for non-fatal errors */
|
/* We don't stop the handshake process for non-fatal errors */
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
err = gnutls_handshake (session);
|
err = gnutls_handshake (session);
|
||||||
if (err < 0)
|
|
||||||
|
if (opt.connect_timeout && err == GNUTLS_E_AGAIN)
|
||||||
|
{
|
||||||
|
if (gnutls_record_get_direction (session))
|
||||||
|
{
|
||||||
|
/* wait for writeability */
|
||||||
|
err = select_fd (fd, opt.connect_timeout, WAIT_FOR_WRITE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* wait for readability */
|
||||||
|
err = select_fd (fd, opt.connect_timeout, WAIT_FOR_READ);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err <= 0)
|
||||||
|
{
|
||||||
|
if (err == 0)
|
||||||
|
{
|
||||||
|
errno = ETIMEDOUT;
|
||||||
|
err = -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err <= 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (err < 0)
|
||||||
{
|
{
|
||||||
logprintf (LOG_NOTQUIET, "GnuTLS: %s\n", gnutls_strerror (err));
|
logprintf (LOG_NOTQUIET, "GnuTLS: %s\n", gnutls_strerror (err));
|
||||||
if (err == GNUTLS_E_WARNING_ALERT_RECEIVED ||
|
if (err == GNUTLS_E_WARNING_ALERT_RECEIVED ||
|
||||||
@ -461,6 +507,18 @@ ssl_connect_wget (int fd, const char *hostname)
|
|||||||
}
|
}
|
||||||
while (err == GNUTLS_E_WARNING_ALERT_RECEIVED && gnutls_error_is_fatal (err) == 0);
|
while (err == GNUTLS_E_WARNING_ALERT_RECEIVED && gnutls_error_is_fatal (err) == 0);
|
||||||
|
|
||||||
|
if (opt.connect_timeout)
|
||||||
|
{
|
||||||
|
#ifdef F_GETFL
|
||||||
|
if (fcntl (fd, F_SETFL, flags) < 0)
|
||||||
|
return -1;
|
||||||
|
#else
|
||||||
|
const int zero = 0;
|
||||||
|
if (ioctl (fd, FIONBIO, &zero) < 0)
|
||||||
|
return -1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
{
|
{
|
||||||
gnutls_deinit (session);
|
gnutls_deinit (session);
|
||||||
|
Loading…
Reference in New Issue
Block a user