X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_request_datashare_api.c;h=6c70f3f7f88fe8f47f288f239cbbfcf2f9d9df6f;hp=870e103382f58c39c67f9f515d4d1de1697aaf6a;hb=accf1817e811a7edabd687ef6105983f39f13942;hpb=7ea5445a6250f29f09d6b97db124cacf457f23c5 diff --git a/http_request_datashare_api.c b/http_request_datashare_api.c index 870e103..6c70f3f 100644 --- a/http_request_datashare_api.c +++ b/http_request_datashare_api.c @@ -21,9 +21,16 @@ #include "php_http_request_datashare_api.h" #include "php_http_request_api.h" #include "php_http_request_object.h" +#ifdef HTTP_HAVE_PERSISTENT_HANDLES +# include "php_http_persistent_handle_api.h" +#endif -#ifndef HAVE_CURL_SHARE_STRERROR -# define curl_share_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; @@ -44,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; \ @@ -53,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; } @@ -89,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); } @@ -130,8 +144,9 @@ PHP_HTTP_API STATUS _http_request_datashare_attach(http_request_datashare *share } } + HTTP_CHECK_CURL_INIT(obj->request->ch, http_curl_init_ex(obj->request->ch, obj->request), return FAILURE); if (CURLE_OK != (rc = curl_easy_setopt(obj->request->ch, CURLOPT_SHARE, share->ch))) { - http_error_ex(HE_WARNING, HTTP_E_REQUEST, "Could not attach HttpRequest object(#%d) to the HttpRequestDataShare: %s", Z_OBJ_HANDLE_P(request), curl_share_strerror(rc)); + http_error_ex(HE_WARNING, HTTP_E_REQUEST, "Could not attach HttpRequest object(#%d) to the HttpRequestDataShare: %s", Z_OBJ_HANDLE_P(request), curl_easy_strerror(rc)); return FAILURE; } @@ -176,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; @@ -219,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