nettest

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTimeout      = errors.New("timeout")
	ErrReadTimeout  = fmt.Errorf("read %w", ErrTimeout)
	ErrWriteTimeout = fmt.Errorf("write %w", ErrTimeout)
)

Functions

func NewConn

func NewConn(name string, maxBuf int) (Conn, Conn)

NewConn creates a pair of Conns that are wired together by pipes.

Types

type Conn

type Conn interface {
	io.Reader
	io.Writer
	io.Closer

	SetDeadline(t time.Time) error
	SetReadDeadline(t time.Time) error
	SetWriteDeadline(t time.Time) error

	// SetReadBlock blocks or unblocks the Read method of this Conn.
	// It reports an error if the existing value matches the new value,
	// or if the Conn has been Closed.
	SetReadBlock(bool) error

	// SetWriteBlock blocks or unblocks the Write method of this Conn.
	// It reports an error if the existing value matches the new value,
	// or if the Conn has been Closed.
	SetWriteBlock(bool) error
}

Conn is a bi-directional in-memory stream that looks like a TCP net.Conn.

type Pipe

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

Pipe implements an in-memory FIFO with timeouts.

func NewPipe

func NewPipe(name string, maxBuf int) *Pipe

NewPipe creates a Pipe with a buffer size fixed at maxBuf.

func (*Pipe) Block

func (p *Pipe) Block() error

func (*Pipe) Close

func (p *Pipe) Close() error

Close implements io.Closer.

func (*Pipe) Read

func (p *Pipe) Read(b []byte) (n int, err error)

Read implements io.Reader.

func (*Pipe) SetReadDeadline

func (p *Pipe) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future Read calls.

func (*Pipe) SetWriteDeadline

func (p *Pipe) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for future Write calls.

func (*Pipe) Unblock

func (p *Pipe) Unblock() error

func (*Pipe) Write

func (p *Pipe) Write(b []byte) (n int, err error)

Write implements io.Writer.

Jump to

Keyboard shortcuts

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