From eaace97ec921efbf21f73f8685863b4b913ca5f8 Mon Sep 17 00:00:00 2001 From: Charl Wentzel Date: Wed, 27 Jul 2016 13:42:50 +0200 Subject: [PATCH] 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 --- BufferCore.cpp | 2 +- FunctionCore.h | 4 ++-- LogCore.cpp | 32 ++++++++++++++++++++++++++------ LogCore.h | 11 ++++++----- SelectableCore.cpp | 16 ++++++++-------- SelectableCore.h | 2 +- 6 files changed, 44 insertions(+), 23 deletions(-) diff --git a/BufferCore.cpp b/BufferCore.cpp index b3a5c5e..3f4eb68 100644 --- a/BufferCore.cpp +++ b/BufferCore.cpp @@ -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; } diff --git a/FunctionCore.h b/FunctionCore.h index a70f388..6c0b1b2 100644 --- a/FunctionCore.h +++ b/FunctionCore.h @@ -68,8 +68,8 @@ protected: return LocalIO; } - // Low Level Local IO interfaces - virtual int Output( const TLocalIO * LocalIO, const char * Data, int Len ); + // Manual Data Input/Output + virtual int Output( const TLocalIO * LocalIO, const char * Data, int Len ); public: // Life cycle diff --git a/LogCore.cpp b/LogCore.cpp index 5794ec1..f996f3b 100644 --- a/LogCore.cpp +++ b/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 ); } - printf( "[%d] ", Len ); + + // 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 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; iOutBuffer) { - // 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 ); } } diff --git a/SelectableCore.h b/SelectableCore.h index 48b5a03..de66662 100644 --- a/SelectableCore.h +++ b/SelectableCore.h @@ -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 );