X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_request_pool_api.c;h=437530350af87b17d01aa332b11ba424209b726b;hp=a38e73fc10f6f2f5a0148d97b0cf0f7aa0251ee3;hb=3d4001d8462ccf22372b7436e1a1c134e83b683e;hpb=559c156f3d0aeffe2c920d9275f47cfcdfc40bdf diff --git a/http_request_pool_api.c b/http_request_pool_api.c index a38e73f..4375303 100644 --- a/http_request_pool_api.c +++ b/http_request_pool_api.c @@ -59,6 +59,7 @@ PHP_HTTP_API http_request_pool *_http_request_pool_init(http_request_pool *pool } } + pool->sent = 0; pool->unfinished = 0; zend_llist_init(&pool->handles, sizeof(zval *), (llist_dtor_func_t) ZVAL_PTR_DTOR, 0); zend_llist_init(&pool->bodies, sizeof(http_request_body *), (llist_dtor_func_t) http_request_pool_freebody, 0); @@ -108,7 +109,7 @@ PHP_HTTP_API STATUS _http_request_pool_detach(http_request_pool *pool, zval *req { getObjectEx(http_request_object, req, request); #if HTTP_DEBUG_REQPOOLS - fprintf(stderr, "Detaching request %p (pool: %p) from pool %p\n", req, req->pool, pool); + fprintf(stderr, "Detaching request %p from pool %p\n", req, pool); #endif if (req->pool != pool) { http_error(E_WARNING, HTTP_E_CURL, "HttpRequest object is not attached to this HttpRequestPool"); @@ -135,7 +136,7 @@ PHP_HTTP_API void _http_request_pool_detach_all(http_request_pool *pool TSRMLS_D fprintf(stderr, "Detaching %d requests from pool %p\n", count, pool); #endif /* - * we cannot apply a function to the llist which actually detaches + * we cannot apply a function to the llist which actually detaches * the curl handle *and* removes the llist element -- * so let's get our hands dirty */ @@ -143,13 +144,14 @@ PHP_HTTP_API void _http_request_pool_detach_all(http_request_pool *pool TSRMLS_D int i = 0; zend_llist_position pos; zval **handle, **handles = emalloc(count * sizeof(zval *)); - + for (handle = zend_llist_get_first_ex(&pool->handles, &pos); handle; handle = zend_llist_get_next_ex(&pool->handles, &pos)) { handles[i++] = *handle; } for (i = 0; i < count; ++i) { http_request_pool_detach(pool, handles[i]); } + efree(handles); } } @@ -160,6 +162,12 @@ PHP_HTTP_API STATUS _http_request_pool_send(http_request_pool *pool TSRMLS_DC) #if HTTP_DEBUG_REQPOOLS fprintf(stderr, "Attempt to send requests of pool %p\n", pool); #endif + if (pool->sent) { + http_error(E_WARNING, HTTP_E_CURL, "HttpRequestPools can only be used once"); + return FAILURE; + } else { + pool->sent = 1; + } while (http_request_pool_perform(pool)) { #if HTTP_DEBUG_REQPOOLS fprintf(stderr, "%d unfinished requests of pool %p remaining\n", pool->unfinished, pool);