summaryrefslogtreecommitdiffstats
path: root/sd_event_loop.cpp
diff options
context:
space:
mode:
authorVernon Mauery <vernon.mauery@linux.intel.com>2018-10-24 13:52:22 -0700
committerVernon Mauery <vernon.mauery@linux.intel.com>2018-12-11 16:39:05 +0000
commitcbccb05ab1ea1a9ad23cd8204722044122a49595 (patch)
treed07595edc71b2360ec52f40437d68540b3d56e87 /sd_event_loop.cpp
parent99b878493c8864e284bf8970134c7847af65b05b (diff)
downloadphosphor-net-ipmid-cbccb05ab1ea1a9ad23cd8204722044122a49595.tar.gz
phosphor-net-ipmid-cbccb05ab1ea1a9ad23cd8204722044122a49595.zip
netipmid: move event loop to boost::asio::io_context
Replacing the event loop with asio provides for more flexibility and less code than the sd_event model. Intially, this will require the loop to handle both sd_events with a wrapper, but after all the sd_event sources are replaced with asio event sources the wrapper can be removed. Change-Id: Icf020c6c26a214bb1239641733c89603501c0c49 Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
Diffstat (limited to 'sd_event_loop.cpp')
-rw-r--r--sd_event_loop.cpp49
1 files changed, 17 insertions, 32 deletions
diff --git a/sd_event_loop.cpp b/sd_event_loop.cpp
index aa5224a..c6ad063 100644
--- a/sd_event_loop.cpp
+++ b/sd_event_loop.cpp
@@ -8,7 +8,9 @@
#include <sys/socket.h>
#include <systemd/sd-daemon.h>
+#include <boost/asio/io_context.hpp>
#include <phosphor-logging/log.hpp>
+#include <sdbusplus/asio/sd_event.hpp>
namespace eventloop
{
@@ -170,35 +172,29 @@ static int retryTimerHandler(sd_event_source* s, uint64_t usec, void* userdata)
return 0;
}
-int EventLoop::startEventLoop(sd_event* events)
+int EventLoop::startEventLoop()
{
int fd = -1;
int r = 0;
int listen_fd;
sigset_t ss;
sd_event_source* source = nullptr;
- auto bus = ipmid_get_sd_bus_connection();
- event = events;
- // Attach the bus to sd_event to service user requests
- r = sd_bus_attach_event(bus, event, SD_EVENT_PRIORITY_NORMAL);
- if (r < 0)
- {
- goto finish;
- }
+ sdbusplus::asio::sd_event_wrapper sdEvents(*io);
+ event = sdEvents.get();
if (sigemptyset(&ss) < 0 || sigaddset(&ss, SIGTERM) < 0 ||
sigaddset(&ss, SIGINT) < 0)
{
r = -errno;
- goto finish;
+ return EXIT_FAILURE;
}
/* Block SIGTERM first, so that the event loop can handle it */
if (sigprocmask(SIG_BLOCK, &ss, nullptr) < 0)
{
r = -errno;
- goto finish;
+ return EXIT_FAILURE;
}
/* Let's make use of the default handler and "floating" reference features
@@ -206,13 +202,13 @@ int EventLoop::startEventLoop(sd_event* events)
r = sd_event_add_signal(event, nullptr, SIGTERM, nullptr, nullptr);
if (r < 0)
{
- goto finish;
+ return EXIT_FAILURE;
}
r = sd_event_add_signal(event, nullptr, SIGINT, nullptr, nullptr);
if (r < 0)
{
- goto finish;
+ return EXIT_FAILURE;
}
// Create our own socket if SysD did not supply one.
@@ -224,7 +220,7 @@ int EventLoop::startEventLoop(sd_event* events)
else if (listen_fd > 1)
{
log<level::ERR>("Too many file descriptors received");
- goto finish;
+ return 1;
}
else
{
@@ -233,7 +229,7 @@ int EventLoop::startEventLoop(sd_event* events)
{
r = -errno;
log<level::ERR>("Unable to manually open socket");
- goto finish;
+ return EXIT_FAILURE;
}
address.sin_family = AF_INET;
@@ -244,35 +240,24 @@ int EventLoop::startEventLoop(sd_event* events)
{
r = -errno;
log<level::ERR>("Unable to bind socket");
- goto finish;
+ close(fd);
+ return EXIT_FAILURE;
}
}
r = sd_event_add_io(event, &source, fd, EPOLLIN, udp623Handler, nullptr);
if (r < 0)
{
- goto finish;
+ close(fd);
+ return EXIT_FAILURE;
}
udpIPMI.reset(source);
source = nullptr;
- r = sd_event_loop(event);
-
-finish:
-
- if (fd >= 0)
- {
- (void)close(fd);
- }
-
- if (r < 0)
- {
- log<level::ERR>("Event Loop Failure:",
- entry("FAILURE=%s", strerror(-r)));
- }
+ io->run();
- return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}
void EventLoop::startHostConsole(const sol::CustomFD& fd)
OpenPOWER on IntegriCloud