package runtime
import (
)
var (
epfd int32 = -1
netpollEventFd uintptr
netpollWakeSig atomic.Uint32
)
func () {
var uintptr
epfd, = syscall.EpollCreate1(syscall.EPOLL_CLOEXEC)
if != 0 {
println("runtime: epollcreate failed with", )
throw("runtime: netpollinit failed")
}
, := syscall.Eventfd(0, syscall.EFD_CLOEXEC|syscall.EFD_NONBLOCK)
if != 0 {
println("runtime: eventfd failed with", -)
throw("runtime: eventfd failed")
}
:= syscall.EpollEvent{
Events: syscall.EPOLLIN,
}
*(**uintptr)(unsafe.Pointer(&.Data)) = &netpollEventFd
= syscall.EpollCtl(epfd, syscall.EPOLL_CTL_ADD, , &)
if != 0 {
println("runtime: epollctl failed with", )
throw("runtime: epollctl failed")
}
netpollEventFd = uintptr()
}
func ( uintptr) bool {
return == uintptr(epfd) || == netpollEventFd
}
func ( uintptr, *pollDesc) uintptr {
var syscall.EpollEvent
.Events = syscall.EPOLLIN | syscall.EPOLLOUT | syscall.EPOLLRDHUP | syscall.EPOLLET
:= taggedPointerPack(unsafe.Pointer(), .fdseq.Load())
*(*taggedPointer)(unsafe.Pointer(&.Data)) =
return syscall.EpollCtl(epfd, syscall.EPOLL_CTL_ADD, int32(), &)
}
func ( uintptr) uintptr {
var syscall.EpollEvent
return syscall.EpollCtl(epfd, syscall.EPOLL_CTL_DEL, int32(), &)
}
func ( *pollDesc, int) {
throw("runtime: unused")
}
func () {
if !netpollWakeSig.CompareAndSwap(0, 1) {
return
}
var uint64 = 1
:= int32(unsafe.Sizeof())
for {
:= write(netpollEventFd, noescape(unsafe.Pointer(&)), )
if == {
break
}
if == -_EINTR {
continue
}
if == -_EAGAIN {
return
}
println("runtime: netpollBreak write failed with", -)
throw("runtime: netpollBreak write failed")
}
}
func ( int64) (gList, int32) {
if epfd == -1 {
return gList{}, 0
}
var int32
if < 0 {
= -1
} else if == 0 {
= 0
} else if < 1e6 {
= 1
} else if < 1e15 {
= int32( / 1e6)
} else {
= 1e9
}
var [128]syscall.EpollEvent
:
, := syscall.EpollWait(epfd, [:], int32(len()), )
if != 0 {
if != _EINTR {
println("runtime: epollwait on fd", epfd, "failed with", )
throw("runtime: netpoll failed")
}
if > 0 {
return gList{}, 0
}
goto
}
var gList
:= int32(0)
for := int32(0); < ; ++ {
:= []
if .Events == 0 {
continue
}
if *(**uintptr)(unsafe.Pointer(&.Data)) == &netpollEventFd {
if .Events != syscall.EPOLLIN {
println("runtime: netpoll: eventfd ready for", .Events)
throw("runtime: netpoll: eventfd ready for something unexpected")
}
if != 0 {
var uint64
read(int32(netpollEventFd), noescape(unsafe.Pointer(&)), int32(unsafe.Sizeof()))
netpollWakeSig.Store(0)
}
continue
}
var int32
if .Events&(syscall.EPOLLIN|syscall.EPOLLRDHUP|syscall.EPOLLHUP|syscall.EPOLLERR) != 0 {
+= 'r'
}
if .Events&(syscall.EPOLLOUT|syscall.EPOLLHUP|syscall.EPOLLERR) != 0 {
+= 'w'
}
if != 0 {
:= *(*taggedPointer)(unsafe.Pointer(&.Data))
:= (*pollDesc)(.pointer())
:= .tag()
if .fdseq.Load() == {
.setEventErr(.Events == syscall.EPOLLERR, )
+= netpollready(&, , )
}
}
}
return ,
}