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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
    • ¥30 eclipse开启服务后,网页无法打开
    • ¥30 雷达辐射源信号参考模型
    • ¥15 html+css+js如何实现这样子的效果?
    • ¥15 STM32单片机自主设计
    • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
    • ¥15 不小心不正规的开发公司导致不给我们y码,
    • ¥15 我的代码无法在vc++中运行呀,错误很多
    • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
    • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000