-#if HTTP_DEBUG_REQPOOLS
- fprintf(stderr, "Detaching %d requests from pool %p\n", count, pool);
-#endif
- /*
- * 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
- */
+
+ 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;
+ }
+ }
+ efree(handles);
+ }
+}
+/* }}} */
+
+/* {{{ void http_request_pool_apply_with_arg(http_request_pool *, http_request_pool_apply_with_arg_func, void *) */
+PHP_HTTP_API void _http_request_pool_apply_with_arg(http_request_pool *pool, http_request_pool_apply_with_arg_func cb, void *arg TSRMLS_DC)
+{
+ int count = zend_llist_count(&pool->handles);
+