aboutsummaryrefslogtreecommitdiffstats
path: root/http_server.h
diff options
context:
space:
mode:
authoripknHama <ipknhama@gmail.com>2014-04-01 01:51:50 +0900
committeripknHama <ipknhama@gmail.com>2014-04-01 01:51:50 +0900
commit4b8c67e2300205200f4f846400d73a03cb3da854 (patch)
tree46b63650efd6952cf88a62cc0511162af54d896f /http_server.h
parent1e11a177ee6b680b55f01d6090ccd1b2e2b8c51c (diff)
downloadcrow-4b8c67e2300205200f4f846400d73a03cb3da854.tar.gz
crow-4b8c67e2300205200f4f846400d73a03cb3da854.zip
accept connections, print http request parsed information
Diffstat (limited to 'http_server.h')
-rw-r--r--http_server.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/http_server.h b/http_server.h
new file mode 100644
index 0000000..002eec6
--- /dev/null
+++ b/http_server.h
@@ -0,0 +1,48 @@
+#pragma once
+
+#include <boost/asio.hpp>
+#include <stdint.h>
+
+#include "http_connection.h"
+
+// TEST
+#include <iostream>
+
+namespace flask
+{
+ using namespace boost;
+ using tcp = asio::ip::tcp;
+ template <typename Handler>
+ class Server
+ {
+ public:
+ Server(Handler* handler, uint16_t port)
+ : acceptor_(io_service_, tcp::endpoint(asio::ip::address(), port)), socket_(io_service_), handler_(handler)
+ {
+ do_accept();
+ }
+
+ void run()
+ {
+ auto _ = std::async(std::launch::async, [this]{io_service_.run();});
+ }
+
+ private:
+ void do_accept()
+ {
+ acceptor_.async_accept(socket_,
+ [this](boost::system::error_code ec)
+ {
+ if (!ec)
+ (new Connection<Handler>(std::move(socket_), handler_))->start();
+ do_accept();
+ });
+ }
+
+ private:
+ asio::io_service io_service_;
+ tcp::acceptor acceptor_;
+ tcp::socket socket_;
+ Handler* handler_;
+ };
+}