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:
kadmin
2021-07-08 20:55:09 +00:00
committed by Josh Bleecher Snyder
parent c0deb1c65e
commit 07374071d0
2 changed files with 31 additions and 0 deletions

View 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
}

View File

@@ -0,0 +1,11 @@
// +build linux
package uring
import (
"testing"
)
func TestUringAvailable(t *testing.T) {
uringSupported()
}