GClasses

GClasses::GPackageServer Class Reference

This class abstracts a server 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::GPackageServer:
GClasses::GTCPServer

List of all members.

Public Member Functions

 GPackageServer (unsigned short port)
virtual ~GPackageServer ()
void send (const char *buf, size_t len, GTCPConnection *pConn)
 Send a package, which guarantees to arrive in the same order and size as it was sent.
char * receive (size_t *pOutLen, GTCPConnection **pOutConn)
 Receives the next available package. (The order and size is guaranteed to arrive the same as when it was sent.) NULL is returned if no package is ready in its entirety. The returned value is a pointer to an internal buffer, the contents of which is only valid until the next time receive is called.
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.

Static Public Member Functions

static void test ()
 Performs unit tests for this class. Throws an exception if there is a failure.

Protected Member Functions

virtual GTCPConnectionmakeConnection (SOCKET s)
 See the comment for GTCPConnection::makeConnection.

Protected Attributes

unsigned int m_maxBufSize
unsigned int m_maxPackageSize

Detailed Description

This class abstracts a server 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::GPackageServer::GPackageServer ( unsigned short  port)
virtual GClasses::GPackageServer::~GPackageServer ( ) [virtual]

Member Function Documentation

virtual GTCPConnection* GClasses::GPackageServer::makeConnection ( SOCKET  s) [protected, virtual]

See the comment for GTCPConnection::makeConnection.

Reimplemented from GClasses::GTCPServer.

char* GClasses::GPackageServer::receive ( size_t *  pOutLen,
GTCPConnection **  pOutConn 
)

Receives the next available package. (The order and size is guaranteed to arrive the same as when it was sent.) NULL is returned if no package is ready in its entirety. The returned value is a pointer to an internal buffer, the contents of which is only valid until the next time receive is called.

void GClasses::GPackageServer::send ( const char *  buf,
size_t  len,
GTCPConnection pConn 
)

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

Reimplemented from GClasses::GTCPServer.

void GClasses::GPackageServer::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.

static void GClasses::GPackageServer::test ( ) [static]

Performs unit tests for this class. Throws an exception if there is a failure.


Member Data Documentation

unsigned int GClasses::GPackageServer::m_maxBufSize [protected]