ReactOS  0.4.14-dev-49-gfb4591c
select.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_new/src/select.c
5  * PURPOSE: Socket Select 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  */
21 INT
22 WSPAPI
24  LPFD_SET set)
25 {
26  INT i = set->fd_count;
27  INT Return = FALSE;
28 
29  /* Loop until a match is found */
30  while (i--) if (set->fd_array[i] == s) Return = TRUE;
31 
32  /* Return */
33  return Return;
34 }
35 
36 /*
37  * @implemented
38  */
39 INT
40 WSAAPI
42  IN OUT LPFD_SET readfds,
43  IN OUT LPFD_SET writefds,
44  IN OUT LPFD_SET exceptfds,
45  IN CONST struct timeval *timeout)
46 {
47  PWSSOCKET Socket;
48  INT Status;
49  INT ErrorCode;
50  SOCKET Handle;
52 
53  DPRINT("select: %lx %p %p %p %p\n", s, readfds, writefds, exceptfds, timeout);
54 
55  /* Check for WSAStartup */
57 
58  if (ErrorCode != ERROR_SUCCESS)
59  {
61  return SOCKET_ERROR;
62  }
63 
64  /* Use the first Socket from the first valid set */
65  if (readfds && readfds->fd_count)
66  {
67  Handle = readfds->fd_array[0];
68  }
69  else if (writefds && writefds->fd_count)
70  {
71  Handle = writefds->fd_array[0];
72  }
73  else if (exceptfds && exceptfds->fd_count)
74  {
75  Handle = exceptfds->fd_array[0];
76  }
77  else
78  {
79  /* Invalid handles */
81  return SOCKET_ERROR;
82  }
83 
84  /* Get the Socket Context */
85  Socket = WsSockGetSocket(Handle);
86 
87  if (!Socket)
88  {
89  /* No Socket Context Found */
91  return SOCKET_ERROR;
92  }
93 
94  /* Get the select procedure */
96 
97  /* Make the call */
98  Status = WSPSelect(s, readfds, writefds, exceptfds, (struct timeval *)timeout,
99  &ErrorCode);
100 
101  /* Deference the Socket Context */
102  WsSockDereference(Socket);
103 
104  /* Return Provider Value */
105  if (Status != SOCKET_ERROR)
106  return Status;
107 
108  /* If everything seemed fine, then the WSP call failed itself */
109  if (ErrorCode == NO_ERROR)
111 
112  /* Return with an error */
114  return SOCKET_ERROR;
115 }
116 
117 /*
118  * @unimplemented
119  */
120 INT
121 WSPAPI
123  IN LPFD_SET set)
124 {
126  return (SOCKET)0;
127 }
128 
129 /*
130  * @implemented
131  */
132 INT
133 WSAAPI
135  IN HWND hWnd,
136  IN UINT wMsg,
137  IN LONG lEvent)
138 {
139  PWSSOCKET Socket;
140  INT Status;
141  INT ErrorCode;
142  DPRINT("WSAAsyncSelect: %lx, %lx, %lx, %lx\n", s, hWnd, wMsg, lEvent);
143 
144  /* Check for WSAStartup */
146  {
147  /* Get the Socket Context */
148  if ((Socket = WsSockGetSocket(s)))
149  {
150  /* Make the call */
152  hWnd,
153  wMsg,
154  lEvent,
155  &ErrorCode);
156  /* Deference the Socket Context */
157  WsSockDereference(Socket);
158 
159  /* Return Provider Value */
160  if (Status == ERROR_SUCCESS) return Status;
161 
162  /* If everything seemed fine, then the WSP call failed itself */
164  }
165  else
166  {
167  /* No Socket Context Found */
169  }
170  }
171 
172  /* Return with an Error */
174  return SOCKET_ERROR;
175 }
176 
177 /*
178  * @implemented
179  */
180 INT
181 WSAAPI
183  IN WSAEVENT hEventObject,
184  IN LONG lNetworkEvents)
185 {
186  PWSSOCKET Socket;
187  INT Status;
188  INT ErrorCode;
189 
190  /* Check for WSAStartup */
192  {
193  /* Get the Socket Context */
194  if ((Socket = WsSockGetSocket(s)))
195  {
196  /* Make the call */
198  hEventObject,
199  lNetworkEvents,
200  &ErrorCode);
201  /* Deference the Socket Context */
202  WsSockDereference(Socket);
203 
204  /* Return Provider Value */
205  if (Status == ERROR_SUCCESS) return Status;
206  }
207  else
208  {
209  /* No Socket Context Found */
211  }
212  }
213 
214  /* Return with an Error */
216  return SOCKET_ERROR;
217 }
Definition: winsock.h:66
#define WSAENOTSOCK
Definition: winerror.h:1951
#define SOCKET_ERROR
Definition: winsock.h:333
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
LPWSPASYNCSELECT lpWSPAsyncSelect
Definition: ws2spi.h:463
#define WSAEINVAL
Definition: winerror.h:1946
#define WSAEVENT
Definition: winsock2.h:585
int(WSPAPI * LPWSPSELECT)(_In_ int nfds, _Inout_opt_ fd_set FAR *readfds, _Inout_opt_ fd_set FAR *writefds, _Inout_opt_ fd_set FAR *exceptfds, _In_opt_ const struct timeval FAR *timeout, _Out_ LPINT lpErrno)
Definition: ws2spi.h:244
HWND hWnd
Definition: settings.c:17
PWSSOCKET WSAAPI WsSockGetSocket(IN SOCKET Handle)
Definition: dsocket.c:140
INT WSPAPI WPUFDIsSet(IN SOCKET s, IN LPFD_SET set)
Definition: select.c:122
Definition: dhcpd.h:245
#define NO_ERROR
Definition: dderror.h:5
int32_t INT
Definition: typedefs.h:56
WSPPROC_TABLE Service
Definition: ws2_32p.h:80
LPWSPSELECT lpWSPSelect
Definition: ws2spi.h:483
VOID WSAAPI WsSockDereference(IN PWSSOCKET Socket)
Definition: dsocket.c:205
LPWSPEVENTSELECT lpWSPEventSelect
Definition: ws2spi.h:471
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
long LONG
Definition: pedump.c:60
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
Definition: select.c:41
INT WSAAPI WSAEventSelect(IN SOCKET s, IN WSAEVENT hEventObject, IN LONG lNetworkEvents)
Definition: select.c:182
INT WSPAPI __WSAFDIsSet(SOCKET s, LPFD_SET set)
Definition: select.c:23
INT WSAAPI WSAAsyncSelect(IN SOCKET s, IN HWND hWnd, IN UINT wMsg, IN LONG lEvent)
Definition: select.c:134
void DPRINT(...)
Definition: polytest.cpp:61
_In_ HANDLE Handle
Definition: extypes.h:390
PTPROVIDER Provider
Definition: ws2_32p.h:199
#define SetLastError(x)
Definition: compat.h:409
HANDLE lEvent
Definition: tftpd.cpp:56
GLdouble s
Definition: gl.h:2039
Status
Definition: gdiplustypes.h:24
int WSPAPI WSPSelect(IN int nfds, IN OUT fd_set *readfds OPTIONAL, IN OUT fd_set *writefds OPTIONAL, IN OUT fd_set *exceptfds OPTIONAL, IN const struct timeval *timeout OPTIONAL, OUT LPINT lpErrno)
Definition: dllmain.c:1065
#define WSASYSCALLFAILURE
Definition: winerror.h:1994
#define WSAAPI
Definition: winsock2.h:584
unsigned int UINT
Definition: ndis.h:50
#define OUT
Definition: typedefs.h:39
#define UNIMPLEMENTED
Definition: debug.h:114
UINT_PTR SOCKET
Definition: winsock.h:47
FORCEINLINE DWORD WsQuickProlog(VOID)
Definition: ws2_32p.h:892
Definition: _set.h:46
#define CONST
Definition: pedump.c:81
#define WSPAPI
Definition: ws2spi.h:39