* attempt to fix pecl Bug #16826 http_date strange behavior and crash
[m6w6/ext-http] / http_requestpool_object.c
index 4a4293ba29549eed553b30540971e918bd8f42e6..03fee88c575ca09a40ea5726d71cc3ffefd93d5e 100644 (file)
@@ -50,7 +50,9 @@ HTTP_END_ARGS;
 
 HTTP_EMPTY_ARGS(send);
 HTTP_EMPTY_ARGS(socketPerform);
-HTTP_EMPTY_ARGS(socketSelect);
+HTTP_BEGIN_ARGS(socketSelect, 0)
+       HTTP_ARG_VAL(timeout, 0)
+HTTP_END_ARGS;
 
 HTTP_EMPTY_ARGS(valid);
 HTTP_EMPTY_ARGS(current);
@@ -173,8 +175,8 @@ PHP_METHOD(HttpRequestPool, __construct)
                }
        }
        efree(argv);
-       SET_EH_NORMAL();
        http_final(HTTP_EX_CE(request_pool));
+       SET_EH_NORMAL();
 }
 /* }}} */
 
@@ -277,14 +279,23 @@ PHP_METHOD(HttpRequestPool, socketPerform)
 }
 /* }}} */
 
-/* {{{ proto protected bool HttpRequestPool::socketSelect() */
+/* {{{ proto protected bool HttpRequestPool::socketSelect([double timeout]) */
 PHP_METHOD(HttpRequestPool, socketSelect)
 {
+       double timeout = 0;
+       struct timeval custom_timeout, *custom_timeout_ptr = NULL;
        getObject(http_requestpool_object, obj);
 
-       NO_ARGS;
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|d", &timeout)) {
+               RETURN_FALSE;
+       }
+       if (ZEND_NUM_ARGS() && timeout > 0) {
+               custom_timeout.tv_sec = (time_t) timeout;
+               custom_timeout.tv_usec = HTTP_USEC(timeout) % HTTP_MCROSEC;
+               custom_timeout_ptr = &custom_timeout;
+       }
 
-       RETURN_SUCCESS(http_request_pool_select(&obj->pool));
+       RETURN_SUCCESS(http_request_pool_select_ex(&obj->pool, custom_timeout_ptr));
 }
 /* }}} */
 
@@ -407,7 +418,9 @@ PHP_METHOD(HttpRequestPool, getFinishedRequests)
 PHP_METHOD(HttpRequestPool, enablePipelining)
 {
        zend_bool enable = 1;
+#if defined(HAVE_CURL_MULTI_SETOPT) && HTTP_CURL_VERSION(7,16,0)
        getObject(http_requestpool_object, obj);
+#endif
        
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &enable)) {
                RETURN_FALSE;
@@ -426,7 +439,9 @@ PHP_METHOD(HttpRequestPool, enablePipelining)
 PHP_METHOD(HttpRequestPool, enableEvents)
 {
        zend_bool enable = 1;
+#if defined(HTTP_HAVE_EVENT)
        getObject(http_requestpool_object, obj);
+#endif
        
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &enable)) {
 #if defined(HTTP_HAVE_EVENT)