+/* {{{ static void http_request_pool_event_callback(int, short, void *) */
+static void http_request_pool_event_callback(int socket, short action, void *event_data)
+{
+ http_request_pool_event *ev = event_data;
+ http_request_pool *pool = ev->pool;
+
+ if (pool->useevents) {
+ CURLMcode rc = CURLE_OK;
+ TSRMLS_FETCH_FROM_CTX(ev->pool->tsrm_ls);
+
+#if HTTP_DEBUG_REQPOOLS
+ {
+ static const char event_strings[][20] = {"NONE","TIMEOUT","READ","TIMEOUT|READ","WRITE","TIMEOUT|WRITE","READ|WRITE","TIMEOUT|READ|WRITE","SIGNAL"};
+ fprintf(stderr, "Event on socket %d (%s) event %p of pool %p\n", socket, event_strings[action], ev, pool);
+ }
+#endif
+
+ /* don't use 'ev' below this loop as it might 've been freed in the socket callback */
+ do {
+#ifdef HAVE_CURL_MULTI_SOCKET_ACTION
+ switch (action & (EV_READ|EV_WRITE)) {
+ case EV_READ:
+ rc = curl_multi_socket_action(pool->ch, socket, CURL_CSELECT_IN, &pool->unfinished);
+ break;
+ case EV_WRITE:
+ rc = curl_multi_socket_action(pool->ch, socket, CURL_CSELECT_OUT, &pool->unfinished);
+ break;
+ case EV_READ|EV_WRITE:
+ rc = curl_multi_socket_action(pool->ch, socket, CURL_CSELECT_IN|CURL_CSELECT_OUT, &pool->unfinished);
+ break;
+ default:
+ http_error_ex(HE_WARNING, HTTP_E_SOCKET, "Unknown event %d", (int) action);
+ return;
+ }
+#else
+ rc = curl_multi_socket(pool->ch, socket, &pool->unfinished);
+#endif
+ } 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
+ }
+ }
+}
+/* }}} */