0

I'm writing a PCI linux driver that handles an interrupt and sends a notification to the user-space program with netlink socket. It works, but user-space program is blocked while waiting for an event( nl_recvmsgs_default() function ). Is it possible to handle an event without blocking and using poll/epoll?

static int nl_cb_func( struct nl_msg* , void* )
{
    std::cerr << "Sync input" << std::endl;
    return NL_OK;
}

int main()
{
    std::cerr << "test netlink start" << std:: endl;
    static struct nl_sock* gNlSock = NULL;
    gNlSock = nl_socket_alloc();
    nl_socket_disable_seq_check( gNlSock );
    nl_socket_set_nonblocking( gNlSock );
    nl_socket_modify_cb( gNlSock, NL_CB_VALID, NL_CB_CUSTOM, nl_cb_func, NULL );
    nl_connect( gNlSock, NETLINK_USERSOCK );
    nl_socket_add_membership( gNlSock, NL_GROUP_ID );


    while ( true ) {
        nl_recvmsgs_default( gNlSock );
    }


    nl_socket_free( gNlSock );

    return 0;
}
  • I don't know about netlink, but you could easily do this with eventfd. Check `vfio_pci_intrs.c` for an example. – a3f Apr 02 '18 at 12:06
  • Can it works like a user-space interrupt which I can handle in any time? Could you write an example code? – Токарев Виталий Apr 05 '18 at 10:56
  • It's used in `vfio_pci_intrs.c` for notifying userspace PCI drivers of interrupts, which sounds like what you want. I haven't used it myself, so can't write an answer. – a3f Apr 06 '18 at 13:12

0 Answers0