aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorMichael Kaufmann <mail@michael-kaufmann.ch>2017-01-29 17:06:49 +0100
committerMichael Kaufmann <mail@michael-kaufmann.ch>2017-02-18 18:09:17 +0100
commit4ddf9798ab1ae0c6d18d8f12ce531991dbd2575a (patch)
treed0c43e98887793816d2fe9a57e42415fe3c5afe6 /docs
parent2f8d0df085519351dbd7123178895ba910d756c1 (diff)
docs: fix timeout handling in multi-uv example
Diffstat (limited to 'docs')
-rw-r--r--docs/examples/multi-uv.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/docs/examples/multi-uv.c b/docs/examples/multi-uv.c
index c0228945d..406a5e062 100644
--- a/docs/examples/multi-uv.c
+++ b/docs/examples/multi-uv.c
@@ -46,7 +46,7 @@ typedef struct curl_context_s {
curl_socket_t sockfd;
} curl_context_t;
-curl_context_t* create_curl_context(curl_socket_t sockfd)
+static curl_context_t* create_curl_context(curl_socket_t sockfd)
{
curl_context_t *context;
@@ -60,18 +60,18 @@ curl_context_t* create_curl_context(curl_socket_t sockfd)
return context;
}
-void curl_close_cb(uv_handle_t *handle)
+static void curl_close_cb(uv_handle_t *handle)
{
curl_context_t *context = (curl_context_t *) handle->data;
free(context);
}
-void destroy_curl_context(curl_context_t *context)
+static void destroy_curl_context(curl_context_t *context)
{
uv_close((uv_handle_t *) &context->poll_handle, curl_close_cb);
}
-void add_download(const char *url, int num)
+static void add_download(const char *url, int num)
{
char filename[50];
FILE *file;
@@ -129,14 +129,12 @@ static void check_multi_info(void)
}
}
-void curl_perform(uv_poll_t *req, int status, int events)
+static void curl_perform(uv_poll_t *req, int status, int events)
{
int running_handles;
int flags = 0;
curl_context_t *context;
- uv_timer_stop(&timeout);
-
if(events & UV_READABLE)
flags |= CURL_CSELECT_IN;
if(events & UV_WRITABLE)
@@ -150,7 +148,7 @@ void curl_perform(uv_poll_t *req, int status, int events)
check_multi_info();
}
-void on_timeout(uv_timer_t *req, int status)
+static void on_timeout(uv_timer_t *req, int status)
{
int running_handles;
curl_multi_socket_action(curl_handle, CURL_SOCKET_TIMEOUT, 0,
@@ -158,15 +156,21 @@ void on_timeout(uv_timer_t *req, int status)
check_multi_info();
}
-void start_timeout(CURLM *multi, long timeout_ms, void *userp)
+static int start_timeout(CURLM *multi, long timeout_ms, void *userp)
{
- if(timeout_ms <= 0)
- timeout_ms = 1; /* 0 means directly call socket_action, but we'll do it in
- a bit */
- uv_timer_start(&timeout, on_timeout, timeout_ms, 0);
+ if(timeout_ms < 0) {
+ uv_timer_stop(&timeout);
+ }
+ else {
+ if(timeout_ms == 0)
+ timeout_ms = 1; /* 0 means directly call socket_action, but we'll do it in
+ a bit */
+ uv_timer_start(&timeout, on_timeout, timeout_ms, 0);
+ }
+ return 0;
}
-int handle_socket(CURL *easy, curl_socket_t s, int action, void *userp,
+static int handle_socket(CURL *easy, curl_socket_t s, int action, void *userp,
void *socketp)
{
curl_context_t *curl_context;