Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated ASIO functions and raise minimum Boost version #4686

Merged
merged 2 commits into from
May 16, 2024
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ set(BOOST_REQUIRED_COMPONENTS system iostreams locale)
if (BUILD_TESTING)
list(APPEND BOOST_REQUIRED_COMPONENTS unit_test_framework)
endif ()
find_package(Boost 1.66.0 REQUIRED COMPONENTS ${BOOST_REQUIRED_COMPONENTS})
find_package(Boost 1.71.0 REQUIRED COMPONENTS ${BOOST_REQUIRED_COMPONENTS})

include_directories(${Boost_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR} ${LUA_INCLUDE_DIR} ${MYSQL_INCLUDE_DIR} ${PUGIXML_INCLUDE_DIR})

Expand Down
12 changes: 6 additions & 6 deletions src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
#include "server.h"
#include "tasks.h"

Connection_ptr ConnectionManager::createConnection(boost::asio::io_service& io_service,
Connection_ptr ConnectionManager::createConnection(boost::asio::io_context& io_context,
ConstServicePort_ptr servicePort)
{
std::lock_guard<std::mutex> lockClass(connectionManagerLock);

auto connection = std::make_shared<Connection>(io_service, servicePort);
auto connection = std::make_shared<Connection>(io_context, servicePort);
connections.insert(connection);
return connection;
}
Expand Down Expand Up @@ -103,7 +103,7 @@ void Connection::accept()
}

try {
readTimer.expires_from_now(std::chrono::seconds(CONNECTION_READ_TIMEOUT));
readTimer.expires_after(std::chrono::seconds(CONNECTION_READ_TIMEOUT));
readTimer.async_wait(
[thisPtr = std::weak_ptr<Connection>(shared_from_this())](const boost::system::error_code& error) {
Connection::handleTimeout(thisPtr, error);
Expand Down Expand Up @@ -181,7 +181,7 @@ void Connection::parseHeader(const boost::system::error_code& error)
}

try {
readTimer.expires_from_now(std::chrono::seconds(CONNECTION_READ_TIMEOUT));
readTimer.expires_after(std::chrono::seconds(CONNECTION_READ_TIMEOUT));
readTimer.async_wait(
[thisPtr = std::weak_ptr<Connection>(shared_from_this())](const boost::system::error_code& error) {
Connection::handleTimeout(thisPtr, error);
Expand Down Expand Up @@ -241,7 +241,7 @@ void Connection::parsePacket(const boost::system::error_code& error)
}

try {
readTimer.expires_from_now(std::chrono::seconds(CONNECTION_READ_TIMEOUT));
readTimer.expires_after(std::chrono::seconds(CONNECTION_READ_TIMEOUT));
readTimer.async_wait(
[thisPtr = std::weak_ptr<Connection>(shared_from_this())](const boost::system::error_code& error) {
Connection::handleTimeout(thisPtr, error);
Expand Down Expand Up @@ -277,7 +277,7 @@ void Connection::internalSend(const OutputMessage_ptr& msg)
{
protocol->onSendMessage(msg);
try {
writeTimer.expires_from_now(std::chrono::seconds(CONNECTION_WRITE_TIMEOUT));
writeTimer.expires_after(std::chrono::seconds(CONNECTION_WRITE_TIMEOUT));
writeTimer.async_wait(
[thisPtr = std::weak_ptr<Connection>(shared_from_this())](const boost::system::error_code& error) {
Connection::handleTimeout(thisPtr, error);
Expand Down
10 changes: 5 additions & 5 deletions src/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ConnectionManager
return instance;
}

Connection_ptr createConnection(boost::asio::io_service& io_service, ConstServicePort_ptr servicePort);
Connection_ptr createConnection(boost::asio::io_context& io_context, ConstServicePort_ptr servicePort);
void releaseConnection(const Connection_ptr& connection);
void closeAll();

Expand All @@ -71,11 +71,11 @@ class Connection : public std::enable_shared_from_this<Connection>
FORCE_CLOSE = true
};

Connection(boost::asio::io_service& io_service, ConstServicePort_ptr service_port) :
readTimer(io_service),
writeTimer(io_service),
Connection(boost::asio::io_context& io_context, ConstServicePort_ptr service_port) :
readTimer(io_context),
writeTimer(io_context),
service_port(std::move(service_port)),
socket(io_service),
socket(io_context),
timeConnected(time(nullptr))
{}
~Connection();
Expand Down
1 change: 1 addition & 0 deletions src/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static constexpr auto CLIENT_VERSION_STR = "13.10";
static constexpr auto AUTHENTICATOR_DIGITS = 6U;
static constexpr auto AUTHENTICATOR_PERIOD = 30U;

#define BOOST_ASIO_NO_DEPRECATED
#define OPENSSL_NO_DEPRECATED

#ifndef __FUNCTION__
Expand Down
2 changes: 1 addition & 1 deletion src/protocolstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum RequestedInfo_t : uint16_t

void ProtocolStatus::onRecvFirstMessage(NetworkMessage& msg)
{
const static auto acceptorAddress = Connection::Address::from_string(getString(ConfigManager::IP));
const static auto acceptorAddress = boost::asio::ip::make_address(getString(ConfigManager::IP));

const auto& ip = getIP();

Expand Down
2 changes: 1 addition & 1 deletion src/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ uint32_t Scheduler::addEvent(SchedulerTask* task)
auto it = eventIdTimerMap.emplace(task->getEventId(), boost::asio::steady_timer{io_context});
auto& timer = it.first->second;

timer.expires_from_now(std::chrono::milliseconds(task->getDelay()));
timer.expires_after(std::chrono::milliseconds(task->getDelay()));
timer.async_wait([this, task](const boost::system::error_code& error) {
eventIdTimerMap.erase(task->getEventId());

Expand Down
2 changes: 1 addition & 1 deletion src/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Scheduler : public ThreadHolder<Scheduler>
std::atomic<uint32_t> lastEventId{0};
std::unordered_map<uint32_t, boost::asio::steady_timer> eventIdTimerMap;
boost::asio::io_context io_context;
boost::asio::io_context::work work{io_context};
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> work{io_context.get_executor()};
};

extern Scheduler g_scheduler;
Expand Down
14 changes: 7 additions & 7 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace {
boost::asio::ip::address getListenAddress()
{
if (getBoolean(ConfigManager::BIND_ONLY_GLOBAL_ADDRESS)) {
return boost::asio::ip::address::from_string(getString(ConfigManager::IP));
return boost::asio::ip::make_address(getString(ConfigManager::IP));
}
return boost::asio::ip::address_v6::any();
}
Expand All @@ -32,13 +32,13 @@ void openAcceptor(std::weak_ptr<ServicePort> weak_service, uint16_t port)

ServiceManager::~ServiceManager() { stop(); }

void ServiceManager::die() { io_service.stop(); }
void ServiceManager::die() { io_context.stop(); }

void ServiceManager::run()
{
assert(!running);
running = true;
io_service.run();
io_context.run();
}

void ServiceManager::stop()
Expand All @@ -51,15 +51,15 @@ void ServiceManager::stop()

for (auto& servicePortIt : acceptors) {
try {
io_service.post([servicePort = servicePortIt.second]() { servicePort->onStopServer(); });
boost::asio::post(io_context, [servicePort = servicePortIt.second]() { servicePort->onStopServer(); });
} catch (boost::system::system_error& e) {
std::cout << "[ServiceManager::stop] Network Error: " << e.what() << std::endl;
}
}

acceptors.clear();

death_timer.expires_from_now(std::chrono::seconds(3));
death_timer.expires_after(std::chrono::seconds(3));
death_timer.async_wait([this](const boost::system::error_code&) { die(); });
}

Expand Down Expand Up @@ -88,7 +88,7 @@ void ServicePort::accept()
return;
}

auto connection = ConnectionManager::getInstance().createConnection(io_service, shared_from_this());
auto connection = ConnectionManager::getInstance().createConnection(io_context, shared_from_this());
acceptor->async_accept(connection->getSocket(),
[=, thisPtr = shared_from_this()](const boost::system::error_code& error) {
thisPtr->onAccept(connection, error);
Expand Down Expand Up @@ -153,7 +153,7 @@ void ServicePort::open(uint16_t port)
try {
auto address = getListenAddress();

acceptor = std::make_unique<ip::tcp::acceptor>(io_service, ip::tcp::endpoint{address, serverPort});
acceptor = std::make_unique<ip::tcp::acceptor>(io_context, ip::tcp::endpoint{address, serverPort});
if (address.is_v6()) {
ip::v6_only option;
acceptor->get_option(option);
Expand Down
12 changes: 6 additions & 6 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Service final : public ServiceBase
class ServicePort : public std::enable_shared_from_this<ServicePort>
{
public:
explicit ServicePort(boost::asio::io_service& io_service) : io_service(io_service) {}
explicit ServicePort(boost::asio::io_context& io_context) : io_context(io_context) {}
~ServicePort();

// non-copyable
Expand All @@ -56,7 +56,7 @@ class ServicePort : public std::enable_shared_from_this<ServicePort>
private:
void accept();

boost::asio::io_service& io_service;
boost::asio::io_context& io_context;
std::unique_ptr<boost::asio::ip::tcp::acceptor> acceptor;
std::vector<Service_ptr> services;

Expand Down Expand Up @@ -87,9 +87,9 @@ class ServiceManager

std::unordered_map<uint16_t, ServicePort_ptr> acceptors;

boost::asio::io_service io_service;
Signals signals{io_service};
boost::asio::steady_timer death_timer{io_service};
boost::asio::io_context io_context;
Signals signals{io_context};
boost::asio::steady_timer death_timer{io_context};
bool running = false;
};

Expand All @@ -107,7 +107,7 @@ bool ServiceManager::add(uint16_t port)
auto foundServicePort = acceptors.find(port);

if (foundServicePort == acceptors.end()) {
service_port = std::make_shared<ServicePort>(io_service);
service_port = std::make_shared<ServicePort>(io_context);
service_port->open(port);
acceptors[port] = service_port;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/signals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void dispatchSignalHandler(int signal)

} // namespace

Signals::Signals(boost::asio::io_service& service) : set(service)
Signals::Signals(boost::asio::io_context& ioc) : set(ioc)
{
set.add(SIGINT);
set.add(SIGTERM);
Expand Down
2 changes: 1 addition & 1 deletion src/signals.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Signals
boost::asio::signal_set set;

public:
explicit Signals(boost::asio::io_service& service);
explicit Signals(boost::asio::io_context& ioc);

private:
void asyncWait();
Expand Down
Loading