Merge branch 'R_2_1'
authorRemi Collet <remi@php.net>
Thu, 25 Sep 2014 13:09:00 +0000 (15:09 +0200)
committerRemi Collet <remi@php.net>
Thu, 25 Sep 2014 13:09:00 +0000 (15:09 +0200)
* R_2_1:
  Fix build with curl < 7.26

1  2 
php_http_client_curl.c

diff --combined php_http_client_curl.c
index 3d28a58e7ef0d33f096e6a254b2775db4e22e294,8f252119493dcd8c3256328d8060ffbf7ccefc24..4056e9260ab9dbfb261c8be5ab04f13cb3c99b36
@@@ -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;
@@@ -1880,17 -1882,6 +1880,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
@@@ -1906,18 -1897,10 +1906,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) {
@@@ -1948,9 -1939,12 +1948,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);
@@@ -2175,7 -2169,9 +2175,9 @@@ PHP_MINIT_FUNCTION(http_client_curl
  #if PHP_HTTP_CURL_VERSION(7,19,1)
        REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_301", CURL_REDIR_POST_301, CONST_CS|CONST_PERSISTENT);
        REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_302", CURL_REDIR_POST_302, CONST_CS|CONST_PERSISTENT);
+ #if PHP_HTTP_CURL_VERSION(7,26,0)
        REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_303", CURL_REDIR_POST_303, CONST_CS|CONST_PERSISTENT);
+ #endif
        REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "POSTREDIR_ALL", CURL_REDIR_POST_ALL, CONST_CS|CONST_PERSISTENT);
  #endif