ReactOS 0.4.16-dev-122-g325d74c
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/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 */
21INT
25 IN INT len,
26 IN INT flags)
27{
28 PWSSOCKET Socket;
29 INT Status;
31 LPWSATHREADID ThreadId;
33 DWORD BytesSent;
34 DPRINT("send: %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 */
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 */
80INT
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;
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 */
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 */
143INT
144WSAAPI
146 IN LPWSABUF lpBuffers,
147 IN DWORD dwBufferCount,
148 OUT LPDWORD lpNumberOfBytesSent,
151 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
152{
153 PWSSOCKET Socket;
154 INT Status;
156 LPWSATHREADID ThreadId;
157 DPRINT("WSASend: %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,
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 */
199INT
200WSAAPI
202 IN LPWSABUF lpOutboundDisconnectData)
203{
206 PWSSOCKET Socket;
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 */
245INT
246WSAAPI
248 IN LPWSABUF lpBuffers,
249 IN DWORD dwBufferCount,
250 OUT LPDWORD lpNumberOfBytesSent,
252 IN CONST struct sockaddr *lpTo,
253 IN INT iToLen,
255 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
256{
257 PWSSOCKET Socket;
258 INT Status;
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 */
271 lpBuffers,
272 dwBufferCount,
273 lpNumberOfBytesSent,
274 dwFlags,
275 lpTo,
276 iToLen,
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}
PVOID Buffers[0x100]
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define SetLastError(x)
Definition: compat.h:752
#define FAR
Definition: zlib.h:34
INT WSAAPI WSASendDisconnect(IN SOCKET s, IN LPWSABUF lpOutboundDisconnectData)
Definition: send.c:201
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
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 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
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
Status
Definition: gdiplustypes.h:25
GLdouble s
Definition: gl.h:2039
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLbitfield flags
Definition: glext.h:7161
GLenum GLsizei len
Definition: glext.h:6722
#define PCHAR
Definition: match.c:90
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:93
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define CONST
Definition: pedump.c:81
#define DPRINT
Definition: sndvol32.h:73
WSPPROC_TABLE Service
Definition: ws2_32p.h:80
LPWSPSENDTO lpWSPSendTo
Definition: ws2spi.h:486
LPWSPSENDDISCONNECT lpWSPSendDisconnect
Definition: ws2spi.h:485
LPWSPSEND lpWSPSend
Definition: ws2spi.h:484
PTPROVIDER Provider
Definition: ws2_32p.h:199
uint32_t * LPDWORD
Definition: typedefs.h:59
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define WSASYSCALLFAILURE
Definition: winerror.h:1994
#define WSAENOTSOCK
Definition: winerror.h:1951
void(CALLBACK * LPWSAOVERLAPPED_COMPLETION_ROUTINE)(IN DWORD dwError, IN DWORD cbTransferred, IN LPWSAOVERLAPPED lpOverlapped, IN DWORD dwFlags)
Definition: winsock2.h:722
#define WSAAPI
Definition: winsock2.h:605
UINT_PTR SOCKET
Definition: winsock.h:47
#define SOCKET_ERROR
Definition: winsock.h:333
VOID WSAAPI WsSockDereference(IN PWSSOCKET Socket)
Definition: dsocket.c:205
FORCEINLINE DWORD WsQuickPrologTid(LPWSATHREADID *Tid)
Definition: ws2_32p.h:900
INT WSAAPI WsApiProlog(OUT PWSPROCESS *Process, OUT PWSTHREAD *Thread)
Definition: wsautil.c:91
PWSSOCKET WSAAPI WsSockGetSocket(IN SOCKET Handle)
Definition: dsocket.c:140
char CHAR
Definition: xmlstorage.h:175