Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions brazier/include/brazier/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ namespace brazier {
std::atomic<int> connection_count_{ 0 };
std::atomic<int> total_requests_{ 0 };

std::thread stats_thread_;
std::atomic<bool> shutdown_flag_{ false };

public:
Server(const std::string& host, unsigned short port);

Expand Down
17 changes: 12 additions & 5 deletions brazier/src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,20 @@
Logger::log("Starting " + std::to_string(threads_count) + " worker threads", "INFO");

for (int i = 0; i < threads_count; ++i) {
threads_.emplace_back([this, i] {
threads_.emplace_back([this] {
io_.run();
});
});
}

std::thread stats_thread([this] {
while (true) {
shutdown_flag_.store(false, std::memory_order_release);
stats_thread_ = std::thread([this] {
while (!shutdown_flag_.load(std::memory_order_acquire)) {
std::this_thread::sleep_for(10s);
if (shutdown_flag_.load(std::memory_order_acquire)) break;
Logger::log("STATS - Active connections: " + std::to_string(connection_count_.load()) +
", Total requests: " + std::to_string(total_requests_.load()), "INFO");
}
});
stats_thread.detach();

for (auto& t : threads_) {
if (t.joinable()) {
Expand All @@ -99,8 +100,14 @@
}

void brazier::Server::stop() {
shutdown_flag_.store(true);

work_guard_.reset();
io_.stop();

if (stats_thread_.joinable()) {
stats_thread_.join();
}
Logger::log("Server stopped", "INFO");
}

Expand Down Expand Up @@ -223,7 +230,7 @@

connection_count_--;
co_return;
}

Check warning on line 233 in brazier/src/Server.cpp

View workflow job for this annotation

GitHub Actions / linux (gcc, Release, ON)

‘brazier::Server::handle_connection(boost::asio::ip::tcp::socket)::_ZN7brazier6Server17handle_connectionEN5boost4asio19basic_stream_socketINS2_2ip3tcpENS2_15any_io_executorEEE.Frame’ has a field ‘brazier::Server::handle_connection(boost::asio::ip::tcp::socket)::<lambda()> brazier::Server::handle_connection(boost::asio::ip::tcp::socket)::_ZN7brazier6Server17handle_connectionEN5boost4asio19basic_stream_socketINS2_2ip3tcpENS2_15any_io_executorEEE.Frame::reset_timer_2_3’ whose type has no linkage [-Wsubobject-linkage]

Check warning on line 233 in brazier/src/Server.cpp

View workflow job for this annotation

GitHub Actions / linux (gcc, Debug, OFF)

‘brazier::Server::handle_connection(boost::asio::ip::tcp::socket)::_ZN7brazier6Server17handle_connectionEN5boost4asio19basic_stream_socketINS2_2ip3tcpENS2_15any_io_executorEEE.Frame’ has a field ‘brazier::Server::handle_connection(boost::asio::ip::tcp::socket)::<lambda()> brazier::Server::handle_connection(boost::asio::ip::tcp::socket)::_ZN7brazier6Server17handle_connectionEN5boost4asio19basic_stream_socketINS2_2ip3tcpENS2_15any_io_executorEEE.Frame::reset_timer_2_3’ whose type has no linkage [-Wsubobject-linkage]

Check warning on line 233 in brazier/src/Server.cpp

View workflow job for this annotation

GitHub Actions / linux (gcc, Debug, ON)

‘brazier::Server::handle_connection(boost::asio::ip::tcp::socket)::_ZN7brazier6Server17handle_connectionEN5boost4asio19basic_stream_socketINS2_2ip3tcpENS2_15any_io_executorEEE.Frame’ has a field ‘brazier::Server::handle_connection(boost::asio::ip::tcp::socket)::<lambda()> brazier::Server::handle_connection(boost::asio::ip::tcp::socket)::_ZN7brazier6Server17handle_connectionEN5boost4asio19basic_stream_socketINS2_2ip3tcpENS2_15any_io_executorEEE.Frame::reset_timer_2_3’ whose type has no linkage [-Wsubobject-linkage]

Check warning on line 233 in brazier/src/Server.cpp

View workflow job for this annotation

GitHub Actions / linux (gcc, Release, OFF)

‘brazier::Server::handle_connection(boost::asio::ip::tcp::socket)::_ZN7brazier6Server17handle_connectionEN5boost4asio19basic_stream_socketINS2_2ip3tcpENS2_15any_io_executorEEE.Frame’ has a field ‘brazier::Server::handle_connection(boost::asio::ip::tcp::socket)::<lambda()> brazier::Server::handle_connection(boost::asio::ip::tcp::socket)::_ZN7brazier6Server17handle_connectionEN5boost4asio19basic_stream_socketINS2_2ip3tcpENS2_15any_io_executorEEE.Frame::reset_timer_2_3’ whose type has no linkage [-Wsubobject-linkage]

net::awaitable<void> brazier::Server::accept_loop() {
for (;;) {
Expand Down
Loading