Merge branch 'v2.6.x'
[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 struct php_http_client_curl_globals {
19 php_http_client_driver_t driver;
20 };
21
22 typedef struct php_http_client_curl_handle {
23 CURLM *multi;
24 CURLSH *share;
25 } php_http_client_curl_handle_t;
26
27 typedef struct php_http_client_curl_ops {
28 void *(*init)();
29 void (*dtor)(void **ctx_ptr);
30 ZEND_RESULT_CODE (*once)(void *ctx);
31 ZEND_RESULT_CODE (*wait)(void *ctx, struct timeval *custom_timeout);
32 ZEND_RESULT_CODE (*exec)(void *ctx);
33 } php_http_client_curl_ops_t;
34
35 typedef struct php_http_client_curl {
36 php_http_client_curl_handle_t *handle;
37
38 int unfinished; /* int because of curl_multi_perform() */
39
40 void *ev_ctx;
41 php_http_client_curl_ops_t *ev_ops;
42 } php_http_client_curl_t;
43
44 static inline void php_http_client_curl_get_timeout(php_http_client_curl_t *curl, long max_tout, struct timeval *timeout)
45 {
46 if ((CURLM_OK == curl_multi_timeout(curl->handle->multi, &max_tout)) && (max_tout > 0)) {
47 timeout->tv_sec = max_tout / 1000;
48 timeout->tv_usec = (max_tout % 1000) * 1000;
49 } else {
50 timeout->tv_sec = 0;
51 timeout->tv_usec = 1000;
52 }
53 }
54
55 PHP_HTTP_API void php_http_client_curl_responsehandler(php_http_client_t *client);
56 PHP_HTTP_API void php_http_client_curl_loop(php_http_client_t *client, curl_socket_t s, int curl_action);
57 PHP_HTTP_API php_http_client_ops_t *php_http_client_curl_get_ops(void);
58
59 PHP_MINIT_FUNCTION(http_client_curl);
60 PHP_MSHUTDOWN_FUNCTION(http_client_curl);
61
62 #endif /* PHP_HTTP_HAVE_CURL */
63
64 #endif /* PHP_HTTP_CLIENT_CURL_H */
65
66 /*
67 * Local variables:
68 * tab-width: 4
69 * c-basic-offset: 4
70 * End:
71 * vim600: noet sw=4 ts=4 fdm=marker
72 * vim<600: noet sw=4 ts=4
73 */