I added some very basic event handling code for ptpip.c (in the ptp2 camlib). A more complete implementation would also handle Cancel_Transaction, Ping, and Pong and only return Event to the user. (Right now it ignores those other commands but it makes sure not to try to return them to the user).
In order for ptp_ptpip_event to work correctly, ptp_ptpip_check_event() should be removed, as right now it just dumps events. I did not remove it because it might break compatibility.
I also made a change in ptp_ptpip_getresp() from:
n = (dtoh32(hdr.length) - ptpip_resp_param1)/sizeof(uint32_t);
n = (dtoh32(hdr.length) - sizeof(hdr) - ptpip_resp_param1)/sizeof(uint32_t);
I believe the intent there was to get the number of paramaters based on the size of the header, however right now it seems to ignore the fact that hdr.length also contains the size of the header itself. I did not look too much into this so someone should double check this.
Finally in ptp_ptpip_connect(), I moved the connect() for evtfd above ptp_ptpip_init_command_request() because on the device I was working on (Playstation Vita), the commands socket refuses to send data until the events socket is also connected. I don't know if other devices may do this too or if it breaks any compatibility.