A server (listening) socket for StreamSocket (TCP) connections. More...
#include <ServerSocket.h++>

Public Member Functions | |
| ServerSocket (uint16_t port, uint_t backlog=3) throw () | |
| Construct a new ServerSocket that will listen on the given port. | |
| ServerSocket (uint16_t port, const NetworkInterface &ixface, uint_t backlog=3) throw () | |
| Construct a new ServerSocket that will listen on the given port and network interface. | |
| ~ServerSocket () throw () | |
| Destructor. | |
| void | init () throw (SocketException) |
| Initialize the socket. | |
| void | shutdown () throw () |
| Shut down the socket. | |
| void | listen () throw (SocketException) |
| Begin listening for connections on the socket. | |
| bool | isListening () const throw () |
| Determine if the socket is in a listening state. | |
| void | accept (StreamSocket &socket) throw (SocketException, TimeoutException) |
| Accept a connection on the socket. | |
| virtual void | connect (const String &addr, uint16_t port) throw (IOException) |
| Connect the socket to a remote endpoint. | |
| virtual void | connect (const SocketAddress &addr) throw (IOException) |
| Connect the socket to a remote endpoint. | |
| void | setTimeout (timespan_ms_t timeout) throw (SocketException) |
| Set the timeout for the socket. | |
| void | setReceiveBufSize (size_t size) throw (SocketException) |
| Set the size of the socket's internal receive buffer. | |
| size_t | getReceiveBufSize () const throw (SocketException) |
| Get the size of the socket's internal receive buffer. | |
| void | setSendBufSize (size_t size) throw (SocketException) |
| Set the size of the socket's internal send buffer. | |
| size_t | getSendBufSize () const throw (SocketException) |
| Get the size of the socket's internal send buffer. | |
| void | setLingerTime (timespan_s_t timeout) throw (SocketException) |
| Set the linger time for the socket. | |
| timespan_s_t | getLingerTime () const throw (SocketException) |
| Get the linger time for the socket. | |
| void | setReuseAddress (bool enable) throw (SocketException) |
| Enable or disable the SO_REUSEADDR option on the socket. | |
| bool | getReuseAddress () const throw (SocketException) |
| Determine if the SO_REUSEADDR option is enabled or disabled. | |
| void | setKeepAlive (bool enable) throw (SocketException) |
| Enable or disable the SO_KEEPALIVE option on the socket. | |
| bool | getKeepAlive () throw (SocketException) |
| Determine if the SO_KEEPALIVE option is enabled or disabled. | |
| void | setTCPDelay (bool enable) throw (SocketException) |
| Enable or disable the Nagle algorithm for send coalescing. | |
| bool | getTCPDelay () throw (SocketException) |
| Determine if the Nagle algorithm is enabled or disabled. | |
| bool | isInitialized () const throw () |
| Determine if the socket has been initialized. | |
| bool | isConnected () const throw () |
| Determine if the socket is connected. | |
| NetProtocol | getType () const throw () |
| Get the socket type. | |
| const SocketAddress & | getLocalAddress () const throw () |
| Get the address of the local end of the socket. | |
| const SocketAddress & | getRemoteAddress () const throw () |
| Get the address of the remote (peer) end of the socket. | |
Protected Types | |
| enum | IOWaitMode { WaitWrite, WaitRead } |
Protected Member Functions | |
| SocketHandle | getSocketHandle () const throw () |
| Get the underlying socket handle for this socket. | |
| void | waitForIO (IOWaitMode mode) throw (IOException) |
| Wait for the socket to become ready for reading or writing. | |
Protected Attributes | |
| NetProtocol | _type |
| The socket type. | |
| SocketHandle | _socket |
| A handle to the socket itself. | |
| SocketAddress | _raddr |
| The remote address. | |
| SocketAddress | _laddr |
| The local address. | |
| int | _sotimeout |
| The timeout value. | |
A server (listening) socket for StreamSocket (TCP) connections.
enum IOWaitMode [protected, inherited] |
| ServerSocket | ( | uint16_t | port, | |
| uint_t | backlog = 3 | |||
| ) | throw () |
Construct a new ServerSocket that will listen on the given port.
| port | The port number to listen on. | |
| backlog | The size of the connection backlog. |
| ServerSocket | ( | uint16_t | port, | |
| const NetworkInterface & | ixface, | |||
| uint_t | backlog = 3 | |||
| ) | throw () |
Construct a new ServerSocket that will listen on the given port and network interface.
| port | The port number to listen on. | |
| ixface | The network interface to listen on. | |
| backlog | The size of the connection backlog. |
| ~ServerSocket | ( | ) | throw () |
Destructor.
Shuts down the socket.
| void accept | ( | StreamSocket & | socket | ) | throw (SocketException, TimeoutException) |
Accept a connection on the socket.
This method blocks until a new connection is pending, unless a timeout has been set on the socket, in which case a TimeoutException is thrown if no connection is pending by the time the timeout expires.
| socket | A socket object which will be initialized to represent the newly-established connection. |
| TimeoutException | If the operation times out. | |
| SocketException | If a socket error occurs. |
| void connect | ( | const SocketAddress & | addr | ) | throw (IOException) [virtual, inherited] |
Connect the socket to a remote endpoint.
Note that if this call fails, the socket will revert to an uninitialized state; call init() again to reuse the socket.
| addr | The address. |
| IOException | If an error occurs. |
Reimplemented in DatagramSocket, and StreamSocket.
| void connect | ( | const String & | addr, | |
| uint16_t | port | |||
| ) | throw (IOException) [virtual, inherited] |
Connect the socket to a remote endpoint.
Note that if this call fails, the socket will revert to an uninitialized state; call init() again to reuse the socket.
| addr | The address, which may either be a dot-separated IP address or a DNS name. | |
| port | The port number. |
| IOException | If an error occurs. |
Reimplemented in DatagramSocket, and StreamSocket.
| bool getKeepAlive | ( | ) | throw (SocketException) [inherited] |
Determine if the SO_KEEPALIVE option is enabled or disabled.
| SocketException | If a socket error occurs. |
| timespan_s_t getLingerTime | ( | ) | const throw (SocketException) [inherited] |
Get the linger time for the socket.
| SocketException | If the linger time could not be retrieved. |
| const SocketAddress& getLocalAddress | ( | ) | const throw () [inline, inherited] |
Get the address of the local end of the socket.
| size_t getReceiveBufSize | ( | ) | const throw (SocketException) [inherited] |
Get the size of the socket's internal receive buffer.
| SocketException | If the size could not be changed. |
| const SocketAddress& getRemoteAddress | ( | ) | const throw () [inline, inherited] |
Get the address of the remote (peer) end of the socket.
| bool getReuseAddress | ( | ) | const throw (SocketException) [inherited] |
Determine if the SO_REUSEADDR option is enabled or disabled.
| SocketException | If a socket error occurs. |
| size_t getSendBufSize | ( | ) | const throw (SocketException) [inherited] |
Get the size of the socket's internal send buffer.
| SocketException | If the size could not be changed. |
| SocketHandle getSocketHandle | ( | ) | const throw () [inline, protected, inherited] |
Get the underlying socket handle for this socket.
| bool getTCPDelay | ( | ) | throw (SocketException) [inherited] |
Determine if the Nagle algorithm is enabled or disabled.
| SocketException | If a socket error occurs. |
| NetProtocol getType | ( | ) | const throw () [inline, inherited] |
Get the socket type.
| void init | ( | ) | throw (SocketException) [virtual] |
Initialize the socket.
This method creates the underlying socket object.
| SocketException | If the socket could not be created. |
Reimplemented from Socket.
| bool isConnected | ( | ) | const throw () [inline, inherited] |
Determine if the socket is connected.
| bool isInitialized | ( | ) | const throw () [inline, inherited] |
Determine if the socket has been initialized.
| bool isListening | ( | ) | const throw () [inline] |
Determine if the socket is in a listening state.
| void listen | ( | ) | throw (SocketException) |
Begin listening for connections on the socket.
| SocketException | If a socket error occurs. |
| void setKeepAlive | ( | bool | enable | ) | throw (SocketException) [inherited] |
Enable or disable the SO_KEEPALIVE option on the socket.
| enable | true to enable the option false to disable it. |
| SocketException | If a socket error occurs. |
| void setLingerTime | ( | timespan_s_t | timeout | ) | throw (SocketException) [inherited] |
Set the linger time for the socket.
| timeout | The new linger time, in seconds; a negative value disables the linger feature. |
| SocketException | If the linger time could not be changed. |
| void setReceiveBufSize | ( | size_t | size | ) | throw (SocketException) [inherited] |
Set the size of the socket's internal receive buffer.
| size | The new size, in bytes. |
| SocketException | If the size could not be changed. |
| void setReuseAddress | ( | bool | enable | ) | throw (SocketException) [inherited] |
Enable or disable the SO_REUSEADDR option on the socket.
This method may only be called before the socket has been initialized. This option is off by default in newly created sockets.
| enable | true to enable the option false to disable it. |
| SocketException | If a socket error occurs, or if the call was made after the socket was initialized. |
| void setSendBufSize | ( | size_t | size | ) | throw (SocketException) [inherited] |
Set the size of the socket's internal send buffer.
| size | The new size, in bytes. |
| SocketException | If the size could not be changed. |
| void setTCPDelay | ( | bool | enable | ) | throw (SocketException) [inherited] |
Enable or disable the Nagle algorithm for send coalescing.
| enable | true to enable the Nagle algorithm (TCP_NODELAY off), false to disable it (TCP_NODELAY on). |
| SocketException | If a socket error occurs. |
| void setTimeout | ( | timespan_ms_t | timeout | ) | throw (SocketException) [inherited] |
Set the timeout for the socket.
The timeout affects both I/O and connections.
| timeout | The timeout, in milliseconds. |
| SocketException | If an error occurs. |
Reimplemented in StreamSocket.
| void shutdown | ( | ) | throw () [virtual] |
Shut down the socket.
Closes the connection and destroys the underlying socket object.
Reimplemented from Socket.
| void waitForIO | ( | IOWaitMode | mode | ) | throw (IOException) [protected, inherited] |
Wait for the socket to become ready for reading or writing.
| mode | The wait mode; one of WaitWrite or WaitRead. |
| IOException | On timeout or other error. |
SocketAddress _laddr [protected, inherited] |
The local address.
SocketAddress _raddr [protected, inherited] |
The remote address.
SocketHandle _socket [protected, inherited] |
A handle to the socket itself.
int _sotimeout [protected, inherited] |
The timeout value.
NetProtocol _type [protected, inherited] |
The socket type.
1.6.3