remove sd event timers from asio context
This class was only ever intended to be a temporary bridge for
converting sd_event applications to asio. It wasn't intended to be a
long term solution.
This commit gets rid of the class entirely, and opts for
boost::asio::steady_timer.
Change-Id: I2d3e19878f77346f1ccbd92e378fe0739ecf4ad6
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/ssifbridged.cpp b/ssifbridged.cpp
index 4ab1197..dd1533c 100644
--- a/ssifbridged.cpp
+++ b/ssifbridged.cpp
@@ -22,11 +22,14 @@
#include <CLI/CLI.hpp>
#include <boost/algorithm/string/replace.hpp>
-#include <boost/asio.hpp>
+#include <boost/asio/completion_condition.hpp>
+#include <boost/asio/io_context.hpp>
+#include <boost/asio/read.hpp>
+#include <boost/asio/steady_timer.hpp>
+#include <boost/asio/write.hpp>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
-#include <sdbusplus/asio/sd_event.hpp>
#include <sdbusplus/timer.hpp>
#include <iostream>
@@ -90,7 +93,7 @@
int numberOfReqNotRsp;
};
-std::unique_ptr<sdbusplus::Timer> rspTimer __attribute__((init_priority(101)));
+std::unique_ptr<boost::asio::steady_timer> rspTimer;
std::unique_ptr<SsifChannel> ssifchannel = nullptr;
SsifChannel::SsifChannel(std::shared_ptr<boost::asio::io_context>& io,
@@ -152,8 +155,12 @@
return numberOfReqNotRsp;
}
-void rspTimerHandler()
+void rspTimerHandler(const boost::system::error_code& ec)
{
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return;
+ }
std::vector<uint8_t> rsp;
constexpr uint8_t ccResponseNotAvailable = 0xce;
@@ -196,11 +203,11 @@
}
}
-void initTimer()
+void initTimer(boost::asio::io_context& io)
{
if (!rspTimer)
{
- rspTimer = std::make_unique<sdbusplus::Timer>(rspTimerHandler);
+ rspTimer = std::make_unique<boost::asio::steady_timer>(io);
}
}
@@ -228,7 +235,8 @@
/* there is a request coming */
numberOfReqNotRsp++;
/* start response timer */
- rspTimer->start(std::chrono::microseconds(hostReqTimeout), false);
+ rspTimer->expires_after(std::chrono::microseconds(hostReqTimeout));
+ rspTimer->async_wait(rspTimerHandler);
if (verbose)
{
@@ -355,7 +363,7 @@
" cc=" + std::to_string(cc);
log<level::ERR>(msgToLog.c_str());
}
- rspTimer->stop();
+ rspTimer->cancel();
},
ipmiQueueService, ipmiQueuePath, ipmiQueueIntf, ipmiQueueMethod,
dbusTimeout, netfn, lun, cmd, data, options);
@@ -372,17 +380,9 @@
app.add_option("-v,--verbose", verbose, "print more verbose output");
CLI11_PARSE(app, argc, argv);
- // Connect to system bus
auto io = std::make_shared<boost::asio::io_context>();
- sd_bus* dbus;
- sd_bus_default_system(&dbus);
- /* This might be a sdbusplus::Timer bug, without timer t2, rspTimer
- * will not work
- */
- sdbusplus::Timer t2([]() { ; });
- t2.start(std::chrono::microseconds(500000), true);
- auto bus = std::make_shared<sdbusplus::asio::connection>(*io, dbus);
+ auto bus = std::make_shared<sdbusplus::asio::connection>(*io);
bus->request_name(ssifBus);
// Create the SSIF channel, listening on D-Bus and on the SSIF device
ssifchannel = make_unique<SsifChannel>(io, bus, device, verbose,
@@ -391,8 +391,7 @@
{
return EXIT_FAILURE;
}
- initTimer();
- sdbusplus::asio::sd_event_wrapper sdEvents(*io);
+ initTimer(*io);
io->run();
return 0;