class tcpsocket::BufferedSocket

This class provides a buffered interface to TCP socket operations.

Child Classes

This class provides a buffered interface to TCP socket operations. It allocates a application memory buffer to speed communications in both sending and receiving.

Note: Since communications are buffered, flushing the socket buffer is required for immediate data sends, in the case of synchronous communications.

The buffered socket has been implemented as a facade of the Socket class to allow the copy constructor and copy operators to receive a Socket, BufferedSocket, or SSLSocket.

This class has no child classes.

Inheritance:


Public Methods

[more]explicit BufferedSocket(const BufferedSocket& s)
Copy constructor, clones the passed socket and uses it for communications.
[more]explicit BufferedSocket(int bufSize = -1)
Constructs the buffered socket
[more]explicit BufferedSocket(int socket_handle, int bufSize = -1)
Constructs the buffered socket using an existing socket handle
[more]explicit BufferedSocket(const char* host, short port, int bufSize = -1) throw(SocketException)
Constructs the socket and opens a connection to a server
[more]explicit BufferedSocket(const Socket& src, int bufSize = -1)
Copy constructor, clones the passed socket and uses it for communications.
[more]explicit BufferedSocket(Socket* src, int bufSize = -1)
Constructs the BufferedSocket and uses src directly as for communications
[more]void close() throw(SocketException)
Flushes and closes the socket
[more]int flush() throw(SocketException)
Flushes the write buffer over the socket connection
[more]int get() throw(SocketException)
Reads a single character from the stream
[more]void getLine(std::string& line, const std::string& eol) throw(SocketException)
Reads until the end of the line has been read @throw SocketException
[more]BufferedSocket& operator << (const std::string& str) throw(SocketException)
Writes a string to the buffered socket
[more]BufferedSocket& operator << (BufferedSocket& (*sockFunc)(BufferedSocket*) throw (SocketException)) throw(SocketException)
Calls a stream format function like endl or flush to operate against this socket
[more]BufferedSocket& operator=(const BufferedSocket& s)
Copy operator, clones the passed socket and uses it for communications.
[more]BufferedSocket& operator=(const Socket& s)
Copy operator, clones the passed socket and uses it for communications.
[more]int peek() throw(SocketException)
Looks at the buffer and returns the first byte in the buffer
[more]int putback(int c) throw(SocketException)
Places a character back into the buffer
[more]size_t receive(char* readBuffer, size_t length) throw(SocketException)
Receives data from the socket.
[more]size_t receiveSome(char* readBuffer, size_t length) throw(SocketException)
Receives data from the socket.
[more]size_t send(const char* sendBuffer, size_t length) throw(SocketException)
Sends data over the socket.
[more] ~BufferedSocket()
Destroys the buffered socket object

Inherited from Socket:

Public Methods

ovirtual Socket* clone() const
ovirtual int getSocket()
obool getThrowOnClosed()
ovoid setThrowOnClosed(bool throwOnClose)

Protected Fields

oint m_socket

Member Documentation


explicit BufferedSocket (int bufSize = -1)
Constructs the buffered socket
Parameters:
bufSize - [in] Specifies the size of the buffer, -1 indicates the buffer should match the system's TCP buffer size


explicit BufferedSocket (int socket_handle, int bufSize = -1)
Constructs the buffered socket using an existing socket handle
Parameters:
socket_handle - [in] An existing socket handle to use in communications
bufSize - [in] Specifies the size of the buffer, -1 indicates the buffer should match the system's TCP buffer size


explicit BufferedSocket (const char* host, short port, int bufSize = -1) throw(SocketException)
Constructs the socket and opens a connection to a server
Parameters:
host - [in] The address of the server or DNS name
- port [in] The TCP port to connect to
bufSize - [in] Specifies the size of the buffer, -1 indicates the buffer should match the system's TCP buffer size


explicit BufferedSocket (const Socket& src, int bufSize = -1)
Copy constructor, clones the passed socket and uses it for communications.
Parameters:
s - [in] The source socket
bufSize - [in] Specifies the size of the buffer, -1 indicates the buffer should match the system's TCP buffer size


explicit BufferedSocket (Socket* src, int bufSize = -1)
Constructs the BufferedSocket and uses src directly as for communications
Parameters:
src - [in] The socket to use in communications
bufSize - [in] Specifies the size of the buffer, -1 indicates the buffer should match the system's TCP buffer size


explicit BufferedSocket (const BufferedSocket& s)
Copy constructor, clones the passed socket and uses it for communications.
Parameters:
s - [in] The source socket


BufferedSocket& operator= (const BufferedSocket& s)
Copy operator, clones the passed socket and uses it for communications.
Parameters:
s - [in] The source socket
Returns:
A reference to this object


BufferedSocket& operator= (const Socket& s)
Copy operator, clones the passed socket and uses it for communications.
Parameters:
s - [in] The source socket
Returns:
A reference to this object


~BufferedSocket ()
Destroys the buffered socket object


size_t send (const char* sendBuffer, size_t length) throw(SocketException)
Sends data over the socket. Sends exactly length bytes.
Throws:
SocketException if the connection was closed and the throw on close flag was set.
Parameters:
sendBuffer - [in] A buffer containing the data to be sent
length - [in] The number of bytes in the buffer
Returns:
The number of bytes sent, -1 on error, and 0 if the connection was closed


size_t receive (char* readBuffer, size_t length) throw(SocketException)
Receives data from the socket. Receives exactly length bytes or less if the socket is closed early.
Throws:
SocketException if the connection was closed and the throw on close flag was set.
Parameters:
sendBuffer - [out] A buffer receiving the data
length - [in] The maximum number of bytes in the buffer
Returns:
The number of bytes received, -1 on error, and 0 if the connection was closed


size_t receiveSome (char* readBuffer, size_t length) throw(SocketException)
Receives data from the socket. Receives upto length bytes.
Throws:
SocketException if the connection was closed and the throw on close flag was set.
Parameters:
sendBuffer - [out] A buffer receiving the data
length - [in] The maximum number of bytes in the buffer
Returns:
The number of bytes received, -1 on error, and 0 if the connection was closed


int get () throw(SocketException)
Reads a single character from the stream
Returns:
-1 in case the stream is closed @throw SocketException


int peek () throw(SocketException)
Looks at the buffer and returns the first byte in the buffer
Returns:
The first byte in teh buffer or -1 on error


int putback (int c) throw(SocketException)
Places a character back into the buffer
Returns:
-1 on error


void getLine (std::string& line, const std::string& eol) throw(SocketException)
Reads until the end of the line has been read @throw SocketException


int flush () throw(SocketException)
Flushes the write buffer over the socket connection
Throws:
Throws SocketException if the socket was closed and the throw on close flag was set.
Returns:
the number of bytes sent, 0 if the socket was closed, or -1 on an error


BufferedSocket& operator << (const std::string& str) throw(SocketException)
Writes a string to the buffered socket
Parameters:
str - The string to write to the buffered socket
Returns:
A reference to this buffered socket


BufferedSocket& operator << (BufferedSocket& (*sockFunc)(BufferedSocket*) throw (SocketException)) throw(SocketException)
Calls a stream format function like endl or flush to operate against this socket
Parameters:
str - The string to write to the buffered socket
Returns:
A reference to this buffered socket


void close () throw(SocketException)
Flushes and closes the socket

Table of Contents HTML hierarchy of classes or Java


Safmq Documentation, copyright (c) 2004-2010 Matthew J. Battey, Licensed Under Apache License Ver 2.0
Powered By: Get SAFMQ: Store and Forward Message Queue at SourceForge.net. Fast, secure and Free Open Source software downloads