Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenselect.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: sselect.c 00005 * PURPOSE: Socket Select 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 WSPAPI 00024 __WSAFDIsSet(SOCKET s, 00025 LPFD_SET set) 00026 { 00027 INT i = set->fd_count; 00028 INT Return = FALSE; 00029 00030 /* Loop until a match is found */ 00031 while (i--) if (set->fd_array[i] == s) Return = TRUE; 00032 00033 /* Return */ 00034 return Return; 00035 } 00036 00037 /* 00038 * @implemented 00039 */ 00040 INT 00041 WSAAPI 00042 select(IN INT s, 00043 IN OUT LPFD_SET readfds, 00044 IN OUT LPFD_SET writefds, 00045 IN OUT LPFD_SET exceptfds, 00046 IN CONST struct timeval *timeout) 00047 { 00048 PWSSOCKET Socket; 00049 INT Status; 00050 INT ErrorCode; 00051 SOCKET Handle; 00052 LPWSPSELECT WSPSelect; 00053 00054 DPRINT("select: %lx %p %p %p %p\n", s, readfds, writefds, exceptfds, timeout); 00055 00056 /* Check for WSAStartup */ 00057 ErrorCode = WsQuickProlog(); 00058 00059 if (ErrorCode != ERROR_SUCCESS) 00060 { 00061 SetLastError(ErrorCode); 00062 return SOCKET_ERROR; 00063 } 00064 00065 /* Use the first Socket from the first valid set */ 00066 if (readfds && readfds->fd_count) 00067 { 00068 Handle = readfds->fd_array[0]; 00069 } 00070 else if (writefds && writefds->fd_count) 00071 { 00072 Handle = writefds->fd_array[0]; 00073 } 00074 else if (exceptfds && exceptfds->fd_count) 00075 { 00076 Handle = exceptfds->fd_array[0]; 00077 } 00078 else 00079 { 00080 /* Invalid handles */ 00081 SetLastError(WSAEINVAL); 00082 return SOCKET_ERROR; 00083 } 00084 00085 /* Get the Socket Context */ 00086 Socket = WsSockGetSocket(Handle); 00087 00088 if (!Socket) 00089 { 00090 /* No Socket Context Found */ 00091 SetLastError(WSAENOTSOCK); 00092 return SOCKET_ERROR; 00093 } 00094 00095 /* Get the select procedure */ 00096 WSPSelect = Socket->Provider->Service.lpWSPSelect; 00097 00098 /* Make the call */ 00099 Status = WSPSelect(s, readfds, writefds, exceptfds, (struct timeval *)timeout, 00100 &ErrorCode); 00101 00102 /* Deference the Socket Context */ 00103 WsSockDereference(Socket); 00104 00105 /* Return Provider Value */ 00106 if (Status != SOCKET_ERROR) 00107 return Status; 00108 00109 /* If everything seemed fine, then the WSP call failed itself */ 00110 if (ErrorCode == NO_ERROR) 00111 ErrorCode = WSASYSCALLFAILURE; 00112 00113 /* Return with an error */ 00114 SetLastError(ErrorCode); 00115 return SOCKET_ERROR; 00116 } 00117 00118 /* 00119 * @unimplemented 00120 */ 00121 INT 00122 WSPAPI 00123 WPUFDIsSet(IN SOCKET s, 00124 IN LPFD_SET set) 00125 { 00126 UNIMPLEMENTED; 00127 return (SOCKET)0; 00128 } 00129 00130 /* 00131 * @implemented 00132 */ 00133 INT 00134 WSAAPI 00135 WSAAsyncSelect(IN SOCKET s, 00136 IN HWND hWnd, 00137 IN UINT wMsg, 00138 IN LONG lEvent) 00139 { 00140 PWSSOCKET Socket; 00141 INT Status; 00142 INT ErrorCode; 00143 DPRINT("WSAAsyncSelect: %lx, %lx, %lx, %lx\n", s, hWnd, wMsg, lEvent); 00144 00145 /* Check for WSAStartup */ 00146 if ((ErrorCode = WsQuickProlog()) == ERROR_SUCCESS) 00147 { 00148 /* Get the Socket Context */ 00149 if ((Socket = WsSockGetSocket(s))) 00150 { 00151 /* Make the call */ 00152 Status = Socket->Provider->Service.lpWSPAsyncSelect(s, 00153 hWnd, 00154 wMsg, 00155 lEvent, 00156 &ErrorCode); 00157 /* Deference the Socket Context */ 00158 WsSockDereference(Socket); 00159 00160 /* Return Provider Value */ 00161 if (Status == ERROR_SUCCESS) return Status; 00162 00163 /* If everything seemed fine, then the WSP call failed itself */ 00164 if (ErrorCode == NO_ERROR) ErrorCode = WSASYSCALLFAILURE; 00165 } 00166 else 00167 { 00168 /* No Socket Context Found */ 00169 ErrorCode = WSAENOTSOCK; 00170 } 00171 } 00172 00173 /* Return with an Error */ 00174 SetLastError(ErrorCode); 00175 return SOCKET_ERROR; 00176 } 00177 00178 /* 00179 * @implemented 00180 */ 00181 INT 00182 WSAAPI 00183 WSAEventSelect(IN SOCKET s, 00184 IN WSAEVENT hEventObject, 00185 IN LONG lNetworkEvents) 00186 { 00187 PWSSOCKET Socket; 00188 INT Status; 00189 INT ErrorCode; 00190 00191 /* Check for WSAStartup */ 00192 if ((ErrorCode = WsQuickProlog()) == ERROR_SUCCESS) 00193 { 00194 /* Get the Socket Context */ 00195 if ((Socket = WsSockGetSocket(s))) 00196 { 00197 /* Make the call */ 00198 Status = Socket->Provider->Service.lpWSPEventSelect(s, 00199 hEventObject, 00200 lNetworkEvents, 00201 &ErrorCode); 00202 /* Deference the Socket Context */ 00203 WsSockDereference(Socket); 00204 00205 /* Return Provider Value */ 00206 if (Status == ERROR_SUCCESS) return Status; 00207 } 00208 else 00209 { 00210 /* No Socket Context Found */ 00211 ErrorCode = WSAENOTSOCK; 00212 } 00213 } 00214 00215 /* Return with an Error */ 00216 SetLastError(ErrorCode); 00217 return SOCKET_ERROR; 00218 } Generated on Sun May 27 2012 04:18:48 for ReactOS by
1.7.6.1
|