2 * PROJECT: ws2_32.dll API tests
3 * LICENSE: GPLv2 or any later version
4 * FILE: apitests/ws2_32/helpers.c
5 * PURPOSE: Helper functions for the socket tests
6 * COPYRIGHT: Copyright 2008 Colin Finck <mail@colinfinck.de>
14 int CreateSocket(SOCKET
* psck
)
16 /* Create the socket */
17 *psck
= socket(AF_INET
, SOCK_STREAM
, IPPROTO_TCP
);
18 ok(*psck
!= INVALID_SOCKET
, "*psck = %d\n", *psck
);
20 if(*psck
== INVALID_SOCKET
)
22 printf("Winsock error code is %u\n", WSAGetLastError());
30 int ConnectToReactOSWebsite(SOCKET sck
)
34 struct sockaddr_in sa
;
36 /* Connect to "www.reactos.org" */
37 host
= gethostbyname("www.reactos.org");
39 sa
.sin_family
= AF_INET
;
40 sa
.sin_addr
.s_addr
= *(u_long
*)host
->h_addr_list
[0];
41 sa
.sin_port
= htons(80);
43 SCKTEST(connect(sck
, (struct sockaddr
*)&sa
, sizeof(sa
)));
48 int GetRequestAndWait(SOCKET sck
)
50 const char szGetRequest
[] = "GET / HTTP/1.0\r\n\r\n";
52 struct fd_set readable
;
54 /* Send the GET request */
55 SCKTEST(send(sck
, szGetRequest
, strlen(szGetRequest
), 0));
56 ok(iResult
== strlen(szGetRequest
), "iResult = %d\n", iResult
);
57 #if 0 /* breaks windows too */
58 /* Shutdown the SEND connection */
59 SCKTEST(shutdown(sck
, SD_SEND
));
61 /* Wait until we're ready to read */
63 FD_SET(sck
, &readable
);
65 SCKTEST(select(0, &readable
, NULL
, NULL
, NULL
));