virtual ~KQueueEngine();
bool AddFd(EventHandler* eh, int event_mask);
void OnSetEvent(EventHandler* eh, int old_mask, int new_mask);
- virtual bool DelFd(EventHandler* eh, bool force = false);
+ virtual void DelFd(EventHandler* eh);
virtual int DispatchEvents();
virtual std::string GetName();
virtual void RecoverFromFork();
size_t len;
mib[0] = CTL_KERN;
- mib[1] = KERN_MAXFILES;
+ mib[1] = KERN_MAXFILESPERPROC;
len = sizeof(MAX_DESCRIPTORS);
sysctl(mib, 2, &MAX_DESCRIPTORS, &len, NULL, 0);
if (MAX_DESCRIPTORS <= 0)
return true;
}
-bool KQueueEngine::DelFd(EventHandler* eh, bool force)
+void KQueueEngine::DelFd(EventHandler* eh)
{
int fd = eh->GetFd();
if ((fd < 0) || (fd > GetMaxFds() - 1))
{
ServerInstance->Logs->Log("SOCKET",DEFAULT,"DelFd() on invalid fd: %d", fd);
- return false;
+ return;
}
struct kevent ke;
EV_SET(&ke, eh->GetFd(), EVFILT_READ, EV_DELETE, 0, 0, NULL);
int j = kevent(EngineHandle, &ke, 1, 0, 0, NULL);
- if ((j < 0) && !force)
+ if (j < 0)
{
ServerInstance->Logs->Log("SOCKET",DEFAULT,"Failed to remove fd: %d %s",
fd, strerror(errno));
- return false;
}
CurrentSetSize--;
ref[fd] = NULL;
ServerInstance->Logs->Log("SOCKET",DEBUG,"Remove file descriptor: %d", fd);
- return true;
}
void KQueueEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
const int bits_to_clr = FD_WANT_SINGLE_WRITE | FD_WANT_FAST_WRITE | FD_WRITE_WILL_BLOCK;
SetEventMask(eh, eh->GetEventMask() & ~bits_to_clr);
eh->HandleEvent(EVENT_WRITE);
+
+ if (eh != ref[ke_list[j].ident])
+ // whoops, deleted out from under us
+ continue;
}
if (ke_list[j].filter == EVFILT_READ)
{