github.com/cbeuw/gotfo@v0.0.0-20180331191851-f2b091af84de/fd_poll_runtime_go19.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.9 6 7 // Note: internal/poll.FD renamed to pollFD 8 // Note: isFile param is ignored 9 10 package gotfo 11 12 import ( 13 "sync" 14 "syscall" 15 _ "unsafe" 16 ) 17 18 //go:linkname runtime_pollServerInit internal/poll.runtime_pollServerInit 19 func runtime_pollServerInit() 20 21 //go:linkname runtime_pollOpen internal/poll.runtime_pollOpen 22 func runtime_pollOpen(fd uintptr) (uintptr, int) 23 24 //go:linkname runtimeNano internal/poll.runtimeNano 25 func runtimeNano() int64 26 27 //go:linkname runtime_pollClose internal/poll.runtime_pollClose 28 func runtime_pollClose(ctx uintptr) 29 30 //go:linkname runtime_pollWait internal/poll.runtime_pollWait 31 func runtime_pollWait(ctx uintptr, mode int) int 32 33 //go:linkname runtime_pollWaitCanceled internal/poll.runtime_pollWaitCanceled 34 func runtime_pollWaitCanceled(ctx uintptr, mode int) int 35 36 //go:linkname runtime_pollReset internal/poll.runtime_pollReset 37 func runtime_pollReset(ctx uintptr, mode int) int 38 39 //go:linkname runtime_pollSetDeadline internal/poll.runtime_pollSetDeadline 40 func runtime_pollSetDeadline(ctx uintptr, d int64, mode int) 41 42 //go:linkname runtime_pollUnblock internal/poll.runtime_pollUnblock 43 func runtime_pollUnblock(ctx uintptr) 44 45 //go:linkname runtime_Semacquire internal/poll.runtime_Semacquire 46 func runtime_Semacquire(sema *uint32) 47 48 //go:linkname runtime_Semrelease internal/poll.runtime_Semrelease 49 func runtime_Semrelease(sema *uint32) 50 51 type pollDesc struct { 52 runtimeCtx uintptr 53 } 54 55 var serverInit sync.Once 56 57 func (pd *pollDesc) init(fd *netFD) error { 58 serverInit.Do(runtime_pollServerInit) 59 ctx, errno := runtime_pollOpen(uintptr(fd.sysfd)) 60 if errno != 0 { 61 if ctx != 0 { 62 runtime_pollUnblock(ctx) 63 runtime_pollClose(ctx) 64 } 65 return syscall.Errno(errno) 66 } 67 pd.runtimeCtx = ctx 68 return nil 69 }