nettest

package
v1.36.2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConn

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

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

func NewTCPConn added in v1.32.0

func NewTCPConn(src, dst netip.AddrPort, maxBuf int) (local Conn, remote Conn)

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

Types

type Conn

type Conn interface {
	net.Conn

	// 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 net.Conn that can additionally have its reads and writes blocked and unblocked.

type Listener added in v1.8.0

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

Listener is a net.Listener using NewConn to create pairs of network connections connected in memory using a buffered pipe. It also provides a Dial method to establish new connections.

func Listen added in v1.8.0

func Listen(addr string) *Listener

Listen returns a new Listener for the provided address.

func (*Listener) Accept added in v1.8.0

func (l *Listener) Accept() (net.Conn, error)

Accept blocks until a new connection is available or the listener is closed.

func (*Listener) Addr added in v1.8.0

func (l *Listener) Addr() net.Addr

Addr implements net.Listener.Addr.

func (*Listener) Close added in v1.8.0

func (l *Listener) Close() error

Close closes the pipe listener.

func (*Listener) Dial added in v1.8.0

func (l *Listener) Dial(ctx context.Context, network, addr string) (_ net.Conn, err error)

Dial connects to the listener using the provided context. The provided Context must be non-nil. If the context expires before the connection is complete, an error is returned. Once successfully connected any expiration of the context will not affect the connection.

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

Block will cause all calls to Read and Write to block until they either timeout, are unblocked or the pipe is closed.

func (*Pipe) Close

func (p *Pipe) Close() error

Close closes the pipe.

func (*Pipe) Read

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

Read implements io.Reader. Once the buffer is drained (i.e. after Close), subsequent calls will return io.EOF.

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

Unblock will cause all blocked Read/Write calls to continue execution.

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