From 4a0d339854536f65b9418c79b617bb718062905f Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sun, 2 Jan 2011 16:13:15 +0100 Subject: Decoupled HTTP::Connection from handler. --- http_connection.h | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'http_connection.h') diff --git a/http_connection.h b/http_connection.h index 8322721..9ceb8a5 100644 --- a/http_connection.h +++ b/http_connection.h @@ -2,31 +2,24 @@ #define HTTP_CONNECTION_H #include -#include +#include #include #include #include using boost::asio::ip::tcp; +#include + namespace HTTP { class Connection : public boost::enable_shared_from_this { friend class Server; - private: - Connection(boost::asio::io_service& io_service); - void handle_write(const boost::system::error_code& error, size_t bytes_transferred); - void handle_read(const boost::system::error_code& error, size_t bytes_transferred); - tcp::socket socket; - boost::asio::streambuf buf; - - //! Parse request headers. - bool parse_request(boost::asio::streambuf& buf); - public: typedef boost::shared_ptr p; + typedef boost::function Handler; - void start(); + void read_request(Handler callback); //! Request method. std::string method; @@ -42,9 +35,20 @@ namespace HTTP { //! Request headers. std::map headers; + + tcp::socket socket; + private: + Connection(boost::asio::io_service& io_service); + void handle_write(const boost::system::error_code& error, size_t bytes_transferred); + void handle_read(const boost::system::error_code& error, size_t bytes_transferred, Handler callback); - static void foo_handler(Connection::p connection); + boost::asio::streambuf buf; + + //! Parse request headers. + bool parse_request(boost::asio::streambuf& buf); }; + + typedef Connection::Handler Handler; }; #endif -- cgit v1.2.3