feat(docs): update readme, added license

Signed-off-by: MastahSenpai <26342994+ii64@users.noreply.github.com>
This commit is contained in:
MastahSenpai 2021-12-22 00:32:32 +07:00
parent b4adb24416
commit 173732c949
Signed by untrusted user who does not match committer: Xeffy
GPG key ID: E41C08AD390E7C49
2 changed files with 95 additions and 2 deletions

21
LICENSE Normal file
View file

@ -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.

View file

@ -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
```
```
## 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)