VBoxServicePipeBuf.cpp revision c233a6c1d308bef5547fbdaf150e55d4bffe8160
/* $Id: */
/** @file
* VBoxServicePipeBuf - Pipe buffering.
*/
/*
* Copyright (C) 2011 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/semaphore.h>
#include "VBoxServicePipeBuf.h"
/**
* Initializes a pipe buffer.
*
* @returns IPRT status code.
* @param pBuf The pipe buffer to initialize.
* @param fNeedNotificationPipe Whether the buffer needs a notification
* pipe or not.
*/
{
/** @todo Add allocation size as function parameter! */
pBuf->fPendingClose = false;
if (RT_SUCCESS(rc))
{
{
if (RT_FAILURE(rc))
{
}
}
}
return rc;
}
/**
* Reads out data from a specififed pipe buffer.
*
* @return IPRT status code.
* @param pBuf Pointer to pipe buffer to read the data from.
* @param pbBuffer Pointer to buffer to store the read out data.
* @param cbBuffer Size (in bytes) of the buffer where to store the data.
* @param pcbToRead Pointer to desired amount (in bytes) of data to read,
* will reflect the actual amount read on return.
*/
{
if (RT_SUCCESS(rc))
{
if (*pcbToRead > 0)
{
}
else
{
*pcbToRead = 0;
}
}
return rc;
}
/**
* Writes data into a specififed pipe buffer.
*
* @return IPRT status code.
* @param pBuf Pointer to pipe buffer to write data into.
* @param pbData Pointer to byte data to write.
* @param cbData Data size (in bytes) to write.
* @param fPendingClose Needs the pipe (buffer) to be closed next time we have the chance to?
* @param pcbWritten Pointer to where the amount of written bytes get stored. Optional.
*/
{
if (RT_SUCCESS(rc))
{
{
/* Rewind the buffer if it's empty. */
if (fAddToSet)
/* Try and see if we can simply append the data. */
{
}
else
{
/* Move any buffered data to the front. */
if (cbInBuf == 0)
{
}
/* Do we need to grow the buffer? */
{
if (pvNew)
{
}
else
rc = VERR_NO_MEMORY;
}
/* Finally, copy the data. */
if (RT_SUCCESS(rc))
{
{
}
else
}
}
if (RT_SUCCESS(rc))
{
/*
* next time we have the chance to.
*/
if (fPendingClose)
/*
* Wake up the thread servicing the process so it can feed it
* (if we have a notification helper pipe).
*/
if (pBuf->fNeedNotification)
{
/* Disable notification until it is set again on successful write. */
}
/* Report back written bytes (if wanted). */
if (pcbWritten)
*pcbWritten = cbData;
}
if (RT_SUCCESS(rc))
}
else
rc = VERR_BAD_PIPE;
}
return rc;
}
{
if (RT_SUCCESS(rc))
{
/* Set current bytes left in pipe buffer. It's okay
* to have no data in yet ... */
&& cbToWrite)
{
if (RT_SUCCESS(rc))
{
pBuf->fNeedNotification = true;
if (rc != VINF_TRY_AGAIN)
/* Did somebody tell us that we should come to an end,
* e.g. no more data coming in? */
if (pBuf->fPendingClose)
{
/* Is there more data to write out? */
{
/* We have a pending close, but there's more data that we can write out
* from buffer to pipe ... */
if (pBuf->fNeedNotification)
{
/* Still data to push out - so we need another
* poll round! Write something into the notification pipe. */
/* Disable notification until it is set again on successful write. */
}
}
}
/* Set new bytes left in pipe buffer afer we wrote to the pipe above. */
}
else
{
*pcbWritten = 0;
}
}
else
{
*pcbWritten = 0;
}
if (RT_SUCCESS(rc))
}
return rc;
}
/**
* Returns whether a pipe buffer is active or not.
*
* @return bool True if pipe buffer is active, false if not.
* @param pBuf The pipe buffer.
*/
{
bool fEnabled = false;
{
}
return fEnabled;
}
/**
* Returns whether a pipe buffer is in a pending close state or
* not. This means that someone has written the last chunk into
* the pipe buffer with the fPendingClose flag set.
*
* @return bool True if pipe buffer is in pending
* close state, false if not.
* @param pBuf The pipe buffer.
*/
{
bool fClosing = false;
{
}
return fClosing;
}
/**
*
* @return IPRT status code.
* @param pBuf The pipe buffer.
* @param fEnabled Pipe buffer status to set.
*/
{
if (RT_SUCCESS(rc))
{
/* Let waiter know that something has changed ... */
}
return rc;
}
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
}
return rc;
}
/**
* Deletes a pipe buffer.
* Note: Not thread safe -- only call this when nobody is relying on the
* data anymore!
*
* @param pBuf The pipe buffer.
*/
{
{
pBuf->cbAllocated = 0;
}
}