1
0
Fork 0
mirror of https://github.com/ii64/gouring.git synced 2025-04-03 20:45:54 +02:00

feat(syscall): simplify sq initialization

Signed-off-by: Nugraha <26342994+ii64@users.noreply.github.com>
This commit is contained in:
Nugraha 2022-02-10 00:55:02 +07:00
parent 860871629c
commit 76ea6c66e8
Signed by untrusted user who does not match committer: Xeffy
GPG key ID: E41C08AD390E7C49
4 changed files with 104 additions and 0 deletions

15
syscall/epoll.go Normal file
View file

@ -0,0 +1,15 @@
package syscall
import (
"syscall"
"github.com/ii64/gouring"
)
var _ = syscall.EpollCtl
// EpollCtl
func EpollCtl(sqe *gouring.SQEntry, epfd int, op int, fd int, event *syscall.EpollEvent) (err error) {
sqe.Opcode = gouring.IORING_OP_EPOLL_CTL
return nil
}

9
syscall/helper.go Normal file
View file

@ -0,0 +1,9 @@
package syscall
import (
"syscall"
_ "unsafe"
)
//go:linkname anyToSockaddr syscall.anyToSockaddr
func anyToSockaddr(rsa *syscall.RawSockaddrAny) (syscall.Sockaddr, error)

64
syscall/io.go Normal file
View file

@ -0,0 +1,64 @@
package syscall
import (
"syscall"
"unsafe"
"github.com/ii64/gouring"
)
var (
_ = syscall.Accept
_ = syscall.Read
_ = syscall.Write
_ = syscall.Close
)
// Accept
func Accept(sqe *gouring.SQEntry, lisFd int, raw *syscall.RawSockaddrAny) {
sqe.Opcode = gouring.IORING_OP_ACCEPT
sqe.Fd = int32(lisFd)
var len uintptr = syscall.SizeofSockaddrAny
*sqe.Addr2() = uint64(uintptr(unsafe.Pointer(&len)))
*sqe.Addr() = uint64(uintptr(unsafe.Pointer(raw)))
}
// Read
func Read(sqe *gouring.SQEntry, fd int, b []byte) {
sqe.Opcode = gouring.IORING_OP_READ
sqe.Fd = int32(fd)
sqe.Len = uint32(len(b))
*sqe.Addr() = uint64(uintptr(unsafe.Pointer(&b[0])))
}
// Readv
func Readv(sqe *gouring.SQEntry, fd int, iovs []syscall.Iovec) {
sqe.Opcode = gouring.IORING_OP_READV
sqe.Fd = int32(fd)
sqe.Len = uint32(len(iovs))
*sqe.Addr() = uint64(uintptr(unsafe.Pointer(&iovs[0])))
}
// Write
func Write(sqe *gouring.SQEntry, fd int, b []byte) {
sqe.Opcode = gouring.IORING_OP_WRITE
sqe.Fd = int32(fd)
sqe.Len = uint32(len(b))
*sqe.Addr() = uint64(uintptr(unsafe.Pointer(&b[0])))
}
// Writev
func Writev(sqe *gouring.SQEntry, fd int, iovs []syscall.Iovec) {
sqe.Opcode = gouring.IORING_OP_WRITEV
sqe.Fd = int32(fd)
sqe.Len = uint32(len(iovs))
*sqe.Addr() = uint64(uintptr(unsafe.Pointer(&iovs[0])))
}
// Close
func Close(sqe *gouring.SQEntry, fd int) {
sqe.Opcode = gouring.IORING_OP_CLOSE
sqe.Fd = int32(fd)
}

16
syscall/io_test.go Normal file
View file

@ -0,0 +1,16 @@
package syscall
import (
"syscall"
"testing"
"unsafe"
)
func TestAccept(t *testing.T) {
var raw syscall.RawSockaddrAny
t.Logf("%d\n", unsafe.Sizeof(raw))
t.Fail()
}