The OpenD Programming Language

1 /**
2  * Windows API header module
3  *
4  * Translated from MinGW Windows headers
5  *
6  * Authors: Daniel Keep
7  * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
8  * Source: $(DRUNTIMESRC core/sys/windows/_mswsock.d)
9  */
10 module core.sys.windows.mswsock;
11 version (Windows):
12 
13 import core.sys.windows.winbase, core.sys.windows.windef;
14 import core.sys.windows.basetyps, core.sys.windows.w32api;
15 
16 import core.sys.windows.winsock2;
17 
18 //static if (_WIN32_WINNT >= 0x500) {
19     enum {
20         /* WinNT5+:
21            ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/socket_options.htm */
22         SO_MAXDG             = 0x7009,
23         SO_MAXPATHDG         = 0x700A,
24     }
25 //}
26 
27 enum {
28     /* WinNT4+:
29        ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/socket_options_for_windows_nt_4_0_2.htm */
30     SO_CONNDATA              = 0x7000,
31     SO_CONNOPT               = 0x7001,
32     SO_DISCDATA              = 0x7002,
33     SO_DISCOPT               = 0x7003,
34     SO_CONNDATALEN           = 0x7004,
35     SO_CONNOPTLEN            = 0x7005,
36     SO_DISCDATALEN           = 0x7006,
37     SO_DISCOPTLEN            = 0x7007,
38 
39     /* WinNT4:
40        ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/socket_options.htm */
41     SO_UPDATE_ACCEPT_CONTENT = 0x700B,
42 }
43 
44 enum {
45     /* Win95+, WinNT4+ but apparently shouldn't used: mark as deprecated?
46        ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/socket_options.htm */
47     SO_OPENTYPE                  = 0x7008,
48 
49     /* Win95+; these two are passed to the SO_OPENTYPE option as arguments,
50        so would they be deprecated as well?
51        ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/socket_options.htm */
52     SO_SYNCHRONOUS_ALERT         = 0x0010,
53     SO_SYNCHRONOUS_NONALERT      = 0x0020,
54 
55     /* Win95:
56        ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/socket_options.htm */
57     SO_CONNECT_TIME              = 0x700C,
58 }
59 
60 
61 enum {
62     TCP_BSDURGENT = 0x7000,
63 }
64 
65 /* These *appear* to be constants for passing to the TransmitFile /
66    TransmitPackets functions, which are available in WinNT3.51+
67    ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/transmitfile_2.htm */
68 enum {
69     TF_DISCONNECT         = 1,
70     TF_REUSE_SOCKET       = 2,
71     TF_WRITE_BEHIND       = 4,
72     TF_USE_DEFAULT_WORKER = 0,
73     TF_USE_SYSTEM_THREAD  = 16,
74     TF_USE_KERNEL_APC     = 32
75 }
76 
77 /* Win95+, WinNT3.51+
78    ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/transmit_file_buffers_2.htm */
79 struct TRANSMIT_FILE_BUFFERS {
80     PVOID Head;
81     DWORD HeadLength;
82     PVOID Tail;
83     DWORD TailLength;
84 }
85 alias TRANSMIT_FILE_BUFFERS* PTRANSMIT_FILE_BUFFERS, LPTRANSMIT_FILE_BUFFERS;
86 
87 extern(Windows) {
88     /* Win95+, WinNT3.51+
89        ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/wsarecvex_2.htm */
90     int WSARecvEx(SOCKET, char*, int, int*);
91 
92     /* Win95+, WinNT3.51+
93        ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/getacceptexSOCKADDRs_2.htm */
94     VOID GetAcceptExSockaddrs(PVOID, DWORD, DWORD, DWORD, SOCKADDR**, LPINT, SOCKADDR**, LPINT);
95 
96     /* WinNT3.51+
97        ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/transmitfile_2.htm */
98     BOOL TransmitFile(SOCKET, HANDLE, DWORD, DWORD, LPOVERLAPPED, LPTRANSMIT_FILE_BUFFERS, DWORD);
99 
100     /* WinNT3.51+
101        ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/acceptex_2.htm */
102     alias BOOL function(SOCKET, SOCKET, PVOID, DWORD, DWORD, DWORD, LPDWORD, LPOVERLAPPED) LPFN_ACCEPTEX;
103     const GUID WSAID_ACCEPTEX = {0xb5367df1,0xcbac,0x11cf,[0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92]};
104 
105     alias BOOL function(SOCKET, SOCKADDR*, int, PVOID, DWORD, LPDWORD, LPOVERLAPPED) LPFN_CONNECTEX;
106     const GUID WSAID_CONNECTEX = {0x25a207b9,0xddf3,0x4660,[0x8e,0xe9,0x76,0xe5,0x8c,0x74,0x06,0x3e]};
107 }
108 
109 static if (_WIN32_WINNT >= 0x501) {
110     /*  These appear to be constants for the TRANSMIT_PACKETS_ELEMENT
111      *  structure below, so I've given them the same minimum version
112      */
113     enum {
114         TP_ELEMENT_FILE   = 1,
115         TP_ELEMENT_MEMORY = 2,
116         TP_ELEMENT_EOP    = 4
117     }
118 
119     /*  WinXP+, Srv2k3+
120      *  ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/transmit_packets_element_2.htm
121      */
122     struct TRANSMIT_PACKETS_ELEMENT {
123         ULONG dwElFlags;
124         ULONG cLength;
125         union {
126             struct {
127                 LARGE_INTEGER nFileOffset;
128                 HANDLE        hFile;
129             }
130             PVOID pBuffer;
131         }
132     }
133 
134     struct WSABUF {
135         ULONG len;
136         CHAR* buf;
137     }
138 
139     alias WSABUF* LPWSABUF;
140 
141     /*  WinXP+, Server2003+:
142      *  ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/wsamsg_2.htm
143      */
144     struct WSAMSG {
145         LPSOCKADDR name;
146         INT        namelen;
147         LPWSABUF   lpBuffers;
148         DWORD      dwBufferCount;
149         WSABUF     Control;
150         DWORD      dwFlags;
151     }
152 
153     alias WSAMSG* PWSAMSG, LPWSAMSG;
154 
155     /* According to MSDN docs, the WSAMSG.Control buffer starts with a
156        cmsghdr header of the following form.  See also RFC 2292. */
157     /* DK: Confirmed.  So I suppose these should get the same version as
158        WSAMSG... */
159     struct WSACMSGHDR {
160         SIZE_T cmsg_len;
161         INT  cmsg_level;
162         INT  cmsg_type;
163         // followed by UCHAR cmsg_data[];
164     }
165 }
166 
167 static if (_WIN32_WINNT >= 0x600) {
168     /* TODO: Standard Posix.1g macros as per RFC 2292, with WSA_uglification. */
169     /* DK: MinGW doesn't define these, and neither does the MSDN docs.  Might have
170        to actually look up RFC 2292... */
171     /+
172     #if 0
173     #define WSA_CMSG_FIRSTHDR(mhdr)
174     #define WSA_CMSG_NXTHDR(mhdr, cmsg)
175     #define WSA_CMSG_SPACE(length)
176     #define WSA_CMSG_LEN(length)
177     #endif
178     +/
179 
180     /*  Win Vista+, Srv2k3+
181      *  ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/disconnectex_2.htm
182      */
183     extern(Windows) BOOL DisconnectEx(SOCKET, LPOVERLAPPED, DWORD, DWORD);
184 }
185 
186 static if (_WIN32_WINNT >= 0x501) {
187     /*  WinXP+, Srv2k3+
188      *  ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/wsarecvmsg_2.htm
189      */
190     extern(Windows) int WSARecvMsg(SOCKET, LPWSAMSG, LPDWORD, LPWSAOVERLAPPED, LPWSAOVERLAPPED_COMPLETION_ROUTINE);
191 }