您好,我是新来的,对netpoll()函数感到困惑。 这东西。当我启动这样的Httpserver时
http.ListenAndServe("127.0.0.1:9988",nil)
println位于 netpoll_kqueue.go:
func netpoll(block bool) *g {
if kq == -1 {
return nil
}
var tp *timespec
var ts timespec
if !block {
tp = &ts
}
var events [64]keventt
retry:
n := kevent(kq, nil, 0, &events[0], int32(len(events)), tp)
println("===============")
if n < 0 {
if n != -_EINTR {
println("runtime: kevent on fd", kq, "failed with", -n)
throw("runtime: netpoll failed")
}
goto retry
}
和
proc.go.sysmon()
asmcgocall(*cgo_yield, nil)
}
// poll network if not polled for more than 10ms
lastpoll := int64(atomic.Load64(&sched.lastpoll))
now := nanotime()
println("+++++++++++++++++++++")
if netpollinited() && lastpoll != 0 && lastpoll+10*1000*1000 < now {
atomic.Cas64(&sched.lastpoll, uint64(lastpoll), uint64(now))
gp := netpoll(false) // non-blocking - returns list of goroutines
if gp != nil {
// Need to decrement number of idle locked M's
// (pretending that one more is running) before i
如前所述,就我而言,应经常调用netpoll()函数。但是,“ ======”和“ ++++++”都只打印一次。而且,仅当我发送请求时,才会打印“ ======”和“ ++++”。根据这种情况,我很困惑,如果netpoll()不是调用系统epoll的函数,而sysmon()不是引发netpoll()的函数,那么谁来做这项工作?
感谢您的帮助