Documentation
¶
Overview ¶
Package gaio is an asynchronous I/O library for Go.
gaio acts in proactor mode, https://en.wikipedia.org/wiki/Proactor_pattern. Users submit async I/O operations and wait for completion signals.
Index ¶
- Constants
- Variables
- type OpResult
- type OpType
- type Signal
- type Watcher
- func (w Watcher) Close() (err error)
- func (w Watcher) Free(conn net.Conn) error
- func (w Watcher) GetGC() (found uint32, closed uint32)
- func (w Watcher) Read(ctx any, conn net.Conn, buf []byte) error
- func (w Watcher) ReadFull(ctx any, conn net.Conn, buf []byte, deadline time.Time) error
- func (w Watcher) ReadTimeout(ctx any, conn net.Conn, buf []byte, deadline time.Time) error
- func (w Watcher) SetLoopAffinity(cpuid int) error
- func (w Watcher) SetPollerAffinity(cpuid int) error
- func (w Watcher) WaitIO() (r []OpResult, err error)
- func (w Watcher) Write(ctx any, conn net.Conn, buf []byte) error
- func (w Watcher) WriteTimeout(ctx any, conn net.Conn, buf []byte, deadline time.Time) error
Constants ¶
const ( EV_READ = 0x1 EV_WRITE = 0x2 )
Variables ¶
var ( // ErrUnsupported means the watcher cannot support this type of connection ErrUnsupported = errors.New("unsupported connection type") // ErrNoRawConn means the connection does not implement SyscallConn ErrNoRawConn = errors.New("net.Conn does implement net.RawConn") // ErrWatcherClosed means the watcher is closed ErrWatcherClosed = errors.New("watcher closed") // ErrPollerClosed suggests that the poller has closed ErrPollerClosed = errors.New("poller closed") // ErrConnClosed means the user called Free() on the related connection ErrConnClosed = errors.New("connection closed") // ErrDeadline means the operation exceeded its deadline before completion ErrDeadline = errors.New("operation exceeded deadline") // ErrEmptyBuffer means the buffer is empty ErrEmptyBuffer = errors.New("empty buffer") // ErrCPUID indicates the given cpuid is invalid ErrCPUID = errors.New("no such core") )
Functions ¶
This section is empty.
Types ¶
type OpResult ¶
type OpResult struct {
// Operation Type
Operation OpType
// User context associated with this request
Context any
// 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 is an internal swap buffer
IsSwapBuffer bool
// Number of bytes sent or received, Buffer[:Size] is the content sent or received.
Size int
// I/O error or timeout error
Error error
}
OpResult is the result of an async I/O operation.
type Signal ¶ added in v1.2.20
type Signal struct {
// contains filtered or unexported fields
}
Signal packages events; when processing is done, signal on the done channel.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher monitors events and processes async I/O requests.
func NewWatcher ¶ added in v1.0.11
NewWatcher creates a new Watcher instance with a default internal buffer size of 64KB.
func NewWatcherSize ¶ added in v1.1.7
NewWatcherSize creates a new Watcher instance with a specified internal buffer size.
It allocates three shared buffers of the given size for handling read requests. This allows efficient management of read operations by using pre-allocated buffers.
func (Watcher) Close ¶
func (w Watcher) Close() (err error)
Close stops monitoring events for all connections.
func (Watcher) Free ¶ added in v1.1.0
Free releases resources related to 'conn' immediately, such as socket file descriptors.
func (Watcher) Read ¶
Read submits an asynchronous read request on 'conn' with context 'ctx' and optional buffer 'buf'. If 'buf' is nil, an internal buffer is used. 'ctx' is a user-defined value passed unchanged.
func (Watcher) ReadFull ¶ added in v1.2.7
ReadFull submits an asynchronous read request on 'conn' with context 'ctx' and buffer 'buf', expecting to fill the buffer before 'deadline'. 'ctx' is a user-defined value passed unchanged. 'buf' must not be nil for ReadFull.
func (Watcher) ReadTimeout ¶ added in v1.0.6
ReadTimeout submits an asynchronous read request on 'conn' with context 'ctx' and buffer 'buf', expecting to read some bytes before 'deadline'. 'ctx' is a user-defined value passed unchanged.
func (Watcher) SetLoopAffinity ¶ added in v1.2.10
Set loop affinity for syscall.Read/syscall.Write.
func (Watcher) SetPollerAffinity ¶ added in v1.2.10
Set poller affinity for epoll/kqueue.
func (Watcher) WaitIO ¶ added in v1.0.5
WaitIO blocks until one or more read/write operations are completed or an error occurs. It returns a slice of OpResult containing details of completed operations and any errors encountered.
The method operates as follows: 1. It recycles previously used aiocb objects to avoid memory leaks and reuse them for new I/O operations. 2. It waits for completion notifications from the chResults channel and accumulates results. 3. It ensures that the buffer in OpResult is not overwritten until the next call to WaitIO.
func (Watcher) Write ¶
Write submits an asynchronous write request on 'conn' with context 'ctx' and buffer 'buf'. 'ctx' is a user-defined value passed unchanged.
func (Watcher) WriteTimeout ¶ added in v1.0.6
WriteTimeout submits an asynchronous write request on 'conn' with context 'ctx' and buffer 'buf', expecting to complete writing before 'deadline'. 'ctx' is a user-defined value passed unchanged.

