Boost logo

Boost-Commit :

From: lists.drrngrvy_at_[hidden]
Date: 2007-08-15 23:30:58


Author: drrngrvy
Date: 2007-08-15 23:30:57 EDT (Wed, 15 Aug 2007)
New Revision: 38708
URL: http://svn.boost.org/trac/boost/changeset/38708

Log:
Added introduction.qbk (correctly); removed libs/cgi/build and libs/cgi/src directories; corrected erroneous usage of boost::system::error_code in async functions; added set_header/cookie interface to basic_request<> (not implemented yet) and noted that on first write or on request close, the header block is terminated (by the standard rn blank line)
Removed:
   sandbox/SOC/2007/cgi/libs/cgi/build/
   sandbox/SOC/2007/cgi/libs/cgi/src/
Text files modified:
   sandbox/SOC/2007/cgi/boost/cgi/basic_protocol_service.hpp | 24 ++++++++++++++----------
   sandbox/SOC/2007/cgi/boost/cgi/basic_request.hpp | 23 ++++++++++++++++++++---
   sandbox/SOC/2007/cgi/boost/cgi/connections/async_stdio.hpp | 22 ++++++++--------------
   sandbox/SOC/2007/cgi/boost/cgi/request_service.hpp | 5 ++---
   sandbox/SOC/2007/cgi/libs/cgi/doc/src/introduction.qbk | 18 ++++++++++++++++++
   sandbox/SOC/2007/cgi/libs/cgi/example/Jamfile.v2 | 15 ++++++---------
   sandbox/SOC/2007/cgi/libs/cgi/example/acgi/Jamfile.v2 | 3 ---
   sandbox/SOC/2007/cgi/libs/cgi/example/servers/fcgi_threadpool_server.cpp | 21 +++++++++++++++------
   8 files changed, 83 insertions(+), 48 deletions(-)

Modified: sandbox/SOC/2007/cgi/boost/cgi/basic_protocol_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/boost/cgi/basic_protocol_service.hpp (original)
+++ sandbox/SOC/2007/cgi/boost/cgi/basic_protocol_service.hpp 2007-08-15 23:30:57 EDT (Wed, 15 Aug 2007)
@@ -34,15 +34,19 @@
     //: public protocol_traits<Protocol> // do this!
   {
   public:
- typedef Protocol protocol_type;
- typedef IoServiceProvider ios_provider_type;
+ typedef Protocol protocol_type;
+ typedef IoServiceProvider ios_provider_type;
     typedef typename detail::protocol_traits<Protocol>::type traits;
- typedef typename traits::request_type request_type;
- //typedef typename traits::gateway_type gateway_type;
- //typedef basic_gateway<Protocol> gateway_type;
- //typedef basic_request<Protocol> request_type;
- typedef typename boost::shared_ptr<request_type> request_ptr;
- //typedef basic_acceptor<Protocol> acceptor_type;
+ typedef typename traits::request_type request_type;
+ typedef typename boost::shared_ptr<request_type> request_ptr;
+ typedef std::set<request_type::pointer> set_type;
+ //typename boost::mpl::if_<
+ // boost::is_same<protocol_type, tags::acgi>::value
+ // , request_type::pointer
+ // , std::set<request_type::pointer>
+ // >::type
+
+ typedef std::queue<request_type::pointer> queue_type;
 
 
     basic_protocol_service(int pool_size_hint = 1)
@@ -131,8 +135,8 @@
     //boost::asio::strand strand_;
 
 
- std::set<request_ptr> request_set_;
- std::queue<request_ptr> request_queue_;
+ set_type request_set_;
+ queue_type request_queue_;
 
     //gateway_type gateway_;
 

Modified: sandbox/SOC/2007/cgi/boost/cgi/basic_request.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/boost/cgi/basic_request.hpp (original)
+++ sandbox/SOC/2007/cgi/boost/cgi/basic_request.hpp 2007-08-15 23:30:57 EDT (Wed, 15 Aug 2007)
@@ -95,7 +95,7 @@
     {
       if (load_now) load(ec, parse_post);//this->service.load(this->impl, true, ec);
     }
-
+
     basic_request(protocol_service_type& s, const bool load_now = false
                  , const bool parse_post = false)
       : basic_io_object<Service>(s.io_service())
@@ -123,6 +123,15 @@
       return this->service.is_open(this->impl);
     }
 
+ /// Set a header
+ void set_header(const std::string& name, const std::string& val)
+ {
+ this->service.set_header(this->impl, name, val);
+ }
+
+ /// Set a cookie
+ void set_cookie
+
     /// Synchronously read/parse the request meta-data
     /**
      * Note: 'loading' including reading/parsing STDIN if parse_stdin == true
@@ -137,11 +146,11 @@
 
     // Error-code semantics
     boost::system::error_code& load(boost::system::error_code& ec
- , bool parse_stdin = false)
+ , bool parse_stdin = false)
     {
       return this->service.load(this->impl, parse_stdin, ec);
     }
-
+
 
     /// Asynchronously read/parse the request meta-data
     /**
@@ -224,6 +233,10 @@
     }
 
     /// Write some data to the client
+ /**
+ * Note: on the first write, the header block is closed (with a blank
+ * line).
+ */
     template<typename ConstBufferSequence/*, typename Sink*/>
     std::size_t write_some(const ConstBufferSequence& buf)
     {
@@ -234,6 +247,10 @@
     }
 
     /// Write some data to the client
+ /**
+ * Note: on the first write, the header block is closed (with a blank
+ * line).
+ */
     template<typename ConstBufferSequence/*, typename Sink*/>
     std::size_t write_some(const ConstBufferSequence& buf
                           , boost::system::error_code& ec)

Modified: sandbox/SOC/2007/cgi/boost/cgi/connections/async_stdio.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/boost/cgi/connections/async_stdio.hpp (original)
+++ sandbox/SOC/2007/cgi/boost/cgi/connections/async_stdio.hpp 2007-08-15 23:30:57 EDT (Wed, 15 Aug 2007)
@@ -47,10 +47,9 @@
     {
     public:
       read_handler(ConnectionPtr cptr, MutableBufferSequence& buf
- , boost::system::error_code& ec, Handler handler)
+ , Handler handler)
         : cptr_(cptr)
         , buf_(buf)
- , ec_(ec)
         , handler_(handler)
       {
       }
@@ -58,22 +57,20 @@
       void operator()()
       {
         std::size_t bytes_read = cptr_->read_some(buf_, ec_);
- handler_(ec_, bytes_read);
+ handler_(boost::system::error_code(), bytes_read);
       }
 
     private:
       ConnectionPtr cptr_;
       MutableBufferSequence& buf_;
- boost::system::error_code& ec_;
       Handler handler_;
     };
 
     template<typename MutableBufferSequence, typename Handler>
- void async_read_some(MutableBufferSequence buf, boost::system::error_code& ec
- , Handler handler)
+ void async_read_some(MutableBufferSequence buf, Handler handler)
     {
       io_service_.post(read_handler<pointer, MutableBufferSequence, Handler>
- (shared_from_this(), buf, ec, handler));
+ (shared_from_this(), buf, handler));
     }
 
     template<typename ConnectionPtr, typename ConstBufferSequence
@@ -82,10 +79,9 @@
     {
     public:
       write_handler(ConnectionPtr cptr, ConstBufferSequence& buf
- , boost::system::error_code& ec, Handler handler)
+ , Handler handler)
         : cptr_(cptr)
         , buf_(buf)
- , ec_(ec)
         , handler_(handler)
       {
       }
@@ -93,22 +89,20 @@
       void operator()()
       {
         std::size_t bytes_written = cptr_->write_some(buf_, ec_);
- handler_(ec_, bytes_written);
+ handler_(boost::system::error_code(), bytes_written);
       }
 
     private:
       ConnectionPtr cptr_;
       ConstBufferSequence& buf_;
- boost::system::error_code& ec_;
       Handler handler_;
     };
 
     template<typename ConstBufferSequence, typename Handler>
- void async_write_some(ConstBufferSequence& buf, boost::system::error_code& ec
- , Handler handler)
+ void async_write_some(ConstBufferSequence& buf, Handler handler)
     {
       io_service_.post(write_handler<pointer, ConstBufferSequence, Handler>
- (shared_from_this(), buf, ec, handler));
+ (shared_from_this(), buf, handler));
     }
 
   private:

Modified: sandbox/SOC/2007/cgi/boost/cgi/request_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/boost/cgi/request_service.hpp (original)
+++ sandbox/SOC/2007/cgi/boost/cgi/request_service.hpp 2007-08-15 23:30:57 EDT (Wed, 15 Aug 2007)
@@ -93,10 +93,9 @@
 
 
     template<typename Handler>
- void async_load(impl_type& impl, bool parse_stdin, boost::system::error_code& ec
- , Handler handler)
+ void async_load(impl_type& impl, bool parse_stdin, Handler handler)
     {
- service_impl_.async_load(impl, parse_stdin, ec, handler);
+ service_impl_.async_load(impl, parse_stdin, handler);
     }
 
     bool is_open(impl_type& impl)

Modified: sandbox/SOC/2007/cgi/libs/cgi/doc/src/introduction.qbk
==============================================================================
--- sandbox/SOC/2007/cgi/libs/cgi/doc/src/introduction.qbk (original)
+++ sandbox/SOC/2007/cgi/libs/cgi/doc/src/introduction.qbk 2007-08-15 23:30:57 EDT (Wed, 15 Aug 2007)
@@ -7,6 +7,24 @@
 
 [section:intro Introduction]
 
+This CGI library reasonably high-level library for web programming. In the Model-View-Controller idiom, herein is implemented the controller portion. The intricacies of dealing with the widely varying specifications of CGI, FastCGI and SCGI are abstracted into three main sub-parts:
 
+* Accepting,
+
+* Loading, and
+
+* Handling
+
+This is all described in more detail in the [link __tutorial__ tutorial].
+
+If a program's purpose is to serve the wider world, it should be written with scalability in mind. The `cgi::srequest` (the 's' is for 'synchronous' - ie. asynchronous operations cannot be used with it) that the [link __quickstart__ quickstart] introduces is simple to use and ideal for shorter, light-use programs, such as admin scripts. However when it comes to heavily used web applications CGI has an inherent limitation: there must be a complete heavyweight process for each client.
+
+FastCGI and SCGI both remove this restriction and there is support for them - of widely varying quality and completeness (see [link __server_support__ here])- in most HTTP servers. These protocols add an extra layer to your CGI programs, as you now must manage the request queue.
+
+Parsing of request meta-data can be done at any point in the program, or not at all. Reading and parsing of data is referred to as '[link __loading__ loading]' and this follows '[link __accepting__ accepting]' a request.
+
+Fortunately, this layer can be largely isolated from the rest of your program logic and development of both can continue in parallel. The two parts share a [link __Service__ service], such as a `cgi::fcgi_service` (similar in use to an [link __asio_io_service__ asio::io_service] for those familiar with [link __asio__ Boost.Asio]).
+
+The [link __examples__ examples] are divided like this.
 
 [endsect]

Modified: sandbox/SOC/2007/cgi/libs/cgi/example/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/cgi/libs/cgi/example/Jamfile.v2 (original)
+++ sandbox/SOC/2007/cgi/libs/cgi/example/Jamfile.v2 2007-08-15 23:30:57 EDT (Wed, 15 Aug 2007)
@@ -9,21 +9,18 @@
 
 local BOOST_ROOT = [ os.environ BOOST_ROOT ] ;
 
-#project boost/cgi/examples
-# : build-dir ../../../bin.v2
-# ;
 
 
 install examples
   : # the sources
     easy_cgi
     acgi
- reply
+ #reply
   : <location>/var/www/cgi-bin
   ;
 
-install scgi
- : # the sources
- scgi
- : <location>/var/www/scgi-bin
- ;
\ No newline at end of file
+#install scgi
+# : # the sources
+# scgi
+# : <location>/var/www/scgi-bin
+# ;
\ No newline at end of file

Modified: sandbox/SOC/2007/cgi/libs/cgi/example/acgi/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/cgi/libs/cgi/example/acgi/Jamfile.v2 (original)
+++ sandbox/SOC/2007/cgi/libs/cgi/example/acgi/Jamfile.v2 2007-08-15 23:30:57 EDT (Wed, 15 Aug 2007)
@@ -9,9 +9,6 @@
 
 local BOOST_ROOT = [ os.environ BOOST_ROOT ] ;
 
-#project boost/cgi/examples/acgi
-# : build-dir ../bin.v2
-# ;
 
 SOURCES = main ;
 

Modified: sandbox/SOC/2007/cgi/libs/cgi/example/servers/fcgi_threadpool_server.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/libs/cgi/example/servers/fcgi_threadpool_server.cpp (original)
+++ sandbox/SOC/2007/cgi/libs/cgi/example/servers/fcgi_threadpool_server.cpp 2007-08-15 23:30:57 EDT (Wed, 15 Aug 2007)
@@ -15,7 +15,7 @@
     typedef cgi::fcgi_acceptor acceptor_type;
     typedef boost::function<int (cgi::fcgi_request&)> handler_type;
 
- /// Constructor
+ /// Constructor (could use Boost.Parameter)
     fcgi_threadpool_server(int num_threads, const handler_type& handler)
       : service_()
       , acceptor_(service_)
@@ -27,6 +27,9 @@
     }
 
     /// Run the io_service(s) that service_ uses
+ /**
+ * This call will block until all of the service_'s work has been completed.
+ */
     void run()
     {
       for (int i = num_threads_; i != 0; i++)
@@ -37,22 +40,28 @@
       thread_group_.join_all();
     }
 
+ /// Stop the server
+ /**
+ * All outstanding async operations will be cancelled when the acceptor
+ * is closed. The server should not be used again until after a call to
+ * `reset`.
+ */
     void stop()
     {
- acceptor_.cancel();
       acceptor_.close();
     }
 
+ /// Start an async accept on a new request object
     void start_accept()
     {
- request_type::pointer new_request(new request_type(service_));
- acceptor_.async_accept(new_request
- , boost::bind(&type::accept_handler
+ request_type::pointer new_request = request_type::create(service_);
+ acceptor_.async_accept(*new_request
+ , boost::bind(&type::handle_accept
                                          , shared_from_this(), new_request
                                          , boost::arg<1>));
     }
 
- /// If no errors, asynchronously load the request and call start_accept() again
+ /// Asynchronously load the request and call `start_accept` again
     void handle_accept(request_type::pointer req, boost::system::error_code& ec)
     {
       if (!ec)


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk