From a679c63de8c84dbd322fcfdafc65186f2ed1533d Mon Sep 17 00:00:00 2001 From: lesismal Date: Tue, 25 Jun 2024 00:43:32 +0800 Subject: [PATCH] epoll: ET without ONESHOT add events once only --- poller_epoll.go | 68 ++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/poller_epoll.go b/poller_epoll.go index 793e99b0..5039d6b9 100644 --- a/poller_epoll.go +++ b/poller_epoll.go @@ -328,21 +328,25 @@ func (p *poller) resetRead(fd int) error { func (p *poller) setRead(op int, fd int) error { switch p.g.EpollMod { case EPOLLET: - return syscall.EpollCtl( - p.epfd, - op, - fd, - &syscall.EpollEvent{ - Fd: int32(fd), - Events: syscall.EPOLLERR | - syscall.EPOLLHUP | - syscall.EPOLLRDHUP | - syscall.EPOLLPRI | - syscall.EPOLLIN | - EPOLLET | - p.g.EPOLLONESHOT, - }, - ) + events := syscall.EPOLLERR | + syscall.EPOLLHUP | + syscall.EPOLLRDHUP | + syscall.EPOLLPRI | + syscall.EPOLLIN | + EPOLLET | + p.g.EPOLLONESHOT + if p.g.EPOLLONESHOT != EPOLLONESHOT { + if op == syscall.EPOLL_CTL_ADD { + return syscall.EpollCtl(p.epfd, op, fd, &syscall.EpollEvent{ + Fd: int32(fd), + Events: events | syscall.EPOLLOUT, + }) + } + } + return syscall.EpollCtl(p.epfd, op, fd, &syscall.EpollEvent{ + Fd: int32(fd), + Events: events, + }) default: return syscall.EpollCtl( p.epfd, @@ -371,20 +375,26 @@ func (p *poller) addReadWrite(fd int) error { func (p *poller) setReadWrite(op int, fd int) error { switch p.g.EpollMod { case EPOLLET: - return syscall.EpollCtl( - p.epfd, op, fd, - &syscall.EpollEvent{ - Fd: int32(fd), - Events: syscall.EPOLLERR | - syscall.EPOLLHUP | - syscall.EPOLLRDHUP | - syscall.EPOLLPRI | - syscall.EPOLLIN | - syscall.EPOLLOUT | - EPOLLET | - p.g.EPOLLONESHOT, - }, - ) + events := syscall.EPOLLERR | + syscall.EPOLLHUP | + syscall.EPOLLRDHUP | + syscall.EPOLLPRI | + syscall.EPOLLIN | + syscall.EPOLLOUT | + EPOLLET | + p.g.EPOLLONESHOT + if p.g.EPOLLONESHOT != EPOLLONESHOT { + if op == syscall.EPOLL_CTL_ADD { + return syscall.EpollCtl(p.epfd, op, fd, &syscall.EpollEvent{ + Fd: int32(fd), + Events: events, + }) + } + } + return syscall.EpollCtl(p.epfd, op, fd, &syscall.EpollEvent{ + Fd: int32(fd), + Events: events, + }) default: return syscall.EpollCtl( p.epfd, op, fd,