bool KQueueEngine::AddFd(EventHandler* eh) { int fd = eh->GetFd(); if ((fd < 0) || (fd > MAX_DESCRIPTORS)) { ServerInstance->Log(DEFAULT,"ERROR: FD of %d added above max of %d",fd,MAX_DESCRIPTORS); return false; } if (GetRemainingFds() <= 1) { ServerInstance->Log(DEFAULT,"ERROR: System out of file descriptors!"); return false; } if (ref[fd]) return false; ref[fd] = eh; ServerInstance->Log(DEBUG,"Add socket %d",fd); struct kevent ke; ServerInstance->Log(DEBUG,"kqueue: Add socket to events, kq=%d socket=%d",EngineHandle,fd); EV_SET(&ke, fd, eh->Readable() ? EVFILT_READ : EVFILT_WRITE, EV_ADD, 0, 0, NULL); int i = kevent(EngineHandle, &ke, 1, 0, 0, NULL); if (i == -1) { ServerInstance->Log(DEBUG,"kqueue: List insertion failure!"); return false; } CurrentSetSize++; return true; }
bool PortsEngine::AddFd(EventHandler* eh) { int fd = eh->GetFd(); if ((fd < 0) || (fd > GetMaxFds() - 1)) return false; if (GetRemainingFds() <= 1) return false; if (ref[fd]) return false; ref[fd] = eh; port_associate(EngineHandle, PORT_SOURCE_FD, fd, eh->Readable() ? POLLRDNORM : POLLWRNORM, eh); ServerInstance->Logs->Log("SOCKET",DEBUG,"New file descriptor: %d", fd); CurrentSetSize++; return true; }
bool SelectEngine::AddFd(EventHandler* eh) { int fd = eh->GetFd(); if ((fd < 0) || (fd > MAX_DESCRIPTORS)) return false; if (GetRemainingFds() <= 1) return false; if (ref[fd]) return false; fds[fd] = fd; ref[fd] = eh; CurrentSetSize++; ServerInstance->Log(DEBUG,"New file descriptor: %d", fd); return true; }
bool PollEngine::AddFd(EventHandler* eh) { int fd = eh->GetFd(); if ((fd < 0) || (fd > GetMaxFds() - 1)) { ServerInstance->Logs->Log("SOCKET",DEBUG,"AddFd out of range: (fd: %d, max: %d)", fd, GetMaxFds()); return false; } if (GetRemainingFds() <= 1) { ServerInstance->Logs->Log("SOCKET",DEBUG,"No remaining FDs cannot add fd: %d", fd); return false; } if (fd_mappings.find(fd) != fd_mappings.end()) { ServerInstance->Logs->Log("SOCKET",DEBUG,"Attempt to add duplicate fd: %d", fd); return false; } unsigned int index = CurrentSetSize; fd_mappings[fd] = index; ref[index] = eh; events[index].fd = fd; if (eh->Readable()) { events[index].events = POLLIN; } else { events[index].events = POLLOUT; } ServerInstance->Logs->Log("SOCKET", DEBUG,"New file descriptor: %d (%d; index %d)", fd, events[fd].events, index); CurrentSetSize++; return true; }