Important Update:

- Converted Select functions into new class CSelectCore
- Move Read/Write code from main() to SelectableCore Read()/Write()
- Pass CSelectCore object to CSelectableCore on create
- Updated SelectCore Read/Write lists directly from SelectableCore
- SelectCore->Test() checks all FDs directly and call Read/Write functions
- Improved checking/validating for methods in SelectableCore
This commit is contained in:
Charl Wentzel
2016-05-24 15:02:51 +02:00
parent dcfbd85efa
commit e83c09ecb6
4 changed files with 361 additions and 113 deletions

View File

@@ -38,16 +38,32 @@ const char ConnectStateName[][15] = { "None", "WaitingToOpen", "Open", "DataWait
//---------------------------------------------------------------------------
void SelectConfig( long Timeout );
void SelectClear();
void SelectAdd( int FD, bool Read, bool Write );
void SelectRemove( int FD, bool Read, bool Write );
bool SelectTest();
bool SelectCheck( int FD, bool &Read, bool &Write );
// Previews
typedef struct SSelectHandle TSelectHandle;
typedef struct SHandle THandle;
class CSelect;
class CSelectableCore;
//---------------------------------------------------------------------------
typedef struct SHandle THandle;
// List of Handles for Select Object
struct SSelectHandle {
// File Descriptor
int FD;
bool Read;
bool Write;
// Event Object
CSelectableCore * Function;
// List
TSelectHandle * Next;
};
//---------------------------------------------------------------------------
// List or Handles for Selectable Function Object
struct SHandle {
// Description
char * Name;
@@ -74,18 +90,56 @@ struct SHandle {
timeval InStart;
long InTimeout; // millisecs
// List / Tree
THandle * Parent;
THandle * Next;
};
//---------------------------------------------------------------------------
class CSelect
{
protected:
// List
TSelectHandle * FirstHandle;
// Select Variables
fd_set ReadTestFDS;
fd_set WriteTestFDS;
fd_set ReadFDS;
fd_set WriteFDS;
// Configuration
int MaxFD;
timeval Timeout;
public:
// Life Cycle
CSelect( long SelectTimeout );
~CSelect();
// Manage FDs
void Clear();
void Add( int FD, bool Read, bool Write, CSelectableCore * Function = NULL);
void Remove( int FD, bool Read, bool Write );
// Testing FDs
bool Test();
bool Check( int FD, bool &Read, bool &Write );
};
//---------------------------------------------------------------------------
class CSelectableCore : public CFunctionCore
{
protected:
// Device Interfaces
// FDs
THandle * FirstHandle;
// Select interface
CSelect * Select;
// Managing File Handles
bool RemoveHandle( THandle * Handle );
bool DestroyHandle( THandle * Handle );
@@ -113,7 +167,7 @@ protected:
// Socket Operations
virtual int OpenServerSocket( THandle * Handle );
//virtual int OpenRemoteClientSocket( THandle * Handle );
virtual int OpenRemoteClientSocket( THandle * Handle );
virtual int OpenClientSocket( THandle * Handle );
// Mutual Operations
@@ -121,6 +175,7 @@ protected:
virtual bool Read( THandle * Handle );
virtual bool Write( THandle * Handle );
int ReadFromFD( int FD, char * Data, int MaxLen );
int WriteToFD( int FD, const char * Data, int Len );
// Buffer operations
@@ -128,7 +183,7 @@ protected:
public:
// Life Cycle
CSelectableCore( const char * Name );
CSelectableCore( const char * Name, CSelect * Selector );
~CSelectableCore();
// Configuration
@@ -142,7 +197,6 @@ public:
bool ClearHandle( const char * HandleName );
virtual int Open( const char * HandleName );
virtual int OpenRemoteClientSocket( THandle * Handle );
virtual bool Close( const char * HandleName, bool CloseChildren = false ) { return (Close( GetHandle( HandleName ), CloseChildren )); };
virtual bool Close( int FD, bool CloseChildren = false ) { return (Close( GetHandle( FD ), CloseChildren )); };