Skip to content

Commit

Permalink
Code format - (Clang-format)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Dec 6, 2023
1 parent ed439b1 commit 2f4c46f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
27 changes: 12 additions & 15 deletions src/server/network/connection/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,29 @@ void ConnectionManager::releaseConnection(const Connection_ptr &connection) {
}

void ConnectionManager::closeAll() {
connections.for_each([](const Connection_ptr& connection) {
connections.for_each([](const Connection_ptr &connection) {
try {
std::error_code error;
connection->socket.shutdown(asio::ip::tcp::socket::shutdown_both, error);
if (error) {
g_logger().error("[ConnectionManager::closeAll] - Failed to close connection, system error code {}", error.message());
}
} catch (const std::system_error& systemError) {
} catch (const std::system_error &systemError) {
g_logger().error("[ConnectionManager::closeAll] - Exception caught: {}", systemError.what());
}
});

connections.clear();
}

Connection::Connection(asio::io_service &initIoService, ConstServicePort_ptr initservicePort)
: readTimer(initIoService),
writeTimer(initIoService),
service_port(std::move(initservicePort)),
socket(initIoService),
timeConnected(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now())) {
Connection::Connection(asio::io_service &initIoService, ConstServicePort_ptr initservicePort) :
readTimer(initIoService),
writeTimer(initIoService),
service_port(std::move(initservicePort)),
socket(initIoService),
timeConnected(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now())) {
}


void Connection::close(bool force) {
ConnectionManager::getInstance().releaseConnection(shared_from_this());

Expand Down Expand Up @@ -276,8 +275,7 @@ void Connection::resumeWork() {
readTimer.expires_from_now(std::chrono::seconds(CONNECTION_READ_TIMEOUT));
readTimer.async_wait(std::bind(&Connection::handleTimeout, std::weak_ptr<Connection>(shared_from_this()), std::placeholders::_1));

asio::async_read(socket, asio::buffer(msg.getBuffer(), HEADER_LENGTH),
std::bind(&Connection::parseHeader, shared_from_this(), std::placeholders::_1));
asio::async_read(socket, asio::buffer(msg.getBuffer(), HEADER_LENGTH), std::bind(&Connection::parseHeader, shared_from_this(), std::placeholders::_1));
}

void Connection::send(const OutputMessage_ptr &outputMessage) {
Expand Down Expand Up @@ -307,7 +305,7 @@ void Connection::internalWorker() {
return;
}

const auto& outputMessage = messageQueue.front();
const auto &outputMessage = messageQueue.front();
lock.unlock();
protocol->onSendMessage(outputMessage);
lock.lock();
Expand Down Expand Up @@ -336,8 +334,7 @@ void Connection::internalSend(const OutputMessage_ptr &outputMessage) {
writeTimer.expires_from_now(std::chrono::seconds(CONNECTION_WRITE_TIMEOUT));
writeTimer.async_wait(std::bind(&Connection::handleTimeout, std::weak_ptr<Connection>(shared_from_this()), std::placeholders::_1));

asio::async_write(socket, asio::buffer(outputMessage->getOutputBuffer(), outputMessage->getLength()),
std::bind(&Connection::onWriteOperation, shared_from_this(), std::placeholders::_1));
asio::async_write(socket, asio::buffer(outputMessage->getOutputBuffer(), outputMessage->getLength()), std::bind(&Connection::onWriteOperation, shared_from_this(), std::placeholders::_1));
}

void Connection::onWriteOperation(const std::error_code &error) {
Expand All @@ -354,7 +351,7 @@ void Connection::onWriteOperation(const std::error_code &error) {
messageQueue.pop_front();

if (!messageQueue.empty()) {
const auto& outputMessage = messageQueue.front();
const auto &outputMessage = messageQueue.front();
lock.unlock();
protocol->onSendMessage(outputMessage);
lock.lock();
Expand Down
2 changes: 1 addition & 1 deletion src/server/network/connection/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Connection : public std::enable_shared_from_this<Connection> {

void resumeWork();

void handleRead(const std::error_code&error);
void handleRead(const std::error_code &error);

void send(const OutputMessage_ptr &outputMessage);

Expand Down

0 comments on commit 2f4c46f

Please sign in to comment.