ReactOS  0.4.14-dev-57-g333b8f1
send.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/send.c
5  * PURPOSE: Socket Sending 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  IN CONST 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 BytesSent;
34  DPRINT("sendto: %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 = (PCHAR)buf;
44  Buffers.len = len;
45 
46  /* Make the call */
47  Status = Socket->Provider->Service.lpWSPSend(s,
48  &Buffers,
49  1,
50  &BytesSent,
51  (DWORD)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) return BytesSent;
61 
62  /* If everything seemed fine, then the WSP call failed itself */
64  }
65  else
66  {
67  /* No Socket Context Found */
69  }
70  }
71 
72  /* Return with an Error */
74  return SOCKET_ERROR;
75 }
76 
77 /*
78  * @implemented
79  */
80 INT
81 WSAAPI
83  IN CONST CHAR FAR* buf,
84  IN INT len,
85  IN INT flags,
86  IN CONST struct sockaddr *to,
87  IN INT tolen)
88 {
89  PWSSOCKET Socket;
90  INT Status;
91  INT ErrorCode;
92  LPWSATHREADID ThreadId;
94  DWORD BytesSent;
95  DPRINT("sendto: %lx, %lx, %lx, %p\n", s, flags, len, buf);
96 
97  /* Check for WSAStartup */
98  if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS)
99  {
100  /* Get the Socket Context */
101  if ((Socket = WsSockGetSocket(s)))
102  {
103  /* Setup the buffers */
104  Buffers.buf = (PCHAR)buf;
105  Buffers.len = len;
106 
107  /* Make the call */
108  Status = Socket->Provider->Service.lpWSPSendTo(s,
109  &Buffers,
110  1,
111  &BytesSent,
112  (DWORD)flags,
113  to,
114  tolen,
115  NULL,
116  NULL,
117  ThreadId,
118  &ErrorCode);
119  /* Deference the Socket Context */
120  WsSockDereference(Socket);
121 
122  /* Return Provider Value */
123  if (Status == ERROR_SUCCESS) return BytesSent;
124 
125  /* If everything seemed fine, then the WSP call failed itself */
127  }
128  else
129  {
130  /* No Socket Context Found */
132  }
133  }
134 
135  /* Return with an Error */
137  return SOCKET_ERROR;
138 }
139 
140 /*
141  * @implemented
142  */
143 INT
144 WSAAPI
146  IN LPWSABUF lpBuffers,
147  IN DWORD dwBufferCount,
148  OUT LPDWORD lpNumberOfBytesSent,
149  IN DWORD dwFlags,
151  IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
152 {
153  PWSSOCKET Socket;
154  INT Status;
155  INT ErrorCode;
156  LPWSATHREADID ThreadId;
157  DPRINT("WSARecvFrom: %lx, %lx, %lx, %p\n", s, dwFlags, dwBufferCount, lpBuffers);
158 
159  /* Check for WSAStartup */
160  if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS)
161  {
162  /* Get the Socket Context */
163  if ((Socket = WsSockGetSocket(s)))
164  {
165  /* Make the call */
166  Status = Socket->Provider->Service.lpWSPSend(s,
167  lpBuffers,
168  dwBufferCount,
169  lpNumberOfBytesSent,
170  dwFlags,
171  lpOverlapped,
172  lpCompletionRoutine,
173  ThreadId,
174  &ErrorCode);
175  /* Deference the Socket Context */
176  WsSockDereference(Socket);
177 
178  /* Return Provider Value */
179  if (Status == ERROR_SUCCESS) return Status;
180 
181  /* If everything seemed fine, then the WSP call failed itself */
183  }
184  else
185  {
186  /* No Socket Context Found */
188  }
189  }
190 
191  /* Return with an Error */
193  return SOCKET_ERROR;
194 }
195 
196 /*
197  * @implemented
198  */
199 INT
200 WSAAPI
202  IN LPWSABUF lpOutboundDisconnectData)
203 {
206  PWSSOCKET Socket;
207  INT ErrorCode;
208  INT Status;
209  DPRINT("WSASendDisconnect: %lx %p\n", s, lpOutboundDisconnectData);
210 
211  /* Enter prolog */
213  {
214  /* Get the Socket Context */
215  if ((Socket = WsSockGetSocket(s)))
216  {
217  /* Make the call */
219  lpOutboundDisconnectData,
220  &ErrorCode);
221  /* Deference the Socket Context */
222  WsSockDereference(Socket);
223 
224  /* Return Provider Value */
225  if (Status == ERROR_SUCCESS) return ERROR_SUCCESS;
226 
227  /* If everything seemed fine, then the WSP call failed itself */
229  }
230  else
231  {
232  /* No Socket Context Found */
234  }
235  }
236 
237  /* Return with an Error */
239  return SOCKET_ERROR;
240 }
241 
242 /*
243  * @implemented
244  */
245 INT
246 WSAAPI
248  IN LPWSABUF lpBuffers,
249  IN DWORD dwBufferCount,
250  OUT LPDWORD lpNumberOfBytesSent,
251  IN DWORD dwFlags,
252  IN CONST struct sockaddr *lpTo,
253  IN INT iToLen,
255  IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
256 {
257  PWSSOCKET Socket;
258  INT Status;
259  INT ErrorCode;
260  LPWSATHREADID ThreadId;
261  DPRINT("WSASendTo: %lx, %lx, %lx, %p\n", s, dwFlags, dwBufferCount, lpBuffers);
262 
263  /* Check for WSAStartup */
264  if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS)
265  {
266  /* Get the Socket Context */
267  if ((Socket = WsSockGetSocket(s)))
268  {
269  /* Make the call */
270  Status = Socket->Provider->Service.lpWSPSendTo(s,
271  lpBuffers,
272  dwBufferCount,
273  lpNumberOfBytesSent,
274  dwFlags,
275  lpTo,
276  iToLen,
277  lpOverlapped,
278  lpCompletionRoutine,
279  ThreadId,
280  &ErrorCode);
281  /* Deference the Socket Context */
282  WsSockDereference(Socket);
283 
284  /* Return Provider Value */
285  if (Status == ERROR_SUCCESS) return Status;
286 
287  /* If everything seemed fine, then the WSP call failed itself */
289  }
290  else
291  {
292  /* No Socket Context Found */
294  }
295  }
296 
297  /* Return with an Error */
299  return SOCKET_ERROR;
300 }
#define WSAENOTSOCK
Definition: winerror.h:1951
#define SOCKET_ERROR
Definition: winsock.h:333
#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
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
#define FAR
Definition: guiddef.h:36
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
FORCEINLINE DWORD WsQuickPrologTid(LPWSATHREADID *Tid)
Definition: ws2_32p.h:900
#define PCHAR
Definition: match.c:90
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
INT WSAAPI WSASendDisconnect(IN SOCKET s, IN LPWSABUF lpOutboundDisconnectData)
Definition: send.c:201
PTPROVIDER Provider
Definition: ws2_32p.h:199
unsigned long DWORD
Definition: ntddk_ex.h:95
INT WSAAPI WSASendTo(IN SOCKET s, IN LPWSABUF lpBuffers, IN DWORD dwBufferCount, OUT LPDWORD lpNumberOfBytesSent, IN DWORD dwFlags, IN CONST struct sockaddr *lpTo, IN INT iToLen, IN LPWSAOVERLAPPED lpOverlapped, IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
Definition: send.c:247
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define SetLastError(x)
Definition: compat.h:409
INT WSAAPI WsApiProlog(OUT PWSPROCESS *Process, OUT PWSTHREAD *Thread)
Definition: wsautil.c:91
GLbitfield flags
Definition: glext.h:7161
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
LPWSPSENDTO lpWSPSendTo
Definition: ws2spi.h:486
Status
Definition: gdiplustypes.h:24
#define WSASYSCALLFAILURE
Definition: winerror.h:1994
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
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:90
#define WSAAPI
Definition: winsock2.h:584
INT WSAAPI sendto(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags, IN CONST struct sockaddr *to, IN INT tolen)
Definition: send.c:82
LPWSPSENDDISCONNECT lpWSPSendDisconnect
Definition: ws2spi.h:485
_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
LPWSPSEND lpWSPSend
Definition: ws2spi.h:484
#define CONST
Definition: pedump.c:81