1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-31 23:45:32 +00:00
openmw-tes3mp/apps/master/SimpleWeb/http_server.hpp
2017-09-12 20:21:32 +08:00

42 lines
1.3 KiB
C++

#pragma once
#include "base_server.hpp"
namespace SimpleWeb {
template <class socket_type>
class Server : public ServerBase<socket_type> {};
using HTTP = asio::ip::tcp::socket;
template <>
class Server<HTTP> : public ServerBase<HTTP> {
public:
Server() noexcept : ServerBase<HTTP>::ServerBase(80) {}
protected:
void accept() override {
auto session = std::make_shared<Session>(create_connection(*io_service));
acceptor->async_accept(*session->connection->socket, [this, session](const error_code &ec) {
auto lock = session->connection->handler_runner->continue_lock();
if(!lock)
return;
// Immediately start accepting a new connection (unless io_service has been stopped)
if(ec != asio::error::operation_aborted)
this->accept();
if(!ec) {
asio::ip::tcp::no_delay option(true);
error_code ec;
session->connection->socket->set_option(option, ec);
this->read_request_and_content(session);
}
else if(this->on_error)
this->on_error(session->request, ec);
});
}
};
} // namespace SimpleWeb