Allenxuxu / gev

🚀Gev is a lightweight, fast non-blocking TCP network library / websocket server based on Reactor mode. Support custom protocols to quickly and easily build high-performance servers.
MIT License
1.73k stars 194 forks source link

这里为啥要进行一次 handler ? #49

Closed g302ge closed 3 years ago

g302ge commented 3 years ago

https://github.com/Allenxuxu/gev/blob/d13351dc99a4522cda9f5b664cbc387970e8e293/poller/epoll.go#L169

Allenxuxu commented 3 years ago

因为这里 https://github.com/Allenxuxu/gev/blob/d13351dc99a4522cda9f5b664cbc387970e8e293/eventloop/eventloop.go#L124

g302ge commented 3 years ago

so why ?

Allenxuxu commented 3 years ago

https://github.com/Allenxuxu/gev/blob/d13351dc99a4522cda9f5b664cbc387970e8e293/connection/connection.go#L103

func (l *EventLoop) QueueInLoop(f func()) {
    l.mu.Lock()
    l.pendingFunc = append(l.pendingFunc, f)
    l.mu.Unlock()

    if !l.eventHandling.Get() {
        if err := l.poll.Wake(); err != nil {
            log.Error("QueueInLoop Wake loop, ", err)
        }
    }
}

epoll 被唤醒不只是因为对等端有了可读可写事件,可以是 wakefd,这里唤醒 epoll 目的就是为了执行 pendingFunc 。

g302ge commented 3 years ago

是的,但是为啥你唤醒了以后还要处理一下这个事件呢,目的是为了清除 EventFD ?

Allenxuxu commented 3 years ago

去检查一下 有没有需要执行的 pendingFunc

g302ge commented 3 years ago

这样子