Beispiel #1
0
extern	int
Send(
	NETFILE	*fp,
	void	*buff,
	size_t	size)
{
	char	*p = buff;
	ssize_t	count
		,	left;
	int		ret;

	if		(	fp  !=  NULL  ) {
		LockNet(fp);
		if	(	!fp->fOK	) {
			UnLockNet(fp);
			return -1;
		}
		ret = size;
		if		(	(  fp->buff  !=  NULL  )
				&&	(  fp->size  >  size  ) ) {
			while	(  size + fp->ptr  >  fp->size  ) {
				left = fp->size - fp->ptr;
				memcpy((fp->buff + fp->ptr),p,left);
				fp->ptr = fp->size;
				if		(  !_Flush(fp)  )	{
					ret = -1;
					break;
				}
				p += left;
				size -= left;
			}
			if		(  ret  !=  -1  ) {
				memcpy((fp->buff + fp->ptr),p,size);
				fp->ptr += size;
				fp->fSent = TRUE;
			}
		} else {
			_Flush(fp);
			while	(  size  >  0  ) {
				if		(  ( count = fp->write(fp,p,size) )  >  0  ) {
					size -= count;
					p += count;
				} else {
					ret = -1;
					fp->fOK = FALSE;
					break;
				}
			}
			fp->fSent = FALSE;
		}
		UnLockNet(fp);
	} else {
		ret = -1;
	}
	return	(ret);
}
Beispiel #2
0
nOS_Error nOS_QueueDelete (nOS_Queue *queue)
{
    nOS_Error       err;
    nOS_StatusReg   sr;

#if (NOS_CONFIG_SAFE > 0)
    if (queue == NULL) {
        err = NOS_E_INV_OBJ;
    } else
#endif
    {
        nOS_EnterCritical(sr);
#if (NOS_CONFIG_SAFE > 0)
        if (queue->e.type != NOS_EVENT_QUEUE) {
            err = NOS_E_INV_OBJ;
        } else
#endif
        {
            _Flush(queue);
            queue->buffer = NULL;
            queue->bsize  = 0;
            queue->bmax   = 0;
            nOS_DeleteEvent((nOS_Event*)queue);

            err = NOS_OK;
        }
        nOS_LeaveCritical(sr);
    }

    return err;
}
Beispiel #3
0
extern	Bool
Flush(
	NETFILE	*fp)
{
	LockNet(fp);
	_Flush(fp);
	UnLockNet(fp);
	return	(fp->fOK);
}
VHTTPServerLog::~VHTTPServerLog()
{
	_StopBackgroundLogFlusher();
	xbox_assert (NULL == fBackgroundFlusherTask);

	if (!fRequestsBuffer.IsEmpty())
		_Flush();

	XBOX::ReleaseRefCountable (&fLogFile);
}
Beispiel #5
0
extern	void
CloseNet(
	NETFILE	*fp)
{
ENTER_FUNC;
	if		(  fp  !=  NULL  ) {
		if		(  fp->fOK  ) {
			_Flush(fp);
		}
		fp->close(fp);
		FreeNet(fp);
	}
LEAVE_FUNC;
}
Beispiel #6
0
//===============================================================================================
// PROCEDURE: SetMode
// PURPOSE:   Sets the buffering mode of the CSynch object.
//
void CSynch::SetMode(eMODE eMode)
{
   MEMBERASSERT();
   if ((m_eMode==eMode) || !_IsFileOpen())
      return;

   // If the old mode was for writing, flush the cache to disk.
   if (m_eMode==eWRITEMODE)
      _Flush();

   // Set the new mode.
   m_eMode = eMode;
   m_uCacheStart = m_uSynchCount;

   // If the new mode is for writing, preload the cache with the last n entries.
   if (m_eMode==eWRITEMODE)
   {
      UINT uCount = SYNCH_BUFFER_SIZE;

      if (m_uSynchCount < SYNCH_BUFFER_SIZE)
      {
         m_uCacheStart = 0;
         uCount = m_uSynchCount;
      }
      else
         m_uCacheStart = m_uSynchCount - SYNCH_BUFFER_SIZE;

      // Read the data out of the file.
      Read( m_SynchBuffer, m_uCacheStart, uCount );

      // Set the current position to the start of the bit we last read, and truncate the file here.
      SetFilePointer(m_hfSynchFile, m_uCacheStart * sizeof(Synch), NULL, FILE_BEGIN);
      //TRACE1( "CSynch::SetMode file position is %d.\n",
      //         SetFilePointer(m_hfSynchFile, 0, NULL, FILE_CURRENT) );
      VERIFY(SetEndOfFile(m_hfSynchFile));

      m_uCacheCount = uCount;
      m_LastEntry   = m_SynchBuffer[uCount-1];
   }
   else
   {
      // Set the start index of the cache to the count of items in the file to
      // cause the cache to be invalid and filled on the next get.
      m_uCacheStart = m_uSynchCount;
   }
}
Beispiel #7
0
/* Can create queue with block count at 0 to use it as pipe object (no buffer needed). */
nOS_Error nOS_QueueCreate (nOS_Queue *queue, void *buffer, uint8_t bsize, nOS_QueueCounter bmax)
{
    nOS_Error       err;
    nOS_StatusReg   sr;

#if (NOS_CONFIG_SAFE > 0)
    if (queue == NULL) {
        err = NOS_E_INV_OBJ;
    }
    else if (bsize == 0) {
        err = NOS_E_INV_VAL;
    }
    else if ((buffer != NULL) && (bmax == 0)) {
        err = NOS_E_INV_VAL;
    }
    else if ((buffer == NULL) && (bmax > 0)) {
        err = NOS_E_INV_VAL;
    } else
#endif
    {
        nOS_EnterCritical(sr);
#if (NOS_CONFIG_SAFE > 0)
        if (queue->e.type != NOS_EVENT_INVALID) {
            err = NOS_E_INV_OBJ;
        } else
#endif
        {
            nOS_CreateEvent((nOS_Event*)queue
#if (NOS_CONFIG_SAFE > 0)
                           ,NOS_EVENT_QUEUE
#endif
                           );
            queue->buffer = (uint8_t*)buffer;
            queue->bsize  = bsize;
            queue->bmax   = bmax;
            _Flush(queue);

            err = NOS_OK;
        }
        nOS_LeaveCritical(sr);
    }

    return err;
}
Beispiel #8
0
nOS_Error nOS_QueueFlush (nOS_Queue *queue, nOS_QueueCallback callback)
{
    nOS_Error       err;
    nOS_StatusReg   sr;

#if (NOS_CONFIG_SAFE > 0)
    if (queue == NULL) {
        err = NOS_E_INV_OBJ;
    } else
#endif
    {
        nOS_EnterCritical(sr);
#if (NOS_CONFIG_SAFE > 0)
        if (queue->e.type != NOS_EVENT_QUEUE) {
            err = NOS_E_INV_OBJ;
        } else
#endif
        {
            /* If blocks are stored in queue ... */
            if (queue->bcount > 0) {
                if (callback != NULL) {
                    /* ... call user's callback for every stored block */
                    while (queue->bcount > 0) {
                        callback(queue, &queue->buffer[(size_t)queue->r * (size_t)queue->bsize]);
                        queue->r = (queue->r + 1) % queue->bmax;
                        queue->bcount--;
                    }
                }
                else {
                    _Flush(queue);
                }
                /* maybe some threads are waiting to write in queue */
                nOS_BroadcastEvent((nOS_Event*)queue, NOS_E_FLUSHED);
            }
            err = NOS_OK;
        }
        nOS_LeaveCritical(sr);
    }

    return err;
}
Beispiel #9
0
//===============================================================================================
// PROCEDURE: Put
// PURPOSE:   Puts a new Synch entry into the synch array, flushing to disk if full.
//
BOOL CSynch::Put( UINT uStart, UINT uLength, UINT uOffset )
{
   MEMBERASSERT();
   ASSERT(m_eMode==eWRITEMODE);
   ASSERT((m_uSynchCount == 0) || (m_LastEntry.dwStart <= uStart));

   // Flush the cache if it is full.
   if ((m_uCacheCount >= SYNCH_BUFFER_SIZE) && (!_Flush()))
      return FALSE;

   // If a value of zero is passed as the file offset, the file offset for this
   // entry is derived from the previous one.      
   if (uOffset == 0)
      m_LastEntry.dwFileOffset += m_LastEntry.dwLength * 2;
   else
      m_LastEntry.dwFileOffset = uOffset;
      
   m_LastEntry.dwStart  = uStart;
   m_LastEntry.dwLength = uLength;
   m_SynchBuffer[m_uCacheCount++] = m_LastEntry;
   m_uSynchCount++;
   return TRUE;
}
Beispiel #10
0
extern	int
Recv(
	NETFILE	*fp,
	void	*buff,
	size_t	size)
{
	char	*p = buff;
	ssize_t	count;
	int		ret;

	if		(	fp  !=  NULL  ) {
		LockNet(fp);
		if	(	!fp->fOK	) {
			UnLockNet(fp);
			return -1;
		}
		if		(  fp->fSent  ) {
			_Flush(fp);
		}
		ret = size;
		while	(  size  >  0  ) {
			if		(  ( count = RecvAtOnce(fp,p,size) )  >  0  ) {
				size -= count;
				p += count;
			} else {
				ret = -1;
				break;
			}
		}
		UnLockNet(fp);
	} else {
		ret = -1;
	}
	fp->fSent = FALSE;
	return	(ret);
}
Beispiel #11
0
bool GPFileWStream::vFlush()
{
    return _Flush(mF);
}
Beispiel #12
0
//===============================================================================================
// PROCEDURE: Write
// PURPOSE:   Copies the complete synch array to another file, packing out the file-offset entry.
//
BOOL CSynch::Write( HANDLE hDataFile, UINT uAcquiredSamples, UINT *puSynchCount, UINT uSampleSize )
{
   MEMBERASSERT();
   ASSERT( hDataFile != INVALID_HANDLE_VALUE );
   WPTRASSERT(puSynchCount);

   // Flush any cached Synch entries to the temp file. This should not fail as the reserve file
   // will have been released just prior to calling this function. If it does fail, we will
   // still be able to work with the Synch entries that were saved ok.
   if (m_uCacheCount)
      _Flush();

   // Set the return value for the number of synch entries. If none exist, return.
   *puSynchCount = 0;
   if (m_uSynchCount == 0)
      return TRUE;

   // Seek to the end of the passed file. This will only fail for invalid file handles.
   CFileIO_NoClose OutFile(hDataFile);
   LONGLONG llCurrentPos = 0;
   if (!OutFile.Seek(0, FILE_END, &llCurrentPos))
      return FALSE;

   // Seek to the start of the temporary file.
   SetFilePointer(m_hfSynchFile, 0L, NULL, FILE_BEGIN);

   // Read the Synch data in a buffer at a time and write it out to the passed file.
   UINT uEntries = m_uSynchCount;
   UINT uWritten = 0;
   UINT uCount = 0;
   while ( uEntries > 0 )
   {
      uCount = min(uEntries, SYNCH_BUFFER_SIZE);
   
      // Read in a buffer from the temp file.
      VERIFY(Read( m_SynchBuffer, uWritten, uCount));      

      // Pack the buffer, removing the dwFileOffset members and checking for invalid synch entries.
      // If an invalid entry is found, the count is truncated at the last valid entry.
      if (!_PackBuffer(uAcquiredSamples, uCount, uSampleSize))
         uEntries = uCount;
      
      // Write the packed buffer out to the temp file.
      if ( !OutFile.Write( m_SynchBuffer, uCount * 2 * sizeof(DWORD) ))
      {
         // If an error occurs, go back to the start of the block and truncate the file
         // ready for the next attempt after the user has freed up some disk space.
         VERIFY(OutFile.Seek(llCurrentPos, FILE_BEGIN));
         VERIFY(OutFile.SetEndOfFile());
         return FALSE;
      }
      
      uEntries -= uCount;
      uWritten += uCount;
   }
   
   // Seek back to end of the temporary file.
   SetFilePointer(m_hfSynchFile, 0L, NULL, FILE_END);
   //TRACE1( "CSynch::Write current file pointer is %d after seek to end.\n",
   //         SetFilePointer(m_hfSynchFile, 0, NULL, FILE_CURRENT) );
   *puSynchCount = uWritten;
   return TRUE;
}