X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_request_pool_api.c;h=282fda9ed2df25b2becac2c64ccd09e617642fb0;hp=b62eeea7674bcb8603b9e791fd24823031b99b86;hb=c71fd3a3bcc7231f2efc4c7520888880f42a6b3c;hpb=19cad54672b6babfac2b7c9c64c415c9a24b888a diff --git a/http_request_pool_api.c b/http_request_pool_api.c index b62eeea..282fda9 100644 --- a/http_request_pool_api.c +++ b/http_request_pool_api.c @@ -34,6 +34,12 @@ # define HTTP_DEBUG_REQPOOLS 0 #endif +ZEND_EXTERN_MODULE_GLOBALS(http); + +#ifndef HAVE_CURL_MULTI_STRERROR +# define curl_multi_strerror(dummy) "unknown error" +#endif + static void http_request_pool_freebody(http_request_body **body); static int http_request_pool_compare_handles(void *h1, void *h2); @@ -51,7 +57,7 @@ PHP_HTTP_API http_request_pool *_http_request_pool_init(http_request_pool *pool if (!pool->ch) { if (!(pool->ch = curl_multi_init())) { - http_error(E_WARNING, HTTP_E_CURL, "Could not initialize curl"); + http_error(HE_WARNING, HTTP_E_REQUEST, "Could not initialize curl"); if (free_pool) { efree(pool); } @@ -77,18 +83,17 @@ PHP_HTTP_API STATUS _http_request_pool_attach(http_request_pool *pool, zval *req fprintf(stderr, "Attaching HttpRequest(#%d) %p to pool %p\n", Z_OBJ_HANDLE_P(request), req, pool); #endif if (req->pool) { - http_error_ex(E_WARNING, HTTP_E_CURL, "HttpRequest object(#%d) is already member of %s HttpRequestPool", Z_OBJ_HANDLE_P(request), req->pool == pool ? "this" : "another"); + http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "HttpRequest object(#%d) is already member of %s HttpRequestPool", Z_OBJ_HANDLE_P(request), req->pool == pool ? "this" : "another"); } else { http_request_body *body = http_request_body_new(); - zval *info = GET_PROP_EX(req, request, responseInfo); - 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"); + if (SUCCESS != http_request_pool_requesthandler(request, body)) { + http_error_ex(HE_WARNING, HTTP_E_REQUEST, "Could not initialize HttpRequest object for attaching to the HttpRequestPool"); } else { CURLMcode 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)); + http_error_ex(HE_WARNING, HTTP_E_REQUEST_POOL, "Could not attach HttpRequest object to the HttpRequestPool: %s", curl_multi_strerror(code)); } else { req->pool = pool; @@ -123,7 +128,7 @@ PHP_HTTP_API STATUS _http_request_pool_detach(http_request_pool *pool, zval *req fprintf(stderr, "HttpRequest object(#%d) %p is not attached to any HttpRequestPool\n", Z_OBJ_HANDLE_P(request), req); #endif } else if (req->pool != pool) { - http_error_ex(E_WARNING, HTTP_E_CURL, "HttpRequest object(#%d) is not attached to this HttpRequestPool", Z_OBJ_HANDLE_P(request)); + http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "HttpRequest object(#%d) is not attached to this HttpRequestPool", Z_OBJ_HANDLE_P(request)); } else { CURLMcode code; @@ -133,7 +138,7 @@ PHP_HTTP_API STATUS _http_request_pool_detach(http_request_pool *pool, zval *req fprintf(stderr, "> %d HttpRequests remaining in pool %p\n", zend_llist_count(&pool->handles), pool); #endif if (CURLM_OK != (code = curl_multi_remove_handle(pool->ch, req->ch))) { - http_error_ex(E_WARNING, HTTP_E_CURL, "Could not detach HttpRequest object from the HttpRequestPool: %s", curl_multi_strerror(code)); + http_error_ex(HE_WARNING, HTTP_E_REQUEST_POOL, "Could not detach HttpRequest object from the HttpRequestPool: %s", curl_multi_strerror(code)); } else { return SUCCESS; } @@ -181,7 +186,11 @@ PHP_HTTP_API STATUS _http_request_pool_send(http_request_pool *pool TSRMLS_DC) fprintf(stderr, "> %d unfinished requests of pool %p remaining\n", pool->unfinished, pool); #endif if (SUCCESS != http_request_pool_select(pool)) { - http_error(E_WARNING, HTTP_E_CURL, "Socket error"); +#ifdef PHP_WIN32 + http_error(HE_WARNING, HTTP_E_SOCKET, WSAGetLastError()); +#else + http_error(HE_WARNING, HTTP_E_SOCKET, strerror(errno)); +#endif return FAILURE; } } @@ -230,6 +239,18 @@ PHP_HTTP_API int _http_request_pool_perform(http_request_pool *pool) } /* }}} */ +/* {{{ STATUS http_request_pool_requesthandler(zval *, http_request_body *) */ +STATUS _http_request_pool_requesthandler(zval *request, http_request_body *body TSRMLS_DC) +{ + getObjectEx(http_request_object, req, request); + if (SUCCESS == http_request_object_requesthandler(req, request, body)) { + http_request_conv(req->ch, &req->response, &req->request); + return SUCCESS; + } + return FAILURE; +} +/* }}} */ + /* {{{ void http_request_pool_responsehandler(zval **) */ void _http_request_pool_responsehandler(zval **req TSRMLS_DC) {