ngx_socket.h revision e18a033b
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
5 */
6
7
8#ifndef _NGX_SOCKET_H_INCLUDED_
9#define _NGX_SOCKET_H_INCLUDED_
10
11
12#include <ngx_config.h>
13#include <ngx_core.h>
14
15
16#define NGX_WRITE_SHUTDOWN SD_SEND
17
18
19typedef SOCKET  ngx_socket_t;
20typedef int     socklen_t;
21
22
23#define ngx_socket(af, type, proto)                                          \
24    WSASocketW(af, type, proto, NULL, 0, WSA_FLAG_OVERLAPPED)
25
26#define ngx_socket_n        "WSASocketW()"
27
28int ngx_nonblocking(ngx_socket_t s);
29int ngx_blocking(ngx_socket_t s);
30
31#define ngx_nonblocking_n   "ioctlsocket(FIONBIO)"
32#define ngx_blocking_n      "ioctlsocket(!FIONBIO)"
33
34#define ngx_shutdown_socket    shutdown
35#define ngx_shutdown_socket_n  "shutdown()"
36
37#define ngx_close_socket    closesocket
38#define ngx_close_socket_n  "closesocket()"
39
40
41#ifndef WSAID_ACCEPTEX
42
43typedef BOOL (PASCAL FAR * LPFN_ACCEPTEX)(
44    IN SOCKET sListenSocket,
45    IN SOCKET sAcceptSocket,
46    IN PVOID lpOutputBuffer,
47    IN DWORD dwReceiveDataLength,
48    IN DWORD dwLocalAddressLength,
49    IN DWORD dwRemoteAddressLength,
50    OUT LPDWORD lpdwBytesReceived,
51    IN LPOVERLAPPED lpOverlapped
52    );
53
54#define WSAID_ACCEPTEX                                                       \
55    {0xb5367df1,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}
56
57#endif
58
59
60#ifndef WSAID_GETACCEPTEXSOCKADDRS
61
62typedef VOID (PASCAL FAR * LPFN_GETACCEPTEXSOCKADDRS)(
63    IN PVOID lpOutputBuffer,
64    IN DWORD dwReceiveDataLength,
65    IN DWORD dwLocalAddressLength,
66    IN DWORD dwRemoteAddressLength,
67    OUT struct sockaddr **LocalSockaddr,
68    OUT LPINT LocalSockaddrLength,
69    OUT struct sockaddr **RemoteSockaddr,
70    OUT LPINT RemoteSockaddrLength
71    );
72
73#define WSAID_GETACCEPTEXSOCKADDRS                                           \
74        {0xb5367df2,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}
75
76#endif
77
78
79#ifndef WSAID_TRANSMITFILE
80
81#ifndef TF_DISCONNECT
82
83#define TF_DISCONNECT           1
84#define TF_REUSE_SOCKET         2
85#define TF_WRITE_BEHIND         4
86#define TF_USE_DEFAULT_WORKER   0
87#define TF_USE_SYSTEM_THREAD    16
88#define TF_USE_KERNEL_APC       32
89
90typedef struct _TRANSMIT_FILE_BUFFERS {
91    LPVOID Head;
92    DWORD HeadLength;
93    LPVOID Tail;
94    DWORD TailLength;
95} TRANSMIT_FILE_BUFFERS, *PTRANSMIT_FILE_BUFFERS, FAR *LPTRANSMIT_FILE_BUFFERS;
96
97#endif
98
99typedef BOOL (PASCAL FAR * LPFN_TRANSMITFILE)(
100    IN SOCKET hSocket,
101    IN HANDLE hFile,
102    IN DWORD nNumberOfBytesToWrite,
103    IN DWORD nNumberOfBytesPerSend,
104    IN LPOVERLAPPED lpOverlapped,
105    IN LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers,
106    IN DWORD dwReserved
107    );
108
109#define WSAID_TRANSMITFILE                                                   \
110    {0xb5367df0,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}
111
112#endif
113
114
115#ifndef WSAID_TRANSMITPACKETS
116
117/* OpenWatcom has a swapped TP_ELEMENT_FILE and TP_ELEMENT_MEMORY definition */
118
119#ifndef TP_ELEMENT_FILE
120
121#ifdef _MSC_VER
122#pragma warning(disable:4201) /* Nonstandard extension, nameless struct/union */
123#endif
124
125typedef struct _TRANSMIT_PACKETS_ELEMENT {
126    ULONG dwElFlags;
127#define TP_ELEMENT_MEMORY   1
128#define TP_ELEMENT_FILE     2
129#define TP_ELEMENT_EOP      4
130    ULONG cLength;
131    union {
132        struct {
133            LARGE_INTEGER nFileOffset;
134            HANDLE        hFile;
135        };
136        PVOID             pBuffer;
137    };
138} TRANSMIT_PACKETS_ELEMENT, *PTRANSMIT_PACKETS_ELEMENT,
139    FAR *LPTRANSMIT_PACKETS_ELEMENT;
140
141#ifdef _MSC_VER
142#pragma warning(default:4201)
143#endif
144
145#endif
146
147typedef BOOL (PASCAL FAR * LPFN_TRANSMITPACKETS) (
148    SOCKET hSocket,
149    TRANSMIT_PACKETS_ELEMENT *lpPacketArray,
150    DWORD nElementCount,
151    DWORD nSendSize,
152    LPOVERLAPPED lpOverlapped,
153    DWORD dwFlags
154    );
155
156#define WSAID_TRANSMITPACKETS                                                \
157    {0xd9689da0,0x1f90,0x11d3,{0x99,0x71,0x00,0xc0,0x4f,0x68,0xc8,0x76}}
158
159#endif
160
161
162#ifndef WSAID_CONNECTEX
163
164typedef BOOL (PASCAL FAR * LPFN_CONNECTEX) (
165    IN SOCKET s,
166    IN const struct sockaddr FAR *name,
167    IN int namelen,
168    IN PVOID lpSendBuffer OPTIONAL,
169    IN DWORD dwSendDataLength,
170    OUT LPDWORD lpdwBytesSent,
171    IN LPOVERLAPPED lpOverlapped
172    );
173
174#define WSAID_CONNECTEX \
175    {0x25a207b9,0xddf3,0x4660,{0x8e,0xe9,0x76,0xe5,0x8c,0x74,0x06,0x3e}}
176
177#endif
178
179
180#ifndef WSAID_DISCONNECTEX
181
182typedef BOOL (PASCAL FAR * LPFN_DISCONNECTEX) (
183    IN SOCKET s,
184    IN LPOVERLAPPED lpOverlapped,
185    IN DWORD  dwFlags,
186    IN DWORD  dwReserved
187    );
188
189#define WSAID_DISCONNECTEX                                                   \
190    {0x7fda2e11,0x8630,0x436f,{0xa0,0x31,0xf5,0x36,0xa6,0xee,0xc1,0x57}}
191
192#endif
193
194
195extern LPFN_ACCEPTEX              ngx_acceptex;
196extern LPFN_GETACCEPTEXSOCKADDRS  ngx_getacceptexsockaddrs;
197extern LPFN_TRANSMITFILE          ngx_transmitfile;
198extern LPFN_TRANSMITPACKETS       ngx_transmitpackets;
199extern LPFN_CONNECTEX             ngx_connectex;
200extern LPFN_DISCONNECTEX          ngx_disconnectex;
201
202
203int ngx_tcp_push(ngx_socket_t s);
204#define ngx_tcp_push_n            "tcp_push()"
205
206
207#endif /* _NGX_SOCKET_H_INCLUDED_ */
208