C++ common classes
General purpose classes for use across projects (Apache license)
CPConnection Class Reference

#include <CPConnection.h>

Inheritance diagram for CPConnection:
CBaseSocket CPClient

List of all members.

Public Types

enum  { CS_BUFFER_SIZE = 0x2000, CS_OUTBUFFER_SIZE = 0x8000 }
 Operations. More...
enum  ECONNECT {
  CONNECT_UNUSED, CONNECT_PENDING, CONNECT_ATTEMPT_FAILED, CONNECT_SUCCESS,
  CONNECT_CLOSE_REQUESTED, CONNECT_DISCONNECTED, CONNECT_FAILURE
}
 No public destructor. More...

Public Member Functions

 CPConnection (CBaseSocket *pOwner, struct sockaddr *pAddr=NULL, int iMaxSendBufferSize=CS_OUTBUFFER_SIZE)
virtual ~CPConnection ()
virtual BOOL Create (int af, int type, int protocol, UINT nPort=0, LPCSTR lpAddr=NULL, BOOL bReuse=FALSE, BOOL bBind=TRUE, int iLinger=-1)
virtual void TerminateConnection ()
 Terminate a connection and close the socket.
virtual time_t GetTimeConnected ()
 Return the time the connection was initiated.
virtual struct sockaddr_in GetSocketAddress ()
 Get socket address.
virtual void AsyncTerminateConnection ()
ECONNECT GetConnectionStatus ()
 Get connection status.
BOOL IsSendComplete ()

Public Attributes

BOOL bRecvPause

Protected Member Functions

virtual int ReceiveData ()
 Receive the data to a socket.
virtual int SendData ()
 Send data from a socket.
virtual BOOL SendDataOut (LPSTR lpData, int nPacketSize, int nTotalLength)
virtual BOOL ProcessData (unsigned char *lpData, int iLen)=0
 Pure virtual function to process data.
virtual BOOL GetHandshake (unsigned char **ucHS, int &iLen)
virtual void Disconnected ()
 When removed from the handler, this gets called.
virtual void UnprotectedCloseSocket ()
 Unprotected close socket.
virtual void SetHandler (CPHandler *pHandler)
 Called by the handler itself when it accepts the connection.
virtual int HandleConnection (void *pParm=NULL)

Protected Attributes

CPHandlercPHandler
int iMaxSendBuffer
unsigned char ucBuffer [CS_BUFFER_SIZE]
 Input buffer.
unsigned char * pOutBuffer
 Output buffer.
int iOBSize
 Current size of the output buffer.
int iLeftToSend
 What's left to send in the out buffer.
int iSendIndex
 Index of bytes to send.
CBaseSocketcOwner
time_t tConnected
struct sockaddr_in sAddr
BOOL bSendData
 There is data to be written.
BOOL bSendBufferHighWaterMark
 No room left in send buffer. Block until some sending occurs.
ECONNECT eConnected
CConnectionSig cSignature
long lCloseRequestTS
 Timestamp of when a close was requested.
int iTotalRecvd
int iTotalSent
int iTotalSendData

Detailed Description

Definition at line 82 of file CPConnection.h.


Member Enumeration Documentation

anonymous enum

Operations.

Enumerator:
CS_BUFFER_SIZE 
CS_OUTBUFFER_SIZE 

8K

Definition at line 90 of file CPConnection.h.

No public destructor.

Enumerator:
CONNECT_UNUSED 
CONNECT_PENDING 
CONNECT_ATTEMPT_FAILED 
CONNECT_SUCCESS 
CONNECT_CLOSE_REQUESTED 
CONNECT_DISCONNECTED 
CONNECT_FAILURE 

Definition at line 99 of file CPConnection.h.


Constructor & Destructor Documentation

CPConnection::CPConnection ( CBaseSocket pOwner,
struct sockaddr *  pAddr = NULL,
int  iMaxSendBufferSize = CS_OUTBUFFER_SIZE 
)

Definition at line 27 of file CPConnection.cpp.

Definition at line 48 of file CPConnection.cpp.


Member Function Documentation

Asynchronously close the socket. If a handler hasn't been assigned, this calls TerminateConnection. Otherwise, the handler waits until the send buffer is clear and then closes the socket.

Definition at line 314 of file CPConnection.cpp.

BOOL CPConnection::Create ( int  af,
int  type,
int  protocol,
UINT  nPort = 0,
LPCSTR  lpAddr = NULL,
BOOL  bReuse = FALSE,
BOOL  bBind = TRUE,
int  iLinger = -1 
) [virtual]
Parameters:
typeAddress family. Only tested with AF_INET.
protocolStream or datagram (SOCK_STREAM or SOCK_DRAM)
nPortUsually 0 for inet sockets
lpAddrPort
bReuseInet address in the standard xxx.xxx.xxx.xxx format
bBindAllow reuse of this socket
iLingerDefault to bind the socket. Not needed if this is the result of an ::accept

Definition at line 68 of file CPConnection.cpp.

virtual void CPConnection::Disconnected ( ) [inline, protected, virtual]

When removed from the handler, this gets called.

Reimplemented in CPClient.

Definition at line 155 of file CPConnection.h.

Get connection status.

Definition at line 193 of file CPConnection.cpp.

virtual BOOL CPConnection::GetHandshake ( unsigned char **  ucHS,
int &  iLen 
) [inline, protected, virtual]

Get handshake. Return TRUE if ptr and int filled This is sent when a connection is established. Redefine to have server send a connection message.

Definition at line 149 of file CPConnection.h.

struct sockaddr_in CPConnection::GetSocketAddress ( ) [read, virtual]

Get socket address.

Definition at line 207 of file CPConnection.cpp.

time_t CPConnection::GetTimeConnected ( ) [virtual]

Return the time the connection was initiated.

Definition at line 200 of file CPConnection.cpp.

virtual int CPConnection::HandleConnection ( void pParm = NULL) [inline, protected, virtual]

Called by SetHandler to indicate that a connection is about about to be handled SetHandler is called within CPHandler::AddConnection

Definition at line 168 of file CPConnection.h.

Has all data submitted by send been transferred? Only valid after AsyncTerminateConnection has been called.

virtual BOOL CPConnection::ProcessData ( unsigned char *  lpData,
int  iLen 
) [protected, pure virtual]

Pure virtual function to process data.

int CPConnection::ReceiveData ( ) [protected, virtual]

Receive the data to a socket.

Definition at line 267 of file CPConnection.cpp.

int CPConnection::SendData ( ) [protected, virtual]

Send data from a socket.

Definition at line 214 of file CPConnection.cpp.

BOOL CPConnection::SendDataOut ( LPSTR  lpData,
int  nPacketSize,
int  nTotalLength 
) [protected, virtual]

Send data. If iMaxSendBufferSize is exceeded, the return will be FALSE, and the sender must wait until some data is sent before proceeding.

Definition at line 117 of file CPConnection.cpp.

void CPConnection::SetHandler ( CPHandler pHandler) [protected, virtual]

Called by the handler itself when it accepts the connection.

Definition at line 91 of file CPConnection.cpp.

Terminate a connection and close the socket.

Removes from handler queue by closing socket

Definition at line 100 of file CPConnection.cpp.

void CPConnection::UnprotectedCloseSocket ( ) [protected, virtual]

Unprotected close socket.

Reimplemented from CBaseSocket.

Definition at line 329 of file CPConnection.cpp.


Member Data Documentation

Definition at line 171 of file CPConnection.h.

No room left in send buffer. Block until some sending occurs.

Definition at line 195 of file CPConnection.h.

There is data to be written.

Definition at line 193 of file CPConnection.h.

Definition at line 189 of file CPConnection.h.

Definition at line 177 of file CPConnection.h.

Definition at line 197 of file CPConnection.h.

Definition at line 196 of file CPConnection.h.

int CPConnection::iLeftToSend [protected]

What's left to send in the out buffer.

Definition at line 186 of file CPConnection.h.

Definition at line 178 of file CPConnection.h.

int CPConnection::iOBSize [protected]

Current size of the output buffer.

Definition at line 184 of file CPConnection.h.

int CPConnection::iSendIndex [protected]

Index of bytes to send.

Definition at line 188 of file CPConnection.h.

int CPConnection::iTotalRecvd [protected]

Definition at line 200 of file CPConnection.h.

Definition at line 202 of file CPConnection.h.

int CPConnection::iTotalSent [protected]

Definition at line 201 of file CPConnection.h.

Timestamp of when a close was requested.

Definition at line 199 of file CPConnection.h.

unsigned char* CPConnection::pOutBuffer [protected]

Output buffer.

Definition at line 182 of file CPConnection.h.

struct sockaddr_in CPConnection::sAddr [protected]

Definition at line 191 of file CPConnection.h.

time_t CPConnection::tConnected [protected]

Definition at line 190 of file CPConnection.h.

unsigned char CPConnection::ucBuffer[CS_BUFFER_SIZE] [protected]

Input buffer.

Definition at line 180 of file CPConnection.h.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines