modularize curl event handler
[m6w6/ext-http] / src / php_http_client_curl.h
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-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #ifndef PHP_HTTP_CLIENT_CURL_H
14 #define PHP_HTTP_CLIENT_CURL_H
15
16 #if PHP_HTTP_HAVE_CURL
17
18 typedef struct php_http_client_curl_handle {
19 CURLM *multi;
20 CURLSH *share;
21 } php_http_client_curl_handle_t;
22
23 typedef struct php_http_client_curl_ops {
24 void *(*init)();
25 void (*dtor)(void **ctx_ptr);
26 ZEND_RESULT_CODE (*once)(void *ctx);
27 ZEND_RESULT_CODE (*wait)(void *ctx, struct timeval *custom_timeout);
28 ZEND_RESULT_CODE (*exec)(void *ctx);
29 } php_http_client_curl_ops_t;
30
31 typedef struct php_http_client_curl {
32 php_http_client_curl_handle_t *handle;
33
34 int unfinished; /* int because of curl_multi_perform() */
35
36 void *ev_ctx;
37 php_http_client_curl_ops_t *ev_ops;
38 } php_http_client_curl_t;
39
40 static inline void php_http_client_curl_get_timeout(php_http_client_curl_t *curl, long max_tout, struct timeval *timeout)
41 {
42 if ((CURLM_OK == curl_multi_timeout(curl->handle->multi, &max_tout)) && (max_tout > 0)) {
43 timeout->tv_sec = max_tout / 1000;
44 timeout->tv_usec = (max_tout % 1000) * 1000;
45 } else {
46 timeout->tv_sec = 0;
47 timeout->tv_usec = 1000;
48 }
49 }
50
51 PHP_HTTP_API void php_http_client_curl_responsehandler(php_http_client_t *client);
52
53 PHP_MINIT_FUNCTION(http_client_curl);
54 PHP_MSHUTDOWN_FUNCTION(http_client_curl);
55 #endif /* PHP_HTTP_HAVE_CURL */
56
57 #endif /* PHP_HTTP_CLIENT_CURL_H */
58
59 /*
60 * Local variables:
61 * tab-width: 4
62 * c-basic-offset: 4
63 * End:
64 * vim600: noet sw=4 ts=4 fdm=marker
65 * vim<600: noet sw=4 ts=4
66 */