activemq-cpp-3.6.0
decaf::internal::net::tcp::TcpSocket Class Reference

Platform-independent implementation of the socket interface. More...

#include <src/main/decaf/internal/net/tcp/TcpSocket.h>

Inheritance diagram for decaf::internal::net::tcp::TcpSocket:

Public Member Functions

 TcpSocket ()
 Construct a non-connected socket.
virtual ~TcpSocket ()
 Releases the socket handle but not gracefully shut down the connection.
bool isConnected () const
bool isClosed () const
virtual std::string getLocalAddress () const
 Gets the value of the local Inet address the Socket is bound to if bound, otherwise return the InetAddress ANY value "0.0.0.0".
Returns
the local address bound to, or ANY.

virtual void create ()
 Creates the underlying platform Socket data structures which allows for Socket options to be applied.The created socket is in an unconnected state.
Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

virtual void accept (SocketImpl *socket)
 
virtual void bind (const std::string &ipaddress, int port)
 Binds this Socket instance to the local ip address and port number given.
Parameters
ipaddressThe address of local ip to bind to.
portThe port number on the host to bind to.
Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

virtual void connect (const std::string &hostname, int port, int timeout)
 Connects this socket to the given host and port.
Parameters
hostnameThe name of the host to connect to, or IP address.
portThe port number on the host to connect to.
timeoutTime in milliseconds to wait for a connection, 0 indicates forever.
Exceptions
IOExceptionif an I/O error occurs while attempting this operation.
SocketTimeoutExceptionif the connect call times out due to timeout being set.
IllegalArguementExceptionif a parameter has an illegal value.

virtual void listen (int backlog)
 Sets the maximum queue length for incoming connection indications (a request to connect) to the count argument.If a connection indication arrives when the queue is full, the connection is refused.
Parameters
backlogThe maximum length of the connection queue.
Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

virtual decaf::io::InputStreamgetInputStream ()
 Gets the InputStream linked to this Socket.
Returns
an InputStream pointer owned by the Socket object.
Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

virtual decaf::io::OutputStreamgetOutputStream ()
 Gets the OutputStream linked to this Socket.
Returns
an OutputStream pointer owned by the Socket object.
Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

virtual int available ()
 Gets the number of bytes that can be read from the Socket without blocking.
Returns
the number of bytes that can be read from the Socket without blocking.
Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

virtual void close ()
 Closes the socket, terminating any blocked reads or writes.
Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

virtual void shutdownInput ()
 Places the input stream for this socket at "end of stream".Any data sent to this socket is acknowledged and then silently discarded. If you read from a socket input stream after invoking shutdownInput() on the socket, the stream will return EOF.
Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

virtual void shutdownOutput ()
 Disables the output stream for this socket.For a TCP socket, any previously written data will be sent followed by TCP's normal connection termination sequence. If you write to a socket output stream after invoking shutdownOutput() on the socket, the stream will throw an IOException.
Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

virtual int getOption (int option) const
 Gets the specified Socket option.
Parameters
optionThe Socket options whose value is to be retrieved.
Returns
the value of the given socket option.
Exceptions
IOExceptionif an I/O error occurs while performing this operation.

virtual void setOption (int option, int value)
 Sets the specified option on the Socket if supported.
Parameters
optionThe Socket option to set.
valueThe value of the socket option to apply to the socket.
Exceptions
IOExceptionif an I/O error occurs while performing this operation.

int read (unsigned char *buffer, int size, int offset, int length)
 Reads the requested data from the Socket and write it into the passed in buffer.
void write (const unsigned char *buffer, int size, int offset, int length)
 Writes the specified data in the passed in buffer to the Socket.
- Public Member Functions inherited from decaf::net::SocketImpl
 SocketImpl ()
virtual ~SocketImpl ()
virtual void accept (SocketImpl *socket)=0
 Accepts a new connection on the given Socket.
int getPort () const
 Gets the port that this socket has been assigned.
int getLocalPort () const
 Gets the value of this SocketImpl's local port field.
std::string getInetAddress () const
 Gets the value of this SocketImpl's address field.
const decaf::io::FileDescriptorgetFileDescriptor () const
 Gets the FileDescriptor for this Socket, the Object is owned by this Socket and should not be deleted by the caller.
std::string toString () const
 Returns a string containing the address and port of this Socket instance.
virtual bool supportsUrgentData () const
virtual void sendUrgentData (int data)
 Sends on byte of urgent data to the Socket.
- Public Member Functions inherited from decaf::net::SocketOptions
virtual ~SocketOptions ()

Protected Member Functions

void checkResult (apr_status_t value) const

Additional Inherited Members

- Static Public Attributes inherited from decaf::net::SocketOptions
static const int SOCKET_OPTION_TCP_NODELAY
 Disable Nagle's algorithm for this connection.
static const int SOCKET_OPTION_BINDADDR
 Fetch the local address binding of a socket (this option cannot be "set" only "gotten", since sockets are bound at creation time, and so the locally bound address cannot be changed).
static const int SOCKET_OPTION_REUSEADDR
 Sets SO_REUSEADDR for a socket.
static const int SOCKET_OPTION_BROADCAST
 Sets SO_BROADCAST for a socket.
static const int SOCKET_OPTION_IP_MULTICAST_IF
 Set which outgoing interface on which to send multicast packets.
static const int SOCKET_OPTION_IP_MULTICAST_IF2
 Same as above.
static const int SOCKET_OPTION_IP_MULTICAST_LOOP
 This option enables or disables local loopback of multicast datagrams.
static const int SOCKET_OPTION_IP_TOS
 This option sets the type-of-service or traffic class field in the IP header for a TCP or UDP socket.
static const int SOCKET_OPTION_LINGER
 Specify a linger-on-close timeout.
static const int SOCKET_OPTION_TIMEOUT
 Set a timeout on blocking Socket operations.
static const int SOCKET_OPTION_SNDBUF
 Set a hint the size of the underlying buffers used by the platform for outgoing network I/O.
static const int SOCKET_OPTION_RCVBUF
 Set a hint the size of the underlying buffers used by the platform for incoming network I/O.
static const int SOCKET_OPTION_KEEPALIVE
 When the keepalive option is set for a TCP socket and no data has been exchanged across the socket in either direction for 2 hours (NOTE: the actual value is implementation dependent), TCP automatically sends a keepalive probe to the peer.
static const int SOCKET_OPTION_OOBINLINE
 When the OOBINLINE option is set, any TCP urgent data received on the socket will be received through the socket input stream.
- Protected Attributes inherited from decaf::net::SocketImpl
int port
 The remote port that this Socket is connected to.
int localPort
 The port on the Local Machine that this Socket is Bound to.
std::string address
 The Remote Address that the Socket is connected to.
io::FileDescriptorfd
 The File Descriptor for this Socket.

Detailed Description

Platform-independent implementation of the socket interface.

Constructor & Destructor Documentation

decaf::internal::net::tcp::TcpSocket::TcpSocket ( )

Construct a non-connected socket.

Exceptions
SocketExceptionthrown if an error occurs while creating the Socket.
virtual decaf::internal::net::tcp::TcpSocket::~TcpSocket ( )
virtual

Releases the socket handle but not gracefully shut down the connection.

Member Function Documentation

virtual void decaf::internal::net::tcp::TcpSocket::accept ( SocketImpl *  socket)
virtual

virtual int decaf::internal::net::tcp::TcpSocket::available ( )
virtual

Gets the number of bytes that can be read from the Socket without blocking.

Returns
the number of bytes that can be read from the Socket without blocking.
Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

Implements decaf::net::SocketImpl.

virtual void decaf::internal::net::tcp::TcpSocket::bind ( const std::string &  ipaddress,
int  port 
)
virtual

Binds this Socket instance to the local ip address and port number given.

Parameters
ipaddressThe address of local ip to bind to.
portThe port number on the host to bind to.
Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

Implements decaf::net::SocketImpl.

void decaf::internal::net::tcp::TcpSocket::checkResult ( apr_status_t  value) const
protected
virtual void decaf::internal::net::tcp::TcpSocket::close ( )
virtual

Closes the socket, terminating any blocked reads or writes.

Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

Implements decaf::net::SocketImpl.

virtual void decaf::internal::net::tcp::TcpSocket::connect ( const std::string &  hostname,
int  port,
int  timeout 
)
virtual

Connects this socket to the given host and port.

Parameters
hostnameThe name of the host to connect to, or IP address.
portThe port number on the host to connect to.
timeoutTime in milliseconds to wait for a connection, 0 indicates forever.
Exceptions
IOExceptionif an I/O error occurs while attempting this operation.
SocketTimeoutExceptionif the connect call times out due to timeout being set.
IllegalArguementExceptionif a parameter has an illegal value.

Implements decaf::net::SocketImpl.

virtual void decaf::internal::net::tcp::TcpSocket::create ( )
virtual

Creates the underlying platform Socket data structures which allows for Socket options to be applied.The created socket is in an unconnected state.

Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

Implements decaf::net::SocketImpl.

virtual decaf::io::InputStream* decaf::internal::net::tcp::TcpSocket::getInputStream ( )
virtual

Gets the InputStream linked to this Socket.

Returns
an InputStream pointer owned by the Socket object.
Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

Implements decaf::net::SocketImpl.

virtual std::string decaf::internal::net::tcp::TcpSocket::getLocalAddress ( ) const
virtual

Gets the value of the local Inet address the Socket is bound to if bound, otherwise return the InetAddress ANY value "0.0.0.0".

Returns
the local address bound to, or ANY.

Implements decaf::net::SocketImpl.

virtual int decaf::internal::net::tcp::TcpSocket::getOption ( int  option) const
virtual

Gets the specified Socket option.

Parameters
optionThe Socket options whose value is to be retrieved.
Returns
the value of the given socket option.
Exceptions
IOExceptionif an I/O error occurs while performing this operation.

Implements decaf::net::SocketImpl.

virtual decaf::io::OutputStream* decaf::internal::net::tcp::TcpSocket::getOutputStream ( )
virtual

Gets the OutputStream linked to this Socket.

Returns
an OutputStream pointer owned by the Socket object.
Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

Implements decaf::net::SocketImpl.

bool decaf::internal::net::tcp::TcpSocket::isClosed ( ) const
Returns
true if the close method has been called on this Socket.
bool decaf::internal::net::tcp::TcpSocket::isConnected ( ) const
Returns
true if the socketHandle is not in a disconnected state.
virtual void decaf::internal::net::tcp::TcpSocket::listen ( int  backlog)
virtual

Sets the maximum queue length for incoming connection indications (a request to connect) to the count argument.If a connection indication arrives when the queue is full, the connection is refused.

Parameters
backlogThe maximum length of the connection queue.
Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

Implements decaf::net::SocketImpl.

int decaf::internal::net::tcp::TcpSocket::read ( unsigned char *  buffer,
int  size,
int  offset,
int  length 
)

Reads the requested data from the Socket and write it into the passed in buffer.

Parameters
bufferThe buffer to read into
sizeThe size of the specified buffer
offsetThe offset into the buffer where reading should start filling.
lengthThe number of bytes past offset to fill with data.
Returns
the actual number of bytes read or -1 if at EOF.
Exceptions
IOExceptionif an I/O error occurs during the read.
NullPointerExceptionif buffer is Null.
IndexOutOfBoundsExceptionif offset + length is greater than buffer size.
virtual void decaf::internal::net::tcp::TcpSocket::setOption ( int  option,
int  value 
)
virtual

Sets the specified option on the Socket if supported.

Parameters
optionThe Socket option to set.
valueThe value of the socket option to apply to the socket.
Exceptions
IOExceptionif an I/O error occurs while performing this operation.

Implements decaf::net::SocketImpl.

virtual void decaf::internal::net::tcp::TcpSocket::shutdownInput ( )
virtual

Places the input stream for this socket at "end of stream".Any data sent to this socket is acknowledged and then silently discarded. If you read from a socket input stream after invoking shutdownInput() on the socket, the stream will return EOF.

Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

Implements decaf::net::SocketImpl.

virtual void decaf::internal::net::tcp::TcpSocket::shutdownOutput ( )
virtual

Disables the output stream for this socket.For a TCP socket, any previously written data will be sent followed by TCP's normal connection termination sequence. If you write to a socket output stream after invoking shutdownOutput() on the socket, the stream will throw an IOException.

Exceptions
IOExceptionif an I/O error occurs while attempting this operation.

Implements decaf::net::SocketImpl.

void decaf::internal::net::tcp::TcpSocket::write ( const unsigned char *  buffer,
int  size,
int  offset,
int  length 
)

Writes the specified data in the passed in buffer to the Socket.

Parameters
bufferThe buffer to write to the socket.
sizeThe size of the specified buffer.
offsetThe offset into the buffer where the data to write starts at.
lengthThe number of bytes past offset to write.
Exceptions
IOExceptionif an I/O error occurs during the write.
NullPointerExceptionif buffer is Null.
IndexOutOfBoundsExceptionif offset + length is greater than buffer size.

The documentation for this class was generated from the following file: