plumbing::endpoint_listener Class Reference

#include <listener.h>

Inheritance diagram for plumbing::endpoint_listener:
plumbing::endpoint

Public Member Functions

virtual ~endpoint_listener ()

Protected Member Functions

 endpoint_listener (reactor &svc, int port_number, int repeat_count)
 endpoint_listener (reactor &svc, const std::string &port_number, int repeat_count)
void process_read ()
void process_write ()
void add_endpoint (const endpoint::pointer &ep)
virtual int get_default_port () const =0
virtual endpoint::pointer endpoint_factory (int fd, void *adr, int adrlen)=0
int get_read_file_descriptor ()

Private Member Functions

void create_listening_socket ()
 endpoint_listener ()
 endpoint_listener (const endpoint_listener &)
endpoint_listeneroperator= (const endpoint_listener &)

Private Attributes

reactorsvc
int port_number
int repeat_count

Detailed Description

The plumbing::endpoint_listener class is used to represent an endpoint which listens for incoming connections. The endpoint_factory method is then used to allocate a new endpoint to process the new connection. By creating a listening endpoint, it is possible for a reactor to listen on two or more ports at once, and create appropriate new endpoint derivatived objects for each connection.

Definition at line 36 of file listener.h.


Constructor & Destructor Documentation

virtual plumbing::endpoint_listener::~endpoint_listener (  )  [virtual]

The destructor.

plumbing::endpoint_listener::endpoint_listener ( reactor svc,
int  port_number,
int  repeat_count 
) [protected]

A constructor. It is protected on purpose, you must derive from this class.

Parameters:
svc The reactor to manage all new connections.
port_number The port number to use, or -1 if need to ask derived class for one later.
repeat_count The number of time to spawn servers before self terminating. Use -1 to mean "infinity".
plumbing::endpoint_listener::endpoint_listener ( reactor svc,
const std::string &  port_number,
int  repeat_count 
) [protected]

A constructor. It is protected on purpose, you must derive from this class.

Parameters:
svc The reactor to manage all new connections.
port_number The port number to use, or the empty string if need to ask derived class for one later.
repeat_count The number of time to spawn servers before self terminating. Use -1 to mean "infinity".
plumbing::endpoint_listener::endpoint_listener (  )  [private]

The default constructor. Do not use.

plumbing::endpoint_listener::endpoint_listener ( const endpoint_listener  )  [private]

The copy constructor. Do not use.


Member Function Documentation

void plumbing::endpoint_listener::add_endpoint ( const endpoint::pointer ep  )  [protected]

The add_endpoint method is used to add another endpoint to those being managed by our associated reactor. This is a simple helper method wrapper, to get the new endpoint to the right place (into the reactor).

Parameters:
ep The endpoint to be managed by the reactor.
void plumbing::endpoint_listener::create_listening_socket (  )  [private]

The create_listening_port method is called by the process method to establish the file descriptor on which to listen for connections. It is safe to call this method redundantly.

virtual endpoint::pointer plumbing::endpoint_listener::endpoint_factory ( int  fd,
void *  adr,
int  adrlen 
) [protected, pure virtual]

The endpoint_factory method is call in response to a successful connection by a client.

Parameters:
fd The file descriptor of the new connnection
adr The address data structure returned by accept
adrlen The length of the address data structure returned by accept
Returns:
A dynamically allocated endpoint instance.
virtual int plumbing::endpoint_listener::get_default_port (  )  const [protected, pure virtual]

The get_default_port method is used to obtain the port number this reactor will listen on, if not port is specified in the configuration file. Each drived class must supply its own default port.

int plumbing::endpoint_listener::get_read_file_descriptor (  )  [protected, virtual]

The get_read_file_descriptor method is used to obtain the file descriptor that select is to wait upon for read events. The default implementation returns the fd instance variable.

Returns:
int; >=0 for a valid file descriptior, or -1 if read events should not be waited for.
Note:
DO NOT close the file descriptor and set it to -1 in this method. Do that in the process_read method instead, otherwise you confuse the select() processing.

Reimplemented from plumbing::endpoint.

endpoint_listener& plumbing::endpoint_listener::operator= ( const endpoint_listener  )  [private]

The assignment operator. Do not use.

void plumbing::endpoint_listener::process_read (  )  [protected, virtual]

The process_read method is called by the select loop when a readable event is detected on the read file descriptor. (This method is virtual in the base class.)

Readable events happen when an incoming connection request is detected, and it is handled by the accept() system call to create a new socket to listen to the new file descriptor.

A new endpoint is created (via the endpoint-factory method) and added to the managing reactor (via the add_endpoint helper method).

Implements plumbing::endpoint.

void plumbing::endpoint_listener::process_write (  )  [protected, virtual]

The process_write method is called by the select loop when a writable event is detected on the read file descriptor.

Implements plumbing::endpoint.


Field Documentation

The port_number instance variable is used to remember the port number this endpoint is to listen on.

Initially the port number is -1, to indicated that the socket creation has been deferred. If, when the process method is called, the value is still -1, the get_default_port methd will be used to obtain the port number to be used.

Definition at line 152 of file listener.h.

The repeat_count instance variable is used to remember the number of times to spawn servers before self terminating. Use -1 to mean "infinity".

Definition at line 159 of file listener.h.

The svc instance variable is used to remember the reactor to attach new endpoints to, so that they may be handled by the common select() code in the reactor::process() method.

Definition at line 141 of file listener.h.


The documentation for this class was generated from the following file:
Generated on Thu Sep 16 14:32:12 2010 for Plumbing by  doxygen 1.6.3