ReactOS 0.4.16-dev-297-gc569aee
event.c File Reference
#include <msafd.h>
Include dependency graph for event.c:

Go to the source code of this file.

Functions

int WSPAPI WSPEventSelect (IN SOCKET Handle, IN WSAEVENT hEventObject, IN long lNetworkEvents, OUT LPINT lpErrno)
 
INT WSPAPI WSPEnumNetworkEvents (IN SOCKET Handle, IN WSAEVENT hEventObject, OUT LPWSANETWORKEVENTS lpNetworkEvents, OUT LPINT lpErrno)
 

Function Documentation

◆ WSPEnumNetworkEvents()

INT WSPAPI WSPEnumNetworkEvents ( IN SOCKET  Handle,
IN WSAEVENT  hEventObject,
OUT LPWSANETWORKEVENTS  lpNetworkEvents,
OUT LPINT  lpErrno 
)

Definition at line 133 of file event.c.

138{
140 IO_STATUS_BLOCK IOSB;
141 PSOCKET_INFORMATION Socket = NULL;
144
145 TRACE("Called (lpNetworkEvents %x)\n", lpNetworkEvents);
146
147 /* Get the Socket Structure associate to this Socket*/
148 Socket = GetSocketStructure(Handle);
149 if (!Socket)
150 {
151 if (lpErrno) *lpErrno = WSAENOTSOCK;
152 return SOCKET_ERROR;
153 }
154 if (!lpNetworkEvents)
155 {
156 if (lpErrno) *lpErrno = WSAEFAULT;
157 return SOCKET_ERROR;
158 }
159
162
163 if( !NT_SUCCESS(Status) ) {
164 ERR("Could not make an event %x\n", Status);
165 return SOCKET_ERROR;
166 }
167
168 EnumReq.Event = hEventObject;
169
170 /* Send IOCTL */
172 SockEvent,
173 NULL,
174 NULL,
175 &IOSB,
177 &EnumReq,
178 sizeof(EnumReq),
179 NULL,
180 0);
181
182 /* Wait for return */
183 if (Status == STATUS_PENDING) {
185 Status = IOSB.Status;
186 }
187
189
190 if (Status != STATUS_SUCCESS)
191 {
192 ERR("Status 0x%08x\n", Status);
193 return MsafdReturnWithErrno(Status, lpErrno, 0, NULL);
194 }
195
196 lpNetworkEvents->lNetworkEvents = 0;
197
198 /* Set Events to wait for */
199 if (EnumReq.PollEvents & AFD_EVENT_RECEIVE) {
200 lpNetworkEvents->lNetworkEvents |= FD_READ;
201 lpNetworkEvents->iErrorCode[FD_READ_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_READ_BIT]);
202 }
203
204 if (EnumReq.PollEvents & AFD_EVENT_SEND) {
205 lpNetworkEvents->lNetworkEvents |= FD_WRITE;
206 lpNetworkEvents->iErrorCode[FD_WRITE_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_WRITE_BIT]);
207 }
208
209 if (EnumReq.PollEvents & AFD_EVENT_OOB_RECEIVE) {
210 lpNetworkEvents->lNetworkEvents |= FD_OOB;
211 lpNetworkEvents->iErrorCode[FD_OOB_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_OOB_BIT]);
212 }
213
214 if (EnumReq.PollEvents & AFD_EVENT_ACCEPT) {
215 lpNetworkEvents->lNetworkEvents |= FD_ACCEPT;
216 lpNetworkEvents->iErrorCode[FD_ACCEPT_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_ACCEPT_BIT]);
217 }
218
219 if (EnumReq.PollEvents &
221 lpNetworkEvents->lNetworkEvents |= FD_CONNECT;
222 lpNetworkEvents->iErrorCode[FD_CONNECT_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_CONNECT_BIT]);
223 }
224
225 if (EnumReq.PollEvents &
227 lpNetworkEvents->lNetworkEvents |= FD_CLOSE;
228 lpNetworkEvents->iErrorCode[FD_CLOSE_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_CLOSE_BIT]);
229 }
230
231 if (EnumReq.PollEvents & AFD_EVENT_QOS) {
232 lpNetworkEvents->lNetworkEvents |= FD_QOS;
233 lpNetworkEvents->iErrorCode[FD_QOS_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_QOS_BIT]);
234 }
235
236 if (EnumReq.PollEvents & AFD_EVENT_GROUP_QOS) {
237 lpNetworkEvents->lNetworkEvents |= FD_GROUP_QOS;
238 lpNetworkEvents->iErrorCode[FD_GROUP_QOS_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_GROUP_QOS_BIT]);
239 }
240
241 TRACE("Leaving\n");
242
243 return MsafdReturnWithErrno(STATUS_SUCCESS, lpErrno, 0, NULL);
244}
LONG NTSTATUS
Definition: precomp.h:26
#define ERR(fmt,...)
Definition: precomp.h:57
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
PSOCKET_INFORMATION GetSocketStructure(SOCKET Handle)
Definition: dllmain.c:3520
INT TranslateNtStatusError(NTSTATUS Status)
Definition: dllmain.c:537
FORCEINLINE DWORD MsafdReturnWithErrno(NTSTATUS Status, LPINT Errno, DWORD Received, LPDWORD ReturnedBytes)
Definition: msafd.h:546
HANDLE SockEvent
#define INFINITE
Definition: serial.h:102
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:25
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
@ SynchronizationEvent
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:96
#define AFD_EVENT_ACCEPT
Definition: shared.h:210
#define AFD_EVENT_SEND
Definition: shared.h:205
#define AFD_EVENT_OOB_RECEIVE
Definition: shared.h:204
#define AFD_EVENT_CONNECT_FAIL
Definition: shared.h:211
#define AFD_EVENT_RECEIVE
Definition: shared.h:203
#define AFD_EVENT_DISCONNECT
Definition: shared.h:206
#define AFD_EVENT_ABORT
Definition: shared.h:207
#define IOCTL_AFD_ENUM_NETWORK_EVENTS
Definition: shared.h:335
#define AFD_EVENT_QOS
Definition: shared.h:212
#define AFD_EVENT_CLOSE
Definition: shared.h:208
#define AFD_EVENT_CONNECT
Definition: shared.h:209
#define AFD_EVENT_GROUP_QOS
Definition: shared.h:213
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE(s)
Definition: solgame.cpp:4
NTSTATUS EventStatus[AFD_MAX_EVENTS]
Definition: shared.h:132
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define WSAENOTSOCK
Definition: winerror.h:1951
#define WSAEFAULT
Definition: winerror.h:1945
#define FD_CONNECT_BIT
Definition: winsock2.h:301
#define FD_QOS
Definition: winsock2.h:306
#define FD_CLOSE_BIT
Definition: winsock2.h:303
#define FD_OOB_BIT
Definition: winsock2.h:297
#define FD_GROUP_QOS
Definition: winsock2.h:308
#define FD_GROUP_QOS_BIT
Definition: winsock2.h:307
#define FD_ACCEPT_BIT
Definition: winsock2.h:299
#define FD_READ_BIT
Definition: winsock2.h:293
#define FD_QOS_BIT
Definition: winsock2.h:305
#define FD_WRITE_BIT
Definition: winsock2.h:295
#define FD_READ
Definition: winsock.h:405
#define FD_WRITE
Definition: winsock.h:406
#define FD_CLOSE
Definition: winsock.h:410
#define SOCKET_ERROR
Definition: winsock.h:333
#define FD_CONNECT
Definition: winsock.h:409
#define FD_OOB
Definition: winsock.h:407
#define FD_ACCEPT
Definition: winsock.h:408

Referenced by WSPStartup().

◆ WSPEventSelect()

int WSPAPI WSPEventSelect ( IN SOCKET  Handle,
IN WSAEVENT  hEventObject,
IN long  lNetworkEvents,
OUT LPINT  lpErrno 
)

Definition at line 17 of file event.c.

22{
23 IO_STATUS_BLOCK IOSB;
24 AFD_EVENT_SELECT_INFO EventSelectInfo;
27 BOOLEAN BlockMode;
29
30 TRACE("WSPEventSelect (%lx) %lx %lx\n", Handle, hEventObject, lNetworkEvents);
31
32 /* Get the Socket Structure associate to this Socket*/
33 Socket = GetSocketStructure(Handle);
34 if (!Socket)
35 {
36 if (lpErrno) *lpErrno = WSAENOTSOCK;
37 return SOCKET_ERROR;
38 }
39
42
43 if (!NT_SUCCESS(Status)) return SOCKET_ERROR;
44
45 /* Set Socket to Non-Blocking */
46 BlockMode = TRUE;
48 Socket->SharedData->NonBlocking = TRUE;
49
50 /* Deactivate Async Select if there is one */
51 if (Socket->EventObject) {
52 Socket->SharedData->hWnd = NULL;
53 Socket->SharedData->wMsg = 0;
54 Socket->SharedData->AsyncEvents = 0;
55 Socket->SharedData->SequenceNumber++; // This will kill Async Select after the next completion
56 }
57
58 /* Set Structure Info */
59 EventSelectInfo.EventObject = hEventObject;
60 EventSelectInfo.Events = 0;
61
62 /* Set Events to wait for */
63 if (lNetworkEvents & FD_READ) {
64 EventSelectInfo.Events |= AFD_EVENT_RECEIVE;
65 }
66
67 if (lNetworkEvents & FD_WRITE) {
68 EventSelectInfo.Events |= AFD_EVENT_SEND;
69 }
70
71 if (lNetworkEvents & FD_OOB) {
72 EventSelectInfo.Events |= AFD_EVENT_OOB_RECEIVE;
73 }
74
75 if (lNetworkEvents & FD_ACCEPT) {
76 EventSelectInfo.Events |= AFD_EVENT_ACCEPT;
77 }
78
79 if (lNetworkEvents & FD_CONNECT) {
81 }
82
83 if (lNetworkEvents & FD_CLOSE) {
85 }
86
87 if (lNetworkEvents & FD_QOS) {
88 EventSelectInfo.Events |= AFD_EVENT_QOS;
89 }
90
91 if (lNetworkEvents & FD_GROUP_QOS) {
92 EventSelectInfo.Events |= AFD_EVENT_GROUP_QOS;
93 }
94
95 /* Send IOCTL */
98 NULL,
99 NULL,
100 &IOSB,
102 &EventSelectInfo,
103 sizeof(EventSelectInfo),
104 NULL,
105 0);
106
107 /* Wait for return */
108 if (Status == STATUS_PENDING) {
110 Status = IOSB.Status;
111 }
112
114
115 if (Status != STATUS_SUCCESS)
116 {
117 ERR("Got status 0x%08x.\n", Status);
118 return MsafdReturnWithErrno(Status, lpErrno, 0, NULL);
119 }
120
121 /* Set Socket Data*/
122 Socket->EventObject = hEventObject;
123 Socket->NetworkEvents = lNetworkEvents;
124
125 TRACE("Leaving\n");
126
127 return 0;
128}
unsigned char BOOLEAN
#define TRUE
Definition: types.h:120
int SetSocketInformation(PSOCKET_INFORMATION Socket, ULONG AfdInformationClass, PBOOLEAN Boolean OPTIONAL, PULONG Ulong OPTIONAL, PLARGE_INTEGER LargeInteger OPTIONAL, LPWSAOVERLAPPED Overlapped OPTIONAL, LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine OPTIONAL)
Definition: dllmain.c:3397
#define IOCTL_AFD_EVENT_SELECT
Definition: shared.h:329
#define AFD_INFO_BLOCKING_MODE
Definition: shared.h:183
LONG NetworkEvents
Definition: msafd.h:111
PSOCK_SHARED_INFO SharedData
Definition: msafd.h:100
HANDLE EventObject
Definition: msafd.h:110
BOOLEAN NonBlocking
Definition: msafd.h:74
LONG AsyncEvents
Definition: msafd.h:92
DWORD SequenceNumber
Definition: msafd.h:90

Referenced by WSPAsyncSelect(), and WSPStartup().