2006-02-17 00:04:10 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS Ancillary Function Driver DLL
|
2015-11-02 17:35:58 +00:00
|
|
|
* FILE: dll/win32/msafd/misc/event.c
|
2006-02-17 00:04:10 +00:00
|
|
|
* PURPOSE: Event handling
|
|
|
|
* PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
|
2016-11-09 11:49:55 +00:00
|
|
|
* Alex Ionescu (alex@relsoft.net)
|
2006-02-17 00:04:10 +00:00
|
|
|
* REVISIONS:
|
2016-11-09 11:49:55 +00:00
|
|
|
* CSH 15/06/2001 - Created
|
|
|
|
* Alex 16/07/2004 - Complete Rewrite
|
2006-02-17 00:04:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <msafd.h>
|
|
|
|
|
2011-10-03 14:40:39 +00:00
|
|
|
int
|
|
|
|
WSPAPI
|
2006-02-17 00:04:10 +00:00
|
|
|
WSPEventSelect(
|
2016-11-09 11:49:55 +00:00
|
|
|
IN SOCKET Handle,
|
|
|
|
IN WSAEVENT hEventObject,
|
|
|
|
IN long lNetworkEvents,
|
|
|
|
OUT LPINT lpErrno)
|
2006-02-17 00:04:10 +00:00
|
|
|
{
|
2016-11-09 11:49:55 +00:00
|
|
|
IO_STATUS_BLOCK IOSB;
|
|
|
|
AFD_EVENT_SELECT_INFO EventSelectInfo;
|
|
|
|
PSOCKET_INFORMATION Socket = NULL;
|
|
|
|
NTSTATUS Status;
|
|
|
|
BOOLEAN BlockMode;
|
|
|
|
HANDLE SockEvent;
|
|
|
|
|
|
|
|
TRACE("WSPEventSelect (%lx) %lx %lx\n", Handle, hEventObject, lNetworkEvents);
|
|
|
|
|
|
|
|
/* Get the Socket Structure associate to this Socket*/
|
|
|
|
Socket = GetSocketStructure(Handle);
|
|
|
|
if (!Socket)
|
|
|
|
{
|
|
|
|
if (lpErrno) *lpErrno = WSAENOTSOCK;
|
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = NtCreateEvent(&SockEvent, EVENT_ALL_ACCESS,
|
2018-01-06 17:11:18 +00:00
|
|
|
NULL, SynchronizationEvent, FALSE);
|
2016-11-09 11:49:55 +00:00
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status)) return SOCKET_ERROR;
|
|
|
|
|
|
|
|
/* Set Socket to Non-Blocking */
|
|
|
|
BlockMode = TRUE;
|
|
|
|
SetSocketInformation(Socket, AFD_INFO_BLOCKING_MODE, &BlockMode, NULL, NULL, NULL, NULL);
|
|
|
|
Socket->SharedData->NonBlocking = TRUE;
|
|
|
|
|
|
|
|
/* Deactivate Async Select if there is one */
|
|
|
|
if (Socket->EventObject) {
|
|
|
|
Socket->SharedData->hWnd = NULL;
|
|
|
|
Socket->SharedData->wMsg = 0;
|
|
|
|
Socket->SharedData->AsyncEvents = 0;
|
|
|
|
Socket->SharedData->SequenceNumber++; // This will kill Async Select after the next completion
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set Structure Info */
|
|
|
|
EventSelectInfo.EventObject = hEventObject;
|
|
|
|
EventSelectInfo.Events = 0;
|
|
|
|
|
|
|
|
/* Set Events to wait for */
|
|
|
|
if (lNetworkEvents & FD_READ) {
|
|
|
|
EventSelectInfo.Events |= AFD_EVENT_RECEIVE;
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lNetworkEvents & FD_WRITE) {
|
2016-11-09 11:49:55 +00:00
|
|
|
EventSelectInfo.Events |= AFD_EVENT_SEND;
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lNetworkEvents & FD_OOB) {
|
|
|
|
EventSelectInfo.Events |= AFD_EVENT_OOB_RECEIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lNetworkEvents & FD_ACCEPT) {
|
2016-11-09 11:49:55 +00:00
|
|
|
EventSelectInfo.Events |= AFD_EVENT_ACCEPT;
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lNetworkEvents & FD_CONNECT) {
|
|
|
|
EventSelectInfo.Events |= AFD_EVENT_CONNECT | AFD_EVENT_CONNECT_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lNetworkEvents & FD_CLOSE) {
|
2016-11-09 11:49:55 +00:00
|
|
|
EventSelectInfo.Events |= AFD_EVENT_DISCONNECT | AFD_EVENT_ABORT | AFD_EVENT_CLOSE;
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lNetworkEvents & FD_QOS) {
|
2016-11-09 11:49:55 +00:00
|
|
|
EventSelectInfo.Events |= AFD_EVENT_QOS;
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lNetworkEvents & FD_GROUP_QOS) {
|
2016-11-09 11:49:55 +00:00
|
|
|
EventSelectInfo.Events |= AFD_EVENT_GROUP_QOS;
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Send IOCTL */
|
|
|
|
Status = NtDeviceIoControlFile((HANDLE)Handle,
|
2016-11-09 11:49:55 +00:00
|
|
|
SockEvent,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&IOSB,
|
|
|
|
IOCTL_AFD_EVENT_SELECT,
|
|
|
|
&EventSelectInfo,
|
|
|
|
sizeof(EventSelectInfo),
|
|
|
|
NULL,
|
|
|
|
0);
|
2006-02-17 00:04:10 +00:00
|
|
|
|
|
|
|
/* Wait for return */
|
|
|
|
if (Status == STATUS_PENDING) {
|
2014-11-10 13:06:48 +00:00
|
|
|
WaitForSingleObject(SockEvent, INFINITE);
|
2010-06-06 23:07:26 +00:00
|
|
|
Status = IOSB.Status;
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 11:49:55 +00:00
|
|
|
NtClose (SockEvent);
|
2006-02-17 00:04:10 +00:00
|
|
|
|
2010-06-06 23:07:26 +00:00
|
|
|
if (Status != STATUS_SUCCESS)
|
2014-11-10 13:06:48 +00:00
|
|
|
{
|
|
|
|
ERR("Got status 0x%08x.\n", Status);
|
2010-06-06 23:07:26 +00:00
|
|
|
return MsafdReturnWithErrno(Status, lpErrno, 0, NULL);
|
2014-11-10 13:06:48 +00:00
|
|
|
}
|
2010-06-06 23:07:26 +00:00
|
|
|
|
2006-02-17 00:04:10 +00:00
|
|
|
/* Set Socket Data*/
|
|
|
|
Socket->EventObject = hEventObject;
|
|
|
|
Socket->NetworkEvents = lNetworkEvents;
|
|
|
|
|
2014-11-10 13:06:48 +00:00
|
|
|
TRACE("Leaving\n");
|
2006-02-17 00:04:10 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INT
|
|
|
|
WSPAPI
|
|
|
|
WSPEnumNetworkEvents(
|
2016-11-09 11:49:55 +00:00
|
|
|
IN SOCKET Handle,
|
|
|
|
IN WSAEVENT hEventObject,
|
|
|
|
OUT LPWSANETWORKEVENTS lpNetworkEvents,
|
|
|
|
OUT LPINT lpErrno)
|
2006-02-17 00:04:10 +00:00
|
|
|
{
|
|
|
|
AFD_ENUM_NETWORK_EVENTS_INFO EnumReq;
|
2016-11-09 11:49:55 +00:00
|
|
|
IO_STATUS_BLOCK IOSB;
|
|
|
|
PSOCKET_INFORMATION Socket = NULL;
|
|
|
|
NTSTATUS Status;
|
|
|
|
HANDLE SockEvent;
|
2006-02-17 00:04:10 +00:00
|
|
|
|
2014-11-10 13:06:48 +00:00
|
|
|
TRACE("Called (lpNetworkEvents %x)\n", lpNetworkEvents);
|
2006-02-17 00:04:10 +00:00
|
|
|
|
|
|
|
/* Get the Socket Structure associate to this Socket*/
|
|
|
|
Socket = GetSocketStructure(Handle);
|
2010-06-07 01:24:15 +00:00
|
|
|
if (!Socket)
|
|
|
|
{
|
2016-11-02 15:36:26 +00:00
|
|
|
if (lpErrno) *lpErrno = WSAENOTSOCK;
|
2010-06-07 01:24:15 +00:00
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
2016-11-09 11:49:55 +00:00
|
|
|
if (!lpNetworkEvents)
|
|
|
|
{
|
|
|
|
if (lpErrno) *lpErrno = WSAEFAULT;
|
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = NtCreateEvent(&SockEvent, EVENT_ALL_ACCESS,
|
2018-01-06 17:11:18 +00:00
|
|
|
NULL, SynchronizationEvent, FALSE);
|
2016-11-09 11:49:55 +00:00
|
|
|
|
|
|
|
if( !NT_SUCCESS(Status) ) {
|
|
|
|
ERR("Could not make an event %x\n", Status);
|
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
2006-02-17 00:04:10 +00:00
|
|
|
|
|
|
|
EnumReq.Event = hEventObject;
|
|
|
|
|
|
|
|
/* Send IOCTL */
|
|
|
|
Status = NtDeviceIoControlFile((HANDLE)Handle,
|
2016-11-09 11:49:55 +00:00
|
|
|
SockEvent,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&IOSB,
|
|
|
|
IOCTL_AFD_ENUM_NETWORK_EVENTS,
|
|
|
|
&EnumReq,
|
|
|
|
sizeof(EnumReq),
|
|
|
|
NULL,
|
|
|
|
0);
|
2006-02-17 00:04:10 +00:00
|
|
|
|
|
|
|
/* Wait for return */
|
|
|
|
if (Status == STATUS_PENDING) {
|
2014-11-10 13:06:48 +00:00
|
|
|
WaitForSingleObject(SockEvent, INFINITE);
|
|
|
|
Status = IOSB.Status;
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 11:49:55 +00:00
|
|
|
NtClose (SockEvent);
|
2006-02-17 00:04:10 +00:00
|
|
|
|
2010-06-06 23:07:26 +00:00
|
|
|
if (Status != STATUS_SUCCESS)
|
2014-11-10 13:06:48 +00:00
|
|
|
{
|
|
|
|
ERR("Status 0x%08x", Status);
|
2010-06-06 23:07:26 +00:00
|
|
|
return MsafdReturnWithErrno(Status, lpErrno, 0, NULL);
|
2014-11-10 13:06:48 +00:00
|
|
|
}
|
2010-06-06 23:07:26 +00:00
|
|
|
|
2010-05-28 03:55:50 +00:00
|
|
|
lpNetworkEvents->lNetworkEvents = 0;
|
2006-02-17 00:04:10 +00:00
|
|
|
|
|
|
|
/* Set Events to wait for */
|
|
|
|
if (EnumReq.PollEvents & AFD_EVENT_RECEIVE) {
|
2014-11-10 13:06:48 +00:00
|
|
|
lpNetworkEvents->lNetworkEvents |= FD_READ;
|
|
|
|
lpNetworkEvents->iErrorCode[FD_READ_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_READ_BIT]);
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (EnumReq.PollEvents & AFD_EVENT_SEND) {
|
2014-11-10 13:06:48 +00:00
|
|
|
lpNetworkEvents->lNetworkEvents |= FD_WRITE;
|
|
|
|
lpNetworkEvents->iErrorCode[FD_WRITE_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_WRITE_BIT]);
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (EnumReq.PollEvents & AFD_EVENT_OOB_RECEIVE) {
|
|
|
|
lpNetworkEvents->lNetworkEvents |= FD_OOB;
|
2014-11-10 13:06:48 +00:00
|
|
|
lpNetworkEvents->iErrorCode[FD_OOB_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_OOB_BIT]);
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (EnumReq.PollEvents & AFD_EVENT_ACCEPT) {
|
2014-11-10 13:06:48 +00:00
|
|
|
lpNetworkEvents->lNetworkEvents |= FD_ACCEPT;
|
|
|
|
lpNetworkEvents->iErrorCode[FD_ACCEPT_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_ACCEPT_BIT]);
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
2011-10-03 14:40:39 +00:00
|
|
|
if (EnumReq.PollEvents &
|
2014-11-10 13:06:48 +00:00
|
|
|
(AFD_EVENT_CONNECT | AFD_EVENT_CONNECT_FAIL)) {
|
2006-02-17 00:04:10 +00:00
|
|
|
lpNetworkEvents->lNetworkEvents |= FD_CONNECT;
|
2014-11-10 13:06:48 +00:00
|
|
|
lpNetworkEvents->iErrorCode[FD_CONNECT_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_CONNECT_BIT]);
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
2011-10-03 14:40:39 +00:00
|
|
|
if (EnumReq.PollEvents &
|
2016-11-09 11:49:55 +00:00
|
|
|
(AFD_EVENT_DISCONNECT | AFD_EVENT_ABORT | AFD_EVENT_CLOSE)) {
|
2014-11-10 13:06:48 +00:00
|
|
|
lpNetworkEvents->lNetworkEvents |= FD_CLOSE;
|
|
|
|
lpNetworkEvents->iErrorCode[FD_CLOSE_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_CLOSE_BIT]);
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (EnumReq.PollEvents & AFD_EVENT_QOS) {
|
2016-11-09 11:49:55 +00:00
|
|
|
lpNetworkEvents->lNetworkEvents |= FD_QOS;
|
|
|
|
lpNetworkEvents->iErrorCode[FD_QOS_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_QOS_BIT]);
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (EnumReq.PollEvents & AFD_EVENT_GROUP_QOS) {
|
2014-11-10 13:06:48 +00:00
|
|
|
lpNetworkEvents->lNetworkEvents |= FD_GROUP_QOS;
|
|
|
|
lpNetworkEvents->iErrorCode[FD_GROUP_QOS_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_GROUP_QOS_BIT]);
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-10 13:06:48 +00:00
|
|
|
TRACE("Leaving\n");
|
2006-02-17 00:04:10 +00:00
|
|
|
|
2010-06-06 23:07:26 +00:00
|
|
|
return MsafdReturnWithErrno(STATUS_SUCCESS, lpErrno, 0, NULL);
|
2006-02-17 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|