- if (network_events.lNetworkEvents & READ_EVENTS)
- io->cb(io->data, IO_READ);
- /*
- The fd might be available for write too. However, if we already fired the read callback, that
- callback might have deleted the io (e.g. through terminate_connection()), so we can't fire the
- write callback here. Instead, we loop back and let the writable io loop above handle it.
- */
+ }
+
+ /* Look up io in the map by index. */
+ event_index = result - WSA_WAIT_EVENT_0 + event_offset;
+ io_t *io = io_map[event_index];
+
+ if(io->fd == -1) {
+ io->cb(io->data, 0);
+
+ if(curgen != io_tree.generation) {
+ break;
+ }
+ } else {
+ WSANETWORKEVENTS network_events;
+
+ if(WSAEnumNetworkEvents(io->fd, io->event, &network_events) != 0) {
+ return(false);
+ }
+
+ if(network_events.lNetworkEvents & READ_EVENTS) {
+ io->cb(io->data, IO_READ);
+
+ if(curgen != io_tree.generation) {
+ break;
+ }
+ }
+
+ /*
+ The fd might be available for write too. However, if we already fired the read callback, that
+ callback might have deleted the io (e.g. through terminate_connection()), so we can't fire the
+ write callback here. Instead, we loop back and let the writable io loop above handle it.
+ */
+ }
+
+ /* Continue checking the rest of the events. */
+ event_offset = event_index + 1;
+
+ /* Just poll the next time through. */
+ timeout_ms = 0;