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