nidas v1.2.3
|
A stream (TCP) socket that is used to listen for connections. More...
#include <Socket.h>
Public Member Functions | |
ServerSocket (int port=0, int backlog=10) | |
Create a AF_INET ServerSocket bound to a port on all local interfaces. | |
ServerSocket (const Inet4Address &bindAddr, int port, int backlog=10) | |
Create a ServerSocket bound to port on a given local address, and set listen backlog parameter. | |
ServerSocket (const SocketAddress &bindAddr, int backlog=10) | |
Create a ServerSocket bound to an address, and set listen backlog parameter. | |
~ServerSocket () | |
Destructor. | |
int | getFd () const |
void | close () |
Close the socket. | |
Socket * | accept () |
Accept connection, return a connected Socket instance. | |
void | setReceiveBufferSize (int size) |
int | getReceiveBufferSize () |
void | setSendBufferSize (int size) |
int | getSendBufferSize () |
const SocketAddress & | getLocalSocketAddress () const |
Fetch the local address that this socket is bound to. | |
int | getLocalPort () const |
int | getDomain () const |
void | setNonBlocking (bool val) |
bool | isNonBlocking () const |
Protected Attributes | |
SocketImpl | _impl |
A stream (TCP) socket that is used to listen for connections.
This class is patterned after the java.net.ServerSocket class.
This class provides the public copy constructors and assignment operators. Objects of this class can be copied and assigned to without restriction. However, because of this, the destructor does not close the socket, so it is the user's responsibility to call Socket::close() when finished with the connection.
Usage scenario of a server which listens for connections on port 5000, and spawns a thread to handle each connection.
ServerSocket::ServerSocket | ( | int | port = 0, |
int | backlog = 10 ) |
Create a AF_INET ServerSocket bound to a port on all local interfaces.
port | Port number, 0<=port<=65535. If zero, the system will select an available port number. To find out which port number was selected, use getLocalPort(). |
IOException |
References _impl, nidas::util::SocketImpl::bind(), close(), port, nidas::util::SocketImpl::setBacklog(), and nidas::util::SocketImpl::setNonBlocking().
ServerSocket::ServerSocket | ( | const Inet4Address & | bindAddr, |
int | port, | ||
int | backlog = 10 ) |
Create a ServerSocket bound to port on a given local address, and set listen backlog parameter.
IOException |
References _impl, nidas::util::SocketImpl::bind(), close(), port, nidas::util::SocketImpl::setBacklog(), and nidas::util::SocketImpl::setNonBlocking().
ServerSocket::ServerSocket | ( | const SocketAddress & | bindAddr, |
int | backlog = 10 ) |
Create a ServerSocket bound to an address, and set listen backlog parameter.
IOException |
References _impl, nidas::util::SocketImpl::bind(), close(), nidas::util::SocketImpl::setBacklog(), and nidas::util::SocketImpl::setNonBlocking().
|
inline |
Destructor.
Does not close the socket. You must explicitly close it with the close method.
)
|
inline |
Accept connection, return a connected Socket instance.
This method does the following in addition to the basic accept() system call.
IOException |
References _impl, and nidas::util::SocketImpl::accept().
Referenced by nidas::core::ServerSocket::connect(), and nidas::core::ServerSocketIODevice::open().
void ServerSocket::close | ( | ) |
Close the socket.
IOException |
References _impl, nidas::util::SocketImpl::close(), DLOG, getDomain(), and getLocalSocketAddress().
Referenced by nidas::core::RemoteSerialListener::close(), nidas::core::ServerSocket::close(), nidas::core::ServerSocketIODevice::closeServerSocket(), ServerSocket(), ServerSocket(), and ServerSocket().
|
inline |
References _impl, and nidas::util::SocketImpl::getDomain().
Referenced by close().
|
inline |
References _impl, and nidas::util::SocketImpl::getFd().
Referenced by nidas::core::RemoteSerialListener::close(), nidas::core::ServerSocketIODevice::closeServerSocket(), nidas::core::RemoteSerialListener::getFd(), nidas::core::ServerSocket::getFd(), and nidas::core::RemoteSerialListener::RemoteSerialListener().
|
inline |
|
inline |
Fetch the local address that this socket is bound to.
)
References _impl, and nidas::util::SocketImpl::getLocalSocketAddress().
Referenced by close(), and nidas::core::RemoteSerialListener::getName().
|
inline |
IOException |
References _impl, and nidas::util::SocketImpl::getReceiveBufferSize().
|
inline |
IOException |
References _impl, and nidas::util::SocketImpl::getSendBufferSize().
|
inline |
IOException |
References _impl, and nidas::util::SocketImpl::isNonBlocking().
|
inline |
IOException |
References _impl, and nidas::util::SocketImpl::setNonBlocking().
|
inline |
IOException |
References _impl, and nidas::util::SocketImpl::setReceiveBufferSize().
|
inline |
IOException |
References _impl, and nidas::util::SocketImpl::setSendBufferSize().
|
protected |