+ } while (CURLM_CALL_MULTI_PERFORM == rc);
+
+ switch (rc) {
+ case CURLM_BAD_SOCKET:
+#if 0
+ fprintf(stderr, "!!! Bad socket: %d (%d)\n", socket, (int) action);
+#endif
+ case CURLM_OK:
+ break;
+ default:
+ http_error(HE_WARNING, HTTP_E_SOCKET, curl_multi_strerror(rc));
+ break;
+ }
+
+ http_request_pool_responsehandler(pool);
+
+ /* remove timeout if there are no transfers left */
+ if (!pool->unfinished && event_initialized(pool->timeout) && event_pending(pool->timeout, EV_TIMEOUT, NULL)) {
+ event_del(pool->timeout);
+#if HTTP_DEBUG_REQPOOLS
+ fprintf(stderr, "Removed timeout of pool %p\n", pool);
+#endif
+ }
+ }
+}
+/* }}} */
+
+/* {{{ static int http_request_pool_socket_callback(CURL *, curl_socket_t, int, void *, void *) */
+static int http_request_pool_socket_callback(CURL *easy, curl_socket_t sock, int action, void *socket_data, void *assign_data)
+{
+ http_request_pool *pool = socket_data;
+
+ if (pool->useevents) {
+ int events = EV_PERSIST;
+ http_request_pool_event *ev = assign_data;
+ TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
+
+ if (!ev) {
+ ev = ecalloc(1, sizeof(http_request_pool_event));
+ ev->pool = pool;
+ curl_multi_assign(pool->ch, sock, ev);
+ event_base_set(HTTP_G->request.pool.event.base, &ev->evnt);
+ } else {
+ event_del(&ev->evnt);
+ }
+
+#if HTTP_DEBUG_REQPOOLS
+ {
+ static const char action_strings[][8] = {"NONE", "IN", "OUT", "INOUT", "REMOVE"};
+ http_request *r;
+ curl_easy_getinfo(easy, CURLINFO_PRIVATE, &r);
+ fprintf(stderr, "Callback on socket %2d (%8s) event %p of pool %p (%d)\n", (int) sock, action_strings[action], ev, pool, pool->unfinished);
+ }
+#endif
+
+ switch (action) {
+ case CURL_POLL_IN:
+ events |= EV_READ;
+ break;
+ case CURL_POLL_OUT:
+ events |= EV_WRITE;
+ break;
+ case CURL_POLL_INOUT:
+ events |= EV_READ|EV_WRITE;
+ break;
+
+ case CURL_POLL_REMOVE:
+ efree(ev);
+ case CURL_POLL_NONE:
+ return 0;
+
+ default:
+ http_error_ex(HE_WARNING, HTTP_E_SOCKET, "Unknown socket action %d", action);
+ return -1;
+ }
+
+ event_set(&ev->evnt, sock, events, http_request_pool_event_callback, ev);
+ event_add(&ev->evnt, NULL);
+ }
+
+ return 0;
+}
+/* }}} */
+
+/* {{{ static void http_request_pool_timer_callback(CURLM *, long, void*) */
+static void http_request_pool_timer_callback(CURLM *multi, long timeout_ms, void *timer_data)
+{
+ http_request_pool *pool = timer_data;
+
+ if (pool->useevents) {
+ TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
+ struct timeval timeout;
+
+ if (!event_initialized(pool->timeout)) {
+ event_set(pool->timeout, -1, 0, http_request_pool_timeout_callback, pool);
+ event_base_set(HTTP_G->request.pool.event.base, pool->timeout);
+ } else if (event_pending(pool->timeout, EV_TIMEOUT, NULL)) {
+ event_del(pool->timeout);
+ }
+
+ if (timeout_ms > 0) {
+ timeout.tv_sec = timeout_ms / 1000;
+ timeout.tv_usec = (timeout_ms % 1000) * 1000;
+ } else {
+ http_request_pool_timeout(pool, &timeout);
+ }
+
+ event_add(pool->timeout, &timeout);
+
+#if HTTP_DEBUG_REQPOOLS
+ fprintf(stderr, "Updating timeout %lu (%lu, %lu) of pool %p\n", (ulong) timeout_ms, (ulong) timeout.tv_sec, (ulong) timeout.tv_usec, pool);
+#endif
+ }