1 module eventcore.internal.win32;
2 
3 version (Windows):
4 
5 public import core.sys.windows.windows;
6 public import core.sys.windows.winsock2;
7 public import core.stdc.config: c_ulong;
8 
9 extern(System) nothrow:
10 
11 enum {
12 	FD_READ = 0x0001,
13 	FD_WRITE = 0x0002,
14 	FD_OOB = 0x0004,
15 	FD_ACCEPT = 0x0008,
16 	FD_CONNECT = 0x0010,
17 	FD_CLOSE = 0x0020,
18 	FD_QOS = 0x0040,
19 	FD_GROUP_QOS = 0x0080,
20 	FD_ROUTING_INTERFACE_CHANGE = 0x0100,
21 	FD_ADDRESS_LIST_CHANGE = 0x0200
22 }
23 
24 
25 enum {
26 	WSA_FLAG_OVERLAPPED = 0x01
27 }
28 
29 enum {
30 	WSAPROTOCOL_LEN  = 255,
31 	MAX_PROTOCOL_CHAIN = 7,
32 }
33 
34 enum WSAEDISCON = 10101;
35 
36 enum WSA_OPERATION_ABORTED = 995;
37 enum WSA_IO_PENDING = 997;
38 
39 struct WSAPROTOCOL_INFOW {
40 	DWORD            dwServiceFlags1;
41 	DWORD            dwServiceFlags2;
42 	DWORD            dwServiceFlags3;
43 	DWORD            dwServiceFlags4;
44 	DWORD            dwProviderFlags;
45 	GUID             ProviderId;
46 	DWORD            dwCatalogEntryId;
47 	WSAPROTOCOLCHAIN ProtocolChain;
48 	int              iVersion;
49 	int              iAddressFamily;
50 	int              iMaxSockAddr;
51 	int              iMinSockAddr;
52 	int              iSocketType;
53 	int              iProtocol;
54 	int              iProtocolMaxOffset;
55 	int              iNetworkByteOrder;
56 	int              iSecurityScheme;
57 	DWORD            dwMessageSize;
58 	DWORD            dwProviderReserved;
59 	WCHAR[WSAPROTOCOL_LEN+1] szProtocol;
60 }
61 
62 struct WSAPROTOCOLCHAIN {
63 	int ChainLen;
64 	DWORD[MAX_PROTOCOL_CHAIN] ChainEntries;
65 }
66 
67 struct WSABUF {
68 	size_t   len;
69 	ubyte *buf;
70 }
71 
72 struct ADDRINFOEXW {
73 	int ai_flags;
74 	int ai_family;
75 	int ai_socktype;
76 	int ai_protocol;
77 	size_t ai_addrlen;
78 	LPCWSTR ai_canonname;
79 	sockaddr* ai_addr;
80 	void* ai_blob;
81 	size_t ai_bloblen;
82 	GUID* ai_provider;
83 	ADDRINFOEXW* ai_next;
84 }
85 
86 struct ADDRINFOA {
87 	int ai_flags;
88 	int ai_family;
89 	int ai_socktype;
90 	int ai_protocol;
91 	size_t ai_addrlen;
92 	LPSTR ai_canonname;
93 	sockaddr* ai_addr;
94 	ADDRINFOA* ai_next;
95 }
96 
97 struct ADDRINFOW {
98 	int ai_flags;
99 	int ai_family;
100 	int ai_socktype;
101 	int ai_protocol;
102 	size_t ai_addrlen;
103 	LPWSTR ai_canonname;
104 	sockaddr* ai_addr;
105 	ADDRINFOW* ai_next;
106 }
107 
108 // https://msdn.microsoft.com/en-us/library/windows/desktop/dd877220(v=vs.85).aspx
109 struct tcp_keepalive {
110 	c_ulong onoff;
111 	c_ulong keepalivetime;
112 	c_ulong keepaliveinterval;
113 };
114 
115 // https://gist.github.com/piscisaureus/906386#file-winsock2-h-L1099
116 enum : DWORD {
117 	IOC_VENDOR = 0x18000000,
118 	IOC_OUT = 0x40000000,
119 	IOC_IN = 0x80000000
120 }
121 
122 DWORD _WSAIOW(DWORD x, DWORD y) pure @safe
123 {
124 	return IOC_IN | x | y;
125 }
126 
127 enum : DWORD {
128 	SIO_KEEPALIVE_VALS = _WSAIOW(IOC_VENDOR, 4)
129 }
130 
131 struct WSAPROTOCOL_INFO {
132 	DWORD            dwServiceFlags1;
133 	DWORD            dwServiceFlags2;
134 	DWORD            dwServiceFlags3;
135 	DWORD            dwServiceFlags4;
136 	DWORD            dwProviderFlags;
137 	GUID             ProviderId;
138 	DWORD            dwCatalogEntryId;
139 	WSAPROTOCOLCHAIN ProtocolChain;
140 	int              iVersion;
141 	int              iAddressFamily;
142 	int              iMaxSockAddr;
143 	int              iMinSockAddr;
144 	int              iSocketType;
145 	int              iProtocol;
146 	int              iProtocolMaxOffset;
147 	int              iNetworkByteOrder;
148 	int              iSecurityScheme;
149 	DWORD            dwMessageSize;
150 	DWORD            dwProviderReserved;
151 	CHAR[WSAPROTOCOL_LEN+1] szProtocol;
152 }
153 alias SOCKADDR = sockaddr;
154 
155 alias LPWSAOVERLAPPED_COMPLETION_ROUTINEX = void function(DWORD, DWORD, WSAOVERLAPPEDX*, DWORD);
156 alias LPLOOKUPSERVICE_COMPLETION_ROUTINE = void function(DWORD, DWORD, WSAOVERLAPPEDX*);
157 alias LPCONDITIONPROC = void*;
158 alias LPTRANSMIT_FILE_BUFFERS = void*;
159 
160 int WSARecv(SOCKET s, WSABUF* lpBuffers, DWORD dwBufferCount, DWORD* lpNumberOfBytesRecvd, DWORD* lpFlags, in WSAOVERLAPPEDX* lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINEX lpCompletionRoutine);
161 int WSARecvFrom(SOCKET s, WSABUF* lpBuffers, DWORD dwBufferCount, DWORD* lpNumberOfBytesRecvd, DWORD* lpFlags, SOCKADDR *lpFrom, LPINT lpFromlen, in WSAOVERLAPPEDX* lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINEX lpCompletionRoutine);
162 int WSASend(SOCKET s, in WSABUF* lpBuffers, DWORD dwBufferCount, DWORD* lpNumberOfBytesSent, DWORD dwFlags, in WSAOVERLAPPEDX* lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINEX lpCompletionRoutine);
163 int WSASendTo(SOCKET s, in WSABUF* lpBuffers, DWORD dwBufferCount, DWORD* lpNumberOfBytesSent, DWORD dwFlags, const(SOCKADDR) *lpTo, int iToLenin, WSAOVERLAPPEDX* lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINEX lpCompletionRoutine);
164 int GetAddrInfoExW(LPCWSTR pName, LPCWSTR pServiceName, DWORD dwNameSpace, GUID* lpNspId, const ADDRINFOEXW *pHints, ADDRINFOEXW **ppResult, timeval *timeout, WSAOVERLAPPEDX* lpOverlapped, LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine, HANDLE* lpNameHandle);
165 
166 @nogc:
167 SOCKET WSAAccept(SOCKET s, sockaddr *addr, INT* addrlen, LPCONDITIONPROC lpfnCondition, DWORD_PTR dwCallbackData);
168 int WSAAsyncSelect(SOCKET s, HWND hWnd, uint wMsg, sizediff_t lEvent);
169 SOCKET WSASocketW(int af, int type, int protocol, WSAPROTOCOL_INFOW *lpProtocolInfo, uint g, DWORD dwFlags);
170 int WSASendDisconnect(SOCKET s, WSABUF* lpOutboundDisconnectData);
171 INT WSAStringToAddressA(in LPTSTR AddressString, INT AddressFamily, in WSAPROTOCOL_INFO* lpProtocolInfo, SOCKADDR* lpAddress, INT* lpAddressLength);
172 INT WSAStringToAddressW(in LPWSTR AddressString, INT AddressFamily, in WSAPROTOCOL_INFOW* lpProtocolInfo, SOCKADDR* lpAddress, INT* lpAddressLength);
173 INT WSAAddressToStringW(in SOCKADDR* lpsaAddress, DWORD dwAddressLength, in WSAPROTOCOL_INFO* lpProtocolInfo, LPWSTR lpszAddressString, DWORD* lpdwAddressStringLength);
174 int GetAddrInfoW(LPCWSTR pName, LPCWSTR pServiceName, const ADDRINFOW *pHints, ADDRINFOW **ppResult);
175 int getaddrinfo(LPCSTR pName, LPCSTR pServiceName, const ADDRINFOA *pHints, ADDRINFOA **ppResult);
176 void FreeAddrInfoW(ADDRINFOW* pAddrInfo);
177 void FreeAddrInfoExW(ADDRINFOEXW* pAddrInfo);
178 void freeaddrinfo(ADDRINFOA* ai);
179 BOOL TransmitFile(SOCKET hSocket, HANDLE hFile, DWORD nNumberOfBytesToWrite, DWORD nNumberOfBytesPerSend, OVERLAPPED* lpOverlapped, LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers, DWORD dwFlags);
180 BOOL CancelIoEx(HANDLE hFile, LPOVERLAPPED lpOverlapped);
181 int WSAIoctl(SOCKET s, DWORD dwIoControlCode, void* lpvInBuffer, DWORD cbInBuffer, void* lpvOutBuffer, DWORD cbOutBuffer, DWORD* lpcbBytesReturned, in WSAOVERLAPPEDX* lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINEX lpCompletionRoutine);
182 
183 /*struct WSAOVERLAPPEDX {
184 	ULONG_PTR Internal;
185 	ULONG_PTR InternalHigh;
186 	union {
187 		struct {
188 			DWORD Offset;
189 			DWORD OffsetHigh;
190 		}
191 		PVOID  Pointer;
192 	}
193 	HANDLE hEvent;
194 }*/
195 
196 alias WSAOVERLAPPEDX = OVERLAPPED;