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

Commit 7b2bb9cc authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk
Browse files

Implement add/remove membership for Netlink sockets

Change-Id: Ib98f14b1d758ee7b4d464b359d4792c3ca7027b0
Test: with other b/169681573 changes
Bug: 169681573
parent abf79902
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -162,6 +162,26 @@ pollfd Socket::preparePoll(short events) {
    return {mFd.get(), events, 0};
}

bool Socket::addMembership(unsigned group) {
    const auto res =
            setsockopt(mFd.get(), SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &group, sizeof(group));
    if (res < 0) {
        PLOG(ERROR) << "Failed joining multicast group " << group;
        return false;
    }
    return true;
}

bool Socket::dropMembership(unsigned group) {
    const auto res =
            setsockopt(mFd.get(), SOL_NETLINK, NETLINK_DROP_MEMBERSHIP, &group, sizeof(group));
    if (res < 0) {
        PLOG(ERROR) << "Failed leaving multicast group " << group;
        return false;
    }
    return true;
}

Socket::receive_iterator::receive_iterator(Socket& socket, bool end)
    : mSocket(socket), mIsEnd(end) {
    if (!end) receive();
+16 −0
Original line number Diff line number Diff line
@@ -191,6 +191,22 @@ class Socket {
     */
    pollfd preparePoll(short events = 0);

    /**
     * Join a multicast group.
     *
     * \param group Group ID (*not* a bitfield)
     * \return whether the operation succeeded
     */
    bool addMembership(unsigned group);

    /**
     * Leave a multicast group.
     *
     * \param group Group ID (*not* a bitfield)
     * \return whether the operation succeeded
     */
    bool dropMembership(unsigned group);

    /**
     * Live iterator continuously receiving messages from Netlink socket.
     *