gaio: github.com/xtaci/gaio Index | Files

package gaio

import "github.com/xtaci/gaio"

Package gaio is an Async-IO library for Golang.

gaio acts in proactor mode, https://en.wikipedia.org/wiki/Proactor_pattern. User submit async IO operations and waits for IO-completion signal.

Index

Package Files

aio_generic.go aio_linux.go time.go watcher.go

Variables

var (
    // ErrUnsupported means the watcher cannot support this type of connection
    ErrUnsupported = errors.New("unsupported connection type")
    // ErrNoRawConn means the connection has not implemented SyscallConn
    ErrNoRawConn = errors.New("net.Conn does implement net.RawConn")
    // ErrWatcherClosed means the watcher is closed
    ErrWatcherClosed = errors.New("watcher closed")
    // ErrPollerClosed suggest that poller has closed
    ErrPollerClosed = errors.New("poller closed")
    // ErrConnClosed means the user called Free() on related connection
    ErrConnClosed = errors.New("connection closed")
    // ErrDeadline means the specific operation has exceeded deadline before completion
    ErrDeadline = errors.New("operation exceeded deadline")
    // ErrEmptyBuffer means the buffer is nil
    ErrEmptyBuffer = errors.New("empty buffer")
)

type OpResult Uses

type OpResult struct {
    // Operation Type
    Operation OpType
    // User context associated with this requests
    Context interface{}
    // Related net.Conn to this result
    Conn net.Conn
    // Buffer points to user's supplied buffer or watcher's internal swap buffer
    Buffer []byte
    // IsSwapBuffer marks true if the buffer internal one
    IsSwapBuffer bool
    // Number of bytes sent or received, Buffer[:Size] is the content sent or received.
    Size int
    // IO error,timeout error
    Error error
}

OpResult is the result of an aysnc-io

type OpType Uses

type OpType int

OpType defines Operation Type

const (
    // OpRead means the aiocb is a read operation
    OpRead OpType = iota
    // OpWrite means the aiocb is a write operation
    OpWrite
)

type Watcher Uses

type Watcher struct {
    // contains filtered or unexported fields
}

Watcher will monitor events and process async-io request(s),

func NewWatcher Uses

func NewWatcher() (*Watcher, error)

NewWatcher creates a management object for monitoring file descriptors with default internal buffer size - 64KB

func NewWatcherSize Uses

func NewWatcherSize(bufsize int) (*Watcher, error)

NewWatcherSize creates a management object for monitoring file descriptors. 'bufsize' sets the internal swap buffer size for Read() with nil, 2 slices with'bufsize' will be allocated for performance.

func (Watcher) Close Uses

func (w Watcher) Close() (err error)

Close stops monitoring on events for all connections

func (Watcher) Free Uses

func (w Watcher) Free(conn net.Conn) error

Free let the watcher to release resources related to this conn immediately, like socket file descriptors.

func (Watcher) Read Uses

func (w Watcher) Read(ctx interface{}, conn net.Conn, buf []byte) error

Read submits an async read request on 'fd' with context 'ctx', using buffer 'buf'. 'buf' can be set to nil to use internal buffer. 'ctx' is the user-defined value passed through the gaio watcher unchanged.

func (Watcher) ReadFull Uses

func (w Watcher) ReadFull(ctx interface{}, conn net.Conn, buf []byte, deadline time.Time) error

ReadFull submits an async read request on 'fd' with context 'ctx', using buffer 'buf', and expects to fill the buffer before 'deadline'. 'ctx' is the user-defined value passed through the gaio watcher unchanged. 'buf' can't be nil in ReadFull.

func (Watcher) ReadTimeout Uses

func (w Watcher) ReadTimeout(ctx interface{}, conn net.Conn, buf []byte, deadline time.Time) error

ReadTimeout submits an async read request on 'fd' with context 'ctx', using buffer 'buf', and expects to read some bytes into the buffer before 'deadline'. 'ctx' is the user-defined value passed through the gaio watcher unchanged.

func (Watcher) WaitIO Uses

func (w Watcher) WaitIO() (r []OpResult, err error)

WaitIO blocks until any read/write completion, or error. An internal 'buf' returned or 'r []OpResult' are safe to use BEFORE next call to WaitIO().

func (Watcher) Write Uses

func (w Watcher) Write(ctx interface{}, conn net.Conn, buf []byte) error

Write submits an async write request on 'fd' with context 'ctx', using buffer 'buf'. 'ctx' is the user-defined value passed through the gaio watcher unchanged.

func (Watcher) WriteTimeout Uses

func (w Watcher) WriteTimeout(ctx interface{}, conn net.Conn, buf []byte, deadline time.Time) error

WriteTimeout submits an async write request on 'fd' with context 'ctx', using buffer 'buf', and expects to complete writing the buffer before 'deadline', 'buf' can be set to nil to use internal buffer. 'ctx' is the user-defined value passed through the gaio watcher unchanged.

Package gaio imports 11 packages (graph). Updated 2020-03-22. Refresh now. Tools for package owners.