Get remove events for client-initiated disconnect?
I may well be missing something, but the only way I can see for a client to initiate a disconnection is to call ei_unref. However, once that has been done, one can no longer call ei_dispatch
or ei_get_event
. In general, libei seems to take care to ensure each "ADDED" event has a matching "REMOVED" event. E.g., if the connection is severed, libei will (according to the documentation) ensure that "REMOVED" events are generated for all devices and seats before generating a "DISCONNECT" event. This is very helpful for resource management, as one can, e.g., allocate user data for each device in the "ADDED" event and then free it in the "REMOVED" event. However, it is made much less helpful by the fact that there is (again, as far as I can tell) no way to receive those events if the client is initiating the disconnection.
Would it be possible to add an ei_disconnect
method that, when called, would trigger a disconnect and cause all of the relevant "REMOVED" and "DISCONNECT" events to be delivered to the client?
In an ideal world, the events would be available immediately so the following would be guaranteed to get all of the "REMOVED" events and "DISCONNECT" without waiting:
ei_disconnect(context);
ei_dispatch(context);
while (event = ei_get_event) {
// ...
}
However, it would be okay if the code needed to continue polling the fd until the "DISCONNECT" event is received.