Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

TCPAcceptor< T, Arg > Class Template Reference

Inherits IOHandler.

List of all members.


Detailed Description

template<class T, class Arg = __nmstl_tcp_acceptor_noarg>
class TCPAcceptor< T, Arg >

A service which creates a server Socket on a local port and waits for connections.

Whenever a connection is accepted, a handler of type T, the first template argument, is constructed. Each acceptor may have an arbitrarily-typed argument (of type Arg, the second template argument) which is passed to all the handlers on construction. TCPAcceptor constructs handlers like this:

 new T(loop, sock, arg);

where loop is the event loop that this acceptor is bound to, sock is a TCP Socket object, and arg is the arbitrary argument passed to the constructor.

If no such argument is required, then omit the second template argument; TCPAcceptor will then construct handlers like this:

 new T(loop, sock);

A typical usage pattern, in which all the server handlers need access to some dispatcher object that manages global state, is as follows:

 class MyDispatcher { ... };

 class MyServerHandler : public IOHandler {
   public:
     MyServerHandler(IOEventLoop& loop, TCPSocket sock,
                     MyDispatcher *disp) :
         IOHandler(loop, sock)
     {
         ...
     }
 };

 typedef TCPAcceptor<MyServerHandler, MyDispatcher*> MyAcceptor;

 int main() {
     static const unsigned int PORT = 8002;

     MyDispatcher *dispatcher = new MyDispatcher;
     IOEventLoop loop;
     MyAcceptor acceptor(loop, PORT, dispatcher);

     loop.run();

     return 0;
 }


Public Methods

 TCPAcceptor (IOEventLoop &_loop, in_port_t localport, Arg arg)
 Creates the service,.

virtual ~TCPAcceptor ()


Constructor & Destructor Documentation

template<class T, class Arg = __nmstl_tcp_acceptor_noarg>
TCPAcceptor< T, Arg >::TCPAcceptor IOEventLoop   _loop,
in_port_t    localport,
Arg    arg
 

Creates the service,.

template<class T, class Arg = __nmstl_tcp_acceptor_noarg>
virtual TCPAcceptor< T, Arg >::~TCPAcceptor   [virtual]
 


The documentation for this class was generated from the following file:
Generated on Fri Dec 20 13:35:11 2002 for NMSTL