contextio

package module
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2024 License: MPL-2.0 Imports: 12 Imported by: 1

README

contextio

Contextio provides context-aware I/O primitives for Go. Supports net.Conn and os.Pipe readers / writers.

Documentation

Overview

Package contextio provides context-aware I/O primitives for Go.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosedPipe = stdio.ErrClosedPipe

Functions

func CopyContext

func CopyContext(ctx context.Context, dst DeadlineWriter, src DeadlineReader, readTimeout *time.Duration) (written int64, err error)

CopyContext is equivalent to `io.Copy` but with context cancellation support (for deadline reader/writers). The optional `readTimeout` parameter can be used to set a timeout for individual read operations, if not provided read operations will block indefinitely (until the context is cancelled).

func Pipe

func Pipe() (*PipeReader, *PipeWriter)

Pipe is equivalent to `io.Pipe` but with deadline support.

func SetNonblock

func SetNonblock(f *os.File) error

func SpliceContext

func SpliceContext(ctx context.Context, rwa DeadlineReadWriter, rwb DeadlineReadWriter,
	readTimeout *time.Duration) (written int64, err error)

SpliceContext copies data between two ReadWriters until EOF is reached on one of them. The optional `readTimeout` parameter can be used to set a timeout for individual read operations, if not provided read operations will block indefinitely (until the context is cancelled).

Types

type DeadlineReadCloser

type DeadlineReadCloser interface {
	stdio.Closer
	DeadlineReader
}

type DeadlineReadWriteCloser

type DeadlineReadWriteCloser interface {
	stdio.Closer
	DeadlineReadWriter
}

type DeadlineReadWriter

type DeadlineReadWriter interface {
	DeadlineReader
	DeadlineWriter
}

Full duplex I/O.

type DeadlineReader

type DeadlineReader interface {
	stdio.Reader
	SetReadDeadline(t time.Time) error
}

Reader types.

func NopDeadlineReader

func NopDeadlineReader(r stdio.Reader) DeadlineReader

type DeadlineWriteCloser

type DeadlineWriteCloser interface {
	stdio.Closer
	DeadlineWriter
}

type DeadlineWriter

type DeadlineWriter interface {
	stdio.Writer
	SetWriteDeadline(t time.Time) error
}

Writer types.

func NopDeadlineWriter

func NopDeadlineWriter(w stdio.Writer) DeadlineWriter

type PipeReader

type PipeReader struct {
	// contains filtered or unexported fields
}

A PipeReader is the read half of a pipe.

func (*PipeReader) Close

func (r *PipeReader) Close() error

func (*PipeReader) Read

func (r *PipeReader) Read(data []byte) (n int, err error)

func (*PipeReader) SetReadDeadline

func (r *PipeReader) SetReadDeadline(t time.Time) error

type PipeWriter

type PipeWriter struct {
	// contains filtered or unexported fields
}

A PipeWriter is the write half of a pipe.

func (*PipeWriter) Close

func (w *PipeWriter) Close() error

func (*PipeWriter) SetWriteDeadline

func (w *PipeWriter) SetWriteDeadline(t time.Time) error

func (*PipeWriter) Write

func (w *PipeWriter) Write(data []byte) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL