- 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));
- } else {
- req->pool = NULL;
- zend_llist_del_element(&pool->handles, request, http_request_pool_compare_handles);
- return SUCCESS;
+/* {{{ void http_request_pool_apply(http_request_pool *, http_request_pool_apply_func) */
+PHP_HTTP_API void _http_request_pool_apply(http_request_pool *pool, http_request_pool_apply_func cb TSRMLS_DC)
+{
+ int count = zend_llist_count(&pool->handles);
+
+ if (count) {
+ 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;
+ }
+
+ /* should never happen */
+ if (i != count) {
+ zend_error(E_ERROR, "number of fetched request handles do not match overall count");
+ count = i;
+ }
+
+ for (i = 0; i < count; ++i) {
+ if (cb(pool, handles[i] TSRMLS_CC)) {
+ break;
+ }