Minor Update:
- BufferCore: - Method WriteToFD should ignore EAGAIN - LogCore: - Add OUT_COUNT output bit (show total output bytes) - SelectableCore: - Add Force param on WriteToFD, ignore EAGAIN if !Force
This commit is contained in:
@@ -356,7 +356,7 @@ int CBuffer::WriteToFD( int Handle, int MaxLen )
|
||||
// Read from file descriptor
|
||||
BufRemain = BufSize - ReadPos;
|
||||
BytesWritten = write( Handle, &Buffer[ReadPos], ((BufRemain > DataRemain)? DataRemain : BufRemain) );
|
||||
if ((BytesWritten <= 0) && (errno != EAGAIN)) {
|
||||
if (BytesWritten <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ protected:
|
||||
return LocalIO;
|
||||
}
|
||||
|
||||
// Low Level Local IO interfaces
|
||||
// Manual Data Input/Output
|
||||
virtual int Output( const TLocalIO * LocalIO, const char * Data, int Len );
|
||||
|
||||
public:
|
||||
|
||||
30
LogCore.cpp
30
LogCore.cpp
@@ -49,30 +49,46 @@ bool ShowOutput( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short Show,
|
||||
va_list ArgPtr;
|
||||
|
||||
// Validate values
|
||||
if (!Buffer || !(Show & (OUT_NORMAL | OUT_HEX | OUT_BIN)))
|
||||
if (!Buffer || !(Show & (OUT_COUNT |OUT_NORMAL | OUT_HEX | OUT_BIN)))
|
||||
return false;
|
||||
if (Len == -1)
|
||||
Len = strlen( Buffer );
|
||||
|
||||
// Check debug level
|
||||
if (MsgLevel > DebugLevel) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get length
|
||||
if (Len == -1)
|
||||
Len = strlen( Buffer );
|
||||
|
||||
// Show Lead
|
||||
if (Format && *Format) {
|
||||
va_start( ArgPtr, Format );
|
||||
vprintf( Format, ArgPtr );
|
||||
va_end( ArgPtr );
|
||||
}
|
||||
|
||||
// Show byte count
|
||||
if (Show & OUT_COUNT)
|
||||
{
|
||||
// Print byte count
|
||||
printf( " [%d] ", Len );
|
||||
|
||||
// EOL if only count wanted
|
||||
if (Show & OUT_COUNT) {
|
||||
printf( "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
// Show Normal output
|
||||
if (Show & OUT_NORMAL) {
|
||||
if (Show & OUT_NORMAL)
|
||||
{
|
||||
if (Show & OUT_ASIS) {
|
||||
// Print entire buffer as is (line feeds included)
|
||||
printf( "%s", Buffer );
|
||||
}
|
||||
else {
|
||||
// Ignore \r\n
|
||||
for (int i=0; i<Len; i++) {
|
||||
if ((Buffer[i] < 32) || (Buffer[i] > 126)) {
|
||||
if ((Show & OUT_CRLF) && ((Buffer[i] == '\r') || (Buffer[i] == '\n')))
|
||||
@@ -85,13 +101,16 @@ bool ShowOutput( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short Show,
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add EOL if not present or ignored
|
||||
if (!(Show & (OUT_ASIS | OUT_CRLF)) || (Buffer[Len-1] != '\n')) {
|
||||
printf( "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
// Show Hex output
|
||||
if (Show & OUT_HEX) {
|
||||
if (Show & OUT_HEX)
|
||||
{
|
||||
// Print Hex values of individual bytes
|
||||
for (int i=0; i<Len; i++) {
|
||||
printf( "%02X ", (unsigned char)Buffer[i] );
|
||||
}
|
||||
@@ -100,6 +119,7 @@ bool ShowOutput( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short Show,
|
||||
|
||||
// Show Binary output
|
||||
if (Show & OUT_BIN) {
|
||||
// Print each byte as 8-bit binary
|
||||
for (int i=0; i<Len; i++) {
|
||||
for (int j=0; j<8; j++) {
|
||||
printf( "%d", (bool)((Buffer[i] << j) & 0x80) );
|
||||
|
||||
11
LogCore.h
11
LogCore.h
@@ -18,11 +18,12 @@
|
||||
|
||||
// Debug options
|
||||
const short
|
||||
OUT_NORMAL = 1,
|
||||
OUT_HEX = 2,
|
||||
OUT_BIN = 4,
|
||||
OUT_CRLF = 8,
|
||||
OUT_ASIS = 16;
|
||||
OUT_COUNT = 1,
|
||||
OUT_NORMAL = 2,
|
||||
OUT_HEX = 4,
|
||||
OUT_BIN = 8,
|
||||
OUT_CRLF = 16,
|
||||
OUT_ASIS = 32;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -851,7 +851,7 @@ bool CSelectableCore::Write( THandle * Handle )
|
||||
{
|
||||
if (Handle->OutBuffer)
|
||||
{
|
||||
// Write to FD directly from buffer
|
||||
// Write to FD directly from output buffer
|
||||
if ((BytesWritten = Handle->OutBuffer->WriteToFD( Handle->FD )))
|
||||
{
|
||||
if (DebugLevel >= dlHigh) {
|
||||
@@ -874,7 +874,7 @@ bool CSelectableCore::Write( THandle * Handle )
|
||||
}
|
||||
else
|
||||
{
|
||||
// No Output buffer, so remove from Write list
|
||||
// No Output buffer to write from, so remove from Write list
|
||||
if (Select) {
|
||||
Select->Remove( Handle->FD, false, true );
|
||||
}
|
||||
@@ -967,7 +967,7 @@ int CSelectableCore::ReadFromFD( int FD, char * Data, int MaxLen )
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
int CSelectableCore::WriteToFD( int FD, const char * Data, int Len )
|
||||
int CSelectableCore::WriteToFD( int FD, const char * Data, int Len, bool Force )
|
||||
{
|
||||
int BytesWritten = 0;
|
||||
int TotalWritten = 0;
|
||||
@@ -984,7 +984,7 @@ int CSelectableCore::WriteToFD( int FD, const char * Data, int Len )
|
||||
{
|
||||
// Read from file descriptor
|
||||
BytesWritten = write( FD, &Data[TotalWritten], DataRemain );
|
||||
if ((BytesWritten <= 0) && (errno != EAGAIN)) {
|
||||
if ((BytesWritten <= 0) && (!Force || (errno != EAGAIN))) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1050,11 +1050,11 @@ int CSelectableCore::Input( const char * IOName, const char * Data, int Len )
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write directly to handle
|
||||
BytesWritten = WriteToFD( ChildHandle->FD, Data, Len, true );
|
||||
|
||||
// Show event
|
||||
ShowOutput( DebugLevel, dlHigh, OutputDisplay, Data, Len, "%s: Handle '%s' - OUT:", Name, ChildHandle->Name );
|
||||
|
||||
// Write directly to handle
|
||||
BytesWritten = WriteToFD( ChildHandle->FD, Data, Len );
|
||||
}
|
||||
}
|
||||
// Next
|
||||
@@ -1083,7 +1083,7 @@ int CSelectableCore::Input( const char * IOName, const char * Data, int Len )
|
||||
ShowOutput( DebugLevel, dlHigh, OutputDisplay, Data, Len, "%s: Handle '%s' - OUT:", Name, Handle->Name );
|
||||
|
||||
// Write directly to handle
|
||||
BytesWritten = WriteToFD( Handle->FD, Data, Len );
|
||||
BytesWritten = WriteToFD( Handle->FD, Data, Len, true );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ protected:
|
||||
virtual bool Write( THandle * Handle );
|
||||
|
||||
int ReadFromFD( int FD, char * Data, int MaxLen );
|
||||
int WriteToFD( int FD, const char * Data, int Len );
|
||||
int WriteToFD( int FD, const char * Data, int Len, bool Force );
|
||||
|
||||
// Buffer operations
|
||||
virtual bool ProcessBuffer( THandle * Handle, bool Force );
|
||||
|
||||
Reference in New Issue
Block a user