#ifndef __DSTCPEndpoint_h__
#define __DSTCPEndpoint_h__ 1
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h> // struct sockaddr_in
#include "DSNetworkUtilities.h" // for some constants
#include "SharedConsts.h"
const uInt32 kTCPOpenTimeout = 120;
#ifdef DSSERVERTCP
const uInt32 kTCPRWTimeout = 60*60*24; #else
const uInt32 kTCPRWTimeout = 60*5; #endif
const uInt32 kTCPMaxListenBackLog = 1024;
const uInt32 kTCPErrorBufferLen = 256;
const uInt32 kDSTCPEndpointMaxMessageSize = 1024; const uInt32 kDSTCPEndpointMessageTagSize = 4;
class DSTCPEndpoint
{
public:
enum eExceptions
{
kConnectionLostWarning = eDSCannotAccessSession, kAbortedWarning = 'sok1', kTimeoutError = eDSServerTimeout, };
enum eTimeoutType
{
kOpenTimeoutType = 1,
kRWTimeoutType,
kDefaultTimeoutType
};
DSTCPEndpoint ( const uInt32 inSessionID,
const uInt32 inOpenTimeOut = kTCPOpenTimeout,
const uInt32 inRdWrTimeOut = kTCPRWTimeout );
DSTCPEndpoint ( const DSTCPEndpoint *inEndpoint,
const uInt32 inSessionID );
virtual ~DSTCPEndpoint ( void );
uInt32 GetSessionID ( void ) { return mLogMsgSessionID; }
uInt32 GetReverseAddress ( void ) const { return mRemoteHostIPAddr; }
uInt32 GetIPAddress ( void ) const { return mMyIPAddr; } const char *GetReverseAddressString ( void ) const { return mRemoteHostIPString; }
int GetCurrentConnection ( void ) const { return mConnectFD; }
sInt32 SendClientReply ( void *inMsg );
void* GetClientMessage ( void );
sInt32 SyncToMessageBody ( const Boolean inStripLeadZeroes, uInt32 *outBuffLen );
sInt32 GetServerReply ( sComData **outMsg );
sInt32 SendServerMessage ( void *inMsg );
sInt32 SendBuffer ( void *inBuffer, uInt32 inLength );
virtual void EncryptData ( void *inData, const uInt32 inBuffSize, void *&outData, uInt32 &outBuffSize );
virtual void DecryptData ( void *inData, const uInt32 inBuffSize, void *&outData, uInt32 &outBuffSize );
uInt32 WriteData ( const void *inData, const uInt32 inSize );
Boolean Connected ( void ) const ;
void Abort ( void );
sInt32 ConnectTo ( const uInt32 inIPAddress, const uInt16 inPort ); void ListenToPort ( const uInt16 inPort );
void ListenToPortOnAddress ( const uInt16 inPort, const uInt32 inWhichAddr );
Boolean AcceptConnection ( void );
void CloseConnection ( void );
int CloseListener ( void ); void SetTimeout ( const int inWhichTimeout, const int inSeconds ); void GetReverseAddressString ( char *ioBuffer, const int inBufferSize ) const ;
uInt32 GetRemoteHostIPAddress ( void );
uInt16 GetRemoteHostPort ( void );
protected:
sComProxyData* AllocToProxyStruct ( sComData *inDataMsg );
sComData* AllocFromProxyStruct( sComProxyData *inProxyDataMsg );
uInt32 DoTCPRecvFrom ( void *ioBuffer, const uInt32 inBufferSize );
private:
void InitBuffers ( void );
int DoTCPOpenSocket ( void );
int SetSocketOption ( const int inSocket, const int inSocketOption);
int DoTCPBind ( void );
int DoTCPListen ( void );
int DoTCPAccept ( void );
int DoTCPCloseSocket ( const int inSockFD );
protected:
uInt32 mLogMsgSessionID;
uInt32 mMyIPAddr; struct sockaddr_in mMySockAddr;
uInt32 mRemoteHostIPAddr; IPAddrStr mRemoteHostIPString; struct sockaddr_in mRemoteSockAddr;
int mListenFD;
int mConnectFD;
char *mErrorBuffer;
Boolean mAborting;
Boolean mWeHaveClosed;
int mOpenTimeout; int mRWTimeout; int mDefaultTimeout;
};
#endif // __DSTCPEndpoint_h__