From d982551f5260407a6301c662604ac0b854fb7ba0 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 5 Dec 2008 09:37:57 +0000 Subject: [PATCH 1/1] * start 1.7.0-dev * Implement Request #14408 (Add a customizable timeout for HttpRequestPool::socketSelect) --- http_request_pool_api.c | 13 ++++++++++++- http_requestpool_object.c | 19 +++++++++++++++---- package2.xml | 8 ++------ php_http.h | 2 +- php_http_request_pool_api.h | 3 +++ 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/http_request_pool_api.c b/http_request_pool_api.c index e5482b4..fcc015e 100644 --- a/http_request_pool_api.c +++ b/http_request_pool_api.c @@ -316,6 +316,13 @@ PHP_HTTP_API void _http_request_pool_dtor(http_request_pool *pool) /* {{{ STATUS http_request_pool_select(http_request_pool *) */ PHP_HTTP_API STATUS _http_request_pool_select(http_request_pool *pool) +{ + return http_request_pool_select_ex(pool, NULL); +} +/* }}} */ + +/* {{{ STATUS http_request_pool_select_ex(http_request_pool *, struct timeval *) */ +PHP_HTTP_API STATUS _http_request_pool_select_ex(http_request_pool *pool, struct timeval *custom_timeout) { int MAX; fd_set R, W, E; @@ -329,7 +336,11 @@ PHP_HTTP_API STATUS _http_request_pool_select(http_request_pool *pool) } #endif - http_request_pool_timeout(pool, &timeout); + if (custom_timeout && timerisset(custom_timeout)) { + timeout = *custom_timeout; + } else { + http_request_pool_timeout(pool, &timeout); + } FD_ZERO(&R); FD_ZERO(&W); diff --git a/http_requestpool_object.c b/http_requestpool_object.c index 48783c8..03fee88 100644 --- a/http_requestpool_object.c +++ b/http_requestpool_object.c @@ -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); @@ -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)); } /* }}} */ diff --git a/package2.xml b/package2.xml index e35c328..34d1096 100644 --- a/package2.xml +++ b/package2.xml @@ -30,7 +30,7 @@ support. Parallel requests are available for PHP 5 and greater. 2008-12-05 - 1.6.2 + 1.7.0-dev 1.6.0 @@ -39,11 +39,7 @@ support. Parallel requests are available for PHP 5 and greater. BSD, revised diff --git a/php_http.h b/php_http.h index 7495a41..a34457c 100644 --- a/php_http.h +++ b/php_http.h @@ -15,7 +15,7 @@ #ifndef PHP_EXT_HTTP_H #define PHP_EXT_HTTP_H -#define PHP_HTTP_VERSION "1.6.2" +#define PHP_HTTP_VERSION "1.7.0-dev" #ifdef HAVE_CONFIG_H # include "config.h" diff --git a/php_http_request_pool_api.h b/php_http_request_pool_api.h index c131662..5f86b95 100644 --- a/php_http_request_pool_api.h +++ b/php_http_request_pool_api.h @@ -73,6 +73,9 @@ PHP_HTTP_API STATUS _http_request_pool_send(http_request_pool *pool); #define http_request_pool_select _http_request_pool_select PHP_HTTP_API STATUS _http_request_pool_select(http_request_pool *pool); +#define http_request_pool_select_ex _http_request_pool_select_ex +PHP_HTTP_API STATUS _http_request_pool_select_ex(http_request_pool *pool, struct timeval *custom_timeout); + #define http_request_pool_perform(p) _http_request_pool_perform((p)) PHP_HTTP_API int _http_request_pool_perform(http_request_pool *pool); -- 2.30.2