Vault  4.1
Public Member Functions
VListenerSocket Class Reference

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>

Inheritance diagram for VListenerSocket:
VSocket

List of all members.

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.
VSocketaccept ()
 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.

Detailed Description

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.

See also:
VListenerThread

Definition at line 37 of file vlistenersocket.h.


Constructor & Destructor Documentation

VListenerSocket::VListenerSocket ( int  portNumber,
const VString bindAddress,
VSocketFactory factory,
int  backlog = 50 
)

Creates a VListenerSocket to listen on a particular port.

Parameters:
portNumberthe port to listen on
bindAddressif 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)
factorya factory that will create a VSocket-derived object for each incoming connection
backlogthe 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().


Member Function Documentation

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.

Returns:
the new VSocket object for the accepted connection

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.


The documentation for this class was generated from the following files:

Copyright ©1997-2014 Trygve Isaacson. All rights reserved. This documentation was generated with Doxygen.