Config.w32: add curl dependent libs
[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_LIBCURL
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 timeout->tv_sec = 0;
47 timeout->tv_usec = 0;
48
49 /* always returns CURLM_OK, check max_tout instead */
50 curl_multi_timeout(curl->handle->multi, &max_tout);
51
52 if (!max_tout) {
53 /* immediately */
54 return;
55 }
56
57 if (max_tout < 0) {
58 /* 5ms */
59 max_tout = 5;
60 } else if (max_tout > 1000) {
61 /* 1s */
62 max_tout = 1000;
63 }
64
65 timeout->tv_sec = max_tout / 1000;
66 timeout->tv_usec = (max_tout % 1000) * 1000;
67 }
68
69 PHP_HTTP_API void php_http_client_curl_responsehandler(php_http_client_t *client);
70 PHP_HTTP_API void php_http_client_curl_loop(php_http_client_t *client, curl_socket_t s, int curl_action);
71 PHP_HTTP_API php_http_client_ops_t *php_http_client_curl_get_ops(void);
72
73 PHP_MINIT_FUNCTION(http_client_curl);
74 PHP_MSHUTDOWN_FUNCTION(http_client_curl);
75
76 #endif /* PHP_HTTP_HAVE_LIBCURL */
77
78 #endif /* PHP_HTTP_CLIENT_CURL_H */
79
80 /*
81 * Local variables:
82 * tab-width: 4
83 * c-basic-offset: 4
84 * End:
85 * vim600: noet sw=4 ts=4 fdm=marker
86 * vim<600: noet sw=4 ts=4
87 */