From 51a8e9fa5003cd6094b3b29973f2df15f48892bf Mon Sep 17 00:00:00 2001 From: hniksic Date: Sat, 20 Sep 2003 21:41:55 -0700 Subject: [PATCH] [svn] Enabled separation of different timeout values. --- NEWS | 4 +++- src/ChangeLog | 8 ++++++++ src/connect.c | 21 +++++++++++---------- src/gen_sslfunc.c | 8 ++++---- src/host.c | 4 ++-- src/init.c | 24 ++++++++++++++++++++---- src/main.c | 17 ++++++++++++++++- src/options.h | 8 +++++--- 8 files changed, 69 insertions(+), 25 deletions(-) diff --git a/NEWS b/NEWS index dcae65fc..7dbb710a 100644 --- a/NEWS +++ b/NEWS @@ -15,7 +15,9 @@ send a POST request with the specified contents. ** 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. diff --git a/src/ChangeLog b/src/ChangeLog index 49627335..2a531b7a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2003-09-21 Hrvoje Niksic + + * 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 * init.c (simple_atof): New function. diff --git a/src/connect.c b/src/connect.c index 5f927647..f12225d8 100644 --- a/src/connect.c +++ b/src/connect.c @@ -117,7 +117,7 @@ connect_with_timeout_callback (void *arg) static int connect_with_timeout (int fd, const struct sockaddr *addr, int addrlen, - int timeout) + double timeout) { struct cwt_context ctx; ctx.fd = fd; @@ -205,7 +205,8 @@ connect_to_one (ip_address *addr, unsigned short port, int silent) } /* 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; @@ -385,15 +386,15 @@ select_fd (int fd, double maxtime, int writep) /* 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) @@ -447,7 +448,7 @@ conaddr (int fd, ip_address *ip) /* 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 @@ -456,8 +457,8 @@ iread (int fd, char *buf, int len) 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 @@ -484,8 +485,8 @@ iwrite (int fd, char *buf, int len) 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 diff --git a/src/gen_sslfunc.c b/src/gen_sslfunc.c index ec4204c7..57cdb0f2 100644 --- a/src/gen_sslfunc.c +++ b/src/gen_sslfunc.c @@ -317,8 +317,8 @@ ssl_iread (SSL *con, char *buf, int len) 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 @@ -343,8 +343,8 @@ ssl_iwrite (SSL *con, char *buf, int len) 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 diff --git a/src/host.c b/src/host.c index baae0f38..489adbcc 100644 --- a/src/host.c +++ b/src/host.c @@ -656,7 +656,7 @@ lookup_host (const char *host, int silent) 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) { @@ -671,7 +671,7 @@ lookup_host (const char *host, int silent) #else { struct hostent *hptr; - hptr = gethostbyname_with_timeout (host, opt.timeout); + hptr = gethostbyname_with_timeout (host, opt.dns_timeout); if (!hptr) { if (!silent) diff --git a/src/init.c b/src/init.c index 62488fd2..884f39f8 100644 --- a/src/init.c +++ b/src/init.c @@ -102,6 +102,7 @@ CMD_DECLARE (cmd_spec_mirror); 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. @@ -123,6 +124,7 @@ static struct { { "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 }, @@ -134,6 +136,7 @@ static struct { { "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 }, @@ -184,6 +187,7 @@ static struct { { "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 }, @@ -209,7 +213,7 @@ static struct { { "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 }, @@ -272,9 +276,7 @@ defaults (void) 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; @@ -1159,6 +1161,20 @@ cmd_spec_restrict_file_names (const char *com, const char *val, void *closure) 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) { diff --git a/src/main.c b/src/main.c index 148205ad..8235bbe8 100644 --- a/src/main.c +++ b/src/main.c @@ -170,7 +170,10 @@ Download:\n\ -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\ @@ -315,8 +318,10 @@ main (int argc, char *const *argv) { "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' }, @@ -346,6 +351,7 @@ main (int argc, char *const *argv) { "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 }, @@ -620,6 +626,15 @@ GNU General Public License for more details.\n")); 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; diff --git a/src/options.h b/src/options.h index 7b67169c..9df52f0a 100644 --- a/src/options.h +++ b/src/options.h @@ -107,9 +107,11 @@ struct options 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 */ -- 2.39.2