improved timeout code
This commit is contained in:
parent
5e9adf9cfe
commit
c37df72aa3
55
network.c
55
network.c
|
@ -199,6 +199,20 @@ static int curl_multi_perform_once()
|
||||||
int n_running_curl;
|
int n_running_curl;
|
||||||
curl_multi_perform(curl_multi, &n_running_curl);
|
curl_multi_perform(curl_multi, &n_running_curl);
|
||||||
|
|
||||||
|
long timeout;
|
||||||
|
if(curl_multi_timeout(curl_multi, &timeout)) {
|
||||||
|
fprintf(stderr, "curl_multi_perform_once(): curl_multi_timeout\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(timeout == -1) {
|
||||||
|
/*
|
||||||
|
* https://curl.haxx.se/libcurl/c/curl_multi_timeout.html
|
||||||
|
* If it returns -1, there's no timeout at all set.
|
||||||
|
*/
|
||||||
|
timeout = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if any of the tasks encountered error */
|
/* Check if any of the tasks encountered error */
|
||||||
int max_fd;
|
int max_fd;
|
||||||
fd_set read_fd_set;
|
fd_set read_fd_set;
|
||||||
|
@ -216,30 +230,27 @@ static int curl_multi_perform_once()
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
long timeout;
|
|
||||||
if(curl_multi_timeout(curl_multi, &timeout)) {
|
|
||||||
fprintf(stderr, "curl_multi_perform_once(): curl_multi_timeout\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(timeout == -1) {
|
|
||||||
timeout = 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(max_fd == -1) {
|
if(max_fd == -1) {
|
||||||
sleep(1);
|
/*
|
||||||
} else {
|
* https://curl.haxx.se/libcurl/c/curl_multi_fdset.html
|
||||||
struct timeval t;
|
* The above web page suggests sleeping for 100ms, unless
|
||||||
t.tv_sec = timeout/1000;
|
* curl_multi_timeout() suggests something shorter.
|
||||||
t.tv_usec = (timeout%1000)*1000;
|
*/
|
||||||
|
if (timeout > 100) {
|
||||||
|
timeout = 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(select(max_fd + 1, &read_fd_set, &write_fd_set,
|
struct timeval t;
|
||||||
&exc_fd_set, &t) < 0) {
|
t.tv_sec = timeout/1000;
|
||||||
fprintf(stderr,
|
t.tv_usec = (timeout%1000)*1000;
|
||||||
"curl_multi_perform_once(): select(%i,,,,%li): %i: %s\n",
|
|
||||||
max_fd + 1, timeout, errno, strerror(errno));
|
if(select(max_fd + 1, &read_fd_set, &write_fd_set,
|
||||||
exit(EXIT_FAILURE);
|
&exc_fd_set, &t) < 0) {
|
||||||
}
|
fprintf(stderr,
|
||||||
|
"curl_multi_perform_once(): select(%i,,,,%li): %i: %s\n",
|
||||||
|
max_fd + 1, timeout, errno, strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Process messages */
|
/* Process messages */
|
||||||
|
|
Loading…
Reference in New Issue