Merge branch 'R_2_1'
authorMichael Wallner <mike@php.net>
Mon, 15 Sep 2014 12:18:14 +0000 (14:18 +0200)
committerMichael Wallner <mike@php.net>
Mon, 15 Sep 2014 12:18:14 +0000 (14:18 +0200)
1  2 
php_http_client_curl.c

diff --combined php_http_client_curl.c
index b261a34112b4f93a0f1f78d5828b135fa585d037,20bbf8eb9d2723b7d8442d75e6839d0e180f1e9c..3ee624eb1d20d90f69fa5f1f4a5b255d8ab6fbde
@@@ -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);
  #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
  
                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);