Skip to content

Commit

Permalink
remove server namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Mar 21, 2024
1 parent 917175b commit 907b3c4
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions example/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@

//#define LOGGING

namespace server {

namespace io = boost::http_io;
namespace urls = boost::urls;
namespace asio = boost::asio;
namespace core = boost::core;
namespace system = boost::system;
namespace http_proto = boost::http_proto;
using namespace std::placeholders;
using tcp = boost::asio::ip::tcp;
Expand Down Expand Up @@ -251,7 +248,7 @@ handle_request(
path.append("index.html");

// Attempt to open the file
system::error_code ec;
boost::system::error_code ec;
http_proto::file f;
std::uint64_t size = 0;
f.open(path.c_str(), http_proto::file_mode::scan, ec);
Expand Down Expand Up @@ -347,19 +344,17 @@ class group
using socket_type = asio::basic_stream_socket< tcp, Executor >;

private:
asio::io_context& ioc_;
acceptor_type acceptor_;
http_proto::context& ctx_;
std::size_t id_ = 0;
std::size_t n_idle_ = 0;

public:
group(
asio::io_context& ioc,
Executor const& ex,
tcp::endpoint ep,
http_proto::context& ctx)
: ioc_(ioc)
, acceptor_(ioc, ep)
: acceptor_(ex, ep)
, ctx_(ctx)
{
}
Expand All @@ -385,7 +380,7 @@ class group
void
stop()
{
system::error_code ec;
boost::system::error_code ec;
acceptor_.cancel(ec);
}

Expand Down Expand Up @@ -422,9 +417,6 @@ class worker
bool is_service_unavailable_;

public:
worker(worker&&) = delete;
worker(worker const&) = delete;

worker(
group_type& grp,
std::string const& doc_root)
Expand All @@ -446,15 +438,15 @@ class worker
void
stop()
{
system::error_code ec;
boost::system::error_code ec;
sock_.cancel(ec);
}

private:
void
fail(
std::string what,
system::error_code ec)
boost::system::error_code ec)
{
if( ec == asio::error::operation_aborted )
return;
Expand All @@ -477,7 +469,7 @@ class worker
do_accept()
{
// Clean up any previous connection.
system::error_code ec;
boost::system::error_code ec;
sock_.close(ec);
pr_.reset();

Expand All @@ -487,7 +479,7 @@ class worker
}

void
on_accept(system::error_code ec)
on_accept(boost::system::error_code ec)
{
is_service_unavailable_ = grp_.on_worker_busy();
if( ec.failed() )
Expand Down Expand Up @@ -516,7 +508,7 @@ class worker

void
on_read_header(
system::error_code ec,
boost::system::error_code ec,
std::size_t bytes_transferred)
{
(void)bytes_transferred;
Expand All @@ -535,7 +527,7 @@ class worker

void
on_read_body(
system::error_code ec,
boost::system::error_code ec,
std::size_t bytes_transferred)
{
(void)bytes_transferred;
Expand Down Expand Up @@ -578,7 +570,7 @@ class worker

void
on_write(
system::error_code ec,
boost::system::error_code ec,
std::size_t bytes_transferred)
{
(void)bytes_transferred;
Expand Down Expand Up @@ -631,7 +623,7 @@ int main(int argc, char* argv[])
http_proto::request_parser::config cfg;
http_proto::install_parser_service(ctx, cfg);
}
group< executor_type > grp( ioc, { addr, port }, ctx );
group< executor_type > grp( ioc.get_executor(), { addr, port }, ctx );

// 1 extra worker to refuse connections when full
++num_workers;
Expand All @@ -642,7 +634,7 @@ int main(int argc, char* argv[])
// Capture SIGINT and SIGTERM to perform a clean shutdown
asio::signal_set signals(ioc, SIGINT, SIGTERM);
signals.async_wait(
[&](system::error_code const&, int)
[&](boost::system::error_code const&, int)
{
// cancel all outstanding work,
// causing io_context::run to return.
Expand All @@ -660,10 +652,3 @@ int main(int argc, char* argv[])
}
return EXIT_SUCCESS;
}

} // server

int main(int argc, char* argv[])
{
return server::main(argc, argv);
}

0 comments on commit 907b3c4

Please sign in to comment.