Important Update:

- Add Resolve Delay, allow time delay before resolving address
  Allow completion of other actions before blocking all to getaddr()
- Remove Handle->KeepAlive, assume always true
This commit is contained in:
Charl Wentzel
2017-12-10 21:39:55 +02:00
parent 75dec370f7
commit 4ec1dc6cd7
2 changed files with 82 additions and 56 deletions

View File

@@ -20,8 +20,8 @@
typedef enum { ctNone = 0, ctSerial = 1, ctLinePrinter = 2, ctServer = 3, ctRemoteClient = 4, ctClient = 5, ctForkPipe = 6 } EConnectType;
const char ConnectTypeName[][15] = { "None", "Port", "ForkPipe", "Server", "RemoteClient", "Client" };
typedef enum { csNone = 0, csWaitingtoOpen = 1, csOpen = 2, csDataWaiting = 3, csClosed = 4, csFailed = 5 } EConnectState;
const char ConnectStateName[][15] = { "None", "WaitingToOpen", "Open", "DataWaiting", "Closed", "Failed" };
typedef enum { csNone = 0, csOpenRequest = 1, csWaitingtoOpen = 2, csOpen = 3, csDataWaiting = 4, csClosed = 5, csFailed = 6 } EConnectState;
const char ConnectStateName[][15] = { "None", "OpenRequest", "WaitingToOpen", "Open", "DataWaiting", "Closed", "Failed" };
//---------------------------------------------------------------------------
@@ -79,8 +79,8 @@ struct SHandle {
bool AutoManage;
bool Persistent;
timeval LastAction;
long ReopenDelay; // millisecs
long CloseTimeout; // millisecs
long ReopenDelay; // millisecs before trying to re-open socket
long CloseTimeout; // millisecs of no traffic before closing socket
// Callback functions
FHandleCallback StateCallback[ 6 ];
@@ -88,15 +88,18 @@ struct SHandle {
// Type specific parameters
char * Path; // Port (file)name or Exec path
// Fork config
pid_t ChildPID; // Forked child PID
// Socket config
char * HostName; // Host name or IP adddress
char * PortName; // Socket port no or protocol, e.g. "80" or "HTTP"
struct addrinfo * AddressList; // List of resolved IP Addresses for host name
struct addrinfo * AddressInfo; // Current selected IP Address
bool AddressFailed; // Indicate failure to connect to address
bool KeepAlive; // Socket keep alive
long ResolveDelay; // Delay before resolving hostname via DNS
// Serial Port config
bool SerialConfig;
int InBaudrate;
int OutBaudrate;
@@ -209,10 +212,10 @@ protected:
int OpenForkPipe( THandle * Handle );
// Socket Operations
bool ResolveAddress( THandle * Handle );
int OpenServerSocket( THandle * Handle );
bool ResolveAddress( THandle * Handle, bool DelayResolve );
int OpenServerSocket( THandle * Handle, bool DelayResolve );
int OpenRemoteClientSocket( THandle * Handle );
int OpenClientSocket( THandle * Handle );
int OpenClientSocket( THandle * Handle, bool DelayResolve );
// Mutual Operations
int ReadFromFD( int FD, char * Data, int MaxLen );
@@ -266,17 +269,17 @@ public:
bool SetSerialHandleConfig( THandle * Handle, int Baudrate, short DataBits, short Parity, short StopBits, short FlowCtrl, int DataWait );
bool SetLinePrinterHandle( THandle * Handle, const char * FileName );
bool SetForkPipeHandle( THandle * Handle, const char * ExecPath );
bool SetSocketHandle( THandle * Handle, EConnectType Type, const char * HostName, const char * PortName, bool KeepAlive );
bool SetSocketHandle( THandle * Handle, EConnectType Type, const char * HostName, const char * PortName, long ResolveDelay );
bool ClearHandle( THandle * Handle );
// FD Operations
virtual int Open( THandle * Handle );
virtual int Open( THandle * Handle, bool DelayResolve = false );
virtual bool Close( THandle * Handle, bool QuickReopen );
virtual bool Read( THandle * Handle );
virtual bool Write( THandle * Handle );
// FD operations
inline virtual int Open( const char * HandleName ) { return (Open( GetHandle( HandleName ))); };
inline virtual int Open( const char * HandleName, bool DelayResolve = false ) { return (Open( GetHandle( HandleName ), DelayResolve)); };
inline virtual bool Close( const char * HandleName, bool QuickReopen ) { return (Close( GetHandle( HandleName ), QuickReopen )); };
inline virtual bool Close( int FD, bool QuickReopen ) { return (Close( GetHandle( FD ), QuickReopen )); };