cmux

package module
v2.0.0-...-dac7908 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: Apache-2.0 Imports: 16 Imported by: 3

Documentation

Overview

Package cmux provides multiplexing over net.Conns using smux and adhering to standard net package interfaces.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed = errors.New("listener closed")
)
View Source
var (
	ErrTimeout = &timeoutError{}
)

Functions

func Listen

func Listen(opts *ListenOpts) net.Listener

Listen creates a net.Listener that multiplexes connections over a connection obtained from the underlying opts.Listener.

func NewSmuxProtocol

func NewSmuxProtocol(config *smux.Config) *smuxProtocol

NewSmuxProtocol creates a new smux based Protocol using the smux configuration givien. If config is nil, the default smux configuration is used.

func RunAllProtocolTests

func RunAllProtocolTests(proto Protocol, t *testing.T)

func RunCloseTest

func RunCloseTest(proto Protocol, t *testing.T)

func RunErrorShapeTest

func RunErrorShapeTest(proto Protocol, t *testing.T)

func RunRoundTripTest

func RunRoundTripTest(proto Protocol, t *testing.T)

Types

type DialFN

type DialFN func(ctx context.Context, network, addr string) (net.Conn, error)

DialFN is a function that dials like net.DialContext.

func Dialer

func Dialer(opts *DialerOpts) DialFN

Dialer creates a DialFN that returns connections that multiplex themselves over a single connection obtained from the underlying opts.Dial function. It will continue to use that single connection until and unless it encounters an error creating a new multiplexed stream, at which point it will dial again.

type DialerOpts

type DialerOpts struct {
	Dial     DialFN
	PoolSize int
	Protocol Protocol
}

type ErrorMapperFn

type ErrorMapperFn func(error) error

type ListenOpts

type ListenOpts struct {
	Listener net.Listener
	Protocol Protocol
}

type Protocol

type Protocol interface {
	Client(net.Conn) (Session, error)
	Server(net.Conn) (Session, error)
	TranslateError(error) error
}

type Session

type Session interface {
	OpenStream() (net.Conn, error)
	AcceptStream() (net.Conn, error)
	Close() error
	NumStreams() int
}

Jump to

Keyboard shortcuts

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