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 ¶
- Variables
- type OpResult
- type OpType
- type Watcher
- func (w Watcher) Close() (err error)
- func (w Watcher) Free(conn net.Conn) error
- 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) 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 ¶
This section is empty.
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") )
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 Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher will monitor events and process async-io request(s),
func NewWatcher ¶
NewWatcher creates a management object for monitoring file descriptors with default internal buffer size - 64KB
func NewWatcherSize ¶
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 ¶
func (w Watcher) Close() (err error)
Close stops monitoring on events for all connections
func (Watcher) Free ¶
Free let the watcher to release resources related to this conn immediately, like socket file descriptors.
func (Watcher) Read ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.