-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlibuv_reactor.h
More file actions
186 lines (159 loc) · 4.72 KB
/
libuv_reactor.h
File metadata and controls
186 lines (159 loc) · 4.72 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
+----------------------------------------------------------------------+
| Copyright (c) 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: |
| https://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 |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Edmond |
+----------------------------------------------------------------------+
*/
#ifndef LIBUV_REACTOR_H
#define LIBUV_REACTOR_H
#define LIBUV_REACTOR_VERSION "0.8.0"
#define LIBUV_REACTOR_NAME "Libuv Reactor 0.8.0"
#include <Zend/zend_async_API.h>
#include "thread.h"
#ifdef PHP_WIN32
#include "libuv/uv.h"
#define SIGCHLD 17
#else
#include <uv.h>
#endif
typedef struct _async_poll_event_t async_poll_event_t;
typedef struct _async_socket_event_t async_socket_event_t;
typedef struct _async_timer_event_t async_timer_event_t;
typedef struct _async_signal_event_t async_signal_event_t;
typedef struct _async_filesystem_event_t async_filesystem_event_t;
typedef struct _async_process_event_t async_process_event_t;
typedef struct _async_thread_event_t async_thread_event_t;
typedef struct _async_trigger_event_t async_trigger_event_t;
typedef struct _async_dns_nameinfo_t async_dns_nameinfo_t;
typedef struct _async_dns_addrinfo_t async_dns_addrinfo_t;
typedef struct _async_exec_event_t async_exec_event_t;
typedef struct _async_io_t async_io_t;
typedef struct _async_io_req_t async_io_req_t;
struct _async_poll_event_t
{
zend_async_poll_event_t event;
uv_poll_t uv_handle;
/* Array of active proxies for correct event aggregation */
zend_async_poll_proxy_t **proxies;
uint32_t proxies_count;
uint32_t proxies_capacity;
/* Cached SOCK_DGRAM flag — UDP sockets do not need the recv(MSG_PEEK)
* spurious-readable filter applied to stream sockets. */
bool is_dgram;
};
struct _async_timer_event_t
{
zend_async_timer_event_t event;
uv_timer_t uv_handle;
};
struct _async_signal_event_t
{
zend_async_signal_event_t event;
// uv_signal_t removed - now using global signal management
};
struct _async_filesystem_event_t
{
zend_async_filesystem_event_t event;
uv_fs_event_t uv_handle;
};
struct _async_dns_nameinfo_t
{
zend_async_dns_nameinfo_t event;
uv_getnameinfo_t uv_handle;
};
struct _async_dns_addrinfo_t
{
zend_async_dns_addrinfo_t event;
uv_getaddrinfo_t uv_handle;
};
struct _async_process_event_t
{
zend_async_process_event_t event;
#ifdef PHP_WIN32
HANDLE hJob;
#endif
};
struct _async_thread_event_t
{
zend_async_thread_event_t event;
uv_thread_t uv_handle;
uv_async_t uv_notify; /* Cross-thread notification handle */
};
struct _async_exec_event_t
{
zend_async_exec_event_t event;
uv_process_t *process;
uv_pipe_t *stdout_pipe;
uv_pipe_t *stderr_pipe;
uv_process_options_t options;
/* Coroutine that initiated the exec — needed for PHPWRITE_CORO
* so that PASSTHRU/SYSTEM output goes through the correct OB stack. */
zend_coroutine_t *coroutine;
/* Line parser state: pending incomplete line between chunks. */
char *line_buf;
size_t line_buf_len; /* bytes used */
size_t line_buf_cap; /* allocated capacity */
};
struct _async_trigger_event_t
{
zend_async_trigger_event_t event;
uv_async_t uv_handle;
};
typedef struct _libuv_work_wrapper_s
{
uv_work_t uv_req;
zend_async_task_t *task;
} libuv_work_wrapper_t;
struct _async_io_t
{
zend_async_io_t base;
int crt_fd;
int orig_fd; /* original stdio fd (0/1/2) when dup'd, or -1 */
async_io_req_t *active_req;
union
{
uv_stream_t stream;
uv_pipe_t pipe;
uv_tty_t tty;
uv_tcp_t tcp;
uv_udp_t udp;
struct
{
zend_off_t offset;
} file;
} handle;
};
struct _async_io_req_t
{
zend_async_io_req_t base;
async_io_t *io;
size_t max_size;
bool buf_owned;
union
{
uv_write_t write_req;
uv_fs_t fs_req;
};
};
typedef struct _async_udp_req_t async_udp_req_t;
struct _async_udp_req_t
{
zend_async_udp_req_t base;
async_io_t *io;
size_t max_size;
uv_udp_send_t send_req;
};
void async_libuv_reactor_register(void);
/* Called by async_thread_run in the child thread after ts_free_thread, so
* the registry entry vanishes only once the child is past TSRM/Zend access. */
void async_libuv_thread_registry_remove(zend_async_thread_handle_t handle);
#endif // LIBUV_REACTOR_H