- WSANETWORKEVENTS network_events;
- if (WSAEnumNetworkEvents(io->fd, io->event, &network_events) != 0)
- return false;
- if (network_events.lNetworkEvents & WRITE_EVENTS)
- io->cb(io->data, IO_WRITE);
- if (network_events.lNetworkEvents & READ_EVENTS)
- io->cb(io->data, IO_READ);
+ if (io->fd == -1) {
+ io->cb(io->data, 0);
+ } else {
+ WSANETWORKEVENTS network_events;
+ if (WSAEnumNetworkEvents(io->fd, io->event, &network_events) != 0)
+ return false;
+ if (network_events.lNetworkEvents & WRITE_EVENTS)
+ io->cb(io->data, IO_WRITE);
+ if (network_events.lNetworkEvents & READ_EVENTS)
+ io->cb(io->data, IO_READ);
+ }