//Our accept socket
class CAcceptSocket : public CTCPSocketAsync
{
public:
//Ctor and Dtor
CAcceptSocket(CTCPRelay* pFather);
virtual ~CAcceptSocket();
protected:
//When a socket can accept an incoming connection
virtual BOOL OnSocketAccept(int iErrorCode);
//No events
NO_OnSocketOOB
NO_OnSocketWrite
NO_OnSocketTimeout
NO_OnSocketConnect
NO_OnSocketClose
NO_OnSocketReceive
private:
//Our father
CTCPRelay* m_pFather;
};
//Our client socket
class CClientSocket : public CTCPSocketAsync
{
public:
//Send data over the sockets
virtual int Send(const char* pBuffer,
unsigned long ulBufferLength);
//Stop the sockets
void Stop();
//Set the connection ID
void SetConnectionID(ConnectionID aConnectionID);
//Try to connect
void Connect();
//Set the other side
void SetSocket(CClientSocket* pSocket);
//Ctor and Dtor
CClientSocket(CTCPRelay* pFather,
CClientSocket* pSocket);
virtual ~CClientSocket();
protected:
//When a socket got a connect event (after calling connect)
virtual BOOL OnSocketConnect(int iErrorCode);
//When a socket was closed
virtual BOOL OnSocketClose(int iErrorCode);
//When socket has data in queue
virtual BOOL OnSocketReceive(int iErrorCode);
//When a timeout occured (implemented at library level)
//User should return 0, if proccessed the message
virtual BOOL OnSocketTimeout();
//No events
NO_OnSocketAccept
NO_OnSocketOOB
NO_OnSocketWrite
private:
//Our father
CTCPRelay* m_pFather;
//Our other side
CClientSocket* m_pSocket;
//Our connection ID
ConnectionID m_aConnectionID;
//Are we the incoming
BOOL m_bIncoming;
//Our CS
CGenericCriticalSection* m_pCSection;
//Do we have an event
BOOL m_bEvent;
};
//Our struct of two sockets
typedef struct _SocketData
{
CClientSocket* pIncomingConnection;
CClientSocket* pOutgoingConnection;
} SocketData;
//Our map of sockets (according to connection IDs)
typedef std::map<ConnectionID,SocketData> ClientMap;