820192552e211999b5ace11de9c6ed5ca88feb2c
[reactos.git] / dll / win32 / ws2_32_new / src / send.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WinSock 2 API
4 * FILE: send.c
5 * PURPOSE: Socket Sending Support.
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
7 */
8
9 /* INCLUDES ******************************************************************/
10 #include "ws2_32.h"
11
12 //#define NDEBUG
13 #include <debug.h>
14
15 /* DATA **********************************************************************/
16
17 /* FUNCTIONS *****************************************************************/
18
19 /*
20 * @implemented
21 */
22 INT
23 WSAAPI
24 send(IN SOCKET s,
25 IN CONST CHAR FAR* buf,
26 IN INT len,
27 IN INT flags)
28 {
29 PWSSOCKET Socket;
30 INT Status;
31 INT ErrorCode;
32 LPWSATHREADID ThreadId;
33 WSABUF Buffers;
34 DWORD BytesSent;
35 DPRINT("send: %lx, %lx, %lx, %p\n", s, flags, len, buf);
36
37 /* Check for WSAStartup */
38 if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS)
39 {
40 /* Get the Socket Context */
41 if ((Socket = WsSockGetSocket(s)))
42 {
43 /* Setup the buffers */
44 Buffers.buf = (PCHAR)buf;
45 Buffers.len = len;
46
47 /* Make the call */
48 Status = Socket->Provider->Service.lpWSPSend(s,
49 &Buffers,
50 1,
51 &BytesSent,
52 (DWORD)flags,
53 NULL,
54 NULL,
55 ThreadId,
56 &ErrorCode);
57 /* Deference the Socket Context */
58 WsSockDereference(Socket);
59
60 /* Return Provider Value */
61 if (Status == ERROR_SUCCESS) return BytesSent;
62
63 /* If everything seemed fine, then the WSP call failed itself */
64 if (ErrorCode == NO_ERROR) ErrorCode = WSASYSCALLFAILURE;
65 }
66 else
67 {
68 /* No Socket Context Found */
69 ErrorCode = WSAENOTSOCK;
70 }
71 }
72
73 /* Return with an Error */
74 SetLastError(ErrorCode);
75 return SOCKET_ERROR;
76 }
77
78 /*
79 * @implemented
80 */
81 INT
82 WSAAPI
83 sendto(IN SOCKET s,
84 IN CONST CHAR FAR* buf,
85 IN INT len,
86 IN INT flags,
87 IN CONST struct sockaddr *to,
88 IN INT tolen)
89 {
90 PWSSOCKET Socket;
91 INT Status;
92 INT ErrorCode;
93 LPWSATHREADID ThreadId;
94 WSABUF Buffers;
95 DWORD BytesSent;
96 DPRINT("send: %lx, %lx, %lx, %p\n", s, flags, len, buf);
97
98 /* Check for WSAStartup */
99 if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS)
100 {
101 /* Get the Socket Context */
102 if ((Socket = WsSockGetSocket(s)))
103 {
104 /* Setup the buffers */
105 Buffers.buf = (PCHAR)buf;
106 Buffers.len = len;
107
108 /* Make the call */
109 Status = Socket->Provider->Service.lpWSPSendTo(s,
110 &Buffers,
111 1,
112 &BytesSent,
113 (DWORD)flags,
114 to,
115 tolen,
116 NULL,
117 NULL,
118 ThreadId,
119 &ErrorCode);
120 /* Deference the Socket Context */
121 WsSockDereference(Socket);
122
123 /* Return Provider Value */
124 if (Status == ERROR_SUCCESS) return BytesSent;
125
126 /* If everything seemed fine, then the WSP call failed itself */
127 if (ErrorCode == NO_ERROR) ErrorCode = WSASYSCALLFAILURE;
128 }
129 else
130 {
131 /* No Socket Context Found */
132 ErrorCode = WSAENOTSOCK;
133 }
134 }
135
136 /* Return with an Error */
137 SetLastError(ErrorCode);
138 return SOCKET_ERROR;
139 }
140
141 /*
142 * @implemented
143 */
144 INT
145 WSAAPI
146 WSASend(IN SOCKET s,
147 IN LPWSABUF lpBuffers,
148 IN DWORD dwBufferCount,
149 OUT LPDWORD lpNumberOfBytesSent,
150 IN DWORD dwFlags,
151 IN LPWSAOVERLAPPED lpOverlapped,
152 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
153 {
154 PWSSOCKET Socket;
155 INT Status;
156 INT ErrorCode;
157 LPWSATHREADID ThreadId;
158 DPRINT("WSARecvFrom: %lx, %lx, %lx, %p\n", s, dwFlags, dwBufferCount, lpBuffers);
159
160 /* Check for WSAStartup */
161 if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS)
162 {
163 /* Get the Socket Context */
164 if ((Socket = WsSockGetSocket(s)))
165 {
166 /* Make the call */
167 Status = Socket->Provider->Service.lpWSPSend(s,
168 lpBuffers,
169 dwBufferCount,
170 lpNumberOfBytesSent,
171 dwFlags,
172 lpOverlapped,
173 lpCompletionRoutine,
174 ThreadId,
175 &ErrorCode);
176 /* Deference the Socket Context */
177 WsSockDereference(Socket);
178
179 /* Return Provider Value */
180 if (Status == ERROR_SUCCESS) return Status;
181
182 /* If everything seemed fine, then the WSP call failed itself */
183 if (ErrorCode == NO_ERROR) ErrorCode = WSASYSCALLFAILURE;
184 }
185 else
186 {
187 /* No Socket Context Found */
188 ErrorCode = WSAENOTSOCK;
189 }
190 }
191
192 /* Return with an Error */
193 SetLastError(ErrorCode);
194 return SOCKET_ERROR;
195 }
196
197 /*
198 * @implemented
199 */
200 INT
201 WSAAPI
202 WSASendDisconnect(IN SOCKET s,
203 IN LPWSABUF lpOutboundDisconnectData)
204 {
205 PWSPROCESS Process;
206 PWSTHREAD Thread;
207 PWSSOCKET Socket;
208 INT ErrorCode;
209 INT Status;
210 DPRINT("WSASendDisconnect: %lx %p\n", s, lpOutboundDisconnectData);
211
212 /* Enter prolog */
213 if ((ErrorCode = WsApiProlog(&Process, &Thread)) == ERROR_SUCCESS)
214 {
215 /* Get the Socket Context */
216 if ((Socket = WsSockGetSocket(s)))
217 {
218 /* Make the call */
219 Status = Socket->Provider->Service.lpWSPSendDisconnect(s,
220 lpOutboundDisconnectData,
221 &ErrorCode);
222 /* Deference the Socket Context */
223 WsSockDereference(Socket);
224
225 /* Return Provider Value */
226 if (Status == ERROR_SUCCESS) return ERROR_SUCCESS;
227
228 /* If everything seemed fine, then the WSP call failed itself */
229 if (ErrorCode == NO_ERROR) ErrorCode = WSASYSCALLFAILURE;
230 }
231 else
232 {
233 /* No Socket Context Found */
234 ErrorCode = WSAENOTSOCK;
235 }
236 }
237
238 /* Return with an Error */
239 SetLastError(ErrorCode);
240 return SOCKET_ERROR;
241 }
242
243 /*
244 * @implemented
245 */
246 INT
247 WSAAPI
248 WSASendTo(IN SOCKET s,
249 IN LPWSABUF lpBuffers,
250 IN DWORD dwBufferCount,
251 OUT LPDWORD lpNumberOfBytesSent,
252 IN DWORD dwFlags,
253 IN CONST struct sockaddr *lpTo,
254 IN INT iToLen,
255 IN LPWSAOVERLAPPED lpOverlapped,
256 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
257 {
258 PWSSOCKET Socket;
259 INT Status;
260 INT ErrorCode;
261 LPWSATHREADID ThreadId;
262 DPRINT("WSASendTo: %lx, %lx, %lx, %p\n", s, dwFlags, dwBufferCount, lpBuffers);
263
264 /* Check for WSAStartup */
265 if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS)
266 {
267 /* Get the Socket Context */
268 if ((Socket = WsSockGetSocket(s)))
269 {
270 /* Make the call */
271 Status = Socket->Provider->Service.lpWSPSendTo(s,
272 lpBuffers,
273 dwBufferCount,
274 lpNumberOfBytesSent,
275 dwFlags,
276 lpTo,
277 iToLen,
278 lpOverlapped,
279 lpCompletionRoutine,
280 ThreadId,
281 &ErrorCode);
282 /* Deference the Socket Context */
283 WsSockDereference(Socket);
284
285 /* Return Provider Value */
286 if (Status == ERROR_SUCCESS) return Status;
287
288 /* If everything seemed fine, then the WSP call failed itself */
289 if (ErrorCode == NO_ERROR) ErrorCode = WSASYSCALLFAILURE;
290 }
291 else
292 {
293 /* No Socket Context Found */
294 ErrorCode = WSAENOTSOCK;
295 }
296 }
297
298 /* Return with an Error */
299 SetLastError(ErrorCode);
300 return SOCKET_ERROR;
301 }