[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: wget2 | wget2 doesn't honour --timeout option (#671)
From: |
Roger Marco Hernandez (@RogerMarcoHernandez) |
Subject: |
Re: wget2 | wget2 doesn't honour --timeout option (#671) |
Date: |
Sun, 07 Jul 2024 12:08:45 +0000 |
Roger Marco Hernandez commented:
https://gitlab.com/gnuwget/wget2/-/issues/671#note_1986700973
The problem was that synchronous sockets hung connecting because there was no
considered timeout. Setting the SO_SNDTIMEO according to the TCP structure
connection timeout fixes the problem.
After establishing the connection successfully, the socket is set with
O_NONBLOCK, that is, the previously set timeout no longer applies, therefore,
everything works as expected.
The patch passes all tests.
```diff
diff --git a/libwget/net.c b/libwget/net.c
index e2089742..99fbaba5 100644
--- a/libwget/net.c
+++ b/libwget/net.c
@@ -620,6 +620,8 @@ static void _set_async(int fd)
static void set_socket_options(const wget_tcp *tcp, int fd)
{
int on = 1;
+ struct timeval tv = { .tv_sec = tcp->connect_timeout/1000,
+
.tv_usec = tcp->connect_timeout % 1000 * 1000 };
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on))
== -1)
error_printf(_("Failed to set socket option REUSEADDR\n"));
@@ -646,6 +648,10 @@ static void set_socket_options(const wget_tcp *tcp, int fd)
debug_printf("Failed to set socket option
TCP_FASTOPEN_CONNECT\n");
}
#endif
+
+ // Synchronous socket connection timeout
+ if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof (tv)) == -1)
+ debug_printf("Failed to set socket option SO_SNDTIMEO\n");
}
/**
```
[671.patch](/uploads/d05c0f9f0e651061f7bcbfdedb36ae04/671.patch)
--
Reply to this email directly or view it on GitLab:
https://gitlab.com/gnuwget/wget2/-/issues/671#note_1986700973
You're receiving this email because of your account on gitlab.com.