private.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * libwebsockets - small server side websockets and web server implementation
  3. *
  4. * Copyright (C) 2010 - 2018 Andy Green <[email protected]>
  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. #include <fcntl.h>
  24. #include <strings.h>
  25. #include <unistd.h>
  26. #include <netinet/in.h>
  27. #include <netinet/tcp.h>
  28. #include <arpa/inet.h>
  29. #include <poll.h>
  30. #include <netdb.h>
  31. #ifndef __cplusplus
  32. #include <errno.h>
  33. #endif
  34. #include <netdb.h>
  35. #include <signal.h>
  36. #include <sys/socket.h>
  37. #include <sys/types.h>
  38. #include <sys/stat.h>
  39. #include <sys/time.h>
  40. #include <sys/mman.h>
  41. #include <sys/un.h>
  42. #if defined(__APPLE__)
  43. #include <machine/endian.h>
  44. #endif
  45. #if defined(__FreeBSD__)
  46. #include <sys/endian.h>
  47. #endif
  48. #if defined(__linux__)
  49. #include <endian.h>
  50. #endif
  51. #if defined(__QNX__)
  52. #include <gulliver.h>
  53. #if defined(__LITTLEENDIAN__)
  54. #define BYTE_ORDER __LITTLEENDIAN__
  55. #define LITTLE_ENDIAN __LITTLEENDIAN__
  56. #define BIG_ENDIAN 4321 /* to show byte order (taken from gcc); for suppres warning that BIG_ENDIAN is not defined. */
  57. #endif
  58. #if defined(__BIGENDIAN__)
  59. #define BYTE_ORDER __BIGENDIAN__
  60. #define LITTLE_ENDIAN 1234 /* to show byte order (taken from gcc); for suppres warning that LITTLE_ENDIAN is not defined. */
  61. #define BIG_ENDIAN __BIGENDIAN__
  62. #endif
  63. #endif
  64. #if defined(__sun) && defined(__GNUC__)
  65. #include <arpa/nameser_compat.h>
  66. #if !defined (BYTE_ORDER)
  67. #define BYTE_ORDER __BYTE_ORDER__
  68. #endif
  69. #if !defined(LITTLE_ENDIAN)
  70. #define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
  71. #endif
  72. #if !defined(BIG_ENDIAN)
  73. #define BIG_ENDIAN __ORDER_BIG_ENDIAN__
  74. #endif
  75. #endif /* sun + GNUC */
  76. #if !defined(BYTE_ORDER)
  77. #define BYTE_ORDER __BYTE_ORDER
  78. #endif
  79. #if !defined(LITTLE_ENDIAN)
  80. #define LITTLE_ENDIAN __LITTLE_ENDIAN
  81. #endif
  82. #if !defined(BIG_ENDIAN)
  83. #define BIG_ENDIAN __BIG_ENDIAN
  84. #endif
  85. #if defined(LWS_BUILTIN_GETIFADDRS)
  86. #include "./misc/getifaddrs.h"
  87. #else
  88. #if defined(__HAIKU__)
  89. #define _BSD_SOURCE
  90. #endif
  91. #include <ifaddrs.h>
  92. #endif
  93. #if defined (__sun) || defined(__HAIKU__) || defined(__QNX__)
  94. #include <syslog.h>
  95. #else
  96. #include <sys/syslog.h>
  97. #endif
  98. #ifdef __QNX__
  99. # include "netinet/tcp_var.h"
  100. # define TCP_KEEPINTVL TCPCTL_KEEPINTVL
  101. # define TCP_KEEPIDLE TCPCTL_KEEPIDLE
  102. # define TCP_KEEPCNT TCPCTL_KEEPCNT
  103. #endif
  104. #define LWS_ERRNO errno
  105. #define LWS_EAGAIN EAGAIN
  106. #define LWS_EALREADY EALREADY
  107. #define LWS_EINPROGRESS EINPROGRESS
  108. #define LWS_EINTR EINTR
  109. #define LWS_EISCONN EISCONN
  110. #define LWS_ENOTCONN ENOTCONN
  111. #define LWS_EWOULDBLOCK EWOULDBLOCK
  112. #define LWS_EADDRINUSE EADDRINUSE
  113. #define lws_set_blocking_send(wsi)
  114. #define LWS_SOCK_INVALID (-1)
  115. #define wsi_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()]
  116. #define insert_wsi(A,B) assert(A->lws_lookup[B->desc.sockfd - \
  117. lws_plat_socket_offset()] == 0); \
  118. A->lws_lookup[B->desc.sockfd - \
  119. lws_plat_socket_offset()] = B
  120. #define delete_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] = 0
  121. #ifndef LWS_NO_FORK
  122. #ifdef LWS_HAVE_SYS_PRCTL_H
  123. #include <sys/prctl.h>
  124. #endif
  125. #endif
  126. #if defined (__ANDROID__)
  127. #include <syslog.h>
  128. #include <sys/resource.h>
  129. #endif
  130. #define compatible_close(x) close(x)
  131. #define lws_plat_socket_offset() (0)
  132. /*
  133. * Mac OSX as well as iOS do not define the MSG_NOSIGNAL flag,
  134. * but happily have something equivalent in the SO_NOSIGPIPE flag.
  135. */
  136. #ifdef __APPLE__
  137. #define MSG_NOSIGNAL SO_NOSIGPIPE
  138. #endif
  139. /*
  140. * Solaris 11.X only supports POSIX 2001, MSG_NOSIGNAL appears in
  141. * POSIX 2008.
  142. */
  143. #ifdef __sun
  144. #define MSG_NOSIGNAL 0
  145. #endif