summaryrefslogtreecommitdiff
path: root/httpd.h
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-12-29 22:08:06 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-12-29 22:08:06 +0100
commit5d94fe647e59aaec7775f1e1bd4a4982b677af01 (patch)
treee459388b0d937bdb4034676c1a8276c59904fc68 /httpd.h
parent2133fd579e0d4726b032288d10d053231109c586 (diff)
HTTPServer/HTTPConnection cleanup.
Diffstat (limited to 'httpd.h')
-rw-r--r--httpd.h57
1 files changed, 25 insertions, 32 deletions
diff --git a/httpd.h b/httpd.h
index f9c0930..0fd601f 100644
--- a/httpd.h
+++ b/httpd.h
@@ -1,37 +1,30 @@
#ifndef HTTPD_H
#define HTTPD_H
-#include <boost/asio.hpp>
-#include <boost/enable_shared_from_this.hpp>
-
-using boost::asio::ip::tcp;
-
-class HTTPConnection : public boost::enable_shared_from_this<HTTPConnection> {
- friend class HTTPServer;
-
- private:
- HTTPConnection(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;
-
- public:
- typedef boost::shared_ptr<HTTPConnection> pointer;
-
- static pointer create(boost::asio::io_service& io_service);
- void start();
-};
-
-class HTTPServer {
- private:
- void start_accept();
- void handle_accept(HTTPConnection::pointer new_connection, const boost::system::error_code& error);
-
- tcp::acceptor acceptor_;
-
- public:
- HTTPServer(boost::asio::io_service& io_service, const tcp::endpoint& endpoint);
-};
+#include "http_connection.h"
+
+#include <string>
+#include <map>
+
+#include <boost/function.hpp>
+
+namespace HTTP {
+ typedef boost::function<void (Connection::p)> Handler;
+
+ class Server {
+ public:
+ Server(boost::asio::io_service& io_service, const tcp::endpoint& endpoint);
+
+ void add_handler(const std::string& name, Handler handler);
+
+ private:
+ void start_accept();
+ void handle_accept(Connection::p new_connection, const boost::system::error_code& error);
+
+ tcp::acceptor acceptor_;
+
+ std::map<std::string, Handler> handlers;
+ };
+}
#endif