C++ common classes
General purpose classes for use across projects (Apache license)
|
#include <CPConnection.h>
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 | |
CPHandler * | cPHandler |
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. | |
CBaseSocket * | cOwner |
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 |
Definition at line 82 of file CPConnection.h.
anonymous enum |
Operations.
Definition at line 90 of file CPConnection.h.
No public destructor.
CONNECT_UNUSED | |
CONNECT_PENDING | |
CONNECT_ATTEMPT_FAILED | |
CONNECT_SUCCESS | |
CONNECT_CLOSE_REQUESTED | |
CONNECT_DISCONNECTED | |
CONNECT_FAILURE |
Definition at line 99 of file CPConnection.h.
CPConnection::CPConnection | ( | CBaseSocket * | pOwner, |
struct sockaddr * | pAddr = NULL , |
||
int | iMaxSendBufferSize = CS_OUTBUFFER_SIZE |
||
) |
Definition at line 27 of file CPConnection.cpp.
CPConnection::~CPConnection | ( | ) | [virtual] |
Definition at line 48 of file CPConnection.cpp.
void CPConnection::AsyncTerminateConnection | ( | ) | [virtual] |
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] |
type | Address family. Only tested with AF_INET. |
protocol | Stream or datagram (SOCK_STREAM or SOCK_DRAM) |
nPort | Usually 0 for inet sockets |
lpAddr | Port |
bReuse | Inet address in the standard xxx.xxx.xxx.xxx format |
bBind | Allow reuse of this socket |
iLinger | Default 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.
void CPConnection::TerminateConnection | ( | ) | [virtual] |
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.
Definition at line 171 of file CPConnection.h.
BOOL CPConnection::bSendBufferHighWaterMark [protected] |
No room left in send buffer. Block until some sending occurs.
Definition at line 195 of file CPConnection.h.
BOOL CPConnection::bSendData [protected] |
There is data to be written.
Definition at line 193 of file CPConnection.h.
CBaseSocket* CPConnection::cOwner [protected] |
Definition at line 189 of file CPConnection.h.
CPHandler* CPConnection::cPHandler [protected] |
Definition at line 177 of file CPConnection.h.
CConnectionSig CPConnection::cSignature [protected] |
Definition at line 197 of file CPConnection.h.
ECONNECT CPConnection::eConnected [protected] |
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.
int CPConnection::iMaxSendBuffer [protected] |
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.
int CPConnection::iTotalSendData [protected] |
Definition at line 202 of file CPConnection.h.
int CPConnection::iTotalSent [protected] |
Definition at line 201 of file CPConnection.h.
long CPConnection::lCloseRequestTS [protected] |
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.