Use a shared string for example HTTP server doc roots

fix #1109
This commit is contained in:
Vinnie Falco committed 2018-05-03 14:18:33 -07:00
1 parent a94efc8c92
commit f48b978044
12 files changed
+65 -64

No files matched your search

@@ -251,7 +251,7 @@ struct send_lambda
void
do_session(
tcp::socket& socket,
std::string const& doc_root,
std::shared_ptr<std::string const> const& doc_root,
boost::asio::yield_context yield)
{
bool close = false;
@@ -274,7 +274,7 @@ do_session(
return fail(ec, "read");
// Send the response
handle_request(doc_root, std::move(req), lambda);
handle_request(*doc_root, std::move(req), lambda);
if(ec)
return fail(ec, "write");
if(close)
@@ -298,7 +298,7 @@ void
do_listen(
boost::asio::io_context& ioc,
tcp::endpoint endpoint,
std::string const& doc_root,
std::shared_ptr<std::string const> const& doc_root,
boost::asio::yield_context yield)
{
boost::system::error_code ec;
@@ -354,7 +354,7 @@ int main(int argc, char* argv[])
}
auto const address = boost::asio::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
std::string const doc_root = argv[3];
auto const doc_root = std::make_shared<std::string>(argv[3]);
auto const threads = std::max<int>(1, std::atoi(argv[4]));
// The io_context is required for all I/O