Changes between Version 13 and Version 14 of soc/2007/cgi
- Timestamp:
- Feb 18, 2008, 6:25:29 PM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
soc/2007/cgi
v13 v14 38 38 }}} 39 39 40 Protocols such as SCGI and FastCGI allow a single process to handle multiple requests. The simplest way to turn the above into a n SCGI ''daemon'' is to use the synchronous API provided by the library. For example:41 42 {{{ 43 #!cpp 44 #include <boost/cgi/ scgi.hpp> // Include only SCGI functionality45 46 using namespace boost:: scgi;40 Protocols such as SCGI and FastCGI allow a single process to handle multiple requests. The simplest way to turn the above into a FastCGI ''daemon'' is to use the synchronous API provided by the library. For example: 41 42 {{{ 43 #!cpp 44 #include <boost/cgi/fcgi.hpp> // Include only FastCGI functionality 45 46 using namespace boost::fcgi; 47 47 48 48 int main() … … 72 72 Using a multiplexing protocol (SCGI or FastCGI) in a multi-threaded environment can be much more flexible than the example above allows. In many (if not most) cases you will be able to increase the throughput of your daemon by handling more than one request at a time (ie. within each process). To get the most out of your process you should use the asynchronous functionality of the library - kindly provided by Boost.Asio. Making a fully asynchronous program requires a different approach to synchronous ones and can be quite mind-bending until you are used to it. 73 73 74 That said, you can still benefit from the asynchronous nature of the library without complicating your program by distinguishing between '''accepting''' requests and '''using''' them. For the example below, we can first create a Server, the purpose of which is to accept requests and pre-load the data from the clients (this is likely sub-optimal, but keeps the demonstration more to the point). The class shown is also not generic - it's only useable with FastCGI programs - but this is just to keep it concise. A generic version is provided (or should be soon) in the distribution.74 You can still benefit from the asynchronous nature of the library without complicating your program by distinguishing between '''accepting''' requests and '''using''' them. For the example below, we can first create a Server, the purpose of which is to accept requests and pre-load the data from the clients (this is likely sub-optimal, but keeps the demonstration more to the point). The class shown is also not generic - it's only useable with FastCGI programs - but this is just to keep it concise. A generic version is provided (or should be soon) in the distribution. 75 75 76 76 {{{ … … 191 191 192 192 === ```cgi::response``` === 193 This simply holds headers and the content of the response and provides various ways to write to it. Up until it is sent to the user, it is unaware of what it's a response to. This helps keep code - both library and user code - clean and explicit, without being overly verbose and aids significantly with response caching (something this library won't address for now). 193 This simply holds headers and the content of the response and provides various ways to write to it. Up until it is sent to the user, it is unaware of what it's a response to. This helps keep both library and user code clean and explicit, without being overly verbose and aids significantly with response caching (something this library won't address for now). 194 195 ''Use of this class is entirely optional.'' 194 196 195 197 === ```cgi::session``` === 196 198 This will provide simple session data caching. 197 199 198 === ```cgi::basic_ service<>``` ===199 This is the main class in the library. There should be specializations for each Protocol and the underlying structure should be generic enough to allow for any type of cgi-like protocol to be 'serviced', without sacrificing efficiency, clarity of code or any of the aims stated in the Design Notes.200 === ```cgi::basic_protocol_service<>``` === 201 This is the base class in the library. It is a container for the `io_service`s (from Boost.Asio) that implement asynchronous support and holds lists of current connections and of waiting requests from multiplexed connections. 200 202 201 203 == Important Internal Classes == 202 204 203 === ```cgi::basic_ gateway<>``` ===205 === ```cgi::basic_client<>``` === 204 206 The gateway is the abstraction of the interface with the server. This can vary from just an abstraction of std::cin/cout to a fully multiplexed set of connections, which can themselves be of more than one type. 205 207