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;
}