2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WinSock 2 API
5 * PURPOSE: Socket Select Support
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
9 /* INCLUDES ******************************************************************/
15 /* DATA **********************************************************************/
17 /* FUNCTIONS *****************************************************************/
24 __WSAFDIsSet(SOCKET s
,
27 INT i
= set
->fd_count
;
30 /* Loop until a match is found */
31 while (i
--) if (set
->fd_array
[i
] == s
) Return
= TRUE
;
43 IN OUT LPFD_SET readfds
,
44 IN OUT LPFD_SET writefds
,
45 IN OUT LPFD_SET exceptfds
,
46 IN CONST
struct timeval
*timeout
)
52 LPWSPSELECT WSPSelect
;
54 DPRINT("select: %lx %p %p %p %p\n", s
, readfds
, writefds
, exceptfds
, timeout
);
56 /* Check for WSAStartup */
57 ErrorCode
= WsQuickProlog();
59 if (ErrorCode
!= ERROR_SUCCESS
)
61 SetLastError(ErrorCode
);
65 /* Use the first Socket from the first valid set */
66 if (readfds
&& readfds
->fd_count
)
68 Handle
= readfds
->fd_array
[0];
70 else if (writefds
&& writefds
->fd_count
)
72 Handle
= writefds
->fd_array
[0];
74 else if (exceptfds
&& exceptfds
->fd_count
)
76 Handle
= exceptfds
->fd_array
[0];
81 SetLastError(WSAEINVAL
);
85 /* Get the Socket Context */
86 Socket
= WsSockGetSocket(Handle
);
90 /* No Socket Context Found */
91 SetLastError(WSAENOTSOCK
);
95 /* Get the select procedure */
96 WSPSelect
= Socket
->Provider
->Service
.lpWSPSelect
;
99 Status
= WSPSelect(s
, readfds
, writefds
, exceptfds
, (struct timeval
*)timeout
,
102 /* Deference the Socket Context */
103 WsSockDereference(Socket
);
105 /* Return Provider Value */
106 if (Status
!= SOCKET_ERROR
)
109 /* If everything seemed fine, then the WSP call failed itself */
110 if (ErrorCode
== NO_ERROR
)
111 ErrorCode
= WSASYSCALLFAILURE
;
113 /* Return with an error */
114 SetLastError(ErrorCode
);
123 WPUFDIsSet(IN SOCKET s
,
135 WSAAsyncSelect(IN SOCKET s
,
143 DPRINT("WSAAsyncSelect: %lx, %lx, %lx, %lx\n", s
, hWnd
, wMsg
, lEvent
);
145 /* Check for WSAStartup */
146 if ((ErrorCode
= WsQuickProlog()) == ERROR_SUCCESS
)
148 /* Get the Socket Context */
149 if ((Socket
= WsSockGetSocket(s
)))
152 Status
= Socket
->Provider
->Service
.lpWSPAsyncSelect(s
,
157 /* Deference the Socket Context */
158 WsSockDereference(Socket
);
160 /* Return Provider Value */
161 if (Status
== ERROR_SUCCESS
) return Status
;
163 /* If everything seemed fine, then the WSP call failed itself */
164 if (ErrorCode
== NO_ERROR
) ErrorCode
= WSASYSCALLFAILURE
;
168 /* No Socket Context Found */
169 ErrorCode
= WSAENOTSOCK
;
173 /* Return with an Error */
174 SetLastError(ErrorCode
);
183 WSAEventSelect(IN SOCKET s
,
184 IN WSAEVENT hEventObject
,
185 IN LONG lNetworkEvents
)
191 /* Check for WSAStartup */
192 if ((ErrorCode
= WsQuickProlog()) == ERROR_SUCCESS
)
194 /* Get the Socket Context */
195 if ((Socket
= WsSockGetSocket(s
)))
198 Status
= Socket
->Provider
->Service
.lpWSPEventSelect(s
,
202 /* Deference the Socket Context */
203 WsSockDereference(Socket
);
205 /* Return Provider Value */
206 if (Status
== ERROR_SUCCESS
) return Status
;
210 /* No Socket Context Found */
211 ErrorCode
= WSAENOTSOCK
;
215 /* Return with an Error */
216 SetLastError(ErrorCode
);