Boost logo

Boost-Commit :

From: lists.drrngrvy_at_[hidden]
Date: 2008-03-12 20:59:36


Author: drrngrvy
Date: 2008-03-12 20:59:35 EDT (Wed, 12 Mar 2008)
New Revision: 43585
URL: http://svn.boost.org/trac/boost/changeset/43585

Log:
Various fixes, mostly to FastCGI parts; one or two small changes to aCGI/CGI files.
Text files modified:
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request_impl.hpp | 1
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request_service.hpp | 7 +
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_io_object.hpp | 12 +-
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_request.hpp | 119 ++++++++++++++++++----------
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/shareable_tcp_socket.hpp | 47 +++++++++++
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/tcp_socket.hpp | 1
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cookie.hpp | 8 +
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/common_headers.hpp | 1
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/throw_error.hpp | 9 +
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/error.hpp | 4
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/client.hpp | 35 ++++++++
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/request.hpp | 6
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/request_service.hpp | 163 +++++++++++++++++++++++++++------------
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/header.hpp | 14 +++
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/response.hpp | 9 +
   15 files changed, 322 insertions(+), 114 deletions(-)

Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request_impl.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request_impl.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request_impl.hpp 2008-03-12 20:59:35 EDT (Wed, 12 Mar 2008)
@@ -34,6 +34,7 @@
     {
     }
 
+ protocol_service_type* service_;
   protected:
     //acgi_request_impl(); // private default constructor
     friend class acgi_service_impl;

Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request_service.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request_service.hpp 2008-03-12 20:59:35 EDT (Wed, 12 Mar 2008)
@@ -44,6 +44,7 @@
     void shutdown_service()
     {
     }
+
     void construct(implementation_type& impl)
     {
       impl.client_.set_connection(
@@ -54,7 +55,11 @@
     void destroy(implementation_type& impl)
     {
     }
-
+
+ void set_service(implementation_type& impl, protocol_service_type& ps)
+ {
+ impl.service_ = &ps;
+ }
   };
 
 } // namespace cgi

Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_io_object.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_io_object.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_io_object.hpp 2008-03-12 20:59:35 EDT (Wed, 12 Mar 2008)
@@ -29,26 +29,27 @@
 
   private:
     typedef typename Service::implementation_type impl_type;
+ typedef typename Service::implementation_type implementation_type;
 
   protected:
     explicit basic_io_object(::cgi::io_service& ios)
       : service(boost::asio::use_service<Service>(ios))
     {
- service.construct(impl);
+ service.construct(implementation);
     }
 
     ~basic_io_object()
     {
- service.destroy(impl);
+ service.destroy(implementation);
     }
 
- impl_type impl;
+ implementation_type implementation;
     service_type& service;
   };
 
   /*
- template<typename Service>
- class basic_io_object<Service, false>
+ template<>
+ class basic_io_object< ::cgi::request>
     : private boost::noncopyable
   {
   public:
@@ -68,6 +69,7 @@
 
     impl_type impl;
     service_type service;
+ boost::asio::io_service io_service;
   };
   */
 

Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_request.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_request.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_request.hpp 2008-03-12 20:59:35 EDT (Wed, 12 Mar 2008)
@@ -94,7 +94,7 @@
     basic_request(bool load_now = true, bool parse_post = true)
       : basic_sync_io_object<service_type>()
     {
- if (load_now) load(parse_post);//this->service.load(this->impl, true, ec);
+ if (load_now) load(parse_post);//this->service.load(this->implementation, true, ec);
     }
 
                 // Won't throw
@@ -103,7 +103,7 @@
                  , const bool parse_post = true)
       : basic_sync_io_object<service_type>()
     {
- if (load_now) load(ec, parse_post);//this->service.load(this->impl, true, ec);
+ if (load_now) load(ec, parse_post);//this->service.load(this->implementation, true, ec);
     }
 
                 // Throws
@@ -112,7 +112,7 @@
       : basic_io_object<service_type>(s.io_service())
     {
       set_protocol_service(s);
- if (load_now) load(parse_post);//this->service.load(this->impl, false, ec);
+ if (load_now) load(parse_post);//this->service.load(this->implementation, false, ec);
     }
 
                 // Won't throw
@@ -122,24 +122,49 @@
       : basic_io_object<service_type>(s.io_service())
     {
       set_protocol_service(s);
- if(load_now) load(ec, parse_post);//this->service.load(this->impl, false, ec);
+ if(load_now) load(ec, parse_post);//this->service.load(this->implementation, false, ec);
     }
 
+ /// Make a new mutiplexed request from an existing connection.
+ basic_request(implementation_type& impl)
+ : basic_io_object<service_type>(impl.service_->io_service())
+ {
+ set_protocol_service(*impl.service_);
+ boost::system::error_code ec;
+ this->service.begin_request_helper(this->implementation
+ , impl.header_buf_, ec);
+ detail::throw_error(ec);
+ }
+
+ /// Make a new mutiplexed request from an existing connection.
+ basic_request(implementation_type& impl, boost::system::error_code& ec)
+ : basic_io_object<service_type>(impl.service_->io_service())
+ {
+ set_protocol_service(*impl.service_);
+ this->service.begin_request_helper(this->implementation
+ , impl.header_buf_, ec);
+ }
+
     ~basic_request()
     {
       //if (is_open())
       // close(http::internal_server_error, 0);
     }
 
+ static pointer create(protocol_service_type& ps)
+ {
+ return pointer(new type(ps));
+ }
+
     void set_protocol_service(protocol_service_type& ps)
     {
- this->service.set_service(this->impl, ps);
+ this->service.set_service(this->implementation, ps);
     }
 
     /// Return `true` if the request is still open (ie. not aborted or closed)
     bool is_open()
     {
- return this->service.is_open(this->impl);
+ return this->service.is_open(this->implementation);
     }
 
     /// Synchronously read/parse the request meta-data
@@ -150,7 +175,7 @@
     void load(bool parse_stdin = false)
     {
       boost::system::error_code ec;
- this->service.load(this->impl, parse_stdin, ec);
+ this->service.load(this->implementation, parse_stdin, ec);
       detail::throw_error(ec);
     }
 
@@ -158,7 +183,7 @@
     boost::system::error_code&
       load(boost::system::error_code& ec, bool parse_stdin = false)
     {
- return this->service.load(this->impl, parse_stdin, ec);
+ return this->service.load(this->implementation, parse_stdin, ec);
     }
 
 
@@ -169,7 +194,8 @@
     template<typename Handler>
     void async_load(Handler handler, bool parse_stdin = false)
     {
- this->service.async_load(this->impl, parse_stdin, handler);
+ this->service.async_load(this->implementation, parse_stdin
+ , handler);
     }
 
     /// Notify the server the request has finished being handled
@@ -190,21 +216,23 @@
     {
       //BOOST_ASSERT( request_status_ != status_type::ended );
 
- //this->service.set_status(this->impl, http_status);
- return this->service.close(this->impl, http_status, program_status);
+ //this->service.set_status(this->implementation, http_status);
+ return this->service.close(this->implementation, http_status
+ , program_status);
     }
 
     /// Reject the request with a standard '500 Internal Server Error' error
     int reject()
     {
- this->service.set_status(this->impl, aborted);
- return this->service.close(this->impl, http::internal_server_error);
+ this->service.set_status(this->implementation, aborted);
+ return this->service.close(this->implementation
+ , http::internal_server_error);
     }
 
     /// Abort a request
     void abort()
     {
- this->service.set_status(this->impl, aborted);
+ this->service.set_status(this->implementation, aborted);
     }
 
     /// Get the client connection associated with the request
@@ -213,7 +241,7 @@
                  */
     client_type& client()
     {
- return this->service.client(this->impl);
+ return this->service.client(this->implementation);
     }
 
     /// Set the output for the request
@@ -226,7 +254,7 @@
     void set_output(cgi::sink dest = stdout_)
     {
       boost::system::error_code ec;
- this->service(this->impl, dest, ec);
+ this->service(this->implementation, dest, ec);
       detail::throw_error(ec);
     }
     */
@@ -234,29 +262,30 @@
     void read_some()
     {
       boost::system::error_code ec;
- this->service.read_some(this->implementation,ec);
+ this->service.read_some(this->implementationementation,ec);
       detail::throw_error(ec);
     }
 
     boost::system::error_code
       read_some(boost::system::error_code& ec)
     {
- return this->service.read_some(this->implementation, ec);
+ return this->service.read_some(this->implementationementation, ec);
     }
 */
     template<typename MutableBufferSequence>
     void read_some(const MutableBufferSequence& buf)
     {
       boost::system::error_code ec;
- this->service.read_some(this->impl, buf, ec);
+ this->service.read_some(this->implementation, buf, ec);
       detail::throw_error(ec);
     }
 
     template<typename MutableBufferSequence>
     boost::system::error_code
- read_some(const MutableBufferSequence& buf, boost::system::error_code& ec)
+ read_some(const MutableBufferSequence& buf
+ , boost::system::error_code& ec)
     {
- return this->service.read_some(this->impl, buf, ec);
+ return this->service.read_some(this->implementation, buf, ec);
     }
 
     /// Set the output for the request
@@ -268,14 +297,14 @@
     /*
     void set_output(cgi::sink dest, boost::system::error_code& ec)
     {
- this->service(this->impl, dest, ec);
+ this->service(this->implementation, dest, ec);
     }
     */
 
     /// Get a `cgi::map&` corresponding to all of the GET variables
     map_type& GET()
     {
- return this->service.GET(this->impl);
+ return this->service.GET(this->implementation);
     }
 
     /// Find the get meta-variable matching name
@@ -287,7 +316,7 @@
     std::string GET(const std::string& name)
     {
       boost::system::error_code ec;
- std::string ret = this->service.GET(this->impl, name, ec);
+ std::string ret = this->service.GET(this->implementation, name, ec);
       detail::throw_error(ec);
       return ret;
     }
@@ -300,13 +329,13 @@
      */
     std::string GET(const std::string& name, boost::system::error_code& ec)
     {
- return this->service.GET(this->impl, name, ec);
+ return this->service.GET(this->implementation, name, ec);
     }
 
     /// Get a `cgi::map&` corresponding to all of the POST variables
     map_type& POST()
     {
- return this->service.POST(this->impl);
+ return this->service.POST(this->implementation);
     }
 
     /// Find the post meta-variable matching name
@@ -322,7 +351,8 @@
     std::string POST(const std::string& name, bool greedy = true)
     {
       boost::system::error_code ec;
- std::string ret = this->service.POST(this->impl, name, ec, greedy);
+ std::string ret
+ = this->service.POST(this->implementation, name, ec, greedy);
       detail::throw_error(ec);
       return ret;
     }
@@ -335,14 +365,14 @@
     std::string POST(const std::string& name, boost::system::error_code& ec
                           , bool greedy = true)
     {
- return this->service.POST(this->impl, name, ec, greedy);
+ return this->service.POST(this->implementation, name, ec, greedy);
     }
 
     /// Get a `cgi::map&` corresponding to all of the form variables
     map_type& form(bool greedy = true)
     {
                   boost::system::error_code ec;
- map_type& data = this->service.form(this->impl, ec, greedy);
+ map_type& data = this->service.form(this->implementation, ec, greedy);
                         detail::throw_error(ec);
                         return data;
     }
@@ -374,10 +404,10 @@
     {
       std::string rm(request_method());
       if (rm == "GET")
- return this->service.GET(this->impl, name, ec);
+ return this->service.GET(this->implementation, name, ec);
       else
       if (rm == "POST")
- return this->service.POST(this->impl, name, ec, greedy);
+ return this->service.POST(this->implementation, name, ec, greedy);
       else
         return "";
     }
@@ -385,7 +415,7 @@
     /// Get a `cgi::map&` corresponding to all of the HTTP_COOKIE variables
     map_type& cookie()
     {
- return this->service.cookie(this->impl);
+ return this->service.cookie(this->implementation);
     }
 
     /// Find the cookie meta-variable matching name
@@ -397,7 +427,8 @@
     std::string cookie(const std::string& name)
     {
       boost::system::error_code ec;
- std::string ret = this->service.cookie(this->impl, name, ec);
+ std::string ret
+ = this->service.cookie(this->implementation, name, ec);
       detail::throw_error(ec);
       return ret;
     }
@@ -410,13 +441,13 @@
      */
     std::string cookie(const std::string& name, boost::system::error_code& ec)
     {
- return this->service.cookie(this->impl, name, ec);
+ return this->service.cookie(this->implementation, name, ec);
     }
 
     /// Get a `cgi::map&` corresponding to all of the environment variables
     map_type& env()
     {
- return this->service.env(this->impl);
+ return this->service.env(this->implementation);
     }
 
     /// Find the environment meta-variable matching name
@@ -428,7 +459,7 @@
     std::string env(const std::string& name)
     {
       boost::system::error_code ec;
- std::string ret = this->service.env(this->impl, name, ec);
+ std::string ret = this->service.env(this->implementation, name, ec);
       detail::throw_error(ec);
       return ret;
     }
@@ -441,7 +472,7 @@
      */
     std::string env(const std::string& name, boost::system::error_code& ec)
     {
- return this->service.env(this->impl, name, ec);
+ return this->service.env(this->implementation, name, ec);
     }
 
     /// Search through all meta vars for the meta-variable matching name
@@ -462,7 +493,7 @@
     {
       boost::system::error_code ec;
       std::string ret = var(name, ec, greedy);
- return this->service.var(this->impl, name, greedy);
+ return this->service.var(this->implementation, name, greedy);
       std::string request_method( env("REQUEST_METHOD") );
 
       std::string tmp;
@@ -569,7 +600,7 @@
      */
     role_type& role()
     {
- return this->service.get_role(this->impl);
+ return this->service.get_role(this->implementation);
     }
 
     /// Get the strand associated with the request (if any)
@@ -579,25 +610,25 @@
     // and there would be no need for protocol-specific code in user programs.
       /* boost::asio::strand* strand()
     {
- return this->impl.strand();
+ return this->implementation.strand();
     }
       */
 
     /// Get the implementation type for the request
- //impl_type& impl() const
+ //implementation_type* impl()
     //{
- // return this->impl;
+ // return &(this->implementation);
     //}
 
     void set_status(http::status_code status)
     {
- this->service.set_status(this->impl, status);
+ this->service.set_status(this->implementation, status);
     }
 
     // The boundary marker for multipart forms (this is likely a transient function).
     std::string boundary_marker()
     {
- return this->impl.boundary_marker;
+ return this->implementation.boundary_marker;
     }
   };
 

Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/shareable_tcp_socket.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/shareable_tcp_socket.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/shareable_tcp_socket.hpp 2008-03-12 20:59:35 EDT (Wed, 12 Mar 2008)
@@ -10,10 +10,13 @@
 #define CGI_CONNECTIONS_SHAREABLE_TCP_SOCKET_HPP_INCLUDED__
 
 #include <map>
+#include <set>
 #include <boost/cstdint.hpp>
+#include <boost/foreach.hpp>
 #include <boost/shared_ptr.hpp>
 
 #include "boost/cgi/tags.hpp"
+#include "boost/cgi/error.hpp"
 #include "boost/cgi/io_service.hpp"
 #include "boost/cgi/connection_base.hpp"
 #include "boost/cgi/basic_connection.hpp"
@@ -52,7 +55,7 @@
     typedef
       detail::protocol_traits<fcgi_>::request_ptr request_ptr;
     typedef std::map<boost::uint16_t, request_type*> request_map_type;
- typedef std::vector<request_ptr> request_vector_type;
+ typedef std::vector<request_type*> request_vector_type;
 
     /** End FastCGI stuff **/
 
@@ -67,6 +70,15 @@
     {
     }
 
+ ~basic_connection()
+ {
+ //BOOST_FOREACH(boost::uint16_t id, deletable_request_ids_)
+ //{
+ // delete requests_.at(id-1);
+ // requests_.at(id-1) = 0;
+ //}
+ }
+
     bool is_open() const
     {
       return sock_.is_open();
@@ -129,6 +141,38 @@
 
     mutex_type& mutex() { return mutex_; }
     condition_type& condition() { return condition_; }
+
+ boost::system::error_code
+ get_slot(boost::uint16_t id, boost::system::error_code& ec)
+ {
+ if (requests_.at(id-1)) // duplicate request!
+ {
+ return error::duplicate_request;
+ }
+
+ if (requests_.size() < (id-1))
+ requests_.resize(id);
+
+ return ec;
+ }
+
+ boost::system::error_code
+ add_request(boost::uint16_t id, request_type* req, bool on_heap
+ , boost::system::error_code& ec)
+ {
+ requests_.at(id-1) = req;
+ if (on_heap)
+ deletable_request_ids_.insert(id);
+ return ec;
+ }
+
+ //template<typename RequestImpl>
+ //boost::system::error_code
+ // multiplex(RequestImpl& impl, boost::system::error_code& ec)
+ //{
+ //
+ // return ec;
+ //}
   private:
     
     next_layer_type sock_;
@@ -139,6 +183,7 @@
     /** FastCGI specific stuff **/
     request_map_type request_map_;
     request_vector_type requests_;
+ std::set<int> deletable_request_ids_;
   };
 
   // probably deletable typedef (leaving it here to keep an open mind)

Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/tcp_socket.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/tcp_socket.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/tcp_socket.hpp 2008-03-12 20:59:35 EDT (Wed, 12 Mar 2008)
@@ -10,6 +10,7 @@
 #define CGI_CONNECTIONS_TCP_SOCKET_HPP_INCLUDED__
 
 #include <boost/shared_ptr.hpp>
+#include <boost/asio/ip/tcp.hpp>
 
 #include "boost/cgi/tags.hpp"
 #include "boost/cgi/io_service.hpp"

Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cookie.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cookie.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cookie.hpp 2008-03-12 20:59:35 EDT (Wed, 12 Mar 2008)
@@ -30,7 +30,7 @@
    * TODO
    * - Data should be URL-encoded, or maybe provide an overload for url_decode
    * that takes an HttpCookie?
- * - Add to_string() ?
+ * - Add from_string() ?
    */
   template<typename String>
   struct basic_cookie
@@ -132,11 +132,13 @@
   };
 
   template<typename OutStream, typename T>
- OutStream& operator<<(OutStream& os, const basic_cookie<T>& ck)
+ OutStream& operator<<(OutStream& os, basic_cookie<T>& ck)
   {
- return os<< ck.to_string();
+ os<< ck.to_string();
+ return os;
   }
 
 } // namespace cgi
 
 #endif // CGI_COOKIE_HPP_INCLUDED__
+

Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/common_headers.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/common_headers.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/common_headers.hpp 2008-03-12 20:59:35 EDT (Wed, 12 Mar 2008)
@@ -23,5 +23,6 @@
 #include "boost/cgi/read.hpp"
 #include "boost/cgi/write.hpp"
 #include "boost/cgi/header.hpp"
+#include "boost/cgi/return.hpp"
 
 #endif // CGI_CGI_CGI_HPP_INCLUDED__

Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/throw_error.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/throw_error.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/throw_error.hpp 2008-03-12 20:59:35 EDT (Wed, 12 Mar 2008)
@@ -11,15 +11,18 @@
 
 #include <boost/system/error_code.hpp>
 #include <boost/system/system_error.hpp>
+#include <boost/throw_exception.hpp>
 
 namespace cgi {
  namespace detail {
 
- void throw_error(const boost::system::error_code& ec)
+ inline void throw_error(const boost::system::error_code& ec)
    {
      if(ec)
-// throw ec;
- throw boost::system::system_error(ec);
+ {
+ boost::system::system_error err(ec);
+ boost::throw_exception(err);
+ }
    }
 
  } // namespace detail

Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/error.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/error.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/error.hpp 2008-03-12 20:59:35 EDT (Wed, 12 Mar 2008)
@@ -42,7 +42,9 @@
 
   // For now a user has to recognise this error and construct a request
   // themselves. This is an ugly hack.
- multiplexed_request_incoming
+ multiplexed_request_incoming,
+
+ duplicate_request
 };
 
   namespace detail {

Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/client.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/client.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/client.hpp 2008-03-12 20:59:35 EDT (Wed, 12 Mar 2008)
@@ -59,6 +59,7 @@
       , fcgi::spec::header_length::value
> header_buffer_type;
     typedef boost::asio::mutable_buffers_1 mutable_buffers_type;
+ typedef fcgi::spec_detail::role_t role_type;
 
     /// Construct
     basic_client()
@@ -104,11 +105,41 @@
       return connection_->is_open();
     }
 
- void close()
+ void close(boost::uint64_t app_status = 0)
     {
       if (status_ == closed_) return;
 
+ std::vector<boost::asio::const_buffer> bufs;
+
       // Write an EndRequest packet to the server.
+ out_header_[0] = static_cast<unsigned char>(1); // FastCGI version
+ out_header_[1] = static_cast<unsigned char>(3); // BEGIN_REQUEST
+ out_header_[2] = static_cast<unsigned char>(request_id_ >> 8) & 0xff;
+ out_header_[3] = static_cast<unsigned char>(request_id_) & 0xff;
+ out_header_[4] = static_cast<unsigned char>(8 >> 8) & 0xff;
+ out_header_[5] = static_cast<unsigned char>(8) & 0xff;
+ out_header_[6] = static_cast<unsigned char>(0);
+ out_header_[7] = 0;
+
+ BOOST_ASSERT(role_ == fcgi::spec_detail::RESPONDER
+ && "Only supports Responder role for now (**FIXME**)");
+
+ header_buffer_type end_request_body =
+ {{
+ static_cast<unsigned char>(app_status >> 24) & 0xff
+ , static_cast<unsigned char>(app_status >> 16) & 0xff
+ , static_cast<unsigned char>(app_status >> 8) & 0xff
+ , static_cast<unsigned char>(app_status >> 0) & 0xff
+ , static_cast<unsigned char>(fcgi::spec_detail::REQUEST_COMPLETE)
+ , static_cast<unsigned char>(0)
+ , static_cast<unsigned char>(0)
+ , static_cast<unsigned char>(0)
+ }};
+
+ bufs.push_back(buffer(out_header_));
+ bufs.push_back(buffer(end_request_body));
+
+ write(*connection_, bufs);
 
       if (!keep_connection_ && connection_)
         connection_->close();
@@ -223,7 +254,7 @@
     header_buffer_type out_header_;
 
     bool keep_connection_;
-
+ role_type role_;
 
   public:
 

Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/request.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/request.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/request.hpp 2008-03-12 20:59:35 EDT (Wed, 12 Mar 2008)
@@ -12,8 +12,9 @@
 #include "boost/cgi/tags.hpp"
 #include "boost/cgi/basic_request_fwd.hpp"
 //#include "boost/cgi/request_service_fwd.hpp"
-#include "boost/cgi/fcgi/request_service.hpp"
 #include "boost/cgi/fcgi/service.hpp"
+#include "boost/cgi/fcgi/request_service.hpp"
+
 namespace cgi {
 
  namespace fcgi {
@@ -22,7 +23,6 @@
  } // namespace fcgi
 } // namespace cgi
 
-//#include "boost/cgi/request_service.hpp"
-#include "boost/cgi/basic_request.hpp"
+//#include "boost/cgi/basic_request.hpp"
 
 #endif // CGI_FCGI_REQUEST_HPP_INCLUDED__

Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/request_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/request_service.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/request_service.hpp 2008-03-12 20:59:35 EDT (Wed, 12 Mar 2008)
@@ -20,6 +20,7 @@
 #include "boost/cgi/detail/throw_error.hpp"
 #include "boost/cgi/detail/service_base.hpp"
 #include "boost/cgi/detail/extract_params.hpp"
+//#include "boost/cgi/basic_request.hpp"
 #include "boost/cgi/fcgi/client.hpp"
 
 namespace cgi {
@@ -47,6 +48,9 @@
       typedef detail::protocol_traits<
         protocol_type
>::protocol_service_type protocol_service_type;
+ typedef detail::protocol_traits<
+ protocol_type
+ >::request_type request_type;
 
       implementation_type()
         : client_()
@@ -113,6 +117,7 @@
     typedef ::cgi::fcgi::fcgi_request_service full_type;
     typedef type::implementation_type::protocol_type protocol_type;
     typedef type::implementation_type::map_type map_type;
+ typedef type::implementation_type::request_type request_type;
 
     fcgi_request_service(::cgi::io_service& ios)
       : detail::service_base<fcgi_request_service>(ios)
@@ -159,7 +164,7 @@
               , int program_status)
     {
       impl.all_done_ = true;
- impl.client_.close();
+ impl.client_.close(program_status);
       return program_status;
     }
 
@@ -417,7 +422,7 @@
   /***************************************************************************/
   public: // Reading stuff goes under here
 
-
+ // **FIXME**
     /// Read some data from the client.
     template<typename MutableBufferSequence>
     std::size_t
@@ -484,45 +489,7 @@
     boost::system::error_code
       process_begin_request(implementation_type& impl, boost::uint16_t id
                            , const unsigned char* buf, boost::uint16_t
- , boost::system::error_code& ec)
- {
- //implementation_type& req
- // = impl.client_.request_id_ == 0
- // ? impl
- // : get_or_make_request(impl);
-
- if (impl.client_.request_id_ == 0) // ie. not set
- {
- impl.client_.request_id_ = fcgi::spec::get_request_id(impl.header_buf_);
-
- BOOST_STATIC_ASSERT((
- fcgi::spec::begin_request::body::size::value
- == fcgi::spec::header_length::value));
-
- // A begin request body is as long as a header, so we can optimise:
- if (read_header(impl, ec))
- return ec;
-
- impl.request_role_ = fcgi::spec::begin_request::get_role(impl.header_buf_);
- std::cerr<< "[hw] New request role: " << impl.request_role_
- << " (" << fcgi::spec::role_type::to_string(impl.header_buf_) << ")"
- << std::endl;
- impl.client_.keep_connection_
- = fcgi::spec::begin_request::get_flags(impl.header_buf_)
- & fcgi::spec::keep_connection;
-
- impl.client_.status_ = constructed;
- }
- else
- {
- std::cerr<< "**FIXME** Role: "
- << fcgi::spec::begin_request::get_role(impl.header_buf_) << std::endl;
- return error::multiplexed_request_incoming;
- }
-
- //connection_->request_map_[id] =
- return ec;
- }
+ , boost::system::error_code& ec);
 
     boost::system::error_code
       process_abort_request(implementation_type& impl, boost::uint16_t id
@@ -730,28 +697,54 @@
     }
 
 /*
- implementation_type&
- get_or_make_request(implementation_type& impl, boost::uint16_t id)
- {
- implementation_type::client_type::connection_type::request_vector_type&
- requests = impl.client_.connection_->requests;
- implementation_type* ret;
+ implementation_type::request_type&
+ get_or_make_request(implementation_type& impl, boost::uint16_t id);
+
+ request_type::pointer ret
       
       try {
         ret = &requests.at(id - 1);
         BOOST_ASSERT(req != 0); // should throw
         return *ret;
       }catch(...){
- req = new request_type(impl.service_);
+ req = request_type::create(impl.service_);
         if (requests.size() < (id - 1))
           requests.resize(id);
         requests.at(id-1) = *req;
- return *req; // same as *ret
+ return req->impl(); // same as *ret
       }
     }
 */
+ boost::system::error_code
+ begin_request_helper(implementation_type& impl
+ , implementation_type::header_buffer_type& header
+ , boost::system::error_code& ec)
+ {
+ impl.client_.request_id_ = fcgi::spec::get_request_id(header);
+
+ BOOST_STATIC_ASSERT((
+ fcgi::spec::begin_request::body::size::value
+ == fcgi::spec::header_length::value));
+
+ // A begin request body is as long as a header, so we can optimise:
+ if (read_header(impl, ec))
+ return ec;
+
+ impl.request_role_
+ = fcgi::spec::begin_request::get_role(impl.header_buf_);
+ // **FIXME** (rm impl.request_role_)
+ impl.client_.role_ = impl.request_role_;
+ std::cerr<< "[hw] New request role: " << impl.request_role_
+ << " (" << fcgi::spec::role_type::to_string(impl.header_buf_) << ")"
+ << std::endl;
+ impl.client_.keep_connection_
+ = fcgi::spec::begin_request::get_flags(impl.header_buf_)
+ & fcgi::spec::keep_connection;
 
- };
+ impl.client_.status_ = constructed;
+ return ec;
+ }
+ };
 
   //template<>
   const fcgi_request_service::proc_func_t fcgi_request_service::proc_funcs[] =
@@ -768,4 +761,74 @@
  } // namespace fcgi
 } // namespace cgi
 
+#include "boost/cgi/fcgi/request.hpp"
+#include "boost/cgi/basic_request.hpp"
+
+namespace cgi {
+ namespace fcgi {
+
+ namespace fdetail {
+ typedef fcgi_request_service service_type;
+ typedef service_type::implementation_type impl_type;
+ typedef impl_type::request_type request_type;
+ } // namespace detail
+
+/*
+ fdetail::request_type&
+ get_or_make_request(fdetail::impl_type& impl, boost::uint16_t id)
+ {
+ fdetail::impl_type::client_type::connection_type::request_vector_type&
+ requests = impl.client_.connection_->requests_;
+
+ if (!requests.at(id-1))
+ {
+ if (requests.size() < (id-1))
+ requests.resize(id);
+ requests.at(id-1) = fdetail::request_type::create(*impl.service_);
+ }
+
+ return *requests.at(id-1);
+ }
+*/
+
+ boost::system::error_code
+ fdetail::service_type::process_begin_request
+ (
+ fdetail::impl_type& impl, boost::uint16_t id, const unsigned char* buf
+ , boost::uint16_t, boost::system::error_code& ec
+ )
+ {
+ if (impl.client_.request_id_ == 0) // ie. hasn't been set yet.
+ {
+ begin_request_helper(impl, impl.header_buf_, ec);
+ }
+ else
+ {
+ std::cerr<< "**FIXME** Role: "
+ << fcgi::spec::begin_request::get_role(impl.header_buf_) << std::endl;
+
+ fdetail::impl_type::client_type::connection_type&
+ conn = *impl.client_.connection_;
+
+ if (conn.get_slot(id, ec))
+ { // error
+ return ec;
+ }
+
+ // **FIXME** THIS LEAKS MEMORY!!!!!!!
+ //requests.at(id-1)
+ request_type* new_request = new request_type(impl, ec);
+
+ conn.add_request(id, new_request, true, ec);
+
+ return ec;//error::multiplexed_request_incoming;
+ }
+
+ return ec;
+ }
+
+
+ } // namespace fcgi
+} // namespace cgi
+
 #endif // CGI_FCGI_REQUEST_SERVICE_HPP_INCLUDED__

Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/header.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/header.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/header.hpp 2008-03-12 20:59:35 EDT (Wed, 12 Mar 2008)
@@ -87,6 +87,20 @@
   {
     return header("Content-encoding", str);
   }
+
+ template<typename T>
+ header
+ content_length(const T& t)
+ {
+ return header("Content-length", boost::lexical_cast<std::string>(t));
+ }
+
+ template<typename T, typename Traits, typename Alloc>
+ header
+ content_length(const std::basic_string<T, Traits, Alloc>& str)
+ {
+ return header("Content-length", str);
+ }
 /*
   template<typename StringT>
   header<StringT>

Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/response.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/response.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/response.hpp 2008-03-12 20:59:35 EDT (Wed, 12 Mar 2008)
@@ -25,7 +25,7 @@
 #include <boost/foreach.hpp>
 
 /// This mess outputs a default Content-type header if the user hasn't set any.
-/**
+/** **FIXME** Not implemented; not sure if it should be...
  * BOOST_CGI_ADD_DEFAULT_HEADER should not persiste beyond this file.
  *
  * It basically works like (default first):
@@ -410,6 +410,13 @@
     return resp;
   }
 
+ template<typename T>
+ response& operator<<(response& resp, http::status_code status)
+ {
+ BOOST_ASSERT(!resp.headers_terminated());
+ return resp.set_status(status);
+ }
+
 } // namespace cgi
 
 #undef BOOST_CGI_ADD_DEFAULT_HEADER


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