- if ((FD_ISSET (a->second, &rfdset)) || (FD_ISSET (a->second, &wfdset)))
- fdlist[result++] = a->second;
+ if ((FD_ISSET (a->second, &rfdset)) || (FD_ISSET (a->second, &wfdset)) || FD_ISSET (a->second, &errfdset))
+ {
+ ev[result++] = ref[a->second];
+ }
+ }
+ }
+
+ /** An event handler may remove its own descriptor from the list, therefore it is not
+ * safe to directly iterate over the list and dispatch events there with STL iterators.
+ * Thats a shame because it makes this code slower and more resource intensive, but maybe
+ * the user should stop using select(), as select() smells anyway.
+ */
+ for (int i = 0; i < result; i++)
+ {
+ if (ev[i])
+ {
+ if (FD_ISSET (ev[i]->GetFd(), &errfdset))
+ {
+ if (ev[i])
+ {
+ if (getsockopt(ev[i]->GetFd(), SOL_SOCKET, SO_ERROR, &errcode, &codesize) < 0)
+ errcode = errno;
+
+ ev[i]->HandleEvent(EVENT_ERROR, errcode);
+ }
+ continue;
+ }
+ if (ev[i])
+ {
+ if (writeable[ev[i]->GetFd()])
+ {
+ if (ev[i])
+ ev[i]->HandleEvent(EVENT_WRITE);
+ writeable[ev[i]->GetFd()] = false;
+
+ }
+ else
+ {
+ if (ev[i])
+ ev[i]->HandleEvent(ev[i]->Readable() ? EVENT_READ : EVENT_WRITE);
+ }
+ }