diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6443d73 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Ii64人 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 58fda85..875a5de 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,79 @@ # gouring -Low-lavel io uring library + +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) +[![Go Reference](https://pkg.go.dev/badge/github.com/ii64/gouring.svg)](https://pkg.go.dev/github.com/ii64/gouring) + +Low-level io uring library ``` go get github.com/ii64/gouring -``` \ No newline at end of file +``` + +## Example + +```go +import "github.com/ii64/gouring" +import "github.com/ii64/gouring/queue" + +// io_uring_setup +ring, err := gouring.New(256, nil) // default io uring setup param +if err != nil { + // ... +} +defer ring.Close() // munmap shared memory, cleanup +var ( + ret int + err error +) + +// io_uring_register +ret, err = ring.Register(gouring.IORING_REGISTER_BUFFERS, addr, nrArg) + +// io_uring_enter +ret, err = ring.Enter(toSubmit, minComplete, gouring.IORING_ENTER_GETEVENTS, nil) + +// setup param +params := ring.Params() + +// ring fd +fd := ring.Fd() + +// Submission Queue +sq := ring.SQ() + +// Completion Queue +cq := ring.CQ() + +/* Using queue package */ +q := queue.New(ring) +go func() { + q.Run(func(cqe *gouring.CQEntry) { + // cqe processing + _ = cqe.UserData + _ = cqe.Res + _ = cqe.Flags + }) +}() + +// buffer +data := []byte("print on stdout\n") + +// get sqe +sqe := q.GetSQEntry() +sqe.UserData = 0 // identifier / event id +sqe.Opcode = gouring.IORING_OP_WRITE // op write +sqe.Fd = int32(syscall.Stdout) // fd 1 +sqe.Len = uint32(len(data)) // buffer size +sqe.SetOffset(0) // fd offset +sqe.SetAddr(&data[0]) // buffer addr + +// submit sqe +submitted, err := q.Submit() +if err != nil { + // ... +} +``` + +### Referece +[github.com/iceber/iouring-go](https://github.com/iceber/iouring-go) \ No newline at end of file