Imported Upstream version 3.2.0
[platform/upstream/libwebsockets.git] / lib / plat / unix / private.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2018 Andy Green <andy@warmcat.com>
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public
8  *  License as published by the Free Software Foundation:
9  *  version 2.1 of the License.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  *  MA  02110-1301  USA
20  *
21  *  Included from lib/core/private.h if no explicit platform
22  */
23
24 #include <fcntl.h>
25 #include <strings.h>
26 #include <unistd.h>
27
28 #include <netinet/in.h>
29 #include <netinet/tcp.h>
30 #include <arpa/inet.h>
31 #include <poll.h>
32 #include <netdb.h>
33
34 #ifndef __cplusplus
35 #include <errno.h>
36 #endif
37 #include <netdb.h>
38 #include <signal.h>
39
40 #include <sys/socket.h>
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <sys/time.h>
44 #include <sys/mman.h>
45 #include <sys/un.h>
46
47 #if defined(__APPLE__)
48 #include <machine/endian.h>
49 #endif
50 #if defined(__FreeBSD__)
51 #include <sys/endian.h>
52 #endif
53 #if defined(__linux__)
54 #include <endian.h>
55 #endif
56 #if defined(__QNX__)
57         #include <gulliver.h>
58         #if defined(__LITTLEENDIAN__)
59                 #define BYTE_ORDER __LITTLEENDIAN__
60                 #define LITTLE_ENDIAN __LITTLEENDIAN__
61                 #define BIG_ENDIAN 4321  /* to show byte order (taken from gcc); for suppres warning that BIG_ENDIAN is not defined. */
62         #endif
63         #if defined(__BIGENDIAN__)
64                 #define BYTE_ORDER __BIGENDIAN__
65                 #define LITTLE_ENDIAN 1234  /* to show byte order (taken from gcc); for suppres warning that LITTLE_ENDIAN is not defined. */
66                 #define BIG_ENDIAN __BIGENDIAN__
67         #endif
68 #endif
69
70 #if defined(__sun) && defined(__GNUC__)
71
72 #include <arpa/nameser_compat.h>
73
74 #if !defined (BYTE_ORDER)
75 #define BYTE_ORDER __BYTE_ORDER__
76 #endif
77
78 #if !defined(LITTLE_ENDIAN)
79 #define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
80 #endif
81
82 #if !defined(BIG_ENDIAN)
83 #define BIG_ENDIAN __ORDER_BIG_ENDIAN__
84 #endif
85
86 #endif /* sun + GNUC */
87
88 #if !defined(BYTE_ORDER)
89 #define BYTE_ORDER __BYTE_ORDER
90 #endif
91 #if !defined(LITTLE_ENDIAN)
92 #define LITTLE_ENDIAN __LITTLE_ENDIAN
93 #endif
94 #if !defined(BIG_ENDIAN)
95 #define BIG_ENDIAN __BIG_ENDIAN
96 #endif
97
98 #if defined(LWS_BUILTIN_GETIFADDRS)
99 #include "./misc/getifaddrs.h"
100 #else
101
102 #if defined(__HAIKU__)
103 #define _BSD_SOURCE
104 #endif
105 #include <ifaddrs.h>
106
107 #endif
108
109 #if defined (__sun) || defined(__HAIKU__) || defined(__QNX__) || defined(__ANDROID__)
110 #include <syslog.h>
111
112 #if defined(__ANDROID__)
113 #include <sys/resource.h>
114 #endif
115
116 #else
117 #include <sys/syslog.h>
118 #endif
119
120 #ifdef __QNX__
121 # include "netinet/tcp_var.h"
122 # define TCP_KEEPINTVL TCPCTL_KEEPINTVL
123 # define TCP_KEEPIDLE  TCPCTL_KEEPIDLE
124 # define TCP_KEEPCNT   TCPCTL_KEEPCNT
125 #endif
126
127 #define LWS_ERRNO errno
128 #define LWS_EAGAIN EAGAIN
129 #define LWS_EALREADY EALREADY
130 #define LWS_EINPROGRESS EINPROGRESS
131 #define LWS_EINTR EINTR
132 #define LWS_EISCONN EISCONN
133 #define LWS_ENOTCONN ENOTCONN
134 #define LWS_EWOULDBLOCK EWOULDBLOCK
135 #define LWS_EADDRINUSE EADDRINUSE
136 #define lws_set_blocking_send(wsi)
137 #define LWS_SOCK_INVALID (-1)
138
139 struct lws_context;
140
141 struct lws *
142 wsi_from_fd(const struct lws_context *context, int fd);
143
144 int
145 insert_wsi(const struct lws_context *context, struct lws *wsi);
146
147 void
148 delete_from_fd(const struct lws_context *context, int fd);
149
150 #ifndef LWS_NO_FORK
151 #ifdef LWS_HAVE_SYS_PRCTL_H
152 #include <sys/prctl.h>
153 #endif
154 #endif
155
156 #define compatible_close(x) close(x)
157 #define lws_plat_socket_offset() (0)
158
159 /*
160  * Mac OSX as well as iOS do not define the MSG_NOSIGNAL flag,
161  * but happily have something equivalent in the SO_NOSIGPIPE flag.
162  */
163 #ifdef __APPLE__
164 #define MSG_NOSIGNAL SO_NOSIGPIPE
165 #endif
166
167 /*
168  * Solaris 11.X only supports POSIX 2001, MSG_NOSIGNAL appears in
169  * POSIX 2008.
170  */
171 #if defined(__sun) && !defined(__smartos__)
172  #define MSG_NOSIGNAL 0
173 #endif