void TMultiplexingServer::epollClose(int fd) { tf_epoll_ctl(epollFd, EPOLL_CTL_DEL, fd, NULL); TF_CLOSE(fd); recvBuffers.remove(fd); QQueue<THttpSendBuffer*> que = sendBuffers.take(fd); for (QListIterator<THttpSendBuffer*> it(que); it.hasNext(); ) { delete it.next(); } pendingRequests.removeAll(fd); }
int TMultiplexingServer::epollDel(int fd) { int ret = tf_epoll_ctl(epollFd, EPOLL_CTL_DEL, fd, NULL); int err = errno; if (ret < 0 && err != ENOENT) { tSystemError("Failed epoll_ctl (EPOLL_CTL_DEL) fd:%d errno:%d", fd, errno); epollClose(fd); } else { tSystemDebug("OK epoll_ctl (EPOLL_CTL_DEL) fd:%d", fd); } return ret; }
int TMultiplexingServer::epollModify(int fd, int events) { struct epoll_event ev; memset(&ev, 0, sizeof(ev)); ev.events = events; ev.data.fd = fd; int ret = tf_epoll_ctl(epollFd, EPOLL_CTL_MOD, fd, &ev); if (ret < 0) { tSystemError("Failed epoll_ctl (EPOLL_CTL_MOD) fd:%d errno:%d", fd, errno); epollClose(fd); } else { tSystemDebug("OK epoll_ctl (EPOLL_CTL_MOD) fd:%d", fd); } return ret; }
bool TEpoll::deletePoll(TEpollSocket *socket) { if (Q_UNLIKELY(pollingSockets.remove(socket) == 0)) { return false; } int ret = tf_epoll_ctl(epollFd, EPOLL_CTL_DEL, socket->socketDescriptor(), nullptr); int err = errno; if (Q_UNLIKELY(ret < 0 && err != ENOENT)) { tSystemError("Failed epoll_ctl (EPOLL_CTL_DEL) sd:%d errno:%d", socket->socketDescriptor(), err); } else { tSystemDebug("OK epoll_ctl (EPOLL_CTL_DEL) sd:%d", socket->socketDescriptor()); } return !ret; }
int TMultiplexingServer::epollAdd(int fd, int events) { struct epoll_event ev; memset(&ev, 0, sizeof(ev)); ev.events = events; ev.data.fd = fd; int ret = tf_epoll_ctl(epollFd, EPOLL_CTL_ADD, fd, &ev); int err = errno; if (ret < 0 && err != EEXIST) { tSystemError("Failed epoll_ctl (EPOLL_CTL_ADD) fd:%d errno:%d", fd, errno); epollClose(fd); } else { //tSystemDebug("OK epoll_ctl (EPOLL_CTL_ADD) (events:%d) fd:%d", events, fd); } return ret; }
bool TEpoll::modifyPoll(TEpollSocket *socket, int events) { if (Q_UNLIKELY(!events)) { return false; } struct epoll_event ev; ev.events = events; ev.data.ptr = socket; int ret = tf_epoll_ctl(epollFd, EPOLL_CTL_MOD, socket->socketDescriptor(), &ev); int err = errno; if (Q_UNLIKELY(ret < 0)) { tSystemError("Failed epoll_ctl (EPOLL_CTL_MOD) sd:%d errno:%d ev:0x%x", socket->socketDescriptor(), err, events); } else { tSystemDebug("OK epoll_ctl (EPOLL_CTL_MOD) sd:%d", socket->socketDescriptor()); } return !ret; }
bool TEpoll::addPoll(TEpollSocket *socket, int events) { if (Q_UNLIKELY(!events)) { return false; } struct epoll_event ev; ev.events = events; ev.data.ptr = socket; int ret = tf_epoll_ctl(epollFd, EPOLL_CTL_ADD, socket->socketDescriptor(), &ev); int err = errno; if (Q_UNLIKELY(ret < 0)){ if (err != EEXIST) { tSystemError("Failed epoll_ctl (EPOLL_CTL_ADD) sd:%d errno:%d", socket->socketDescriptor(), err); } } else { tSystemDebug("OK epoll_ctl (EPOLL_CTL_ADD) (events:%u) sd:%d", events, socket->socketDescriptor()); pollingSockets.insert(socket, socket->socketId()); } return !ret; }