X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_request_pool_api.c;fp=http_request_pool_api.c;h=29df94f12a5203e4bcc2b0416f8588e88176a567;hp=154161404a4f3d0cb8f9c6cf9f1df4770ff6c59f;hb=42dd649e29ed164437f98039ed58fa5fdd5fb2c9;hpb=001d038560e304bef20f3b3cea063653a45e3a61 diff --git a/http_request_pool_api.c b/http_request_pool_api.c index 1541614..29df94f 100644 --- a/http_request_pool_api.c +++ b/http_request_pool_api.c @@ -23,6 +23,7 @@ #include "php_http_request_object.h" #include "php_http_request_pool_api.h" #include "php_http_requestpool_object.h" +#include "php_http_persistent_handle_api.h" #ifndef HTTP_DEBUG_REQPOOLS # define HTTP_DEBUG_REQPOOLS 0 @@ -32,8 +33,26 @@ # define curl_multi_strerror(dummy) "unknown error" #endif +#ifdef HTTP_HAVE_PERSISTENT_HANDLES +# define HTTP_CURL_MULTI_CTOR(ch) (SUCCESS == http_persistent_handle_acquire("http_request_pool", &(ch))) +# define HTTP_CURL_MULTI_DTOR(chp) http_persistent_handle_release("http_request_pool", (chp)) +#else +# define HTTP_CURL_MULTI_CTOR(ch) ((ch) = curl_multi_init()) +# define HTTP_CURL_MULTI_DTOR(chp) curl_multi_cleanup(*(chp)); *(chp) = NULL +#endif + static int http_request_pool_compare_handles(void *h1, void *h2); +#ifdef HTTP_HAVE_PERSISTENT_HANDLES +PHP_MINIT_FUNCTION(http_request_pool) +{ + if (SUCCESS != http_persistent_handle_provide("http_request_pool", curl_multi_init, (http_persistent_handle_dtor) curl_multi_cleanup)) { + return FAILURE; + } + return SUCCESS; +} +#endif + /* {{{ http_request_pool *http_request_pool_init(http_request_pool *) */ PHP_HTTP_API http_request_pool *_http_request_pool_init(http_request_pool *pool TSRMLS_DC) { @@ -48,8 +67,7 @@ PHP_HTTP_API http_request_pool *_http_request_pool_init(http_request_pool *pool pool->ch = NULL; } - HTTP_CHECK_CURL_INIT(pool->ch, curl_multi_init(), ;); - if (!pool->ch) { + if (!HTTP_CURL_MULTI_CTOR(pool->ch)) { if (free_pool) { efree(pool); } @@ -245,7 +263,7 @@ PHP_HTTP_API void _http_request_pool_dtor(http_request_pool *pool TSRMLS_DC) pool->unfinished = 0; zend_llist_clean(&pool->finished); zend_llist_clean(&pool->handles); - curl_multi_cleanup(pool->ch); + HTTP_CURL_MULTI_DTOR(&pool->ch); } /* }}} */