forked from laruence/yar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyar_transport.c
132 lines (106 loc) · 3.97 KB
/
yar_transport.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
+----------------------------------------------------------------------+
| Yar - Light, concurrent RPC framework |
+----------------------------------------------------------------------+
| Copyright (c) 2012-2013 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Xinchen Hui <[email protected]> |
| Zhenyu Zhang <[email protected]> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_yar.h"
#include "yar_transport.h"
/* True globals, no need for thread safety */
int le_calldata;
int le_plink;
struct _yar_transports_list {
unsigned int size;
unsigned int num;
yar_transport_t **transports;
} yar_transports_list;
extern yar_transport_t yar_transport_curl;
extern yar_transport_t yar_transport_socket;
static void php_yar_plink_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */ {
yar_persistent_le_t *le = (yar_persistent_le_t *)rsrc->ptr;
le->dtor(le->ptr TSRMLS_CC);
free(le);
}
/* }}} */
static void php_yar_calldata_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */ {
yar_call_data_t *entry = (yar_call_data_t *)rsrc->ptr;
if (entry->uri) {
efree(entry->uri);
}
if (entry->method) {
efree(entry->method);
}
if (entry->callback) {
zval_ptr_dtor(&entry->callback);
}
if (entry->parameters) {
zval_ptr_dtor(&entry->parameters);
}
if (entry->options) {
zval_ptr_dtor(&entry->options);
}
efree(entry);
}
/* }}} */
PHP_YAR_API yar_transport_t * php_yar_transport_get(char *name, int nlen TSRMLS_DC) /* {{{ */ {
int i = 0;
for (;i<yar_transports_list.num;i++) {
if (strncmp(yar_transports_list.transports[i]->name, name, nlen) == 0) {
return yar_transports_list.transports[i];
}
}
return NULL;
} /* }}} */
PHP_YAR_API int php_yar_transport_register(yar_transport_t *transport TSRMLS_DC) /* {{{ */ {
if (!yar_transports_list.size) {
yar_transports_list.size = 5;
yar_transports_list.transports = (yar_transport_t **)malloc(sizeof(yar_transport_t *) * yar_transports_list.size);
} else if (yar_transports_list.num == yar_transports_list.size) {
yar_transports_list.size += 5;
yar_transports_list.transports = (yar_transport_t **)realloc(yar_transports_list.transports, sizeof(yar_transport_t *) * yar_transports_list.size);
}
yar_transports_list.transports[yar_transports_list.num] = transport;
return yar_transports_list.num++;
} /* }}} */
YAR_STARTUP_FUNCTION(transport) /* {{{ */ {
php_yar_transport_register(&yar_transport_curl TSRMLS_CC);
php_yar_transport_register(&yar_transport_socket TSRMLS_CC);
le_calldata = zend_register_list_destructors_ex(php_yar_calldata_dtor, NULL, "Yar Call Data", module_number);
le_plink = zend_register_list_destructors_ex(NULL, php_yar_plink_dtor, "Yar Persistent Link", module_number);
return SUCCESS;
} /* }}} */
YAR_ACTIVATE_FUNCTION(transport) /* {{{ */ {
YAR_G(transport) = &yar_transport_curl;
return SUCCESS;
} /* }}} */
YAR_SHUTDOWN_FUNCTION(transport) /* {{{ */ {
if (yar_transports_list.size) {
free(yar_transports_list.transports);
}
return SUCCESS;
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/