This class implements server sockets.
More...
#include <src/main/decaf/net/ServerSocket.h>
|
| | ServerSocket () |
| | Creates a non-bound server socket.
|
| | ServerSocket (int port) |
| | Creates a new ServerSocket bound to the specified port, if the value of port is 0, then any free port is chosen.
|
| | ServerSocket (int port, int backlog) |
| | Creates a new ServerSocket bound to the specified port, if the value of port is 0, then any free port is chosen.
|
| | ServerSocket (int port, int backlog, const InetAddress *address) |
| | Creates a new ServerSocket bound to the specified port, if the value of port is 0, then any free port is chosen.
|
| virtual | ~ServerSocket () |
| | Releases socket handle if close() hasn't been called.
|
| virtual void | bind (const std::string &host, int port) |
| | Bind and listen to given local IPAddress and port, if the address is empty than a valid local address will be chosen, and if the port of 0 than an available open port will be chosen.
|
| virtual void | bind (const std::string &host, int port, int backlog) |
| | Bind and listen to given local IPAddress and port, if the address is empty than a valid local address will be chosen, and if the port of 0 than an available open port will be chosen.
|
| virtual Socket * | accept () |
| | Listens for a connection request on the bound IPAddress and Port for this ServerSocket, the caller blocks until a connection is made.
|
| virtual void | close () |
| | Closes the server socket, causing any Threads blocked on an accept call to throw an Exception.
|
| virtual bool | isClosed () const |
| virtual bool | isBound () const |
| 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 | getSoTimeout () const |
| | Gets the timeout for socket operations, SO_TIMEOUT.
|
| virtual void | setSoTimeout (int timeout) |
| | Sets the timeout for socket operations, SO_TIMEOUT.
|
| virtual int | getLocalPort () const |
| | Gets the port number on the Local machine that this ServerSocket is bound to.
|
| virtual std::string | toString () const |
This class implements server sockets.
A server socket waits for requests to come in over the network.
The actual work of the server socket is performed by an instance of the SocketImpl class. An application can change the socket factory that creates the socket implementation to configure itself to create sockets of a particular type.
- Since
- 1.0
◆ ServerSocket() [1/5]
| decaf::net::ServerSocket::ServerSocket |
( |
| ) |
|
Creates a non-bound server socket.
◆ ServerSocket() [2/5]
| decaf::net::ServerSocket::ServerSocket |
( |
int | port | ) |
|
Creates a new ServerSocket bound to the specified port, if the value of port is 0, then any free port is chosen.
When this constructor is called the size of the backlog queue is set at 50, connections that arrive after the backlog has been reached are refused.
If a SocketImplFactory is registered then the createSocketImpl method on the factory will be called otherwise a default SocketImpl is created.
- Parameters
-
- Exceptions
-
| IOException | if there is an I/O error while performing this operation. |
| IllegalArgumentException | if the port value is negative or greater than 65535. |
◆ ServerSocket() [3/5]
| decaf::net::ServerSocket::ServerSocket |
( |
int | port, |
|
|
int | backlog ) |
Creates a new ServerSocket bound to the specified port, if the value of port is 0, then any free port is chosen.
When this constructor is called the size of the backlog queue is set at backlog, connections that arrive after the backlog has been reached are refused. If backlog is zero or negative then the default backlog value of 50 is used.
If a SocketImplFactory is registered then the createSocketImpl method on the factory will be called otherwise a default SocketImpl is created.
- Parameters
-
| port | The port to bind the ServerSocket to. |
| backlog | The the number of incoming connection attempts to queue before connections are refused. |
- Exceptions
-
| IOException | if there is an I/O error while performing this operation. |
| IllegalArgumentException | if the port value is negative or greater than 65535. |
◆ ServerSocket() [4/5]
| decaf::net::ServerSocket::ServerSocket |
( |
int | port, |
|
|
int | backlog, |
|
|
const InetAddress * | address ) |
Creates a new ServerSocket bound to the specified port, if the value of port is 0, then any free port is chosen.
If the value of the ifAddress is empty or NULL then the ANY address is used.
When this constructor is called the size of the backlog queue is set at backlog, connections that arrive after the backlog has been reached are refused. If backlog is zero or negative then the default backlog value of 50 is used.
If a SocketImplFactory is registered then the createSocketImpl method on the factory will be called otherwise a default SocketImpl is created.
- Parameters
-
| port | The port to bind the ServerSocket to. |
| backlog | The the number of incoming connection attempts to queue before connections are refused. |
| address | The IP Address to bind to on the local machine. |
- Exceptions
-
| IOException | if there is an I/O error while performing this operation. |
| IllegalArgumentException | if the port value is negative or greater than 65535. |
◆ ~ServerSocket()
| virtual decaf::net::ServerSocket::~ServerSocket |
( |
| ) |
|
|
virtual |
Releases socket handle if close() hasn't been called.
◆ ServerSocket() [5/5]
| decaf::net::ServerSocket::ServerSocket |
( |
SocketImpl * | impl | ) |
|
|
protected |
◆ accept()
| virtual Socket * decaf::net::ServerSocket::accept |
( |
| ) |
|
|
virtual |
Listens for a connection request on the bound IPAddress and Port for this ServerSocket, the caller blocks until a connection is made.
If the SO_TIMEOUT option is set this method could throw a SocketTimeoutException if the operation times out.
- Returns
- a new Socket object pointer. Never returns NULL, the returned pointer is owned by the caller and must be explicitly freed by them.
- Exceptions
-
| IOException | if an I/O error occurs while binding the socket. |
| SocketException | if an error occurs while blocking on the accept call. |
| SocketTimeoutException | if the SO_TIMEOUT option was used and the accept timed out. |
Reimplemented in decaf::internal::net::ssl::openssl::OpenSSLServerSocket.
◆ bind() [1/2]
| virtual void decaf::net::ServerSocket::bind |
( |
const std::string & | host, |
|
|
int | port ) |
|
virtual |
Bind and listen to given local IPAddress and port, if the address is empty than a valid local address will be chosen, and if the port of 0 than an available open port will be chosen.
- Parameters
-
| host | The IP address or host name. |
| port | The TCP port between 1..655535. |
- Exceptions
-
| IOException | if an I/O error occurs while binding the socket. |
| IllegalArgumentException | if the parameters are not valid. |
◆ bind() [2/2]
| virtual void decaf::net::ServerSocket::bind |
( |
const std::string & | host, |
|
|
int | port, |
|
|
int | backlog ) |
|
virtual |
Bind and listen to given local IPAddress and port, if the address is empty than a valid local address will be chosen, and if the port of 0 than an available open port will be chosen.
If the backlog is greater than zero it will be used instead of the default value, otherwise the default value is used and no error is generated.
- Parameters
-
| host | The IP address or host name. |
| port | The TCP port between 1..655535. |
| backlog | The size of listen backlog. |
- Exceptions
-
| IOException | if an I/O error occurs while binding the socket. |
| IllegalArgumentException | if the parameters are not valid. |
◆ checkClosed()
| void decaf::net::ServerSocket::checkClosed |
( |
| ) |
const |
|
protected |
◆ close()
| virtual void decaf::net::ServerSocket::close |
( |
| ) |
|
|
virtual |
Closes the server socket, causing any Threads blocked on an accept call to throw an Exception.
- Exceptions
-
| IOException | if an I/O error occurs while performing this operation. |
◆ ensureCreated()
| void decaf::net::ServerSocket::ensureCreated |
( |
| ) |
const |
|
protected |
◆ getDefaultBacklog()
| virtual int decaf::net::ServerSocket::getDefaultBacklog |
( |
| ) |
|
|
protectedvirtual |
Allows a subclass to override what is considered the default backlog.
- Returns
- the default backlog for connections.
◆ getLocalPort()
| virtual int decaf::net::ServerSocket::getLocalPort |
( |
| ) |
const |
|
virtual |
Gets the port number on the Local machine that this ServerSocket is bound to.
- Returns
- the port number of this machine that is bound, if not bound returns -1.
◆ getReceiveBufferSize()
| virtual int decaf::net::ServerSocket::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.
- Returns
- the receive buffer size in bytes.
- Exceptions
-
| SocketException | if the operation fails. |
◆ getReuseAddress()
| virtual bool decaf::net::ServerSocket::getReuseAddress |
( |
| ) |
const |
|
virtual |
Gets the reuse address flag, SO_REUSEADDR.
- Returns
- True if the address can be reused.
- Exceptions
-
| SocketException | if the operation fails. |
◆ getSoTimeout()
| virtual int decaf::net::ServerSocket::getSoTimeout |
( |
| ) |
const |
|
virtual |
Gets the timeout for socket operations, SO_TIMEOUT.
- Returns
- The timeout in milliseconds for socket operations.
- Exceptions
-
| SocketException | Thrown if unable to retrieve the information. |
◆ implAccept()
| virtual void decaf::net::ServerSocket::implAccept |
( |
Socket * | socket | ) |
|
|
protectedvirtual |
Virtual method that allows a ServerSocket subclass to override the accept call and provide its own SocketImpl for the socket.
- Parameters
-
| socket | The socket object whose SocketImpl should be used for the accept call. |
- Exceptions
-
| IOException | if an I/O error occurs while performing this operation. |
◆ isBound()
| virtual bool decaf::net::ServerSocket::isBound |
( |
| ) |
const |
|
virtual |
- Returns
- true of the server socket is bound.
◆ isClosed()
| virtual bool decaf::net::ServerSocket::isClosed |
( |
| ) |
const |
|
virtual |
- Returns
- true if the close method has been called on the ServerSocket.
◆ setReceiveBufferSize()
| virtual void decaf::net::ServerSocket::setReceiveBufferSize |
( |
int | size | ) |
|
|
virtual |
Sets the receive buffer size for this socket, SO_RCVBUF.
- Parameters
-
| size | Number of bytes to set the receive buffer to. |
- Exceptions
-
| SocketException | if the operation fails. |
| IllegalArgumentException | if the value is zero or negative. |
◆ setReuseAddress()
| virtual void decaf::net::ServerSocket::setReuseAddress |
( |
bool | reuse | ) |
|
|
virtual |
Sets the reuse address flag, SO_REUSEADDR.
- Parameters
-
| reuse | If true, sets the flag. |
- Exceptions
-
| SocketException | if the operation fails. |
◆ setSocketImplFactory()
Sets the instance of a SocketImplFactory that the ServerSocket 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.
- Parameters
-
- Exceptions
-
| IOException | if an I/O error occurs while performing this operation. |
| SocketException | if this method has already been called with a valid factory. |
◆ setSoTimeout()
| virtual void decaf::net::ServerSocket::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.
- Parameters
-
| timeout | The timeout in milliseconds for socket operations. |
- Exceptions
-
| SocketException | Thrown if unable to set the information. |
| IllegalArgumentException | if the timeout value is negative. |
◆ setupSocketImpl()
| void decaf::net::ServerSocket::setupSocketImpl |
( |
int | port, |
|
|
int | backlog, |
|
|
const InetAddress * | ifAddress ) |
|
protected |
◆ toString()
| virtual std::string decaf::net::ServerSocket::toString |
( |
| ) |
const |
|
virtual |
The documentation for this class was generated from the following file: