aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauri Kasanen <curaga@operamail.com>2013-10-12 21:47:07 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2013-10-12 21:47:07 +0200
commitd074b416f8d3ca6b6ae7b44d17e204ea8d81e7a0 (patch)
treeca2227cabe38037276d4b8f270878bd26860a6d8
parent730e4d8b5245502803c9c2335e96d81f70d63012 (diff)
downloadbusybox-w32-d074b416f8d3ca6b6ae7b44d17e204ea8d81e7a0.tar.gz
busybox-w32-d074b416f8d3ca6b6ae7b44d17e204ea8d81e7a0.tar.bz2
busybox-w32-d074b416f8d3ca6b6ae7b44d17e204ea8d81e7a0.zip
wget: add support for connect timeout
function old new delta open_socket 33 64 +31 wget_main 2182 2194 +12 Signed-off-by: Lauri Kasanen <curaga@operamail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/Config.src16
-rw-r--r--networking/wget.c24
2 files changed, 30 insertions, 10 deletions
diff --git a/networking/Config.src b/networking/Config.src
index e1ae0c9d5..ca0ddcdd9 100644
--- a/networking/Config.src
+++ b/networking/Config.src
@@ -970,16 +970,18 @@ config FEATURE_WGET_LONG_OPTIONS
970 Support long options for the wget applet. 970 Support long options for the wget applet.
971 971
972config FEATURE_WGET_TIMEOUT 972config FEATURE_WGET_TIMEOUT
973 bool "Enable read timeout option -T SEC" 973 bool "Enable timeout option -T SEC"
974 default y 974 default y
975 depends on WGET 975 depends on WGET
976 help 976 help
977 Supports network read timeout for wget, so that wget will give 977 Supports network read and connect timeouts for wget,
978 up and timeout when reading network data, through the -T command 978 so that wget will give up and timeout, through the -T
979 line option. Currently only network data read timeout is 979 command line option.
980 supported (i.e., timeout is not applied to the DNS nor TCP 980
981 connection initialization). When FEATURE_WGET_LONG_OPTIONS is 981 Currently only connect and network data read timeout are
982 also enabled, the --timeout option will work in addition to -T. 982 supported (i.e., timeout is not applied to the DNS query). When
983 FEATURE_WGET_LONG_OPTIONS is also enabled, the --timeout option
984 will work in addition to -T.
983 985
984config ZCIP 986config ZCIP
985 bool "zcip" 987 bool "zcip"
diff --git a/networking/wget.c b/networking/wget.c
index 5dac2b500..a32f85229 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -72,6 +72,7 @@ struct globals {
72 const char *user_agent; /* "User-Agent" header field */ 72 const char *user_agent; /* "User-Agent" header field */
73#if ENABLE_FEATURE_WGET_TIMEOUT 73#if ENABLE_FEATURE_WGET_TIMEOUT
74 unsigned timeout_seconds; 74 unsigned timeout_seconds;
75 bool connecting;
75#endif 76#endif
76 int output_fd; 77 int output_fd;
77 int o_flags; 78 int o_flags;
@@ -87,7 +88,6 @@ struct globals {
87#define G (*ptr_to_globals) 88#define G (*ptr_to_globals)
88#define INIT_G() do { \ 89#define INIT_G() do { \
89 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 90 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
90 IF_FEATURE_WGET_TIMEOUT(G.timeout_seconds = 900;) \
91} while (0) 91} while (0)
92 92
93 93
@@ -195,13 +195,27 @@ static char* sanitize_string(char *s)
195 return s; 195 return s;
196} 196}
197 197
198#if ENABLE_FEATURE_WGET_TIMEOUT
199static void alarm_handler(int sig UNUSED_PARAM)
200{
201 /* This is theoretically unsafe (uses stdio and malloc in signal handler) */
202 if (G.connecting)
203 bb_error_msg_and_die("download timed out");
204}
205#endif
206
198static FILE *open_socket(len_and_sockaddr *lsa) 207static FILE *open_socket(len_and_sockaddr *lsa)
199{ 208{
209 int fd;
200 FILE *fp; 210 FILE *fp;
201 211
212 IF_FEATURE_WGET_TIMEOUT(alarm(G.timeout_seconds); G.connecting = 1;)
213 fd = xconnect_stream(lsa);
214 IF_FEATURE_WGET_TIMEOUT(G.connecting = 0;)
215
202 /* glibc 2.4 seems to try seeking on it - ??! */ 216 /* glibc 2.4 seems to try seeking on it - ??! */
203 /* hopefully it understands what ESPIPE means... */ 217 /* hopefully it understands what ESPIPE means... */
204 fp = fdopen(xconnect_stream(lsa), "r+"); 218 fp = fdopen(fd, "r+");
205 if (fp == NULL) 219 if (fp == NULL)
206 bb_perror_msg_and_die(bb_msg_memory_exhausted); 220 bb_perror_msg_and_die(bb_msg_memory_exhausted);
207 221
@@ -209,6 +223,7 @@ static FILE *open_socket(len_and_sockaddr *lsa)
209} 223}
210 224
211/* Returns '\n' if it was seen, else '\0'. Trims at first '\r' or '\n' */ 225/* Returns '\n' if it was seen, else '\0'. Trims at first '\r' or '\n' */
226/* FIXME: does not respect FEATURE_WGET_TIMEOUT and -T N: */
212static char fgets_and_trim(FILE *fp) 227static char fgets_and_trim(FILE *fp)
213{ 228{
214 char c; 229 char c;
@@ -944,7 +959,10 @@ int wget_main(int argc UNUSED_PARAM, char **argv)
944 959
945 INIT_G(); 960 INIT_G();
946 961
947 IF_FEATURE_WGET_TIMEOUT(G.timeout_seconds = 900;) 962#if ENABLE_FEATURE_WGET_TIMEOUT
963 G.timeout_seconds = 900;
964 signal(SIGALRM, alarm_handler);
965#endif
948 G.proxy_flag = "on"; /* use proxies if env vars are set */ 966 G.proxy_flag = "on"; /* use proxies if env vars are set */
949 G.user_agent = "Wget"; /* "User-Agent" header field */ 967 G.user_agent = "Wget"; /* "User-Agent" header field */
950 968