poll-posix.cpp revision e64031e20c39650a7bc902a3e1aba613b9415dee
/* $Id$ */
/** @file
* IPRT - Polling I/O Handles, POSIX Implementation.
*/
/*
* Copyright (C) 2010 Oracle Corporation
*
* 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <limits.h>
#include <errno.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Handle entry in a poll set.
*/
typedef struct RTPOLLSETHNDENT
{
/** The handle type. */
/** The handle ID. */
/** The handle union. */
/** Pointer to a handle entry. */
typedef RTPOLLSETHNDENT *PRTPOLLSETHNDENT;
/**
* Poll set data, POSIX.
*/
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 number of allocated handles. */
/** Pointer to an array of pollfd structures. */
/** Pointer to an array of handles and IDs. */
/**
* Common worker for RTPoll and RTPollNoResume
*/
static int rtPollNoResumeWorker(RTPOLLSETINTERNAL *pThis, RTMSINTERVAL cMillies, uint32_t *pfEvents, uint32_t *pid)
{
return VERR_DEADLOCK;
/* clear the revents. */
while (i-- > 0)
? -1
: (int)cMillies);
if (rc == 0)
return VERR_TIMEOUT;
if (rc < 0)
return RTErrConvertFromErrno(errno);
{
if (pfEvents)
{
*pfEvents = 0;
#ifdef POLLRDNORM
| POLLRDNORM /* just in case */
#endif
#ifdef POLLRDBAND
| POLLRDBAND /* ditto */
#endif
#ifdef POLLPRI
| POLLPRI /* ditto */
#endif
#ifdef POLLMSG
| POLLMSG /* ditto */
#endif
#ifdef POLLWRITE
| POLLWRITE /* ditto */
#endif
#ifdef POLLEXTEND
| POLLEXTEND /* ditto */
#endif
)
)
*pfEvents |= RTPOLL_EVT_READ;
#ifdef POLLWRNORM
| POLLWRNORM /* just in case */
#endif
#ifdef POLLWRBAND
| POLLWRBAND /* ditto */
#endif
)
)
*pfEvents |= RTPOLL_EVT_WRITE;
#ifdef POLLRDHUP
#endif
)
)
*pfEvents |= RTPOLL_EVT_ERROR;
}
if (pid)
return VINF_SUCCESS;
}
AssertFailed();
return VERR_INTERRUPTED;
}
{
/*
* 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;
pThis->cHandlesAllocated = 0;
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;
int fd = -1;
{
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 (fd != -1)
{
/* Check that the handle ID doesn't exist already. */
uint32_t j = i;
while (j-- > 0)
{
break;
}
if (RT_SUCCESS(rc))
{
/* Grow the tables if necessary. */
{
void *pvNew;
if (pvNew)
{
if (pvNew)
else
rc = VERR_NO_MEMORY;
}
else
rc = VERR_NO_MEMORY;
}
if (RT_SUCCESS(rc))
{
/* Add it to the poll file descriptor array and call poll to
validate the event flags. */
if (fEvents & RTPOLL_EVT_READ)
if (fEvents & RTPOLL_EVT_WRITE)
if (fEvents & RTPOLL_EVT_ERROR)
{
/* Add the handle info and close the transaction. */
rc = VINF_SUCCESS;
}
else
{
}
}
}
}
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 (cToMove)
{
}
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;
}