Documentation
¶
Overview ¶
Package blockio implements symmetric bounded blocking Reader and Writer endpoints backed by non-blocking connection turns.
Index ¶
- Constants
- Variables
- func EnterTurn()
- func LeaveTurn()
- func OnTurn() bool
- type Access
- type Getter
- type Reader
- type Source
- type State
- type Writer
- func (w *Writer) Buffered() int
- func (w *Writer) Flush() error
- func (w *Writer) FlushContext(ctx context.Context) error
- func (w *Writer) NotifySpace()
- func (w *Writer) ReadFrom(r io.Reader) (int64, error)
- func (w *Writer) SetWriteDeadline(t time.Time) error
- func (w *Writer) TryWriteOwned(buf *bytebuf.Buffer) (int, error)
- func (w *Writer) Write(p []byte) (int, error)
- func (w *Writer) WriteContext(ctx context.Context, p []byte) (int, error)
- func (w *Writer) WriteOwned(buf *bytebuf.Buffer) (int, error)
- func (w *Writer) WriteOwnedContext(ctx context.Context, buf *bytebuf.Buffer) (int, error)
- func (w *Writer) Writev(vec [][]byte) (int, error)
- func (w *Writer) WritevContext(ctx context.Context, vec [][]byte) (int, error)
Constants ¶
const DefaultWindow = 64 << 10
DefaultWindow is the default per-direction blocking buffer limit (64 KiB).
Variables ¶
var ErrBlockingOnTurn = errors.New("uio: blocking I/O cannot run on a connection turn")
ErrBlockingOnTurn reports an attempt to invoke a blocking operation from a connection turn or event-loop goroutine.
var ErrOverflow = errors.New("outbound buffer overflow")
ErrOverflow matches the underlying transport's outbound overflow sentinel.
Functions ¶
Types ¶
type Access ¶
type Access[T Getter] struct{}
Access embeds a zero-sized capability marker on supported connections.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader is a stream connection's pull-mode blocking inbound endpoint.
func (*Reader) Pump ¶
func (r *Reader) Pump()
Pump runs on the connection's turn in place of Handler.OnRead, moving inbound bytes directly into a parked reader's slice or into the bounded pipe.
func (*Reader) Read ¶
Read reads up to len(p) bytes from the connection, blocking until data arrives, the peer ends the stream, the connection closes, or the read deadline expires.
func (*Reader) SetReadDeadline ¶
SetReadDeadline sets the deadline for blocked Read and WriteTo calls without closing the underlying connection on expiry.
type Source ¶
type Source interface {
PeekChunk() []byte
Discard(n int) (int, error)
InboundBuffered() int
ReadEnded() bool
WriteEnded() bool
ClosingOrClosed() bool
Write(p []byte) (int, error)
Writev(vec [][]byte) (int, error)
WriteOwned(buf *bytebuf.Buffer) (int, error)
Flush() error
OutboundBuffered() int
MaxInbound() int
MaxOutbound() int
EnablePullRead() (onConnTurn bool, err error)
Wake() error
NewReadPause() *readcontrol.Pause
WatchWrite(fn func(int)) bool
IsOverflow(err error) bool
}
Source abstracts the non-blocking stream connection operations needed by Reader and Writer without importing root package uio.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State lazily holds a stream connection's Reader and Writer instances.
func StateOf ¶
StateOf resolves source's blocking I/O State, or (nil, false) if unsupported (such as datagram connections).
func (*State) ActiveReader ¶
ActiveReader returns the attached Reader if pull mode is active, or nil.
func (*State) HasWriter ¶ added in v1.9.1
HasWriter reports whether a blocking Writer has been attached to s.
func (*State) OnClose ¶
OnClose notifies any attached Reader and Writer that the underlying connection closed. localClose is true when closed locally via Conn.Close().
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is a stream connection's blocking outbound endpoint.
func (*Writer) Flush ¶
Flush asks the underlying transport to flush queued outbound data and waits until the outbound buffer drains, the connection closes, or the write deadline expires.
func (*Writer) FlushContext ¶
FlushContext asks the underlying transport to flush queued outbound data and waits until the outbound buffer drains, the connection closes, the write deadline expires, or ctx ends.
func (*Writer) NotifySpace ¶
func (w *Writer) NotifySpace()
NotifySpace wakes any writer waiting for outbound queue or flow-control room.
func (*Writer) ReadFrom ¶
ReadFrom copies from r into the connection using pooled zero-copy WriteOwned buffers. When r implements io.WriterTo (such as *Reader), it delegates to WriteTo so pooled pipe blocks transfer directly without an intermediate copy.
func (*Writer) SetWriteDeadline ¶
SetWriteDeadline sets the deadline for blocked Write and ReadFrom calls without closing the underlying connection on expiry.
func (*Writer) TryWriteOwned ¶ added in v1.9.1
TryWriteOwned attempts a fast non-blocking write when no writer is currently contended or parked on w and no deadline has expired. If the outbound window is full or contended, it returns ErrOverflow without releasing buf so the caller can fall back to WriteOwnedContext.
func (*Writer) Write ¶
Write writes all of p to the connection, suspending when the outbound window is full. Concurrent calls on the same Writer are serialized atomically.
func (*Writer) WriteContext ¶
WriteContext writes all of p to the connection, suspending until space is available, the connection closes, the write deadline expires, or ctx ends.
func (*Writer) WriteOwned ¶
WriteOwned transfers ownership of buf to the connection, suspending while the outbound window has no room, and always releases buf on failure.
func (*Writer) WriteOwnedContext ¶
WriteOwnedContext transfers ownership of buf to the connection, suspending while the outbound window has no room until space drains, the connection closes, the write deadline expires, or ctx ends. Always consumes or releases buf.