2000-09-17 09:36:01 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS WinSock 2 DLL
|
|
|
|
* FILE: misc/event.c
|
|
|
|
* PURPOSE: Event handling
|
|
|
|
* PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
|
|
|
|
* REVISIONS:
|
|
|
|
* CSH 01/09-2000 Created
|
|
|
|
*/
|
2001-07-04 20:40:24 +00:00
|
|
|
|
2011-08-10 23:04:40 +00:00
|
|
|
#include "ws2_32.h"
|
2000-09-17 09:36:01 +00:00
|
|
|
|
2003-07-10 21:28:17 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2000-09-17 09:36:01 +00:00
|
|
|
BOOL
|
|
|
|
EXPORT
|
2006-08-14 17:26:36 +00:00
|
|
|
WSACloseEvent(IN WSAEVENT hEvent)
|
2000-09-17 09:36:01 +00:00
|
|
|
{
|
2006-08-14 17:26:36 +00:00
|
|
|
BOOL Success;
|
2000-09-17 09:36:01 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
if (!WSAINITIALIZED)
|
|
|
|
{
|
|
|
|
WSASetLastError(WSANOTINITIALISED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-01-14 17:44:38 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
Success = CloseHandle((HANDLE)hEvent);
|
2001-01-14 17:44:38 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
if (!Success)
|
|
|
|
WSASetLastError(WSA_INVALID_HANDLE);
|
2001-01-14 17:44:38 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
return Success;
|
2000-09-17 09:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-10 21:28:17 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2000-09-17 09:36:01 +00:00
|
|
|
WSAEVENT
|
|
|
|
EXPORT
|
|
|
|
WSACreateEvent(VOID)
|
|
|
|
{
|
2006-08-14 17:26:36 +00:00
|
|
|
HANDLE Event;
|
2001-01-14 17:44:38 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
if (!WSAINITIALIZED)
|
|
|
|
{
|
|
|
|
WSASetLastError(WSANOTINITIALISED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-09-17 09:36:01 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
Event = CreateEventW(NULL, TRUE, FALSE, NULL);
|
2001-01-14 17:44:38 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
if (Event == INVALID_HANDLE_VALUE)
|
|
|
|
WSASetLastError(WSA_INVALID_HANDLE);
|
2003-08-07 04:03:25 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
return (WSAEVENT)Event;
|
2000-09-17 09:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-10 21:28:17 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2000-09-17 09:36:01 +00:00
|
|
|
BOOL
|
|
|
|
EXPORT
|
2006-08-14 17:26:36 +00:00
|
|
|
WSAResetEvent(IN WSAEVENT hEvent)
|
2000-09-17 09:36:01 +00:00
|
|
|
{
|
2006-08-14 17:26:36 +00:00
|
|
|
BOOL Success;
|
2001-01-14 17:44:38 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
if (!WSAINITIALIZED)
|
|
|
|
{
|
|
|
|
WSASetLastError(WSANOTINITIALISED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-01-14 17:44:38 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
Success = ResetEvent((HANDLE)hEvent);
|
2001-01-14 17:44:38 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
if (!Success)
|
|
|
|
WSASetLastError(WSA_INVALID_HANDLE);
|
2000-09-17 09:36:01 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
return Success;
|
2000-09-17 09:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-10 21:28:17 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2000-09-17 09:36:01 +00:00
|
|
|
BOOL
|
|
|
|
EXPORT
|
2006-08-14 17:26:36 +00:00
|
|
|
WSASetEvent(IN WSAEVENT hEvent)
|
2000-09-17 09:36:01 +00:00
|
|
|
{
|
2006-08-14 17:26:36 +00:00
|
|
|
BOOL Success;
|
2000-09-17 09:36:01 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
if (!WSAINITIALIZED)
|
|
|
|
{
|
|
|
|
WSASetLastError(WSANOTINITIALISED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-01-14 17:44:38 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
Success = SetEvent((HANDLE)hEvent);
|
2001-01-14 17:44:38 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
if (!Success)
|
|
|
|
WSASetLastError(WSA_INVALID_HANDLE);
|
2001-01-14 17:44:38 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
return Success;
|
2000-09-17 09:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-10 21:28:17 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2000-09-17 09:36:01 +00:00
|
|
|
DWORD
|
|
|
|
EXPORT
|
2006-08-14 17:26:36 +00:00
|
|
|
WSAWaitForMultipleEvents(IN DWORD cEvents,
|
|
|
|
IN CONST WSAEVENT FAR* lphEvents,
|
|
|
|
IN BOOL fWaitAll,
|
|
|
|
IN DWORD dwTimeout,
|
|
|
|
IN BOOL fAlertable)
|
2001-07-04 20:40:24 +00:00
|
|
|
{
|
2006-08-14 17:26:36 +00:00
|
|
|
DWORD Status;
|
|
|
|
|
|
|
|
if (!WSAINITIALIZED)
|
|
|
|
{
|
|
|
|
WSASetLastError(WSANOTINITIALISED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = WaitForMultipleObjectsEx(cEvents,
|
|
|
|
lphEvents,
|
|
|
|
fWaitAll,
|
|
|
|
dwTimeout,
|
|
|
|
fAlertable);
|
|
|
|
if (Status == WAIT_FAILED)
|
|
|
|
{
|
|
|
|
Status = GetLastError();
|
|
|
|
|
|
|
|
if (Status == ERROR_NOT_ENOUGH_MEMORY)
|
|
|
|
WSASetLastError(WSA_NOT_ENOUGH_MEMORY);
|
|
|
|
else if (Status == ERROR_INVALID_HANDLE)
|
|
|
|
WSASetLastError(WSA_INVALID_HANDLE);
|
|
|
|
else
|
|
|
|
WSASetLastError(WSA_INVALID_PARAMETER);
|
|
|
|
|
|
|
|
return WSA_WAIT_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
2001-07-04 20:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-10 21:28:17 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2001-07-04 20:40:24 +00:00
|
|
|
INT
|
|
|
|
EXPORT
|
2006-08-14 17:26:36 +00:00
|
|
|
WSAEnumNetworkEvents(IN SOCKET s,
|
|
|
|
IN WSAEVENT hEventObject,
|
|
|
|
OUT LPWSANETWORKEVENTS lpNetworkEvents)
|
2001-07-04 20:40:24 +00:00
|
|
|
{
|
2006-08-14 17:26:36 +00:00
|
|
|
PCATALOG_ENTRY Provider;
|
|
|
|
INT Status;
|
|
|
|
INT Errno;
|
|
|
|
|
|
|
|
WS_DbgPrint(MID_TRACE,("Called (Socket %x, hEventObject %x, "
|
|
|
|
"lpNetworkEvents %x)\n",
|
|
|
|
s,
|
|
|
|
hEventObject,
|
|
|
|
lpNetworkEvents));
|
|
|
|
|
|
|
|
if (!lpNetworkEvents)
|
|
|
|
{
|
|
|
|
WSASetLastError(WSAEINVAL);
|
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!WSAINITIALIZED)
|
|
|
|
{
|
|
|
|
WSASetLastError(WSANOTINITIALISED);
|
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ReferenceProviderByHandle((HANDLE)s,
|
|
|
|
&Provider))
|
|
|
|
{
|
|
|
|
WSASetLastError(WSAENOTSOCK);
|
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = Provider->ProcTable.lpWSPEnumNetworkEvents(s,
|
|
|
|
hEventObject,
|
|
|
|
lpNetworkEvents,
|
|
|
|
&Errno);
|
|
|
|
|
|
|
|
DereferenceProviderByPointer(Provider);
|
|
|
|
|
|
|
|
if (Status == SOCKET_ERROR)
|
|
|
|
WSASetLastError(Errno);
|
|
|
|
|
|
|
|
WS_DbgPrint(MID_TRACE,("Leaving %x\n", Status));
|
|
|
|
|
|
|
|
return Status;
|
2001-07-04 20:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-10 21:28:17 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2001-07-04 20:40:24 +00:00
|
|
|
INT
|
|
|
|
EXPORT
|
2006-08-14 17:26:36 +00:00
|
|
|
WSAEventSelect(IN SOCKET s,
|
|
|
|
IN WSAEVENT hEventObject,
|
|
|
|
IN LONG lNetworkEvents)
|
2000-09-17 09:36:01 +00:00
|
|
|
{
|
2006-08-14 17:26:36 +00:00
|
|
|
PCATALOG_ENTRY Provider;
|
|
|
|
INT Status;
|
|
|
|
INT Errno;
|
2001-07-04 20:40:24 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
if (!WSAINITIALIZED)
|
|
|
|
{
|
|
|
|
WSASetLastError(WSANOTINITIALISED);
|
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
2001-01-14 17:44:38 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
if (!ReferenceProviderByHandle((HANDLE)s, &Provider))
|
|
|
|
{
|
|
|
|
WSASetLastError(WSAENOTSOCK);
|
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
2001-01-14 17:44:38 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
Status = Provider->ProcTable.lpWSPEventSelect(s,
|
|
|
|
hEventObject,
|
|
|
|
lNetworkEvents,
|
|
|
|
&Errno);
|
2001-01-14 17:44:38 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
DereferenceProviderByPointer(Provider);
|
2001-01-14 17:44:38 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
if (Status == SOCKET_ERROR)
|
|
|
|
WSASetLastError(Errno);
|
2000-09-17 09:36:01 +00:00
|
|
|
|
2006-08-14 17:26:36 +00:00
|
|
|
return Status;
|
2000-09-17 09:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|