What is kqueue EV_RECEIPT?

The kqueue mechanism has an EV_RECEIPT event EV_RECEIPT , which according to the linked man page:

... useful for making massive changes to kqueue without any pending events. When they are passed as input, it causes EV_ERROR always return. When the filter, the successfully added data field will be null.

My understanding, however, is that it is trivial to make massive changes to kqueue without depleting the pending events, simply passing 0 for the nevents parameter to kevent and thus not causing any events from the queue. With that in mind, why is EV_RECEIPT necessary?

Some sample code in the Apple documentation for OS X actually uses EV_RECEIPT:

 kq = kqueue(); EV_SET(&changes, gTargetPID, EVFILT_PROC, EV_ADD | EV_RECEIPT, NOTE_EXIT, 0, NULL); (void) kevent(kq, &changes, 1, &changes, 1, NULL); 

But, seeing that the changes array is never examined after kevent , it is completely incomprehensible to me why EV_RECEIPT was used in this case.

Is EV_RECEIPT really necessary? In what situation will it really be useful?

+5
source share
1 answer

If you make massive changes, and one of them causes an error, then the event will be placed in the eventlist with EV_ERROR set to flags , and the system error in data .

Therefore, you can determine which changelist element caused the error.

If you set nevents to zero, you will receive an error code, but you did not indicate which event caused the error.

Thus, EV_RECEIPT allows you to set nevents to a non-zero value without turning off pending events.

+2
source

All Articles