I want to be notified when an USB mouse is disconnected (not just having the read fail). I use epoll with the flags
EPOLLIN | EPOLLERR | EPOLLRDHUP | EPOLLET
I used
read(fd, struct input_event, sizeof input_event)
I wait for events from the mouse. All is good and working fine, until I click on a mouse button. This generates two events at the same time. One is the EV_MSC/MSC_SCAN event and the other is EV_KEY/BTN_LEFT. If I read only one event (ie. read with buffer of len 24) I get another EPOLL notication and the the read gets the EV_MSC event again. If I read with a buffer of size 48 I get both events.
What is the correct way to handle this case. Should I not keep on reading until I get EAGAIN in the read event handler?