X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_request_api.c;h=722e0b5a3ddd8b7e46d8eaeac0aed20deb757cb6;hb=724e5fabfb5ed0ff62c37a857c403db89eb5fb5e;hp=49b699b04dba59a7fea3b83827273d72f5b2a2a7;hpb=13941ce7e1264e891630fc7f909bbd11a1282721;p=m6w6%2Fext-http diff --git a/http_request_api.c b/http_request_api.c index 49b699b..722e0b5 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -114,11 +114,6 @@ static size_t http_curl_read_callback(void *, size_t, size_t, void *); static int http_curl_progress_callback(void *, double, double, double, double); static int http_curl_debug_callback(CURL *, curl_infotype, char *, size_t, void *); -typedef struct { - void ***tsrm_ctx; - void *data; -} http_curl_callback_ctx; - #define HTTP_CURL_CALLBACK_DATA(from, type, var) \ http_curl_callback_ctx *__CTX = (http_curl_callback_ctx *) (from); \ TSRMLS_FETCH_FROM_CTX(__CTX->tsrm_ctx); \ @@ -177,6 +172,12 @@ void *_http_request_data_copy(int type, void *data TSRMLS_DC) return data; } + case COPY_CONTEXT: + { + zend_llist_add_element(&HTTP_G(request).copies.contexts, &data); + return data; + } + default: { return data; @@ -199,6 +200,13 @@ void _http_request_data_free_slist(void *list) } /* }}} */ +/* {{{ _http_request_data_free_context(http_curl_callback_ctx **) */ +void _http_request_data_free_context(void *context) +{ + efree(*((http_curl_callback_ctx **) context)); +} +/* }}} */ + /* {{{ http_request_body *http_request_body_new() */ PHP_HTTP_API http_request_body *_http_request_body_new(TSRMLS_D) { @@ -811,7 +819,7 @@ PHP_HTTP_API STATUS _http_request_method_unregister(unsigned long method TSRMLS_ } /* }}} */ - +#ifdef ZEND_ENGINE_2 /* {{{ 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) { @@ -860,14 +868,17 @@ PHP_HTTP_API STATUS _http_request_pool_attach(http_request_pool *pool, zval *req if (SUCCESS != http_request_object_requesthandler(req, request, body)) { http_error_ex(E_WARNING, HTTP_E_CURL, "Could not initialize HttpRequest object for attaching to the HttpRequestPool"); - } else if (CURLM_OK != (code = curl_multi_add_handle(pool->ch, req->ch))) { - http_error_ex(E_WARNING, HTTP_E_CURL, "Could not attach HttpRequest object to the HttpRequestPool: %s", curl_multi_strerror(code)); } else { - req->pool = pool; - zval_add_ref(&request); - zend_llist_add_element(&pool->handles, &request); - zend_llist_add_element(&pool->bodies, &body); - return SUCCESS; + code = curl_multi_add_handle(pool->ch, req->ch); + if ((CURLM_OK != code) && (CURLM_CALL_MULTI_PERFORM != code)) { + http_error_ex(E_WARNING, HTTP_E_CURL, "Could not attach HttpRequest object to the HttpRequestPool: %s", curl_multi_strerror(code)); + } else { + req->pool = pool; + zval_add_ref(&request); + zend_llist_add_element(&pool->handles, &request); + zend_llist_add_element(&pool->bodies, &body); + return SUCCESS; + } } efree(body); } @@ -973,7 +984,7 @@ void _http_request_pool_responsehandler(zval **req TSRMLS_DC) #if HTTP_DEBUG_REQPOOLS fprintf(stderr, "Fetching data from request %p of pool %p\n", obj, obj->pool); #endif - http_request_object_responsehandler(obj, *req, NULL); + http_request_object_responsehandler(obj, *req); } /* }}} */ @@ -999,6 +1010,7 @@ static void http_request_pool_freehandle(zval **request, http_request_pool *pool #endif } /* }}} */ +#endif /* ZEND_ENGINE_2 */ /* {{{ char *http_request_methods[] */ static const char *const http_request_methods[] = { @@ -1065,7 +1077,7 @@ static http_curl_callback_ctx *_http_curl_callback_data(void *data TSRMLS_DC) http_curl_callback_ctx *ctx = emalloc(sizeof(http_curl_callback_ctx)); TSRMLS_SET_CTX(ctx->tsrm_ctx); ctx->data = data; - return ctx; + return http_request_data_copy(COPY_CONTEXT, ctx); } /* }}} */