Important Update:

- Implement Handle Address renaming:
- Restructure JSON config, with address list and rename list
- SelectableCore:
  - Add method GetHandleAddress() - lookup renamed handle
  - Add init values to all struct and classes declarations
- Replace malloc()/strcpy() sequences with strdup()
This commit is contained in:
Charl Wentzel
2019-01-08 08:35:21 +02:00
parent c5da842ac1
commit 3e40f7a86d
7 changed files with 128 additions and 232 deletions

View File

@@ -55,16 +55,16 @@ typedef void (*FHandleCallback)( CSelectableCore * Function, THandle * Handle, E
// List of Handles for Select Object
struct SSelectHandle {
// File Descriptor
int FD;
bool Read;
bool Write;
int FD = -1;
bool Read = false;
bool Write = false;
// Event Object
THandle * Handle;
CSelectableCore * Function;
THandle * Handle = NULL;
CSelectableCore * Function = NULL;
// List
TSelectHandle * Next;
TSelectHandle * Next = NULL;
};
//---------------------------------------------------------------------------
@@ -72,63 +72,63 @@ struct SSelectHandle {
// List or Handles for Selectable Function Object
struct SHandle {
// Description
char * Name;
EConnectType Type;
char * Name = NULL;
EConnectType Type = ctNone;
// State
int FD;
EConnectState State;
int FD = -1;
EConnectState State = csNone;
bool AutoManage;
bool Persistent;
timeval LastAction;
long ReopenDelay; // millisecs before trying to re-open socket
long CloseTimeout; // millisecs of no traffic before closing socket
bool AutoManage = false;
bool Persistent = false;
timeval LastAction = {0,0};
long ReopenDelay = 1000; // millisecs before trying to re-open socket
long CloseTimeout = 1000; // millisecs of no traffic before closing socket
// Callback functions
FHandleCallback StateCallback[ 7 ];
FHandleCallback StateCallback[ 7 ] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
// Type specific parameters
char * Path; // Port (file)name or Exec path
char * Path = NULL; // 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
short Queue; // Max waiting connections
long ResolveDelay; // Delay before resolving hostname via DNS
char * HostName = NULL; // Host name or IP adddress
char * PortName = NULL; // Socket port no or protocol, e.g. "80" or "HTTP"
struct addrinfo * AddressList = NULL; // List of resolved IP Addresses for host name
struct addrinfo * AddressInfo = NULL; // Current selected IP Address
bool AddressFailed = false; // Indicate failure to connect to address
short Queue = 2; // Max waiting connections
long ResolveDelay = 0; // Delay before resolving hostname via DNS
// Serial Port config
bool SerialConfig;
int InBaudrate;
int OutBaudrate;
short DataBits;
short Parity;
short StopBits;
short FlowCtrl;
int DataWait;
bool SerialConfig = false;
int InBaudrate = 0;
int OutBaudrate = 0;
short DataBits = 0;
short Parity = NO_PARITY;
short StopBits = 0;
short FlowCtrl = NO_FLOWCTRL;
int DataWait = 0;
// Buffers
CRollingBuffer * InBuffer;
CRollingBuffer * OutBuffer;
CRollingBuffer * InBuffer = NULL;
CRollingBuffer * OutBuffer = NULL;
// Input Markers
char * InMarker;
int InMarkerLen;
char * InMarker = NULL;
int InMarkerLen = 0;
// Input Timer
timeval InStart;
long InTimeout; // millisecs
timeval InStart = {0,0};
long InTimeout = 0; // millisecs
// List / Tree
TChannel * Channel;
THandle * Parent;
THandle * Next;
TChannel * Channel = NULL;
THandle * Parent = NULL;
THandle * Next = NULL;
};
//---------------------------------------------------------------------------
@@ -137,7 +137,7 @@ class CSelect
{
protected:
// List
TSelectHandle * FirstHandle;
TSelectHandle * FirstHandle = NULL;
// Select Variables
fd_set ReadTestFDS;
@@ -147,12 +147,12 @@ protected:
fd_set WriteFDS;
// Configuration
int MaxFD;
timeval Timeout;
int MaxFD = 0;
timeval Timeout = {0,0};
// Output
CLogCore * Log;
EDebugLevel LogLevel;
CLogCore * Log = NULL;
EDebugLevel LogLevel = dlNone;
public:
// Life Cycle
@@ -184,10 +184,10 @@ class CSelectableCore : public CFunctionCore
{
protected:
// FDs
THandle * FirstHandle;
THandle * FirstHandle = NULL;
// Select interface
CSelect * Selector;
CSelect * Selector = NULL;
// Managing File Handles
bool RemoveHandle( THandle * Handle );
@@ -278,6 +278,7 @@ public:
// General port parameters
THandle * CreateHandle( const char * HandleName, bool CreateChannel );
virtual CDataMember * GetHandleAddress( THandle * Handle, const char * HandleRef );
bool SetCallback( THandle * Handle, EConnectState pState, FHandleCallback pCallback );
bool SetAutoManage( THandle * Handle, bool AutoManage, bool Persistent, int ReopenDelay = 0, int CloseTimeout = 0 );