GClasses
GClasses::GPackageClient Class Reference

Detailed Description

This class abstracts a client that speaks a home-made protocol that guarantees packages will arrive in the same order and size as when they were sent. This protocol is a simple layer on top of TCP.

#include <GSocket.h>

Inheritance diagram for GClasses::GPackageClient:
GClasses::GDomClient

Public Member Functions

 GPackageClient ()
 
virtual ~GPackageClient ()
 
void connect (const char *addr, unsigned short port, int timeoutSecs=20)
 Connect to a server. Throws an exception if it fails to connect within the specified timout period. More...
 
void disconnect ()
 Disconnect from the server. More...
 
virtual void pump ()
 Receives any pending messages into an internal buffer (to unblock the server, in case its send buffer is full.) More...
 
char * receive (size_t *pLen)
 Receive the next available package. (This returns a pointer to an internal buffer, the contents of which only remain valid until the next time you call receive.) More...
 
void send (const char *buf, size_t len)
 Send a package, which guarantees to arrive in the same order and size as it was sent. More...
 
void setMaxBufferSizes (size_t a, size_t b)
 Sets some internal values that guide how it reallocates the internal buffer. 'a' is the maximum buffer size to keep around. 'b' is the maximum size for the buffer ever. If a package bigger than 'b' is sent, an exception will be thrown. If a package bigger than 'a' is sent, then the buffer will be grown to that size, but it will be made small again the next time a package is received. More...
 

Protected Member Functions

virtual void onDisconnect ()
 This is called when the connection is first known to have disconnected. More...
 
virtual void onReceiveBadData (const char *message)
 This method is called if the peer sends data that does not follow the expected protocol. More...
 

Protected Attributes

GPackageConnection m_conn
 
unsigned int m_maxBufSize
 
unsigned int m_maxPackageSize
 

Constructor & Destructor Documentation

GClasses::GPackageClient::GPackageClient ( )
virtual GClasses::GPackageClient::~GPackageClient ( )
virtual

Member Function Documentation

void GClasses::GPackageClient::connect ( const char *  addr,
unsigned short  port,
int  timeoutSecs = 20 
)

Connect to a server. Throws an exception if it fails to connect within the specified timout period.

void GClasses::GPackageClient::disconnect ( )

Disconnect from the server.

virtual void GClasses::GPackageClient::onDisconnect ( )
inlineprotectedvirtual

This is called when the connection is first known to have disconnected.

virtual void GClasses::GPackageClient::onReceiveBadData ( const char *  message)
inlineprotectedvirtual

This method is called if the peer sends data that does not follow the expected protocol.

virtual void GClasses::GPackageClient::pump ( )
virtual

Receives any pending messages into an internal buffer (to unblock the server, in case its send buffer is full.)

char* GClasses::GPackageClient::receive ( size_t *  pLen)

Receive the next available package. (This returns a pointer to an internal buffer, the contents of which only remain valid until the next time you call receive.)

void GClasses::GPackageClient::send ( const char *  buf,
size_t  len 
)

Send a package, which guarantees to arrive in the same order and size as it was sent.

void GClasses::GPackageClient::setMaxBufferSizes ( size_t  a,
size_t  b 
)
inline

Sets some internal values that guide how it reallocates the internal buffer. 'a' is the maximum buffer size to keep around. 'b' is the maximum size for the buffer ever. If a package bigger than 'b' is sent, an exception will be thrown. If a package bigger than 'a' is sent, then the buffer will be grown to that size, but it will be made small again the next time a package is received.

Member Data Documentation

GPackageConnection GClasses::GPackageClient::m_conn
protected
unsigned int GClasses::GPackageClient::m_maxBufSize
protected
unsigned int GClasses::GPackageClient::m_maxPackageSize
protected