Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygensend.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS WinSock 2 API 00004 * FILE: send.c 00005 * PURPOSE: Socket Sending Support. 00006 * PROGRAMMER: Alex Ionescu (alex@relsoft.net) 00007 */ 00008 00009 /* INCLUDES ******************************************************************/ 00010 #include "ws2_32.h" 00011 00012 //#define NDEBUG 00013 #include <debug.h> 00014 00015 /* DATA **********************************************************************/ 00016 00017 /* FUNCTIONS *****************************************************************/ 00018 00019 /* 00020 * @implemented 00021 */ 00022 INT 00023 WSAAPI 00024 send(IN SOCKET s, 00025 IN CONST CHAR FAR* buf, 00026 IN INT len, 00027 IN INT flags) 00028 { 00029 PWSSOCKET Socket; 00030 INT Status; 00031 INT ErrorCode; 00032 LPWSATHREADID ThreadId; 00033 WSABUF Buffers; 00034 DWORD BytesSent; 00035 DPRINT("send: %lx, %lx, %lx, %p\n", s, flags, len, buf); 00036 00037 /* Check for WSAStartup */ 00038 if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS) 00039 { 00040 /* Get the Socket Context */ 00041 if ((Socket = WsSockGetSocket(s))) 00042 { 00043 /* Setup the buffers */ 00044 Buffers.buf = (PCHAR)buf; 00045 Buffers.len = len; 00046 00047 /* Make the call */ 00048 Status = Socket->Provider->Service.lpWSPSend(s, 00049 &Buffers, 00050 1, 00051 &BytesSent, 00052 (DWORD)flags, 00053 NULL, 00054 NULL, 00055 ThreadId, 00056 &ErrorCode); 00057 /* Deference the Socket Context */ 00058 WsSockDereference(Socket); 00059 00060 /* Return Provider Value */ 00061 if (Status == ERROR_SUCCESS) return BytesSent; 00062 00063 /* If everything seemed fine, then the WSP call failed itself */ 00064 if (ErrorCode == NO_ERROR) ErrorCode = WSASYSCALLFAILURE; 00065 } 00066 else 00067 { 00068 /* No Socket Context Found */ 00069 ErrorCode = WSAENOTSOCK; 00070 } 00071 } 00072 00073 /* Return with an Error */ 00074 SetLastError(ErrorCode); 00075 return SOCKET_ERROR; 00076 } 00077 00078 /* 00079 * @implemented 00080 */ 00081 INT 00082 WSAAPI 00083 sendto(IN SOCKET s, 00084 IN CONST CHAR FAR* buf, 00085 IN INT len, 00086 IN INT flags, 00087 IN CONST struct sockaddr *to, 00088 IN INT tolen) 00089 { 00090 PWSSOCKET Socket; 00091 INT Status; 00092 INT ErrorCode; 00093 LPWSATHREADID ThreadId; 00094 WSABUF Buffers; 00095 DWORD BytesSent; 00096 DPRINT("send: %lx, %lx, %lx, %p\n", s, flags, len, buf); 00097 00098 /* Check for WSAStartup */ 00099 if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS) 00100 { 00101 /* Get the Socket Context */ 00102 if ((Socket = WsSockGetSocket(s))) 00103 { 00104 /* Setup the buffers */ 00105 Buffers.buf = (PCHAR)buf; 00106 Buffers.len = len; 00107 00108 /* Make the call */ 00109 Status = Socket->Provider->Service.lpWSPSendTo(s, 00110 &Buffers, 00111 1, 00112 &BytesSent, 00113 (DWORD)flags, 00114 to, 00115 tolen, 00116 NULL, 00117 NULL, 00118 ThreadId, 00119 &ErrorCode); 00120 /* Deference the Socket Context */ 00121 WsSockDereference(Socket); 00122 00123 /* Return Provider Value */ 00124 if (Status == ERROR_SUCCESS) return BytesSent; 00125 00126 /* If everything seemed fine, then the WSP call failed itself */ 00127 if (ErrorCode == NO_ERROR) ErrorCode = WSASYSCALLFAILURE; 00128 } 00129 else 00130 { 00131 /* No Socket Context Found */ 00132 ErrorCode = WSAENOTSOCK; 00133 } 00134 } 00135 00136 /* Return with an Error */ 00137 SetLastError(ErrorCode); 00138 return SOCKET_ERROR; 00139 } 00140 00141 /* 00142 * @implemented 00143 */ 00144 INT 00145 WSAAPI 00146 WSASend(IN SOCKET s, 00147 IN LPWSABUF lpBuffers, 00148 IN DWORD dwBufferCount, 00149 OUT LPDWORD lpNumberOfBytesSent, 00150 IN DWORD dwFlags, 00151 IN LPWSAOVERLAPPED lpOverlapped, 00152 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine) 00153 { 00154 PWSSOCKET Socket; 00155 INT Status; 00156 INT ErrorCode; 00157 LPWSATHREADID ThreadId; 00158 DPRINT("WSARecvFrom: %lx, %lx, %lx, %p\n", s, dwFlags, dwBufferCount, lpBuffers); 00159 00160 /* Check for WSAStartup */ 00161 if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS) 00162 { 00163 /* Get the Socket Context */ 00164 if ((Socket = WsSockGetSocket(s))) 00165 { 00166 /* Make the call */ 00167 Status = Socket->Provider->Service.lpWSPSend(s, 00168 lpBuffers, 00169 dwBufferCount, 00170 lpNumberOfBytesSent, 00171 dwFlags, 00172 lpOverlapped, 00173 lpCompletionRoutine, 00174 ThreadId, 00175 &ErrorCode); 00176 /* Deference the Socket Context */ 00177 WsSockDereference(Socket); 00178 00179 /* Return Provider Value */ 00180 if (Status == ERROR_SUCCESS) return Status; 00181 00182 /* If everything seemed fine, then the WSP call failed itself */ 00183 if (ErrorCode == NO_ERROR) ErrorCode = WSASYSCALLFAILURE; 00184 } 00185 else 00186 { 00187 /* No Socket Context Found */ 00188 ErrorCode = WSAENOTSOCK; 00189 } 00190 } 00191 00192 /* Return with an Error */ 00193 SetLastError(ErrorCode); 00194 return SOCKET_ERROR; 00195 } 00196 00197 /* 00198 * @implemented 00199 */ 00200 INT 00201 WSAAPI 00202 WSASendDisconnect(IN SOCKET s, 00203 IN LPWSABUF lpOutboundDisconnectData) 00204 { 00205 PWSPROCESS Process; 00206 PWSTHREAD Thread; 00207 PWSSOCKET Socket; 00208 INT ErrorCode; 00209 INT Status; 00210 DPRINT("WSASendDisconnect: %lx %p\n", s, lpOutboundDisconnectData); 00211 00212 /* Enter prolog */ 00213 if ((ErrorCode = WsApiProlog(&Process, &Thread)) == ERROR_SUCCESS) 00214 { 00215 /* Get the Socket Context */ 00216 if ((Socket = WsSockGetSocket(s))) 00217 { 00218 /* Make the call */ 00219 Status = Socket->Provider->Service.lpWSPSendDisconnect(s, 00220 lpOutboundDisconnectData, 00221 &ErrorCode); 00222 /* Deference the Socket Context */ 00223 WsSockDereference(Socket); 00224 00225 /* Return Provider Value */ 00226 if (Status == ERROR_SUCCESS) return ERROR_SUCCESS; 00227 00228 /* If everything seemed fine, then the WSP call failed itself */ 00229 if (ErrorCode == NO_ERROR) ErrorCode = WSASYSCALLFAILURE; 00230 } 00231 else 00232 { 00233 /* No Socket Context Found */ 00234 ErrorCode = WSAENOTSOCK; 00235 } 00236 } 00237 00238 /* Return with an Error */ 00239 SetLastError(ErrorCode); 00240 return SOCKET_ERROR; 00241 } 00242 00243 /* 00244 * @implemented 00245 */ 00246 INT 00247 WSAAPI 00248 WSASendTo(IN SOCKET s, 00249 IN LPWSABUF lpBuffers, 00250 IN DWORD dwBufferCount, 00251 OUT LPDWORD lpNumberOfBytesSent, 00252 IN DWORD dwFlags, 00253 IN CONST struct sockaddr *lpTo, 00254 IN INT iToLen, 00255 IN LPWSAOVERLAPPED lpOverlapped, 00256 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine) 00257 { 00258 PWSSOCKET Socket; 00259 INT Status; 00260 INT ErrorCode; 00261 LPWSATHREADID ThreadId; 00262 DPRINT("WSASendTo: %lx, %lx, %lx, %p\n", s, dwFlags, dwBufferCount, lpBuffers); 00263 00264 /* Check for WSAStartup */ 00265 if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS) 00266 { 00267 /* Get the Socket Context */ 00268 if ((Socket = WsSockGetSocket(s))) 00269 { 00270 /* Make the call */ 00271 Status = Socket->Provider->Service.lpWSPSendTo(s, 00272 lpBuffers, 00273 dwBufferCount, 00274 lpNumberOfBytesSent, 00275 dwFlags, 00276 lpTo, 00277 iToLen, 00278 lpOverlapped, 00279 lpCompletionRoutine, 00280 ThreadId, 00281 &ErrorCode); 00282 /* Deference the Socket Context */ 00283 WsSockDereference(Socket); 00284 00285 /* Return Provider Value */ 00286 if (Status == ERROR_SUCCESS) return Status; 00287 00288 /* If everything seemed fine, then the WSP call failed itself */ 00289 if (ErrorCode == NO_ERROR) ErrorCode = WSASYSCALLFAILURE; 00290 } 00291 else 00292 { 00293 /* No Socket Context Found */ 00294 ErrorCode = WSAENOTSOCK; 00295 } 00296 } 00297 00298 /* Return with an Error */ 00299 SetLastError(ErrorCode); 00300 return SOCKET_ERROR; 00301 } Generated on Sat May 26 2012 04:25:40 for ReactOS by
1.7.6.1
|