+ std::map<int, unsigned int>::iterator it = fd_mappings.find(fd);
+ if (it == fd_mappings.end())
+ {
+ ServerInstance->Logs->Log("SOCKET",DEBUG,"DelFd() on unknown fd: %d", fd);
+ return false;
+ }
+
+ unsigned int index = it->second;
+ unsigned int last_index = CurrentSetSize - 1;
+ int last_fd = events[last_index].fd;
+
+ if (index != last_index)
+ {
+ // We need to move the last fd we got into this gap (gaps are evil!)
+
+ // So update the mapping for the last fd to its new position
+ fd_mappings[last_fd] = index;
+
+ // move last_fd from last_index into index
+ events[index].fd = last_fd;
+ events[index].events = events[last_index].events;
+
+ ref[index] = ref[last_index];
+ }
+
+ // Now remove all data for the last fd we got into out list.
+ // Above code made sure this always is right
+ fd_mappings.erase(it);
+ events[last_index].fd = 0;
+ events[last_index].events = 0;
+ ref[last_index] = NULL;