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

ssobjects::BufferedSocket Class Reference

#include <bufferedsocket.h>

Inheritance diagram for ssobjects::BufferedSocket::

ssobjects::SocketInstance List of all members.

Public Types

enum  ReleaseFlag { autoRelease, noRelease }

Public Methods

 BufferedSocket ()
 Construct the socket. More...

 ~BufferedSocket ()
 Destroys the socket, and closes the connection. More...

int sendPacket (PacketBuffer *pPacket, const ReleaseFlag release=noRelease)
 Transmits the packet. More...

int sendPacket (PacketBuffer &packet)
 Transmits the packet. More...

PacketBufferrecvPacket ()
 Reads and waits for a full PacketBuffer object. More...

PacketBufferrecvPacket (PacketBuffer &packet)
 Reads and waits for a full PacketBuffer object. More...

int setTimeout (const int iTimeOut)
 Sets how long to wait for incoming data before throwing. More...

void operator<< (PacketBuffer &packet)
 Transmits the packet. More...

void operator<< (PacketBuffer *ppacket)
 Transmits the packet. More...

void operator>> (PacketBuffer &packet)
 Reads and waits for a full PacketBuffer object. More...


Detailed Description

Base class for sending and receiving data send as PacketBuffers.

When data is sent, not all data is garenteed to be sent in the one call. (See man page for send(3) for details.)

When data is read, or received, not all the data is garenteed to be read in one recv call. (See man page for recv(3) for details.)

To make life easier, the functionality for sending and receiving an entire PacketBuffer object, without multiple calls to send()/recv() is wrapped up in this object.

Also, if 3 packets were sent, but only 2 1/2 were read, BufferedSocket will parse out the two, and keep the data from 3 till the next call.

Todo:
Verify it's send(3) and not send(2).


Member Enumeration Documentation

enum ssobjects::BufferedSocket::ReleaseFlag
 

Enumeration values:
autoRelease 
noRelease 


Constructor & Destructor Documentation

BufferedSocket::BufferedSocket  
 

Construct the socket.

Exceptions:
BufferedSocketException  If memory for the buffer was not available.

BufferedSocket::~BufferedSocket  
 

Destroys the socket, and closes the connection.


Member Function Documentation

void BufferedSocket::operator<< PacketBuffer   ppacket
 

Transmits the packet.

void BufferedSocket::operator<< PacketBuffer   packet
 

Transmits the packet.

void BufferedSocket::operator>> PacketBuffer   packet
 

Reads and waits for a full PacketBuffer object.

PacketBuffer * BufferedSocket::recvPacket PacketBuffer   packet
 

Reads and waits for a full PacketBuffer object.

Reads data into the referenced packet. This isn't as effiecent as using recvPacket(). You are gerented to receive a full PacketBuffer object.

Exceptions:
SocketInstanceException  If there is a read error, or a connection was closed.
BufferedSocketException  If a bad packet was read.

PacketBuffer * BufferedSocket::recvPacket  
 

Reads and waits for a full PacketBuffer object.

Reads data and returns a pointer to a new PacketBuffer object. You are responsible for deleting the returned packet when you are finished with it.

You are gerented to receive a full PacketBuffer object.

When data is read in, some verification is done to ensure that the packet header is valid. There is no way to validate the buffer portion of the packet. A test is done on the header to see if the cookie (just a constant value passed all the time) and to see the the command looks like it might be valid. There is no way to tell other then if the command is zero (PacketBuffer::pcInvalid). Note that a common problem with getting PacketBuffer::pcInvalid as a command is not setting the command in a packet before sending it.

If a packet is sent with a size greater then 3000 bytes, the read operation will reset the internal buffer, and throw an exception. This is done to prevent bogus packets overflowing the buffer.

Exceptions:
SocketInstanceException  If there is a read error, or a connection was closed.
BufferedSocketException  If a bad packet was read.

int BufferedSocket::sendPacket PacketBuffer   packet
 

Transmits the packet.

int BufferedSocket::sendPacket PacketBuffer   pPacket,
const ReleaseFlag    release = noRelease
 

Transmits the packet.

Sends the data pointed to by pPacket, and optionaly destroys the memory pointed to by pPacket once the data is sent. All data is garented to be sent.

Parameters:
pPacket  Packet you are sending.
release  When set to autoRelease, pPacket will be deleted once the data has been sent. When set to noRelease, pPacket is not deleted.
Exceptions:
SocketInstanceException  If there was a problem during the send operation.

int BufferedSocket::setTimeout const int    iTimeout
 

Sets how long to wait for incoming data before throwing.

Sets how many seconds a read or send operation will wait before throwing an exception.


The documentation for this class was generated from the following files:
Generated on Thu Nov 8 12:39:27 2001 for SimpleServerObjects by doxygen1.2.11 written by Dimitri van Heesch, © 1997-2001