Files
redAcore/SocketCore.h
Charl Wentzel 0d1c46ac53 Major update:
- Converted CSocketCore to Class/Object
- Implemented CFunctionCore as base class for CPortCore and CSocketCore
- Moved common functions to CFunctionCore and renamed
  eg. Maintain() -> Process()
- Pass Objects directly to each other as OutputFunction
- New Input() method allows data transfer between objects
2016-05-19 15:10:55 +02:00

67 lines
1.9 KiB
C++

/*
* SocketCore.h
*
* Created on: 13 May 2016
* Author: wentzelc
*/
#ifndef REDACORE_SOCKETCORE_H_
#define REDACORE_SOCKETCORE_H_
// redA Libraries
#include "FunctionCore.h"
// Standard C/C++ Libraries
/* none */
//---------------------------------------------------------------------------
// Types required for sockets
typedef enum { ctNone = 0, ctServer = 1, ctRemoteClient = 2, ctClient = 3 } ESockConnectType;
const char SockConnectTypeName[][15] = { "None", "Server", "RemoteClient", "Client" };
typedef enum { ssNone = 0, ssWaitingtoOpen = 1, ssOpen = 2, ssDataWaiting = 3, ssClosed = 4, ssFailed = 5 } ESocketState;
const char SocketStateName[][15] = { "None", "WaitingToOpen", "Open", "DataWaiting", "Closed", "Failed" };
//---------------------------------------------------------------------------
// Port Core Class
class CSocketCore : public CFunctionCore
{
protected:
char ServerAddress[25];
int PortNo;
char ClientAddress[25];
int ServerHandle;
ESocketState ServerState;
int ClientHandle;
ESocketState ClientState;
public:
// Life Cycle
CSocketCore( const char * ServerName );
virtual ~CSocketCore();
// Socket Functions
int OpenTCPserverSocket( const char *ServerAddress, int PortNo, bool KeepAlive );
int OpenTCPinClientSocket();
int OpenTCPoutClientSocket( const char *ServerAddress, int PortNo, bool KeepAlive );
ESocketState GetServerState();
ESocketState GetClientState();
bool CloseTCPSocket( ESockConnectType SocketType );
int GetServerFD() { return ServerHandle; };
int GetClientFD() { return ClientHandle; };
virtual int Input( int InputID, char * Buffer, int BufLen );
virtual bool Read( int FD );
virtual bool ProcessBuffer( bool Force );
};
//---------------------------------------------------------------------------
#endif /* REDACORE_SOCKETCORE_H_ */