activemq-cpp-3.4.0
|
#include <src/main/decaf/net/Socket.h>
Public Member Functions | |
Socket () | |
Creates an unconnected Socket using the set SocketImplFactory or if non is set than the default SockImpl type is created. | |
Socket (SocketImpl *impl) | |
Creates a Socket wrapping the provided SocketImpl instance, this Socket is considered unconnected. | |
Socket (const InetAddress *address, int port) | |
Creates a new Socket instance and connects it to the given address and port. | |
Socket (const InetAddress *address, int port, const InetAddress *localAddress, int localPort) | |
Creates a new Socket instance and connects it to the given address and port. | |
Socket (const std::string &host, int port) | |
Creates a new Socket instance and connects it to the given host and port. | |
Socket (const std::string &host, int port, const InetAddress *localAddress, int localPort) | |
Creates a new Socket instance and connects it to the given host and port. | |
virtual | ~Socket () |
virtual void | bind (const std::string &ipaddress, int port) |
Binds this Socket to the given local address and port. | |
virtual void | close () |
Closes the Socket. | |
virtual void | connect (const std::string &host, int port) |
Connects to the specified destination. | |
virtual void | connect (const std::string &host, int port, int timeout) |
Connects to the specified destination, with a specified timeout value. | |
bool | isConnected () const |
Indicates whether or not this socket is connected to am end point. | |
bool | isClosed () const |
bool | isBound () const |
bool | isInputShutdown () const |
bool | isOutputShutdown () const |
virtual decaf::io::InputStream * | getInputStream () |
Gets the InputStream for this socket if its connected. | |
virtual decaf::io::OutputStream * | getOutputStream () |
Gets the OutputStream for this socket if it is connected. | |
int | getPort () const |
Gets the on the remote host this Socket is connected to. | |
int | getLocalPort () const |
Gets the local port the socket is bound to. | |
std::string | getInetAddress () const |
Returns the address to which the socket is connected. | |
std::string | getLocalAddress () const |
Gets the local address to which the socket is bound. | |
virtual void | shutdownInput () |
Shuts down the InputStream for this socket essentially marking it as EOF. | |
virtual void | shutdownOutput () |
Shuts down the OutputStream for this socket, any data already written to the socket will be sent, any further calls to OuputStream::write will throw an IOException. | |
virtual int | getSoLinger () const |
Gets the linger time for the socket, SO_LINGER. | |
virtual void | setSoLinger (bool state, int timeout) |
Sets the linger time (SO_LINGER) using a specified time value, this limits of this value are platform specific. | |
virtual bool | getKeepAlive () const |
Gets the keep alive flag for this socket, SO_KEEPALIVE. | |
virtual void | setKeepAlive (bool keepAlive) |
Enables/disables the keep alive flag for this socket, SO_KEEPALIVE. | |
virtual int | getReceiveBufferSize () const |
Gets the receive buffer size for this socket, SO_RCVBUF. | |
virtual void | setReceiveBufferSize (int size) |
Sets the receive buffer size for this socket, SO_RCVBUF. | |
virtual bool | getReuseAddress () const |
Gets the reuse address flag, SO_REUSEADDR. | |
virtual void | setReuseAddress (bool reuse) |
Sets the reuse address flag, SO_REUSEADDR. | |
virtual int | getSendBufferSize () const |
Gets the send buffer size for this socket, SO_SNDBUF, this value is used by the platform socket to buffer data written to the socket. | |
virtual void | setSendBufferSize (int size) |
Gets the send buffer size for this socket, SO_SNDBUF, this value is used by the platform socket to buffer data written to the socket. | |
virtual int | getSoTimeout () const |
Gets the timeout for socket operations, SO_TIMEOUT. | |
virtual void | setSoTimeout (int timeout) |
Sets the timeout for socket operations, SO_TIMEOUT. | |
virtual bool | getTcpNoDelay () const |
Gets the Status of the TCP_NODELAY setting for this socket. | |
virtual void | setTcpNoDelay (bool value) |
Sets the Status of the TCP_NODELAY param for this socket., this setting is used to disable or enable Nagle's algorithm on the Socket. | |
virtual int | getTrafficClass () const |
Gets the Traffic Class setting for this Socket, sometimes referred to as Type of Service setting. | |
virtual void | setTrafficClass (int value) |
Gets the Traffic Class setting for this Socket, sometimes referred to as Type of Service setting. | |
virtual bool | getOOBInline () const |
Gets the value of the OOBINLINE for this socket. | |
virtual void | setOOBInline (bool value) |
Sets the value of the OOBINLINE for this socket, by default this option is disabled. | |
virtual void | sendUrgentData (int data) |
Sends on byte of urgent data to the Socket. | |
virtual std::string | toString () const |
Static Public Member Functions | |
static void | setSocketImplFactory (SocketImplFactory *factory) |
Sets the instance of a SocketImplFactory that the Socket class should use when new instances of this class are created. | |
Protected Member Functions | |
void | accepted () |
void | initSocketImpl (const std::string &address, int port, const InetAddress *localAddress, int localPort) |
void | checkClosed () const |
void | ensureCreated () const |
Protected Attributes | |
SocketImpl * | impl |
Friends | |
class | ServerSocket |
decaf::net::Socket::Socket | ( | ) |
Creates an unconnected Socket using the set SocketImplFactory or if non is set than the default SockImpl type is created.
decaf::net::Socket::Socket | ( | SocketImpl * | impl | ) |
Creates a Socket wrapping the provided SocketImpl instance, this Socket is considered unconnected.
The Socket class takes ownership of this SocketImpl pointer and will delete it when the Socket class is destroyed.
impl | The SocketImpl instance to wrap. |
NullPointerException | if the passed SocketImpl is Null. |
decaf::net::Socket::Socket | ( | const InetAddress * | address, |
int | port | ||
) |
Creates a new Socket instance and connects it to the given address and port.
If there is a SocketImplFactory set then the SokcetImpl is created using the factory otherwise the default Socket implementation is used.
If the host parameter is empty then the loop back address is used.
address | The address to connect to. |
port | The port number to connect to [0...65535] |
UnknownHostException | if the host cannot be resolved. |
IOException | if an I/O error occurs while connecting the Socket. |
NullPointerException | if the InetAddress instance in NULL. |
IllegalArgumentException | if the port if not in range [0...65535] |
decaf::net::Socket::Socket | ( | const InetAddress * | address, |
int | port, | ||
const InetAddress * | localAddress, | ||
int | localPort | ||
) |
Creates a new Socket instance and connects it to the given address and port.
If there is a SocketImplFactory set then the SokcetImpl is created using the factory otherwise the default Socket implementation is used. The Socket will also bind to the local address and port specified.
address | The address to connect to. |
port | The port number to connect to [0...65535] |
localAddress | The IP address on the local machine to bind to. |
localPort | The port on the local machine to bind to. |
UnknownHostException | if the host cannot be resolved. |
IOException | if an I/O error occurs while connecting the Socket. |
NullPointerException | if the InetAddress instance in NULL. |
IllegalArgumentException | if the port if not in range [0...65535] |
decaf::net::Socket::Socket | ( | const std::string & | host, |
int | port | ||
) |
Creates a new Socket instance and connects it to the given host and port.
If there is a SocketImplFactory set then the SokcetImpl is created using the factory otherwise the default Socket implementation is used.
If the host parameter is empty then the loop back address is used.
host | The host name or IP address to connect to, empty string means loopback. |
port | The port number to connect to [0...65535] |
UnknownHostException | if the host cannot be resolved. |
IOException | if an I/O error occurs while connecting the Socket. |
IllegalArgumentException | if the port if not in range [0...65535] |
decaf::net::Socket::Socket | ( | const std::string & | host, |
int | port, | ||
const InetAddress * | localAddress, | ||
int | localPort | ||
) |
Creates a new Socket instance and connects it to the given host and port.
If there is a SocketImplFactory set then the SokcetImpl is created using the factory otherwise the default Socket implementation is used.
If the host parameter is empty then the loop back address is used.
host | The host name or IP address to connect to, empty string means loopback. |
port | The port number to connect to [0...65535] |
localAddress | The IP address on the local machine to bind to. |
localPort | The port on the local machine to bind to. |
UnknownHostException | if the host cannot be resolved. |
IOException | if an I/O error occurs while connecting the Socket. |
IllegalArgumentException | if the port if not in range [0...65535] |
virtual decaf::net::Socket::~Socket | ( | ) | [virtual] |
void decaf::net::Socket::accepted | ( | ) | [protected] |
virtual void decaf::net::Socket::bind | ( | const std::string & | ipaddress, |
int | port | ||
) | [virtual] |
Binds this Socket to the given local address and port.
If the SocketAddress value is NULL then the Socket will be bound to an available local address and port.
ipaddress | The local address and port to bind the socket to. |
port | The port on the local machine to bind to. |
IOException | if an error occurs during the bind operation. |
IllegalArgumentException | if the Socket can't process the subclass of SocketAddress that has been provided. |
void decaf::net::Socket::checkClosed | ( | ) | const [protected] |
virtual void decaf::net::Socket::close | ( | ) | [virtual] |
Closes the Socket.
Once closed a Socket cannot be connected or otherwise operated upon, a new Socket instance must be created.
IOException | if an I/O error occurs while closing the Socket. |
Implements decaf::io::Closeable.
Reimplemented in decaf::internal::net::ssl::openssl::OpenSSLSocket.
virtual void decaf::net::Socket::connect | ( | const std::string & | host, |
int | port, | ||
int | timeout | ||
) | [virtual] |
Connects to the specified destination, with a specified timeout value.
If a connection to the remote host is not established within the specified timeout interval than an SocketTimeoutException is thrown. A timeout value of zero is treated as an inifinite timeout.
host | The host name or IP address of the remote host to connect to. |
port | The port on the remote host to connect to. |
timeout | The number of Milliseconds to wait before treating the connection as failed. |
IOException | Thrown if a failure occurred in the connect. |
SocketTimeoutException | if the timeout for connection is exceeded. |
IllegalArguementException | if the timeout value is negative or the endpoint is invalid. |
Reimplemented in decaf::internal::net::ssl::openssl::OpenSSLSocket.
virtual void decaf::net::Socket::connect | ( | const std::string & | host, |
int | port | ||
) | [virtual] |
Connects to the specified destination.
host | The host name or IP address of the remote host to connect to. |
port | The port on the remote host to connect to. |
IOException | Thrown if a failure occurred in the connect. |
IllegalArguementException | if the timeout value is negative or the endpoint is invalid. |
void decaf::net::Socket::ensureCreated | ( | ) | const [protected] |
std::string decaf::net::Socket::getInetAddress | ( | ) | const |
Returns the address to which the socket is connected.
virtual decaf::io::InputStream* decaf::net::Socket::getInputStream | ( | ) | [virtual] |
Gets the InputStream for this socket if its connected.
The pointer returned is the property of the associated Socket and should not be deleted by the caller.
When the returned InputStream is performing a blocking operation and the underlying connection is closed or otherwise broker the read calls will normally throw an exception to indicate the failure.
Closing the InputStream will also close the underlying Socket.
IOException | if an error occurs during creation of the InputStream, also if the Socket is not connected or the input has been shutdown previously. |
Reimplemented in decaf::internal::net::ssl::openssl::OpenSSLSocket.
virtual bool decaf::net::Socket::getKeepAlive | ( | ) | const [virtual] |
Gets the keep alive flag for this socket, SO_KEEPALIVE.
SocketException | if the operation fails. |
std::string decaf::net::Socket::getLocalAddress | ( | ) | const |
Gets the local address to which the socket is bound.
int decaf::net::Socket::getLocalPort | ( | ) | const |
Gets the local port the socket is bound to.
virtual bool decaf::net::Socket::getOOBInline | ( | ) | const [virtual] |
Gets the value of the OOBINLINE for this socket.
SocketException | if an error is encountered while performing this operation. |
virtual decaf::io::OutputStream* decaf::net::Socket::getOutputStream | ( | ) | [virtual] |
Gets the OutputStream for this socket if it is connected.
The pointer returned is the property of the Socket instance and should not be deleted by the caller.
Closing the returned Socket will also close the underlying Socket.
IOException | if an error occurs during the creation of this OutputStream, or if the Socket is closed or the output has been shutdown previously. |
Reimplemented in decaf::internal::net::ssl::openssl::OpenSSLSocket.
int decaf::net::Socket::getPort | ( | ) | const |
Gets the on the remote host this Socket is connected to.
virtual int decaf::net::Socket::getReceiveBufferSize | ( | ) | const [virtual] |
Gets the receive buffer size for this socket, SO_RCVBUF.
This is the buffer used by the underlying platform socket to buffer received data.
SocketException | if the operation fails. |
virtual bool decaf::net::Socket::getReuseAddress | ( | ) | const [virtual] |
Gets the reuse address flag, SO_REUSEADDR.
SocketException | if the operation fails. |
virtual int decaf::net::Socket::getSendBufferSize | ( | ) | const [virtual] |
Gets the send buffer size for this socket, SO_SNDBUF, this value is used by the platform socket to buffer data written to the socket.
SocketException | if the operation fails. |
virtual int decaf::net::Socket::getSoLinger | ( | ) | const [virtual] |
Gets the linger time for the socket, SO_LINGER.
A return value of -1 indicates that the option is disabled.
SocketException | if the operation fails. |
virtual int decaf::net::Socket::getSoTimeout | ( | ) | const [virtual] |
Gets the timeout for socket operations, SO_TIMEOUT.
SocketException | Thrown if unable to retrieve the information. |
virtual bool decaf::net::Socket::getTcpNoDelay | ( | ) | const [virtual] |
Gets the Status of the TCP_NODELAY setting for this socket.
SocketException | Thrown if unable to set the information. |
virtual int decaf::net::Socket::getTrafficClass | ( | ) | const [virtual] |
Gets the Traffic Class setting for this Socket, sometimes referred to as Type of Service setting.
This setting is dependent on the underlying network implementation for the platform this Socket runs on and is not guaranteed to have any effect.
Refer to your platforms network documentation regarding support for this setting.
SocketException | if an error is encountered while performing this operation. |
void decaf::net::Socket::initSocketImpl | ( | const std::string & | address, |
int | port, | ||
const InetAddress * | localAddress, | ||
int | localPort | ||
) | [protected] |
bool decaf::net::Socket::isBound | ( | ) | const [inline] |
bool decaf::net::Socket::isClosed | ( | ) | const [inline] |
bool decaf::net::Socket::isConnected | ( | ) | const [inline] |
Indicates whether or not this socket is connected to am end point.
bool decaf::net::Socket::isInputShutdown | ( | ) | const [inline] |
bool decaf::net::Socket::isOutputShutdown | ( | ) | const [inline] |
virtual void decaf::net::Socket::sendUrgentData | ( | int | data | ) | [virtual] |
Sends on byte of urgent data to the Socket.
data | The value to write as urgent data, only the lower eight bits are sent. |
IOException | if an I/O error occurs while performing this operation. |
Reimplemented in decaf::internal::net::ssl::openssl::OpenSSLSocket.
virtual void decaf::net::Socket::setKeepAlive | ( | bool | keepAlive | ) | [virtual] |
Enables/disables the keep alive flag for this socket, SO_KEEPALIVE.
keepAlive | If true, enables the flag. |
SocketException | if the operation fails. |
virtual void decaf::net::Socket::setOOBInline | ( | bool | value | ) | [virtual] |
Sets the value of the OOBINLINE for this socket, by default this option is disabled.
If enabled the urgent data is read inline on the Socket's InputStream, no notification is give.
SocketException | if an error is encountered while performing this operation. |
Reimplemented in decaf::internal::net::ssl::openssl::OpenSSLSocket.
virtual void decaf::net::Socket::setReceiveBufferSize | ( | int | size | ) | [virtual] |
Sets the receive buffer size for this socket, SO_RCVBUF.
size | Number of bytes to set the receive buffer to. |
SocketException | if the operation fails. |
IllegalArgumentException | if the value is zero or negative. |
virtual void decaf::net::Socket::setReuseAddress | ( | bool | reuse | ) | [virtual] |
Sets the reuse address flag, SO_REUSEADDR.
reuse | If true, sets the flag. |
SocketException | if the operation fails. |
virtual void decaf::net::Socket::setSendBufferSize | ( | int | size | ) | [virtual] |
Gets the send buffer size for this socket, SO_SNDBUF, this value is used by the platform socket to buffer data written to the socket.
size | The number of bytes to set the send buffer to, must be larger than zero. |
SocketException | if the operation fails. |
IllegalArgumentException | if the value is zero or negative. |
static void decaf::net::Socket::setSocketImplFactory | ( | SocketImplFactory * | factory | ) | [static] |
Sets the instance of a SocketImplFactory that the Socket class should use when new instances of this class are created.
This method is only allowed to be used once during the lifetime of the application.
factory | The instance of a SocketImplFactory to use when new Socket objects are created. |
IOException | if an I/O error occurs while performing this operation. |
SocketException | if this method has already been called with a valid factory. |
virtual void decaf::net::Socket::setSoLinger | ( | bool | state, |
int | timeout | ||
) | [virtual] |
Sets the linger time (SO_LINGER) using a specified time value, this limits of this value are platform specific.
state | The state of SO_LINGER, true is on. |
timeout | The linger time in seconds, must be non-negative. |
SocketException | if the operation fails. |
IllegalArgumentException | if state is true and timeout is negative. |
virtual void decaf::net::Socket::setSoTimeout | ( | int | timeout | ) | [virtual] |
Sets the timeout for socket operations, SO_TIMEOUT.
A value of zero indicates that timeout is infinite for operations on this socket.
timeout | The timeout in milliseconds for socket operations. |
SocketException | Thrown if unable to set the information. |
IllegalArgumentException | if the timeout value is negative. |
virtual void decaf::net::Socket::setTcpNoDelay | ( | bool | value | ) | [virtual] |
Sets the Status of the TCP_NODELAY param for this socket., this setting is used to disable or enable Nagle's algorithm on the Socket.
value | The setting for the socket's TCP_NODELAY option, true to enable. |
SocketException | Thrown if unable to set the information. |
virtual void decaf::net::Socket::setTrafficClass | ( | int | value | ) | [virtual] |
Gets the Traffic Class setting for this Socket, sometimes referred to as Type of Service setting.
This setting is dependent on the underlying network implementation for the platform this Socket runs on and is not guaranteed to have any effect.
Refer to your platforms network documentation regarding support for this setting.
value | The integer value representing the traffic class setting bitset. |
SocketException | if an error is encountered while performing this operation. |
IllegalArgumentException | if the value is not in the range [0..255]. |
virtual void decaf::net::Socket::shutdownInput | ( | ) | [virtual] |
Shuts down the InputStream for this socket essentially marking it as EOF.
The stream returns EOF for any calls to read after this method has been called.
IOException | if an I/O error occurs while performing this operation. |
Reimplemented in decaf::internal::net::ssl::openssl::OpenSSLSocket.
virtual void decaf::net::Socket::shutdownOutput | ( | ) | [virtual] |
Shuts down the OutputStream for this socket, any data already written to the socket will be sent, any further calls to OuputStream::write will throw an IOException.
IOException | if an I/O error occurs while performing this operation. |
Reimplemented in decaf::internal::net::ssl::openssl::OpenSSLSocket.
virtual std::string decaf::net::Socket::toString | ( | ) | const [virtual] |
friend class ServerSocket [friend] |
SocketImpl* decaf::net::Socket::impl [mutable, protected] |