Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 37bbf800 authored by Mark Salyzyn's avatar Mark Salyzyn
Browse files

init: epoll: add events argument to RegisterHandler

Allow caller to specify events other than EPOLLIN default.

Test: boot
Bug: 124072565
Change-Id: Id4e582a6abc74c5fdb26fea7dcbd3ba2150dadd6
parent 92dcfb31
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#include "epoll.h"

#include <stdint.h>
#include <sys/epoll.h>

#include <chrono>
@@ -37,13 +38,16 @@ Result<Success> Epoll::Open() {
    return Success();
}

Result<Success> Epoll::RegisterHandler(int fd, std::function<void()> handler) {
Result<Success> Epoll::RegisterHandler(int fd, std::function<void()> handler, uint32_t events) {
    if (!events) {
        return Error() << "Must specify events";
    }
    auto [it, inserted] = epoll_handlers_.emplace(fd, std::move(handler));
    if (!inserted) {
        return Error() << "Cannot specify two epoll handlers for a given FD";
    }
    epoll_event ev;
    ev.events = EPOLLIN;
    ev.events = events;
    // std::map's iterators do not get invalidated until erased, so we use the
    // pointer to the std::function in the map directly for epoll_ctl.
    ev.data.ptr = reinterpret_cast<void*>(&it->second);
+5 −1
Original line number Diff line number Diff line
@@ -17,6 +17,9 @@
#ifndef _INIT_EPOLL_H
#define _INIT_EPOLL_H

#include <stdint.h>
#include <sys/epoll.h>

#include <chrono>
#include <functional>
#include <map>
@@ -34,7 +37,8 @@ class Epoll {
    Epoll();

    Result<Success> Open();
    Result<Success> RegisterHandler(int fd, std::function<void()> handler);
    Result<Success> RegisterHandler(int fd, std::function<void()> handler,
                                    uint32_t events = EPOLLIN);
    Result<Success> UnregisterHandler(int fd);
    Result<Success> Wait(std::optional<std::chrono::milliseconds> timeout);