mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
Implement add/remove membership for Netlink sockets
Change-Id: Ib98f14b1d758ee7b4d464b359d4792c3ca7027b0 Test: with other b/169681573 changes Bug: 169681573
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user