github.com/cbeuw/gotfo@v0.0.0-20180331191851-f2b091af84de/fd_poll_runtime_go18.go (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build go1.8,!go1.9 6 7 package gotfo 8 9 import ( 10 "runtime" 11 "sync" 12 "syscall" 13 _ "unsafe" 14 ) 15 16 //go:linkname runtime_pollServerInit net.runtime_pollServerInit 17 func runtime_pollServerInit() 18 19 //go:linkname runtime_pollOpen net.runtime_pollOpen 20 func runtime_pollOpen(fd uintptr) (uintptr, int) 21 22 //go:linkname runtimeNano net.runtimeNano 23 func runtimeNano() int64 24 25 //go:linkname runtime_pollClose net.runtime_pollClose 26 func runtime_pollClose(ctx uintptr) 27 28 //go:linkname runtime_pollWait net.runtime_pollWait 29 func runtime_pollWait(ctx uintptr, mode int) int 30 31 //go:linkname runtime_pollWaitCanceled net.runtime_pollWaitCanceled 32 func runtime_pollWaitCanceled(ctx uintptr, mode int) int 33 34 //go:linkname runtime_pollReset net.runtime_pollReset 35 func runtime_pollReset(ctx uintptr, mode int) int 36 37 //go:linkname runtime_pollSetDeadline net.runtime_pollSetDeadline 38 func runtime_pollSetDeadline(ctx uintptr, d int64, mode int) 39 40 //go:linkname runtime_pollUnblock net.runtime_pollUnblock 41 func runtime_pollUnblock(ctx uintptr) 42 43 //go:linkname runtime_Semacquire net.runtime_Semacquire 44 func runtime_Semacquire(sema *uint32) 45 46 //go:linkname runtime_Semrelease net.runtime_Semrelease 47 func runtime_Semrelease(sema *uint32) 48 49 type pollDesc struct { 50 runtimeCtx uintptr 51 } 52 53 var serverInit sync.Once 54 55 func (pd *pollDesc) init(fd *netFD) error { 56 serverInit.Do(runtime_pollServerInit) 57 ctx, errno := runtime_pollOpen(uintptr(fd.sysfd)) 58 runtime.KeepAlive(fd) 59 if errno != 0 { 60 return syscall.Errno(errno) 61 } 62 pd.runtimeCtx = ctx 63 return nil 64 }