News Priviw

Switch to the dark mode that's kinder on your eyes at night time.

Switch to the light mode that's kinder on your eyes at day time.

Menu

News Priviw

Menu
in

Provides easy-to-use async IO interface with io_uring



io_uring

io_uring-wahtsnew

LWN io_uring

Lord of the io_uring

【译】高性能异步 IO —— io_uring (Effecient IO with io_uring)

Go 与异步 IO – io_uring 的思考

  • register a file set for io_uring instance
  • support file IO
  • support socket IO
  • support IO timeout
  • link request
  • set timer
  • add request extra info, could get it from the result
  • set logger
  • register buffers and IO with buffers
  • support SQPoll
go get github.com/iceber/iouring-go

doc

<div class=”highlight highlight-source-go position-relative” data-snippet-clipboard-copy-content=”package main

import (
” fmt” “os” “github.com iceber iouring-go” ) var str=”io with iouring” func main() { iour, err := iouring.New(1) if err != nil { panic(fmt.Sprintf(“new IOURing error: %v”, err)) } defer iour.Close() file, err := os.Create(“./tmp.txt”) if err != nil { panic(err) } ch := make(chan iouring.Result, 1) prepRequest := iouring.Write(int(file.Fd()), []byte(str)) if _, err := iour.SubmitRequest(prepRequest, ch); err != nil { panic(err) } result :=

package main

import (
        "fmt"
        "os"

        "github.com/iceber/iouring-go"
)

var str = "io with iouring"

func main() {
        iour, err := iouring.New(1)
        if err != nil {
                panic(fmt.Sprintf("new IOURing error: %v", err))
        }
        defer iour.Close()

        file, err := os.Create("./tmp.txt")
        if err != nil {
                panic(err)
        }

        ch := make(chan iouring.Result, 1)

        prepRequest := iouring.Write(int(file.Fd()), []byte(str))
        if _, err := iour.SubmitRequest(prepRequest, ch); err != nil {
                panic(err)
        }

        result := <-ch
        i, err := result.ReturnInt()
        if err != nil {
                fmt.Println("write error: ", err)
                return
        }

        fmt.Printf("write byte: %dn", i)
}

<div class=”highlight highlight-source-go position-relative” data-snippet-clipboard-copy-content=”prepRequest := iouring.Write(int(file.Fd()), []byte(str)).WithInfo(file.Name())

request, err := iour.SubmitRequest(prepRequest, nil)
if err != nil {
panic(err)
}

prepRequest := iouring.Write(int(file.Fd()), []byte(str)).WithInfo(file.Name())

request, err := iour.SubmitRequest(prepRequest, nil)
if err != nil {
    panic(err)
}

<- request.Done()
info, ok := request.GetRequestInfo().(string)

<div class=”highlight highlight-source-go position-relative” data-snippet-clipboard-copy-content=”prepR := iouring.Timeout(5 * time.Second)
request, err := iour.SubmitRequest(prepR, nil)
if err != nil {
panic(err)
}

if _, err := request.Cancel(); err != nil{
fmt.Printf(” cancel request error: %vn”, err) return }

prepR := iouring.Timeout(5 * time.Second)
request, err := iour.SubmitRequest(prepR, nil)
if err != nil {
    panic(err)
}

if _, err := request.Cancel(); err != nil{
    fmt.Printf("cancel request error: %vn", err)
    return
}

<- request.Done()
if err := request.Err(); err != nil{
    if err == iouring.ErrRequestCanceled{
        fmt.Println("request is canceled"0
        return
    }
    fmt.Printf("request error: %vn", err)
    return
}

<div class=”highlight highlight-source-go position-relative” data-snippet-clipboard-copy-content=”var offset uint64
buf1 := make([]byte, 1024)
prep1:= iouring.Pread(fd, buf1, offset)

offset += 1024
buf2 := make([]byte, 1024)
prep2:= iouring.Pread(fd, buf1, offset)

requests, err := iour.SubmitRequests([]iouring.PrepRequest{prep1,prep2}, nil)
if err != nil{
panic(err)
}

var offset uint64
buf1 := make([]byte, 1024)
prep1:= iouring.Pread(fd, buf1, offset)

offset += 1024
buf2 := make([]byte, 1024)
prep2:= iouring.Pread(fd, buf1, offset)

requests, err := iour.SubmitRequests([]iouring.PrepRequest{prep1,prep2}, nil)
if err != nil{
    panic(err)
}
<- requests.Done()
fmt.Println("requests are completed")
var offset uint64
buf := make([]byte, 1024)
prep1 := iouring.Pread(fd, buf1, offset)
prep2 := iouring.Write(int(os.Stdout.Fd()), buf)

iour.SubmitLinkRequests([]iouring.PrepRequest{prep1, prep2}, nil)




Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

GIPHY App Key not set. Please check settings

Hailey Bieber, Travis Barker, Billy Porter, And More Will Present At The 2021 VMAs thumbnail

Hailey Bieber, Travis Barker, Billy Porter, And More Will Present At The 2021 VMAs

Description Basic Recon tool for beginners in python

Back to Top

Log In

Forgot password?

Forgot password?

Enter your account data and we will send you a link to reset your password.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Your password reset link appears to be invalid or expired.

Log in

Privacy Policy

To use social login you have to agree with the storage and handling of your data by this website. %privacy_policy%

Add to Collection

No Collections

Here you'll find all collections you've created before.