From: Michael Wallner Date: Tue, 4 Oct 2016 14:01:03 +0000 (+0200) Subject: fix performance regression with event loop X-Git-Tag: RELEASE_2_6_0_RC1~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=3d6646aaa19df97351eac93369c012d39cb74031;p=m6w6%2Fext-http fix performance regression with event loop --- diff --git a/src/php_http_client_curl_event.c b/src/php_http_client_curl_event.c index 058c51f..21f5c9c 100644 --- a/src/php_http_client_curl_event.c +++ b/src/php_http_client_curl_event.c @@ -100,16 +100,22 @@ static void php_http_client_curl_event_timeout_callback(int socket, short action static void php_http_client_curl_event_timer(CURLM *multi, long timeout_ms, void *timer_data) { php_http_client_curl_event_context_t *context = timer_data; + struct timeval timeout; #if DBG_EVENTS - fprintf(stderr, "\ntimer <- timeout_ms: %ld\n", timeout_ms); + fprintf(stderr, "(%ld)", timeout_ms); #endif - if (timeout_ms < 0) { + switch (timeout_ms) { + case -1: + if (event_initialized(context->timeout) && event_pending(context->timeout, EV_TIMEOUT, NULL)) { + event_del(context->timeout); + } + break; + case 0: php_http_client_curl_event_handler(context, CURL_SOCKET_TIMEOUT, 0); - } else if (timeout_ms > 0 || !event_initialized(context->timeout) || !event_pending(context->timeout, EV_TIMEOUT, NULL)) { - struct timeval timeout; - + break; + default: if (!event_initialized(context->timeout)) { event_assign(context->timeout, context->evbase, CURL_SOCKET_TIMEOUT, 0, php_http_client_curl_event_timeout_callback, context); } @@ -117,7 +123,10 @@ static void php_http_client_curl_event_timer(CURLM *multi, long timeout_ms, void timeout.tv_sec = timeout_ms / 1000; timeout.tv_usec = (timeout_ms % 1000) * 1000; - event_add(context->timeout, &timeout); + if (!event_pending(context->timeout, EV_TIMEOUT, &timeout)) { + event_add(context->timeout, &timeout); + } + break; } }