$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r62412 - in sandbox/SOC/2007/cgi/trunk/boost: . cgi cgi/cgi cgi/common cgi/connections cgi/detail cgi/fcgi cgi/impl cgi/scgi
From: lists.drrngrvy_at_[hidden]
Date: 2010-06-03 13:26:13
Author: drrngrvy
Date: 2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
New Revision: 62412
URL: http://svn.boost.org/trac/boost/changeset/62412
Log:
* Refactoring traits classes to remove some cruft. Further work required here to make customising existing protocols easier.
* Added preliminary support for SCGI.
* Various code comments added.
Added:
   sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/traits.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/coroutine.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/unyield.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/yield.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/traits.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/
   sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/acceptor.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/client.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/error.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_acceptor_service.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_impl.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_parser.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_parser.ipp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_service.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_service.ipp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/service.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/traits.hpp   (contents, props changed)
Text files modified: 
   sandbox/SOC/2007/cgi/trunk/boost/cgi.hpp                                  |     6                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_client.hpp                     |     3                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request.hpp                    |     3                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request_acceptor.hpp           |     3                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi.hpp                              |     1                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/client.hpp                       |     2                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request.hpp                      |     2                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request_service.hpp              |     2                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/service.hpp                      |     2                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/basic_protocol_service.hpp    |     2                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/commit.hpp                    |     1                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/error.hpp                     |     2                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/protocol_traits.hpp           |   137 ----------------------------------------
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/request_base.hpp              |    13 ++-                                     
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/response.hpp                  |    49 +++++++++++--                           
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/tags.hpp                      |     1                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/connections/shareable_tcp_socket.hpp |     2                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/save_environment.hpp          |     2                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi.hpp                             |    11 ++-                                     
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/acceptor.hpp                    |     1                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/acceptor_service_impl.hpp       |     6 -                                       
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/client.hpp                      |     6 +                                       
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request.hpp                     |     2                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/service.hpp                     |     2                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/win32_acceptor_service_impl.hpp |    12 +--                                     
   sandbox/SOC/2007/cgi/trunk/boost/cgi/impl/fcgi_request_service.ipp        |     8 +-                                      
   26 files changed, 91 insertions(+), 190 deletions(-)
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -1,6 +1,6 @@
-//                      -- cgi.hpp --
+//                     -- cgi.hpp --
 //
-//            Copyright (c) Darren Garvey 2007.
+//          Copyright (c) Darren Garvey 2007-2010.
 // Distributed under the Boost Software License, Version 1.0.
 //    (See accompanying file LICENSE_1_0.txt or copy at
 //          http://www.boost.org/LICENSE_1_0.txt)
@@ -13,6 +13,6 @@
 
 #include "boost/cgi/cgi.hpp"
 #include "boost/cgi/fcgi.hpp"
-//#include "boost/cgi/scgi.hpp"
+#include "boost/cgi/scgi.hpp"
 
 #endif // BOOST_CGI_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_client.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_client.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_client.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -68,7 +68,6 @@
     typedef typename traits::mutable_buffers_type mutable_buffers_type;
     typedef typename traits::header_buffer_type   header_buffer_type;
     typedef typename connection_type::pointer     connection_ptr;
-    typedef typename traits::role_type            role_type;
 
     basic_client()
     {
@@ -245,7 +244,7 @@
     std::vector<boost::asio::const_buffer> outbuf_;
 
     bool keep_connection_;
-    role_type role_;
+    common::role_type role_;
   };
 
  } // namespace common
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -69,10 +69,10 @@
     typedef protocol_traits<protocol_type>             traits;
     typedef typename traits::protocol_service_type     protocol_service_type;
     typedef typename traits::service_type              service_type;
-    typedef typename traits::pointer                   pointer;
     typedef typename service_type::implementation_type implementation_type;
     typedef typename traits::char_type                 char_type;
     typedef typename traits::string_type               string_type;
+    typedef typename traits::request_type              request_type;
     typedef typename traits::client_type               client_type;
     typedef typename traits::buffer_type               buffer_type;
 #ifdef BOOST_CGI_ENABLE_SESSIONS
@@ -80,6 +80,7 @@
 
     session_type session;
 #endif // BOOST_CGI_ENABLE_SESSIONS
+    typedef boost::shared_ptr<request_type>            pointer;
     
     /// The environment data, exposed as a `request_data<env_map>`.
     env_data    env;
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request_acceptor.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request_acceptor.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request_acceptor.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -36,7 +36,6 @@
     typedef Protocol                               protocol_type;
     typedef protocol_traits<protocol_type>         traits;
     typedef typename traits::acceptor_service      service_type;
-    typedef typename traits::port_number_type      port_number_type;
     typedef typename traits::endpoint_type         endpoint_type;
     typedef typename traits::native_type           native_type;
     typedef typename traits::protocol_service_type protocol_service_type;
@@ -47,7 +46,7 @@
     template<typename IoServiceProvider>
     explicit basic_request_acceptor(
           common::basic_protocol_service<protocol_type, IoServiceProvider>& ps,
-          port_number_type port_num = 0)
+          unsigned short port_num = 0)
       : boost::asio::basic_io_object<service_type>(ps.get_io_service())
     {
       this->service.set_protocol_service(this->implementation, ps);
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -12,6 +12,7 @@
 #include "boost/cgi/config.hpp"
 
 // Include all cgi-related headers only.
+#include "boost/cgi/cgi/traits.hpp"
 #include "boost/cgi/cgi/request.hpp"
 #include "boost/cgi/cgi/client.hpp"
 #include "boost/cgi/cgi/service.hpp"
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/client.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/client.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/client.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -9,7 +9,7 @@
 #ifndef CGI_CLIENT_HPP_INCLUDED__
 #define CGI_CLIENT_HPP_INCLUDED__
 
-#include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/cgi/traits.hpp"
 #include "boost/cgi/fwd/basic_client_fwd.hpp"
 
 BOOST_CGI_NAMESPACE_BEGIN
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -11,7 +11,7 @@
 
 #include "boost/cgi/detail/push_options.hpp"
 
-#include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/cgi/traits.hpp"
 #include "boost/cgi/cgi/service.hpp"
 #include "boost/cgi/cgi/request_service.hpp"
 #include "boost/cgi/fwd/basic_request_fwd.hpp"
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request_service.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request_service.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -169,7 +169,7 @@
 
       if (parse_opts & common::parse_cookie_only)
       {
-        if (parse_cookie_vars(impl, ec)) // returns an error_code
+        if (parse_cookie_vars(impl, "HTTP_COOKIE", ec)) // returns an error_code
           return ec;
       }
 
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/service.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/service.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -9,7 +9,7 @@
 #ifndef CGI_CGI_SERVICE_HPP_INCLUDED__
 #define CGI_CGI_SERVICE_HPP_INCLUDED__
 
-#include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/cgi/traits.hpp"
 #include "boost/cgi/fwd/basic_protocol_service_fwd.hpp"
 
 BOOST_CGI_NAMESPACE_BEGIN
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/traits.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/traits.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,88 @@
+//                 -- cgi/traits.hpp --
+//
+//          Copyright (c) Darren Garvey 2007-2010.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef BOOST_CGI_CGI_TRAITS_HPP_INCLUDED_
+#define BOOST_CGI_CGI_TRAITS_HPP_INCLUDED_
+
+#include <boost/asio/ip/tcp.hpp>
+#include <boost/none.hpp>
+#include <boost/config.hpp>
+///////////////////////////////////////////////////////////
+#include "boost/cgi/common/parse_options.hpp"
+#include "boost/cgi/common/protocol_traits.hpp"
+#include "boost/cgi/common/role_type.hpp"
+#include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/fwd/basic_client_fwd.hpp"
+#include "boost/cgi/fwd/basic_connection_fwd.hpp"
+#include "boost/cgi/fwd/basic_protocol_service_fwd.hpp"
+#include "boost/cgi/fwd/basic_request_fwd.hpp"
+#include "boost/cgi/fwd/form_parser_fwd.hpp"
+#ifdef BOOST_CGI_ENABLE_SESSIONS
+#  include "boost/cgi/fwd/sessions_fwd.hpp"
+#endif // BOOST_CGI_ENABLE_SESSIONS
+
+BOOST_CGI_NAMESPACE_BEGIN
+
+    namespace cgi  {}
+
+  // Forward declarations
+
+  class cgi_service_impl;
+
+  class cgi_request_service;
+
+ namespace common {
+ 
+    /// Common Traits for CGI.
+    template<>
+    struct protocol_traits<tags::cgi>
+    {
+      typedef protocol_traits<tags::cgi>             type;
+      typedef tags::cgi                              protocol_type;
+      typedef cgi_request_service                    request_service_impl;
+      typedef cgi_request_service                    service_type;
+      typedef common::basic_protocol_service<
+                  protocol_type
+              >                                      protocol_service_type;
+      typedef basic_request<
+                  protocol_type
+              >                                      request_type; 
+      typedef cgi_service_impl                       service_impl_type;
+      typedef basic_connection<
+                  tags::async_stdio
+              >                                      connection_type;
+      typedef basic_client<
+                  protocol_type
+              >                                      client_type;
+      typedef form_parser                            form_parser_type;
+      typedef boost::none_t                          header_type;
+      typedef char                                   char_type;
+      typedef std::basic_string<char_type>           string_type;
+      typedef string_type                            buffer_type;
+      typedef boost::array<unsigned char, 8>         header_buffer_type;
+      typedef boost::asio::const_buffers_1           const_buffers_type;
+      typedef boost::asio::mutable_buffers_1         mutable_buffers_type;
+#ifdef BOOST_CGI_ENABLE_SESSIONS
+      typedef basic_session<
+                std::map<string_type, string_type>
+              >                                      session_type;
+      typedef boost::uuids::random_generator         uuid_generator_type;
+      typedef basic_session_manager<
+                protocol_type
+              >                                      session_manager_type;
+      static const bool auto_start_session = true;
+      static const int session_options = path_session;
+
+#endif // BOOST_CGI_ENABLE_SESSIONS
+      static const common::parse_options parse_opts = common::parse_all;
+    };
+
+ } // namespace common
+BOOST_CGI_NAMESPACE_END
+
+#endif // BOOST_CGI_CGI_TRAITS_HPP_INCLUDED_
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/basic_protocol_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/basic_protocol_service.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/basic_protocol_service.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -40,7 +40,7 @@
     typedef typename protocol_traits<Protocol>::type traits;
     typedef typename traits::string_type             string_type;
     typedef typename traits::request_type            request_type;
-    typedef typename request_type::pointer           request_ptr;
+    typedef boost::shared_ptr<request_type>          request_ptr;
     typedef std::set<request_ptr>                    set_type;
     typedef std::queue<request_ptr>                  queue_type;
 
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/commit.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/commit.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/commit.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -56,6 +56,7 @@
 
   namespace cgi { using ::BOOST_CGI_NAMESPACE::common::commit; }
   namespace fcgi { using ::BOOST_CGI_NAMESPACE::common::commit; }
+  namespace scgi { using ::BOOST_CGI_NAMESPACE::common::commit; }
 
 } // namespace boost
 
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/error.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/error.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/error.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -105,6 +105,8 @@
     case max_post_exceeded:
       return "The content length of the file upload is larger than maximum"
              " allowed by the BOOST_CGI_POST_MAX macro.";
+    case already_closed:
+      return "Trying to close a request that has already been closed.";
     default:
       return "(CGI) BOOM!!!";
     }
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/protocol_traits.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/protocol_traits.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/protocol_traits.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -29,35 +29,6 @@
 
 BOOST_CGI_NAMESPACE_BEGIN
 
-  struct empty;
-
-  namespace cgi  {}
-  namespace fcgi
-  {
-  class fcgi_service_impl;
-  template<typename Protocol>
-  class fcgi_request_service;
-  class fcgi_acceptor_service;
-  }
-  namespace scgi
-  {
-  class scgi_service_impl;
-  class scgi_request_service;
-  class scgi_acceptor_service;
-  }
-
-  // Forward declarations
-
-  class cgi_service_impl;
-  class fcgi_service_impl;
-
-  class fcgi_acceptor_service;
-  template<typename Protocol>
-  class fcgi_request_acceptor_service;
-
-  class cgi_request_service;
-  class fcgi_request_service;
-
  namespace common {
  
     enum session_opts
@@ -71,114 +42,6 @@
     {
     };
 
-    /// Common Traits for CGI.
-    template<>
-    struct protocol_traits<tags::cgi>
-    {
-      typedef protocol_traits<tags::cgi>             type;
-      typedef tags::cgi                              protocol_type;
-      typedef cgi_request_service                    request_service_impl;
-      typedef cgi_request_service                    service_type;
-      typedef common::basic_protocol_service<
-                  protocol_type
-              >                                      protocol_service_type;
-      typedef basic_request<
-                  protocol_type
-              >                                      request_type; 
-      typedef cgi_service_impl                       service_impl_type;
-      typedef basic_connection<
-                  tags::async_stdio
-              >                                      connection_type;
-      typedef basic_client<
-                  protocol_type
-              >                                      client_type;
-      typedef form_parser                            form_parser_type;
-      typedef boost::none_t                          header_type;
-      typedef char                                   char_type;
-      typedef std::basic_string<char_type>           string_type;
-      typedef string_type                            buffer_type;
-      typedef boost::array<unsigned char, 8>         header_buffer_type;
-      typedef boost::asio::const_buffers_1           const_buffers_type;
-      typedef boost::asio::mutable_buffers_1         mutable_buffers_type;
-      typedef common::role_type                      role_type;
-      typedef boost::shared_ptr<request_type>        pointer;
-#ifdef BOOST_CGI_ENABLE_SESSIONS
-      typedef basic_session<
-                std::map<string_type, string_type>
-              >                                      session_type;
-      typedef boost::uuids::random_generator         uuid_generator_type;
-      typedef basic_session_manager<
-                protocol_type
-              >                                      session_manager_type;
-      static const bool auto_start_session = true;
-      static const int session_options = path_session;
-
-#endif // BOOST_CGI_ENABLE_SESSIONS
-      static const common::parse_options parse_opts = common::parse_all;
-    };
-
-    /// Common Traits for FastCGI.
-    template<>
-    struct protocol_traits<tags::fcgi>
-    {
-      typedef protocol_traits<tags::fcgi>            type;
-      typedef tags::fcgi                             protocol_type;
-      typedef fcgi::fcgi_request_service<protocol_type>             request_service_impl;
-      typedef fcgi::fcgi_request_service<protocol_type>             service_type;
-      typedef basic_protocol_service<
-                  protocol_type
-              >                                      protocol_service_type;
-      typedef basic_request<protocol_type>           request_type; 
-      typedef boost::shared_ptr<request_type>        request_ptr;
-      typedef fcgi::fcgi_service_impl                service_impl_type;
-      typedef fcgi_request_acceptor_service<protocol_type>  acceptor_service;
-      typedef fcgi::fcgi_acceptor_service            acceptor_service_impl;
-#if defined(BOOST_WINDOWS)
-      typedef basic_connection<
-                  tags::anonymous_pipe
-              >                                      connection_type;
-      //typedef anonymous_pipe                         connection_type;
-#else
-      typedef basic_connection<
-                  tags::shareable_tcp_socket
-              >                                      connection_type;
-#endif // defined(BOOST_WINDOWS)
-      typedef boost::asio::ip::tcp                   native_protocol_type;
-      typedef boost::asio::socket_acceptor_service<
-                  native_protocol_type
-              >                                      acceptor_service_type;
-      typedef 
-          acceptor_service_type::implementation_type acceptor_impl_type;
-      typedef acceptor_service_type::native_type     native_type;
-      typedef unsigned short                         port_number_type;
-      typedef boost::asio::ip::tcp::endpoint         endpoint_type;
-      typedef basic_client<protocol_type>            client_type;
-      typedef form_parser                            form_parser_type;
-      typedef fcgi::spec::header                     header_type;
-      typedef fcgi::spec_detail::role_types          role_type;
-
-      typedef char                                   char_type;
-      typedef std::basic_string<char_type>           string_type;
-      typedef string_type                            buffer_type;
-      typedef boost::array<unsigned char, 8>         header_buffer_type;
-      typedef boost::asio::const_buffers_1           const_buffers_type;
-      typedef boost::asio::mutable_buffers_1         mutable_buffers_type;
-      typedef boost::shared_ptr<request_type>        pointer;
-#ifdef BOOST_CGI_ENABLE_SESSIONS
-      typedef basic_session<
-                std::map<string_type, string_type>
-              >                                      session_type;
-      typedef boost::uuids::random_generator         uuid_generator_type;
-      typedef basic_session_manager<
-                protocol_type
-              >                                      session_manager_type;
-      static const bool auto_start_session = true;
-      static const int session_options = path_session;
-#endif // BOOST_CGI_ENABLE_SESSIONS
-
-      static const parse_options parse_opts = common::parse_none;
-    };
-
  } // namespace common
 BOOST_CGI_NAMESPACE_END
 
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/request_base.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/request_base.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/request_base.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -27,6 +27,7 @@
 #include "boost/cgi/common/request_status.hpp"
 #include "boost/cgi/detail/extract_params.hpp"
 #include "boost/cgi/detail/save_environment.hpp"
+#include "boost/cgi/http/status_code.hpp"
 #include "boost/cgi/config.hpp"
 #ifdef BOOST_CGI_ENABLE_SESSIONS
 #  include "boost/cgi/utility/sessions.hpp"
@@ -328,8 +329,6 @@
     boost::system::error_code
     parse_get_vars(ImplType& impl, boost::system::error_code& ec)
     {
-      // Make sure the request is in a pre-loaded state
-      //BOOST_ASSERT (impl.status() <= unloaded);
       if (!(status(impl) & common::get_read))
       {
         std::string const& vars (env_vars(impl.vars_)["QUERY_STRING"]);
@@ -346,16 +345,18 @@
     /// Read and parse the HTTP_COOKIE meta variable.
     /**
      * Note: Do not URL decode the cookie values.
+     *
+     * @param cookie_key The name of the header that the cookie should appear
+     *        as. eg. this is HTTP_COOKIE for CGI-like protocols and Cookie
+     *        for HTTP.
      */
     template<typename ImplType>
     boost::system::error_code
-    parse_cookie_vars(ImplType& impl, boost::system::error_code& ec)
+    parse_cookie_vars(ImplType& impl, const char* cookie_key, boost::system::error_code& ec)
     {
-      // Make sure the request is in a pre-loaded state
-      //BOOST_ASSERT (impl.status() <= unloaded);
       if (!(status(impl) & common::cookies_read))
       {
-        std::string const& vars (env_vars(impl.vars_)["HTTP_COOKIE"]);
+        std::string const& vars (env_vars(impl.vars_)[cookie_key]);
         if (!vars.empty())
           detail::extract_params(vars, cookie_vars(impl.vars_)
                                 , boost::char_separator<char>
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/response.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/response.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/response.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -29,6 +29,21 @@
  namespace common {
 
   /// The response class: a helper for responding to requests.
+  /**
+   * This class has no knowledge of requests or protocols. It is a lightweight
+   * wrapper over a std::ostream that separates response headers from the
+   * response body.
+   *
+   * One response can be reused for several requests (though not
+   * simultaneously) and multiple responses can be combined.
+   *
+   * Note that std::endl is not supported for this class. std::endl usually
+   * flushes an std::ostream, which is not possible with this class as it
+   * is request-agnostic.
+   *
+   * When a response has been constructed, you can send it to any
+   * SyncWriteStream by calling send() or flush().
+   */
   template<typename CharT>
   class basic_response
   {
@@ -56,15 +71,16 @@
     /// Return the response to the 'just constructed' state.
     void reset();
 
-    // provide this too?
+    /// Write characters to the response body.
     std::size_t write(const char_type* str, std::size_t len);
 
+    /// Write a string to the response body.
     std::size_t write(string_type const& str);
 
     template<typename ConstBufferSequence>
     std::size_t write(const ConstBufferSequence& buf);
 
-    /// Synchronously flush the data to the supplied SyncWriteStream
+    /// Synchronously flush the data to the supplied SyncWriteStream.
     /**
      * This call uses throwing semantics. ie. an exception will be thrown on
      * any failure.
@@ -76,7 +92,7 @@
     /// Put a character into the stream.
     self_type& put (char_type c);
 
-    /// Synchronously flush the data via the supplied request
+    /// Synchronously flush the data via the supplied SyncWriteStream.
     /**
      * This call uses error_code semantics. ie. ec is set if an error occurs.
      * If there is no error, the buffer is cleared.
@@ -108,7 +124,7 @@
     template<typename SyncWriteStream>
     void resend(SyncWriteStream& sws);
 
-    /// Asynchronously send the data through the supplied request
+    /// Asynchronously send the data through the supplied AsyncWriteStream.
     /**
      * Note: This is quite crude at the moment and not as asynchronous as
      *       it could/should be. The data in the stream isn't cleared after
@@ -148,6 +164,7 @@
       return *this;
     }
 
+    /// Add a cookie to the response.
     basic_response<char_type>&
       set(const basic_cookie<char_type>& ck)
     {
@@ -155,6 +172,7 @@
       return *this;
     }
 
+    /// Set a header give a string of the form "name=value".
     basic_response<char_type>&
       set_header(const string_type& value);
 
@@ -165,21 +183,25 @@
     /// Get the contents of the response as a string.
     /**
      * This copies the contents of the response into a string.
-     * Headers aren't included in the dump unless `include_header` is true.
+     * Headers aren't included unless `include_header` is true.
      */
     string_type str(bool include_header = false) const;
 
+    /// Get the value of a header in this response with the name `name`.
     string_type header_value(string_type const& name);
 
+    /// Clear all of the response headers.
     void clear_headers();
 
     void reset_headers();
     
     /// Get the charset.
     string_type& charset() const { return charset_; }
+
     /// Set the charset.
     void charset(string_type const& cs) { charset_ = cs; }
 
+    /// Check if more response headers may be added.
     bool headers_terminated() const;
 
     // Is this really necessary?
@@ -188,9 +210,10 @@
     /// Get the ostream containing the response body.
     ostream_type& ostream();
 
-    /// Get the headers
+    /// Get the response headers.
     std::vector<string_type>& headers();
 
+    /// Stream any type to the response.
     template<typename T>
     self_type& operator<<(T t)
     {
@@ -198,28 +221,39 @@
       return *this;
     }
 
+    /// Change the charset of the response.
     self_type& operator<< (charset_header<char_type> const& hdr)
     {
       charset(hdr.content);
       return *this;
     }
  
-     self_type& operator<< (basic_header<char_type> const& hdr)
+    /// Add a header to the response.
+    self_type& operator<< (basic_header<char_type> const& hdr)
     {
       return set(hdr);
     }
  
+    /// Add a cookie to the response.
     self_type& operator<< (basic_cookie<char_type> const& ck)
     {
       return set(ck);
     }
  
+    /// Set the HTTP status of the response.
     self_type& operator<< (http::status_code stat)
     {
       status(stat);
       return *this;
     }
 
+    /// Copy another response into this response.
+    /**
+     * The body of the other response is appended to the body of this
+     * response. The headers of the other response are added to this
+     * response, except for the "Content-type" header. The content-type
+     * of this response is assumed to be authoritative.
+     */
     self_type& operator<< (self_type& other)
     {
       if (!headers_terminated())
@@ -262,7 +296,6 @@
 
    /// Typedefs for typical usage.
    typedef basic_response<char>    response;
-   typedef basic_response<wchar_t> wresponse; // **TODO** (untested)
 
  } // namespace common
 BOOST_CGI_NAMESPACE_END
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/tags.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/tags.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/tags.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -27,6 +27,7 @@
     struct cgi {};
     struct fcgi {};
     struct scgi {};
+    struct http {};
 
     // IoServiceProvider PoolingPolicy types
     struct single_service {};
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/connections/shareable_tcp_socket.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/connections/shareable_tcp_socket.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/connections/shareable_tcp_socket.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -56,7 +56,7 @@
     typedef common::protocol_traits<tags::fcgi>       traits;
     /** FastCGI specific stuff **/
     typedef traits::request_type                      request_type;
-    typedef traits::request_ptr                       request_ptr;
+    typedef boost::shared_ptr<request_type>           request_ptr;
     typedef std::map<boost::uint16_t, request_type*>  request_map_type;
     typedef std::vector<request_type*>                request_vector_type;
     /** End FastCGI stuff      **/
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/coroutine.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/coroutine.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,79 @@
+//
+// coroutine.hpp
+// ~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef BOOST_CGI_DETAIL_COROUTINE_HPP
+#define BOOST_CGI_DETAIL_COROUTINE_HPP
+
+class coroutine
+{
+public:
+  coroutine() : value_(0) {}
+  bool is_child() const { return value_ < 0; }
+  bool is_parent() const { return !is_child(); }
+  bool is_complete() const { return value_ == -1; }
+private:
+  friend class coroutine_ref;
+  int value_;
+};
+
+class coroutine_ref
+{
+public:
+  coroutine_ref(coroutine& c) : value_(c.value_), modified_(false) {}
+  coroutine_ref(coroutine* c) : value_(c->value_), modified_(false) {}
+  ~coroutine_ref() { if (!modified_) value_ = -1; }
+  operator int() const { return value_; }
+  int& operator=(int v) { modified_ = true; return value_ = v; }
+private:
+  void operator=(const coroutine_ref&);
+  int& value_;
+  bool modified_;
+};
+
+#define CORO_REENTER(c) \
+  switch (coroutine_ref _coro_value = c) \
+    case -1: if (_coro_value) \
+    { \
+      goto terminate_coroutine; \
+      terminate_coroutine: \
+      _coro_value = -1; \
+      goto bail_out_of_coroutine; \
+      bail_out_of_coroutine: \
+      break; \
+    } \
+    else case 0:
+
+#define CORO_YIELD \
+  for (_coro_value = __LINE__;;) \
+    if (_coro_value == 0) \
+    { \
+      case __LINE__: ; \
+      break; \
+    } \
+    else \
+      switch (_coro_value ? 0 : 1) \
+        for (;;) \
+          case -1: if (_coro_value) \
+            goto terminate_coroutine; \
+          else for (;;) \
+            case 1: if (_coro_value) \
+              goto bail_out_of_coroutine; \
+            else case 0:
+
+#define CORO_FORK \
+  for (_coro_value = -__LINE__;; _coro_value = __LINE__) \
+    if (_coro_value == __LINE__) \
+    { \
+      case -__LINE__: ; \
+      break; \
+    } \
+    else
+
+#endif // BOOST_CGI_DETAIL_COROUTINE_HPP
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/save_environment.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/save_environment.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/save_environment.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -37,7 +37,7 @@
     */
    template<typename MapT>
    void save_environment(MapT& env_map, char** env =
-       // Windows calls the environment environ_
+       // Windows calls the environment _environ
 #      if BOOST_WINDOWS
          _environ
 #      else
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/unyield.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/unyield.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,21 @@
+//
+// unyield.hpp
+// ~~~~~~~~~~~
+//
+// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifdef reenter
+# undef reenter
+#endif
+
+#ifdef yield
+# undef yield
+#endif
+
+#ifdef fork
+# undef fork
+#endif
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/yield.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/yield.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,23 @@
+//
+// yield.hpp
+// ~~~~~~~~~
+//
+// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include "boost/cgi/detail/coroutine.hpp"
+
+#ifndef reenter
+# define reenter(c) CORO_REENTER(c)
+#endif
+
+#ifndef yield
+# define yield CORO_YIELD
+#endif
+
+#ifndef fork
+# define fork CORO_FORK
+#endif
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -1,6 +1,6 @@
-//                   -- fcgi.hpp --
+//                    -- fcgi.hpp --
 //
-//           Copyright (c) Darren Garvey 2007.
+//         Copyright (c) Darren Garvey 2007-2010.
 // Distributed under the Boost Software License, Version 1.0.
 //    (See accompanying file LICENSE_1_0.txt or copy at
 //          http://www.boost.org/LICENSE_1_0.txt)
@@ -9,14 +9,17 @@
 #ifndef CGI_FCGI_HPP_INCLUDED__
 #define CGI_FCGI_HPP_INCLUDED__
 
-// #include all fcgi-related files only
+// Include all FastCGI-related headers
 #include "boost/cgi/config.hpp"
-#include "boost/cgi/detail/common_headers.hpp"
+#include "boost/cgi/fcgi/traits.hpp"
 #include "boost/cgi/fcgi/acceptor.hpp"
 #include "boost/cgi/fcgi/client.hpp"
 #include "boost/cgi/fcgi/request.hpp"
 #include "boost/cgi/fcgi/service.hpp"
 
+// Include common headers.
+#include "boost/cgi/detail/common_headers.hpp"
+
 BOOST_CGI_NAMESPACE_BEGIN
  namespace fcgi {
    using namespace ::BOOST_CGI_NAMESPACE::common; // import common elements.
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/acceptor.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/acceptor.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/acceptor.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -9,6 +9,7 @@
 #ifndef CGI_FCGI_ACCEPTOR_HPP_INCLUDED__
 #define CGI_FCGI_ACCEPTOR_HPP_INCLUDED__
 
+#include "boost/cgi/fcgi/traits.hpp"
 #include "boost/cgi/basic_request_acceptor.hpp"
 #include "boost/cgi/fcgi/request_acceptor_service.hpp"
 
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/acceptor_service_impl.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/acceptor_service_impl.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/acceptor_service_impl.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -77,11 +77,10 @@
      typedef typename traits::native_protocol_type  native_protocol_type;
      typedef typename traits::native_type           native_type;
      typedef typename traits::request_type          request_type;
-     typedef typename traits::pointer               request_ptr;
      typedef typename traits::acceptor_service_type acceptor_service_type;
      typedef typename traits::acceptor_impl_type    acceptor_impl_type;
-     typedef typename traits::port_number_type      port_number_type;
      typedef typename traits::endpoint_type         endpoint_type;
+     typedef boost::shared_ptr<request_type>        request_ptr;
      typedef std::pair<
        typename std::set<request_ptr>::iterator, bool> request_iter;
      typedef boost::function<int (request_type&)>   accept_handler_type;
@@ -94,7 +93,6 @@
        typedef typename traits::native_protocol_type  native_protocol_type;
        typedef typename traits::request_type          request_type;
        typedef typename traits::acceptor_service_type acceptor_service_type;
-       typedef typename traits::port_number_type      port_number_type;
        typedef typename traits::endpoint_type         endpoint_type;
 
        acceptor_impl_type                            acceptor_;
@@ -102,7 +100,7 @@
        std::queue<boost::shared_ptr<request_type> >  waiting_requests_;
        std::set<request_ptr>                         running_requests_;
        protocol_service_type*                        service_;
-       port_number_type                              port_num_;
+       unsigned short                                port_num_;
        endpoint_type                                 endpoint_;
        
      };
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/client.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/client.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/client.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -17,7 +17,7 @@
 ///////////////////////////////////////////////////////////
 #include "boost/cgi/basic_client.hpp"
 #include "boost/cgi/common/map.hpp"
-#include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/fcgi/traits.hpp"
 #include "boost/cgi/connections/shareable_tcp_socket.hpp"
 #include "boost/cgi/detail/throw_error.hpp"
 #include "boost/cgi/fcgi/specification.hpp"
@@ -171,10 +171,12 @@
     std::size_t total_buffer_size = static_cast<std::size_t>(header_.content_length());
     
 #if !defined(BOOST_CGI_NO_LOGGING) && !defined(NDEBUG)
+    std::ofstream log("../logs/fcgi_client.log", std::ios::out | std::ios::app);
     if (ec)
       std::cerr<< "Error " << ec << ": " << ec.message() << '\n';
     else    
-      std::cerr
+      //std::cerr
+      log
         << "Transferred " << total_buffer_size
         << " (+" << (bytes_transferred - total_buffer_size)
         << " protocol) bytes (running total: "
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -9,7 +9,7 @@
 #ifndef CGI_FCGI_REQUEST_HPP_INCLUDED__
 #define CGI_FCGI_REQUEST_HPP_INCLUDED__
 
-#include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/fcgi/traits.hpp"
 #include "boost/cgi/fcgi/service.hpp"
 #include "boost/cgi/fcgi/request_service.hpp"
 #include "boost/cgi/fwd/basic_request_fwd.hpp"
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/service.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/service.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -9,7 +9,7 @@
 #ifndef CGI_FCGI_SERVICE_HPP_INCLUDED__
 #define CGI_FCGI_SERVICE_HPP_INCLUDED__
 
-#include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/fcgi/traits.hpp"
 #include "boost/cgi/common/basic_protocol_service.hpp"
 
 BOOST_CGI_NAMESPACE_BEGIN
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/traits.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/traits.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,128 @@
+//                 -- fcgi/traits.hpp --
+//
+//          Copyright (c) Darren Garvey 2007-2010.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef BOOST_CGI_FCGI_TRAITS_HPP_INCLUDED_
+#define BOOST_CGI_FCGI_TRAITS_HPP_INCLUDED_
+
+#include <boost/asio/ip/tcp.hpp>
+#include <boost/none.hpp>
+#include <boost/config.hpp>
+///////////////////////////////////////////////////////////
+#include "boost/cgi/common/parse_options.hpp"
+#include "boost/cgi/common/protocol_traits.hpp"
+#include "boost/cgi/common/role_type.hpp"
+#include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/fwd/basic_client_fwd.hpp"
+#include "boost/cgi/fwd/basic_connection_fwd.hpp"
+#include "boost/cgi/fwd/basic_protocol_service_fwd.hpp"
+#include "boost/cgi/fwd/basic_request_fwd.hpp"
+#include "boost/cgi/fwd/form_parser_fwd.hpp"
+#ifdef BOOST_CGI_ENABLE_SESSIONS
+#  include "boost/cgi/fwd/sessions_fwd.hpp"
+#endif // BOOST_CGI_ENABLE_SESSIONS
+
+BOOST_CGI_NAMESPACE_BEGIN
+
+  namespace fcgi
+  {
+  class fcgi_service_impl;
+  template<typename Protocol>
+  class fcgi_request_service;
+  class fcgi_acceptor_service;
+  }
+
+  // Forward declarations
+
+  class fcgi_service_impl;
+
+  class fcgi_acceptor_service;
+  template<typename Protocol>
+  class fcgi_request_acceptor_service;
+
+  class fcgi_request_service;
+
+ namespace common {
+ 
+    /// Common Traits for FastCGI.
+    template<>
+    struct protocol_traits<tags::fcgi>
+    {
+      /// Identity types
+      typedef protocol_traits<tags::fcgi>            type;
+      typedef tags::fcgi                             protocol_type;
+
+      /// Char traits
+      typedef char                                   char_type;
+      typedef std::basic_string<char_type>           string_type;
+      typedef string_type                            buffer_type;
+
+      // Core types
+      typedef basic_protocol_service<
+                  protocol_type
+              >                                      protocol_service_type;
+      typedef basic_request<protocol_type>           request_type; 
+      typedef basic_client<protocol_type>            client_type;
+#if defined(BOOST_WINDOWS)
+      typedef basic_connection<
+                  tags::anonymous_pipe
+              >                                      connection_type;
+#else
+      typedef basic_connection<
+                  tags::shareable_tcp_socket
+              >                                      connection_type;
+#endif // defined(BOOST_WINDOWS)
+
+      // Runtime options
+      static const parse_options parse_opts = common::parse_none;
+
+      // Utility types
+#ifdef BOOST_CGI_ENABLE_SESSIONS
+      typedef basic_session<
+                std::map<string_type, string_type>
+              >                                      session_type;
+      typedef boost::uuids::random_generator         uuid_generator_type;
+      typedef basic_session_manager<
+                protocol_type
+              >                                      session_manager_type;
+      static const bool auto_start_session = true;
+      static const int session_options = path_session;
+#endif // BOOST_CGI_ENABLE_SESSIONS
+
+      // Internal types (advanced)
+
+      typedef boost::array<unsigned char, 8>         header_buffer_type;
+      typedef boost::asio::const_buffers_1           const_buffers_type;
+      typedef boost::asio::mutable_buffers_1         mutable_buffers_type;
+      typedef fcgi::fcgi_request_service<
+                  protocol_type
+              >                                      request_service_impl;
+      typedef fcgi::fcgi_request_service<
+                  protocol_type
+              >                                      service_type;
+      typedef fcgi::fcgi_service_impl                service_impl_type;
+      typedef fcgi_request_acceptor_service<
+                  protocol_type
+              >                                      acceptor_service;
+      typedef fcgi::fcgi_acceptor_service            acceptor_service_impl;
+
+      typedef boost::asio::ip::tcp                   native_protocol_type;
+      typedef boost::asio::socket_acceptor_service<
+                  native_protocol_type
+              >                                      acceptor_service_type;
+      typedef 
+          acceptor_service_type::implementation_type acceptor_impl_type;
+      typedef acceptor_service_type::native_type     native_type;
+      typedef native_protocol_type::endpoint         endpoint_type;
+      typedef form_parser                            form_parser_type;
+      typedef fcgi::spec::header                     header_type;
+    };
+
+ } // namespace common
+BOOST_CGI_NAMESPACE_END
+
+#endif // BOOST_CGI_FCGI_TRAITS_HPP_INCLUDED_
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/win32_acceptor_service_impl.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/win32_acceptor_service_impl.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/win32_acceptor_service_impl.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -130,11 +130,10 @@
      typedef typename traits::native_protocol_type  native_protocol_type;
      typedef typename traits::native_type           native_type;
      typedef typename traits::request_type          request_type;
-     typedef typename traits::pointer               request_ptr;
      typedef typename traits::acceptor_service_type acceptor_service_type;
      typedef typename traits::acceptor_impl_type    acceptor_impl_type;
-     typedef typename traits::port_number_type      port_number_type;
      typedef typename traits::endpoint_type         endpoint_type;
+     typedef boost::shared_ptr<request_type>        request_ptr;
      typedef std::pair<
        typename std::set<request_ptr>::iterator, bool> request_iter;
      typedef boost::function<int (request_type&)>   accept_handler_type;
@@ -147,7 +146,6 @@
        typedef typename traits::native_protocol_type  native_protocol_type;
        typedef typename traits::request_type          request_type;
        typedef typename traits::acceptor_service_type acceptor_service_type;
-       typedef typename traits::port_number_type      port_number_type;
        typedef typename traits::endpoint_type         endpoint_type;
 
        acceptor_impl_type                            acceptor_;
@@ -155,7 +153,7 @@
        std::queue<boost::shared_ptr<request_type> >  waiting_requests_;
        std::set<request_ptr>                         running_requests_;
        protocol_service_type*                        service_;
-       port_number_type                              port_num_;
+       unsigned short                                port_num_;
        endpoint_type                                 endpoint_;
        
      };
@@ -419,10 +417,8 @@
        }
 
        // If we can reuse this request's connection, return.
-       if (request.client().keep_connection())
-         return ec;
-
-       detail::accept_named_pipe(listen_handle, *request.client().connection(), ec);
+       if (!request.client().keep_connection())
+         detail::accept_named_pipe(listen_handle, *request.client().connection(), ec);
 
        if (!ec)
          request.status(common::accepted);
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/impl/fcgi_request_service.ipp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/impl/fcgi_request_service.ipp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/impl/fcgi_request_service.ipp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -102,8 +102,8 @@
     {
       /**
        * Apache on Windows with mod_fcgid requires that all of the
-       * pending data for the connection is read before the response
-       * is sent.
+       * pending data for the connection is read before the request
+       * is closed.
        */
       while(!ec 
         && impl.client_.status() < common::stdin_read
@@ -226,7 +226,7 @@
               return ec;
       }
       if (opts & common::parse_cookies_only)
-        parse_cookie_vars(impl, ec);
+        parse_cookie_vars(impl, "HTTP_COOKIE", ec);
         
       if (ec == error::eof) {
         ec = boost::system::error_code();
@@ -747,7 +747,7 @@
         
        spec::begin_request packet(impl.header_buf_);
        impl.request_role_ = packet.role();
-       impl.client_.role_ = packet.role();
+       impl.client_.role_ = static_cast<common::role_type>(packet.role());
        impl.client_.keep_connection_
          = packet.flags() & spec::keep_connection;
 
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,38 @@
+//                   -- cgi/scgi.hpp --
+//
+//           Copyright (c) Darren Garvey 2010.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_SCGI_HPP_INCLUDED__
+#define CGI_SCGI_HPP_INCLUDED__
+
+#include "boost/cgi/config.hpp"
+
+// Include all SCGI-related headers.
+#include "boost/cgi/scgi/traits.hpp"
+#include "boost/cgi/scgi/request.hpp"
+#include "boost/cgi/scgi/client.hpp"
+#include "boost/cgi/scgi/service.hpp"
+#include "boost/cgi/scgi/acceptor.hpp"
+
+// Include headers common to all protocols
+#include "boost/cgi/detail/common_headers.hpp"
+
+BOOST_CGI_NAMESPACE_BEGIN
+  namespace scgi {
+
+  using namespace common;
+  
+ } // namespace scgi
+BOOST_CGI_NAMESPACE_END
+
+namespace boost { namespace scgi {
+
+  using namespace BOOST_CGI_NAMESPACE::scgi;
+
+} } // namespace boost::scgi
+
+#endif // CGI_SCGI_HPP_INCLUDED__
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/acceptor.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/acceptor.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,33 @@
+//                -- scgi/acceptor.hpp --
+//
+//           Copyright (c) Darren Garvey 2010.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_SCGI_ACCEPTOR_HPP_INCLUDED__
+#define CGI_SCGI_ACCEPTOR_HPP_INCLUDED__
+
+#include "boost/cgi/scgi/traits.hpp"
+#include "boost/cgi/basic_request_acceptor.hpp"
+#include "boost/cgi/scgi/request_acceptor_service.hpp"
+
+BOOST_CGI_NAMESPACE_BEGIN
+ namespace scgi {
+
+   /// Typedef for common usage (SCGI)
+   typedef
+     ::BOOST_CGI_NAMESPACE::common::basic_request_acceptor<
+        ::BOOST_CGI_NAMESPACE::common::tags::scgi
+       >
+   acceptor;
+
+ } // namespace scgi
+BOOST_CGI_NAMESPACE_END
+
+namespace boost { namespace scgi {
+  using ::BOOST_CGI_NAMESPACE::scgi::acceptor;
+} }
+
+#endif // CGI_SCGI_ACCEPTOR_HPP_INCLUDED__
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/client.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/client.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,35 @@
+//                 -- scgi/client.hpp --
+//
+//            Copyright (c) Darren Garvey 2010.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_SCGI_CLIENT_HPP_INCLUDED__
+#define CGI_SCGI_CLIENT_HPP_INCLUDED__
+
+#include "boost/cgi/basic_client.hpp"
+#include "boost/cgi/common/map.hpp"
+#include "boost/cgi/scgi/traits.hpp"
+#include "boost/cgi/connections/tcp_socket.hpp"
+#include "boost/cgi/detail/throw_error.hpp"
+#include "boost/cgi/fwd/basic_request_fwd.hpp"
+#include "boost/cgi/error.hpp"
+#include "boost/cgi/import/read.hpp"
+#include "boost/cgi/import/buffer.hpp"
+#include "boost/cgi/import/io_service.hpp"
+
+BOOST_CGI_NAMESPACE_BEGIN
+
+namespace scgi {
+    typedef
+      common::basic_client<
+        ::BOOST_CGI_NAMESPACE::common::tags::scgi
+      >
+    client;
+} // namespace scgi
+
+BOOST_CGI_NAMESPACE_END
+
+#endif // CGI_SCGI_CLIENT_HPP_INCLUDED__
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/error.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/error.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,180 @@
+//                     -- error.hpp --
+//
+//            Copyright (c) Darren Garvey 2010.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+//
+// Abstract:
+// ---------
+//
+// SCGI errors are defined in here.
+//
+////////////////////////////////////////////////////////////////
+#ifndef BOOST_SCGI_ERROR_HPP_INCLUDED__
+#define BOOST_SCGI_ERROR_HPP_INCLUDED__
+
+#include <string>
+#include <boost/system/error_code.hpp>
+
+BOOST_CGI_NAMESPACE_BEGIN
+ namespace scgi {
+  namespace error {
+
+enum scgi_errors
+{
+  bad_header_type = 1,
+
+  /// A packet arrived for a request id that doesn't exist and the 
+  /// packet wasn't a BEGIN_REQUEST record.
+  bad_request_id,
+
+  /// When trying to write a packet, the client::write_some() call didn't
+  // transmit enough data before returning.
+  couldnt_write_complete_packet,
+
+  // Tried to read/write from/to the client associated to a request when it
+  // was closed.
+  client_closed,
+
+  // Self-explanatory (not much a user can do about this though).
+  abort_request_record_recieved_for_invalid_request,
+
+  // For now a user has to recognise this error and construct a request
+  // themselves. This is an ugly hack.
+  multiplexed_request_incoming,
+
+  // A begin_request packet has come in with an existing request id.
+  duplicate_request,
+
+  // Calling async_accept on a request that hasn't been closed isn't
+  // allowed.
+  accepting_on_an_open_request,
+
+  invalid_socket,
+
+  // On Windows, attempting to call DuplicateHandle on STDIN failed.
+  unable_to_duplicate_handle,
+
+  // On Windows, a call to SetStdHandle failed.
+  failed_to_redirect_stdin,
+
+  // On Windows, TCP connections aren't supported.
+  unsupported_handle_type,
+
+  // The CONTENT_TYPE for form data wasn't recognised.
+  invalid_form_type,
+
+  // Used in basic_connection<tags::stdio>
+  broken_pipe,
+
+  // An invalid request was received.
+  invalid_request,
+
+  // **FIXME**
+  bad_read,
+
+  // **FIXME**
+  bad_write,
+
+  // A client wasn't able to open.
+  client_not_open,
+  
+  // Multiplexing connections are not yet supported.
+  // (I have no access to a server that supports it)
+  multiplexing_not_supported,
+  
+  // The client has already been closed.
+  already_closed,
+
+  // There is no such thing as 'default initialisation' with SCGI.
+  no_default_init,
+  
+  // An empty FastCGI packet was read (eg. STDIN or GET_PARAM data has been read).
+  //empty_packet_read,
+  
+  // End of File (read zero bytes)
+  eof
+};
+
+  namespace detail {
+
+class scgi_category
+  : public boost::system::error_category
+{
+public:
+  const char* name() const { return "scgi_error"; }
+  std::string message(int e) const
+  {
+    switch(e)
+    {
+    case client_closed:
+      return "You are trying to read from or write to a closed client.";
+    case multiplexed_request_incoming:
+      return "A new request is pending on this connection (ie. it is "
+             "multiplexed). This isn't handled for now. **FIXME**";
+    case accepting_on_an_open_request:
+      return "You called async_accept before closing a request.";
+    case already_closed:
+      return "The client has already been closed.";
+    case invalid_request:
+      return "An invalid request was received.";
+    case multiplexing_not_supported:
+      return "Multiplexing connections are not yet fully supported.";
+    case unable_to_duplicate_handle:
+      return "A call to DuplicateHandle failed while trying to duplicate the FastCGI HANDLE.";
+    case failed_to_redirect_stdin:
+      return "A call to SetStdHandle failed while trying to redirect the FastCGI HANDLE.";
+    case unsupported_handle_type:
+      return "An unsupported connection type was used to communicate with the FastCGI application.";
+    //case empty_packet_read:
+    //  return "An empty FastCGI packet was read (eg. STDIN or GET_PARAM data has been read).";
+    default:
+      return "An unknown FastCGI error occurred.";
+    }
+  }
+};
+
+  } // namespace detail
+
+inline const boost::system::error_category& get_scgi_category()
+{
+  static detail::scgi_category instance;
+  return instance;
+}
+
+static const boost::system::error_category& scgi_category
+  = ::BOOST_CGI_NAMESPACE::scgi::error::get_scgi_category();
+
+  } // namespace error
+ } // namespace scgi
+BOOST_CGI_NAMESPACE_END
+
+namespace boost {
+  namespace system {
+
+    template<> struct is_error_code_enum<
+        ::BOOST_CGI_NAMESPACE::scgi::error::scgi_errors
+      >
+    {
+      BOOST_STATIC_CONSTANT(bool, value = true);
+    };
+
+  } // namespace system
+} // namespace boost
+
+BOOST_CGI_NAMESPACE_BEGIN
+ namespace scgi {
+  namespace error {
+  
+    inline boost::system::error_code make_error_code(scgi_errors e)
+    {
+      return boost::system::error_code(
+          static_cast<int>(e), get_scgi_category());
+    }
+
+  } // namespace error
+ } // namespace scgi
+BOOST_CGI_NAMESPACE_END
+
+#endif // BOOST_SCGI_ERROR_HPP_INCLUDED__
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,36 @@
+//                 -- scgi/request.hpp --
+//
+//            Copyright (c) Darren Garvey 2010.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_SCGI_REQUEST_HPP_INCLUDED__
+#define CGI_SCGI_REQUEST_HPP_INCLUDED__
+
+#include "boost/cgi/scgi/traits.hpp"
+#include "boost/cgi/scgi/service.hpp"
+#include "boost/cgi/scgi/request_service.hpp"
+#include "boost/cgi/fwd/basic_request_fwd.hpp"
+
+BOOST_CGI_NAMESPACE_BEGIN
+ namespace scgi {
+   
+   // typedef for typical usage (SCGI)
+   typedef
+     common::basic_request<
+          common::tags::scgi
+     >
+   request;
+
+ } // namespace scgi
+BOOST_CGI_NAMESPACE_END
+
+namespace boost { namespace scgi {
+  using ::BOOST_CGI_NAMESPACE::scgi::request;
+} }
+
+#include "boost/cgi/basic_request.hpp"
+
+#endif // CGI_SCGI_REQUEST_HPP_INCLUDED__
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_acceptor_service.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_acceptor_service.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,316 @@
+//          -- scgi/scgi_request_acceptor_service.hpp --
+//
+//           Copyright (c) Darren Garvey 2010.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_SCGI_REQUEST_ACCEPTOR_SERVICE_HPP_INCLUDED__
+#define CGI_SCGI_REQUEST_ACCEPTOR_SERVICE_HPP_INCLUDED__
+
+#include "boost/cgi/detail/push_options.hpp"
+
+#include <boost/ref.hpp>
+#include <boost/bind.hpp>
+#include <boost/asio.hpp>
+#include <boost/thread.hpp>
+#include <boost/function.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/system/error_code.hpp>
+///////////////////////////////////////////////////////////
+#include "boost/cgi/common/protocol_traits.hpp"
+#include "boost/cgi/scgi/request.hpp"
+#include "boost/cgi/scgi/error.hpp"
+#include "boost/cgi/import/io_service.hpp"
+#include "boost/cgi/detail/throw_error.hpp"
+#include "boost/cgi/detail/service_base.hpp"
+#include "boost/cgi/fwd/basic_protocol_service_fwd.hpp"
+
+BOOST_CGI_NAMESPACE_BEGIN
+
+  //namespace scgi {
+
+  /// The service_impl class for FCGI basic_request_acceptor<>s
+   template<typename Protocol = common::tags::scgi>
+   class scgi_request_acceptor_service
+     : public detail::service_base<
+         ::BOOST_CGI_NAMESPACE::scgi_request_acceptor_service<Protocol>
+       >
+   {
+   public:
+   
+     typedef scgi_request_acceptor_service<Protocol> self_type;
+     typedef Protocol                               protocol_type;
+     typedef common::protocol_traits<Protocol>      traits;
+     typedef typename traits::protocol_service_type protocol_service_type;
+     typedef typename traits::native_protocol_type  native_protocol_type;
+     typedef typename traits::native_type           native_type;
+     typedef typename traits::request_type          request_type;
+     typedef typename traits::acceptor_service_type acceptor_service_type;
+     typedef typename traits::acceptor_impl_type    acceptor_impl_type;
+     typedef typename traits::endpoint_type         endpoint_type;
+     typedef boost::shared_ptr<request_type>        request_ptr;
+     typedef std::pair<
+       typename std::set<request_ptr>::iterator, bool> request_iter;
+     typedef boost::function<int (request_type&)>   accept_handler_type;
+
+     struct implementation_type
+     {
+       typedef Protocol                               protocol_type;
+       typedef common::protocol_traits<Protocol>      traits;
+       typedef typename traits::protocol_service_type protocol_service_type;
+       typedef typename traits::native_protocol_type  native_protocol_type;
+       typedef typename traits::request_type          request_type;
+       typedef typename traits::acceptor_service_type acceptor_service_type;
+       typedef typename traits::endpoint_type         endpoint_type;
+
+       acceptor_impl_type                            acceptor_;
+       protocol_service_type*                        protocol_service_;
+       unsigned short                                port_num_;
+       endpoint_type                                 endpoint_;
+       
+     };
+
+     explicit scgi_request_acceptor_service(::BOOST_CGI_NAMESPACE::common::io_service& ios)
+       : detail::service_base< ::BOOST_CGI_NAMESPACE::scgi_request_acceptor_service<Protocol> >(ios)
+       , acceptor_service_(boost::asio::use_service<acceptor_service_type>(ios))
+       , strand_(ios)
+     {
+     }
+
+     protocol_service_type&
+       service(implementation_type const& impl) const
+     {
+       return *impl.protocol_service_;
+     }
+
+     void set_protocol_service(implementation_type& impl
+                              , protocol_service_type& ps)
+     {
+       impl.protocol_service_ = &ps;
+     }
+
+     protocol_service_type&
+       get_protocol_service(implementation_type& impl)
+     {
+       BOOST_ASSERT(impl.protocol_service_ != NULL);
+       return *impl.protocol_service_;
+     }
+
+     void construct(implementation_type& impl)
+     {
+       acceptor_service_.construct(impl.acceptor_);
+     }
+
+     void destroy(implementation_type& impl)
+     {
+       // close/reject all the waiting requests
+       acceptor_service_.destroy(impl.acceptor_);
+     }
+
+     void shutdown_service()
+     {
+       acceptor_service_.shutdown_service();
+     }
+
+     boost::system::error_code
+     default_init(implementation_type& impl, boost::system::error_code& ec)
+     {
+       ec = boost::system::error_code(829, boost::system::system_category);
+       return ec;
+     }
+
+     /// Check if the given implementation is open.
+     bool is_open(implementation_type& impl)
+     {
+       return acceptor_service_.is_open(impl.acceptor_);
+     }
+
+     /// Open a new *socket* acceptor implementation.
+     boost::system::error_code
+       open(implementation_type& impl, const native_protocol_type& protocol
+           , boost::system::error_code& ec)
+     {
+       return acceptor_service_.open(impl.acceptor_, protocol, ec);
+     }
+
+     template<typename Endpoint>
+     boost::system::error_code
+       bind(implementation_type& impl, const Endpoint& endpoint
+           , boost::system::error_code& ec)
+     {
+       acceptor_service_.set_option(impl.acceptor_,
+           boost::asio::socket_base::reuse_address(true), ec);
+       return acceptor_service_.bind(impl.acceptor_, endpoint, ec);
+     }
+
+     /// Assign an existing native acceptor to a *socket* acceptor.
+     boost::system::error_code
+       assign(implementation_type& impl, const native_protocol_type& protocol
+             , const native_type& native_acceptor
+             , boost::system::error_code& ec)
+     {
+       return acceptor_service_.assign(impl.acceptor_, protocol
+                                      , native_acceptor, ec);
+     }
+
+     boost::system::error_code
+       listen(implementation_type& impl, int backlog, boost::system::error_code& ec)
+     {
+       return acceptor_service_.listen(impl.acceptor_, backlog, ec);
+     }
+     
+     void do_accept(implementation_type& impl
+             , accept_handler_type handler)
+     {
+       request_ptr new_request;
+       
+       new_request = request_type::create(*impl.protocol_service_);
+       
+       if (!new_request->is_open())
+       {
+         acceptor_service_.async_accept(impl.acceptor_,
+             new_request->client().connection()->next_layer(), 0,
+             strand_.wrap(
+               boost::bind(&self_type::handle_accept
+                , this, boost::ref(impl), new_request, handler, _1
+               )
+             )
+           );
+       }
+       else
+       {
+         impl.protocol_service_->post(
+           strand_.wrap(
+             boost::bind(&self_type::handle_accept
+                 , this, boost::ref(impl), new_request, handler, boost::system::error_code()
+               )
+             )
+           );
+       }
+     }
+
+     void handle_accept(
+         implementation_type& impl, request_ptr new_request,
+         accept_handler_type handler, const boost::system::error_code& ec
+      )
+     {
+       new_request->status(common::accepted);
+       int status = handler(*new_request);
+       if (new_request->is_open()) {
+         new_request->close(http::ok, status);
+       }
+       new_request->clear();
+     }
+
+     /// Accepts a request and runs the passed handler.
+     void async_accept(implementation_type& impl
+             , accept_handler_type handler)
+     {
+       strand_.post(
+         boost::bind(&self_type::do_accept,
+             this, boost::ref(impl), handler)
+         );
+     }
+     
+     int accept(implementation_type& impl, accept_handler_type handler
+             , endpoint_type* endpoint, boost::system::error_code& ec)
+     {
+       request_ptr new_request;
+       
+       // Accepting on new request.
+       new_request = request_type::create(*impl.protocol_service_);
+       
+       // The waiting request may be open if it is a multiplexed request.
+       if (!new_request->is_open())
+       {
+         ec = acceptor_service_.accept(impl.acceptor_,
+                  new_request->client().connection()->next_layer(), endpoint, ec);
+       }
+       new_request->status(common::accepted);
+       int status = handler(*new_request);
+       
+       if (new_request->is_open()) {
+         new_request->close(common::http::ok, status);
+       }
+       new_request->clear();
+       
+       return status;
+     }
+
+     /// Accepts one request.
+     template<typename CommonGatewayRequest>
+     boost::system::error_code
+       accept(implementation_type& impl, CommonGatewayRequest& request
+             , endpoint_type* endpoint, boost::system::error_code& ec)
+     {
+       BOOST_ASSERT
+       ( ! request.is_open()
+        && "Error: Calling accept on open request (close it first?)."
+       );
+
+       // If the client is open, make sure the request is clean.
+       // ie. don't leak data from one request to another!
+       if (request.client().is_open())
+       {
+         request.clear();
+       }
+
+       // ...otherwise accept a new connection.
+       ec = acceptor_service_.accept(impl.acceptor_,
+                request.client().connection()->next_layer(), endpoint, ec);
+       if (!ec)
+         request.status(common::accepted);
+       return ec;
+     }
+
+     /// Asynchronously accepts one request.
+     template<typename Handler>
+     void async_accept(implementation_type& impl
+					  , typename implementation_type::request_type& request
+                      , Handler handler)
+     {
+       acceptor_service_.async_accept(impl.acceptor_,
+          request.client().connection()->next_layer(), handler);
+     }
+
+     /// Close the acceptor (not implemented yet).
+     boost::system::error_code
+       close(implementation_type& impl, boost::system::error_code& ec)
+     {
+       return boost::system::error_code(348, boost::system::system_category);
+     }
+
+     typename implementation_type::endpoint_type
+       local_endpoint(implementation_type& impl, boost::system::error_code& ec)
+     {
+       return acceptor_service_.local_endpoint(impl.acceptor_, ec);
+     }
+
+     native_type
+     native(implementation_type& impl)
+     {
+       return acceptor_service_.native(impl.acceptor_);
+     }
+
+     bool
+     is_cgi(implementation_type& impl)
+     {
+       return false;
+     }
+
+   public:
+     /// The underlying socket acceptor service.
+     acceptor_service_type&          acceptor_service_;
+     boost::asio::io_service::strand strand_;
+   };
+
+ //} // namespace scgi
+BOOST_CGI_NAMESPACE_END
+
+#include "boost/cgi/detail/pop_options.hpp"
+
+#endif // CGI_SCGI_REQUEST_ACCEPTOR_SERVICE_HPP_INCLUDED__
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_impl.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_impl.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,43 @@
+//
+// request.hpp
+// ~~~~~~~~~~~
+//
+// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef BOOST_CGI_SCGI_REQUEST_IMPL_HPP_INCLUDED_
+#define BOOST_CGI_SCGI_REQUEST_IMPL_HPP_INCLUDED_
+
+#include <string>
+#include <vector>
+
+BOOST_CGI_NAMESPACE_BEGIN
+   namespace scgi {
+
+struct header_impl
+{
+  std::string name;
+  std::string value;
+};
+
+/// A request received from a client.
+struct request_impl
+{
+  /// The headers included with the request.
+  std::vector<header_impl> headers;
+
+  /// The optional content sent with the request.
+  std::string content;
+
+  /// The length of the headers.
+  std::size_t headers_length_;
+  std::size_t content_length_;
+};
+
+ } // namespace scgi
+BOOST_CGI_NAMESPACE_END
+
+#endif // BOOST_CGI_SCGI_REQUEST_IMPL_HPP_INCLUDED_
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_parser.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_parser.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,65 @@
+//             -- scgi/request_parser.hpp --
+//
+//            Copyright (c) Darren Garvey 2010.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_SCGI_REQUEST_PARSER_HPP_INCLUDED__
+#define CGI_SCGI_REQUEST_PARSER_HPP_INCLUDED__
+
+#include <string>
+#include <boost/logic/tribool.hpp>
+#include <boost/tuple/tuple.hpp>
+#include "boost/cgi/detail/coroutine.hpp"
+
+BOOST_CGI_NAMESPACE_BEGIN
+ namespace scgi {
+
+struct request_impl;
+
+/// Parser for incoming requests.
+class request_parser : coroutine
+{
+public:
+  /// Parse some data. The tribool return value is true when a complete request
+  /// has been parsed, false if the data is invalid, indeterminate when more
+  /// data is required. The InputIterator return value indicates how much of the
+  /// input has been consumed.
+  template <typename InputIterator>
+  boost::tuple<boost::tribool, InputIterator> parse(request_impl& req,
+      InputIterator begin, InputIterator end)
+  {
+    while (begin != end)
+    {
+      std::cerr<< *begin;
+      boost::tribool result = consume(req, *begin++);
+      if (result || !result)
+        return boost::make_tuple(result, begin);
+    }
+    boost::tribool result = boost::indeterminate;
+    return boost::make_tuple(result, begin);
+  }
+
+private:
+  /// The name of the content length header.
+  static std::string content_length_name_;
+
+  /// Whether writing the header name at the moment.
+  bool writing_header_name_;
+
+  /// Length of the headers. Always required.
+  std::size_t headers_length_;
+
+  /// Content length as decoded from headers. Defaults to 0.
+  std::size_t content_length_;
+
+  /// Handle the next character of input.
+  boost::tribool consume(request_impl& req, char input);
+};
+
+ } // namespace scgi
+BOOST_CGI_NAMESPACE_END
+
+#endif // CGI_SCGI_REQUEST_PARSER_HPP_INCLUDED__
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_parser.ipp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_parser.ipp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,124 @@
+//             -- scgi/request_parser.ipp --
+//
+//            Copyright (c) Darren Garvey 2010.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_SCGI_REQUEST_PARSER_IPP_INCLUDED__
+#define CGI_SCGI_REQUEST_PARSER_IPP_INCLUDED__
+
+#include "boost/cgi/scgi/request_parser.hpp"
+#include <algorithm>
+#include <cctype>
+#include <boost/lexical_cast.hpp>
+#include "boost/cgi/scgi/request_impl.hpp"
+
+BOOST_CGI_NAMESPACE_BEGIN
+ namespace scgi {
+
+#include "boost/cgi/detail/yield.hpp" // Enable the pseudo-keywords reenter, yield and fork.
+
+/// The "meat" of the SCGI parser.
+boost::tribool request_parser::consume(request_impl& req, char c)
+{
+  reenter (this)
+  {
+    req.headers.clear();
+    req.content.clear();
+    content_length_ = 0;
+    headers_length_ = 0;
+
+    // Length of headers.
+    while (c != ':')
+    {
+      // Save the number to the content until we have the whole string,
+      // at which point the content can be cleared again.
+      req.content.push_back(c);
+      yield return boost::indeterminate;
+    }
+    if (req.content.empty())
+      return false;
+
+    // Skip the ":" character.
+    yield return boost::indeterminate;
+
+    try 
+    {
+      headers_length_ = boost::lexical_cast<std::size_t>(req.content);
+      req.content.clear();
+    }
+    catch (boost::bad_lexical_cast&)
+    {
+      return false;
+    }
+
+    writing_header_name_ = true;
+    req.headers.push_back(header_impl());
+
+    // Headers.
+    while (c != ',')
+    {
+      if (c == '\0')
+      {
+        if (writing_header_name_)
+          writing_header_name_ = false;
+        else
+        {
+          writing_header_name_ = true;
+          // Add another empty header.
+          req.headers.push_back(header_impl());
+        }
+      }
+      else
+      {
+        if (writing_header_name_)
+          req.headers.back().name.push_back(c);
+        else
+          req.headers.back().value.push_back(c);
+      }
+
+      yield return boost::indeterminate;
+    }
+
+    // Content length. The first header MUST be the Content-length header.
+    std::cerr<< std::endl << "First header is: " << req.headers.front().name << std::endl;
+
+    for(std::vector<header_impl>::iterator iter (req.headers.begin()), end (req.headers.end())
+      ; iter != end; ++iter)
+    {
+      std::cerr<< "Header is: " << iter->name << " = " << iter->value << std::endl;
+    }
+
+
+    if (req.headers.front().name != "CONTENT_LENGTH")
+      return false;
+
+    try 
+    {
+      std::cerr<< std::endl << "Got content-length:" << req.headers.front().value << std::endl;
+      content_length_ = boost::lexical_cast<std::size_t>(req.headers.front().value);
+    }
+    catch (boost::bad_lexical_cast&)
+    {
+      return false;
+    }
+
+    // Content.
+    while (req.content.size() < content_length_)
+    {
+      yield return boost::indeterminate;
+      req.content.push_back(c);
+    }
+  }
+
+  return true;
+}
+
+#include "boost/cgi/detail/unyield.hpp"
+
+ } // namespace scgi
+BOOST_CGI_NAMESPACE_END
+
+#endif // CGI_SCGI_REQUEST_PARSER_IPP_INCLUDED__
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_service.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_service.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,212 @@
+//             -- scgi/request_service.hpp --
+//
+//            Copyright (c) Darren Garvey 2010.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_SCGI_REQUEST_SERVICE_HPP_INCLUDED__
+#define CGI_SCGI_REQUEST_SERVICE_HPP_INCLUDED__
+
+#include <boost/logic/tribool.hpp>
+#include <boost/fusion/include/vector.hpp>
+#include <boost/fusion/support.hpp>
+#include <boost/system/error_code.hpp>
+////////////////////////////////////////////////////////////////
+#include "boost/cgi/common/form_parser.hpp"
+#include "boost/cgi/common/map.hpp"
+#include "boost/cgi/common/parse_options.hpp"
+#include "boost/cgi/common/request_base.hpp"
+#include "boost/cgi/common/role_type.hpp"
+#include "boost/cgi/common/source_enums.hpp"
+#include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/connections/tcp_socket.hpp"
+#include "boost/cgi/detail/service_base.hpp"
+#include "boost/cgi/detail/throw_error.hpp"
+#include "boost/cgi/scgi/client.hpp"
+#include "boost/cgi/scgi/request_parser.hpp"
+#include "boost/cgi/http/status_code.hpp"
+#include "boost/cgi/import/read.hpp"
+#include "boost/cgi/import/io_service.hpp"
+
+BOOST_CGI_NAMESPACE_BEGIN
+ namespace scgi {
+ 
+  /// The IoObjectService class for a SCGI basic_request<>s
+  template<typename Protocol>
+  class scgi_request_service
+    : public common::request_base<Protocol>
+    , public detail::service_base<scgi_request_service<Protocol> >
+  {
+  public:
+    typedef scgi_request_service<Protocol>           self_type;
+    typedef scgi_request_service<Protocol>           full_type;
+    typedef common::request_base<Protocol>           base_type;
+    typedef typename base_type::traits               traits;
+    typedef typename base_type::client_type          client_type;
+    typedef typename base_type::string_type          string_type;
+    typedef typename base_type::mutable_buffers_type mutable_buffers_type;
+    typedef typename traits::header_buffer_type      header_buffer_type;
+
+    /// The actual implementation date for an SCGI request.
+    struct implementation_type
+      : base_type::impl_base
+    {
+      typedef typename base_type::traits                 traits;
+      typedef typename base_type::client_type            client_type;
+      typedef typename base_type::buffer_type            buffer_type;
+      typedef typename base_type::mutable_buffers_type   mutable_buffers_type;
+      typedef typename client_type::header_buffer_type   header_buffer_type;
+      typedef request_parser               request_parser_type;
+
+      implementation_type()
+        : id_(0)
+      {
+      }
+
+      boost::uint16_t id_;
+
+      header_buffer_type header_buf_;
+      
+      // Buffer to hold param records and filter data, etc.
+      buffer_type param_buffer_;
+      boost::shared_ptr<boost::array<char, 8192> > buffer_;
+
+      /// Whether the request is valid or not.
+      boost::tribool valid_request_;
+
+      /// The parser for the incoming request.
+      request_parser_type request_parser_;
+
+      mutable_buffers_type prepare_misc(std::size_t size)
+      {
+        // Make sure we're not trying to make a zero-sized buffer.
+        BOOST_ASSERT(size && "Attempting to allocate a zero-sized buffer.");
+        std::size_t bufsz(param_buffer_.size());
+        param_buffer_.resize(bufsz + size);
+        return boost::asio::buffer(¶m_buffer_[bufsz], size);
+      }
+     };
+
+     template<typename Service>
+     struct callback_functor
+     {
+       callback_functor(implementation_type& impl, Service* service)
+         : impl_(impl)
+         , service_(service)
+       {
+       }
+
+       std::size_t operator()(boost::system::error_code& ec)
+       {
+         return service_->read_some(impl_, ec);
+       }
+
+     private:
+       implementation_type& impl_;
+       Service* service_;
+     };
+
+
+    scgi_request_service(::BOOST_CGI_NAMESPACE::common::io_service& ios)
+      : detail::service_base<scgi_request_service<Protocol> >(ios)
+      , strand_(ios)
+    {
+    }
+
+    ~scgi_request_service()
+    {
+    }
+
+    void construct(implementation_type& impl)
+    {
+      impl.client_.set_connection(
+        implementation_type::connection_type::create(this->get_io_service())
+      );
+    }
+
+    void shutdown_service()
+    {
+    }
+
+    /// Close the request.
+    int close(implementation_type& impl,
+      common::http::status_code hsc = common::http::ok
+      , int program_status = 0);
+
+    /// Close the request.
+    int close(implementation_type& impl,
+        common::http::status_code hsc
+      , int program_status, boost::system::error_code& ec);
+
+    /// Clear all request data (object is then safe to reuse).
+    void clear(implementation_type& impl);
+
+    /// Load the request to a point where it can be usefully used.
+    boost::system::error_code
+    load(implementation_type& impl, common::parse_options opts
+          , boost::system::error_code& ec);
+
+    /// Read and parse the cgi POST meta variables (greedily)
+    template<typename RequestImpl>
+    boost::system::error_code
+    parse_post_vars(RequestImpl& impl, boost::system::error_code& ec)
+    {
+      // Return an error, except ignore EOF, as this is expected.
+      if (ec)
+      {
+        if (ec == boost::cgi::common::error::eof)
+          ec = boost::system::error_code();
+        else
+          return ec;
+      }
+
+      return base_type::parse_post_vars(
+          impl,
+          callback_functor<self_type>(impl, this),
+          ec
+        );
+    }
+
+    // **FIXME**
+    template<typename Handler>
+    void async_load(implementation_type& impl, common::parse_options opts, Handler handler);
+
+    /// Returns true if the request environment params have been read.
+    bool params_read(implementation_type& impl);
+
+    common::role_type role(implementation_type const& impl) const
+    {
+      return common::responder;
+    }
+
+    client_type&
+      client(implementation_type& impl)
+    {
+      return impl.client_;
+    }
+    
+  private:
+  
+    template<typename Handler>
+    void do_load(
+        implementation_type& impl, common::parse_options opts,
+        Handler handler, boost::system::error_code& ec
+      );
+
+  private:
+    boost::asio::io_service::strand strand_;
+  };
+
+ } // namespace scgi
+BOOST_CGI_NAMESPACE_END
+
+#include "boost/cgi/scgi/request.hpp"
+#include "boost/cgi/basic_request.hpp"
+
+#if !defined( BOOST_CGI_BUILD_LIB )
+#    include "boost/cgi/scgi/request_service.ipp"
+#endif
+
+#endif // CGI_SCGI_REQUEST_SERVICE_HPP_INCLUDED__
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_service.ipp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/request_service.ipp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,236 @@
+//             -- scgi/request_service.ipp --
+//
+//            Copyright (c) Darren Garvey 2010.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_SCGI_REQUEST_SERVICE_IPP_INCLUDED__
+#define CGI_SCGI_REQUEST_SERVICE_IPP_INCLUDED__
+
+#include <boost/fusion/support.hpp>
+#include <boost/fusion/include/algorithm.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/fusion/include/vector.hpp>
+////////////////////////////////////////////////////////////////
+#include "boost/cgi/scgi/client.hpp"
+#include "boost/cgi/scgi/error.hpp"
+#include "boost/cgi/scgi/request_service.hpp"
+#include "boost/cgi/common/map.hpp"
+#include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/common/role_type.hpp"
+#include "boost/cgi/common/form_parser.hpp"
+#include "boost/cgi/common/source_enums.hpp"
+#include "boost/cgi/common/request_base.hpp"
+#include "boost/cgi/common/parse_options.hpp"
+#include "boost/cgi/http/status_code.hpp"
+#include "boost/cgi/import/read.hpp"
+#include "boost/cgi/import/io_service.hpp"
+#include "boost/cgi/detail/service_base.hpp"
+#include "boost/cgi/detail/throw_error.hpp"
+#include "boost/cgi/config.hpp"
+#include "boost/cgi/scgi/request_impl.hpp"
+
+BOOST_CGI_NAMESPACE_BEGIN
+
+   namespace detail {
+     
+     /// Helper class to asynchronously load a request.
+     /**
+      * This is just a function object that can be posted to another
+      * thread to do the actual work of loading. It's operator()() does
+      * the work.
+      */
+     template<typename T, typename Handler>
+     struct async_load_helper
+     {
+       async_load_helper(T& t, typename T::implementation_type& impl
+                        , common::parse_options opts, Handler h)
+         : type(t)
+         , impl_(impl)
+         , parse_opts_(opts)
+         , handler_(h)
+       {
+       }
+
+       void operator()()
+       {
+         boost::system::error_code ec;
+         type.load(impl_, parse_opts_, ec);
+         handler_(ec);
+       }
+
+       T& type;
+       typename T::implementation_type& impl_;
+       common::parse_options parse_opts_;
+       Handler handler_;
+     };
+     
+     struct clear_data
+     {
+       template<typename T>
+       void operator()(T& x) const {
+         x.clear();
+       }
+     };
+
+  } // namespace detail
+
+  namespace scgi {
+ 
+    /// Close the request.
+    template<typename Protocol>
+    BOOST_CGI_INLINE int
+    scgi_request_service<Protocol>::close(
+        implementation_type& impl
+      , common::http::status_code hsc
+      , int program_status)
+    {
+      boost::system::error_code ec;
+      close(impl, hsc, program_status, ec);
+      detail::throw_error(ec);
+      return program_status;
+    }
+
+	template<typename Protocol>
+    BOOST_CGI_INLINE int
+    scgi_request_service<Protocol>::close(
+        implementation_type& impl
+      , common::http::status_code hsc
+      , int program_status
+      , boost::system::error_code& ec)
+    {
+      impl.all_done_ = true;
+      impl.client_.close(program_status, ec);
+      impl.request_status_ = common::closed;
+      return program_status;
+    }
+
+	template<typename Protocol>
+    BOOST_CGI_INLINE void
+    scgi_request_service<Protocol>::clear(implementation_type& impl)
+    {
+      impl.post_buffer_.clear();
+      // Clear all request data.
+      boost::fusion::for_each(impl.vars_, detail::clear_data());
+      impl.stdin_parsed_ = false;
+      impl.http_status_ = common::http::no_content;
+      impl.request_status_ = common::null;
+      impl.all_done_ = false;
+      impl.client_.status_ = common::none_;
+      impl.client_.request_id_ = -1;
+    }
+      
+    /// Load the request to a point where it can be usefully used.
+    template<typename Protocol>
+    BOOST_CGI_INLINE boost::system::error_code
+    scgi_request_service<Protocol>::load(
+        implementation_type& impl, common::parse_options parse_opts
+      , boost::system::error_code& ec)
+    {
+      impl.client_.construct(impl, ec);
+
+      // Bomb out if the client isn't open here.
+      if (!impl.client_.connection()->is_open())
+          return error::client_not_open;
+
+      impl.buffer_.reset(new boost::array<char, 8192>);
+      request_impl req;
+
+      do
+      {
+        // Receive some more data. When control resumes at the following line,
+        // the ec and length parameters reflect the result of the asynchronous
+        // operation.
+        std::size_t length
+          = impl.client_.connection()->read_some(boost::asio::buffer(*impl.buffer_));
+
+        // Parse the data we just received.
+        boost::tie(impl.valid_request_, boost::tuples::ignore)
+          = impl.request_parser_.parse(req,
+              impl.buffer_->data(), impl.buffer_->data() + length);
+
+        // An indeterminate result means we need more data, so keep looping.
+      } while (boost::indeterminate(impl.valid_request_));
+
+      if (!impl.valid_request_)
+      {
+        ec = error::invalid_request;
+        return ec;
+      }
+
+      for(std::vector<header_impl>::iterator iter (req.headers.begin()), end (req.headers.end())
+        ; iter != end; ++iter)
+      {
+        env_vars(impl.vars_)[iter->name.c_str()] = iter->value.c_str();
+      }
+      
+      std::string const& cl = env_vars(impl.vars_)["CONTENT_LENGTH"];
+      impl.bytes_left_
+         = cl.empty() ? 0 : boost::lexical_cast<std::size_t>(cl);
+      impl.client_.bytes_left()
+         = impl.bytes_left_;
+      std::string const& request_method
+         = env_vars(impl.vars_)["REQUEST_METHOD"];
+
+      if ((request_method == "GET" || request_method == "HEAD")
+          && parse_opts > common::parse_env
+          && parse_opts & common::parse_get_only)
+      {
+        parse_get_vars(impl, ec);
+      }
+      else
+      if (request_method == "POST"
+          && (parse_opts & common::parse_post_only))
+      {
+        parse_post_vars(impl, ec);
+      }
+
+      if (ec) return ec;
+
+      if (parse_opts & common::parse_cookie_only)
+      {
+        if (parse_cookie_vars(impl, "HTTP_COOKIE", ec)) // returns an error_code
+          return ec;
+      }
+
+      status(impl, common::loaded);
+
+      return ec;
+    }
+
+    template<typename Protocol>
+    template<typename Handler>
+    BOOST_CGI_INLINE
+    void scgi_request_service<Protocol>::do_load(
+        implementation_type& impl, common::parse_options opts,
+        Handler handler, boost::system::error_code& ec
+      )
+    {
+      impl.client_.construct(impl, ec);
+      // Bomb out if the client isn't open here.
+      if (!impl.client_.connection()->is_open())
+          ec = error::client_not_open;
+
+    }
+
+    // **FIXME**
+    template<typename Protocol>
+    template<typename Handler> BOOST_CGI_INLINE
+    void scgi_request_service<Protocol>::async_load(
+        implementation_type& impl, common::parse_options opts, Handler handler)
+    {
+      strand_.post(
+        detail::async_load_helper<self_type, Handler>(this, opts, handler)
+      );
+    }
+
+ } // namespace scgi
+BOOST_CGI_NAMESPACE_END
+
+#include "boost/cgi/scgi/request.hpp"
+#include "boost/cgi/scgi/request_parser.ipp"
+#include "boost/cgi/basic_request.hpp"
+
+#endif // CGI_SCGI_REQUEST_SERVICE_IPP_INCLUDED__
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/service.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/service.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,32 @@
+//                 -- scgi/service.hpp --
+//
+//            Copyright (c) Darren Garvey 2010.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_SCGI_SERVICE_HPP_INCLUDED__
+#define CGI_SCGI_SERVICE_HPP_INCLUDED__
+
+#include "boost/cgi/scgi/traits.hpp"
+#include "boost/cgi/common/basic_protocol_service.hpp"
+
+BOOST_CGI_NAMESPACE_BEGIN
+ namespace scgi {
+ 
+   // typedef for standard scgi::service (a model of ProtocolService)
+   typedef
+   common::basic_protocol_service<
+       common::tags::scgi
+     >
+   service;
+   
+ } // namespace scgi
+BOOST_CGI_NAMESPACE_END
+
+namespace boost { namespace scgi {
+  using ::BOOST_CGI_NAMESPACE::scgi::service;
+} }
+
+#endif // CGI_SCGI_SERVICE_HPP_INCLUDED__
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/traits.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/scgi/traits.hpp	2010-06-03 13:26:05 EDT (Thu, 03 Jun 2010)
@@ -0,0 +1,111 @@
+//                 -- scgi/traits.hpp --
+//
+//            Copyright (c) Darren Garvey 2010.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef BOOST_CGI_SCGI_TRAITS_HPP_INCLUDED_
+#define BOOST_CGI_SCGI_TRAITS_HPP_INCLUDED_
+
+#include <boost/asio/ip/tcp.hpp>
+#include <boost/none.hpp>
+#include <boost/config.hpp>
+///////////////////////////////////////////////////////////
+#include "boost/cgi/common/parse_options.hpp"
+#include "boost/cgi/common/protocol_traits.hpp"
+#include "boost/cgi/common/role_type.hpp"
+#include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/fwd/basic_client_fwd.hpp"
+#include "boost/cgi/fwd/basic_connection_fwd.hpp"
+#include "boost/cgi/fwd/basic_protocol_service_fwd.hpp"
+#include "boost/cgi/fwd/basic_request_fwd.hpp"
+#include "boost/cgi/fwd/form_parser_fwd.hpp"
+#ifdef BOOST_CGI_ENABLE_SESSIONS
+#  include "boost/cgi/fwd/sessions_fwd.hpp"
+#endif // BOOST_CGI_ENABLE_SESSIONS
+
+BOOST_CGI_NAMESPACE_BEGIN
+
+  namespace scgi
+  {
+  class scgi_service_impl;
+  template<typename Protocol>
+  class scgi_request_service;
+  class scgi_acceptor_service;
+  }
+
+  // Forward declarations
+
+  template<typename Protocol>
+  class scgi_request_acceptor_service;
+
+ namespace common {
+ 
+    /// Common Traits for SCGI.
+    template<>
+    struct protocol_traits<tags::scgi>
+    {
+      /// Identity types
+      typedef protocol_traits<tags::scgi>            type;
+      typedef tags::scgi                             protocol_type;
+
+      /// Char traits
+      typedef char                                   char_type;
+      typedef std::basic_string<char_type>           string_type;
+      typedef string_type                            buffer_type;
+
+      // Core types
+      typedef basic_protocol_service<
+                  protocol_type
+              >                                      protocol_service_type;
+      typedef basic_request<protocol_type>           request_type; 
+      typedef basic_client<protocol_type>            client_type;
+      typedef basic_connection<
+                  tags::tcp_socket
+              >                                      connection_type;
+
+      // Runtime options
+      static const parse_options parse_opts = common::parse_none;
+
+      // Utility types
+#ifdef BOOST_CGI_ENABLE_SESSIONS
+      typedef basic_session<
+                std::map<string_type, string_type>
+              >                                      session_type;
+      typedef boost::uuids::random_generator         uuid_generator_type;
+      typedef basic_session_manager<
+                protocol_type
+              >                                      session_manager_type;
+      static const bool auto_start_session = true;
+      static const int session_options = path_session;
+#endif // BOOST_CGI_ENABLE_SESSIONS
+
+      // Internal types (advanced)
+      typedef scgi::scgi_request_service<
+                  protocol_type
+              >                                      request_service_impl;
+      typedef scgi_request_acceptor_service<
+                  protocol_type
+              >                                      acceptor_service;
+      typedef boost::asio::ip::tcp                   native_protocol_type;
+      typedef boost::asio::socket_acceptor_service<
+                  native_protocol_type
+              >                                      acceptor_service_type;
+      typedef 
+          acceptor_service_type::implementation_type acceptor_impl_type;
+      typedef acceptor_service_type::native_type     native_type;
+      typedef native_protocol_type::endpoint         endpoint_type;
+      typedef form_parser                            form_parser_type;
+      typedef boost::none_t                          header_type;
+
+      typedef boost::array<unsigned char, 8>         header_buffer_type;
+      typedef boost::asio::const_buffers_1           const_buffers_type;
+      typedef boost::asio::mutable_buffers_1         mutable_buffers_type;
+    };
+
+ } // namespace common
+BOOST_CGI_NAMESPACE_END
+
+#endif // BOOST_CGI_SCGI_TRAITS_HPP_INCLUDED_