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, DragonFlyBSD and macOS, backlog negative values are truncated to SOMAXCONN
19 */
20 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__) || \
21 defined(__DragonFly__) || defined(__APPLE__)
22 #define FPM_BACKLOG_DEFAULT -1
23 #else
24 #define FPM_BACKLOG_DEFAULT 511
25 #endif
26
27 #define FPM_ENV_SOCKET_SET_MAX 256
28 #define FPM_ENV_SOCKET_SET_SIZE 128
29
30 enum fpm_address_domain fpm_sockets_domain_from_address(char *addr);
31 int fpm_sockets_init_main(void);
32 int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq);
33 int fpm_socket_unix_test_connect(struct sockaddr_un *sock, size_t socklen);
34
35
fd_set_blocked(int fd,int blocked)36 static inline int fd_set_blocked(int fd, int blocked) /* {{{ */
37 {
38 int flags = fcntl(fd, F_GETFL);
39
40 if (flags < 0) {
41 return -1;
42 }
43
44 if (blocked) {
45 flags &= ~O_NONBLOCK;
46 } else {
47 flags |= O_NONBLOCK;
48 }
49 return fcntl(fd, F_SETFL, flags);
50 }
51 /* }}} */
52
53 #endif
54