1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-23 16:48:49 -05:00

examples: various fixes in ephiperfifo.c

The main change here is the timer value that was wrong, it was given in
usecs (ms * 1000), while the itimerspec struct wants nsecs (ms * 1000 *
1000). This resulted in the callback being invoked WAY TOO OFTEN.

As a quick check you can run this command before and after applying this
commit:

    # shell 1
    ./ephiperfifo 2>&1 | tee ephiperfifo.log
    # shell 2
    echo http://hacking.elboulangero.com > hiper.fifo

Then just compare the size of the logs files.

Closes #3633
Fixes #3632
Signed-off-by: Arnaud Rebillout <arnaud.rebillout@collabora.com>
This commit is contained in:
Arnaud Rebillout 2019-03-01 16:58:25 +07:00 committed by Daniel Stenberg
parent 65eb65fde6
commit a977d93805
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -153,23 +153,26 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, GlobalInfo *g)
fprintf(MSG_OUT, "multi_timer_cb: Setting timeout to %ld ms\n", timeout_ms); fprintf(MSG_OUT, "multi_timer_cb: Setting timeout to %ld ms\n", timeout_ms);
timerfd_settime(g->tfd, /*flags=*/0, &its, NULL);
if(timeout_ms > 0) { if(timeout_ms > 0) {
its.it_interval.tv_sec = 1; its.it_interval.tv_sec = 1;
its.it_interval.tv_nsec = 0; its.it_interval.tv_nsec = 0;
its.it_value.tv_sec = timeout_ms / 1000; its.it_value.tv_sec = timeout_ms / 1000;
its.it_value.tv_nsec = (timeout_ms % 1000) * 1000; its.it_value.tv_nsec = (timeout_ms % 1000) * 1000 * 1000;
timerfd_settime(g->tfd, /*flags=*/0, &its, NULL);
} }
else if(timeout_ms == 0) { else if(timeout_ms == 0) {
rc = curl_multi_socket_action(g->multi, /* libcurl wants us to timeout now, however setting both fields of
CURL_SOCKET_TIMEOUT, 0, &g->still_running); * new_value.it_value to zero disarms the timer. The closest we can
mcode_or_die("multi_timer_cb: curl_multi_socket_action", rc); * do is to schedule the timer to fire in 1 ns. */
its.it_interval.tv_sec = 1;
its.it_interval.tv_nsec = 0;
its.it_value.tv_sec = 0;
its.it_value.tv_nsec = 1;
} }
else { else {
memset(&its, 0, sizeof(struct itimerspec)); memset(&its, 0, sizeof(struct itimerspec));
timerfd_settime(g->tfd, /*flags=*/0, &its, NULL);
} }
timerfd_settime(g->tfd, /*flags=*/0, &its, NULL);
return 0; return 0;
} }
@ -206,8 +209,8 @@ static void event_cb(GlobalInfo *g, int fd, int revents)
CURLMcode rc; CURLMcode rc;
struct itimerspec its; struct itimerspec its;
int action = (revents & EPOLLIN ? CURL_POLL_IN : 0) | int action = (revents & EPOLLIN ? CURL_CSELECT_IN : 0) |
(revents & EPOLLOUT ? CURL_POLL_OUT : 0); (revents & EPOLLOUT ? CURL_CSELECT_OUT : 0);
rc = curl_multi_socket_action(g->multi, fd, action, &g->still_running); rc = curl_multi_socket_action(g->multi, fd, action, &g->still_running);
mcode_or_die("event_cb: curl_multi_socket_action", rc); mcode_or_die("event_cb: curl_multi_socket_action", rc);