$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
From: lists.drrngrvy_at_[hidden]
Date: 2008-03-21 12:49:11
Author: drrngrvy
Date: 2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
New Revision: 43749
URL: http://svn.boost.org/trac/boost/changeset/43749
Log:
* all-files
  - Moved common bits into namespace ::cgi::common
  - Updated references to things that were moved over
* basic_request.hpp
  - adding close() overload that takes an error_code;
  - adding a clear() function so a request can be safely reused.
* basic_request_acceptor.hpp
  - an acceptor now initialises itself by default (using default_init())
  - added protocol_service() function to get the underlying basic_protocol_service
  - accept() calls now use the endpoint, like Boost.Asio.
* basic_sync_io_object.hpp
  - s/impl/implementation
* common/form_parser.hpp
  - added name member, because every form part has a name (saves looking it up in a map every time)
* connections/stdio.hpp
  - simplified write_some() a little.
* detail/cgi_*_impl_base.hpp
  - cosmetic changes, removed old fluff (see source)
* error.hpp
  - added a couple of new errors
* fcgi/acceptor_service_impl.hpp
  - added default_init() function, which only works on linux for now.
* fcgi/client.hpp
  - added close() overload that doesn't take an error_code
* response.hpp
  - added resend() function, which sends the header+body regardless of the value of `headers_terminated_`
Added:
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/acceptor.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_client_fwd.hpp   (contents, props changed)
Text files modified: 
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request.hpp                     |     6                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request_impl.hpp                |    11 +                                       
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request_service.hpp             |     2                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/service.hpp                     |     4                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_client.hpp                     |     9 +                                       
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_connection.hpp                 |     3                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_connection_fwd.hpp             |     2                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_protocol_service.hpp           |     2                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_protocol_service_fwd.hpp       |     2                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_request.hpp                    |    20 +++                                     
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_request_acceptor.hpp           |    59 ++++++++-                               
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_request_fwd.hpp                |     2                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_sync_io_object.hpp             |    12 +                                       
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cgi/request.hpp                      |     9                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cgi/request_impl.hpp                 |     4                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cgi/request_service.hpp              |     2                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cgi/service.hpp                      |     2                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/common/form_part.hpp                 |     7 +                                       
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/async_stdio.hpp          |     2                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/shareable_tcp_socket.hpp |     6                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/stdio.hpp                |    18 ++                                      
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/tcp_socket.hpp           |    11 +                                       
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/cgi_request_impl_base.hpp     |    49 +------                                 
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/cgi_service_impl_base.hpp     |   236 ++++++++++++++++++++++++--------------- 
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/protocol_traits.hpp           |    30 ++--                                    
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/error.hpp                            |    12 +                                       
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/acceptor.hpp                    |     6                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/acceptor_service_impl.hpp       |   105 ++++++++++++-----                       
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/client.hpp                      |    44 +++++-                                  
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/request.hpp                     |     9 +                                       
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/request_acceptor_service.hpp    |    30 +++-                                    
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/service.hpp                     |     2                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/specification.hpp               |     2                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/io_service.hpp                       |     6 +                                       
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/map.hpp                              |     2                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/read.hpp                             |     2                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/request_service.hpp                  |     4                                         
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/response.hpp                         |    50 +++++--                                 
   sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/write.hpp                            |     4                                         
   39 files changed, 526 insertions(+), 262 deletions(-)
Added: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/acceptor.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/acceptor.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -0,0 +1,28 @@
+//                -- acgi/acceptor.hpp --
+//
+//           Copyright (c) Darren Garvey 2007.
+// 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_ACGI_ACCEPTOR_HPP_INCLUDED__
+#define CGI_ACGI_ACCEPTOR_HPP_INCLUDED__
+
+#include "boost/cgi/basic_request_acceptor.hpp"
+#include "boost/cgi/acgi/request_acceptor_service.hpp"
+
+namespace cgi {
+ namespace acgi {
+
+   /// Typedef for common usage (ACGI)
+   typedef
+     ::cgi::common::basic_request_acceptor<
+       acgi_request_acceptor_service<>
+     >
+   acceptor;
+
+ } // namespace acgi
+} // namespace cgi
+
+#endif // CGI_ACGI_ACCEPTOR_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -20,7 +20,11 @@
 
   class acgi_request_service;
 
-  typedef basic_request<acgi_request_service, acgi_service> acgi_request;
+  typedef
+    common::basic_request<
+      acgi_request_service, acgi_service
+    >
+  acgi_request;
 
 } // namespace cgi
 
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request_impl.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request_impl.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request_impl.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -22,15 +22,20 @@
   class acgi_service_impl;
 
   class acgi_request_impl
-    : public cgi_request_impl_base<async_stdio_connection>
+    : public cgi_request_impl_base<common::async_stdio_connection>
   {
   public:
     typedef acgi_service    protocol_service_type;
-    typedef ::cgi::basic_client<async_stdio_connection, tags::acgi> client_type;
+    typedef common::async_stdio_connection connection_type;
+    typedef
+      ::cgi::common::basic_client<
+        connection_type, tags::acgi
+      >
+    client_type;
     //typedef async_stdio_connection client_type;
 
     acgi_request_impl()
-      : cgi_request_impl_base<async_stdio_connection>()
+      : cgi_request_impl_base<connection_type>()
     {
     }
 
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request_service.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/request_service.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -29,7 +29,7 @@
   public:
     typedef acgi_request_service        type;
     typedef acgi_request_impl           impl_type;
-    typedef ::cgi::map                  map_type;
+    typedef ::cgi::common::map          map_type;
     typedef tags::acgi                  protocol_type;
     typedef acgi_service                protocol_service_type;
 
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/service.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/acgi/service.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -20,10 +20,10 @@
   /**
    * Works with both cgi_request and acgi_request.
    */
-  typedef basic_protocol_service<tags::acgi> acgi_service;
+  typedef common::basic_protocol_service<tags::acgi> acgi_service;
 
   namespace acgi {
-    typedef basic_protocol_service<tags::acgi> service;
+    typedef common::basic_protocol_service<tags::acgi> service;
   }
 
   /// A service 'owned' by a single user-supplied io_service
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_client.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_client.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_client.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -18,6 +18,7 @@
 #include "boost/cgi/connections/tcp_socket.hpp"
 
 namespace cgi {
+ namespace common {
 
   /// A client
   /**
@@ -94,6 +95,7 @@
 
     /// Get a shared_ptr of the connection associated with the client.
     connection_ptr& connection() { return connection_; }
+    std::size_t& bytes_left()    { return bytes_left_; }
 
     /// Write some data to the client.
     template<typename ConstBufferSequence>
@@ -108,7 +110,9 @@
     std::size_t read_some(const MutableBufferSequence& buf
                          , boost::system::error_code& ec)
     {
-      return connection_->read_some(buf, ec);
+      std::size_t bytes_read = connection_->read_some(buf, ec);
+      bytes_left_ -= bytes_read;
+      return bytes_left_ > 0 ? bytes_read : (bytes_read + bytes_left_);
     }
 
     /// Asynchronously write some data to the client.
@@ -127,8 +131,11 @@
   private:
     //io_service&                           io_service_;
     connection_ptr                        connection_;
+    // we should never read more than content-length bytes.
+    std::size_t                           bytes_left_;
   };
 
+ } // namespace common
 } // namespace cgi
 
 #endif // CGI_BASIC_CLIENT_HPP_INCLUDED__
Added: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_client_fwd.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_client_fwd.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -0,0 +1,22 @@
+//               -- basic_client_fwd.hpp --
+//
+//            Copyright (c) Darren Garvey 2007.
+// 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_BASIC_CLIENT_FWD_HPP_INCLUDED__
+#define CGI_BASIC_CLIENT_FWD_HPP_INCLUDED__
+
+namespace cgi {
+ namespace common {
+
+  template<typename Connection, typename Protocol>
+  class basic_client;
+
+ } // namespace common
+} // namespace cgi
+
+#endif // CGI_BASIC_CLIENT_FWD_HPP_INCLUDED__
+
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_connection.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_connection.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_connection.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -18,6 +18,7 @@
 //#include "connections/async_stdio_connection_impl.hpp"
 
 namespace cgi {
+ namespace common {
 
   template<typename ConnectionType>
   class basic_connection;
@@ -79,7 +80,7 @@
 //#include "connections/async_stdio_connection.hpp"
 //#include "connections/tcp_connection.hpp"
 
-
+ } // namespace common
 } // namespace cgi
 
 #endif // CGI_BASIC_CONNECTION_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_connection_fwd.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_connection_fwd.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_connection_fwd.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -10,10 +10,12 @@
 #define CGI_BASIC_CONNECTION_FWD_HPP_INCLUDED__
 
 namespace cgi {
+ namespace common {
 
   template<typename ConnectionType>
   class basic_connection;
 
+ } // namespace common
 } // namespace cgi
 
 #endif // CGI_BASIC_CONNECTION_FWD_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_protocol_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_protocol_service.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_protocol_service.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -22,6 +22,7 @@
 #include "boost/cgi/basic_protocol_service_fwd.hpp"
 
 namespace cgi {
+ namespace common {
 
   /// Basic Protocol Service
   /**
@@ -145,6 +146,7 @@
     //friend class request_type;
   };
 
+ } // namespace common
 } // namespace cgi
 
 #endif // CGI_BASIC_PROTOCOL_SERVICE_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_protocol_service_fwd.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_protocol_service_fwd.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_protocol_service_fwd.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -16,6 +16,7 @@
 #include "boost/cgi/io_service_provider.hpp"
 
 namespace cgi {
+ namespace common {
 
   template<
     typename Protocol,
@@ -23,6 +24,7 @@
   >
   class basic_protocol_service;
 
+ } // namespace common
 } // namespace cgi
 
 #endif // CGI_BASIC_PROTOCOL_SERVICE_FWD_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_request.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_request.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_request.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -42,6 +42,7 @@
 #include "boost/cgi/map.hpp"
 
 namespace cgi {
+ namespace common {
 
   /// The basic_request class, primary entry point to the library
   /**
@@ -81,7 +82,7 @@
   public:
     typedef basic_request<RequestService, ProtocolService
                          , Role, Allocator >             type;
-    typedef ::cgi::map                                   map_type;
+    typedef ::cgi::common::map                                   map_type;
     typedef RequestService                               service_type;
     typedef typename service_type::protocol_type         protocol_type;
     typedef ProtocolService                              protocol_service_type;
@@ -221,6 +222,14 @@
                                 , program_status);
     }
 
+    int close(http::status_code http_status
+             , int program_status
+             , boost::system::error_code& ec)
+    {
+      return this->service.close(this->implementation, http_status
+                                , program_status, ec);
+    }
+
     /// Reject the request with a standard '500 Internal Server Error' error
     int reject()
     {
@@ -235,6 +244,14 @@
       this->service.set_status(this->implementation, aborted);
     }
 
+    /// Clear the data for the request, for reusing this object.
+    // I'd imagine clearing and re-loading a request is quicker than 
+    // destroying/re-creating one. **Unverified claims** **FIXME**
+    void clear()
+    {
+      this->service.clear(this->implementation);
+    }
+
     /// Get the client connection associated with the request
     /**
      * You use the client for read/write calls. Y
@@ -632,6 +649,7 @@
     }
   };
 
+ } // namespace common
 } // namespace cgi
 
 #include "boost/cgi/detail/pop_options.hpp"
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_request_acceptor.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_request_acceptor.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_request_acceptor.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -15,9 +15,11 @@
 #include <boost/asio/basic_io_object.hpp>
 #include <boost/asio/ip/basic_endpoint.hpp>
 #include <boost/asio/ip/tcp.hpp>
+#include <boost/cgi/basic_protocol_service.hpp>
 #include "boost/cgi/detail/throw_error.hpp"
 
 namespace cgi {
+ namespace common {
 
   /// The interface class for any *cgi::acceptor.
   template<typename RequestAcceptorService>
@@ -39,18 +41,43 @@
         typename service_type::endpoint_type
     endpoint_type;
     typedef typename service_type::native_type             native_type;
+    typedef
+        typename service_type::service_impl_type::protocol_service_type
+    protocol_service_type;
+    
+
+    //template<typename IoServiceProvider>
+    //explicit basic_request_acceptor(
+    //      basic_protocol_service<protocol_type, IoServiceProvider>& ps)
+    //  : boost::asio::basic_io_object<RequestAcceptorService>(ps.io_service())
+    //{
+    //  this->service.set_protocol_service(this->implementation, ps);
+    //}
 
     template<typename IoServiceProvider>
-    explicit basic_request_acceptor(
-          basic_protocol_service<protocol_type, IoServiceProvider>& ps)
+    explicit basic_request_acceptor
+    (
+        common::basic_protocol_service<protocol_type, IoServiceProvider>& ps
+      , bool default_init = true
+    )
       : boost::asio::basic_io_object<RequestAcceptorService>(ps.io_service())
     {
       this->service.set_protocol_service(this->implementation, ps);
+      if (default_init)
+      {
+        boost::system::error_code ec;
+        this->service.default_init(this->implementation, ec);
+        if (ec)
+        {
+          boost::system::system_error err(ec, "Problem constructing acceptor");
+          boost::throw_exception(err);
+        }
+      }
     }
-
+    
     template<typename IoServiceProvider>
     explicit basic_request_acceptor(
-          basic_protocol_service<protocol_type, IoServiceProvider>& ps,
+          common::basic_protocol_service<protocol_type, IoServiceProvider>& ps,
           port_number_type port_num)
       : boost::asio::basic_io_object<RequestAcceptorService>(ps.io_service())
     {
@@ -77,7 +104,7 @@
 
     template<typename IoServiceProvider, typename InternetProtocol>
     explicit basic_request_acceptor(
-          basic_protocol_service<protocol_type, IoServiceProvider>& ps,
+          common::basic_protocol_service<protocol_type, IoServiceProvider>& ps,
           const boost::asio::ip::basic_endpoint<InternetProtocol>& endpoint,
           bool reuse_addr = true)
       : boost::asio::basic_io_object<RequestAcceptorService>(ps.io_service())
@@ -97,7 +124,7 @@
 
     template<typename IoServiceProvider, typename InternetProtocol>
     explicit basic_request_acceptor(
-          basic_protocol_service<protocol_type, IoServiceProvider>& ps,
+          common::basic_protocol_service<protocol_type, IoServiceProvider>& ps,
           const InternetProtocol& ip,
           const native_type& native_acceptor)
       : boost::asio::basic_io_object<RequestAcceptorService>(ps.io_service())
@@ -112,6 +139,11 @@
     {
     }
 
+    protocol_service_type& protocol_service() const
+    {
+      return this->service.protocol_service(this->implementation);
+    }
+
     /// Check if the acceptor is open
     bool is_open()
     {
@@ -201,17 +233,25 @@
     void accept(CommonGatewayRequest& request)
     {
       boost::system::error_code ec;
-      this->service.accept(this->implementation, request, ec);
+      this->service.accept(this->implementation, request, 0, ec);
       detail::throw_error(ec);
     }
 
     /// Accept one request
     template<typename CommonGatewayRequest>
     boost::system::error_code
-    accept(CommonGatewayRequest& request, boost::system::error_code& ec)
+      accept(CommonGatewayRequest& request, boost::system::error_code& ec)
     {
       //std::cerr<< "mine:::: endpoint.port := " << this->implementation.endpoint_.port() << std::endl;
-      return this->service.accept(this->implementation, request, ec);
+      return this->service.accept(this->implementation, request, 0, ec);
+    }
+
+    template<typename CommonGatewayRequest>
+    boost::system::error_code
+      accept(CommonGatewayRequest& request, endpoint_type& ep
+            , boost::system::error_code& ec)
+    {
+      return this->service.accept(this->implementation, request, &ep, ec);
     }
 
     //template<typename CommonGatewayRequest, typename Endpoint>
@@ -240,6 +280,7 @@
     }
   };
 
+ } // namespace common
 } // namespace cgi
 
 #endif // CGI_BASIC_REQUEST_ACCEPTOR_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_request_fwd.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_request_fwd.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_request_fwd.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -16,6 +16,7 @@
 #include "basic_protocol_service_fwd.hpp"
 
 namespace cgi {
+ namespace common {
 
   template<typename RequestService
           , typename ProtocolService
@@ -23,6 +24,7 @@
           , typename Allocator = std::allocator<char> >
   class basic_request;
 
+ } // namespace common
 } // namespace cgi
 
 #endif // CGI_BASIC_REQUEST_FWD_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_sync_io_object.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_sync_io_object.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/basic_sync_io_object.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -12,6 +12,7 @@
 #include <boost/noncopyable.hpp>
 
 namespace cgi {
+ namespace common {
 
   /// basic_io_object alternative when an io_service isn't used
   template<typename Service>
@@ -19,25 +20,26 @@
     : private boost::noncopyable
   {
   public:
-    typedef Service                        service_type;
-    typedef typename Service::impl_type    impl_type;
+    typedef Service                                  service_type;
+    typedef typename Service::implementation_type    implementation_type;
 
   protected:
     explicit basic_sync_io_object()
     {
       std::cerr<< "Hello";
-      service.construct(impl);
+      service.construct(implementation);
     }
 
     ~basic_sync_io_object()
     {
-      service.destroy(impl);
+      service.destroy(implementation);
     }
 
     service_type service;
-    impl_type impl;
+    implementation_type implementation;
   };
 
+ } // namespace common
 } // namespace cgi
 
 #endif // CGI_BASIC_SYNC_IO_OBJECT_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cgi/request.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cgi/request.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cgi/request.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -20,11 +20,12 @@
 
   class cgi_service_impl;
 
-  typedef basic_request<cgi_request_service, cgi_service> cgi_request;
+  typedef common::basic_request<cgi_request_service, cgi_service> cgi_request;
+  typedef cgi_request request;
 
- namespace cgi {
-   typedef cgi_request request;
- } // namespace cgi
+ //namespace cgi {
+ //  typedef cgi_request request;
+ //} // namespace cgi
 } // namespace cgi
 
 #endif // CGI_CGI_REQUEST_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cgi/request_impl.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cgi/request_impl.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cgi/request_impl.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -38,11 +38,11 @@
    * restricted but if someone really wants to copy the data, then they can.
    */
   class cgi_request_impl
-    : public cgi_request_impl_base<stdio_connection>
+    : public cgi_request_impl_base<common::stdio_connection>
   {
   public:
     //typedef stdio_connection client_type;
-    typedef ::cgi::basic_client<stdio_connection, tags::cgi> client_type;
+    typedef ::cgi::common::basic_client<common::stdio_connection, tags::cgi> client_type;
 
     /// Constructor
     /**
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cgi/request_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cgi/request_service.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cgi/request_service.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -26,7 +26,7 @@
   class cgi_request_service
    : public cgi_service_impl_base<cgi_request_impl>
   {
-    typedef ::cgi::map         map_type;
+    typedef ::cgi::common::map         map_type;
   public:
     typedef cgi_request_impl   impl_type;
     typedef tags::cgi          protocol_type;
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cgi/service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cgi/service.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/cgi/service.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -20,7 +20,7 @@
   /**
    * Works with both cgi_request and acgi_request.
    */
-  typedef basic_protocol_service<tags::acgi> cgi_service;
+  typedef common::basic_protocol_service<tags::acgi> cgi_service;
 
   /// A service 'owned' by a single user-supplied io_service
   //typedef basic_protocol_service<tags::acgi> cgi_sub_service;
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/common/form_part.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/common/form_part.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/common/form_part.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -1,3 +1,6 @@
+#ifndef BOOST_CGI_FORM_PART_HPP_INCLUDED__
+#define BOOST_CGI_FORM_PART_HPP_INCLUDED__
+
 #include <map>
 #include <vector>
 #include <boost/range.hpp>
@@ -34,6 +37,7 @@
      pair_t buffer_;
 
      std::string content_type; // must exist
+     std::string name; // Has to exist?
 
      // Using a simple map while everything is changing. This will not copy the
      // values when it is properly implemented (it'll hold a pair of iterators 
@@ -46,3 +50,6 @@
 
  } // namespace common
 } // namespace cgi
+
+#endif // BOOST_CGI_FORM_PART_HPP_INCLUDED__
+
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/async_stdio.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/async_stdio.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/async_stdio.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -19,6 +19,7 @@
 #include "boost/cgi/tags.hpp"
 
 namespace cgi {
+ namespace common {
 
   // Asynchronous access to stdio
   template<>
@@ -130,6 +131,7 @@
   //  typedef basic_connection<tags::async_cgi, ProtocolService>    type;
   //};
 
+ } // namespace common
 } // namespace cgi
 
 #endif // CGI_ASYNC_STDIO_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/shareable_tcp_socket.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/shareable_tcp_socket.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/shareable_tcp_socket.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -11,9 +11,11 @@
 
 #include <map>
 #include <set>
+#include <boost/asio.hpp>
 #include <boost/cstdint.hpp>
 #include <boost/foreach.hpp>
 #include <boost/shared_ptr.hpp>
+#include <boost/thread.hpp>
 
 #include "boost/cgi/tags.hpp"
 #include "boost/cgi/error.hpp"
@@ -27,6 +29,7 @@
 #include "boost/cgi/detail/protocol_traits.hpp"
 
 namespace cgi {
+ namespace common {
 
   /*** 05.02.2008 :
    *  I'm planning on making this class a more FastCGI-specific one since a
@@ -150,7 +153,7 @@
         return error::duplicate_request;
       }
 
-      if (requests_.size() < (id-1))
+      if (requests_.size() < boost::uint16_t(id-1))
         requests_.resize(id);
 
       return ec;
@@ -193,6 +196,7 @@
     typedef basic_connection<tags::shareable_tcp_socket> shareable_tcp;
   } // namespace connection
 
+ } // namespace common
 } // namespace cgi
 
 #include "boost/cgi/detail/pop_options.hpp"
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/stdio.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/stdio.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/stdio.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -23,6 +23,7 @@
 //#include "boost/cgi/io_service.hpp"
 
 namespace cgi {
+ namespace common {
 
   template<>
   class basic_connection<tags::stdio>
@@ -61,6 +62,11 @@
     std::size_t read_some(MutableBufferSequence buf
                          , boost::system::error_code& ec)
     {
+      if (std::cin.eof())
+      {
+        //ec = boost::asio::error::eof;
+        return boost::asio::error::eof;
+      }
       //if( buf.data() != in_.rdbuf() )
       //  return in_.read(buf.begin(), buf.size());
       //return buf.size();
@@ -92,10 +98,8 @@
          ; i != buf.end(); ++i)
       {
         std::size_t buf_len = boost::asio::buffer_size(*i);
-        std::string s(boost::asio::buffer_cast<const char*>(*i)
-                     , buf_len);
         bytes_transferred += buf_len;
-        std::cout.write(s.c_str(), buf_len);
+        std::cout.write(boost::asio::buffer_cast<const char*>(*i), buf_len);
       }
       return bytes_transferred;
     }
@@ -104,6 +108,13 @@
     bool is_open_;
   };
 
+  namespace connection {
+
+    typedef basic_connection<tags::stdio> stdio;
+
+  } // namespace connection
+
+  // Deprecated
   typedef basic_connection<tags::stdio> stdio_connection;
 
   //  template<typename ProtocolService = detail::cgi_service>
@@ -112,6 +123,7 @@
   //  typedef basic_connection<tags::stdio, ProtocolService>    type;
   //};
 
+ } // namespace common
 } // namespace cgi
 
 #endif // CGI_STDIO_CONNECTION_IMPL_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/tcp_socket.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/tcp_socket.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/connections/tcp_socket.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -19,6 +19,7 @@
 #include "boost/cgi/detail/push_options.hpp"
 
 namespace cgi {
+ namespace common {
 
   template<>
   class basic_connection<tags::tcp_socket>
@@ -95,12 +96,16 @@
     next_layer_type sock_;
   };
 
-  typedef basic_connection<tags::tcp_socket> tcp_connection;
-
   namespace connection {
+
     typedef basic_connection<tags::tcp_socket> tcp;
-  }// namespace connection
 
+  } // namespace connection
+
+  // Deprecated
+  typedef basic_connection<tags::tcp_socket> tcp_connection;
+
+ } // namespace common
 } // namespace cgi
 
 #include "boost/cgi/detail/pop_options.hpp"
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/cgi_request_impl_base.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/cgi_request_impl_base.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/cgi_request_impl_base.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -40,15 +40,17 @@
   class cgi_request_impl_base
   {
   public:
-    typedef ::cgi::map                         map_type;
+    typedef ::cgi::common::map                         map_type;
     typedef Connection                         connection_type;
     typedef 
-      basic_client<Connection, tags::acgi>     client_type;
+      common::basic_client<Connection, tags::acgi>     client_type;
     typedef typename connection_type::pointer  conn_ptr;
 
     /// Constructor
     cgi_request_impl_base()
       : stdin_parsed_(false)
+      , stdin_data_read_(false)
+      , stdin_bytes_left_(-1)
       , http_status_(http::ok)
       , request_status_(unloaded)
     {
@@ -59,12 +61,12 @@
     map_type& post_vars()            { return post_vars_;      }
     map_type& cookie_vars()          { return cookie_vars_;    }
 
-    bool& stdin_parsed()              { return stdin_parsed_;   }
+    bool stdin_parsed()              { return stdin_parsed_;   }
     http::status_code& http_status() { return http_status_;    }
     status_type& status()            { return request_status_; }
 
     conn_ptr& connection()           { return connection_;     }
-    std::string& null_str()          { return null_str_;       }
+    //std::string& null_str()          { return null_str_;       }
 
   protected:
     //conn_ptr connection() { return connection_; }
@@ -76,49 +78,18 @@
     map_type post_vars_;
     map_type cookie_vars_;
 
+  public:
     bool stdin_parsed_;
+    bool stdin_data_read_;
+    std::size_t stdin_bytes_left_;
+  protected:
 
     http::status_code http_status_;
     status_type request_status_;
 
     conn_ptr connection_;
-
-    std::string null_str_;
   };
 
-  //template<> inline const std::string&
-  //cgi_request_impl::var<tags::ENV>(const std::string& name)
-  //{
-  //  return ::getenv(name.c_str());
-  //}
-
-  /// Get a request map of all the environment meta-variables (slow)
-  /**
-   * -- NOT IMPLEMENTED FOR NOW --
-   *
-   * In the case of a CGI request, the environment meta-data is usually stored
-   * in the process environment, which means there is no direct access to all
-   * of them as a map_type&. In other words, this function call will have to
-   * load all of the variables into memory and then return the map
-   */
-  //template<> inline cgi_request_impl::map_type&
-  //cgi_request_impl::var<tags::ENV>()
-  //{
-  //  throw std::logic_error("Can't get all environment vars as a map_type&");
-  //}
-
-  //template<> inline cgi_request_impl::map_type&
-  //cgi_request_impl::var<tags::HTTP>() { return http_map_; }
-
-  //template<> inline cgi_request_impl::map_type&
-  //cgi_request_impl::var<tags::COOKIE>() { return cookie_map_; }
-
-  //template<> inline cgi_request_impl::map_type&
-  //cgi_request_impl::var<tags::GET>() { return get_map_; }
-
-  //template<> inline cgi_request_impl::map_type&
-  //cgi_request_impl::var<tags::POST>() { return post_map_; }
-
 } // namespace cgi
 
 #endif // CGI_CGI_REQUEST_IMPL_BASE_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/cgi_service_impl_base.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/cgi_service_impl_base.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/cgi_service_impl_base.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -22,6 +22,8 @@
 #include "boost/cgi/common/form_part.hpp"
 #include "boost/cgi/detail/throw_error.hpp"
 
+#include "boost/cgi/common/form_parser.hpp"
+
 namespace cgi {
 
  namespace detail {
@@ -38,7 +40,7 @@
   {
   public:
     //typedef RequestImplType     implementation_type;
-    typedef ::cgi::map          map_type;
+    typedef ::cgi::common::map          map_type;
 
     cgi_service_impl_base()
     {
@@ -59,10 +61,11 @@
       //typedef std::list<std::string>::iterator      marker_list_type;
 
       implementation_type()
-        : buffer_()
-        , istream_(&buffer_)
-        , pos_()
+        : //buffer_()
+        //, istream_(&buffer_)
+          pos_()
         , offset_(0)
+        , fp_(NULL)
       {
       }
 
@@ -73,10 +76,10 @@
       //std::vector<char> data_buffer_;
       // The number of characters left to read (ie. "content_length - bytes_read")
       std::size_t characters_left_;
-
+      
       //std::vector<char>::iterator read_pos_;
-      boost::asio::streambuf buffer_;
-      std::istream istream_;
+      //boost::asio::streambuf buffer_;
+      //std::istream istream_;
 
       buffer_type buf_;
       typename buffer_type::iterator pos_;
@@ -84,6 +87,8 @@
       //boost::sub_match<typename buffer_type::iterator> offset_;
       std::vector<common::form_part> form_parts_;
       
+      detail::form_parser* fp_;
+
       /*
       mutable_buffers_type prepare(typename buffer_type::iterator& pos, std::size_t size)
       {
@@ -116,7 +121,7 @@
 
         cerr<< "Pre-read buffer (size: " << buf_.size() 
             << "|capacity: " << buf_.capacity() << ") == {" << endl
-            << std::string(buf_.begin(), buf_.end()) << endl
+            << std::string(buf_.begin() + offset_, buf_.end()) << endl
    //         << "-----end buffer-----" << endl
    //         << "-------buffer-------" << endl
   //          << std::string(&buf_[0], &buf_[buf_.size()]) << endl
@@ -186,6 +191,7 @@
       detail::save_environment(impl.env_vars());
       const std::string& cl = var(impl.env_vars(), "CONTENT_LENGTH", ec);
       impl.characters_left_ = cl.empty() ? 0 : boost::lexical_cast<std::size_t>(cl);
+      impl.client_.bytes_left() = impl.characters_left_;
 
       const std::string& request_method = var(impl.env_vars(), "REQUEST_METHOD", ec);
       if (request_method == "GET")
@@ -198,6 +204,7 @@
 
       parse_cookie_vars(impl, ec);
       impl.status() = loaded;
+
       //BOOST_ASSERT(impl.status() >= loaded);
 
       return ec;
@@ -320,7 +327,7 @@
     {
       //BOOST_ASSERT(impl.status() >= loaded);
       const char* c = ::getenv(name.c_str());
-      return c ? c : impl.null_str();
+      return c ? c : std::string();
     }
 
     map_type&
@@ -422,17 +429,7 @@
       std::string str;
       map_type& post_map(impl.post_vars());
 
-      /* What were these lines here for?
-      const char* a = ::getenv("content_length");
-      if (a) str = a;
-      else throw std::runtime_error("no content-length");
-      */
-
-      //std::cerr<< "content length = ";
-      //var(impl.get_vars(), "CONTENT_LENGTH", ec);
-      //std::cerr.flush();
-
-      while( is.get(ch) )
+      while( is.get(ch) && impl.characters_left_-- )
       {
           //std::cerr<< "; ch=" << ch << "; ";
           switch(ch)
@@ -440,9 +437,10 @@
           case '%': // unencode a hex character sequence
               // note: function params are resolved in an undefined order!
               str += detail::url_decode(is);
+              impl.characters_left_ -= 2; // this is dodgy **FIXME**
               break;
           case '+':
-              str += ' ';
+              str.append(1, ' ');
               break;
           case ' ':
               continue;
@@ -456,7 +454,7 @@
               name.clear();
              break;
           default:
-              str += ch;
+              str.append(1, ch);
           }
       }
       // save the last param (it won't have a trailing &)
@@ -480,7 +478,9 @@
         return boost::system::error_code();
       }
 
-      parse_form_part(impl, ec);
+      do {
+        parse_form_part(impl, ec);
+      }while( !impl.stdin_parsed_  && impl.client_.bytes_left() != 0 );
 
       // Do this just for now, for debugging
       parse_url_encoded_form(impl, ec);
@@ -503,7 +503,6 @@
       std::string regex("^(.*?)" // the data
                         "\\x0D\\x0A" // CR LF
                         "--" "(");
-      //typename implementation_type::form_iterator 
       if (impl.boundary_markers.size() > 1)
       {
         std::list<std::string>::iterator i(impl.boundary_markers.begin());
@@ -519,7 +518,7 @@
         regex += *impl.boundary_markers.begin();
       }
       
-      regex += ")[ ]*\\x0D\\x0A";
+      regex += ")(--)?[ ]*\\x0D\\x0A";
       cerr<< "Regex: " << regex << endl;
       boost::regex re(regex);
       
@@ -535,6 +534,7 @@
       //int runs = 0;
       buffer_iter begin(impl.buf_.begin() + offset);
       buffer_iter end(impl.buf_.end());
+
       for(;;)
       {
         cerr<< "Starting regex_search" << endl;
@@ -568,14 +568,35 @@
              = std::make_pair(matches[1].first, matches[1].second);
             cerr<< "Saved buffer (size: "
                 << std::distance(matches[1].first, matches[1].second)
-                << ")" << endl;
-            //impl.offset_ += 
-            return ec;
+                << ") := { " << impl.form_parts_.back().name << ", " << matches[1] << " }" << endl;
+            impl.post_vars()[impl.form_parts_.back().name] = matches[1];
+            impl.offset_ = offset + matches[0].length();
+            //offset += matches[0].length();
+            impl.pos_ = matches[0].second;
+            cerr<< "offset := " << offset << endl
+                << "impl.offset_ := " << impl.offset_ << endl;
+
+            if (matches[3].matched)
+              impl.stdin_parsed_ = true;
+            //if (impl.client_.bytes_left() == 0)
+            //{
+            //  cerr<< "Read all the bytes up." << endl;
+              //impl.stdin_parsed_ = true;
+              return ec;
+            //}
           }
           else
           {
             cerr<< "Reading more data." << endl;
-            std::size_t bytes_read = impl.client_.read_some(impl.prepare(32), ec);
+            std::size_t bytes_read = impl.client_.read_some(impl.prepare(64), ec);
+            //impl.stdin_bytes_read_ += bytes_read;
+            
+            if (bytes_read == 0)
+            {
+              impl.stdin_data_read_ = true;
+              return ec;
+            }
+
             begin = impl.buf_.begin() + offset;
             end = impl.buf_.end();
             cerr<< "Buffer (+" << bytes_read << ") == {" << endl
@@ -600,29 +621,52 @@
     boost::system::error_code
       parse_form_part_meta_data(implementation_type& impl, boost::system::error_code& ec)
     {
-      boost::regex re(//"(?:.*?)?"
-                      "^(?:"//\\x0D\\x0A"         // start of the line
-                        "(?:"         // [IGNORE] the line may be empty, as meta-data is optional
+      // Oh dear this is ugly. The move to Boost.Spirit will have to be sooner than planned.
+      // (it's a nested, recursive pattern, which regexes don't suit, apparently)
+      boost::regex re(  "(?:"         // [IGNORE] the line may be empty, as meta-data is optional
+                          "^"
+                          "([-\\w]+)" // name
+                          ":[ ^]*"       // separator
+                          "([-/\\w]+)" // optional(?) value
+                          ""
+                          "(?:"
+                            ";"
+                            "[ ]*"    // additional name/value pairs (don't capture)
+                            "([-\\w]+)" // name
+                            "[ \\x0D\\x0A]*=[ \\x0D\\x0A]*"       // separator
+                            "(?:\"?([-.\\w]*)\"?)" // value may be empty
+                          ")?"
+                          "(?:"
+                            ";"
+                            "[ ]*"    // additional name/value pairs (don't capture)
+                            "([-\\w]+)" // name
+                            "[ \\x0D\\x0A]*=[ \\x0D\\x0A]*"       // separator
+                            "(?:\"?([-.\\w]*)\"?)" // value may be empty
+                          ")?"        // mark the extra n/v pairs optional
+                          "\\x0D\\x0A"
+                        ")"
+                        "(?:"
                           "([-\\w]+)" // name
                           ":[ ^]*"       // separator
-                          "([-\\w]+)" // optional(?) value
-                          
+                          "([-/\\w]+)" // optional(?) value
+                          ""
                           "(?:"
                             ";"
-                            "[ \\x0D\\x0A]*"    // additional name/value pairs (don't capture)
+                            "[ ]*"    // additional name/value pairs (don't capture)
                             "([-\\w]+)" // name
                             "[ \\x0D\\x0A]*=[ \\x0D\\x0A]*"       // separator
-                            //"(?"
-                            //  "(?=\")([^\"]+)\"" // value (delimited; any character)
-                            //"|"
-                            //  "([-\\w]+)"  // value (7-bit ASCII only)
-                            "(?:\"?([-\\w]+)\"?)"
-                            //")"
-                          ")*"        // mark the extra n/v pairs optional
-                        ")*" 
-                        ")?"
-                        //"|(\\x0D\\x0A)"
-                      "\\x0D\\x0A");       // followed by the end of the line
+                            "(?:\"?([-.\\w]*)\"?)" // value may be empty
+                          ")?"
+                          "(?:"
+                            ";"
+                            "[ ]*"    // additional name/value pairs (don't capture)
+                            "([-\\w]+)" // name
+                            "[ \\x0D\\x0A]*=[ \\x0D\\x0A]*"       // separator
+                            "(?:\"?([-.\\w]*)\"?)" // value may be empty
+                          ")?"        // mark the extra n/v pairs optional
+                          "\\x0D\\x0A"    // followed by the end of the line
+                        ")?" 
+                      "(\\x0D\\x0A)");     // followed by the 'header termination' line
 
       typedef typename
         implementation_type::buffer_type::iterator
@@ -633,77 +677,78 @@
           implementation_type::buffer_type::iterator
       > matches;
       
-      //impl.buf_.clear();
-      //typename implementation_type::buffer_type::difference_type
-      std::size_t offset = impl.offset_;//std::difference(impl.buf_.begin(), impl.pos_);
+      std::size_t offset = impl.offset_;
       cerr.flush();
       impl.pos_ = impl.buf_.begin();
-      //buffer_iter begin(impl.pos_);
       int runs = 0;
       cerr<< "Entering for() loop." << endl;
       std::size_t bytes_read = 0;
       for(;;)
       {
-        buffer_iter begin(impl.buf_.begin() + offset);//impl.pos_);// + offset);//
+        buffer_iter begin(impl.buf_.begin() + offset);
         buffer_iter end(impl.buf_.end());
+        
         if (!boost::regex_search(begin, end, matches, re
                                 , boost::match_default | boost::match_partial))
         {
           cerr<< "No chance of a match, quitting." << endl;
+          impl.stdin_parsed_ = true;
           return ec;
         }
         cerr<< "matches.str() == {" << endl
             << matches.str() << endl
-            << "}" << endl;
+            << "}" << endl
+            << matches.size() << " submatches" << endl;
+        for (unsigned i = matches.size(); i != 0; --i)
+        {
+          cerr<< "match[" << i << "] := { " << matches[i] << " }" << endl;
+        }
         if (matches[0].matched)
         {
-          //cerr<< "matches[0].length() == " << matches[0].length() << endl;
-          if (0 == matches[1].length())
-          { // empty line: terminate headers
-            cerr<< "Headers terminated." << endl;
-            impl.offset_ = offset + matches[0].length();
-            impl.pos_ = matches[0].second;
-            cerr<< "Current buffer == {" << endl
-                << impl.buffer_string() << endl
-                << "}" << endl;
-            cerr<< "Leaving parse_form_part_meta_data()" << endl;
-            return ec;
-          }
-          // else we have a match for a header line
-          cerr<< "Parsing form part meta-data." << endl;
-              //<< "matches.size() == " << matches.size() << endl;
           common::form_part part;
-          for (unsigned int i = 1; i < matches.size(); i+=2)
+          for ( unsigned int i = 1
+              ; i < matches.size() 
+               && matches[i].matched
+               && !matches[i].str().empty()
+              ; i+=2)
           {
-            // We need to ignore matches[0] : the complete string
-            // Ignore last match, which is the header terminator
-            /*
-            if (matches[i].length())
+           if (matches[i].str() == "name")
             {
-              cerr<< "[" << i << "] == {" << endl
-                  << matches[i] << endl
-                  << "}" << endl;
+              part.name = matches[i+1];
+              cerr<< "Saved name" << endl;
             }
-            */
-          //if (matches[i].str() == "Content-type
-          part.meta_data_[matches[i]] //= matches[2].str();
-            = std::make_pair(matches[i+1].first, matches[i+1].second);
-          cerr<< "Part := { " << matches[i] << ", " << matches[i+1] << " }" << endl;
-            //= boost::iterator_range<buffer_iter>(matches[3].first, matches[3].second);
-          }
-          impl.form_parts_.push_back(part);
-          //cerr<< "Added meta data to form_part list (size: "
-          //    << impl.form_parts_.size() << "| elements: "
-          //    << impl.form_parts_.back().meta_data_.size() << ")" << endl;
+            else
+            {
+              part.meta_data_[matches[i]]
+                = std::make_pair(matches[i+1].first, matches[i+1].second);
+              cerr<< "Part := { " << matches[i] << ", " << matches[i+1] << " }" << endl;
+              //= boost::iterator_range<buffer_iter>(matches[3].first, matches[3].second);
+            }
+            impl.form_parts_.push_back(part);
           
-
-          offset += matches[0].length();
-          impl.pos_ = matches[0].second;
-          //break;
-  
+          
+         }
+          
+         if (matches[13].str() == "\r\n")
+         {
+           impl.offset_ = offset + matches[0].length();
+           offset += matches[0].length();
+           impl.pos_ = matches[0].second;
+          
+           //cerr<< "Current buffer == {" << endl
+           //    << impl.buffer_string() << endl
+           //    << "}" << endl;
+           cerr<< "Leaving parse_form_part_meta_data()" << endl;
+           return ec;
+         }
+         else
+         {
+           throw std::runtime_error("Invalid POST data (header wasn't terminated as expected)");
+         }
+         
         }else{
           cerr<< "Not read enough data yet, reading more." << endl;
-          bytes_read = impl.client_.read_some(impl.prepare(32), ec);
+          bytes_read = impl.client_.read_some(impl.prepare(64), ec);
           if (ec)
           {
             cerr<< "Error reading data: " << ec.message() << endl;
@@ -712,7 +757,7 @@
           }
           cerr<< "Read " << bytes_read << " bytes." << endl;
           cerr<< "buffer = {" << endl
-              << std::string(impl.buf_.begin(), impl.buf_.end()) << endl
+              << impl.buffer_string() << endl
               << "} or {" << endl;
               //<< std::string(impl.pos_, ;
           /*
@@ -730,8 +775,11 @@
               << "----------------" << endl;
           */
           //offset = impl.buf_.end();
-            if (++runs > 20)
+            if (++runs > 40)
+            {
+              cerr<< "Run 40 times; bailing out." << endl;
               break;
+            }
           cerr<< "Waiting buffer (unparsed) == {" << endl << std::flush
               << impl.buffer_string() << endl
               << "}" << endl
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/protocol_traits.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/protocol_traits.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/detail/protocol_traits.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -89,12 +89,12 @@
       typedef protocol_traits<tags::cgi>             type;
       typedef cgi_request_impl                       impl_type;
       typedef cgi_request_service                    request_service_impl;
-      typedef basic_protocol_service<tags::cgi>      protocol_service_type;
-      typedef basic_request<
+      typedef common::basic_protocol_service<tags::cgi>      protocol_service_type;
+      typedef common::basic_request<
         request_service_impl, protocol_service_type
       >                                              request_type; 
       typedef cgi_service_impl                       service_impl_type;
-      typedef basic_connection<tags::stdio>          connection_type;
+      typedef common::basic_connection<tags::stdio>          connection_type;
 //    typedef cgi_gateway_impl                       gateway_impl_type;
 //    typedef cgi_gateway_service                    gateway_service_impl_type;
     };
@@ -105,12 +105,12 @@
       typedef protocol_traits<tags::async_cgi>       type;
       typedef async_cgi_request_impl                 impl_type;
       typedef acgi_request_service                   request_service_impl;
-      typedef basic_protocol_service<tags::acgi>     protocol_service_type;
-      typedef basic_request<
+      typedef common::basic_protocol_service<tags::acgi>     protocol_service_type;
+      typedef common::basic_request<
         request_service_impl, protocol_service_type
       >                                              request_type; 
       typedef async_cgi_service_impl                 service_impl_type;
-      typedef basic_connection<tags::async_stdio>    connection_type;
+      typedef common::basic_connection<tags::async_stdio>    connection_type;
       typedef async_cgi_gateway_impl                 gateway_impl_type;
       typedef async_cgi_gateway_service              gateway_service_type;
     };
@@ -122,12 +122,12 @@
       typedef protocol_traits<tags::acgi>            type;
       typedef acgi_request_impl                      impl_type;
       typedef acgi_request_service                   request_service_impl;
-      typedef basic_protocol_service<tags::acgi>     protocol_service_type;
-      typedef basic_request<
+      typedef common::basic_protocol_service<tags::acgi>     protocol_service_type;
+      typedef common::basic_request<
         request_service_impl, protocol_service_type
       >                                              request_type; 
       typedef acgi_service_impl                      service_impl_type;
-      typedef basic_connection<tags::async_stdio>    connection_type;
+      typedef common::basic_connection<tags::async_stdio>    connection_type;
       typedef acgi_gateway_impl                      gateway_impl_type;
       typedef acgi_gateway_service                   gateway_service_type;
     };
@@ -138,8 +138,8 @@
       typedef protocol_traits<tags::fcgi>            type;
       typedef fcgi::fcgi_request_impl                impl_type;
       typedef fcgi::fcgi_request_service             request_service_impl;
-      typedef basic_protocol_service<fcgi_>          protocol_service_type;
-      typedef basic_request<
+      typedef common::basic_protocol_service<fcgi_>          protocol_service_type;
+      typedef common::basic_request<
         request_service_impl, protocol_service_type
       >                                              request_type; 
       typedef boost::shared_ptr<request_type>        request_ptr;
@@ -147,7 +147,7 @@
       //        ::implementation_type                  request_impl_type;
       typedef fcgi::fcgi_service_impl                service_impl_type;
       typedef fcgi::fcgi_acceptor_service            acceptor_service_impl;
-      typedef basic_connection<
+      typedef common::basic_connection<
         tags::shareable_tcp_socket
       >                                              connection_type;
       //typedef fcgi_gateway_impl                      gateway_impl_type;
@@ -160,13 +160,13 @@
       typedef protocol_traits<tags::scgi>            type;
       typedef scgi::scgi_request_impl                impl_type;
       typedef scgi::scgi_request_service             request_service_impl;
-      typedef basic_protocol_service<tags::scgi>     protocol_service_type;
-      typedef basic_request<
+      typedef common::basic_protocol_service<tags::scgi>     protocol_service_type;
+      typedef common::basic_request<
         request_service_impl, protocol_service_type
       >                                              request_type; 
       typedef scgi::scgi_service_impl                service_impl_type;
       typedef scgi::scgi_acceptor_service            acceptor_service_impl;
-      typedef basic_connection<tags::tcp_socket>     connection_type;
+      typedef common::basic_connection<tags::tcp_socket>     connection_type;
       //typedef scgi_gateway_impl                      gateway_impl_type;
       //typedef scgi_gateway_service                   gateway_service_type;
     };
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/error.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/error.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/error.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -44,7 +44,13 @@
   // themselves. This is an ugly hack.
   multiplexed_request_incoming,
 
-  duplicate_request
+  duplicate_request,
+
+  // Calling async_accept on a request that hasn't been closed isn't
+  // allowed.
+  accepting_on_an_open_request,
+
+  invalid_socket
 };
 
   namespace detail {
@@ -63,8 +69,10 @@
     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.";
     default:
-      return "BOOM!!!";
+      return "(FastCGI) BOOM!!!";
     }
   }
 };
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/acceptor.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/acceptor.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/acceptor.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -16,7 +16,11 @@
  namespace fcgi {
 
    /// Typedef for common usage (FCGI)
-   typedef basic_request_acceptor<fcgi_request_acceptor_service<> > acceptor;
+   typedef
+     ::cgi::common::basic_request_acceptor<
+       fcgi_request_acceptor_service<>
+     >
+   acceptor;
 
  } // namespace fcgi
 } // namespace cgi
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/acceptor_service_impl.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/acceptor_service_impl.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/acceptor_service_impl.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -87,7 +87,9 @@
      struct implementation_type
      {
        typedef Protocol_                             protocol_type;
-       typedef basic_protocol_service<protocol_type> protocol_service_type;
+       typedef common::basic_protocol_service<
+                 protocol_type
+               >                                     protocol_service_type;
        typedef boost::asio::ip::tcp                  native_protocol_type;
        typedef fcgi::request                         request_type;
        typedef boost::asio::socket_acceptor_service<
@@ -121,6 +123,9 @@
                                                          native_protocol_type;
      typedef typename
        acceptor_service_type::native_type                native_type;
+
+     typedef typename 
+       type::implementation_type::endpoint_type          endpoint_type;
  
 
      explicit acceptor_service_impl(::cgi::io_service& ios)
@@ -130,6 +135,39 @@
      {
      }
  
+     protocol_service_type&
+       service(implementation_type const& impl) const
+     {
+       return *impl.service_;
+     }
+
+     /// Default-initialize the acceptor.
+     boost::system::error_code
+       default_init(implementation_type& impl, boost::system::error_code& ec)
+     {
+#if ! defined(BOOST_WINDOWS)
+       //assign(impl.acceptor_, , 0, ec);
+       return acceptor_service_.assign(impl.acceptor_, boost::asio::ip::tcp::v4()
+                                      , 0, ec);
+ #else
+//#      error "Windows isn't supported at the moment"
+       HANDLE hListen = INVALID_HANDLE_VALUE;
+       boost::asio::detail::socket_type sock;
+       struct sockaddr sa;
+       int sa_len = sizeof(sa);
+#if NO_WSAACCEPT
+       sock = accept((boost::asio::detail::socket_type)hListen, &sa, &sa_len);
+       if (sock == INVALID_SOCKET)
+         return cgi::error::invalid_socket;
+#else
+       sock = WSAAccept((unsigned int)hListen, &sa, &sa_len, NULL, (DWORD)NULL);
+       if (sock == INVALID_SOCKET)
+         return ::cgi::error::invalid_socket;
+#endif
+#endif
+       return ec;
+     }
+
      void set_protocol_service(implementation_type& impl
                               , protocol_service_type& ps)
      {
@@ -205,7 +243,7 @@
      template<typename CommonGatewayRequest>
      boost::system::error_code
        accept(implementation_type& impl, CommonGatewayRequest& request
-             , boost::system::error_code& ec)
+             , endpoint_type* endpoint, boost::system::error_code& ec)
      {
        /* THIS BIT IS BROKEN:
         *-- The noncopyable semantics of a basic_request<> don't allow the
@@ -227,36 +265,24 @@
          }
        }
        */
-       return acceptor_service_.accept(impl.acceptor_,
-                request.client().connection()->next_layer(), 0, ec);
-     }
- 
-     /// Accepts one request.
-     template<typename CommonGatewayRequest, typename Endpoint>
-     boost::system::error_code
-       accept(implementation_type& impl, CommonGatewayRequest& request
-             , Endpoint* endpoint, boost::system::error_code& ec)
-     {
-       /* THIS BIT IS BROKEN:
-        *-- The noncopyable semantics of a basic_request<> don't allow the
-            assignment. There are a couple of ways around this; the one that
-            seems sensible is to keep the basic_request<>s noncopyable, but
-            allow the actual data be copied. At the moment the actual data is
-            held in a vector<string> headers container and a cgi::streambuf.
-            These two bits should really be factored out into a message type.
-            IOW, the message type will be copyable (but should probably have
-            unique-ownership semantics).
-        --*
+
+       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())
        {
-         boost::mutex::scoped_lock lk(impl.mutex_);
-         if (!impl.waiting_requests_.empty())
-         {
-           request = *(impl.waiting_requests_.front());
-           impl.waiting_requests_.pop();
-           return ec;
-         }
+         request.clear();
        }
-       */
+
+       // If we can reuse this request's connection, return.
+       if (request.client().keep_connection())
+         return ec;
+
+       // ...otherwise accept a new connection.
        return acceptor_service_.accept(impl.acceptor_,
                 request.client().connection()->next_layer(), endpoint, ec);
      }
@@ -314,7 +340,24 @@
          }
        }
        */
-       acceptor_service_.async_accept(impl.acceptor_,
+
+       // We can't call accept on an open request (close it first).
+       if (request.is_open())
+         return handler(error::accepting_on_an_open_request);
+
+       // 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();
+       }
+
+       // If we can reuse this request's connection, return.
+       if (request.client().keep_connection())
+         return handler(boost::system::error_code());
+
+       // ...otherwise accept a new connection (asynchronously).
+       return acceptor_service_.async_accept(impl.acceptor_,
          request.client().connection()->next_layer(), 0, handler);
      }
  
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/client.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/client.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/client.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -27,6 +27,7 @@
 #include "boost/cgi/basic_request_fwd.hpp"
 //#error BOOST_HAS_RVALUE_REFS
 namespace cgi {
+ namespace common {
 
   enum client_status
   {
@@ -41,13 +42,13 @@
 
   /// A client that uses a TCP socket that owned by it.
   template<typename Protocol>
-  class basic_client<shareable_tcp_connection, Protocol>
+  class basic_client<common::shareable_tcp_connection, Protocol>
   {
   public:
     typedef ::cgi::io_service                 io_service_type;
-    typedef ::cgi::map                        map_type;
+    typedef ::cgi::common::map                map_type;
     typedef Protocol                          protocol_type;
-    typedef shareable_tcp_connection          connection_type;
+    typedef common::shareable_tcp_connection  connection_type;
     //typedef detail::protocol_traits<
     //  fcgi_
     //>::request_impl_type                      request_impl_type;
@@ -65,6 +66,7 @@
     basic_client()
       : request_id_(-1)
       , status_(none_)
+      , keep_connection_(false)
     {
     }
 
@@ -72,6 +74,7 @@
     basic_client(io_service_type& ios)
       : request_id_(-1)
       , status_(none_)
+      , keep_connection_(false)
       //, io_service_(ios)
       //, connection_(new connection_type::pointer(ios))
     {
@@ -107,13 +110,21 @@
 
     void close(boost::uint64_t app_status = 0)
     {
-      if (status_ == closed_) return;
+      boost::system::error_code ec;
+      close(app_status, ec);
+      detail::throw_error(ec);
+    }
+
+    boost::system::error_code
+      close(boost::uint64_t app_status, boost::system::error_code& ec)
+    {
+      if (status_ == closed_) return ec;
 
       std::vector<boost::asio::const_buffer> bufs;
 
       // Write an EndRequest packet to the server.
       out_header_[0] = static_cast<unsigned char>(1); // FastCGI version
-      out_header_[1] = static_cast<unsigned char>(3); // BEGIN_REQUEST
+      out_header_[1] = static_cast<unsigned char>(3); // END_REQUEST
       out_header_[2] = static_cast<unsigned char>(request_id_ >> 8) & 0xff;
       out_header_[3] = static_cast<unsigned char>(request_id_) & 0xff;
       out_header_[4] = static_cast<unsigned char>(8 >> 8) & 0xff;
@@ -121,8 +132,8 @@
       out_header_[6] = static_cast<unsigned char>(0);
       out_header_[7] = 0;
 
-      BOOST_ASSERT(role_ == fcgi::spec_detail::RESPONDER
-                   && "Only supports Responder role for now (**FIXME**)");
+      //BOOST_ASSERT(role_ == fcgi::spec_detail::RESPONDER
+      //             && "Only supports Responder role for now (**FIXME**)");
 
       header_buffer_type end_request_body =
       {{
@@ -139,10 +150,12 @@
       bufs.push_back(buffer(out_header_));
       bufs.push_back(buffer(end_request_body));
 
-      write(*connection_, bufs);
+      write(*connection_, bufs, boost::asio::transfer_all(), ec);
 
-      if (!keep_connection_ && connection_)
+      if (!keep_connection_)
         connection_->close();
+
+      return ec;
     }
 
     //io_service_type& io_service() { return io_service_; }
@@ -236,6 +249,11 @@
       return status_;
     }
 
+    bool keep_connection() const
+    {
+      return keep_connection_;
+    }
+
   public:
     friend class fcgi_request_service;
     boost::uint16_t request_id_;
@@ -268,8 +286,14 @@
 
 //#include "boost/cgi/fcgi/client_fwd.hpp"
 
+ } // namespace common
+
 namespace fcgi {
-    typedef basic_client<shareable_tcp_connection, ::cgi::fcgi_> client;
+    typedef
+      common::basic_client<
+        common::shareable_tcp_connection, ::cgi::fcgi_
+      >
+    client;
 } // namespace fcgi
 
 
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/request.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/request.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/request.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -16,10 +16,15 @@
 #include "boost/cgi/fcgi/request_service.hpp"
 
 namespace cgi {
-
  namespace fcgi {
+   
    // typedef for typical usage (FCGI)
-   typedef basic_request<fcgi_request_service, service> request;
+   typedef
+     ::cgi::common::basic_request<
+        fcgi_request_service, service
+     >
+   request;
+
  } // namespace fcgi
 } // namespace cgi
 
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/request_acceptor_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/request_acceptor_service.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/request_acceptor_service.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -69,6 +69,18 @@
       service_impl_.shutdown_service();
     }
 
+    service_impl_type::protocol_service_type&
+      protocol_service(implementation_type const& impl) const
+    {
+      return service_impl_.service(impl);
+    }
+
+    boost::system::error_code
+      default_init(implementation_type& impl, boost::system::error_code& ec)
+    {
+      return service_impl_.default_init(impl, ec);
+    }
+
     bool is_open(implementation_type& impl)
     {
       return service_impl_.is_open(impl);
@@ -109,18 +121,18 @@
       return service_impl_.listen(impl, backlog, ec);
     }
 
-    template<typename CommonGatewayRequest>
-    boost::system::error_code
-      accept(implementation_type& impl, CommonGatewayRequest& request
-            , boost::system::error_code& ec)
-    {
-      return service_impl_.accept(impl, request, ec);
-    }
+//    template<typename CommonGatewayRequest>
+//    boost::system::error_code
+//      accept(implementation_type& impl, CommonGatewayRequest& request
+//            , boost::system::error_code& ec)
+//    {
+//      return service_impl_.accept(impl, request, NULL, ec);
+//    }
 
-    template<typename CommonGatewayRequest, typename Endpoint>
+    template<typename CommonGatewayRequest>
     boost::system::error_code
       accept(implementation_type& impl, CommonGatewayRequest& request
-            , Endpoint* ep, boost::system::error_code& ec)
+            , endpoint_type * ep, boost::system::error_code& ec)
     {
       return service_impl_.accept(impl, request, ep, ec);
     }
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/service.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/service.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -19,7 +19,7 @@
  namespace fcgi {
 
    // typedef for standard scgi::service (a model of ProtocolService)
-   typedef basic_protocol_service< ::cgi::fcgi_> service;
+   typedef ::cgi::common::basic_protocol_service< ::cgi::fcgi_> service;
 
  }
 } // namespace cgi
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/specification.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/specification.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/fcgi/specification.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -9,7 +9,7 @@
 #ifndef CGI_FCGI_SPECIFICATION_HPP_INCLUDED__
 #define CGI_FCGI_SPECIFICATION_HPP_INCLUDED__
 
-#include <inttypes.h>
+//#include <inttypes.h>
 #include <boost/cstdint.hpp>
 
 // NOTE: CamelCase style mimicks the FastCGI specification
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/io_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/io_service.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/io_service.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -16,9 +16,15 @@
 #include <boost/asio/io_service.hpp>
 
 namespace cgi {
+ namespace common {
 
   using boost::asio::io_service;
 
+ } // namespace common
+
+  // This should go?
+  using boost::asio::io_service;
+
 } // namespace cgi
 
 #endif // CGI_IO_SERVICE_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/map.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/map.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/map.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -13,9 +13,11 @@
 #include <string>
 
 namespace cgi {
+ namespace common {
 
   typedef std::map<std::string,std::string>    map;
 
+ } // namespace common
 } // namespace cgi
 
 #endif // CGI_MAP_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/read.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/read.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/read.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -12,10 +12,12 @@
 #include <boost/asio/read.hpp>
 
 namespace cgi {
+ namespace common {
 
   using boost::asio::read;
   using boost::asio::async_read;
 
+ } // namespace common
 } // namespace cgi
 
 #endif // CGI_READ_HPP_INCLUDED
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/request_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/request_service.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/request_service.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -21,6 +21,7 @@
 //#include "service_selector.hpp"
 
 namespace cgi {
+ namespace common {
 
   /// The generic service class for basic_request<>s
   /**
@@ -43,7 +44,7 @@
     typedef typename 
       service_impl_type::implementation_type          implementation_type;
     typedef Protocol                                  protocol_type;
-    typedef basic_protocol_service<Protocol>  protocol_service_type;
+    typedef common::basic_protocol_service<Protocol>  protocol_service_type;
 
     /// The unique service identifier
     //static boost::asio::io_service::id id;
@@ -159,6 +160,7 @@
     service_impl_type& service_impl_;
   };
 
+ } // namespace common
 } // namespace cgi
 
 #include "boost/cgi/detail/pop_options.hpp"
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/response.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/response.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/response.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -14,6 +14,9 @@
 #include <string>
 #include <fstream> // only for testing
 
+#include <boost/foreach.hpp>
+#include <boost/bind.hpp>
+
 //#include "boost/cgi/request_ostream.hpp"
 #include "boost/cgi/buffer.hpp"
 #include "boost/cgi/cookie.hpp"
@@ -22,7 +25,7 @@
 #include "boost/cgi/basic_request_fwd.hpp"
 #include "boost/cgi/http/status_code.hpp"
 #include "boost/cgi/streambuf.hpp"
-#include <boost/foreach.hpp>
+#include "boost/cgi/detail/throw_error.hpp"
 
 /// This mess outputs a default Content-type header if the user hasn't set any.
 /** **FIXME** Not implemented; not sure if it should be...
@@ -54,6 +57,7 @@
 
 
 namespace cgi {
+ namespace common {
 
   /// The response class: a helper for responding to requests.
   class response
@@ -90,6 +94,7 @@
     {
       ostream_.clear();
       headers_.clear();
+      headers_terminated_ = false;
     }
 
     /// Return the response to the 'just constructed' state.
@@ -150,7 +155,8 @@
           return ec;
       }
 
-      std::size_t bytes_written = common::write(sws, buffer_->data(), ec);
+      std::size_t bytes_written
+        = common::write(sws, buffer_->data(), boost::asio::transfer_all(), ec);
       if (!ec)
         buffer_->consume(bytes_written);
 
@@ -178,18 +184,21 @@
      * object.
      */
     template<typename SyncWriteStream>
-    boost::system::error_code&
+    boost::system::error_code
       send(SyncWriteStream& sws, boost::system::error_code& ec)
     {
       if (!headers_terminated_)
       {
-        //BOOST_FOREACH(headers_.begin(), headers_.end()
-        //             , headers.push_back(::cgi::buffer(*_1)));
+        /* Not sure if streambuf allows this
+         *
+        // We want to be able to keep adding to a response, calling send() on
+        // it whenever, without resending the headers. Call resend() if you
+        // want to send the whole response again.
+        headers_terminated_ = true;
+         */
         std::vector<boost::asio::const_buffer> headers;
         prepare_headers(headers);//, ec)
-        if (common::write(sws, headers, boost::asio::transfer_all(), ec))
-          std::cerr<< "Broken." << std::endl;
-          //return ec;
+        common::write(sws, headers, boost::asio::transfer_all(), ec);
       }
 
       common::write(sws, buffer_->data(), boost::asio::transfer_all(), ec);
@@ -197,6 +206,17 @@
       return ec;
     }
 
+    /// Resend headers + content regardless of value of `headers_terminated_`.
+    template<typename SyncWriteStream>
+    void resend(SyncWriteStream& sws)
+    {
+      std::vector<boost::asio::const_buffer> headers;
+      prepare_headers(headers);//, ec)
+      common::write(sws, headers);
+
+      common::write(sws, buffer_->data());
+    }
+
     /// Asynchronously send the data through the supplied request
     /**
      * Note: This is quite crude at the moment and not as asynchronous as
@@ -242,11 +262,6 @@
     }
 
     /// Get the status code associated with the response.
-    http::status_code& get_status()
-    {
-      return http_status_;
-    }
-
     http::status_code& status()
     {
       return http_status_;
@@ -300,7 +315,8 @@
     // Vector of all the headers, each followed by a CRLF
     std::vector<std::string> headers_;
 
-    boost::shared_ptr<common::streambuf> buffer_; // maybe scoped_ptr?
+    // The buffer is a shared_ptr, so you can keep it cached elsewhere.
+    boost::shared_ptr<common::streambuf> buffer_;
 
     ostream_type ostream_;
 
@@ -312,6 +328,9 @@
     template<typename T>
     friend response& operator<<(response& resp, const T& t);
 
+    //template<typename A, typename B>
+    //friend A& operator<<(A& resp, B b);
+
   private:
 
     // Send the response headers and mark that they've been sent.
@@ -378,7 +397,7 @@
   }*/
 
   template<>
-  response& operator<<(response& resp, const ::cgi::header& hdr)
+  response& operator<<(response& resp, const ::cgi::common::header& hdr)
   {
     if (hdr.content.empty()) {
       resp.headers_terminated_ = true;
@@ -417,6 +436,7 @@
     return resp.set_status(status);
   }
 
+ } // namespace common
 } // namespace cgi
 
 #undef BOOST_CGI_ADD_DEFAULT_HEADER
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/write.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/write.hpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/boost/cgi/write.hpp	2008-03-21 12:49:08 EDT (Fri, 21 Mar 2008)
@@ -19,8 +19,8 @@
 
  } // namespace common
 
-  using common::write;
-  using common::async_write;
+  //using common::write;
+  //using common::async_write;
 
 } // namespace cgi