Documentation
¶
Overview ¶
Package iox provides non-blocking I/O helpers that extend Go's standard io semantics with explicit non-failure control-flow errors (see ErrWouldBlock, ErrMore) while remaining compatible with standard library interfaces.
IDE note: iox re-exports (aliases) the core io interfaces so that users can stay in the "iox" namespace while reading documentation and navigating types. The contracts below mirror the standard io expectations, with iox-specific behavior documented where relevant (typically at call sites such as Copy).
Index ¶
- Variables
- func Copy(dst Writer, src Reader) (written int64, err error)
- func CopyBuffer(dst Writer, src Reader, buf []byte) (written int64, err error)
- func CopyN(dst Writer, src Reader, n int64) (written int64, err error)
- func CopyNBuffer(dst Writer, src Reader, n int64, buf []byte) (written int64, err error)
- func IsMore(err error) bool
- func IsNonFailure(err error) bool
- func IsProgress(err error) bool
- func IsSemantic(err error) bool
- func IsWouldBlock(err error) bool
- type Buffer
- type ByteReader
- type ByteScanner
- type ByteWriter
- type Closer
- type Outcome
- type ReadCloser
- type ReadSeeker
- type ReadWriteCloser
- type ReadWriteSeeker
- type ReadWriter
- type Reader
- type ReaderAt
- type ReaderFrom
- type ReaderFromAdapter
- type RuneReader
- type RuneScanner
- type Seeker
- type StringWriter
- type WriteCloser
- type WriteSeeker
- type Writer
- type WriterAt
- type WriterTo
- type WriterToAdapter
Constants ¶
This section is empty.
Variables ¶
var ( // EOF is returned by Read when no more input is available. // Functions should return EOF only to signal a graceful end of input. EOF = io.EOF // ErrClosedPipe is returned on write to a closed pipe. // It may also be returned by other operations that behave like a closed pipe. ErrClosedPipe = io.ErrClosedPipe // ErrNoProgress reports that a Reader returned no data and no error after // multiple Read calls. It is used by some io helpers to detect broken Readers // (i.e., lack of forward progress). ErrNoProgress = io.ErrNoProgress // ErrShortBuffer means a provided buffer was too small to complete the operation. // Callers typically retry with a larger buffer. ErrShortBuffer = io.ErrShortBuffer // ErrShortWrite means a write accepted fewer bytes than requested and returned // no explicit error (or equivalently, could not complete the full write). ErrShortWrite = io.ErrShortWrite // ErrUnexpectedEOF means EOF was encountered earlier than expected. // It is commonly used by fixed-size reads/copies when the stream ends mid-record. ErrUnexpectedEOF = io.ErrUnexpectedEOF )
Common sentinel errors re-exported for convenience.
Note: iox also defines semantic non-failure errors (ErrWouldBlock, ErrMore) used by iox helpers and adapters; those are not part of the standard io set.
var ErrMore = errors.New("io: expect more")
ErrMore means “this operation remains active; more completions will follow” (multi-shot / streaming style). Next step: keep polling and processing results.
var ErrWouldBlock = errors.New("io: would block")
ErrWouldBlock means “no further progress without waiting”. Linux analogy: EAGAIN/EWOULDBLOCK / not-ready / no completion available. Next step: wait (via poll/epoll/io_uring/etc), then retry.
Functions ¶
func Copy ¶
Copy copies from src to dst until either EOF is reached on src or an error occurs.
iox semantics extension:
- ErrWouldBlock: return immediately because the next step would block. written may be > 0 (partial progress); retry after readiness/completion.
- ErrMore: return immediately because progress happened and the operation remains active; written may be > 0; keep polling for more completions.
func CopyBuffer ¶
CopyBuffer is like Copy but stages through buf if needed. If buf is nil, a stack buffer is used. If buf has zero length, CopyBuffer panics.
func CopyN ¶
CopyN copies n bytes (or until an error) from src to dst. On return, written == n if and only if err == nil.
iox semantics extension:
- ErrWouldBlock / ErrMore may be returned when progress stops early; written may be > 0 and is the number of bytes already copied.
func CopyNBuffer ¶
CopyNBuffer is like CopyN but stages through buf if needed. If buf is nil, a stack buffer is used. If buf has zero length, CopyNBuffer panics.
func IsMore ¶
IsMore reports whether err carries the iox multi-shot (more completions) semantic. It returns true for ErrMore and wrappers (via errors.Is).
func IsNonFailure ¶
IsNonFailure reports whether err should be treated as a non-failure in non-blocking I/O control flow: nil, ErrWouldBlock, or ErrMore.
Typical usage: decide whether to keep a descriptor active without logging an error or tearing down the operation.
func IsProgress ¶
IsProgress reports whether the current call produced usable progress now: returns true for nil and ErrMore. In both cases caller can proceed with delivered data/work; for ErrMore keep polling for subsequent completions.
func IsSemantic ¶
IsSemantic reports whether err represents an iox semantic signal: either ErrWouldBlock or ErrMore (including wrapped forms).
func IsWouldBlock ¶
IsWouldBlock reports whether err carries the iox would-block semantic. It returns true for ErrWouldBlock and wrappers (via errors.Is).
Types ¶
type Buffer ¶
type Buffer [32 * 1024]byte
Buffer is the default stack buffer used by Copy when none is supplied.
type ByteReader ¶
type ByteReader = io.ByteReader
ByteReader reads and returns a single byte.
ByteReader is an alias of io.ByteReader.
type ByteScanner ¶
type ByteScanner = io.ByteScanner
ByteScanner is a ByteReader that can "unread" the last byte read.
ByteScanner is an alias of io.ByteScanner.
type ByteWriter ¶
type ByteWriter = io.ByteWriter
ByteWriter writes a single byte.
ByteWriter is an alias of io.ByteWriter.
type Closer ¶
Closer is implemented by types that can release resources.
Close should be idempotent where practical; callers should not assume any particular behavior beyond resource release and an error indicating failure.
Closer is an alias of io.Closer.
type Outcome ¶
type Outcome uint8
Outcome classifies an operation result based on iox's extended semantics.
OutcomeOK: success, no more to come. OutcomeWouldBlock: no progress is possible right now; retry later. OutcomeMore: progress happened and more completions are expected. OutcomeFailure: any other error (including EOF when it's not absorbed by helpers).
type ReadCloser ¶
type ReadCloser = io.ReadCloser
ReadCloser groups Read and Close.
ReadCloser is an alias of io.ReadCloser.
type ReadSeeker ¶
type ReadSeeker = io.ReadSeeker
ReadSeeker groups Read and Seek.
ReadSeeker is an alias of io.ReadSeeker.
type ReadWriteCloser ¶
type ReadWriteCloser = io.ReadWriteCloser
ReadWriteCloser groups Read, Write, and Close.
ReadWriteCloser is an alias of io.ReadWriteCloser.
type ReadWriteSeeker ¶
type ReadWriteSeeker = io.ReadWriteSeeker
ReadWriteSeeker groups Read, Write, and Seek.
ReadWriteSeeker is an alias of io.ReadWriteSeeker.
type ReadWriter ¶
type ReadWriter = io.ReadWriter
ReadWriter groups the basic Read and Write methods.
ReadWriter is an alias of io.ReadWriter.
type Reader ¶
Reader is implemented by types that can read bytes into p.
Read must return the number of bytes read (0 <= n <= len(p)) and any error encountered. Even if Read returns n > 0, it may return a non-nil error to signal a condition observed after producing those bytes.
Callers should treat a return of (0, nil) as "no progress": it does not mean end-of-stream. Well-behaved implementations should avoid returning (0, nil) except when len(p) == 0.
Reader is an alias of io.Reader.
func AsWriterTo ¶
AsWriterTo wraps r so that it also implements WriterTo via iox semantics.
func TeeReader ¶
TeeReader returns a Reader that writes to w what it reads from r. It mirrors io.TeeReader but propagates iox semantics:
- If r.Read returns data with ErrWouldBlock or ErrMore, the data is first written to w, then the special error is returned unchanged.
- If writing to w fails, that error is returned.
- Short writes to w are reported as io.ErrShortWrite.
type ReaderAt ¶
ReaderAt reads from the underlying input at a given offset.
ReaderAt should not affect and should not be affected by the current seek offset. Implementations must return a non-nil error when n < len(p).
ReaderAt is an alias of io.ReaderAt.
type ReaderFrom ¶
type ReaderFrom = io.ReaderFrom
ReaderFrom is an optional optimization for Writers.
If implemented by a Writer, Copy-like helpers may call ReadFrom to transfer data from r more efficiently than a generic read/write loop.
ReaderFrom is an alias of io.ReaderFrom.
type ReaderFromAdapter ¶
type ReaderFromAdapter struct{ W Writer }
ReaderFromAdapter adapts a Writer to implement ReaderFrom using iox.Copy.
type RuneReader ¶
type RuneReader = io.RuneReader
RuneReader reads and returns a single UTF-8 encoded rune.
RuneReader is an alias of io.RuneReader.
type RuneScanner ¶
type RuneScanner = io.RuneScanner
RuneScanner is a RuneReader that can "unread" the last rune read.
RuneScanner is an alias of io.RuneScanner.
type Seeker ¶
Seeker is implemented by types that can set the offset for the next Read or Write.
Seek sets the offset based on whence and returns the new absolute offset.
Seeker is an alias of io.Seeker.
type StringWriter ¶
type StringWriter = io.StringWriter
StringWriter writes the contents of s more efficiently than Write([]byte(s)) for implementations that can avoid an allocation/copy.
StringWriter is an alias of io.StringWriter.
type WriteCloser ¶
type WriteCloser = io.WriteCloser
WriteCloser groups Write and Close.
WriteCloser is an alias of io.WriteCloser.
type WriteSeeker ¶
type WriteSeeker = io.WriteSeeker
WriteSeeker groups Write and Seek.
WriteSeeker is an alias of io.WriteSeeker.
type Writer ¶
Writer is implemented by types that can write bytes from p.
Write must return the number of bytes written (0 <= n <= len(p)) and any error encountered. If Write returns n < len(p), it must return a non-nil error (except in the special case of len(p) == 0).
Writer is an alias of io.Writer.
func AsReaderFrom ¶
AsReaderFrom wraps w so that it also implements ReaderFrom via iox semantics.
func TeeWriter ¶
TeeWriter returns a Writer that duplicates all writes to primary and tee. If writing to primary returns an error or short count, it is returned immediately. Otherwise, the data is written to tee. If writing to tee fails or is short, the error (or io.ErrShortWrite) is returned. Special errors ErrWouldBlock and ErrMore are propagated unchanged.
type WriterAt ¶
WriterAt writes to the underlying output at a given offset.
WriterAt should not affect and should not be affected by the current seek offset. Implementations must return a non-nil error when n < len(p).
WriterAt is an alias of io.WriterAt.
type WriterTo ¶
WriterTo is an optional optimization for Readers.
If implemented by a Reader, Copy-like helpers may call WriteTo to transfer data to w more efficiently than a generic read/write loop.
WriterTo is an alias of io.WriterTo.
type WriterToAdapter ¶
type WriterToAdapter struct{ R Reader }
WriterToAdapter adapts a Reader to implement WriterTo using iox.Copy.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package examples contains small, runnable snippets that demonstrate how to use iox's non-blocking semantics in typical copy-style flows.
|
Package examples contains small, runnable snippets that demonstrate how to use iox's non-blocking semantics in typical copy-style flows. |