- make libevent usable by choice at runtime
[m6w6/ext-http] / http_request_pool_api.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2007, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 /* $Id$ */
14
15 #define HTTP_WANT_CURL
16 #define HTTP_WANT_EVENT
17 #include "php_http.h"
18
19 #if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
20
21 #include "php_http_api.h"
22 #include "php_http_exception_object.h"
23 #include "php_http_persistent_handle_api.h"
24 #include "php_http_request_api.h"
25 #include "php_http_request_object.h"
26 #include "php_http_request_pool_api.h"
27 #include "php_http_requestpool_object.h"
28
29 #ifndef HTTP_DEBUG_REQPOOLS
30 # define HTTP_DEBUG_REQPOOLS 0
31 #endif
32
33 #ifdef HTTP_HAVE_EVENT
34 typedef struct _http_request_pool_event_t {
35 struct event evnt;
36 http_request_pool *pool;
37 } http_request_pool_event;
38
39 static inline void http_request_pool_update_timeout(http_request_pool *pool);
40 static void http_request_pool_timeout_callback(int socket, short action, void *event_data);
41 static void http_request_pool_event_callback(int socket, short action, void *event_data);
42 static int http_request_pool_socket_callback(CURL *easy, curl_socket_t s, int action, void *, void *);
43 #endif
44
45 static int http_request_pool_compare_handles(void *h1, void *h2);
46
47 PHP_MINIT_FUNCTION(http_request_pool)
48 {
49 if (SUCCESS != http_persistent_handle_provide("http_request_pool", curl_multi_init, (http_persistent_handle_dtor) curl_multi_cleanup, NULL)) {
50 return FAILURE;
51 }
52 return SUCCESS;
53 }
54
55 #ifdef HTTP_HAVE_EVENT
56 PHP_RINIT_FUNCTION(http_request_pool)
57 {
58 if (!HTTP_G->request.pool.event.base && !(HTTP_G->request.pool.event.base = event_init())) {
59 return FAILURE;
60 }
61
62 return SUCCESS;
63 }
64 #endif
65
66 /* {{{ http_request_pool *http_request_pool_init(http_request_pool *) */
67 PHP_HTTP_API http_request_pool *_http_request_pool_init(http_request_pool *pool TSRMLS_DC)
68 {
69 zend_bool free_pool;
70
71 #if HTTP_DEBUG_REQPOOLS
72 fprintf(stderr, "Initializing request pool %p\n", pool);
73 #endif
74
75 if ((free_pool = (!pool))) {
76 pool = emalloc(sizeof(http_request_pool));
77 pool->ch = NULL;
78 }
79
80 if (SUCCESS != http_persistent_handle_acquire("http_request_pool", &pool->ch)) {
81 if (free_pool) {
82 efree(pool);
83 }
84 return NULL;
85 }
86
87 TSRMLS_SET_CTX(pool->tsrm_ls);
88
89 #if HTTP_HAVE_EVENT
90 pool->timeout = ecalloc(1, sizeof(struct event));
91 curl_multi_setopt(pool->ch, CURLMOPT_SOCKETDATA, pool);
92 curl_multi_setopt(pool->ch, CURLMOPT_SOCKETFUNCTION, http_request_pool_socket_callback);
93 #endif
94
95 pool->unfinished = 0;
96 zend_llist_init(&pool->finished, sizeof(zval *), (llist_dtor_func_t) ZVAL_PTR_DTOR, 0);
97 zend_llist_init(&pool->handles, sizeof(zval *), (llist_dtor_func_t) ZVAL_PTR_DTOR, 0);
98
99 #if HTTP_DEBUG_REQPOOLS
100 fprintf(stderr, "Initialized request pool %p\n", pool);
101 #endif
102
103 return pool;
104 }
105 /* }}} */
106
107 /* {{{ STATUS http_request_pool_attach(http_request_pool *, zval *) */
108 PHP_HTTP_API STATUS _http_request_pool_attach(http_request_pool *pool, zval *request)
109 {
110 TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
111 getObjectEx(http_request_object, req, request);
112
113 #if HTTP_DEBUG_REQPOOLS
114 fprintf(stderr, "Attaching HttpRequest(#%d) %p to pool %p\n", Z_OBJ_HANDLE_P(request), req, pool);
115 #endif
116
117 if (req->pool) {
118 http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "HttpRequest object(#%d) is already member of %s HttpRequestPool", Z_OBJ_HANDLE_P(request), req->pool == pool ? "this" : "another");
119 } else if (SUCCESS != http_request_object_requesthandler(req, request)) {
120 http_error_ex(HE_WARNING, HTTP_E_REQUEST, "Could not initialize HttpRequest object(#%d) for attaching to the HttpRequestPool", Z_OBJ_HANDLE_P(request));
121 } else {
122 CURLMcode code = curl_multi_add_handle(pool->ch, req->request->ch);
123
124 while (CURLM_CALL_MULTI_PERFORM == code) {
125 #ifdef HTTP_HAVE_EVENT
126 if (pool->useevents) {
127 code = curl_multi_socket_all(pool->ch, &pool->unfinished);
128 } else {
129 #endif
130 code = curl_multi_perform(pool->ch, &pool->unfinished);
131 #ifdef HTTP_HAVE_EVENT
132 }
133 #endif
134 }
135 if (CURLM_OK != code) {
136 http_error_ex(HE_WARNING, HTTP_E_REQUEST_POOL, "Could not attach HttpRequest object(#%d) to the HttpRequestPool: %s", Z_OBJ_HANDLE_P(request), curl_multi_strerror(code));
137 } else {
138 req->pool = pool;
139
140 ZVAL_ADDREF(request);
141 zend_llist_add_element(&pool->handles, &request);
142
143 #if HTTP_DEBUG_REQPOOLS
144 fprintf(stderr, "> %d HttpRequests attached to pool %p\n", zend_llist_count(&pool->handles), pool);
145 #endif
146 return SUCCESS;
147 }
148 }
149 return FAILURE;
150 }
151 /* }}} */
152
153 /* {{{ STATUS http_request_pool_detach(http_request_pool *, zval *) */
154 PHP_HTTP_API STATUS _http_request_pool_detach(http_request_pool *pool, zval *request)
155 {
156 CURLMcode code;
157 TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
158 getObjectEx(http_request_object, req, request);
159
160 #if HTTP_DEBUG_REQPOOLS
161 fprintf(stderr, "Detaching HttpRequest(#%d) %p from pool %p\n", Z_OBJ_HANDLE_P(request), req, pool);
162 #endif
163
164 if (!req->pool) {
165 /* not attached to any pool */
166 #if HTTP_DEBUG_REQPOOLS
167 fprintf(stderr, "HttpRequest object(#%d) %p is not attached to any HttpRequestPool\n", Z_OBJ_HANDLE_P(request), req);
168 #endif
169 } else if (req->pool != pool) {
170 http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "HttpRequest object(#%d) is not attached to this HttpRequestPool", Z_OBJ_HANDLE_P(request));
171 } else if (req->request->_in_progress_cb) {
172 http_error_ex(HE_WARNING, HTTP_E_REQUEST_POOL, "HttpRequest object(#%d) cannot be detached from the HttpRequestPool while executing the progress callback", Z_OBJ_HANDLE_P(request));
173 } else if (CURLM_OK != (code = curl_multi_remove_handle(pool->ch, req->request->ch))) {
174 http_error_ex(HE_WARNING, HTTP_E_REQUEST_POOL, "Could not detach HttpRequest object(#%d) from the HttpRequestPool: %s", Z_OBJ_HANDLE_P(request), curl_multi_strerror(code));
175 } else {
176 req->pool = NULL;
177 zend_llist_del_element(&pool->finished, request, http_request_pool_compare_handles);
178 zend_llist_del_element(&pool->handles, request, http_request_pool_compare_handles);
179
180 #if HTTP_DEBUG_REQPOOLS
181 fprintf(stderr, "> %d HttpRequests remaining in pool %p\n", zend_llist_count(&pool->handles), pool);
182 #endif
183
184 return SUCCESS;
185 }
186 return FAILURE;
187 }
188 /* }}} */
189
190 /* {{{ void http_request_pool_apply(http_request_pool *, http_request_pool_apply_func) */
191 PHP_HTTP_API void _http_request_pool_apply(http_request_pool *pool, http_request_pool_apply_func cb)
192 {
193 int count = zend_llist_count(&pool->handles);
194
195 if (count) {
196 int i = 0;
197 zend_llist_position pos;
198 zval **handle, **handles = emalloc(count * sizeof(zval *));
199
200 for (handle = zend_llist_get_first_ex(&pool->handles, &pos); handle; handle = zend_llist_get_next_ex(&pool->handles, &pos)) {
201 handles[i++] = *handle;
202 }
203
204 /* should never happen */
205 if (i != count) {
206 zend_error(E_ERROR, "number of fetched request handles do not match overall count");
207 count = i;
208 }
209
210 for (i = 0; i < count; ++i) {
211 if (cb(pool, handles[i])) {
212 break;
213 }
214 }
215 efree(handles);
216 }
217 }
218 /* }}} */
219
220 /* {{{ void http_request_pool_apply_with_arg(http_request_pool *, http_request_pool_apply_with_arg_func, void *) */
221 PHP_HTTP_API void _http_request_pool_apply_with_arg(http_request_pool *pool, http_request_pool_apply_with_arg_func cb, void *arg)
222 {
223 int count = zend_llist_count(&pool->handles);
224
225 if (count) {
226 int i = 0;
227 zend_llist_position pos;
228 zval **handle, **handles = emalloc(count * sizeof(zval *));
229
230 for (handle = zend_llist_get_first_ex(&pool->handles, &pos); handle; handle = zend_llist_get_next_ex(&pool->handles, &pos)) {
231 handles[i++] = *handle;
232 }
233
234 /* should never happen */
235 if (i != count) {
236 zend_error(E_ERROR, "number of fetched request handles do not match overall count");
237 count = i;
238 }
239
240 for (i = 0; i < count; ++i) {
241 if (cb(pool, handles[i], arg)) {
242 break;
243 }
244 }
245 efree(handles);
246 }
247 }
248 /* }}} */
249
250 /* {{{ void http_request_pool_detach_all(http_request_pool *) */
251 PHP_HTTP_API void _http_request_pool_detach_all(http_request_pool *pool)
252 {
253 #if HTTP_DEBUG_REQPOOLS
254 fprintf(stderr, "Detaching %d requests from pool %p\n", zend_llist_count(&pool->handles), pool);
255 #endif
256 http_request_pool_apply(pool, _http_request_pool_detach);
257 }
258 /* }}} */
259
260 /* {{{ STATUS http_request_pool_send(http_request_pool *) */
261 PHP_HTTP_API STATUS _http_request_pool_send(http_request_pool *pool)
262 {
263 TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
264
265 #if HTTP_DEBUG_REQPOOLS
266 fprintf(stderr, "Attempt to send %d requests of pool %p\n", zend_llist_count(&pool->handles), pool);
267 #endif
268
269 #ifdef HTTP_HAVE_EVENT
270 if (pool->useevents) {
271 while (CURLM_CALL_MULTI_PERFORM == curl_multi_socket_all(pool->ch, &pool->unfinished));
272 http_request_pool_update_timeout(pool);
273
274 event_base_dispatch(HTTP_G->request.pool.event.base);
275 } else
276 #endif
277 {
278 while (http_request_pool_perform(pool)) {
279 if (SUCCESS != http_request_pool_select(pool)) {
280 #ifdef PHP_WIN32
281 /* see http://msdn.microsoft.com/library/en-us/winsock/winsock/windows_sockets_error_codes_2.asp */
282 http_error_ex(HE_WARNING, HTTP_E_SOCKET, "WinSock error: %d", WSAGetLastError());
283 #else
284 http_error(HE_WARNING, HTTP_E_SOCKET, strerror(errno));
285 #endif
286 return FAILURE;
287 }
288 }
289 }
290
291 #if HTTP_DEBUG_REQPOOLS
292 fprintf(stderr, "Finished sending %d HttpRequests of pool %p (still unfinished: %d)\n", zend_llist_count(&pool->handles), pool, pool->unfinished);
293 #endif
294
295 return SUCCESS;
296 }
297 /* }}} */
298
299 /* {{{ void http_request_pool_dtor(http_request_pool *) */
300 PHP_HTTP_API void _http_request_pool_dtor(http_request_pool *pool)
301 {
302 TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
303
304 #if HTTP_DEBUG_REQPOOLS
305 fprintf(stderr, "Destructing request pool %p\n", pool);
306 #endif
307
308 #if HTTP_HAVE_EVENT
309 efree(pool->timeout);
310 #endif
311
312 pool->unfinished = 0;
313 zend_llist_clean(&pool->finished);
314 zend_llist_clean(&pool->handles);
315 http_persistent_handle_release("http_request_pool", &pool->ch);
316 }
317 /* }}} */
318
319 #ifdef PHP_WIN32
320 # define SELECT_ERROR SOCKET_ERROR
321 #else
322 # define SELECT_ERROR -1
323 #endif
324
325 /* {{{ STATUS http_request_pool_select(http_request_pool *) */
326 PHP_HTTP_API STATUS _http_request_pool_select(http_request_pool *pool)
327 {
328 int MAX;
329 fd_set R, W, E;
330 struct timeval timeout;
331
332 #ifdef HTTP_HAVE_EVENT
333 if (pool->useevents) {
334 TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
335 http_error(HE_WARNING, HTTP_E_RUNTIME, "not implemented; use HttpRequest callbacks");
336 return FAILURE;
337 }
338 #endif
339
340 http_request_pool_timeout(pool, &timeout);
341
342 FD_ZERO(&R);
343 FD_ZERO(&W);
344 FD_ZERO(&E);
345
346 if (CURLM_OK == curl_multi_fdset(pool->ch, &R, &W, &E, &MAX)) {
347 if (MAX == -1) {
348 http_sleep((double) timeout.tv_sec + (double) (timeout.tv_usec / HTTP_MCROSEC));
349 return SUCCESS;
350 } else if (SELECT_ERROR != select(MAX + 1, &R, &W, &E, &timeout)) {
351 return SUCCESS;
352 }
353 }
354 return FAILURE;
355 }
356 /* }}} */
357
358 /* {{{ int http_request_pool_perform(http_request_pool *) */
359 PHP_HTTP_API int _http_request_pool_perform(http_request_pool *pool)
360 {
361 TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
362
363 #ifdef HTTP_HAVE_EVENT
364 if (pool->useevents) {
365 http_error(HE_WARNING, HTTP_E_RUNTIME, "not implemented; use HttpRequest callbacks");
366 return FAILURE;
367 }
368 #endif
369
370 while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(pool->ch, &pool->unfinished));
371
372 #if HTTP_DEBUG_REQPOOLS
373 fprintf(stderr, "%u unfinished requests of pool %p remaining\n", pool->unfinished, pool);
374 #endif
375
376 http_request_pool_responsehandler(pool);
377
378 return pool->unfinished;
379 }
380 /* }}} */
381
382 /* {{{ void http_request_pool_responsehandler(http_request_pool *) */
383 void _http_request_pool_responsehandler(http_request_pool *pool)
384 {
385 CURLMsg *msg;
386 int remaining = 0;
387 TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
388
389 do {
390 msg = curl_multi_info_read(pool->ch, &remaining);
391 if (msg && CURLMSG_DONE == msg->msg) {
392 if (CURLE_OK != msg->data.result) {
393 http_request *r = NULL;
394 curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &r);
395 http_error_ex(HE_WARNING, HTTP_E_REQUEST, "%s; %s (%s)", curl_easy_strerror(msg->data.result), r?r->_error:"", r?r->url:"");
396 }
397 http_request_pool_apply_with_arg(pool, _http_request_pool_apply_responsehandler, msg->easy_handle);
398 }
399 } while (remaining);
400 }
401 /* }}} */
402
403 /* {{{ int http_request_pool_apply_responsehandler(http_request_pool *, zval *, void *) */
404 int _http_request_pool_apply_responsehandler(http_request_pool *pool, zval *req, void *ch)
405 {
406 TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
407 getObjectEx(http_request_object, obj, req);
408
409 if ((!ch) || obj->request->ch == (CURL *) ch) {
410
411 #if HTTP_DEBUG_REQPOOLS
412 fprintf(stderr, "Fetching data from HttpRequest(#%d) %p of pool %p\n", Z_OBJ_HANDLE_P(req), obj, obj->pool);
413 #endif
414
415 ZVAL_ADDREF(req);
416 zend_llist_add_element(&obj->pool->finished, &req);
417 http_request_object_responsehandler(obj, req);
418 return 1;
419 }
420 return 0;
421 }
422 /* }}} */
423
424 /* {{{ struct timeval *_http_request_pool_timeout(http_request_pool *, struct timeval *) */
425 struct timeval *_http_request_pool_timeout(http_request_pool *pool, struct timeval *timeout)
426 {
427 #ifdef HAVE_CURL_MULTI_TIMEOUT
428 long max_tout = 1000;
429
430 if ((CURLM_OK == curl_multi_timeout(pool->ch, &max_tout)) && (max_tout != -1)) {
431 timeout->tv_sec = max_tout / 1000;
432 timeout->tv_usec = (max_tout % 1000) * 1000;
433 } else {
434 #endif
435 timeout->tv_sec = 1;
436 timeout->tv_usec = 0;
437 #ifdef HAVE_CURL_MULTI_TIMEOUT
438 }
439 #endif
440
441 #if HTTP_DEBUG_REQPOOLS
442 fprintf(stderr, "Calculating timeout (%lu, %lu) of pool %p\n", (ulong) timeout->tv_sec, (ulong) timeout->tv_usec, pool);
443 #endif
444
445 return timeout;
446 }
447 /* }}} */
448
449 /*#*/
450
451 /* {{{ static int http_request_pool_compare_handles(void *, void *) */
452 static int http_request_pool_compare_handles(void *h1, void *h2)
453 {
454 return (Z_OBJ_HANDLE_PP((zval **) h1) == Z_OBJ_HANDLE_P((zval *) h2));
455 }
456 /* }}} */
457
458 #ifdef HTTP_HAVE_EVENT
459 /* {{{ static void http_request_pool_update_timeout(http_request_pool *) */
460 static inline void http_request_pool_update_timeout(http_request_pool *pool)
461 {
462 struct timeval timeout;
463 TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
464
465 if (event_initialized(pool->timeout)) {
466 event_del(pool->timeout);
467 }
468
469 if (pool->unfinished) {
470 event_set(pool->timeout, -1, 0, http_request_pool_timeout_callback, pool);
471 event_base_set(HTTP_G->request.pool.event.base, pool->timeout);
472 event_add(pool->timeout, http_request_pool_timeout(pool, &timeout));
473
474 #if HTTP_DEBUG_REQPOOLS
475 fprintf(stderr, "Updating timeout (%lu, %lu) of pool %p\n", (ulong) timeout.tv_sec, (ulong) timeout.tv_usec, pool);
476 #endif
477 }
478 #if HTTP_DEBUG_REQPOOLS
479 else fprintf(stderr, "Removed timeout of pool %p\n", pool);
480 #endif
481 }
482 /* }}} */
483
484 /* {{{ static void http_request_pool_timeout_callback(int, short, void *) */
485 static void http_request_pool_timeout_callback(int socket, short action, void *event_data)
486 {
487 CURLMcode rc;
488 http_request_pool *pool = event_data;
489 TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
490
491 #if HTTP_DEBUG_REQPOOLS
492 fprintf(stderr, "Timeout occurred of pool %p\n", pool);
493 #endif
494
495 while (CURLM_CALL_MULTI_PERFORM == (rc = curl_multi_socket(pool->ch, CURL_SOCKET_TIMEOUT, &pool->unfinished)));
496
497 if (CURLM_OK != rc) {
498 http_error(HE_WARNING, HTTP_E_SOCKET, curl_multi_strerror(rc));
499 }
500
501 http_request_pool_update_timeout(pool);
502 }
503 /* }}} */
504
505 /* {{{ static void http_request_pool_event_callback(int, short, void *) */
506 static void http_request_pool_event_callback(int socket, short action, void *event_data)
507 {
508 CURLMcode rc = CURLE_OK;
509 http_request_pool_event *ev = event_data;
510 http_request_pool *pool = ev->pool;
511 TSRMLS_FETCH_FROM_CTX(ev->pool->tsrm_ls);
512
513 #if HTTP_DEBUG_REQPOOLS
514 {
515 static const char event_strings[][20] = {"NONE","TIMEOUT","READ","TIMEOUT|READ","WRITE","TIMEOUT|WRITE","READ|WRITE","TIMEOUT|READ|WRITE","SIGNAL"};
516 fprintf(stderr, "Event on socket %d (%s) event %p of pool %p\n", socket, event_strings[action], ev, pool);
517 }
518 #endif
519
520 /* don't use 'ev' below this loop as it might 've been freed in the socket callback */
521 do {
522 #ifdef HAVE_CURL_MULTI_SOCKET_ACTION
523 switch (action & (EV_READ|EV_WRITE)) {
524 case EV_READ:
525 rc = curl_multi_socket_action(pool->ch, socket, CURL_CSELECT_IN, &pool->unfinished);
526 break;
527 case EV_WRITE:
528 rc = curl_multi_socket_action(pool->ch, socket, CURL_CSELECT_OUT, &pool->unfinished);
529 break;
530 case EV_READ|EV_WRITE:
531 rc = curl_multi_socket_action(pool->chm socket, CURL_CSELECT_IN|CURL_CSELECT_OUT, &pool->unfinished);
532 break;
533 default:
534 http_error(HE_WARNING, HTTP_E_SOCKET, "Unknown event %d", (int) action);
535 return;
536 }
537 #else
538 rc = curl_multi_socket(pool->ch, socket, &pool->unfinished);
539 #endif
540 } while (CURLM_CALL_MULTI_PERFORM == rc);
541
542 #if HTTP_DEBUG_REQPOOLS
543 fprintf(stderr, "%u unfinished requests of pool %p remaining\n", pool->unfinished, pool);
544 #endif
545
546 if (CURLM_OK != rc) {
547 http_error(HE_WARNING, HTTP_E_SOCKET, curl_multi_strerror(rc));
548 }
549
550 http_request_pool_responsehandler(pool);
551 http_request_pool_update_timeout(pool);
552 }
553 /* }}} */
554
555 /* {{{ static int http_request_pool_socket_callback(CURL *, curl_socket_t, int, void *, void *) */
556 static int http_request_pool_socket_callback(CURL *easy, curl_socket_t sock, int action, void *socket_data, void *assign_data)
557 {
558 int events = EV_PERSIST;
559 http_request_pool *pool = socket_data;
560 http_request_pool_event *ev = assign_data;
561 TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
562
563 if (!ev) {
564 ev = ecalloc(1, sizeof(http_request_pool_event));
565 ev->pool = pool;
566 curl_multi_assign(pool->ch, sock, ev);
567 fprintf(stderr, "+%2d\n", sock);
568 } else {
569 event_del(&ev->evnt);
570 fprintf(stderr, "-%2d\n", sock);
571 }
572
573 #if HTTP_DEBUG_REQPOOLS
574 {
575 static const char action_strings[][8] = {"NONE", "IN", "OUT", "INOUT", "REMOVE"};
576 http_request *r;
577 curl_easy_getinfo(easy, CURLINFO_PRIVATE, &r);
578 fprintf(stderr, "Callback on socket %d (%s) event %p of pool %p (%s)\n", (int) sock, action_strings[action], ev, pool, r->url);
579 }
580 #endif
581
582 switch (action) {
583 case CURL_POLL_IN:
584 events |= EV_READ;
585 break;
586 case CURL_POLL_OUT:
587 events |= EV_WRITE;
588 break;
589 case CURL_POLL_INOUT:
590 events |= EV_READ|EV_WRITE;
591 break;
592
593 case CURL_POLL_REMOVE:
594 efree(ev);
595 case CURL_POLL_NONE:
596 return 0;
597
598 default:
599 http_error_ex(HE_WARNING, HTTP_E_SOCKET, "Unknown socket action %d", action);
600 return -1;
601 }
602
603 event_set(&ev->evnt, sock, events, http_request_pool_event_callback, ev);
604 event_base_set(HTTP_G->request.pool.event.base, &ev->evnt);
605 event_add(&ev->evnt, NULL);
606
607 return 0;
608 }
609 /* }}} */
610 #endif /* HTTP_HAVE_EVENT */
611
612 #endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */
613
614
615 /*
616 * Local variables:
617 * tab-width: 4
618 * c-basic-offset: 4
619 * End:
620 * vim600: noet sw=4 ts=4 fdm=marker
621 * vim<600: noet sw=4 ts=4
622 */
623