- proper request pool cleanup
[m6w6/ext-http] / http_requestpool_object.c
1 /*
2 +----------------------------------------------------------------------+
3 | PECL :: http |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
14 */
15
16 /* $Id$ */
17
18
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #endif
22
23 #ifdef HTTP_HAVE_CURL
24 # ifdef PHP_WIN32
25 # include <winsock2.h>
26 # endif
27 # include <curl/curl.h>
28 #endif
29
30 #include "php.h"
31
32 #include "php_http_std_defs.h"
33 #include "php_http_requestpool_object.h"
34 #include "php_http_request_api.h"
35
36 #ifdef ZEND_ENGINE_2
37 #ifdef HTTP_HAVE_CURL
38
39 #define http_requestpool_object_declare_default_properties() _http_requestpool_object_declare_default_properties(TSRMLS_C)
40 static inline void _http_requestpool_object_declare_default_properties(TSRMLS_D);
41
42 zend_class_entry *http_requestpool_object_ce;
43 zend_function_entry http_requestpool_object_fe[] = {
44 PHP_ME(HttpRequestPool, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
45 PHP_ME(HttpRequestPool, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
46 PHP_ME(HttpRequestPool, attach, NULL, ZEND_ACC_PUBLIC)
47 PHP_ME(HttpRequestPool, detach, NULL, ZEND_ACC_PUBLIC)
48 PHP_ME(HttpRequestPool, send, NULL, ZEND_ACC_PUBLIC)
49
50 {NULL, NULL, NULL}
51 };
52 static zend_object_handlers http_requestpool_object_handlers;
53
54 void _http_requestpool_object_init(INIT_FUNC_ARGS)
55 {
56 HTTP_REGISTER_CLASS_EX(HttpRequestPool, http_requestpool_object, NULL, 0);
57 }
58
59 zend_object_value _http_requestpool_object_new(zend_class_entry *ce TSRMLS_DC)
60 {
61 zend_object_value ov;
62 http_requestpool_object *o;
63
64 o = ecalloc(1, sizeof(http_requestpool_object));
65 o->zo.ce = ce;
66
67 http_request_pool_init(&o->pool);
68
69 ALLOC_HASHTABLE(OBJ_PROP(o));
70 zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0);
71 zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
72
73 ov.handle = zend_objects_store_put(o, (zend_objects_store_dtor_t) zend_objects_destroy_object, http_requestpool_object_free, NULL TSRMLS_CC);
74 ov.handlers = &http_requestpool_object_handlers;
75
76 return ov;
77 }
78
79 static inline void _http_requestpool_object_declare_default_properties(TSRMLS_D)
80 {
81 zend_class_entry *ce = http_requestpool_object_ce;
82
83 DCL_PROP_N(PROTECTED, pool);
84 }
85
86 void _http_requestpool_object_free(zend_object *object TSRMLS_DC)
87 {
88 http_requestpool_object *o = (http_requestpool_object *) object;
89
90 if (OBJ_PROP(o)) {
91 zend_hash_destroy(OBJ_PROP(o));
92 FREE_HASHTABLE(OBJ_PROP(o));
93 }
94 http_request_pool_dtor(&o->pool);
95 efree(o);
96 }
97
98 static void http_requestpool_object_ondestructhandler(zval **request, http_request_pool *pool TSRMLS_DC)
99 {
100 http_request_pool_detach(pool, *request);
101 }
102
103 void _http_requestpool_object_ondestruct(http_request_pool *pool TSRMLS_DC)
104 {
105 zend_llist_apply_with_argument(&pool->handles, (llist_apply_with_arg_func_t) http_requestpool_object_ondestructhandler, pool TSRMLS_CC);
106 }
107
108
109 #endif /* HTTP_HAVE_CURL */
110 #endif /* ZEND_ENGINE_2 */
111
112 /*
113 * Local variables:
114 * tab-width: 4
115 * c-basic-offset: 4
116 * End:
117 * vim600: noet sw=4 ts=4 fdm=marker
118 * vim<600: noet sw=4 ts=4
119 */
120