poll-win.cpp revision f482d2774312de1fa64a6232d17fc7ef7296f80e
/* $Id$ */
/** @file
* IPRT - Polling I/O Handles, Windows Implementation.
*
* @todo merge poll-win.cpp and poll-posix.cpp, there is lots of common code.
*/
/*
* Copyright (C) 2010 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <Windows.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Handle entry in a poll set.
*/
typedef struct RTPOLLSETHNDENT
{
/** The handle type. */
/** The handle ID. */
/** The events we're waiting for here. */
/** Set if this is the final entry for this handle.
* If the handle is entered more than once, this will be clear for all but
* the last entry. */
bool fFinalEntry;
/** The handle union. */
/** Pointer to a handle entry. */
typedef RTPOLLSETHNDENT *PRTPOLLSETHNDENT;
/**
* Poll set data, Windows.
*/
typedef struct RTPOLLSETINTERNAL
{
/** The magic value (RTPOLLSET_MAGIC). */
/** Set when someone is polling or making changes. */
bool volatile fBusy;
/** The number of valid handles in the set. */
/** The native handles. */
/** Array of handles and IDs. */
/**
* Common worker for RTPoll and RTPollNoResume
*/
static int rtPollNoResumeWorker(RTPOLLSETINTERNAL *pThis, RTMSINTERVAL cMillies, uint32_t *pfEvents, uint32_t *pid)
{
int rc;
return VERR_DEADLOCK;
/*
* Check for special case, RTThreadSleep...
*/
if (cHandles == 0)
{
if (RT_SUCCESS(rc))
rc = VERR_TIMEOUT;
return rc;
}
/*
* Check + prepare the handles before waiting.
*/
uint32_t i;
for (i = 0; i < cHandles; i++)
{
{
case RTHANDLETYPE_PIPE:
break;
case RTHANDLETYPE_SOCKET:
break;
default:
AssertFailed();
break;
}
if (fEvents)
break;
}
if ( fEvents
|| fNoWait)
{
if (pid)
if (pfEvents)
: fEvents != UINT32_MAX
/* clean up */
if (!fNoWait)
while (i-- > 0)
{
{
case RTHANDLETYPE_PIPE:
break;
case RTHANDLETYPE_SOCKET:
break;
default:
AssertFailed();
break;
}
}
return rc;
}
/*
* Wait.
*/
FALSE /*fWaitAll */,
TRUE /*fAlertable*/);
if ( dwRc >= WAIT_OBJECT_0
else if (dwRc == WAIT_TIMEOUT)
rc = VERR_TIMEOUT;
else if (dwRc == WAIT_IO_COMPLETION)
else if (dwRc == WAIT_FAILED)
else
{
}
/*
* Get event (if pending) and do wait cleanup.
*/
i = cHandles;
while (i-- > 0)
{
fEvents = 0;
{
case RTHANDLETYPE_PIPE:
break;
case RTHANDLETYPE_SOCKET:
break;
default:
AssertFailed();
break;
}
if (fEvents)
{
if (pfEvents)
if (pid)
rc = VINF_SUCCESS;
}
}
return rc;
}
{
/*
* Set the busy flag and do the job.
*/
int rc;
{
while (rc == VERR_INTERRUPTED);
}
else
{
{
{
rc = VERR_TIMEOUT;
break;
}
}
}
return rc;
}
RTDECL(int) RTPollNoResume(RTPOLLSET hPollSet, RTMSINTERVAL cMillies, uint32_t *pfEvents, uint32_t *pid)
{
/*
* Set the busy flag and do the job.
*/
return rc;
}
{
if (!pThis)
return VERR_NO_MEMORY;
return VINF_SUCCESS;
}
{
if (pThis == NIL_RTPOLLSET)
return VINF_SUCCESS;
return VINF_SUCCESS;
}
{
/*
* Validate the input (tedious).
*/
if (!pHandle)
return VINF_SUCCESS;
AssertReturn(pHandle->enmType > RTHANDLETYPE_INVALID && pHandle->enmType < RTHANDLETYPE_END, VERR_INVALID_PARAMETER);
/*
* Set the busy flag and do the job.
*/
int rc = VINF_SUCCESS;
{
case RTHANDLETYPE_PIPE:
break;
case RTHANDLETYPE_SOCKET:
break;
case RTHANDLETYPE_FILE:
AssertMsgFailed(("Files are always ready for reading/writing and thus not pollable. Use native APIs for special devices.\n"));
break;
case RTHANDLETYPE_THREAD:
AssertMsgFailed(("Thread handles are currently not pollable\n"));
break;
default:
AssertMsgFailed(("\n"));
break;
}
if ( RT_SUCCESS(rc)
&& hNative != INVALID_HANDLE_VALUE)
{
/* Check that the handle ID doesn't exist already. */
uint32_t j = i;
while (j-- > 0)
{
{
break;
}
iPrev = j;
}
/* Check that we won't overflow the poll set now. */
if ( RT_SUCCESS(rc)
if (RT_SUCCESS(rc))
{
/* Add the handles to the two parallel arrays. */
if (iPrev != UINT32_MAX)
{
}
rc = VINF_SUCCESS;
}
}
return rc;
}
{
/*
* Validate the input.
*/
/*
* Set the busy flag and do the job.
*/
int rc = VERR_POLL_HANDLE_ID_NOT_FOUND;
while (i-- > 0)
{
/* Save some details for the duplicate searching. */
/* Remove the entry. */
if (cToMove)
{
}
/* Check for duplicate and set the fFinalEntry flag. */
if (fFinalEntry)
while (i-- > 0)
{
break;
}
rc = VINF_SUCCESS;
break;
}
return rc;
}
{
/*
* Validate the input.
*/
/*
* Set the busy flag and do the job.
*/
int rc = VERR_POLL_HANDLE_ID_NOT_FOUND;
while (i-- > 0)
{
if (pHandle)
{
}
rc = VINF_SUCCESS;
break;
}
return rc;
}
{
/*
* Validate the input.
*/
/*
* Set the busy flag and do the job.
*/
return cHandles;
}