vpr::Socket_t< SockConfig_ > Class Template Reference

Cross-platform block-based socket interface. More...

#include <vpr/IO/Socket/Socket_t.h>

Inheritance diagram for vpr::Socket_t< SockConfig_ >:

Inheritance graph
[legend]
Collaboration diagram for vpr::Socket_t< SockConfig_ >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef SockConfig_ Config
typedef Config::SocketImpl SocketImpl
typedef Config::SocketIOStatsStrategy DefaultIOStatsStrategy

Public Member Functions

virtual const std::string & getName () const
 Gets the "name" of this socket.
vpr::ReturnStatus open ()
 Opens the socket.
vpr::ReturnStatus close ()
 Closes the socket.
bool isOpen () const
 Gets the open state of this socket.
bool isBound () const
 Gets the bound state of this socket.
bool isConnected () const
 Gets the status of a possibly connected socket.
vpr::IOSys::Handle getHandle () const
 Gets the handle to this socket.
bool isBlockingFixed () const
 Queries if the blocking state for this socket is fixed and can no longer be changed.
vpr::ReturnStatus setBlocking (bool blocking)
 Reconfigures the socket so that it is in blocking or non-blocking mode depending on the value of the parameter.
bool isBlocking () const
 Gets the current blocking state for the socket.
vpr::ReturnStatus bind ()
 Binds this socket to the address in the host address member variable.
vpr::ReturnStatus connect (const vpr::Interval timeout=vpr::Interval::NoTimeout)
 Connects the socket on the client side to the server side.
vpr::ReturnStatus recv (void *buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout)
 Receives at most the specified number of bytes from the socket into the given buffer.
vpr::ReturnStatus recv (std::string &buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout)
 Receives at most the specified number of bytes from the socket into the given buffer.
vpr::ReturnStatus recv (std::vector< vpr::Uint8 > &buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout)
 Receives at most the specified number of bytes from the socket into the given buffer.
vpr::ReturnStatus recvn (void *buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout)
 Receives exactly the specified number of bytes from the socket into the given buffer.
vpr::ReturnStatus recvn (std::string &buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout)
 Receives exactly the specified number of bytes from the socket into the given buffer.
vpr::ReturnStatus recvn (std::vector< vpr::Uint8 > &buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout)
 Receives exactly the specified number of bytes from the socket into the given buffer.
virtual vpr::Uint32 availableBytes () const
 Returns the number of avaiable bytes for reading.
vpr::ReturnStatus send (const void *buffer, const vpr::Uint32 length, vpr::Uint32 &bytesWritten, const vpr::Interval timeout=vpr::Interval::NoTimeout)
 Sends the buffer to the remote side of the socket.
vpr::ReturnStatus send (const std::string &buffer, const vpr::Uint32 length, vpr::Uint32 &bytesWritten, const vpr::Interval timeout=vpr::Interval::NoTimeout)
 Sends the buffer to the remote side of the socket.
vpr::ReturnStatus send (const std::vector< vpr::Uint8 > &buffer, const vpr::Uint32 length, vpr::Uint32 &bytesWritten, const vpr::Interval timeout=vpr::Interval::NoTimeout)
 Sends the buffer to the remote side of the socket.
const vpr::SocketTypes::TypegetType () const
 Gets the type of this socket (e.g., vpr::SocketTypes::STREAM).
const InetAddrgetLocalAddr () const
vpr::ReturnStatus setLocalAddr (const InetAddr &addr)
const InetAddrgetRemoteAddr () const
vpr::ReturnStatus setRemoteAddr (const InetAddr &addr)

Public Attributes

boost::shared_ptr< SocketImplmSocketImpl
 Platform-specific socket implementation object.

Protected Member Functions

 Socket_t ()
 Default constructor.
 Socket_t (const std::string &address)
 Constructor.
virtual ~Socket_t ()
 Destructor.
void initSocket_t ()
 Helper function to capture code common between constructors.
virtual vpr::ReturnStatus read_i (void *buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout)
 Implementation of the read() template method.
virtual vpr::ReturnStatus readn_i (void *buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout)
 Implementation of the readn() template method.
virtual vpr::ReturnStatus write_i (const void *buffer, const vpr::Uint32 length, vpr::Uint32 &bytesWritten, const vpr::Interval timeout=vpr::Interval::NoTimeout)
 Implementation of the write() template method.
virtual vpr::ReturnStatus getOption (const vpr::SocketOptions::Types option, struct vpr::SocketOptions::Data &data) const
 Retrieves the value for the given option as set on the socket.
virtual vpr::ReturnStatus setOption (const vpr::SocketOptions::Types option, const struct vpr::SocketOptions::Data &data)
 Sets a value for the given option on the socket using the given data block.

Detailed Description

template<class SockConfig_>
class vpr::Socket_t< SockConfig_ >

Cross-platform block-based socket interface.

vpr::Socket objects cannot be instantiated. Instead, see vpr::SocketStream and vpr::SocketDatagram. Given a SocketConfiguration declaration, this class is typedef'd to vpr::Socket.

Parameters:
SockConfig_ The SocketConfiguration type that matches the platform-specific socket implementation to use.
See also:
vpr::SocketStream_t, vpr::SocketDatagram_t, vpr::SocketImplNSPR, vpr::SocketImplBSD

Definition at line 84 of file Socket_t.h.


Member Typedef Documentation

template<class SockConfig_>
typedef SockConfig_ vpr::Socket_t< SockConfig_ >::Config

Reimplemented in vpr::SocketDatagram_t< SocketConfig_ >, and vpr::SocketStream_t< SocketConfig_ >.

Definition at line 87 of file Socket_t.h.

template<class SockConfig_>
typedef Config::SocketImpl vpr::Socket_t< SockConfig_ >::SocketImpl

Definition at line 88 of file Socket_t.h.

template<class SockConfig_>
typedef Config::SocketIOStatsStrategy vpr::Socket_t< SockConfig_ >::DefaultIOStatsStrategy

Definition at line 89 of file Socket_t.h.


Constructor & Destructor Documentation

template<class SockConfig_>
vpr::Socket_t< SockConfig_ >::Socket_t (  )  [inline, protected]

Default constructor.

The socket address is set to "INADDRY_ANY", and the implementation socket is initialized to NULL.

Precondition:
None.
Postcondition:
"INADDR_ANY" is passed on to the vpr::BlockIO constructor, and mSocketImpl is set to NULL.

Definition at line 626 of file Socket_t.h.

00627       : vpr::BlockIO()
00628    {
00629       initSocket_t();
00630    }

template<class SockConfig_>
vpr::Socket_t< SockConfig_ >::Socket_t ( const std::string &  address  )  [inline, protected]

Constructor.

The socket address is set to the given address, and the implementation socket is initialized to NULL.

Precondition:
None.
Postcondition:
address is passed on to the vpr::BlockIO constructor, and mSocketImpl is set to NULL.
Parameters:
address The address string for this socket object.

Definition at line 642 of file Socket_t.h.

00643        : vpr::BlockIO(address)
00644    {
00645       initSocket_t();
00646    }

template<class SockConfig_>
virtual vpr::Socket_t< SockConfig_ >::~Socket_t (  )  [inline, protected, virtual]

Destructor.

If the socket implementation object pointer is non-NULL, its memory is released.

Precondition:
None.
Postcondition:
internal socket_impl* == NULL

Definition at line 655 of file Socket_t.h.

00656    {
00657 /*
00658       if(mSocketImpl != NULL)
00659          delete mSocketImpl;
00660 */
00661 
00662       //mSocketImpl = NULL;  // Don't destory because it is a member of the child class
00663       //                      // it will get destroyed on it's own
00664    }


Member Function Documentation

template<class SockConfig_>
virtual const std::string& vpr::Socket_t< SockConfig_ >::getName (  )  const [inline, virtual]

Gets the "name" of this socket.

It is typically the address of the peer host.

Returns:
An object containing the "name" of this socket.

Reimplemented from vpr::BlockIO.

Definition at line 102 of file Socket_t.h.

00103    {
00104       return mSocketImpl->getName();
00105    }

template<class SockConfig_>
vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::open (  )  [inline, virtual]

Opens the socket.

Precondition:
The socket is not already open.
Postcondition:
An attempt is made to open the socket. The resulting status is returned to the caller. If the socket is opened, mOpen is set to true.
Returns:
vpr::ReturnStatus::Succeed is returned if this socket is opened successfully.

vpr::ReturnStatus::Fail is returned otherwise.

Implements vpr::BlockIO.

Definition at line 119 of file Socket_t.h.

Referenced by vpr::SocketConnector::checkOpen(), and vpr::SocketAcceptor::open().

00120    {
00121       return mSocketImpl->open();
00122    }

template<class SockConfig_>
vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::close (  )  [inline, virtual]

Closes the socket.

Precondition:
The socket is open.
Postcondition:
An attempt is made to close the socket. The resulting status is returned to the caller. If the socket is closed, mOpen is set to false.
Returns:
vpr::ReturnStatus::Succeed is returned if this socket is closed successfully.

vpr::ReturnStatus::Fail is returned otherwise.

Implements vpr::BlockIO.

Definition at line 136 of file Socket_t.h.

Referenced by vpr::SocketAcceptor::open().

00137    {
00138       return mSocketImpl->close();
00139    }

template<class SockConfig_>
bool vpr::Socket_t< SockConfig_ >::isOpen (  )  const [inline, virtual]

Gets the open state of this socket.

Precondition:
None.
Postcondition:
The boolean value giving the open state is returned to the caller.
Returns:
true is returned if this socket is open; false otherwise.

Reimplemented from vpr::BlockIO.

Definition at line 151 of file Socket_t.h.

Referenced by vpr::SocketConnector::checkOpen(), vpr::SocketConnector::connectStart(), and vpr::SocketAcceptor::open().

00152    {
00153       return mSocketImpl->isOpen();
00154    }

template<class SockConfig_>
bool vpr::Socket_t< SockConfig_ >::isBound (  )  const [inline]

Gets the bound state of this socket.

Precondition:
None.
Postcondition:
The boolean value giving the bound state is returned
Returns:
true is returned if this socket is bound; false otherwise.

Definition at line 165 of file Socket_t.h.

Referenced by vpr::SocketConnector::connectStart().

00166    {
00167       return mSocketImpl->isBound();
00168    }

template<class SockConfig_>
bool vpr::Socket_t< SockConfig_ >::isConnected (  )  const [inline]

Gets the status of a possibly connected socket.

Returns:
true is returned if this socket is connected to a remote address.

false is returned if this socket is not currently connected (the other wise may have disconnected).

Definition at line 178 of file Socket_t.h.

Referenced by vpr::SocketConnector::complete().

00179    {
00180       return mSocketImpl->isConnected();
00181    }

template<class SockConfig_>
vpr::IOSys::Handle vpr::Socket_t< SockConfig_ >::getHandle (  )  const [inline, virtual]

Gets the handle to this socket.

Implements vpr::BlockIO.

Definition at line 184 of file Socket_t.h.

Referenced by vpr::SocketConnector::complete().

00185    {
00186       return mSocketImpl->getHandle();
00187    }

template<class SockConfig_>
bool vpr::Socket_t< SockConfig_ >::isBlockingFixed (  )  const [inline]

Queries if the blocking state for this socket is fixed and can no longer be changed.

Definition at line 193 of file Socket_t.h.

00194    {
00195       return mSocketImpl->isBlockingFixed();
00196    }

template<class SockConfig_>
vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::setBlocking ( bool  blocking  )  [inline, virtual]

Reconfigures the socket so that it is in blocking or non-blocking mode depending on the value of the parameter.

If the socket has not been opened yet, it will be opened in blocking or non-blocking mode appropriately when open() is called.

Postcondition:
Processes will block when accessing the socket.
Parameters:
blocking A value of true indicates that the socket should be configure to use blocking I/O. A value of false indicates that it should use non-blocking I/O.
Returns:
vpr::ReturnStatus::Succeed is returned if the socket's blocking mode is set to blocking. vpr::ReturnStatus::Fail is returned otherwise.

Implements vpr::BlockIO.

Definition at line 214 of file Socket_t.h.

Referenced by vpr::SocketConnector::connectStart().

00215    {
00216       return mSocketImpl->setBlocking(blocking);
00217    }

template<class SockConfig_>
bool vpr::Socket_t< SockConfig_ >::isBlocking (  )  const [inline, virtual]

Gets the current blocking state for the socket.

Precondition:
The blocking mode on the internal socket implementation is set correctly.
Returns:
true is returned if the socket is in blocking mode. Otherwise, false is returned.

Reimplemented from vpr::BlockIO.

Definition at line 228 of file Socket_t.h.

Referenced by vpr::SocketConnector::complete().

00229    {
00230       return mSocketImpl->isBlocking();
00231    }

template<class SockConfig_>
vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::bind (  )  [inline]

Binds this socket to the address in the host address member variable.

Precondition:
The socket is open.
Postcondition:
The socket is bound to the address defined in the constructor.
Returns:
vpr::ReturnStatus::Succeed is returned if this socket was bound to its designated local address successfully.

vpr::ReturnStatus::Fail is returned otherwise.

Definition at line 243 of file Socket_t.h.

Referenced by vpr::SocketConnector::connectStart(), and vpr::SocketAcceptor::open().

00244    {
00245       return mSocketImpl->bind();
00246    }

template<class SockConfig_>
vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::connect ( const vpr::Interval  timeout = vpr::Interval::NoTimeout  )  [inline]

Connects the socket on the client side to the server side.

For a datagram socket, this makes the address given to the constructor the default destination for all packets. For a stream socket, this has the effect of establishing a connection with the destination.

Precondition:
The socket is open.
Postcondition:
The socket is connected to the address in mLocalAddr. For a stream socket, this means that a connection for future communication has been established. For a datagram socket, the default destination for all packets is now mLocalAddr.
Returns:
vpr::ReturnStatus::Succeed is returned if the connection succeeded.

vpr::ReturnStatus::InProgress is returned if this is a non-blocking socket and the connection is still in progress. The connection will be completed "in the background".

vpr::ReturnStatus::Timeout is returned if the connection could not be made within the given timeout interval.

vpr::ReturnStatus::Fail is returned if the connection could not be made.

Definition at line 274 of file Socket_t.h.

Referenced by vpr::SocketConnector::connect().

00275    {
00276       return mSocketImpl->connect(timeout);
00277    }

template<class SockConfig_>
vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::recv ( void *  buffer,
const vpr::Uint32  length,
vpr::Uint32 bytesRead,
const vpr::Interval  timeout = vpr::Interval::NoTimeout 
) [inline]

Receives at most the specified number of bytes from the socket into the given buffer.

Precondition:
The socket is open for reading, and the buffer is at least length bytes long.
Postcondition:
The given buffer has length bytes copied into it from the socket, and the number of bytes read successfully is returned to the caller via the bytesRead argument.
Parameters:
buffer A pointer to the buffer where the socket's buffer contents are to be stored.
length The number of bytes to be read.
bytesRead The number of bytes read into the buffer.
timeout The maximum amount of time to wait for data to be available for reading. This argument is optional and defaults to vpr::Interval::NoTimeout.
Returns:
vpr::ReturnStatus::Succeed is returned if the read operation completed successfully.

vpr::ReturnStatus::Fail is returned if the read operation failed.

vpr::ReturnStatus::WouldBlock if the device is in non-blocking mode, and there is no data to receive.

vpr::ReturnStatus::Timeout is returned if the read could not begin within the timeout interval.

Definition at line 305 of file Socket_t.h.

00308    {
00309       return read(buffer, length, bytesRead, timeout);
00310    }

template<class SockConfig_>
vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::recv ( std::string &  buffer,
const vpr::Uint32  length,
vpr::Uint32 bytesRead,
const vpr::Interval  timeout = vpr::Interval::NoTimeout 
) [inline]

Receives at most the specified number of bytes from the socket into the given buffer.

Precondition:
The device is open for reading, and the buffer is at least length bytes long.
Postcondition:
The given buffer has length bytes copied into it from the device, and the number of bytes read successfully is returned to the caller via the bytesRead argument.
Parameters:
buffer A reference to the buffer (a std::string object) where the device's buffer contents are to be stored.
length The number of bytes to be read.
bytesRead The number of bytes read into the buffer.
timeout The maximum amount of time to wait for data to be available for reading. This argument is optional and defaults to vpr::Interval::NoTimeout.
Returns:
vpr::ReturnStatus::Succeed is returned if the read operation completed successfully.

vpr::ReturnStatus::Fail is returned if the read operation failed.

vpr::ReturnStatus::WouldBlock if the device is in non-blocking mode, and there is no data to receive.

vpr::ReturnStatus::Timeout is returned if the read could not begin within the timeout interval.

Definition at line 339 of file Socket_t.h.

00342    {
00343       return read(buffer, length, bytesRead, timeout);
00344    }

template<class SockConfig_>
vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::recv ( std::vector< vpr::Uint8 > &  buffer,
const vpr::Uint32  length,
vpr::Uint32 bytesRead,
const vpr::Interval  timeout = vpr::Interval::NoTimeout 
) [inline]

Receives at most the specified number of bytes from the socket into the given buffer.

Precondition:
The device is open for reading, and the buffer is at least length bytes long.
Postcondition:
The given buffer has length bytes copied into it from the device, and the number of bytes read successfully is returned to the caller via the bytesRead argument.
Parameters:
buffer A pointer to the buffer (a vector of chars) where the device's buffer contents are to be stored.
length The number of bytes to be read.
bytesRead The number of bytes read into the buffer.
timeout The maximum amount of time to wait for data to be available for reading. This argument is optional and defaults to vpr::Interval::NoTimeout.
Returns:
vpr::ReturnStatus::Succeed is returned if the read operation completed successfully.

vpr::ReturnStatus::Fail is returned if the read operation failed.

vpr::ReturnStatus::WouldBlock if the device is in non-blocking mode, and there is no data to receive.

vpr::ReturnStatus::Timeout is returned if the read could not begin within the timeout interval.

Definition at line 373 of file Socket_t.h.

00376    {
00377       return read(buffer, length, bytesRead, timeout);
00378    }

template<class SockConfig_>
vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::recvn ( void *  buffer,
const vpr::Uint32  length,
vpr::Uint32 bytesRead,
const vpr::Interval  timeout = vpr::Interval::NoTimeout 
) [inline]

Receives exactly the specified number of bytes from the socket into the given buffer.

Precondition:
The device is open for reading, and the buffer is at least length bytes long.
Postcondition:
The given buffer has length bytes copied into it from the device, and the number of bytes read successfully is returned to the caller via the bytesRead parameter.
Parameters:
buffer A pointer to the buffer where the device's buffer contents are to be stored.
length The number of bytes to be read.
bytesRead The number of bytes read into the buffer.
timeout The maximum amount of time to wait for data to be available for reading. This argument is optional and defaults to vpr::Interval::NoTimeout.
Returns:
vpr::ReturnStatus::Succeed is returned if the read operation completed successfully.

vpr::ReturnStatus::Fail is returned if the read operation failed.

vpr::ReturnStatus::WouldBlock if the device is in non-blocking mode, and there is no data to receive.

Definition at line 404 of file Socket_t.h.

00407    {
00408       return readn(buffer, length, bytesRead, timeout);
00409    }

template<class SockConfig_>
vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::recvn ( std::string &  buffer,
const vpr::Uint32  length,
vpr::Uint32 bytesRead,
const vpr::Interval  timeout = vpr::Interval::NoTimeout 
) [inline]

Receives exactly the specified number of bytes from the socket into the given buffer.

Precondition:
The device is open for reading, and the buffer is at least length bytes long.
Postcondition:
The given buffer has length bytes copied into it from the device, and the number of bytes read successfully is returned to the caller via the bytesRead parameter.
Parameters:
buffer A reference to the buffer (a std::string object) where the device's buffer contents are to be stored.
length The number of bytes to be read.
bytesRead The number of bytes read into the buffer.
timeout The maximum amount of time to wait for data to be available for reading. This argument is optional and defaults to vpr::Interval::NoTimeout.
Returns:
vpr::ReturnStatus::Succeed is returned if the read operation completed successfully. vpr::ReturnStatus::Fail is returned if the read operation failed. vpr::ReturnStatus::WouldBlock if the device is in non-blocking mode, and there is no data to receive.

Definition at line 437 of file Socket_t.h.

00440    {
00441       return readn(buffer, length, bytesRead, timeout);
00442    }

template<class SockConfig_>
vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::recvn ( std::vector< vpr::Uint8 > &  buffer,
const vpr::Uint32  length,
vpr::Uint32 bytesRead,
const vpr::Interval  timeout = vpr::Interval::NoTimeout 
) [inline]

Receives exactly the specified number of bytes from the socket into the given buffer.

Precondition:
The device is open for reading, and the buffer is at least length bytes long.
Postcondition:
The given buffer has length bytes copied into it from the device, and the number of bytes read successfully is returned to the caller.
Parameters:
buffer A pointer to the buffer (a vector of chars) where the device's buffer contents are to be stored.
length The number of bytes to be read.
bytesRead The number of bytes read into the buffer.
timeout The maximum amount of time to wait for data to be available for reading. This argument is optional and defaults to vpr::Interval::NoTimeout.
Returns:
vpr::ReturnStatus::Succeed is returned if the read operation completed successfully.

vpr::ReturnStatus::Fail is returned if the read operation failed.

vpr::ReturnStatus::WouldBlock if the device is in non-blocking mode, and there is no data to receive.

vpr::ReturnStatus::Timeout is returned if the read could not begin within the timeout interval.

Definition at line 471 of file Socket_t.h.

00474    {
00475       return readn(buffer, length, bytesRead, timeout);
00476    }

template<class SockConfig_>
virtual vpr::Uint32 vpr::Socket_t< SockConfig_ >::availableBytes (  )  const [inline, virtual]

Returns the number of avaiable bytes for reading.

Reimplemented from vpr::BlockIO.

Definition at line 479 of file Socket_t.h.

00480    {
00481       return mSocketImpl->availableBytes();
00482    }

template<class SockConfig_>
vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::send ( const void *  buffer,
const vpr::Uint32  length,
vpr::Uint32 bytesWritten,
const vpr::Interval  timeout = vpr::Interval::NoTimeout 
) [inline]

Sends the buffer to the remote side of the socket.

Precondition:
The device is open for writing.
Postcondition:
The given buffer is written to the I/O device, and the number of bytes written successfully is returned to the caller via the bytesWritten parameter.
Parameters:
buffer A pointer to the buffer to be written.
length The length of the buffer.
bytesWritten The number of bytes written to the device.
timeout The maximum amount of time to wait for data to be available for writing. This argument is optional and defaults to vpr::Interval::NoTimeout.
Returns:
vpr::ReturnStatus::Succeed is returned if the write operation completed successfully.

vpr::ReturnStatus::Fail is returned if the write operation failed.

vpr::ReturnStatus::WouldBlock is returned if the handle is in non-blocking mode, and the write operation could not be completed.

vpr::ReturnStatus::Timeout is returned if the write could not begin within the timeout interval.

Definition at line 509 of file Socket_t.h.

00512    {
00513       return write(buffer, length, bytesWritten, timeout);
00514    }

template<class SockConfig_>
vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::send ( const std::string &  buffer,
const vpr::Uint32  length,
vpr::Uint32 bytesWritten,
const vpr::Interval  timeout = vpr::Interval::NoTimeout 
) [inline]

Sends the buffer to the remote side of the socket.

Precondition:
The device is open for writing.
Postcondition:
The given buffer is written to the I/O device, and the number of bytes written successfully is returned to the caller via the bytesWritten parameter.
Parameters:
buffer A reference to the buffer (a std::string object) to be written.
length The length of the buffer.
bytesWritten The number of bytes written to the device.
timeout The maximum amount of time to wait for data to be available for writing. This argument is optional and defaults to vpr::Interval::NoTimeout.
Returns:
vpr::ReturnStatus::Succeed is returned if the write operation completed successfully.

vpr::ReturnStatus::Fail is returned if the write operation failed.

vpr::ReturnStatus::WouldBlock is returned if the handle is in non-blocking mode, and the send operation could not be completed.

vpr::ReturnStatus::Timeout is returned if the write could not begin within the timeout interval.

Definition at line 541 of file Socket_t.h.

00544    {
00545       vprASSERT(length <= buffer.size() && "length was bigger than the data given");
00546       return write(buffer, length, bytesWritten, timeout);
00547    }

template<class SockConfig_>
vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::send ( const std::vector< vpr::Uint8 > &  buffer,
const vpr::Uint32  length,
vpr::Uint32 bytesWritten,
const vpr::Interval  timeout = vpr::Interval::NoTimeout 
) [inline]

Sends the buffer to the remote side of the socket.

Precondition:
The device is open for writing.
Postcondition:
The given buffer is written to the I/O device, and the number of bytes written successfully is returned to the caller via the bytesWritten parameter.
Parameters:
buffer A reference to the buffer (a std::string object) to be written.
length The length of the buffer.
bytesWritten The number of bytes written to the device.
timeout The maximum amount of time to wait for data to be available for writing. This argument is optional and defaults to vpr::Interval::NoTimeout.
Returns:
vpr::ReturnStatus::Succeed is returned if the write operation completed successfully.

vpr::ReturnStatus::Fail is returned if the write operation failed.

vpr::ReturnStatus::WoudlBlock is returned if the handle is in non-blocking mode, and the send operation could not be completed.

vpr::ReturnStatus::Timeout is returned if the write could not begin within the timeout interval.

Definition at line 574 of file Socket_t.h.

00578    {
00579       vprASSERT(length <= buffer.size() && "length was bigger than the data given");
00580       return write(buffer, length, bytesWritten,timeout);
00581    }

template<class SockConfig_>
const vpr::SocketTypes::Type& vpr::Socket_t< SockConfig_ >::getType (  )  const [inline]

Gets the type of this socket (e.g., vpr::SocketTypes::STREAM).

Precondition:
The socket implementation pointer is valid.
Postcondition:
The socket type for mSocketImpl is returned to the caller.
Returns:
A vpr::SocketTypes::Type value giving the socket type for this socket.

Definition at line 592 of file Socket_t.h.

00593    {
00594       return mSocketImpl->getType();
00595    }

template<class SockConfig_>
const InetAddr& vpr::Socket_t< SockConfig_ >::getLocalAddr (  )  const [inline]

Definition at line 597 of file Socket_t.h.

00598    {
00599       return mSocketImpl->getLocalAddr();
00600    }

template<class SockConfig_>
vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::setLocalAddr ( const InetAddr addr  )  [inline]

Definition at line 602 of file Socket_t.h.

Referenced by vpr::SocketConnector::connectStart(), and vpr::SocketAcceptor::open().

00603    {
00604       return mSocketImpl->setLocalAddr(addr);
00605    }

template<class SockConfig_>
const InetAddr& vpr::Socket_t< SockConfig_ >::getRemoteAddr (  )  const [inline]

Definition at line 607 of file Socket_t.h.

00608    {
00609       return mSocketImpl->getRemoteAddr();
00610    }

template<class SockConfig_>
vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::setRemoteAddr ( const InetAddr addr  )  [inline]

Definition at line 612 of file Socket_t.h.

Referenced by vpr::SocketConnector::connect().

00613    {
00614       return mSocketImpl->setRemoteAddr(addr);
00615    }

template<class SockConfig_>
void vpr::Socket_t< SockConfig_ >::initSocket_t (  )  [inline, protected]

Helper function to capture code common between constructors.

Definition at line 669 of file Socket_t.h.

Referenced by vpr::Socket_t< SocketConfig_ >::Socket_t().

00670    {
00671       // Allocate stats stategy object.
00672       // First, use template programming magic.  If the stategy is the null
00673       // one, then don't allocate one.
00674       // NOTE: Because all the info is static the compiler "should" optimize
00675       // the following if statement away.
00676       if( DefaultIOStatsStrategy::IS_NULL == 0)     // If we have a real one
00677       {
00678          //std::cout << "Allocating strategy: " << typeid(DefaultIOStatsStrategy).name() << std::endl;
00679          BaseIOStatsStrategy* new_strategy = new DefaultIOStatsStrategy;
00680          this->setIOStatStrategy(new_strategy);
00681       }
00682    }

template<class SockConfig_>
virtual vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::read_i ( void *  buffer,
const vpr::Uint32  length,
vpr::Uint32 bytesRead,
const vpr::Interval  timeout = vpr::Interval::NoTimeout 
) [inline, protected, virtual]

Implementation of the read() template method.

This reads at most the specified number of bytes from the socket into the given buffer.

Precondition:
The device is open for reading, and the buffer is at least length bytes long.
Postcondition:
The given buffer has length bytes copied into it from the device, and the number of bytes read successfully is returned to the caller via the bytesRead parameter.
Parameters:
buffer A pointer to the buffer where the device's buffer contents are to be stored.
length The number of bytes to be read.
bytesRead The number of bytes read into the buffer.
timeout The maximum amount of time to wait for data to be available for reading. This argument is optional and defaults to vpr::Interval::NoTimeout.
Returns:
vpr::ReturnStatus::Succeed is returned if the read operation completed successfully.

vpr::ReturnStatus::WouldBlock if the device is in non-blocking mode, and there is no data to read.

vpr::ReturnStatus::Timeout is returned if the read could not begin within the timeout interval.

vpr::ReturnStatus::Fail is returned if the read operation failed.

Implements vpr::BlockIO.

Definition at line 711 of file Socket_t.h.

00714    {
00715       return mSocketImpl->read_i(buffer, length, bytesRead, timeout);
00716    }

template<class SockConfig_>
virtual vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::readn_i ( void *  buffer,
const vpr::Uint32  length,
vpr::Uint32 bytesRead,
const vpr::Interval  timeout = vpr::Interval::NoTimeout 
) [inline, protected, virtual]

Implementation of the readn() template method.

This reads exactly the specified number of bytes from the socket into the given buffer.

Precondition:
The device is open for reading, and the buffer is at least length bytes long.
Postcondition:
The given buffer has length bytes copied into it from the device, and the number of bytes read successfully is returned to the caller via the bytesRead parameter.
Parameters:
buffer A pointer to the buffer where the device's buffer contents are to be stored.
length The number of bytes to be read.
bytesRead The number of bytes read into the buffer.
timeout The maximum amount of time to wait for data to be available for reading. This argument is optional and defaults to vpr::Interval::NoTimeout.
Returns:
vpr::ReturnStatus::Succeed is returned if the read operation completed successfully.

vpr::ReturnStatus::WouldBlock if the device is in non-blocking mode, and there is no data to read.

vpr::ReturnStatus::Timeout is returned if the read could not begin within the timeout interval.

vpr::ReturnStatus::Fail is returned if the read operation failed.

Implements vpr::BlockIO.

Definition at line 745 of file Socket_t.h.

00748    {
00749       return mSocketImpl->readn_i(buffer, length, bytesRead, timeout);
00750    }

template<class SockConfig_>
virtual vpr::ReturnStatus vpr::Socket_t< SockConfig_ >::write_i ( const void *  buffer,
const vpr::Uint32  length,
vpr::Uint32 bytesWritten,
const vpr::Interval  timeout = vpr::Interval::NoTimeout 
) [inline, protected, virtual]

Implementation of the write() template method.

This writes the buffer to the socket.

Precondition:
The device is open for writing.
Postcondition:
The given buffer is written to the I/O device, and the number of bytes written successfully is returned to the caller via the bytesWritten parameter.
Parameters:
buffer A pointer to the buffer to be written.
length The length of the buffer.
bytesWritten The number of bytes written to the device.
timeout The maximum amount of time to wait for data to be available for writing. This argument is optional and defaults to vpr::Interval::NoTimeout.
Returns:
vpr::ReturnStatus::Succeed is returned if the write operation completed successfully.

vpr::ReturnStatus::WouldBlock is returned if the handle is in non-blocking mode, and the write could not be completed.

vpr::ReturnStatus::Timeout is returned if the write could not begin within the timeout interval.

vpr::ReturnStatus::Fail is returned if the write operation failed.

Implements vpr::BlockIO.

Definition at line 777 of file Socket_t.h.

00781    {
00782       return mSocketImpl->write_i(buffer, length, bytesWritten, timeout);
00783    }

template<class SockConfig_>
virtual vpr::ReturnStatus vpr::Soc