** The `--timeout' option now affects DNS lookup and establishing the
connection as well. Previously it only affected reading and writing
-data.
+data. Those three timeouts can be set separately using
+`--dns-timeout', `--connection-timeout', and `--read-timeout',
+respectively.
** Download speed shown by the progress bar is based on the data
recently read, rather than the average speed of the entire download.
+2003-09-21 Hrvoje Niksic <hniksic@xemacs.org>
+
+ * connect.c (connect_with_timeout): Made timeout type double.
+
+ * options.h (struct options): New members read_timeout,
+ dns_timeout, and connect_timeout.
+ Use them.
+
2003-09-21 Hrvoje Niksic <hniksic@xemacs.org>
* init.c (simple_atof): New function.
static int
connect_with_timeout (int fd, const struct sockaddr *addr, int addrlen,
- int timeout)
+ double timeout)
{
struct cwt_context ctx;
ctx.fd = fd;
}
/* Connect the socket to the remote host. */
- if (connect_with_timeout (sock, &sa.sa, sockaddr_len (), opt.timeout) < 0)
+ if (connect_with_timeout (sock, &sa.sa, sockaddr_len (),
+ opt.connect_timeout) < 0)
{
close (sock);
sock = -1;
/* Call accept() on MSOCK and store the result to *SOCK. This assumes
that bindport() has been used to initialize MSOCK to a correct
value. It blocks the caller until a connection is established. If
- no connection is established for OPT.TIMEOUT seconds, the function
- exits with an error status. */
+ no connection is established for OPT.CONNECT_TIMEOUT seconds, the
+ function exits with an error status. */
uerr_t
acceptport (int *sock)
{
int addrlen = sockaddr_len ();
#ifdef HAVE_SELECT
- if (select_fd (msock, opt.timeout, 0) <= 0)
+ if (select_fd (msock, opt.connect_timeout, 0) <= 0)
return ACCEPTERR;
#endif
if ((*sock = accept (msock, addr, &addrlen)) < 0)
/* Read at most LEN bytes from FD, storing them to BUF. This is
virtually the same as read(), but takes care of EINTR braindamage
and uses select() to timeout the stale connections (a connection is
- stale if more than OPT.TIMEOUT time is spent in select() or
+ stale if more than OPT.READ_TIMEOUT time is spent in select() or
read()). */
int
int res;
#ifdef HAVE_SELECT
- if (opt.timeout)
- if (select_fd (fd, opt.timeout, 0) <= 0)
+ if (opt.read_timeout)
+ if (select_fd (fd, opt.read_timeout, 0) <= 0)
return -1;
#endif
do
while (len > 0)
{
#ifdef HAVE_SELECT
- if (opt.timeout)
- if (select_fd (fd, opt.timeout, 1) <= 0)
+ if (opt.read_timeout)
+ if (select_fd (fd, opt.read_timeout, 1) <= 0)
return -1;
#endif
do
int res, fd;
BIO_get_fd (con->rbio, &fd);
#ifdef HAVE_SELECT
- if (opt.timeout && !SSL_pending (con))
- if (select_fd (fd, opt.timeout, 0) <= 0)
+ if (opt.read_timeout && !SSL_pending (con))
+ if (select_fd (fd, opt.read_timeout, 0) <= 0)
return -1;
#endif
do
while (len > 0)
{
#ifdef HAVE_SELECT
- if (opt.timeout)
- if (select_fd (fd, opt.timeout, 1) <= 0)
+ if (opt.read_timeout)
+ if (select_fd (fd, opt.read_timeout, 1) <= 0)
return -1;
#endif
do
else
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
- err = getaddrinfo_with_timeout (host, NULL, &hints, &ai, opt.timeout);
+ err = getaddrinfo_with_timeout (host, NULL, &hints, &ai, opt.dns_timeout);
if (err != 0 || ai == NULL)
{
#else
{
struct hostent *hptr;
- hptr = gethostbyname_with_timeout (host, opt.timeout);
+ hptr = gethostbyname_with_timeout (host, opt.dns_timeout);
if (!hptr)
{
if (!silent)
CMD_DECLARE (cmd_spec_progress);
CMD_DECLARE (cmd_spec_recursive);
CMD_DECLARE (cmd_spec_restrict_file_names);
+CMD_DECLARE (cmd_spec_timeout);
CMD_DECLARE (cmd_spec_useragent);
/* List of recognized commands, each consisting of name, closure and function.
{ "base", &opt.base_href, cmd_string },
{ "bindaddress", &opt.bind_address, cmd_string },
{ "cache", &opt.allow_cache, cmd_boolean },
+ { "connecttimeout", &opt.connect_timeout, cmd_time },
{ "continue", &opt.always_rest, cmd_boolean },
{ "convertlinks", &opt.convert_links, cmd_boolean },
{ "cookies", &opt.cookies, cmd_boolean },
{ "dirprefix", &opt.dir_prefix, cmd_directory },
{ "dirstruct", NULL, cmd_spec_dirstruct },
{ "dnscache", &opt.dns_cache, cmd_boolean },
+ { "dnstimeout", &opt.dns_timeout, cmd_time },
{ "domains", &opt.domains, cmd_vector },
{ "dotbytes", &opt.dot_bytes, cmd_bytes },
{ "dotsinline", &opt.dots_in_line, cmd_number },
{ "quiet", &opt.quiet, cmd_boolean },
{ "quota", &opt.quota, cmd_bytes },
{ "randomwait", &opt.random_wait, cmd_boolean },
+ { "readtimeout", &opt.read_timeout, cmd_time },
{ "reclevel", &opt.reclevel, cmd_number_inf },
{ "recursive", NULL, cmd_spec_recursive },
{ "referer", &opt.referer, cmd_string },
{ "sslprotocol", &opt.sslprotocol, cmd_number },
#endif /* HAVE_SSL */
{ "strictcomments", &opt.strict_comments, cmd_boolean },
- { "timeout", &opt.timeout, cmd_time },
+ { "timeout", NULL, cmd_spec_timeout },
{ "timestamping", &opt.timestamping, cmd_boolean },
{ "tries", &opt.ntry, cmd_number_inf },
{ "useproxy", &opt.use_proxy, cmd_boolean },
opt.no_proxy = sepstring (tmp);
opt.allow_cache = 1;
-#ifdef HAVE_SELECT
- opt.timeout = 900;
-#endif
+ opt.read_timeout = 900;
opt.use_robots = 1;
opt.remove_listing = 1;
return 1;
}
+/* Set all three timeout values. */
+
+static int
+cmd_spec_timeout (const char *com, const char *val, void *closure)
+{
+ double value;
+ if (!cmd_time (com, val, &value))
+ return 0;
+ opt.read_timeout = value;
+ opt.connect_timeout = value;
+ opt.dns_timeout = value;
+ return 1;
+}
+
static int
cmd_spec_useragent (const char *com, const char *val, void *closure)
{
-N, --timestamping don\'t re-retrieve files unless newer than local.\n\
-S, --server-response print server response.\n\
--spider don\'t download anything.\n\
- -T, --timeout=SECONDS set the read timeout to SECONDS.\n\
+ -T, --timeout=SECONDS set all timeout values to SECONDS.\n\
+ --dns-timeout=SECS set the DNS lookup timeout to SECS.\n\
+ --connect-timeout=SECS set the connect timeout to SECS.\n\
+ --read-timeout=SECS set the read timeout to SECS.\n\
-w, --wait=SECONDS wait SECONDS between retrievals.\n\
--waitretry=SECONDS wait 1...SECONDS between retries of a retrieval.\n\
--random-wait wait from 0...2*WAIT secs between retrievals.\n\
{ "base", required_argument, NULL, 'B' },
{ "bind-address", required_argument, NULL, 155 },
{ "cache", required_argument, NULL, 'C' },
+ { "connect-timeout", required_argument, NULL, 180 },
{ "cookies", required_argument, NULL, 160 },
{ "cut-dirs", required_argument, NULL, 145 },
+ { "dns-timeout", required_argument, NULL, 178 },
{ "directory-prefix", required_argument, NULL, 'P' },
{ "dns-cache", required_argument, NULL, 175 },
{ "domains", required_argument, NULL, 'D' },
{ "proxy-passwd", required_argument, NULL, 144 },
{ "proxy-user", required_argument, NULL, 143 },
{ "quota", required_argument, NULL, 'Q' },
+ { "read-timeout", required_argument, NULL, 179 },
{ "reject", required_argument, NULL, 'R' },
{ "restrict-file-names", required_argument, NULL, 176 },
{ "save-cookies", required_argument, NULL, 162 },
case 176:
setoptval ("restrictfilenames", optarg);
break;
+ case 178:
+ setoptval ("dnstimeout", optarg);
+ break;
+ case 179:
+ setoptval ("readtimeout", optarg);
+ break;
+ case 180:
+ setoptval ("connecttimeout", optarg);
+ break;
case 'A':
setoptval ("accept", optarg);
break;
char *progress_type; /* progress indicator type. */
char *proxy_user; /*oli*/
char *proxy_passwd;
-#ifdef HAVE_SELECT
- double timeout; /* The read/connect/DNS timeout. */
-#endif
+
+ double read_timeout; /* The read/write timeout. */
+ double dns_timeout; /* The DNS timeout. */
+ double connect_timeout; /* The connect timeout. */
+
int random_wait; /* vary from 0 .. wait secs by random()? */
double wait; /* The wait period between retrievals. */
double waitretry; /* The wait period between retries. - HEH */