+ 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);
+ } 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 %d (%s) event %p of pool %p (%s)\n", (int) sock, action_strings[action], ev, pool, r->url);
+ }
+#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_base_set(HTTP_G->request.pool.event.base, &ev->evnt);
+ event_add(&ev->evnt, NULL);
+ }
+
+ return 0;