Derived from: TCP_Listener
Declared in: HTTPListener.h
Library: libHTTP.so
The HTTPListener class is analogeous to the BLooper class. It waits to receive messages in its own thread over TCP and passes them to a HTTPHandler object by means of the handler's MessageReceived() method. It differs from the BLooper/BHandler model in certain aspects. When a connection is opened, a new handler thread is created and a copy of the template handler is created to handle requests on that connection. The listener returns immediatly to wait for new connections, while the handler thread processes the request messages.
The connection thread manages the connection, receives requests on that connection, and passes properly formatted requests to the handler via MessageReceived(). The connection thread implements HTTP/1.1 persistant connections; it can receive multiple requests over the same TCP conneciton.
The handler is responsible for sending any reply that may be required.
HTTPListener( HTTPHandler *handler, unsigned short port = 80, int acceptance_count = 32 )
Creates and initializes a HTTPListener object. The hander is a template handler. Ownership of the template handler is retained by the caller and it must not be deleted while the listener is running. The template is not actually used to handle the requests. The template's NewCopy() method is called when the listener needs another hander to process a connection.
The port argument is the TCP port number on the HTTPListener will listen. The defualt port for HTTP is port 80. The acceptance_count is the number of TCP connections the listener is willing to accept at a time. Connections are refused when the the number of active connections reaches the acceptance_count.
virtual ~HTTPListener( void )
virtual thread_id Run( void )
Starts the listener thread.
virtual void Quit( void )
Stops the listener thread.