From: Michael Wallner Date: Mon, 15 Sep 2014 12:18:14 +0000 (+0200) Subject: Merge branch 'R_2_1' X-Git-Tag: RELEASE_2_2_0_RC1~11^2~3 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=commitdiff_plain;h=0fec4ae3ad609adc395f7c5abbc6472792d03514;hp=-c Merge branch 'R_2_1' --- 0fec4ae3ad609adc395f7c5abbc6472792d03514 diff --combined php_http_client_curl.c index b261a34,20bbf8e..3ee624e --- a/php_http_client_curl.c +++ b/php_http_client_curl.c @@@ -783,6 -783,8 +783,6 @@@ static void php_http_curlm_timer_callba if (!event_initialized(curl->timeout)) { event_assign(curl->timeout, curl->evbase, CURL_SOCKET_TIMEOUT, 0, php_http_curlm_timeout_callback, context); - } else if (event_pending(curl->timeout, EV_TIMEOUT, NULL)) { - event_del(curl->timeout); } timeout.tv_sec = timeout_ms / 1000; @@@ -1675,10 -1677,8 +1675,8 @@@ static STATUS php_http_client_curl_hand return SUCCESS; } - static void php_http_client_curl_handler_dtor(php_http_client_curl_handler_t *handler) + static void php_http_client_curl_handler_clear(php_http_client_curl_handler_t *handler) { - TSRMLS_FETCH_FROM_CTX(handler->client->ts); - curl_easy_setopt(handler->handle, CURLOPT_NOPROGRESS, 1L); #if PHP_HTTP_CURL_VERSION(7,32,0) curl_easy_setopt(handler->handle, CURLOPT_XFERINFOFUNCTION, NULL); @@@ -1687,6 -1687,13 +1685,13 @@@ #endif curl_easy_setopt(handler->handle, CURLOPT_VERBOSE, 0L); curl_easy_setopt(handler->handle, CURLOPT_DEBUGFUNCTION, NULL); + } + + static void php_http_client_curl_handler_dtor(php_http_client_curl_handler_t *handler) + { + TSRMLS_FETCH_FROM_CTX(handler->client->ts); + + php_http_client_curl_handler_clear(handler); php_resource_factory_handle_dtor(handler->rf, handler->handle TSRMLS_CC); php_resource_factory_free(&handler->rf); @@@ -1851,6 -1858,7 +1856,7 @@@ static STATUS php_http_client_curl_dequ php_http_client_curl_handler_t *handler = enqueue->opaque; TSRMLS_FETCH_FROM_CTX(h->ts); + php_http_client_curl_handler_clear(handler); if (CURLM_OK == (rs = curl_multi_remove_handle(curl->handle, handler->handle))) { zend_llist_del_element(&h->requests, handler->handle, (int (*)(void *, void *)) compare_queue); return SUCCESS; @@@ -1871,17 -1879,6 +1877,17 @@@ static void php_http_client_curl_reset( } } +static inline void php_http_client_curl_get_timeout(php_http_client_curl_t *curl, long max_tout, struct timeval *timeout) +{ + if ((CURLM_OK == curl_multi_timeout(curl->handle, &max_tout)) && (max_tout > 0)) { + timeout->tv_sec = max_tout / 1000; + timeout->tv_usec = (max_tout % 1000) * 1000; + } else { + timeout->tv_sec = 0; + timeout->tv_usec = 1000; + } +} + #ifdef PHP_WIN32 # define SELECT_ERROR SOCKET_ERROR #else @@@ -1897,18 -1894,10 +1903,18 @@@ static STATUS php_http_client_curl_wait #if PHP_HTTP_HAVE_EVENT if (curl->useevents) { - TSRMLS_FETCH_FROM_CTX(h->ts); + if (!event_initialized(curl->timeout)) { + event_assign(curl->timeout, curl->evbase, CURL_SOCKET_TIMEOUT, 0, php_http_curlm_timeout_callback, h); + } else if (custom_timeout && timerisset(custom_timeout)) { + event_add(curl->timeout, custom_timeout); + } else if (!event_pending(curl->timeout, EV_TIMEOUT, NULL)) { + php_http_client_curl_get_timeout(curl, 1000, &timeout); + event_add(curl->timeout, &timeout); + } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "not implemented"); - return FAILURE; + event_base_loop(curl->evbase, EVLOOP_ONCE); + + return SUCCESS; } #endif @@@ -1920,7 -1909,15 +1926,7 @@@ if (custom_timeout && timerisset(custom_timeout)) { timeout = *custom_timeout; } else { - long max_tout = 1000; - - if ((CURLM_OK == curl_multi_timeout(curl->handle, &max_tout)) && (max_tout > 0)) { - timeout.tv_sec = max_tout / 1000; - timeout.tv_usec = (max_tout % 1000) * 1000; - } else { - timeout.tv_sec = 0; - timeout.tv_usec = 1000; - } + php_http_client_curl_get_timeout(curl, 1000, &timeout); } if (MAX == -1) { @@@ -1939,9 -1936,12 +1945,9 @@@ static int php_http_client_curl_once(ph #if PHP_HTTP_HAVE_EVENT if (curl->useevents) { - TSRMLS_FETCH_FROM_CTX(h->ts); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "not implemented"); - return FAILURE; - } + event_base_loop(curl->evbase, EVLOOP_NONBLOCK); + } else #endif - while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(curl->handle, &curl->unfinished)); php_http_curlm_responsehandler(h);