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