- }
- else
- {
- /* NOTE: This is a pair of seperate if statements as the socket
- * may be in both read and writeable state at the same time.
- * If an error event occurs above it is not worth processing the
- * read and write states even if set.
- */
- if (FD_ISSET (i, &rfdset))
- {
- ReadEvents++;
- SetEventMask(ev, ev->GetEventMask() & ~FD_READ_WILL_BLOCK);
- ev->HandleEvent(EVENT_READ);
- if (ev != ref[i])
- continue;
- }
- if (FD_ISSET (i, &wfdset))
- {
- WriteEvents++;
- SetEventMask(ev, ev->GetEventMask() & ~(FD_WRITE_WILL_BLOCK | FD_WANT_SINGLE_WRITE));
- ev->HandleEvent(EVENT_WRITE);
- }
- }
+ }
+
+ if (has_write)
+ {
+ stats.WriteEvents++;
+ int newmask = (ev->GetEventMask() & ~(FD_WRITE_WILL_BLOCK | FD_WANT_SINGLE_WRITE));
+ SocketEngine::OnSetEvent(ev, ev->GetEventMask(), newmask);
+ ev->SetEventMask(newmask);
+ ev->HandleEvent(EVENT_WRITE);