CharBufferCore:
- Bug fix - FindStr() for input marker not matching correctly
SeletableBare/Core:
- Reformat code - eliminate & compact {} where needed
This commit is contained in:
@@ -266,10 +266,10 @@ int CRollingBuffer::PeekCopy( char ** Data, int PeekPos, int MaxLen )
|
||||
// Look for first occurrence of character in buffer
|
||||
bool CRollingBuffer::FindStr( const char * SearchStr, int SearchLen, int &FoundPos, int StartPos )
|
||||
{
|
||||
char * CheckPos = NULL;
|
||||
char * CheckLimit = NULL;
|
||||
char * MatchPos = NULL;
|
||||
char * MatchLimit = NULL;
|
||||
const char * CheckPos = NULL;
|
||||
const char * CheckLimit = NULL;
|
||||
const char * MatchPos = NULL;
|
||||
const char * MatchLimit = NULL;
|
||||
|
||||
// Check if buffer exists
|
||||
if (!BufSize || !SearchStr || !SearchLen) {
|
||||
@@ -288,8 +288,8 @@ bool CRollingBuffer::FindStr( const char * SearchStr, int SearchLen, int &FoundP
|
||||
CheckLimit = &Buffer[BufSize-1];
|
||||
|
||||
// Set Match start point and limit
|
||||
MatchPos = (char*)SearchStr;
|
||||
MatchLimit = (char*)&SearchStr[SearchLen-1];
|
||||
MatchPos = SearchStr;
|
||||
MatchLimit = &SearchStr[SearchLen-1];
|
||||
|
||||
// Search for char
|
||||
FoundPos = StartPos;
|
||||
@@ -307,9 +307,10 @@ bool CRollingBuffer::FindStr( const char * SearchStr, int SearchLen, int &FoundP
|
||||
MatchPos++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else if (MatchPos != SearchStr){
|
||||
// Reset match point
|
||||
MatchPos = (char*)SearchStr;
|
||||
FoundPos -= MatchPos - SearchStr;
|
||||
MatchPos = SearchStr;
|
||||
}
|
||||
|
||||
// Next char
|
||||
|
||||
@@ -46,12 +46,10 @@ CSelectableBare::~CSelectableBare()
|
||||
THandle * NextHandle = NULL;
|
||||
|
||||
// Destroy File Handles
|
||||
while (FirstHandle)
|
||||
{
|
||||
while (FirstHandle) {
|
||||
// Close handle if open
|
||||
if ((FirstHandle->State == csOpen) || (FirstHandle->State == csWaitingtoOpen)) {
|
||||
if ((FirstHandle->State == csOpen) || (FirstHandle->State == csWaitingtoOpen))
|
||||
Close( FirstHandle, false );
|
||||
}
|
||||
|
||||
NextHandle = FirstHandle->Next;
|
||||
DestroyHandle( FirstHandle );
|
||||
@@ -82,8 +80,7 @@ THandle * CSelectableBare::CreateHandle( const char * HandleName, bool CreateCh
|
||||
Handle = &((*Handle)->Next);
|
||||
|
||||
// Create if necessary
|
||||
if (!*Handle)
|
||||
{
|
||||
if (!*Handle) {
|
||||
// Create File handle at end of list
|
||||
*Handle = new THandle;
|
||||
|
||||
@@ -103,9 +100,8 @@ THandle * CSelectableBare::CreateHandle( const char * HandleName, bool CreateCh
|
||||
}
|
||||
|
||||
// Create Matching Channel
|
||||
if (CreateChannel) {
|
||||
if (CreateChannel)
|
||||
(*Handle)->Channel = AddChannel( HandleName, CH_off );
|
||||
}
|
||||
|
||||
return *Handle;
|
||||
}
|
||||
@@ -116,19 +112,17 @@ bool CSelectableBare::RemoveHandle( THandle * Handle )
|
||||
THandle ** HandlePtr = NULL;
|
||||
|
||||
// Validate
|
||||
if (!Handle || (Handle->State == csOpen) || (Handle->State == csWaitingtoOpen)) {
|
||||
if (!Handle || (Handle->State == csOpen) || (Handle->State == csWaitingtoOpen))
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find in List
|
||||
HandlePtr = &FirstHandle;
|
||||
while (*HandlePtr && (*HandlePtr != Handle)) {
|
||||
while (*HandlePtr && (*HandlePtr != Handle))
|
||||
HandlePtr = &((*HandlePtr)->Next);
|
||||
}
|
||||
|
||||
// Remove from list if found
|
||||
if (*HandlePtr) {
|
||||
if (*HandlePtr)
|
||||
*HandlePtr = (*HandlePtr)->Next;
|
||||
}
|
||||
|
||||
// Log event
|
||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Handle '%s' - Removed",
|
||||
@@ -193,9 +187,8 @@ bool CSelectableBare::HandleState( THandle * Handle, EConnectState State )
|
||||
bool CSelectableBare::SetCallback( THandle * Handle, EConnectState pState, FHandleCallback pCallback )
|
||||
{
|
||||
// Validate
|
||||
if (!Handle) {
|
||||
if (!Handle)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set callback
|
||||
Handle->StateCallback[ (int)pState ] = pCallback;
|
||||
@@ -206,9 +199,8 @@ bool CSelectableBare::SetCallback( THandle * Handle, EConnectState pState, FHand
|
||||
bool CSelectableBare::SetAutoManage( THandle * Handle, bool AutoManage, bool Persistent, int ReopenDelay, int CloseTimeout )
|
||||
{
|
||||
// Validate
|
||||
if (!Handle) {
|
||||
if (!Handle)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set params
|
||||
Handle->AutoManage = AutoManage;
|
||||
@@ -222,18 +214,16 @@ bool CSelectableBare::SetAutoManage( THandle * Handle, bool AutoManage, bool Per
|
||||
bool CSelectableBare::SetInBuffer( THandle * Handle, int InBufSize, int InTimeout, const char * InMarker, int InMarkerLen )
|
||||
{
|
||||
// Validate
|
||||
if (!Handle) {
|
||||
if (!Handle)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Input Buffer
|
||||
if (Handle->InBuffer) {
|
||||
delete Handle->InBuffer;
|
||||
Handle->InBuffer = NULL;
|
||||
}
|
||||
if (InBufSize) {
|
||||
if (InBufSize)
|
||||
Handle->InBuffer = (CRollingBuffer*) new CRollingBuffer( InBufSize );
|
||||
}
|
||||
|
||||
// Set Input Timeout
|
||||
Handle->InTimeout = InTimeout;
|
||||
@@ -253,18 +243,16 @@ bool CSelectableBare::SetInBuffer( THandle * Handle, int InBufSize, int InTimeou
|
||||
bool CSelectableBare::SetOutBuffer( THandle * Handle, int OutBufSize )
|
||||
{
|
||||
// Validate
|
||||
if (!Handle) {
|
||||
if (!Handle)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Output Buffer
|
||||
if (Handle->OutBuffer) {
|
||||
delete Handle->OutBuffer;
|
||||
Handle->OutBuffer = NULL;
|
||||
}
|
||||
if (OutBufSize) {
|
||||
if (OutBufSize)
|
||||
Handle->OutBuffer = (CRollingBuffer*) new CRollingBuffer( OutBufSize );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -277,44 +265,38 @@ bool CSelectableBare::ProcessInputBuffer( THandle * Handle, bool Force )
|
||||
char * Data = NULL;
|
||||
|
||||
// Check if buffered data
|
||||
if (!Handle || !Handle->InBuffer || !Handle->InBuffer->Len()) {
|
||||
if (!Handle || !Handle->InBuffer || !Handle->InBuffer->Len())
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if forced processed
|
||||
if (Force || (!Handle->InTimeout && !Handle->InMarkerLen))
|
||||
{
|
||||
if (Force || (!Handle->InTimeout && !Handle->InMarkerLen)) {
|
||||
// Show Packet
|
||||
Len = Handle->InBuffer->Peek( &Data );
|
||||
if (Log) Log->Output( LogLevel, dlHigh, LogOutput, Data, Len, "%s/%s: Handle '%s' - IN-T:",
|
||||
ProcessName, Name, Handle->Name );
|
||||
|
||||
// Write buffer to Outputs
|
||||
if ((Handle->Type == ctTCPremote) || (Handle->Type == ctUNIXremote)) {
|
||||
if ((Handle->Type == ctTCPremote) || (Handle->Type == ctUNIXremote))
|
||||
Output( Handle->Parent->Channel, NULL, true, Data, Len );
|
||||
} else {
|
||||
else
|
||||
Output( Handle->Channel, NULL, true, Data, Len );
|
||||
}
|
||||
|
||||
// Clear processed bytes from buffer
|
||||
Handle->InBuffer->Clear( Len );
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
// Search for end of packet marker
|
||||
while (Handle->InBuffer->FindStr( Handle->InMarker, Handle->InMarkerLen, Pos ))
|
||||
{
|
||||
while (Handle->InBuffer->FindStr( Handle->InMarker, Handle->InMarkerLen, Pos )) {
|
||||
// Show Packet
|
||||
Len = Handle->InBuffer->Peek( &Data, 0, Pos+Handle->InMarkerLen );
|
||||
if (Log) Log->Output( LogLevel, dlHigh, LogOutput, Data, Len, "%s/%s: Handle '%s' - IN-M:",
|
||||
ProcessName, Name, Handle->Name );
|
||||
|
||||
// Write buffer to Outputs
|
||||
if ((Handle->Type == ctTCPremote) || (Handle->Type == ctUNIXremote)) {
|
||||
if ((Handle->Type == ctTCPremote) || (Handle->Type == ctUNIXremote))
|
||||
Output( Handle->Parent->Channel, NULL, true, Data, Len );
|
||||
} else {
|
||||
else
|
||||
Output( Handle->Channel, NULL, true, Data, Len );
|
||||
}
|
||||
|
||||
// Clear processed bytes from buffer
|
||||
Handle->InBuffer->Clear( Len );
|
||||
@@ -330,15 +312,13 @@ int CSelectableBare::Open( THandle * Handle )
|
||||
|
||||
|
||||
// Validate
|
||||
if (!Handle || (Handle->Type == ctNone)) {
|
||||
if (!Handle || (Handle->Type == ctNone))
|
||||
return -1;
|
||||
} else if (Handle->State == csOpen) {
|
||||
else if (Handle->State == csOpen)
|
||||
return Handle->FD;
|
||||
}
|
||||
|
||||
// Check if port exits
|
||||
if (access( Handle->Path, F_OK ) != 0)
|
||||
{
|
||||
if (access( Handle->Path, F_OK ) != 0) {
|
||||
// Log event
|
||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Handle '%s' - Path not found [%s]",
|
||||
ProcessName, Name, Handle->Name, Handle->Path );
|
||||
@@ -347,8 +327,7 @@ int CSelectableBare::Open( THandle * Handle )
|
||||
|
||||
// Open Port
|
||||
Handle->FD = open( Handle->Path, O_RDWR );
|
||||
if (Handle->FD == -1)
|
||||
{
|
||||
if (Handle->FD == -1) {
|
||||
// Log event
|
||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Handle '%s' - Could not open Path [%s]",
|
||||
ProcessName, Name, Handle->Name, Handle->Path );
|
||||
@@ -360,9 +339,8 @@ int CSelectableBare::Open( THandle * Handle )
|
||||
ProcessName, Name, Handle->Name, Handle->Path );
|
||||
|
||||
// Add to Select Lists
|
||||
if (Selector) {
|
||||
if (Selector)
|
||||
Selector->Add( Handle->FD, true, false, Handle, this );
|
||||
}
|
||||
|
||||
// Set timer (for re-open or auto-close)
|
||||
SetStartTime( &Handle->LastAction );
|
||||
@@ -387,9 +365,8 @@ bool CSelectableBare::Close( THandle * Handle, bool QuickReopen )
|
||||
|
||||
// Remove from Select List
|
||||
if (!Fail && Selector) {
|
||||
if (Handle->Type != ctUDPremote) {
|
||||
if (Handle->Type != ctUDPremote)
|
||||
Selector->Remove( Handle->FD, true, true );
|
||||
}
|
||||
}
|
||||
|
||||
// Reset FD
|
||||
@@ -418,17 +395,15 @@ bool CSelectableBare::Read( THandle * Handle )
|
||||
int BytesWaiting = -1;
|
||||
|
||||
// Validate
|
||||
if (!Handle || (Handle->State == csNone) || (Handle->State == csFailed) || (Handle->State == csClosed)) {
|
||||
if (!Handle || (Handle->State == csNone) || (Handle->State == csFailed) || (Handle->State == csClosed))
|
||||
return false;
|
||||
}
|
||||
|
||||
// Log Read Event
|
||||
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: Handle '%s' - Read Event",
|
||||
ProcessName, Name, Handle->Name );
|
||||
|
||||
// Check if socket ready (non-block open in progress)
|
||||
if (Handle->State == csWaitingtoOpen)
|
||||
{
|
||||
if (Handle->State == csWaitingtoOpen) {
|
||||
Open( Handle );
|
||||
|
||||
// Reset Timer (for auto-close)
|
||||
@@ -440,8 +415,7 @@ bool CSelectableBare::Read( THandle * Handle )
|
||||
ioctl( Handle->FD, FIONREAD, &BytesWaiting );
|
||||
|
||||
// Error on port
|
||||
if (BytesWaiting < 0)
|
||||
{
|
||||
if (BytesWaiting < 0) {
|
||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Handle '%s' - Data waiting error (%s)",
|
||||
ProcessName, Name, Handle->Name, strerror(errno) );
|
||||
|
||||
@@ -451,13 +425,11 @@ bool CSelectableBare::Read( THandle * Handle )
|
||||
}
|
||||
|
||||
// Validate
|
||||
if (Handle->State != csOpen) {
|
||||
if (Handle->State != csOpen)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read File directly into buffer
|
||||
if (Handle->InBuffer)
|
||||
{
|
||||
if (Handle->InBuffer) {
|
||||
errno = 0;
|
||||
BytesRead = Handle->InBuffer->ReadFromFD( Handle->FD, BytesWaiting );
|
||||
|
||||
@@ -471,10 +443,9 @@ bool CSelectableBare::Read( THandle * Handle )
|
||||
ProcessName, Name, Handle->Name, BytesRead, BytesWaiting );
|
||||
}
|
||||
|
||||
if (BytesRead != 0) {
|
||||
// Process Buffer
|
||||
// Process Buffer
|
||||
if (BytesRead != 0)
|
||||
ProcessInputBuffer( Handle, false );
|
||||
}
|
||||
}
|
||||
|
||||
// Reset timer
|
||||
@@ -495,16 +466,13 @@ bool CSelectableBare::Write( THandle * Handle )
|
||||
return false;
|
||||
|
||||
// Is Handle open?
|
||||
if ((Handle->State == csNone) || (Handle->State == csFailed) || (Handle->State == csClosed))
|
||||
{
|
||||
if ((Handle->State == csNone) || (Handle->State == csFailed) || (Handle->State == csClosed)) {
|
||||
// May it be opened?
|
||||
if (!Handle->AutoManage)
|
||||
{
|
||||
if (!Handle->AutoManage) {
|
||||
// Must be opened manually
|
||||
return false;
|
||||
}
|
||||
else if (Timeout( Handle->LastAction, Handle->ReopenDelay ))
|
||||
{
|
||||
else if (Timeout( Handle->LastAction, Handle->ReopenDelay )) {
|
||||
// Attempt to re-open port
|
||||
Open( Handle );
|
||||
}
|
||||
@@ -514,8 +482,7 @@ bool CSelectableBare::Write( THandle * Handle )
|
||||
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: Handle '%s' - Write Event",
|
||||
ProcessName, Name, Handle->Name );
|
||||
|
||||
if (Handle->State == csWaitingtoOpen)
|
||||
{
|
||||
if (Handle->State == csWaitingtoOpen) {
|
||||
// Complete socket open process
|
||||
Open( Handle );
|
||||
|
||||
@@ -523,15 +490,12 @@ bool CSelectableBare::Write( THandle * Handle )
|
||||
SetStartTime( &(Handle->LastAction) );
|
||||
|
||||
// Remove from set for select write
|
||||
if (Selector) {
|
||||
if (Selector)
|
||||
Selector->Remove( Handle->FD, false, true );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (Handle->State == csOpen)
|
||||
{
|
||||
if (Handle->OutBuffer)
|
||||
{
|
||||
else if (Handle->State == csOpen) {
|
||||
if (Handle->OutBuffer) {
|
||||
// Write directly to handle / socket
|
||||
errno = 0;
|
||||
BytesWritten = Handle->OutBuffer->WriteToFD( Handle->FD );
|
||||
@@ -549,29 +513,25 @@ bool CSelectableBare::Write( THandle * Handle )
|
||||
ProcessName, Name, Handle->Name, BytesWritten, Len );
|
||||
}
|
||||
|
||||
if (BytesWritten != 0)
|
||||
{
|
||||
if (BytesWritten != 0) {
|
||||
// Update Buffer
|
||||
Handle->OutBuffer->Clear( (BytesWritten > 0)? BytesWritten : -BytesWritten ); // negative value reported if error occurred
|
||||
|
||||
// Check if Buffer empty
|
||||
if (!Handle->OutBuffer->Len()) {
|
||||
// Remove from Select Write list
|
||||
if (Selector) {
|
||||
if (Selector)
|
||||
Selector->Remove( Handle->FD, false, true );
|
||||
}
|
||||
}
|
||||
|
||||
// Reset timeout
|
||||
SetStartTime( &(Handle->LastAction) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
// No Output buffer to write from, so remove from Write list
|
||||
if (Selector) {
|
||||
if (Selector)
|
||||
Selector->Remove( Handle->FD, false, true );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -588,13 +548,11 @@ int CSelectableBare::ReadFromFD( int FD, char * Data, int MaxLen )
|
||||
bool Error = false;
|
||||
|
||||
// Check if buffer created
|
||||
if ((FD == -1) || (MaxLen < 1)) {
|
||||
if ((FD == -1) || (MaxLen < 1))
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Read Data into buffer
|
||||
while (DataRemain)
|
||||
{
|
||||
while (DataRemain) {
|
||||
// Read from file descriptor
|
||||
BytesRead = read( FD, &Data[TotalRead], DataRemain );
|
||||
if ((BytesRead < 0)) {
|
||||
@@ -607,9 +565,8 @@ int CSelectableBare::ReadFromFD( int FD, char * Data, int MaxLen )
|
||||
TotalRead += BytesRead;
|
||||
DataRemain -= BytesRead;
|
||||
|
||||
if (DataRemain) {
|
||||
if (DataRemain)
|
||||
usleep( 500 );
|
||||
}
|
||||
}
|
||||
return (Error)? -TotalRead : TotalRead; // Report negative total on error
|
||||
}
|
||||
@@ -623,13 +580,11 @@ int CSelectableBare::WriteToFD( int FD, const char * Data, int Len, bool Force )
|
||||
bool Error = false;
|
||||
|
||||
// Check if buffer created
|
||||
if ((FD == -1) || !DataRemain) {
|
||||
if ((FD == -1) || !DataRemain)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Read Data into buffer
|
||||
while (DataRemain)
|
||||
{
|
||||
while (DataRemain) {
|
||||
// Read from file descriptor
|
||||
BytesWritten = write( FD, &Data[TotalWritten], DataRemain );
|
||||
if ((BytesWritten <= 0) && (!Force || (errno != EAGAIN))) {
|
||||
@@ -642,9 +597,8 @@ int CSelectableBare::WriteToFD( int FD, const char * Data, int Len, bool Force )
|
||||
TotalWritten += BytesWritten;
|
||||
DataRemain -= BytesWritten;
|
||||
|
||||
if (DataRemain) {
|
||||
if (DataRemain)
|
||||
usleep( 500 );
|
||||
}
|
||||
}
|
||||
return (Error)? -TotalWritten : TotalWritten; // Report negative total on error
|
||||
}
|
||||
@@ -659,9 +613,8 @@ int CSelectableBare::Input( const char * ChannelName, const char * SourceRef, co
|
||||
int BytesWritten = 0;
|
||||
|
||||
// Validate
|
||||
if (!ChannelName || !Data) {
|
||||
if (!ChannelName || !Data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get Channel
|
||||
if (!(Channel = GetChannel( ChannelName ))) {
|
||||
@@ -683,10 +636,8 @@ int CSelectableBare::Input( const char * ChannelName, const char * SourceRef, co
|
||||
|
||||
// Find Linked handle
|
||||
Handle = FirstHandle;
|
||||
while( Handle )
|
||||
{
|
||||
if (Handle->Channel && !strcasecmp( ChannelName, Handle->Channel->Name ))
|
||||
{
|
||||
while( Handle ) {
|
||||
if (Handle->Channel && !strcasecmp( ChannelName, Handle->Channel->Name )) {
|
||||
// Input to Handle
|
||||
TempWritten = OutputHandle( Handle, Data, Len );
|
||||
BytesWritten = (TempWritten > BytesWritten)? TempWritten : BytesWritten;
|
||||
@@ -711,18 +662,15 @@ int CSelectableBare::OutputHandle( THandle * Handle, const char * Data, int Len
|
||||
int BytesWritten = 0;
|
||||
int DataLen = (Len != -1)? Len : (Data)? strlen(Data) : 0;
|
||||
|
||||
if ((Handle->State != csOpen))
|
||||
{
|
||||
if ((Handle->State != csOpen)) {
|
||||
// Check if auto-managed handle
|
||||
if (!Handle->AutoManage)
|
||||
{
|
||||
if (!Handle->AutoManage) {
|
||||
// Handle is not open or auto-managed
|
||||
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: Handle '%s' - Input rejected, Handle not Open (not auto-managed)",
|
||||
ProcessName, Name, Handle->Name );
|
||||
return 0;
|
||||
}
|
||||
else if (Timeout( Handle->LastAction, Handle->ReopenDelay ))
|
||||
{
|
||||
else if (Timeout( Handle->LastAction, Handle->ReopenDelay )) {
|
||||
// Complete opening process
|
||||
Open( Handle );
|
||||
|
||||
@@ -743,8 +691,7 @@ int CSelectableBare::OutputHandle( THandle * Handle, const char * Data, int Len
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: Handle '%s' - Input rejected, Retry (auto-managed) Handle re-open in %d ms",
|
||||
ProcessName, Name, Handle->Name, TimeLeft( Handle->LastAction, Handle->ReopenDelay) );
|
||||
return 0;
|
||||
@@ -752,23 +699,19 @@ int CSelectableBare::OutputHandle( THandle * Handle, const char * Data, int Len
|
||||
}
|
||||
|
||||
// Check packet length
|
||||
if (Len == -1) {
|
||||
if (Len == -1)
|
||||
Len = strlen( Data );
|
||||
}
|
||||
|
||||
// Decide where to put data
|
||||
if (Handle->OutBuffer)
|
||||
{
|
||||
if (Handle->OutBuffer) {
|
||||
// Write to buffer
|
||||
BytesWritten = Handle->OutBuffer->Push( true, Data, Len );
|
||||
|
||||
// Add to select write list
|
||||
if (BytesWritten && Selector) {
|
||||
if (BytesWritten && Selector)
|
||||
Selector->Add( Handle->FD, false, true, Handle, this );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
// Write directly to handle / socket
|
||||
errno = 0;
|
||||
BytesWritten = WriteToFD( Handle->FD, Data, Len, true );
|
||||
@@ -786,10 +729,9 @@ int CSelectableBare::OutputHandle( THandle * Handle, const char * Data, int Len
|
||||
ProcessName, Name, Handle->Name, BytesWritten, DataLen );
|
||||
}
|
||||
|
||||
if (BytesWritten != 0) {
|
||||
// Reset timeout
|
||||
// Reset timeout
|
||||
if (BytesWritten != 0)
|
||||
SetStartTime( &(Handle->LastAction) );
|
||||
}
|
||||
}
|
||||
|
||||
return BytesWritten;
|
||||
@@ -802,8 +744,7 @@ bool CSelectableBare::Process()
|
||||
|
||||
// Check all handles
|
||||
Handle = FirstHandle;
|
||||
while (Handle)
|
||||
{
|
||||
while (Handle) {
|
||||
// Auto manage handles
|
||||
if (Handle->State == csPrepared) {
|
||||
// Proceed to open
|
||||
@@ -811,9 +752,8 @@ bool CSelectableBare::Process()
|
||||
}
|
||||
else if ((Handle->State != csOpen) && Handle->AutoManage && Handle->Persistent) {
|
||||
// Try to re-open port after delay
|
||||
if (Timeout( Handle->LastAction, Handle->ReopenDelay )) {
|
||||
if (Timeout( Handle->LastAction, Handle->ReopenDelay ))
|
||||
Open( Handle );
|
||||
}
|
||||
}
|
||||
else if (Handle->Channel && (Handle->Channel->InState == CH_off) && Handle->AutoManage) {
|
||||
// Set channel to standby
|
||||
@@ -835,9 +775,8 @@ bool CSelectableBare::Process()
|
||||
// Check for auto close (but not on servers)
|
||||
if ((Handle->State == csOpen) && Handle->AutoManage && !Handle->Persistent) {
|
||||
// Close port after timeout
|
||||
if (Timeout( Handle->LastAction, Handle->CloseTimeout )) {
|
||||
if (Timeout( Handle->LastAction, Handle->CloseTimeout ))
|
||||
Close( Handle, true );
|
||||
}
|
||||
}
|
||||
Handle = Handle->Next;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user