-
-
Notifications
You must be signed in to change notification settings - Fork 319
/
yar_transport.c
101 lines (83 loc) · 3.33 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
/*
+----------------------------------------------------------------------+
| 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_plink;
struct _yar_transports_list {
unsigned int size;
unsigned int num;
const yar_transport_t **transports;
} yar_transports_list;
extern const yar_transport_t yar_transport_curl;
extern const yar_transport_t yar_transport_socket;
static void php_yar_plink_dtor(zend_resource *rsrc) /* {{{ */ {
yar_persistent_le_t *le = (yar_persistent_le_t *)rsrc->ptr;
le->dtor(le->ptr);
efree(le);
}
/* }}} */
PHP_YAR_API const yar_transport_t * php_yar_transport_get(char *name, int nlen) /* {{{ */ {
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(const yar_transport_t *transport) /* {{{ */ {
if (!yar_transports_list.size) {
yar_transports_list.size = 5;
yar_transports_list.transports = (const 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 = (const 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);
php_yar_transport_register(&yar_transport_socket);
le_plink = zend_register_list_destructors_ex(php_yar_plink_dtor, NULL, "Yar Persistent Link", module_number);
return SUCCESS;
} /* }}} */
YAR_ACTIVATE_FUNCTION(transport) /* {{{ */ {
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
*/