何时在Golang中调用netpoll()

时间:2018-07-19 07:00:04

标签: go epoll

您好,我是新来的,对netpoll()函数感到困惑。 这东西。当我启动这样的Httpserver时

http.ListenAndServe("127.0.0.1:9988",nil)

就我而言,应该有一个gorouting或线程,或者其他一些epoll事情来检查套接字事件。原因在MAC上进行即时测试,相关的运行时代码在“ netpoll_kqueue.go”中。该函数由sysmon()调用。为了调试,我添加了一些“ println”以打印出相关信息。

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()的函数,那么谁来做这项工作?

感谢您的帮助

0 个答案:

没有答案