ReactOS 0.4.15-dev-8219-ge8b88cf
WSARecv.c File Reference
#include "ws2_32.h"
Include dependency graph for WSARecv.c:

Go to the source code of this file.

Macros

#define RECV_BUF   4
 
#define WSARecv_TIMEOUT   2000
 

Functions

void CALLBACK completion (DWORD dwError, DWORD cbTransferred, LPWSAOVERLAPPED lpOverlapped, DWORD dwFlags)
 
void Test_WSARecv ()
 
 START_TEST (WSARecv)
 

Variables

static int count = 0
 

Macro Definition Documentation

◆ RECV_BUF

#define RECV_BUF   4

Definition at line 10 of file WSARecv.c.

◆ WSARecv_TIMEOUT

#define WSARecv_TIMEOUT   2000

Definition at line 11 of file WSARecv.c.

Function Documentation

◆ completion()

void CALLBACK completion ( DWORD  dwError,
DWORD  cbTransferred,
LPWSAOVERLAPPED  lpOverlapped,
DWORD  dwFlags 
)

Definition at line 16 of file WSARecv.c.

21{
22 //trace("completion called dwFlags %ld cbTransferred %ld lpOverlapped %p dwFlags %ld\n", dwError, cbTransferred, lpOverlapped, dwFlags);
23 count++;
24 ok(count == 1, "completion sould be called only once count = %d\n", count);
25 ok(dwError == 0, "dwError = %ld\n", dwError);
26 ok(cbTransferred == RECV_BUF, "cbTransferred %ld != %d\n", cbTransferred, RECV_BUF);
27 ok(lpOverlapped != NULL, "lpOverlapped %p\n", lpOverlapped);
28 if (lpOverlapped)
29 {
30 ok(lpOverlapped->hEvent != INVALID_HANDLE_VALUE, "lpOverlapped->hEvent %p\n", lpOverlapped->hEvent);
33 }
34}
#define RECV_BUF
Definition: WSARecv.c:10
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WSAAPI WSASetEvent(IN WSAEVENT hEvent)
Definition: event.c:64
GLuint GLuint GLsizei count
Definition: gl.h:1545
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:93

Referenced by _check_pipe_handle_state(), and Test_WSARecv().

◆ START_TEST()

START_TEST ( WSARecv  )

Definition at line 203 of file WSARecv.c.

204{
205 Test_WSARecv();
206}
void Test_WSARecv()
Definition: WSARecv.c:36

◆ Test_WSARecv()

void Test_WSARecv ( )

Definition at line 36 of file WSARecv.c.

37{
38 const char szDummyBytes[RECV_BUF] = { 0xFF, 0x00, 0xFF, 0x00 };
39
40 char szBuf[RECV_BUF];
41 char szRecvBuf[RECV_BUF];
42 int iResult, err;
43 SOCKET sck;
44 WSADATA wdata;
46 DWORD dwRecv, dwSent, dwFlags;
48 char szGetRequest[] = "GET / HTTP/1.0\r\n\r\n";
49 struct fd_set readable;
50 BOOL ret;
51
52 /* Start up Winsock */
53 iResult = WSAStartup(MAKEWORD(2, 2), &wdata);
54 ok(iResult == 0, "WSAStartup failed, iResult == %d\n", iResult);
55
56 /* If we call recv without a socket, it should return with an error and do nothing. */
57 memcpy(szBuf, szDummyBytes, RECV_BUF);
58 buffers.buf = szBuf;
59 buffers.len = sizeof(szBuf);
60 dwFlags = 0;
61 dwRecv = 0;
62 iResult = WSARecv(0, &buffers, 1, &dwRecv, &dwFlags, NULL, NULL);
63 ok(iResult == SOCKET_ERROR, "iRseult = %d\n", iResult);
64 ok(!memcmp(szBuf, szDummyBytes, RECV_BUF), "not equal\n");
65
66 /* Create the socket */
68 if(sck == INVALID_SOCKET)
69 {
70 WSACleanup();
71 skip("CreateSocket failed. Aborting test.\n");
72 return;
73 }
74
75 /* Now we can pass at least a socket, but we have no connection yet. Should return with an error and do nothing. */
76 memcpy(szBuf, szDummyBytes, RECV_BUF);
77 buffers.buf = szBuf;
78 buffers.len = sizeof(szBuf);
79 dwFlags = 0;
80 dwRecv = 0;
81 iResult = WSARecv(sck, &buffers, 1, &dwRecv, &dwFlags, NULL, NULL);
82 ok(iResult == SOCKET_ERROR, "iResult = %d\n", iResult);
83 ok(!memcmp(szBuf, szDummyBytes, RECV_BUF), "not equal\n");
84
85 /* Connect to "www.reactos.org" */
87 {
88 WSACleanup();
89 skip("ConnectToReactOSWebsite failed. Aborting test.\n");
90 return;
91 }
92
93 /* prepare overlapped */
94 memset(&overlapped, 0, sizeof(overlapped));
95 overlapped.hEvent = WSACreateEvent();
96
97 /* Send the GET request */
98 buffers.buf = szGetRequest;
99 buffers.len = lstrlenA(szGetRequest);
100 dwSent = 0;
101 WSASetLastError(0xdeadbeef);
102 iResult = WSASend(sck, &buffers, 1, &dwSent, 0, &overlapped, NULL);
104 ok(iResult == 0 || (iResult == SOCKET_ERROR && err == WSA_IO_PENDING), "iResult = %d, %d\n", iResult, err);
105 if (err == WSA_IO_PENDING)
106 {
108 ok(iResult == WSA_WAIT_EVENT_0, "WSAWaitForMultipleEvents failed %d\n", iResult);
109 ret = WSAGetOverlappedResult(sck, &overlapped, &dwSent, TRUE, &dwFlags);
110 ok(ret, "WSAGetOverlappedResult failed %d\n", WSAGetLastError());
111 }
112 ok(dwSent == strlen(szGetRequest), "dwSent %ld != %d\n", dwSent, strlen(szGetRequest));
113#if 0 /* break windows too */
114 /* Shutdown the SEND connection */
115 iResult = shutdown(sck, SD_SEND);
116 ok(iResult != SOCKET_ERROR, "iResult = %d\n", iResult);
117#endif
118 /* Wait until we're ready to read */
119 FD_ZERO(&readable);
120 FD_SET(sck, &readable);
121
122 iResult = select(0, &readable, NULL, NULL, NULL);
123 ok(iResult != SOCKET_ERROR, "iResult = %d\n", iResult);
124
125 /* Receive the data. */
126 buffers.buf = szBuf;
127 buffers.len = sizeof(szBuf);
128 dwRecv = sizeof(szBuf);
129 iResult = WSARecv(sck, &buffers, 1, &dwRecv, &dwFlags, NULL, NULL);
130 ok(iResult != SOCKET_ERROR, "iResult = %d\n", iResult);
131 ok(dwRecv == sizeof(szBuf), "dwRecv %ld != %d\n", dwRecv, sizeof(szBuf));
132 /* MSG_PEEK is invalid for overlapped (MSDN), but passes??? */
133 buffers.buf = szRecvBuf;
134 buffers.len = sizeof(szRecvBuf);
136 dwRecv = sizeof(szRecvBuf);
137 ok(overlapped.hEvent != NULL, "WSACreateEvent failed %d\n", WSAGetLastError());
138 WSASetLastError(0xdeadbeef);
139 iResult = WSARecv(sck, &buffers, 1, &dwRecv, &dwFlags, &overlapped, NULL);
141 ok(iResult == 0 || (iResult == SOCKET_ERROR && err == WSA_IO_PENDING), "iResult = %d, %d\n", iResult, err);
142 if (err == WSA_IO_PENDING)
143 {
145 ok(iResult == WSA_WAIT_EVENT_0, "WSAWaitForMultipleEvents failed %d\n", iResult);
146 ret = WSAGetOverlappedResult(sck, &overlapped, &dwRecv, TRUE, &dwFlags);
147 ok(ret, "WSAGetOverlappedResult failed %d\n", WSAGetLastError());
148 }
149 ok(dwRecv == sizeof(szRecvBuf), "dwRecv %ld != %d\n", dwRecv, sizeof(szRecvBuf));
150 /* normal overlapped, no completion */
151 buffers.buf = szBuf;
152 buffers.len = sizeof(szBuf);
153 dwFlags = 0;
154 dwRecv = sizeof(szBuf);
156 WSASetLastError(0xdeadbeef);
157 iResult = WSARecv(sck, &buffers, 1, &dwRecv, &dwFlags, &overlapped, NULL);
159 ok(iResult == 0 || (iResult == SOCKET_ERROR && err == WSA_IO_PENDING), "iResult = %d, %d\n", iResult, err);
160 if (err == WSA_IO_PENDING)
161 {
163 ok(iResult == WSA_WAIT_EVENT_0, "WSAWaitForMultipleEvents failed %d\n", iResult);
164 ret = WSAGetOverlappedResult(sck, &overlapped, &dwRecv, TRUE, &dwFlags);
165 ok(ret, "WSAGetOverlappedResult failed %d\n", WSAGetLastError());
166 }
167 ok(dwRecv == sizeof(szBuf), "dwRecv %ld != %d\n", dwRecv, sizeof(szBuf));
168 ok(memcmp(szRecvBuf, szBuf, sizeof(szBuf)) == 0, "MSG_PEEK shouldn't have moved the pointer\n");
169 /* overlapped with completion */
170 dwFlags = 0;
171 dwRecv = sizeof(szBuf);
173 WSASetLastError(0xdeadbeef);
174 iResult = WSARecv(sck, &buffers, 1, &dwRecv, &dwFlags, &overlapped, &completion);
176 ok(iResult == 0 || (iResult == SOCKET_ERROR && err == WSA_IO_PENDING), "iResult = %d, %d\n", iResult, err);
177 if (err == WSA_IO_PENDING)
178 {
180 ok(iResult == WSA_WAIT_EVENT_0, "WSAWaitForMultipleEvents failed %d\n", iResult);
181 ret = WSAGetOverlappedResult(sck, &overlapped, &dwRecv, TRUE, &dwFlags);
182 ok(ret, "WSAGetOverlappedResult failed %d\n", WSAGetLastError());
183 }
184 ret = WSACloseEvent(overlapped.hEvent);
185 ok(ret, "WSACloseEvent failed %d\n", WSAGetLastError());
186 ok(dwRecv == sizeof(szBuf), "dwRecv %ld != %d\n", dwRecv, sizeof(szBuf));
187 /* no overlapped with completion */
188 dwFlags = 0;
189 dwRecv = sizeof(szBuf);
190 WSASetLastError(0xdeadbeef);
191 /* call doesn't fail, but completion is not called */
192 iResult = WSARecv(sck, &buffers, 1, &dwRecv, &dwFlags, NULL, &completion);
194 ok(iResult == 0 || (iResult == SOCKET_ERROR && err == WSA_IO_PENDING), "iResult = %d, %d\n", iResult, err);
195 ok(err == 0, "WSARecv failed %d\n", err);
196 ok(dwRecv == sizeof(szBuf), "dwRecv %ld != %d and 0\n", dwRecv, sizeof(szBuf));
197
198 closesocket(sck);
199 WSACleanup();
200 return;
201}
#define WSARecv_TIMEOUT
Definition: WSARecv.c:11
void CALLBACK completion(DWORD dwError, DWORD cbTransferred, LPWSAOVERLAPPED lpOverlapped, DWORD dwFlags)
Definition: WSARecv.c:16
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define skip(...)
Definition: atltest.h:64
#define TRUE
Definition: types.h:120
VOID WSAAPI WSASetLastError(IN INT iError)
Definition: dllmain.c:123
BOOL WSAAPI WSAResetEvent(IN WSAEVENT hEvent)
Definition: event.c:53
BOOL WSAAPI WSACloseEvent(IN WSAEVENT hEvent)
Definition: event.c:23
DWORD WSAAPI WSAWaitForMultipleEvents(IN DWORD cEvents, IN CONST WSAEVENT FAR *lphEvents, IN BOOL fWaitAll, IN DWORD dwTimeout, IN BOOL fAlertable)
Definition: event.c:75
INT WSAAPI WSARecv(IN SOCKET s, IN OUT LPWSABUF lpBuffers, IN DWORD dwBufferCount, OUT LPDWORD lpNumberOfBytesRecvd, IN OUT LPDWORD lpFlags, IN LPWSAOVERLAPPED lpOverlapped, IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
Definition: recv.c:155
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)
Definition: select.c:41
INT WSAAPI WSASend(IN SOCKET s, IN LPWSABUF lpBuffers, IN DWORD dwBufferCount, OUT LPDWORD lpNumberOfBytesSent, IN DWORD dwFlags, IN LPWSAOVERLAPPED lpOverlapped, IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
Definition: send.c:145
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
#define IPPROTO_TCP
Definition: ip.h:196
#define SOCK_STREAM
Definition: tcpip.h:118
#define AF_INET
Definition: tcpip.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
const GLuint * buffers
Definition: glext.h:5916
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
int ConnectToReactOSWebsite(SOCKET sck)
Definition: helpers.c:27
#define closesocket
Definition: ncftp.h:477
#define err(...)
#define memset(x, y, z)
Definition: compat.h:39
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED * overlapped
Definition: sock.c:81
INT WSAAPI shutdown(IN SOCKET s, IN INT how)
Definition: sockctrl.c:506
BOOL WSAAPI WSAGetOverlappedResult(IN SOCKET s, IN LPWSAOVERLAPPED lpOverlapped, OUT LPDWORD lpcbTransfer, IN BOOL fWait, OUT LPDWORD lpdwFlags)
Definition: sockctrl.c:603
SOCKET WSAAPI WSASocketW(IN INT af, IN INT type, IN INT protocol, IN LPWSAPROTOCOL_INFOW lpProtocolInfo, IN GROUP g, IN DWORD dwFlags)
Definition: socklife.c:490
Definition: winsock.h:66
#define MAKEWORD(a, b)
Definition: typedefs.h:248
int ret
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define WSA_WAIT_EVENT_0
Definition: winsock2.h:626
#define WSA_FLAG_OVERLAPPED
Definition: winsock2.h:466
WINSOCK_API_LINKAGE WSAEVENT WSAAPI WSACreateEvent(void)
Definition: event.c:42
#define WSA_IO_PENDING
Definition: winsock2.h:616
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:112
#define FD_ZERO(set)
Definition: winsock.h:96
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60
#define INVALID_SOCKET
Definition: winsock.h:332
UINT_PTR SOCKET
Definition: winsock.h:47
#define MSG_PEEK
Definition: winsock.h:222
#define SOCKET_ERROR
Definition: winsock.h:333
#define SD_SEND
Definition: winsock.h:55
#define FD_SET(fd, set)
Definition: winsock.h:89

Referenced by START_TEST().

Variable Documentation

◆ count

int count = 0
static

Definition at line 13 of file WSARecv.c.