| 1 |
//go:build go1.12 |
| 2 |
// +build go1.12 |
| 3 |
|
| 4 |
package cap |
| 5 |
|
| 6 |
import "os" |
| 7 |
|
| 8 |
// fd returns the file descriptor of the file. This is a little more |
| 9 |
// elaborate than using file.Fd() as it works around Go's default of |
| 10 |
// locking system calls to threads when functions get raw access to |
| 11 |
// their file descriptor. We judge that behavior to not be needed in |
| 12 |
// our limited use case and don't want to burden applications with the |
| 13 |
// corresponding resource overhead of that thread pinning. |
| 14 |
// |
| 15 |
// See https://sites.google.com/site/fullycapable/getting-started-with-go/some-go-gotchas-with-psx-and-cap-packages |
| 16 |
func fd(file *os.File) uintptr { |
| 17 |
s, err := file.SyscallConn() |
| 18 |
if err != nil { |
| 19 |
return ^uintptr(0) |
| 20 |
} |
| 21 |
var exported uintptr |
| 22 |
s.Control(func(fd uintptr) { |
| 23 |
exported = fd |
| 24 |
}) |
| 25 |
return exported |
| 26 |
} |