- }
- 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 (ev->GetFd(), &wfdset))
- {
- WriteEvents++;
- writeable[ev->GetFd()] = false;
- ev->HandleEvent(EVENT_WRITE);
- }
- if (FD_ISSET (ev->GetFd(), &rfdset))
- {
- ReadEvents++;
- ev->HandleEvent(EVENT_READ);
- }
- }
+ }
+
+ 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);