X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_request_datashare_api.c;h=6c70f3f7f88fe8f47f288f239cbbfcf2f9d9df6f;hp=2bf05632daa71b2d9312eda6831b657765c56b20;hb=accf1817e811a7edabd687ef6105983f39f13942;hpb=5b440d6af3dd3052dde7b137f975692f0aa84603 diff --git a/http_request_datashare_api.c b/http_request_datashare_api.c index 2bf0563..6c70f3f 100644 --- a/http_request_datashare_api.c +++ b/http_request_datashare_api.c @@ -21,12 +21,16 @@ #include "php_http_request_datashare_api.h" #include "php_http_request_api.h" #include "php_http_request_object.h" - -#ifndef HAVE_CURL_SHARE_STRERROR -# define curl_share_strerror(dummy) "unknown error" +#ifdef HTTP_HAVE_PERSISTENT_HANDLES +# include "php_http_persistent_handle_api.h" #endif -#ifndef HAVE_CURL_EASY_STRERROR -# define curl_easy_strerror(dummy) "unknown error" + +#ifdef HTTP_HAVE_PERSISTENT_HANDLES +# define HTTP_CURL_SHARE_CTOR(ch) (SUCCESS == http_persistent_handle_acquire("http_request_datashare", &(ch))) +# define HTTP_CURL_SHARE_DTOR(chp) http_persistent_handle_release("http_request_datashare", (chp)) +#else +# define HTTP_CURL_SHARE_CTOR(ch) ((ch) = curl_share_init()) +# define HTTP_CURL_SHARE_DTOR(chp) curl_share_cleanup(*(chp)); *(chp) = NULL #endif static HashTable http_request_datashare_options; @@ -47,6 +51,16 @@ PHP_MINIT_FUNCTION(http_request_datashare) { curl_lock_data val; +#ifdef HTTP_HAVE_PERSISTENT_HANDLES + if (SUCCESS != http_persistent_handle_provide("http_request_datashare", curl_share_init, (http_persistent_handle_dtor) curl_share_cleanup)) { + return FAILURE; + } +#endif + + if (!http_request_datashare_init_ex(&http_request_datashare_global, 1)) { + return FAILURE; + } + zend_hash_init(&http_request_datashare_options, 4, NULL, NULL, 1); #define ADD_DATASHARE_OPT(name, opt) \ val = opt; \ @@ -56,8 +70,6 @@ PHP_MINIT_FUNCTION(http_request_datashare) ADD_DATASHARE_OPT("ssl", CURL_LOCK_DATA_SSL_SESSION); ADD_DATASHARE_OPT("connect", CURL_LOCK_DATA_CONNECT); - http_request_datashare_init_ex(&http_request_datashare_global, 1); - return SUCCESS; } @@ -92,8 +104,7 @@ PHP_HTTP_API http_request_datashare *_http_request_datashare_init_ex(http_reques } memset(share, 0, sizeof(http_request_datashare)); - HTTP_CHECK_CURL_INIT(share->ch, curl_share_init(), ;); - if (!share->ch) { + if (!HTTP_CURL_SHARE_CTOR(share->ch)) { if (free_share) { pefree(share, persistent); } @@ -180,7 +191,7 @@ PHP_HTTP_API void _http_request_datashare_dtor(http_request_datashare *share TSR zend_llist_destroy(share->handles); efree(share->handles); } - curl_share_cleanup(share->ch); + HTTP_CURL_SHARE_DTOR(&share->ch); #ifdef ZTS if (share->persistent) { int i; @@ -223,10 +234,13 @@ static void http_request_datashare_destroy_handles(void *el) { zval **r = (zval **) el; TSRMLS_FETCH(); - getObjectEx(http_request_object, obj, *r); - curl_easy_setopt(obj->request->ch, CURLOPT_SHARE, NULL); - zval_ptr_dtor(r); + { /* gcc 2.95 needs these braces */ + getObjectEx(http_request_object, obj, *r); + + curl_easy_setopt(obj->request->ch, CURLOPT_SHARE, NULL); + zval_ptr_dtor(r); + } } #ifdef ZTS