/*! \file socket.h
This is the Socket class definition.
\author Jon A. Lambert
\date 05/02/2003
\version 0.30
*/
#ifndef SOCKET_H
#define SOCKET_H
/*!
A BlockingException in the context of Socket streams is not really an
error condition. It is thrown when we reach the end of available data
and should be caught and handled.
*/
class BlockingException : public exception {
public:
BlockingException(int errcode = 0) : mErrCode(errcode) {};
int mErrCode;
};
/*!
A ShutdownException is thrown when we detect the client's connection
has been closed from their end.
*/
class ShutdownException : public exception {
public:
ShutdownException(int errcode = 0) : mErrCode(errcode) {};
int mErrCode;
};
/*!
An IOErrorException is a general purpose exception that indicates
a severe non-recoverable error. Generally this requires the Socket
to be disconnected.
*/
class IOErrorException : public exception {
public:
IOErrorException(int errcode = 0) : mErrCode(errcode) {};
int mErrCode;
};
/*!
The Socket class contains the minimum amount of attributes to reasonably
maintain a socket connection with a client.
\note
This was refactored out of the Connection class and implemented there as
a composite member. It might have been made a superclass were it not for
the all the functions we'd have to remap and/or override to keep exception
and error handling safely within the Connection class.
*/
class Socket {
public:
Socket(SOCKET mSock, int size = 4096);
Socket(const Socket& r_sock);
virtual ~Socket();
char Read();
void Write(const char c);
void Write(const string& r_str);
void Write(const char* p_char);
void Write(const char* p_char, int len);
void Flush();
SOCKET GetSocket();
void Close();
private:
Socket& operator= (const Socket& r_sock);
SOCKET mSock; //!< network socket
int mSize; //!< size of buffers
char * mpInBuffer; //!< the socket input buffer.
char * mpOutBuffer; //!< the socket output buffer.
char * mpRead; //!< pointer to the start of data in mpInBuffer.
char * mpEod; //!< pointer to the end of data in mpInBuffer.
char * mpWrite; //!< pointer to the next write position in mpOutBuffer.
char * mpStartWrite; //!< pointer to the data to start send in mpOutBuffer.
};
#endif // SOCKET_H