Skip to content

Commit

Permalink
netlink: improved event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmm committed Sep 10, 2024
1 parent 04717a6 commit 9e175b5
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/netlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,10 @@ void Netlink::subscribe() const {
}

void Netlink::handle_events() {
// std::vector<char> buff(getpagesize());
char buff[4096];
std::vector<char> buff(getpagesize());
sockaddr_nl addr{};
iovec iov[1];

iov[0].iov_base = buff;
// iov[0].iov_len = sizeof(char) * buff.size();
iov[0].iov_len = sizeof(buff);

msghdr msg_hdr{.msg_name = &addr,
.msg_namelen = sizeof(addr),
.msg_iov = iov,
Expand All @@ -97,6 +92,9 @@ void Netlink::handle_events() {
.msg_controllen = 0,
.msg_flags = 0};

iov[0].iov_base = buff.data();
iov[0].iov_len = sizeof(char) * buff.size();

auto input_file = std::filesystem::temp_directory_path() / std::filesystem::path{"fastgame.json"};

while (listen) {
Expand All @@ -107,15 +105,15 @@ void Netlink::handle_events() {
auto len = recvmsg(nl_socket, &msg_hdr, 0);

if (len == -1) {
util::warning("len == -1");
continue;
}

if (addr.nl_pid != 0) { // https://linux.die.net/man/7/netlink
continue;
}

// auto* nlmsg_hdr = reinterpret_cast<nlmsghdr*>(buff.data());
auto* nlmsg_hdr = reinterpret_cast<nlmsghdr*>(buff);
auto* nlmsg_hdr = reinterpret_cast<nlmsghdr*>(buff.data());

while (NLMSG_OK(nlmsg_hdr, len)) {
if (!std::filesystem::is_regular_file(input_file)) {
Expand Down

0 comments on commit 9e175b5

Please sign in to comment.