|
21 | 21 | #include "php_swoole_cxx.h"
|
22 | 22 | #include "swoole_server.h"
|
23 | 23 |
|
| 24 | +#include <unordered_map> |
| 25 | +#include <list> |
| 26 | +#include <vector> |
| 27 | + |
24 | 28 | //--------------------------------------------------------
|
25 | 29 | enum php_swoole_server_callback_type {
|
26 | 30 | SW_SERVER_CB_onStart, // master
|
@@ -54,30 +58,90 @@ enum php_swoole_server_port_callback_type {
|
54 | 58 | #define PHP_SWOOLE_SERVER_CALLBACK_NUM (SW_SERVER_CB_onPipeMessage + 1)
|
55 | 59 | #define PHP_SWOOLE_SERVER_PORT_CALLBACK_NUM (SW_SERVER_CB_onBufferEmpty + 1)
|
56 | 60 |
|
57 |
| -struct php_swoole_server_port_property { |
| 61 | +namespace swoole { |
| 62 | +struct TaskCo; |
| 63 | + |
| 64 | +struct ServerPortProperty { |
58 | 65 | zval *callbacks[PHP_SWOOLE_SERVER_PORT_CALLBACK_NUM];
|
59 | 66 | zend_fcall_info_cache *caches[PHP_SWOOLE_SERVER_PORT_CALLBACK_NUM];
|
60 | 67 | zval _callbacks[PHP_SWOOLE_SERVER_PORT_CALLBACK_NUM];
|
61 |
| - swServer *serv; |
62 |
| - swListenPort *port; |
| 68 | + Server *serv; |
| 69 | + ListenPort *port; |
63 | 70 | zval *zsetting;
|
64 | 71 | };
|
65 | 72 |
|
| 73 | +struct ServerProperty { |
| 74 | + std::vector<zval *> ports; |
| 75 | + std::vector<zval *> user_processes; |
| 76 | + ServerPortProperty *primary_port; |
| 77 | + zend_fcall_info_cache *callbacks[PHP_SWOOLE_SERVER_CALLBACK_NUM]; |
| 78 | + std::unordered_map<TaskId, zend_fcall_info_cache> task_callbacks; |
| 79 | + std::unordered_map<TaskId, TaskCo *> task_coroutine_map; |
| 80 | + std::unordered_map<SessionId, std::list<FutureTask *> *> send_coroutine_map; |
| 81 | +}; |
| 82 | + |
| 83 | +struct ServerObject { |
| 84 | + Server *serv; |
| 85 | + ServerProperty *property; |
| 86 | + zend_object std; |
| 87 | + |
| 88 | + zend_class_entry *get_ce() { |
| 89 | + return Z_OBJCE_P(get_object()); |
| 90 | + } |
| 91 | + |
| 92 | + zval *get_object() { |
| 93 | + return (zval *) serv->private_data_2; |
| 94 | + } |
| 95 | + |
| 96 | + bool isset_callback(ListenPort *port, int event_type) { |
| 97 | + ServerPortProperty *port_property = (ServerPortProperty *) port->ptr; |
| 98 | + return (port_property->callbacks[event_type] || property->primary_port->callbacks[event_type]); |
| 99 | + } |
| 100 | + |
| 101 | + zend_bool is_websocket_server() { |
| 102 | + return instanceof_function(get_ce(), swoole_websocket_server_ce); |
| 103 | + } |
| 104 | + |
| 105 | + zend_bool is_http_server() { |
| 106 | + return instanceof_function(get_ce(), swoole_http_server_ce); |
| 107 | + } |
| 108 | + |
| 109 | + zend_bool is_redis_server() { |
| 110 | + return instanceof_function(get_ce(), swoole_redis_server_ce); |
| 111 | + } |
| 112 | + |
| 113 | + void register_callback(); |
| 114 | + void on_before_start(); |
| 115 | +}; |
| 116 | + |
| 117 | +struct TaskCo { |
| 118 | + FutureTask context; |
| 119 | + int *list; |
| 120 | + uint32_t count; |
| 121 | + zval *result; |
| 122 | + TimerNode *timer; |
| 123 | + ServerObject *server_object; |
| 124 | +}; |
| 125 | + |
| 126 | +} // namespace swoole |
| 127 | + |
66 | 128 | void php_swoole_server_register_callbacks(swServer *serv);
|
67 | 129 | zend_fcall_info_cache *php_swoole_server_get_fci_cache(swServer *serv, int server_fd, int event_type);
|
68 | 130 | int php_swoole_create_dir(const char *path, size_t length);
|
69 | 131 | void php_swoole_server_before_start(swServer *serv, zval *zobject);
|
| 132 | +bool php_swoole_server_isset_callback(swServer *serv, swListenPort *port, int event_type); |
70 | 133 | void php_swoole_http_server_init_global_variant();
|
71 | 134 | void php_swoole_server_send_yield(swServer *serv, swoole::SessionId sesion_id, zval *zdata, zval *return_value);
|
72 | 135 | void php_swoole_get_recv_data(swServer *serv, zval *zdata, swRecvData *req);
|
73 |
| -void php_swoole_onConnect(swServer *, swDataHead *); |
74 |
| -int php_swoole_onReceive(swServer *, swRecvData *); |
75 |
| -int php_swoole_http_onReceive(swServer *, swRecvData *); |
76 |
| -void php_swoole_http_onClose(swServer *, swDataHead *); |
77 |
| -int php_swoole_onPacket(swServer *, swRecvData *); |
78 |
| -void php_swoole_onClose(swServer *, swDataHead *); |
79 |
| -void php_swoole_onBufferFull(swServer *, swDataHead *); |
80 |
| -void php_swoole_onBufferEmpty(swServer *, swDataHead *); |
| 136 | +void php_swoole_server_onConnect(swServer *, swDataHead *); |
| 137 | +int php_swoole_server_onReceive(swServer *, swRecvData *); |
| 138 | +int php_swoole_http_server_onReceive(swServer *, swRecvData *); |
| 139 | +int php_swoole_redis_server_onReceive(swServer *serv, swRecvData *req); |
| 140 | +void php_swoole_http_server_onClose(swServer *, swDataHead *); |
| 141 | +int php_swoole_server_onPacket(swServer *, swRecvData *); |
| 142 | +void php_swoole_server_onClose(swServer *, swDataHead *); |
| 143 | +void php_swoole_server_onBufferFull(swServer *, swDataHead *); |
| 144 | +void php_swoole_server_onBufferEmpty(swServer *, swDataHead *); |
81 | 145 |
|
82 | 146 | swServer *php_swoole_server_get_and_check_server(zval *zobject);
|
83 | 147 | void php_swoole_server_port_deref(zend_object *object);
|
0 commit comments