src/os/win32/ngx_socket.h - nginx source code

Data types defined

Macros defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #ifndef _NGX_SOCKET_H_INCLUDED_
  6. #define _NGX_SOCKET_H_INCLUDED_


  7. #include <ngx_config.h>
  8. #include <ngx_core.h>


  9. #define NGX_WRITE_SHUTDOWN SD_SEND
  10. #define NGX_READ_SHUTDOWN  SD_RECEIVE
  11. #define NGX_RDWR_SHUTDOWN  SD_BOTH


  12. typedef SOCKET  ngx_socket_t;
  13. typedef int     socklen_t;


  14. #define ngx_socket(af, type, proto)                                          \
  15.     WSASocketW(af, type, proto, NULL, 0, WSA_FLAG_OVERLAPPED)

  16. #define ngx_socket_n        "WSASocketW()"

  17. int ngx_nonblocking(ngx_socket_t s);
  18. int ngx_blocking(ngx_socket_t s);

  19. #define ngx_nonblocking_n   "ioctlsocket(FIONBIO)"
  20. #define ngx_blocking_n      "ioctlsocket(!FIONBIO)"

  21. int ngx_socket_nread(ngx_socket_t s, int *n);
  22. #define ngx_socket_nread_n  "ioctlsocket(FIONREAD)"

  23. #define ngx_shutdown_socket    shutdown
  24. #define ngx_shutdown_socket_n  "shutdown()"

  25. #define ngx_close_socket    closesocket
  26. #define ngx_close_socket_n  "closesocket()"


  27. #ifndef WSAID_ACCEPTEX

  28. typedef BOOL (PASCAL FAR * LPFN_ACCEPTEX)(
  29.     IN SOCKET sListenSocket,
  30.     IN SOCKET sAcceptSocket,
  31.     IN PVOID lpOutputBuffer,
  32.     IN DWORD dwReceiveDataLength,
  33.     IN DWORD dwLocalAddressLength,
  34.     IN DWORD dwRemoteAddressLength,
  35.     OUT LPDWORD lpdwBytesReceived,
  36.     IN LPOVERLAPPED lpOverlapped
  37.     );

  38. #define WSAID_ACCEPTEX                                                       \
  39.     {0xb5367df1,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}

  40. #endif


  41. #ifndef WSAID_GETACCEPTEXSOCKADDRS

  42. typedef VOID (PASCAL FAR * LPFN_GETACCEPTEXSOCKADDRS)(
  43.     IN PVOID lpOutputBuffer,
  44.     IN DWORD dwReceiveDataLength,
  45.     IN DWORD dwLocalAddressLength,
  46.     IN DWORD dwRemoteAddressLength,
  47.     OUT struct sockaddr **LocalSockaddr,
  48.     OUT LPINT LocalSockaddrLength,
  49.     OUT struct sockaddr **RemoteSockaddr,
  50.     OUT LPINT RemoteSockaddrLength
  51.     );

  52. #define WSAID_GETACCEPTEXSOCKADDRS                                           \
  53.         {0xb5367df2,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}

  54. #endif


  55. #ifndef WSAID_TRANSMITFILE

  56. #ifndef TF_DISCONNECT

  57. #define TF_DISCONNECT           1
  58. #define TF_REUSE_SOCKET         2
  59. #define TF_WRITE_BEHIND         4
  60. #define TF_USE_DEFAULT_WORKER   0
  61. #define TF_USE_SYSTEM_THREAD    16
  62. #define TF_USE_KERNEL_APC       32

  63. typedef struct _TRANSMIT_FILE_BUFFERS {
  64.     LPVOID Head;
  65.     DWORD HeadLength;
  66.     LPVOID Tail;
  67.     DWORD TailLength;
  68. } TRANSMIT_FILE_BUFFERS, *PTRANSMIT_FILE_BUFFERS, FAR *LPTRANSMIT_FILE_BUFFERS;

  69. #endif

  70. typedef BOOL (PASCAL FAR * LPFN_TRANSMITFILE)(
  71.     IN SOCKET hSocket,
  72.     IN HANDLE hFile,
  73.     IN DWORD nNumberOfBytesToWrite,
  74.     IN DWORD nNumberOfBytesPerSend,
  75.     IN LPOVERLAPPED lpOverlapped,
  76.     IN LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers,
  77.     IN DWORD dwReserved
  78.     );

  79. #define WSAID_TRANSMITFILE                                                   \
  80.     {0xb5367df0,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}

  81. #endif


  82. #ifndef WSAID_TRANSMITPACKETS

  83. /* OpenWatcom has a swapped TP_ELEMENT_FILE and TP_ELEMENT_MEMORY definition */

  84. #ifndef TP_ELEMENT_FILE

  85. #ifdef _MSC_VER
  86. #pragma warning(disable:4201) /* Nonstandard extension, nameless struct/union */
  87. #endif

  88. typedef struct _TRANSMIT_PACKETS_ELEMENT {
  89.     ULONG dwElFlags;
  90. #define TP_ELEMENT_MEMORY   1
  91. #define TP_ELEMENT_FILE     2
  92. #define TP_ELEMENT_EOP      4
  93.     ULONG cLength;
  94.     union {
  95.         struct {
  96.             LARGE_INTEGER nFileOffset;
  97.             HANDLE        hFile;
  98.         };
  99.         PVOID             pBuffer;
  100.     };
  101. } TRANSMIT_PACKETS_ELEMENT, *PTRANSMIT_PACKETS_ELEMENT,
  102.     FAR *LPTRANSMIT_PACKETS_ELEMENT;

  103. #ifdef _MSC_VER
  104. #pragma warning(default:4201)
  105. #endif

  106. #endif

  107. typedef BOOL (PASCAL FAR * LPFN_TRANSMITPACKETS) (
  108.     SOCKET hSocket,
  109.     TRANSMIT_PACKETS_ELEMENT *lpPacketArray,
  110.     DWORD nElementCount,
  111.     DWORD nSendSize,
  112.     LPOVERLAPPED lpOverlapped,
  113.     DWORD dwFlags
  114.     );

  115. #define WSAID_TRANSMITPACKETS                                                \
  116.     {0xd9689da0,0x1f90,0x11d3,{0x99,0x71,0x00,0xc0,0x4f,0x68,0xc8,0x76}}

  117. #endif


  118. #ifndef WSAID_CONNECTEX

  119. typedef BOOL (PASCAL FAR * LPFN_CONNECTEX) (
  120.     IN SOCKET s,
  121.     IN const struct sockaddr FAR *name,
  122.     IN int namelen,
  123.     IN PVOID lpSendBuffer OPTIONAL,
  124.     IN DWORD dwSendDataLength,
  125.     OUT LPDWORD lpdwBytesSent,
  126.     IN LPOVERLAPPED lpOverlapped
  127.     );

  128. #define WSAID_CONNECTEX \
  129.     {0x25a207b9,0xddf3,0x4660,{0x8e,0xe9,0x76,0xe5,0x8c,0x74,0x06,0x3e}}

  130. #endif


  131. #ifndef WSAID_DISCONNECTEX

  132. typedef BOOL (PASCAL FAR * LPFN_DISCONNECTEX) (
  133.     IN SOCKET s,
  134.     IN LPOVERLAPPED lpOverlapped,
  135.     IN DWORD  dwFlags,
  136.     IN DWORD  dwReserved
  137.     );

  138. #define WSAID_DISCONNECTEX                                                   \
  139.     {0x7fda2e11,0x8630,0x436f,{0xa0,0x31,0xf5,0x36,0xa6,0xee,0xc1,0x57}}

  140. #endif


  141. extern LPFN_ACCEPTEX              ngx_acceptex;
  142. extern LPFN_GETACCEPTEXSOCKADDRS  ngx_getacceptexsockaddrs;
  143. extern LPFN_TRANSMITFILE          ngx_transmitfile;
  144. extern LPFN_TRANSMITPACKETS       ngx_transmitpackets;
  145. extern LPFN_CONNECTEX             ngx_connectex;
  146. extern LPFN_DISCONNECTEX          ngx_disconnectex;


  147. #if (NGX_HAVE_POLL && !defined POLLIN)

  148. /*
  149. * WSAPoll() is only available if _WIN32_WINNT >= 0x0600.
  150. * If it is not available during compilation, we try to
  151. * load it dynamically at runtime.
  152. */

  153. #define NGX_LOAD_WSAPOLL 1

  154. #define POLLRDNORM  0x0100
  155. #define POLLRDBAND  0x0200
  156. #define POLLIN      (POLLRDNORM | POLLRDBAND)
  157. #define POLLPRI     0x0400

  158. #define POLLWRNORM  0x0010
  159. #define POLLOUT     (POLLWRNORM)
  160. #define POLLWRBAND  0x0020

  161. #define POLLERR     0x0001
  162. #define POLLHUP     0x0002
  163. #define POLLNVAL    0x0004

  164. typedef struct pollfd {

  165.     SOCKET  fd;
  166.     SHORT   events;
  167.     SHORT   revents;

  168. } WSAPOLLFD, *PWSAPOLLFD, FAR *LPWSAPOLLFD;

  169. typedef int (WSAAPI *ngx_wsapoll_pt)(
  170.     LPWSAPOLLFD fdArray,
  171.     ULONG fds,
  172.     INT timeout
  173.     );

  174. extern ngx_wsapoll_pt             WSAPoll;
  175. extern ngx_uint_t                 ngx_have_wsapoll;

  176. #endif


  177. int ngx_tcp_push(ngx_socket_t s);
  178. #define ngx_tcp_push_n            "tcp_push()"


  179. #endif /* _NGX_SOCKET_H_INCLUDED_ */