ReactOS  0.4.14-dev-593-g1793dcc
recv.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS WinSock 2 API
4  * FILE: dll/win32/ws2_32_new/src/recv.c
5  * PURPOSE: Socket Receive Support
6  * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
7  */
8 
9 /* INCLUDES ******************************************************************/
10 
11 #include <ws2_32.h>
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* FUNCTIONS *****************************************************************/
17 
18 /*
19  * @implemented
20  */
21 INT
22 WSAAPI
24  OUT CHAR FAR* buf,
25  IN INT len,
26  IN INT flags)
27 {
28  PWSSOCKET Socket;
29  INT Status;
30  INT ErrorCode;
31  LPWSATHREADID ThreadId;
33  DWORD BytesReceived;
34  DPRINT("recv: %lx, %lx, %lx, %p\n", s, flags, len, buf);
35 
36  /* Check for WSAStartup */
37  if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS)
38  {
39  /* Get the Socket Context */
40  if ((Socket = WsSockGetSocket(s)))
41  {
42  /* Setup the buffers */
43  Buffers.buf = buf;
44  Buffers.len = len;
45 
46  /* Make the call */
47  Status = Socket->Provider->Service.lpWSPRecv(s,
48  &Buffers,
49  1,
50  &BytesReceived,
51  (LPDWORD)&flags,
52  NULL,
53  NULL,
54  ThreadId,
55  &ErrorCode);
56  /* Deference the Socket Context */
57  WsSockDereference(Socket);
58 
59  /* Return Provider Value */
60  if (Status == ERROR_SUCCESS)
61  {
62  /* Handle OOB */
63  if (!(flags & MSG_PARTIAL)) return BytesReceived;
65  }
66 
67  /* If everything seemed fine, then the WSP call failed itself */
69  }
70  else
71  {
72  /* No Socket Context Found */
74  }
75  }
76 
77  /* Return with an Error */
79  return SOCKET_ERROR;
80 }
81 
82 /*
83  * @implemented
84  */
85 INT
86 WSAAPI
88  OUT CHAR FAR* buf,
89  IN INT len,
90  IN INT flags,
92  IN OUT INT FAR* fromlen)
93 {
94  PWSSOCKET Socket;
95  INT Status;
96  INT ErrorCode;
97  LPWSATHREADID ThreadId;
99  DWORD BytesReceived;
100  DPRINT("recvfrom: %lx, %lx, %lx, %p\n", s, flags, len, buf);
101 
102  /* Check for WSAStartup */
103  if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS)
104  {
105  /* Get the Socket Context */
106  if ((Socket = WsSockGetSocket(s)))
107  {
108  /* Setup the buffers */
109  Buffers.buf = buf;
110  Buffers.len = len;
111 
112  /* Make the call */
114  &Buffers,
115  1,
116  &BytesReceived,
117  (LPDWORD)&flags,
118  from,
119  fromlen,
120  NULL,
121  NULL,
122  ThreadId,
123  &ErrorCode);
124  /* Deference the Socket Context */
125  WsSockDereference(Socket);
126 
127  /* Return Provider Value */
128  if (Status == ERROR_SUCCESS)
129  {
130  /* Handle OOB */
131  if (!(flags & MSG_PARTIAL)) return BytesReceived;
133  }
134 
135  /* If everything seemed fine, then the WSP call failed itself */
137  }
138  else
139  {
140  /* No Socket Context Found */
142  }
143  }
144 
145  /* Return with an Error */
147  return SOCKET_ERROR;
148 }
149 
150 /*
151  * @implemented
152  */
153 INT
154 WSAAPI
156  IN OUT LPWSABUF lpBuffers,
157  IN DWORD dwBufferCount,
158  OUT LPDWORD lpNumberOfBytesRecvd,
159  IN OUT LPDWORD lpFlags,
161  IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
162 {
163  PWSSOCKET Socket;
164  INT Status;
165  INT ErrorCode;
166  LPWSATHREADID ThreadId;
167  DPRINT("WSARecv: %lx, %lx, %lx, %p\n", s, lpFlags, dwBufferCount, lpBuffers);
168 
169  /* Check for WSAStartup */
170  if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS)
171  {
172  /* Get the Socket Context */
173  if ((Socket = WsSockGetSocket(s)))
174  {
175  /* Make the call */
176  Status = Socket->Provider->Service.lpWSPRecv(s,
177  lpBuffers,
178  dwBufferCount,
179  lpNumberOfBytesRecvd,
180  lpFlags,
181  lpOverlapped,
182  lpCompletionRoutine,
183  ThreadId,
184  &ErrorCode);
185  /* Deference the Socket Context */
186  WsSockDereference(Socket);
187 
188  /* Return Provider Value */
189  if (Status == ERROR_SUCCESS) return Status;
190 
191  /* If everything seemed fine, then the WSP call failed itself */
193  }
194  else
195  {
196  /* No Socket Context Found */
198  }
199  }
200 
201  /* Return with an Error */
203  return SOCKET_ERROR;
204 }
205 
206 /*
207  * @implemented
208  */
209 INT
210 WSAAPI
212  OUT LPWSABUF lpInboundDisconnectData)
213 {
216  PWSSOCKET Socket;
217  INT ErrorCode;
218  INT Status;
219  DPRINT("WSARecvDisconnect: %lx %p\n", s, lpInboundDisconnectData);
220 
221  /* Enter prolog */
223  {
224  /* Get the Socket Context */
225  if ((Socket = WsSockGetSocket(s)))
226  {
227  /* Make the call */
229  lpInboundDisconnectData,
230  &ErrorCode);
231  /* Deference the Socket Context */
232  WsSockDereference(Socket);
233 
234  /* Return Provider Value */
235  if (Status == ERROR_SUCCESS) return ERROR_SUCCESS;
236  }
237  else
238  {
239  /* No Socket Context Found */
241  }
242  }
243 
244  /* Return with an Error */
246  return SOCKET_ERROR;
247 }
248 
249 /*
250  * @implemented
251  */
252 INT
253 WSAAPI
255  IN OUT LPWSABUF lpBuffers,
256  IN DWORD dwBufferCount,
257  OUT LPDWORD lpNumberOfBytesRecvd,
258  IN OUT LPDWORD lpFlags,
259  OUT LPSOCKADDR lpFrom,
260  IN OUT LPINT lpFromlen,
262  IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
263 {
264  PWSSOCKET Socket;
265  INT Status;
266  INT ErrorCode;
267  LPWSATHREADID ThreadId;
268  DPRINT("WSARecvFrom: %lx, %lx, %lx, %p\n", s, lpFlags, dwBufferCount, lpBuffers);
269 
270  /* Check for WSAStartup */
271  if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS)
272  {
273  /* Get the Socket Context */
274  if ((Socket = WsSockGetSocket(s)))
275  {
276  /* Make the call */
278  lpBuffers,
279  dwBufferCount,
280  lpNumberOfBytesRecvd,
281  lpFlags,
282  lpFrom,
283  lpFromlen,
284  lpOverlapped,
285  lpCompletionRoutine,
286  ThreadId,
287  &ErrorCode);
288  /* Deference the Socket Context */
289  WsSockDereference(Socket);
290 
291  /* Return Provider Value */
292  if (Status == ERROR_SUCCESS) return Status;
293 
294  /* If everything seemed fine, then the WSP call failed itself */
296  }
297  else
298  {
299  /* No Socket Context Found */
301  }
302  }
303 
304  /* Return with an Error */
306  return SOCKET_ERROR;
307 }
LPWSPRECVFROM lpWSPRecvFrom
Definition: ws2spi.h:482
#define WSAENOTSOCK
Definition: winerror.h:1951
#define SOCKET_ERROR
Definition: winsock.h:333
INT WSAAPI recvfrom(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags, OUT LPSOCKADDR from, IN OUT INT FAR *fromlen)
Definition: recv.c:87
#define IN
Definition: typedefs.h:38
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
char CHAR
Definition: xmlstorage.h:175
PVOID Buffers[0x100]
PWSSOCKET WSAAPI WsSockGetSocket(IN SOCKET Handle)
Definition: dsocket.c:140
#define NO_ERROR
Definition: dderror.h:5
INT WSAAPI WSARecvDisconnect(IN SOCKET s, OUT LPWSABUF lpInboundDisconnectData)
Definition: recv.c:211
int32_t INT
Definition: typedefs.h:56
WSPPROC_TABLE Service
Definition: ws2_32p.h:80
VOID WSAAPI WsSockDereference(IN PWSSOCKET Socket)
Definition: dsocket.c:205
LPWSPRECV lpWSPRecv
Definition: ws2spi.h:480
#define FAR
Definition: guiddef.h:36
INT WSAAPI WSARecvFrom(IN SOCKET s, IN OUT LPWSABUF lpBuffers, IN DWORD dwBufferCount, OUT LPDWORD lpNumberOfBytesRecvd, IN OUT LPDWORD lpFlags, OUT LPSOCKADDR lpFrom, IN OUT LPINT lpFromlen, IN LPWSAOVERLAPPED lpOverlapped, IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
Definition: recv.c:254
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
FORCEINLINE DWORD WsQuickPrologTid(LPWSATHREADID *Tid)
Definition: ws2_32p.h:900
PTPROVIDER Provider
Definition: ws2_32p.h:199
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define SetLastError(x)
Definition: compat.h:417
INT WSAAPI WsApiProlog(OUT PWSPROCESS *Process, OUT PWSTHREAD *Thread)
Definition: wsautil.c:91
GLbitfield flags
Definition: glext.h:7161
#define WSAEMSGSIZE
Definition: winerror.h:1953
#define MSG_PARTIAL
Definition: winsock.h:402
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
Status
Definition: gdiplustypes.h:24
#define WSASYSCALLFAILURE
Definition: winerror.h:1994
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
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:90
#define WSAAPI
Definition: winsock2.h:584
LPWSPRECVDISCONNECT lpWSPRecvDisconnect
Definition: ws2spi.h:481
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define OUT
Definition: typedefs.h:39
void(CALLBACK * LPWSAOVERLAPPED_COMPLETION_ROUTINE)(IN DWORD dwError, IN DWORD cbTransferred, IN LPWSAOVERLAPPED lpOverlapped, IN DWORD dwFlags)
Definition: winsock2.h:722
uint32_t * LPDWORD
Definition: typedefs.h:57
UINT_PTR SOCKET
Definition: winsock.h:47
CardRegion * from
Definition: spigame.cpp:19
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
int * LPINT
Definition: windef.h:178