func netpoll(block bool) gList {
	timeout := int32(0)
	if !block {
		timeout = 0
		return gList{}
	}
	if pollVerbose {
		println("*** netpoll", block)
	}
retry:
	lock(&mtxpoll)
	lock(&mtxset)
	pendingUpdates = 0
	unlock(&mtxpoll)

	if pollVerbose {
		println("*** netpoll before poll")
	}
	n := libc_poll(&pfds[0], int32(len(pfds)), timeout)
	if pollVerbose {
		println("*** netpoll after poll", n)
	}
	if n < 0 {
		e := errno()
		if e != _EINTR {
			println("errno=", e, " len(pfds)=", len(pfds))
			throw("poll failed")
		}
		if pollVerbose {
			println("*** poll failed")
		}
		unlock(&mtxset)
		goto retry
	}
	// Check if some descriptors need to be changed
	if n != 0 && pfds[0].revents&(_POLLIN|_POLLHUP|_POLLERR) != 0 {
		var b [1]byte
		for read(rdwake, unsafe.Pointer(&b[0]), 1) == 1 {
			if pollVerbose {
				println("*** read 1 byte from pipe")
			}
		}
		// Do not look at the other fds in this case as the mode may have changed
		// XXX only additions of flags are made, so maybe it is ok
		unlock(&mtxset)
		goto retry
	}
	var toRun gList
	for i := 0; i < len(pfds) && n > 0; i++ {
		pfd := &pfds[i]

		var mode int32
		if pfd.revents&(_POLLIN|_POLLHUP|_POLLERR) != 0 {
			mode += 'r'
			pfd.events &= ^_POLLIN
		}
		if pfd.revents&(_POLLOUT|_POLLHUP|_POLLERR) != 0 {
			mode += 'w'
			pfd.events &= ^_POLLOUT
		}
		if mode != 0 {
			if pollVerbose {
				println("*** netpollready i=", i, "revents=", pfd.revents, "events=", pfd.events, "pd=", pds[i])
			}
			netpollready(&toRun, pds[i], mode)
			n--
		}
	}
	unlock(&mtxset)
	if block && toRun.empty() {
		goto retry
	}
	if pollVerbose {
		println("*** netpoll returning end")
	}
	return toRun
}
// polls for ready network connections
// returns list of goroutines that become runnable
//go:nowritebarrierrec
polls for ready network connections
returns list of goroutines that become runnable
go:nowritebarrierrec
// polls for ready network connections // returns list of goroutines that become runnable // go : nowritebarrierrec
func netpoll(block bool) gList {
	timeout := int32(0)
	if !block {
		timeout = 0
		return gList{}
	}
	if pollVerbose {
		println("*** netpoll", block)
	}
retry:
	lock(&mtxpoll)
	lock(&mtxset)
	pendingUpdates = 0
	unlock(&mtxpoll)
	if pollVerbose {
		println("*** netpoll before poll")
	}
	n := libc_poll(&pfds[0], int32(len(pfds)), timeout)
	if pollVerbose {
		println("*** netpoll after poll", n)
	}
	if n < 0 {
		e := errno()
		if e != _EINTR {
			println("errno=", e, " len(pfds)=", len(pfds))
			throw("poll failed")
		}
		if pollVerbose {
			println("*** poll failed")
		}
		unlock(&mtxset)
		goto retry
	}
	if n != 0 && pfds[0].revents&(_POLLIN|_POLLHUP|_POLLERR) != 0 {
		var b [1]byte
		for read(rdwake, unsafe.Pointer(&b[0]), 1) == 1 {
			if pollVerbose {
				println("*** read 1 byte from pipe")
			}
		}
		unlock(&mtxset)
		goto retry
	}
	var toRun gList
	for i := 0; i < len(pfds) && n > 0; i++ {
		pfd := &pfds[i]
		var mode int32
		if pfd.revents&(_POLLIN|_POLLHUP|_POLLERR) != 0 {
			mode += 'r'
			pfd.events &= ^_POLLIN
		}
		if pfd.revents&(_POLLOUT|_POLLHUP|_POLLERR) != 0 {
			mode += 'w'
			pfd.events &= ^_POLLOUT
		}
		if mode != 0 {
			if pollVerbose {
				println("*** netpollready i=", i, "revents=", pfd.revents, "events=", pfd.events, "pd=", pds[i])
			}
			netpollready(&toRun, pds[i], mode)
			n--
		}
	}
	unlock(&mtxset)
	if block && toRun.empty() {
		goto retry
	}
	if pollVerbose {
		println("*** netpoll returning end")
	}
	return toRun
}
func netpoll ( block bool ) gList { timeout := int32 ( 0 ) if ! block { timeout = 0 return gList { } } if pollVerbose { println ( " " , block ) } retry : lock ( & mtxpoll ) lock ( & mtxset ) pendingUpdates = 0 unlock ( & mtxpoll ) if pollVerbose { println ( " " ) } n := libc_poll ( & pfds [ 0 ] , int32 ( len ( pfds ) ) , timeout ) if pollVerbose { println ( " " , n ) } if n < 0 { e := errno ( ) if e != _EINTR { println ( " " , e , " " , len ( pfds ) ) throw ( " " ) } if pollVerbose { println ( " " ) } unlock ( & mtxset ) goto retry } if n != 0 && pfds [ 0 ] . revents & ( _POLLIN | _POLLHUP | _POLLERR ) != 0 { var b [ 1 ] byte for read ( rdwake , unsafe . Pointer ( & b [ 0 ] ) , 1 ) == 1 { if pollVerbose { println ( " " ) } } unlock ( & mtxset ) goto retry } var toRun gList for i := 0 ; i < len ( pfds ) && n > 0 ; i ++ { pfd := & pfds [ i ] var mode int32 if pfd . revents & ( _POLLIN | _POLLHUP | _POLLERR ) != 0 { mode += 'r' pfd . events &= ^ _POLLIN } if pfd . revents & ( _POLLOUT | _POLLHUP | _POLLERR ) != 0 { mode += 'w' pfd . events &= ^ _POLLOUT } if mode != 0 { if pollVerbose { println ( " " , i , " " , pfd . revents , " " , pfd . events , " " , pds [ i ] ) } netpollready ( & toRun , pds [ i ] , mode ) n -- } } unlock ( & mtxset ) if block && toRun . empty ( ) { goto retry } if pollVerbose { println ( " " ) } return toRun }
polls for ready network connections
returns list of goroutines that become runnable
go:nowritebarrierrec
polls for ready network connections returns list of goroutines that become runnable go : nowritebarrierrec
// Check if some descriptors need to be changed // Do not look at the other fds in this case as the mode may have changed // XXX only additions of flags are made, so maybe it is ok