dongwen7730 2018-07-19 07:00
浏览 277

何时在Golang中调用netpoll()

Hi there, Im new Goer and confused by the netpoll() function. Heres the thing. When I start a Httpserver like this

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

as far as I concerned, there should be a gorouting or thread or something else do the epoll things to check the socket events. Cause Im testing on MAC, the related runtime code is in "netpoll_kqueue.go". This func is called by the sysmon(). In order to debug, I add some "println" to print out the related information.

The println is in 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
}

and

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

As mentioned before, as far as I concerned, the netpoll() function should been called frequently. However, both "======" and "++++++" are printed only once. And, only when I send a request, the "======" and "++++" are printed. It confused me a lot, according to the scenario, if the netpoll() is not the function to call system epoll and sysmon() is not the function to raise netpoll() then who do the job?

Appreciate your help

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料