Important Update:
- BufferCore: - Added PeekCopy and PopCopy methods - SelectableCore: - Add status checking of Handle on Read and Write - Reject input if Handle not open - TimingCore: - Added method ClearStartTime
This commit is contained in:
@@ -120,6 +120,56 @@ int CBuffer::Peek( char ** Data, int PeekPos, int MaxLen )
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Return "stitched" buffer data in temporary buffer
|
||||
int CBuffer::PeekCopy( char ** Data, int PeekPos, int MaxLen )
|
||||
{
|
||||
int BytesReturned = 0;
|
||||
int StartPos = 0;
|
||||
|
||||
// Check if any data
|
||||
if (!BufLen || !MaxLen) {
|
||||
if (*Data)
|
||||
(*Data)[0] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Validate start position
|
||||
if (PeekPos >= BufLen) {
|
||||
if (*Data)
|
||||
(*Data)[0] = 0;
|
||||
return 0;
|
||||
}
|
||||
else if (BufStart + StartPos < BufSize) {
|
||||
StartPos = BufStart + PeekPos;
|
||||
}
|
||||
else {
|
||||
StartPos = BufStart + PeekPos - BufSize;
|
||||
}
|
||||
|
||||
// Validate MaxLen
|
||||
if ((MaxLen == -1) || (MaxLen > BufSize)) {
|
||||
MaxLen = BufSize;
|
||||
}
|
||||
BytesReturned = (MaxLen > BufLen - PeekPos)? (BufLen - PeekPos) : MaxLen;
|
||||
|
||||
// Allocate memory
|
||||
if (!*Data)
|
||||
*Data = (char*)malloc( BytesReturned + 1 );
|
||||
|
||||
// Copy Data from Buffer
|
||||
if (StartPos + BytesReturned <= BufSize) {
|
||||
memcpy( *Data, &Buffer[StartPos], BytesReturned );
|
||||
}
|
||||
else {
|
||||
memcpy( *Data, &Buffer[StartPos], BufSize-StartPos ); // Copy from end of buffer
|
||||
memcpy( &(*Data)[BufSize-StartPos], Buffer, (BytesReturned-(BufSize-StartPos)) ); // Copy rollover from start of buffer
|
||||
}
|
||||
(*Data)[BytesReturned] = 0;
|
||||
|
||||
return BytesReturned;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
int CBuffer::Clear( int ClearLen )
|
||||
{
|
||||
int BytesCleared;
|
||||
@@ -223,6 +273,23 @@ int CBuffer::Pop( char ** Data, int MaxLen )
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Read first-in bytes from buffer
|
||||
// Return "stitched" buffer data in temporary buffer
|
||||
int CBuffer::PopCopy( char ** Data, int MaxLen )
|
||||
{
|
||||
int BytesWritten = 0;
|
||||
|
||||
// Read data
|
||||
BytesWritten = PeekCopy( Data, MaxLen );
|
||||
|
||||
// Clear bytes
|
||||
Clear( BytesWritten );
|
||||
|
||||
// Return temp buffer
|
||||
return BytesWritten;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Read File descriptor directly into rolling buffer
|
||||
int CBuffer::ReadFromFD( int Handle, int MaxRead )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user