GClasses

GClasses::GPackageClient Class Reference

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. More...

#include <GSocket.h>

Inheritance diagram for GClasses::GPackageClient:
GClasses::GTCPClient

List of all members.

Public Member Functions

 GPackageClient ()
virtual ~GPackageClient ()
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.
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.)
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.

Protected Member Functions

virtual void onReceiveBadData (const char *message)
 This method is called if the peer sends data that does not follow the expected protocol.

Protected Attributes

unsigned int m_header [2]
unsigned int m_headerBytes
unsigned int m_payloadBytes
unsigned int m_bufSize
unsigned int m_maxBufSize
unsigned int m_maxPackageSize
char * m_pBuf

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.


Constructor & Destructor Documentation

GClasses::GPackageClient::GPackageClient ( )
virtual GClasses::GPackageClient::~GPackageClient ( ) [virtual]

Member Function Documentation

virtual void GClasses::GPackageClient::onReceiveBadData ( const char *  message) [inline, protected, virtual]

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

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.

Reimplemented from GClasses::GTCPClient.

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

unsigned int GClasses::GPackageClient::m_bufSize [protected]
unsigned int GClasses::GPackageClient::m_header[2] [protected]
unsigned int GClasses::GPackageClient::m_headerBytes [protected]
unsigned int GClasses::GPackageClient::m_maxBufSize [protected]
unsigned int GClasses::GPackageClient::m_payloadBytes [protected]