summaryrefslogtreecommitdiff
path: root/include/tgbot/net/HttpServer.h
diff options
context:
space:
mode:
authorOleg Morozenkov <omorozenkov@gmail.com>2015-08-11 22:13:23 +0300
committerOleg Morozenkov <omorozenkov@gmail.com>2015-08-11 22:13:23 +0300
commit376b88ec09ef8cf71dd823467406c58204485fcc (patch)
tree9ca599b854d18006c65b26003ce7dbdd416fdf18 /include/tgbot/net/HttpServer.h
parentd7fbf7149d0e0c1c30972dab68d510ef6ac377dd (diff)
Fixed compiler's errors in TgTypeParser + fixed indentation + some other fixes
Diffstat (limited to 'include/tgbot/net/HttpServer.h')
-rw-r--r--include/tgbot/net/HttpServer.h106
1 files changed, 53 insertions, 53 deletions
diff --git a/include/tgbot/net/HttpServer.h b/include/tgbot/net/HttpServer.h
index 0a66900..bac7382 100644
--- a/include/tgbot/net/HttpServer.h
+++ b/include/tgbot/net/HttpServer.h
@@ -39,63 +39,63 @@ template<typename Protocol>
class HttpServer {
private:
- class Connection;
+ class Connection;
public:
- typedef std::function<std::string (const std::string&, const std::map<std::string, std::string>)> ServerHandler;
-
- HttpServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>>& acceptor, const ServerHandler& handler) : _acceptor(acceptor), _handler(handler) {
- }
-
- /**
- * Starts receiving new connections.
- */
- void start() {
- std::shared_ptr<boost::asio::basic_stream_socket<Protocol>> socket(new boost::asio::basic_stream_socket<Protocol>(acceptor->get_io_service()));
- std::shared_ptr<Connection<Protocol>> connection(new Connection<Protocol>(socket, _handler));
- acceptor->async_accept(*connection->socket, [this, connection]() {
- connection->start();
- start();
- });
- _ioService.run();
- }
-
- /**
- * Stops receiving new connections.
- */
- void stop() {
- _ioService.stop();
- }
+ typedef std::function<std::string (const std::string&, const std::map<std::string, std::string>)> ServerHandler;
+
+ HttpServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>>& acceptor, const ServerHandler& handler) : _acceptor(acceptor), _handler(handler) {
+ }
+
+ /**
+ * Starts receiving new connections.
+ */
+ void start() {
+ std::shared_ptr<boost::asio::basic_stream_socket<Protocol>> socket(new boost::asio::basic_stream_socket<Protocol>(acceptor->get_io_service()));
+ std::shared_ptr<Connection<Protocol>> connection(new Connection<Protocol>(socket, _handler));
+ acceptor->async_accept(*connection->socket, [this, connection]() {
+ connection->start();
+ start();
+ });
+ _ioService.run();
+ }
+
+ /**
+ * Stops receiving new connections.
+ */
+ void stop() {
+ _ioService.stop();
+ }
private:
- template<typename Protocol>
- class Connection {
-
- public:
- Connection(std::shared_ptr<boost::asio::basic_stream_socket<Protocol>>& socket, const ServerHandler& handler) : socket(socket), _handler(handler) {
- boost::asio::socket_base::keep_alive option(true);
- socket.set_option(option);
- }
-
- void start() {
- data.reserve(10240);
- socket->async_receive(data, [this]() {
- std::map<std::string, std::string> headers;
- std::string body = HttpParser::parseResponse(data, headers);
- socket->async_send(_handler(body, headers));
- });
- }
-
- std::shared_ptr<boost::asio::basic_stream_socket<Protocol>> socket;
- std::string data;
-
- private:
- const ServerHandler _handler;
- };
-
- boost::asio::io_service _ioService;
- std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>> _acceptor;
- const ServerHandler _handler;
+ template<typename Protocol>
+ class Connection {
+
+ public:
+ Connection(std::shared_ptr<boost::asio::basic_stream_socket<Protocol>>& socket, const ServerHandler& handler) : socket(socket), _handler(handler) {
+ boost::asio::socket_base::keep_alive option(true);
+ socket.set_option(option);
+ }
+
+ void start() {
+ data.reserve(10240);
+ socket->async_receive(data, [this]() {
+ std::map<std::string, std::string> headers;
+ std::string body = HttpParser::parseResponse(data, headers);
+ socket->async_send(_handler(body, headers));
+ });
+ }
+
+ std::shared_ptr<boost::asio::basic_stream_socket<Protocol>> socket;
+ std::string data;
+
+ private:
+ const ServerHandler _handler;
+ };
+
+ boost::asio::io_service _ioService;
+ std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>> _acceptor;
+ const ServerHandler _handler;
};
}