xref: /PHP-8.3/sapi/fpm/fpm/fpm_sockets.h (revision e2a5428c)
1 	/* (c) 2007,2008 Andrei Nigmatulin */
2 
3 #ifndef FPM_MISC_H
4 #define FPM_MISC_H 1
5 
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #if defined(__FreeBSD__)
9 #include <sys/sysctl.h>
10 #endif
11 #include <sys/un.h>
12 #include <unistd.h>
13 #include <fcntl.h>
14 
15 #include "fpm_worker_pool.h"
16 
17 /*
18   On Linux, FreeBSD, OpenBSD and macOS, backlog negative values are truncated to SOMAXCONN
19 */
20 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(__APPLE__)
21 #define FPM_BACKLOG_DEFAULT -1
22 #else
23 #define FPM_BACKLOG_DEFAULT 511
24 #endif
25 
26 #define FPM_ENV_SOCKET_SET_MAX 256
27 #define FPM_ENV_SOCKET_SET_SIZE 128
28 
29 enum fpm_address_domain fpm_sockets_domain_from_address(char *addr);
30 int fpm_sockets_init_main(void);
31 int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq);
32 int fpm_socket_unix_test_connect(struct sockaddr_un *sock, size_t socklen);
33 
34 
fd_set_blocked(int fd,int blocked)35 static inline int fd_set_blocked(int fd, int blocked) /* {{{ */
36 {
37 	int flags = fcntl(fd, F_GETFL);
38 
39 	if (flags < 0) {
40 		return -1;
41 	}
42 
43 	if (blocked) {
44 		flags &= ~O_NONBLOCK;
45 	} else {
46 		flags |= O_NONBLOCK;
47 	}
48 	return fcntl(fd, F_SETFL, flags);
49 }
50 /* }}} */
51 
52 #endif
53