Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ssobjects::ServerSocket Class Reference

Socket object that contains both a read and write buffer. More...

#include <serversocket.h>

Inheritance diagram for ssobjects::ServerSocket::

ssobjects::SocketInstance List of all members.

Public Types

enum  {
  modeInvalid = 0, modeWriteOkay = 1, modeSendOkay = 2, modeReadOkay = 4,
  modeClosing = 8, modeNotified = 16, modeClosed = 32, modeValid = modeSendOkay|modeWriteOkay|modeReadOkay,
  modeAll = 0xFFFFFFFF
}
 Not used. More...


Public Methods

 ServerSocket (const unsigned32 nBufferSize=18000, const int iTimeout=DEFAULT_SOCKET_TIMEOUT)
 ServerSocket (const SocketInstance &socket, const SockAddr &sa, const unsigned32 nBuffSize, const int iTimeout)
virtual ~ServerSocket ()
void sendPacket (const PacketBuffer &packet)
 Will add to outgoing buffer, and try sending it. More...

void sendPacket (const PacketBuffer *const ppacket)
 Will add to outgoing buffer, and try sending it. More...

void sendBuffer ()
 Will attept to send any data in the outgoing buffer. More...

int readData ()
 Reads in as much data is available on the socket. More...

PacketBufferextractPacket ()
 Extracts a packet from the incoming buffer. More...

const Flagsflags () const
 Returns the socket flags. (Not currently used.). More...

unsigned32 getOutBufferSize () const
 Return bytes in outgoing buffer. More...

unsigned32 getOutBufferSizeMax () const
 Return the actual size (how much was allocated) of the buffer. More...

unsigned32 getInBufferSize () const
 Return bytes in incoming buffer. More...

unsigned32 getBufferSizeMax () const
 How big the in/out buffer is. More...

SockAddr getAddr () const
 Gets the socket address information of the connected socket. More...

int socketTimeout () const
 Returns the number of seconds a send/receive operation will wait before throwing. More...

ServerHandlerserverHandler () const
 Returns the ServerHandler object that was assigned to this server socket object. More...

void setServerHandler (ServerHandler *s)
 Sets the ServerHandler object that this server socket will use. More...


Protected Methods

char* getOutBuffer () const
char* getInBuffer () const
void rotateBuffer (char *pbuffer, unsigned32 nBuffSize, unsigned32 nBytesRotatingOut)
void addPacketBuffer (const PacketBuffer *const ppacket)
 ServerSocket (const ServerSocket &)
ServerSocket& operator= (const ServerSocket &)

Protected Attributes

ServerHandlerm_pserverHandler
SockAddr m_socketAddr
unsigned32 m_nID
int m_iTimeout
Flags m_flags
char* m_pInBuff
char* m_pOutBuff
char* m_pOutPtr
char* m_pInPtr
unsigned32 m_nBytesIn
unsigned32 m_nBytesOut
unsigned32 m_nBufferSizeMax

Detailed Description

Socket object that contains both a read and write buffer.

The Server Socket object contains an incoming buffer for data that is read in and isn't parsed, and an outgoing buffer for data that hasn't been sent. The SimpleServer object uses this object for every connection that comes in.

A ServerHandler object can be stored here for easy access to it from a server object that has a number of server socket objects.


Member Enumeration Documentation

anonymous enum
 

Not used.

Enumeration values:
modeInvalid  
modeWriteOkay  
modeSendOkay  
modeReadOkay  
modeClosing  
modeNotified  
modeClosed  
modeValid  
modeAll  


Constructor & Destructor Documentation

ssobjects::ServerSocket::ServerSocket ( const unsigned32 nBufferSize = 18000,
const int iTimeout = DEFAULT_SOCKET_TIMEOUT )
 

ssobjects::ServerSocket::ServerSocket ( const SocketInstance & socket,
const SockAddr & sa,
const unsigned32 nBuffSize,
const int iTimeout )
 

ssobjects::ServerSocket::~ServerSocket ( ) [virtual]
 

Deletes the in buffer, out buffer, and the server handler you assigned it.

ssobjects::ServerSocket::ServerSocket ( const ServerSocket & ) [protected]
 


Member Function Documentation

void ssobjects::ServerSocket::addPacketBuffer ( const PacketBuffer *const ppacket ) [protected]
 

PacketBuffer * ssobjects::ServerSocket::extractPacket ( )
 

Extracts a packet from the incoming buffer.

We do two checks to see that we have enough data to make a full packet. One check is to see that we have enough data the make a header. The second is to see if there is enough to make a packet with a header plus it's data.

We return NULL if there wasn't enough data to make a full packet. If there is enough data we return _one_ complete packet, and make sure the buffer is ready to extract more packets, and recieve additional data.

A full packet is the size of the packet header (all packets _must_ have full header) plus the size of any data. There doesn't always have to be any data with the packet.

If the size that is read in is invalid, extractPacket throws an exception. This indicates that the data read in was not valid.

Returns:
NULL if there isn't enough data to return a full packet. A pointer to a newly created PacketBuffer object if there is.
Exceptions:
ServerSocketException   If a packet with an invalid size is read.

const Flags & ssobjects::ServerSocket::flags ( ) const [inline]
 

Returns the socket flags. (Not currently used.).

SockAddr ssobjects::ServerSocket::getAddr ( ) const [inline]
 

Gets the socket address information of the connected socket.

unsigned32 ssobjects::ServerSocket::getBufferSizeMax ( ) const [inline]
 

How big the in/out buffer is.

char * ssobjects::ServerSocket::getInBuffer ( ) const [inline, protected]
 

unsigned32 ssobjects::ServerSocket::getInBufferSize ( ) const [inline]
 

Return bytes in incoming buffer.

char * ssobjects::ServerSocket::getOutBuffer ( ) const [inline, protected]
 

unsigned32 ssobjects::ServerSocket::getOutBufferSize ( ) const [inline]
 

Return bytes in outgoing buffer.

unsigned32 ssobjects::ServerSocket::getOutBufferSizeMax ( ) const [inline]
 

Return the actual size (how much was allocated) of the buffer.

ServerSocket & ssobjects::ServerSocket::operator= ( const ServerSocket & ) [protected]
 

int ssobjects::ServerSocket::readData ( )
 

Reads in as much data is available on the socket.

Reads data from the socket. Will only read as many bytes as will fit in our input buffer. If 0 bytes are available in the buffer, then recv will read 0 bytes. When this happens, a SocketInstanceException is thrown. This is desirable as if the buffer is full, and hasn't been processed, then it is considered an error.

Returns:
The number of bytes read.
Exceptions:
SocketInstanceException   If there was a read error, or the input buffer was full.

void ssobjects::ServerSocket::rotateBuffer ( char * pbuffer,
unsigned32 nBuffSize,
unsigned32 nBytesRotatingOut ) [protected]
 

void ssobjects::ServerSocket::sendBuffer ( )
 

Will attept to send any data in the outgoing buffer.

void ssobjects::ServerSocket::sendPacket ( const PacketBuffer *const ppacket )
 

Will add to outgoing buffer, and try sending it.

void ssobjects::ServerSocket::sendPacket ( const PacketBuffer & packet )
 

Will add to outgoing buffer, and try sending it.

ServerHandler * ssobjects::ServerSocket::serverHandler ( ) const [inline]
 

Returns the ServerHandler object that was assigned to this server socket object.

void ssobjects::ServerSocket::setServerHandler ( ServerHandler * s ) [inline]
 

Sets the ServerHandler object that this server socket will use.

int ssobjects::ServerSocket::socketTimeout ( ) const [inline]
 

Returns the number of seconds a send/receive operation will wait before throwing.


Member Data Documentation

Flags ssobjects::ServerSocket::m_flags [protected]
 

int ssobjects::ServerSocket::m_iTimeout [protected]
 

unsigned32 ssobjects::ServerSocket::m_nBufferSizeMax [protected]
 

unsigned32 ssobjects::ServerSocket::m_nBytesIn [protected]
 

unsigned32 ssobjects::ServerSocket::m_nBytesOut [protected]
 

unsigned32 ssobjects::ServerSocket::m_nID [protected]
 

char * ssobjects::ServerSocket::m_pInBuff [protected]
 

char * ssobjects::ServerSocket::m_pInPtr [protected]
 

char * ssobjects::ServerSocket::m_pOutBuff [protected]
 

char * ssobjects::ServerSocket::m_pOutPtr [protected]
 

ServerHandler * ssobjects::ServerSocket::m_pserverHandler [protected]
 

SockAddr ssobjects::ServerSocket::m_socketAddr [protected]
 


The documentation for this class was generated from the following files:
Generated at Tue Sep 25 00:26:37 2001 for SimpleServerObjects by doxygen1.2.7 written by Dimitri van Heesch, © 1997-2001