identt
HttpServer.hpp
Go to the documentation of this file.
1 
33 #ifndef _IDENTT_HTTP_SERVER_HPP_
34 #define _IDENTT_HTTP_SERVER_HPP_
35 
36 #include "HttpServerBase.hpp"
37 
38 namespace identt {
39 namespace http {
40 
41 template <class socket_type>
42 class HttpServer : public HttpServerBase<socket_type> {};
43 
44 using HTTP = asio::ip::tcp::socket;
45 
46 template <>
47 class HttpServer<HTTP> : public HttpServerBase<HTTP> {
48 public:
49  HttpServer(unsigned short port) noexcept
51 
52 protected:
53  void accept() override
54  {
55  auto connection = create_connection(*io_whatever);
56 
57  acceptor->async_accept(*connection->socket, [this, connection](const error_code &ec) {
58  auto lock = connection->handler_runner->continue_lock();
59  if(!lock)
60  return;
61 
62  // Immediately start accepting a new connection (unless io_service has been stopped)
63  if(ec != error::operation_aborted)
64  this->accept();
65 
66  auto session = std::make_shared<Session>(config.max_request_streambuf_size, connection);
67 
68  if(!ec) {
69  asio::ip::tcp::no_delay option(true);
70  error_code ec;
71  session->connection->socket->set_option(option, ec);
72 
73  this->read(session);
74  }
75  else if(this->on_error)
76  this->on_error(session->request, ec);
77  });
78  }
79 };
80 
81 } // namespace http
82 } // namespace identt
83 #endif /* _IDENTT_HTTP_SERVER_HPP_ */
Definition: HttpServerBase.hpp:53
Definition: CryptoBase.hpp:49
Definition: HttpServer.hpp:42