loopback

package
v0.0.0-...-e91a9a7 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPipeWrite = errors.New("write on closed pipe")

Functions

func Dial

func Dial(netw, addr string) (net.Conn, error)

Dial is the same as net.Dial except that it also recognises networks with the prefix "loopback:"; it removes the prefix, dials the original network, and then applies the given loopback Options. Incoming data has inOpts applied; outgoing data has outOpts applied.

func Listen

func Listen(netw, laddr string) (net.Listener, error)

Dial is the same as net.Listen except that it also recognises networks with the [attr=val, attr=val, ...]network; it removes the prefix, listens on the original network, and then applies the given loopback Options to each connection. Incoming data has inOpts applied; outgoing data has outOpts applied.

func ListenOpts

func ListenOpts(netw, laddr string, inOpts, outOpts Options) (net.Listener, error)

func NetPipe

func NetPipe(opt0, opt1 Options) (c0 net.Conn, c1 net.Conn)

NetPipe creates a synchronous, in-memory, full duplex network connection; both ends implement the net.Conn interface. The opt0 options apply to the traffic from c0 to c1; the opt1 options apply to the traffic from c1 to c0.

func NewConn

func NewConn(c net.Conn, inOpts, outOpts Options) net.Conn

func Pipe

func Pipe(opt Options) (r io.ReadCloser, w io.WriteCloser)

Pipe creates an asynchronous in-memory pipe, Writes are divided into packets of at most opts.MTU bytes written to a flow-controlled output queue, transferred across the link, and put into an input queue where it is readable with the r. The options determine when and how the data will be transferred.

Types

type Options

type Options struct {
	// ByteDelay controls the time a packet takes in the link.  A
	// packet n bytes long takes time ByteDelay * n to exit the
	// output queue and is available for reading Latency time later.
	ByteDelay time.Duration
	Latency   time.Duration

	// MTU gives the maximum packet size that can be tranferred
	// atomically across the link.  Larger packets will be split.
	// If this is zero, a default of 32768 is assumed
	MTU int

	// InLimit and OutLimit gives the size of the input and output
	// queues.  If either is zero, a default of MTU is assumed.
	InLimit  int
	OutLimit int
}

Loopback options for use with Pipe.

Jump to

Keyboard shortcuts

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