1 /*
2   +----------------------------------------------------------------------+
3   | Swoole                                                               |
4   +----------------------------------------------------------------------+
5   | This source file is subject to version 2.0 of the Apache license,    |
6   | that is bundled with this package in the file LICENSE, and is        |
7   | available through the world-wide-web at the following url:           |
8   | http://www.apache.org/licenses/LICENSE-2.0.html                      |
9   | If you did not receive a copy of the Apache2.0 license and are unable|
10   | to obtain it through the world-wide-web, please send a note to       |
11   | license@swoole.com so we can mail you a copy immediately.            |
12   +----------------------------------------------------------------------+
13   | Author: Tianfeng Han  <mikan.tenny@gmail.com>                        |
14   +----------------------------------------------------------------------+
15 */
16 #ifndef SWOOLE_CONFIG_H_
17 #define SWOOLE_CONFIG_H_
18 
19 #ifndef __clang__
20 // gcc version check
21 #if defined(__GNUC__) && (__GNUC__ < 3 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8))
22 #error "GCC 4.8 or later required"
23 #endif
24 #endif
25 
26 #define SW_MAX_FDTYPE 32  // 32 kinds of event
27 #define SW_MAX_HOOK_TYPE 32
28 #define SW_ERROR_MSG_SIZE 16384
29 #define SW_MAX_FILE_CONTENT (64 * 1024 * 1024)  // for swoole_file_get_contents
30 #define SW_MAX_LISTEN_PORT 60000
31 #define SW_MAX_CONNECTION 100000
32 #define SW_MAX_CONCURRENT_TASK 1024
33 #define SW_STACK_BUFFER_SIZE 65536
34 
35 #ifdef HAVE_MALLOC_TRIM
36 #define SW_USE_MALLOC_TRIM 1
37 #endif
38 #define SW_MALLOC_TRIM_INTERVAL 60
39 #define SW_MALLOC_TRIM_PAD 0
40 #define SW_USE_MONOTONIC_TIME 1
41 
42 #define SW_MAX_SOCKETS_DEFAULT 1024
43 
44 #define SW_SOCKET_OVERFLOW_WAIT 100
45 #define SW_SOCKET_MAX_DEFAULT 65536
46 #if defined(__MACH__) || defined(__FreeBSD__) || defined(__DragonFly__)
47 #define SW_SOCKET_BUFFER_SIZE 262144
48 #else
49 #define SW_SOCKET_BUFFER_SIZE 8388608
50 #endif
51 #define SW_SOCKET_RETRY_COUNT 10
52 
53 #define SW_SOCKET_DEFAULT_DNS_TIMEOUT 60
54 #define SW_SOCKET_DEFAULT_CONNECT_TIMEOUT 2
55 #define SW_SOCKET_DEFAULT_READ_TIMEOUT 60
56 #define SW_SOCKET_DEFAULT_WRITE_TIMEOUT 60
57 
58 #define SW_SYSTEMD_FDS_START 3
59 
60 #define SW_GLOBAL_MEMORY_PAGESIZE (2 * 1024 * 1024)  // global memory page
61 
62 #define SW_MAX_THREAD_NCPU 4     // n * cpu_num
63 #define SW_MAX_WORKER_NCPU 1000  // n * cpu_num
64 
65 #define SW_HOST_MAXSIZE                                                                                                \
66     sizeof(((struct sockaddr_un *) NULL)->sun_path)  // Linux has 108 UNIX_PATH_MAX, but BSD/MacOS limit is only 104
67 
68 #define SW_LOG_NO_SRCINFO 1  // no source info
69 #define SW_CLIENT_BUFFER_SIZE 65536
70 #define SW_CLIENT_CONNECT_TIMEOUT 0.5
71 #define SW_CLIENT_MAX_PORT 65535
72 
73 // !!!Don't modify.----------------------------------------------------------
74 #ifdef __MACH__
75 #define SW_IPC_MAX_SIZE 2048  // MacOS
76 #else
77 #define SW_IPC_MAX_SIZE 8192  // for IPC, dgram and message-queue max size
78 #endif
79 #define SW_IPC_BUFFER_SIZE (SW_IPC_MAX_SIZE - sizeof(swoole::DataHead))
80 // !!!End.-------------------------------------------------------------------
81 
82 #define SW_BUFFER_SIZE_STD 8192
83 #define SW_BUFFER_SIZE_BIG 65536
84 #define SW_BUFFER_SIZE_UDP 65536
85 
86 #define SW_SENDFILE_CHUNK_SIZE 65536
87 #define SW_SENDFILE_MAXLEN 4194304
88 
89 #define SW_HASHMAP_KEY_MAXLEN 256
90 #define SW_HASHMAP_INIT_BUCKET_N 32  // hashmap bucket num (default value for init)
91 
92 #define SW_DATA_EOF "\r\n\r\n"
93 #define SW_DATA_EOF_MAXLEN 8
94 
95 #define SW_TASKWAIT_TIMEOUT 0.5
96 
97 #define SW_AIO_THREAD_NUM_MULTIPLE 8
98 #define SW_AIO_THREAD_MAX_IDLE_TIME 1.0
99 #define SW_AIO_TASK_MAX_WAIT_TIME 0.001
100 #define SW_AIO_MAX_FILESIZE (4 * 1024 * 1024)
101 #define SW_AIO_EVENT_NUM 128
102 #define SW_AIO_DEFAULT_CHUNK_SIZE 65536
103 #define SW_AIO_MAX_CHUNK_SIZE (1 * 1024 * 1024)
104 #define SW_AIO_MAX_EVENTS 128
105 #define SW_AIO_HANDLER_MAX_SIZE 8
106 #define SW_THREADPOOL_QUEUE_LEN 10000
107 #define SW_IP_MAX_LENGTH 46
108 
109 #define SW_WORKER_WAIT_TIMEOUT 1000
110 
111 #define SW_WORKER_USE_SIGNALFD 1
112 #define SW_WORKER_MAX_WAIT_TIME 3
113 #define SW_WORKER_MIN_REQUEST 10
114 #define SW_WORKER_MAX_RECV_CHUNK_COUNT 32
115 
116 #define SW_REACTOR_MAXEVENTS 4096
117 
118 #define SW_SESSION_LIST_SIZE (1 * 1024 * 1024)
119 
120 #define SW_MSGMAX 65536
121 #define SW_UNIXSOCK_MAX_BUF_SIZE (2 * 1024 * 1024)
122 
123 #define SW_DGRAM_HEADER_SIZE 32
124 
125 /**
126  * The maximum number of Reactor threads
127  * the number of the CPU cores threads will be started by default
128  * number 8 is the maximum
129  */
130 #define SW_REACTOR_MAX_THREAD 8
131 
132 /**
133  * Loops read data from the pipeline,
134  * helping to alleviate pipeline cache congestion
135  * reduce the pressure of interprocess communication
136  */
137 #define SW_REACTOR_RECV_AGAIN 1
138 
139 /**
140  * RINGBUFFER
141  */
142 #define SW_RINGQUEUE_LEN 1024
143 #define SW_RINGBUFFER_FREE_N_MAX 4  // when free_n > MAX, execute collect
144 #define SW_RINGBUFFER_WARNING 100
145 
146 /**
147  * ringbuffer memory pool size
148  */
149 #define SW_OUTPUT_BUFFER_SIZE (2 * 1024 * 1024)
150 #define SW_INPUT_BUFFER_SIZE (2 * 1024 * 1024)
151 #define SW_BUFFER_MIN_SIZE 65536
152 #define SW_SEND_BUFFER_SIZE 65536
153 
154 #define SW_BACKLOG 512
155 
156 /**
157  * max accept times for single time
158  */
159 #define SW_ACCEPT_MAX_COUNT 64
160 #define SW_ACCEPT_RETRY_TIME 1.0
161 
162 #define SW_TCP_KEEPCOUNT 5
163 #define SW_TCP_KEEPIDLE 3600  // 1 hour
164 #define SW_TCP_KEEPINTERVAL 60
165 
166 #define SW_USE_EVENTFD                                                                                                 \
167     1  // Whether to use eventfd for message notification, Linux 2.6.22 or later is required to support
168 
169 #define SW_TASK_TMP_PATH_SIZE  256
170 #define SW_TASK_TMP_DIR  "/tmp"
171 #define SW_TASK_TMP_FILE "swoole.task.XXXXXX"
172 
173 #define SW_FILE_CHUNK_SIZE 65536
174 
175 #define SW_TABLE_CONFLICT_PROPORTION 0.2  // 20%
176 #define SW_TABLE_KEY_SIZE 64
177 
178 #define SW_SSL_BUFFER_SIZE 16384
179 #define SW_SSL_CIPHER_LIST "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"
180 #define SW_SSL_ECDH_CURVE "auto"
181 
182 #define SW_SPINLOCK_LOOP_N 1024
183 
184 #define SW_STRING_BUFFER_MAXLEN (1024 * 1024 * 128)
185 #define SW_STRING_BUFFER_DEFAULT 128
186 #define SW_STRING_BUFFER_GARBAGE_MIN (1024 * 64)
187 #define SW_STRING_BUFFER_GARBAGE_RATIO 4
188 
189 #define SW_SIGNO_MAX 128
190 #define SW_UNREGISTERED_SIGNAL_FMT "Unable to find callback function for signal %s"
191 
192 #define SW_DNS_HOST_BUFFER_SIZE 16
193 #define SW_DNS_SERVER_PORT 53
194 #define SW_DNS_RESOLV_CONF "/etc/resolv.conf"
195 
196 #define SW_Z_BEST_SPEED 1
197 #define SW_COMPRESSION_MIN_LENGTH_DEFAULT  20
198 
199 #ifndef IOV_MAX
200 #define IOV_MAX   16
201 #endif
202 
203 #define IOV_MAX_ERROR_MSG "The maximum of iov count is %d"
204 
205 /**
206  * HTTP Protocol
207  */
208 #define SW_HTTP_SERVER_SOFTWARE "swoole-http-server"
209 #define SW_HTTP_PARAM_MAX_NUM 128
210 #define SW_HTTP_FORM_KEYLEN 512
211 #define SW_HTTP_COOKIE_KEYLEN 128
212 #define SW_HTTP_COOKIE_VALLEN 4096
213 #define SW_HTTP_RESPONSE_INIT_SIZE 65536
214 #define SW_HTTP_HEADER_MAX_SIZE 65536
215 #define SW_HTTP_HEADER_KEY_SIZE 128
216 #define SW_HTTP_UPLOAD_TMPDIR_SIZE SW_TASK_TMP_PATH_SIZE
217 #define SW_HTTP_DATE_FORMAT "D, d M Y H:i:s T"
218 #define SW_HTTP_RFC1123_DATE_GMT "%a, %d %b %Y %T GMT"
219 #define SW_HTTP_RFC1123_DATE_UTC "%a, %d %b %Y %T UTC"
220 #define SW_HTTP_RFC850_DATE "%A, %d-%b-%y %T GMT"
221 #define SW_HTTP_ASCTIME_DATE "%a %b %e %T %Y"
222 
223 // #define SW_HTTP_100_CONTINUE
224 #define SW_HTTP_100_CONTINUE_PACKET "HTTP/1.1 100 Continue\r\n\r\n"
225 #define SW_HTTP_BAD_REQUEST_PACKET "HTTP/1.1 400 Bad Request\r\n\r\n"
226 #define SW_HTTP_REQUEST_ENTITY_TOO_LARGE_PACKET "HTTP/1.1 413 Request Entity Too Large\r\n\r\n"
227 #define SW_HTTP_SERVICE_UNAVAILABLE_PACKET "HTTP/1.1 503 Service Unavailable\r\n\r\n"
228 #define SW_HTTP_PAGE_400 "<html><body><h2>HTTP 400 Bad Request</h2><hr><i>Powered by Swoole</i></body></html>"
229 #define SW_HTTP_PAGE_404 "<html><body><h2>HTTP 404 Not Found</h2><hr><i>Powered by Swoole</i></body></html>"
230 
231 /**
232  * HTTP2 Protocol
233  */
234 #define SW_HTTP2_DATA_BUFFER_SIZE 8192
235 #define SW_HTTP2_DEFAULT_HEADER_TABLE_SIZE (1 << 12)
236 #define SW_HTTP2_MAX_MAX_CONCURRENT_STREAMS 128
237 #define SW_HTTP2_MAX_MAX_FRAME_SIZE ((1u << 14))
238 #define SW_HTTP2_MAX_WINDOW_SIZE ((1u << 31) - 1)
239 #define SW_HTTP2_DEFAULT_WINDOW_SIZE 65535
240 #define SW_HTTP2_DEFAULT_MAX_HEADER_LIST_SIZE (1 << 12)
241 #define SW_HTTP2_MAX_MAX_HEADER_LIST_SIZE UINT32_MAX
242 
243 #define SW_HTTP_CLIENT_USERAGENT "swoole-http-client"
244 #define SW_HTTP_CLIENT_BOUNDARY_PREKEY "----SwooleBoundary"
245 #define SW_HTTP_CLIENT_BOUNDARY_TOTAL_SIZE 39
246 #define SW_HTTP_FORM_RAW_DATA_FMT "--%.*s\r\nContent-Disposition: form-data; name=\"%.*s\"\r\n\r\n"
247 #define SW_HTTP_FORM_RAW_DATA_FMT_LEN 8
248 #define SW_HTTP_FORM_FILE_DATA_FMT                                                                                     \
249     "--%.*s\r\nContent-Disposition: form-data; name=\"%.*s\"; filename=\"%.*s\"\r\nContent-Type: %.*s\r\n\r\n"
250 #define SW_HTTP_FORM_FILE_DATA_FMT_LEN 16
251 
252 #define SW_WEBSOCKET_VERSION "13"
253 #define SW_WEBSOCKET_KEY_LENGTH 16
254 #define SW_WEBSOCKET_QUEUE_SIZE 16
255 #define SW_WEBSOCKET_EXTENSION_DEFLATE "permessage-deflate; client_no_context_takeover; server_no_context_takeover"
256 
257 /**
258  * MySQL Client
259  */
260 #define SW_MYSQL_DEFAULT_HOST "127.0.0.1"
261 #define SW_MYSQL_DEFAULT_PORT 3306
262 #define SW_MYSQL_DEFAULT_CHARSET 33  // 0x21, utf8_general_ci
263 
264 /**
265  * PGSQL Client
266  */
267 #define SW_PGSQL_CONNECT_TIMEOUT 3.0
268 
269 /**
270  * Coroutine
271  */
272 #define SW_DEFAULT_C_STACK_SIZE (2 * 1024 * 1024)
273 #define SW_CORO_SUPPORT_BAILOUT 1
274 #define SW_CORO_SWAP_BAILOUT 1
275 //#define SW_CONTEXT_PROTECT_STACK_PAGE    1
276 //#define SW_CONTEXT_DETECT_STACK_USAGE    1
277 
278 #ifdef SW_DEBUG
279 #ifndef SW_LOG_TRACE_OPEN
280 #define SW_LOG_TRACE_OPEN 1
281 #endif
282 #endif
283 
284 #endif /* SWOOLE_CONFIG_H_ */
285