diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-01-02 16:13:15 +0100 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-01-02 16:13:15 +0100 |
commit | 4a0d339854536f65b9418c79b617bb718062905f (patch) | |
tree | c7b80fee61114197269beb37af7dc345c81336db /http_connection.h | |
parent | 1ec379a805fdc4e7e076f1f59fa054bde8cf89c2 (diff) |
Decoupled HTTP::Connection from handler.
Diffstat (limited to 'http_connection.h')
-rw-r--r-- | http_connection.h | 30 |
1 files changed, 17 insertions, 13 deletions
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 <string> -#include <vector> +#include <list> #include <map> #include <boost/asio.hpp> #include <boost/enable_shared_from_this.hpp> using boost::asio::ip::tcp; +#include <boost/function.hpp> + namespace HTTP { class Connection : public boost::enable_shared_from_this<Connection> { 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<Connection> p; + typedef boost::function<void (Connection::p)> Handler; - void start(); + void read_request(Handler callback); //! Request method. std::string method; @@ -42,9 +35,20 @@ namespace HTTP { //! Request headers. std::map<std::string, std::string> 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 |