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

tcp_acceptor< T, Arg > Class Template Reference

Inherits io_handler.

List of all members.

Detailed Description

template<class T, class Arg = __nmstl_tcp_acceptor_noarg>
class tcp_acceptor< 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. tcp_acceptor 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; tcp_acceptor 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 io_handler {
     MyServerHandler(io_event_loop& loop, tcpsocket sock,
                     MyDispatcher *disp) :
         io_handler(loop, sock)

 typedef tcp_acceptor<MyServerHandler, MyDispatcher*> MyAcceptor;

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

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

     return 0;

Public Methods

 tcp_acceptor (io_event_loop &_loop, in_port_t localport, Arg arg)
 Creates the service,.

virtual ~tcp_acceptor ()

Constructor & Destructor Documentation

template<class T, class Arg = __nmstl_tcp_acceptor_noarg>
tcp_acceptor< T, Arg >::tcp_acceptor io_event_loop   _loop,
in_port_t    localport,
Arg    arg

Creates the service,.

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

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