Documentation
¶
Overview ¶
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 ¶
- 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 interface{}, conn net.Conn, buf []byte) error
- func (w Watcher) ReadFull(ctx interface{}, conn net.Conn, buf []byte, deadline time.Time) error
- func (w Watcher) ReadTimeout(ctx interface{}, conn net.Conn, buf []byte, deadline time.Time) error
- func (w Watcher) SetLoopAffinity(cpuid int) (err error)
- func (w Watcher) SetPollerAffinity(cpuid int) (err error)
- func (w Watcher) WaitIO() (r []OpResult, err error)
- func (w Watcher) Write(ctx interface{}, conn net.Conn, buf []byte) error
- func (w Watcher) WriteTimeout(ctx interface{}, 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 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") // 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 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 Signal ¶ added in v1.2.20
type Signal struct {
// contains filtered or unexported fields
}
Signal is a package of events when you've done with events, you should send a signal to done channel.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher will monitor events and process async-io request(s),
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 on 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.
