![]() |
Vault
4.1
|
VListenerSocket is a special kind of socket that can accept incoming connections and create a new VSocket for each such connection that it accepts. More...
#include <vlistenersocket.h>
Public Member Functions | |
VListenerSocket (int portNumber, const VString &bindAddress, VSocketFactory *factory, int backlog=50) | |
Creates a VListenerSocket to listen on a particular port. | |
virtual | ~VListenerSocket () |
Destructor. | |
VSocket * | accept () |
Blocks until an incoming connection occurs or the timeout interval elapses (if a timeout has been specified), returning a new VSocket object for the connection. | |
void | listen () |
Causes the listener to activate by listening for incoming connections; generally this is followed by a loop that calls accept() to accept inbound connections. |
VListenerSocket is a special kind of socket that can accept incoming connections and create a new VSocket for each such connection that it accepts.
Usually you won't have to use this class directly when implementing a server; you will use VListenerThread to manage things.
There is one counter-intuitive thing about this class: the listen() method is implemented in its superclass, VSocket. This is because listen() is a platform-specific bit of code, and VSocket is where all of the platform-specific socket code lives. This class merely adds the accept() method.
Definition at line 37 of file vlistenersocket.h.
VListenerSocket::VListenerSocket | ( | int | portNumber, |
const VString & | bindAddress, | ||
VSocketFactory * | factory, | ||
int | backlog = 50 |
||
) |
Creates a VListenerSocket to listen on a particular port.
portNumber | the port to listen on |
bindAddress | if empty, the socket will bind to INADDR_ANY (usually a good default); if a value is supplied the socket will bind to the supplied IP address (can be useful on a multi-homed server) |
factory | a factory that will create a VSocket-derived object for each incoming connection |
backlog | the listen backlog for the socket; this limits the number of pending incoming connections that can be queued up for acceptance |
Definition at line 16 of file vlistenersocket.cpp.
References VString::chars(), VSocket::setHostIPAddressAndPort(), and VSocket::setReadTimeOut().
VSocket * VListenerSocket::accept | ( | ) |
Blocks until an incoming connection occurs or the timeout interval elapses (if a timeout has been specified), returning a new VSocket object for the connection.
If you fail to call listen() before calling accept(), this method will throw a VException. The socket cannot accept until it is listening.
Definition at line 41 of file vlistenersocket.cpp.
References VString::chars(), VSocketFactory::createSocket(), VSystemError::getSocketError(), VSocket::kNoSocketID, VSocket::mPortNumber, VSocket::mReadTimeOut, VSocket::mReadTimeOutActive, VSocket::mSocketID, and NULL.