Boost.ASIO: upgrade io_service=>io_context, finally
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <algorithm>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/deadline_timer.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <opts.h>
|
||||
|
||||
@@ -19,7 +19,7 @@ BroadcastListener::BroadcastListener(
|
||||
listeningPort(listeningPort),
|
||||
connectPort(connectPort),
|
||||
deviceGoneAwayCb(nullptr),
|
||||
socket(componentThread->getIoService()),
|
||||
socket(componentThread->getIoContext()),
|
||||
listeningEndpoint(boost::asio::ip::udp::v4(), listeningPort),
|
||||
isListening(false)
|
||||
{
|
||||
|
||||
@@ -1098,7 +1098,7 @@ void Device::startHeartbeat()
|
||||
|
||||
// Create heartbeat timer
|
||||
heartbeatTimer = std::make_unique<boost::asio::deadline_timer>(
|
||||
componentThread->getIoService());
|
||||
componentThread->getIoContext());
|
||||
|
||||
heartbeatActive.store(true);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace endian {
|
||||
// IPv4 address validation
|
||||
inline bool isValidIPv4(const std::string& ipAddress) {
|
||||
boost::system::error_code ec;
|
||||
boost::asio::ip::address_v4::from_string(ipAddress, ec);
|
||||
(void)boost::asio::ip::make_address_v4(ipAddress, ec);
|
||||
return !ec;
|
||||
}
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ void UdpCommandDemuxer::setupCommandSocket()
|
||||
|
||||
// Create boost wrapper for async operations
|
||||
cmdEndpointFdDesc = std::make_shared<boost::asio::posix::stream_descriptor>(
|
||||
componentThread->getIoService(), socketGuard.getFd());
|
||||
componentThread->getIoContext(), socketGuard.getFd());
|
||||
|
||||
// Transfer ownership, prevent auto-close
|
||||
socketGuard.commit();
|
||||
@@ -269,7 +269,7 @@ void UdpCommandDemuxer::setupPcloudDataSocket()
|
||||
|
||||
// Create boost wrapper for async operations
|
||||
pcloudDataFdDesc = std::make_shared<boost::asio::posix::stream_descriptor>(
|
||||
componentThread->getIoService(), socketGuard.getFd());
|
||||
componentThread->getIoContext(), socketGuard.getFd());
|
||||
|
||||
// Transfer ownership, prevent auto-close
|
||||
socketGuard.commit();
|
||||
@@ -419,16 +419,16 @@ void UdpCommandDemuxer::processIncomingData()
|
||||
struct UdpCommandDemuxer::PendingCommandWaitDesc
|
||||
{
|
||||
CommandWaitKey key;
|
||||
boost::asio::io_service &resumeIoService;
|
||||
boost::asio::io_context &resumeIoContext;
|
||||
std::atomic<bool> settled{false};
|
||||
UdpCommandResponseResult result{};
|
||||
std::coroutine_handle<> callerSchedHandle;
|
||||
|
||||
PendingCommandWaitDesc(
|
||||
CommandWaitKey keyIn,
|
||||
boost::asio::io_service &resumeIoServiceIn)
|
||||
boost::asio::io_context &resumeIoContextIn)
|
||||
: key(std::move(keyIn)),
|
||||
resumeIoService(resumeIoServiceIn)
|
||||
resumeIoContext(resumeIoContextIn)
|
||||
{}
|
||||
};
|
||||
|
||||
@@ -458,7 +458,7 @@ void UdpCommandDemuxer::settlePendingCommandWait(
|
||||
return;
|
||||
}
|
||||
|
||||
boost::asio::post(wait->resumeIoService, handle);
|
||||
boost::asio::post(wait->resumeIoContext, handle);
|
||||
}
|
||||
|
||||
std::shared_ptr<UdpCommandDemuxer::PendingCommandWaitDesc>
|
||||
@@ -518,7 +518,7 @@ UdpCommandDemuxer::waitForCommandResponseCReq(
|
||||
{
|
||||
const CommandWaitKey key{deviceIp, cmdSet, cmdId};
|
||||
auto wait = std::make_shared<PendingCommandWaitDesc>(
|
||||
key, componentThread->getIoService());
|
||||
key, componentThread->getIoContext());
|
||||
|
||||
{
|
||||
sscl::SpinLock::Guard guard(pendingWaits.lock);
|
||||
@@ -577,10 +577,10 @@ UdpCommandDemuxer::waitForCommandResponseCReq(
|
||||
* request. If the device does not respond within the timeout period,
|
||||
* we will consider the command to have failed.
|
||||
*/
|
||||
boost::asio::io_service &ioService = componentThread->getIoService();
|
||||
boost::asio::io_context &ioContext = componentThread->getIoContext();
|
||||
std::optional<std::shared_ptr<boost::asio::deadline_timer>> raceTimer;
|
||||
auto timerAwaiter = adapters::boostAsio::getDeadlineTimerAReqAwaiter(
|
||||
ioService,
|
||||
ioContext,
|
||||
boost::posix_time::milliseconds(timeoutMs),
|
||||
raceTimer);
|
||||
auto responseInvoker = waitForCommandResponseCReq(cmdSet, cmdId, deviceIp);
|
||||
|
||||
Reference in New Issue
Block a user