memconn

package
v0.0.0-...-d97ffc9 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Overview

Package memconn provides an in-memory network connections. This allows applications to connect to themselves without having to open up ports on the network.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pipe

func Pipe() (local, remote net.Conn)

Pipe creates a single pair of in-memory net.Conns. Use NewListener if you want to create more than one connection.

Types

type Addr

type Addr struct{}

Addr is the address of a memlistener.

func (Addr) Network

func (Addr) Network() string

Network implements net.Addr. Returns "memory."

func (Addr) String

func (Addr) String() string

String implements net.Addr. Returns "memory."

type Listener

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

Listener is an in-memory net.Listener. Call DialContext to create a new connection.

func NewListener

func NewListener(l log.Logger) *Listener

NewListener creates a new in-memory Listener.

func (*Listener) Accept

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

Accept waits for and returns the next connection to l. Connections to l are established by calling l.DialContext.

The returned net.Conn is the server side of the connection.

func (*Listener) Addr

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

Addr returns l's address. This will always be a fake "memory" address.

func (*Listener) Close

func (l *Listener) Close() error

Close closes l. Any blocked Accept operations will immediately be unblocked and return errors. Already Accepted connections are not closed.

func (*Listener) DialContext

func (l *Listener) DialContext(ctx context.Context) (net.Conn, error)

DialContext creates a new connection to l. DialContext will block until the connection is accepted through a blocked l.Accept call or until ctx is canceled.

Note that unlike other Dial methods in different packages, there is no address to supply because the remote side of the connection is always the in-memory listener.

Jump to

Keyboard shortcuts

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