Home | Libraries | People | FAQ | More |
TODO: Document using Acceptors
A basic_request_acceptor<>
is responsible for
accepting requests. The following typedefs
are provided for typical use:
boost::cgi::acceptor // CGI boost::fcgi::acceptor // FastCGI
Accepting requests is considered distinct to the loading stage for several reasons, the most significant of which is to allow for multiplexing protocols like FastCGI work with the other protocols.
A basic_request_acceptor<>
takes an instance of a ProtocolService
in its constructor. The
following member functions are available, where Request is any class that
models the Request
concept:
Function signature |
Purpose |
---|---|
|
Takes an empty request and blocks until a request is waiting to be handled. This will throw if the accept fails. |
|
Takes an empty request and blocks until a request is waiting to
be handled. |
|
Accepts a new request and calls |
|
Takes an empty request and asynchronously accepts a request. |
|
Cancel all outstanding asynchronous accepts that are running |
A simple example that runs a handler function for each request that is accepted. The requests are handled one at a time.
#include <boost/cgi/fcgi.hpp> namespace fcgi = boost::fcgi; int handler(fcgi::request& req) { // use the request. } int main() { // create a ProtocolService fcgi::service service; // create an acceptor fcgi::acceptor acceptor(service); int status(0) while(!status) { // accept a request status = acceptor.accept(&handler); } return status; }
Another example that allows you to construct your own request object and then accept a new request into the object. Useful if you need to store a list of requests in your application.
#include <boost/cgi/fcgi.hpp> int main() { using namespace cgi::fcgi; // for example // create a ProtocolService service service; // create an acceptor acceptor acceptor(service); // make an empty request request req(service); boost::system::error_code ec; // accept a request acceptor.accept(req, ec); if (!ec) { // a request was accepted ok } return 0; }