mirror of
https://github.com/tailscale/tailscale.git
synced 2026-04-04 06:36:01 -04:00
net/uring: add probing capability
Adds the ability to probe for various capabilities. It will not call into C unless necessary. It also allocates one probe per call to new capability, which may be expensive, so in theory they could be reused instead. Signed-off-by: kadmin <julianknodt@gmail.com>
This commit is contained in:
committed by
Josh Bleecher Snyder
parent
c0deb1c65e
commit
07374071d0
20
net/uring/capability_linux.go
Normal file
20
net/uring/capability_linux.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package uring
|
||||
|
||||
// #cgo CFLAGS: -I${SRCDIR}/liburing/src/include
|
||||
// #cgo LDFLAGS: -L${SRCDIR}/liburing/src/ -luring
|
||||
// #include "io_uring.c"
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// hasUring reports whether it is possible to use io_uring syscalls on the system.
|
||||
func uringSupported() bool {
|
||||
probe, err := C.io_uring_get_probe()
|
||||
if err == nil && probe != nil {
|
||||
C.free(unsafe.Pointer(probe))
|
||||
}
|
||||
return err != syscall.ENOSYS
|
||||
}
|
||||
11
net/uring/io_uring_test.go
Normal file
11
net/uring/io_uring_test.go
Normal file
@@ -0,0 +1,11 @@
|
||||
// +build linux
|
||||
|
||||
package uring
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUringAvailable(t *testing.T) {
|
||||
uringSupported()
|
||||
}
|
||||
Reference in New Issue
Block a user