16{
26 int nConRes, nSockNameRes;
40 unsigned int Addr_con_locLoopCount = 0,
41 ServerSocketLoopCount = 0;
42
44 {
45 skip(
"WSAStartup failed\n");
46 return;
47 }
48
53
55 {
56 skip(
"ERROR: Server socket creation failed\n");
57 return;
58 }
60 {
61 skip(
"ERROR: Client socket creation failed\n");
63 return;
64 }
66 {
67 skip(
"ERROR: Server WSAEvent creation failed\n");
70 return;
71 }
73 {
74 skip(
"ERROR: Client WSAEvent creation failed\n");
78 return;
79 }
82 {
83 ok(ent !=
NULL,
"ERROR: gethostbyname '127.0.0.1' failed, trying 'localhost'\n");
85
87 {
88 skip(
"ERROR: gethostbyname 'localhost' failed\n");
89 goto done;
90 }
91 }
92
93 server_addr_in.sin_family =
AF_INET;
96
97
98 trace(
"Initializing server and client connections ...\n");
102
103
105 ok(
ioctlsocket(ClientSocket,
FIONBIO, &ulValue) == 0,
"ERROR: client ioctlsocket FIONBIO failed\n");
106
107
108 trace(
"Starting server listening mode ...\n");
110
111 trace(
"Starting client to server connection ...\n");
112
113 nConRes =
connect(ClientSocket, (
struct sockaddr*)&server_addr_in,
sizeof(server_addr_in));
114 ok(nConRes ==
SOCKET_ERROR,
"ERROR: client connect() result is not SOCKET_ERROR\n");
116
118 fSockets[1] = ClientSocket;
119
120 fEvents[0] = ServerEvent;
121 fEvents[1] = ClientEvent;
122
124 {
126
129 {
130 ok(
FALSE,
"Unknown event received %lu\n", dwWait);
131 skip(
"ERROR: Connection timeout\n");
132 break;
133 }
134
136
138 {
139 trace(
"Event FD_ACCEPT...\n");
142 {
143 addrsize = sizeof(addr_remote);
147 }
148 }
149
151 {
152 trace(
"Event FD_CONNECT...\n");
155 {
156 len =
sizeof(addr_con_loc);
159 }
160 }
161 }
165
166
169
171 {
172 skip(
"ERROR: Server socket creation failed\n");
173 return;
174 }
176 {
177 skip(
"ERROR: Client socket creation failed\n");
179 return;
180 }
183 {
184 ok(ent !=
NULL,
"ERROR: gethostbyname '127.0.0.1' failed, trying 'localhost'\n");
186
188 {
189 skip(
"ERROR: gethostbyname 'localhost' failed\n");
190 goto done;
191 }
192 }
193
194 server_addr_in.sin_family =
AF_INET;
197
198
199 trace(
"Initializing server and client connections ...\n");
202
203
204 ok(
ioctlsocket(ClientSocket,
FIONBIO, &ulValue) == 0,
"ERROR: client ioctlsocket FIONBIO failed\n");
205
206
207 trace(
"Starting server listening mode ...\n");
209
213
215 {
216 len =
sizeof(addr_con_loc);
218 if (
dwFlags == 0 && !ConnectSent)
219 {
222 trace(
"Starting client to server connection ...\n");
223
224 nConRes =
connect(ClientSocket, (
struct sockaddr*)&server_addr_in,
sizeof(server_addr_in));
225 ok(nConRes ==
SOCKET_ERROR,
"ERROR: client connect() result is not SOCKET_ERROR\n");
228 continue;
229 }
230 else
231 {
232 if (nSockNameRes != 0)
233 ok(
FALSE,
"ERROR: getsockname function failed, expected 0 error %d\n", nSockNameRes);
234 if (
len !=
sizeof(addr_con_loc))
235 ok(
FALSE,
"ERROR: getsockname function wrong size, expected %Iu returned %d\n",
sizeof(addr_con_loc),
len);
236
237 if (addr_con_loc.sin_addr.s_addr == 0ul)
238 {
240 {
241 ok(
FALSE,
"Giving up, on getsockname() (%u/%u), as addr_con_loc is not set yet\n",
243 goto done;
244 }
245
246 trace(
"Looping, for getsockname() (%u/%u), as addr_con_loc is not set yet\n",
249 continue;
250 }
251
252 if (addr_con_loc.sin_addr.s_addr != server_addr_in.sin_addr.s_addr)
253 ok(
FALSE,
"ERROR: getsockname function wrong addr, expected %08lx returned %08lx\n", server_addr_in.sin_addr.s_addr, addr_con_loc.sin_addr.s_addr);
254 }
256 {
257 trace(
"Select CONNECT...\n");
259 }
260
265 FD_SET(ClientSocket, &select_rfds);
267 FD_SET(ClientSocket, &select_wfds);
269 FD_SET(ClientSocket, &select_efds);
271 {
272 FD_SET(sockaccept, &select_rfds);
273 FD_SET(sockaccept, &select_wfds);
274 FD_SET(sockaccept, &select_efds);
275 }
276 if (
select(0, &select_rfds, &select_wfds, &select_efds, &
timeval) != 0)
277 {
279 {
280 trace(
"Select ACCEPT&CONNECT...\n");
281 ok(
FD_ISSET(ClientSocket, &select_wfds),
"ClientSocket is not writable\n");
282 ok(
FD_ISSET(sockaccept, &select_wfds),
"sockaccept is not writable\n");
284 }
286 {
287 trace(
"Select ACCEPT...\n");
288 ok(!
FD_ISSET(ClientSocket, &select_wfds),
"ClientSocket is writable\n");
289 ok(
FD_ISSET(sockaccept, &select_wfds),
"sockaccept is not writable\n");
291 }
293 {
295 {
296 trace(
"Select ACCEPT...\n");
297 addrsize = sizeof(addr_remote);
301 }
302 else
303 {
305 {
306 ok(
FALSE,
"Giving up, on select() (%u/%u), as ServerSocket is not readable yet\n",
308 goto done;
309 }
310
311 trace(
"Looping, for select() (%u/%u), as ServerSocket is not readable yet\n",
314 continue;
315 }
316 }
317 }
318 }
319
320done:
326
328}
BOOL WSAAPI WSACloseEvent(IN WSAEVENT hEvent)
INT WSAAPI WSAEnumNetworkEvents(IN SOCKET s, IN WSAEVENT hEventObject, OUT LPWSANETWORKEVENTS lpNetworkEvents)
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
INT WSAAPI WSAEventSelect(IN SOCKET s, IN WSAEVENT hEventObject, IN LONG lNetworkEvents)
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
PHOSTENT WSAAPI gethostbyname(IN const char FAR *name)
#define memcpy(s1, s2, n)
INT WSAAPI getsockname(IN SOCKET s, OUT LPSOCKADDR name, IN OUT INT FAR *namelen)
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
int iErrorCode[FD_MAX_EVENTS]
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
WINSOCK_API_LINKAGE WSAEVENT WSAAPI WSACreateEvent(void)
#define WSA_INVALID_EVENT
#define FD_ISSET(fd, set)
int PASCAL FAR WSAGetLastError(void)
int PASCAL FAR WSACleanup(void)