cmux

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2023 License: MIT Imports: 5 Imported by: 3

README

Cmux

Go Report Card GoDoc GitHub license

Cmux is a stream router

License

Licensed under the MIT License. See LICENSE for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrListenerClosed = fmt.Errorf("listener closed")
View Source
var (
	ErrNotFound = fmt.Errorf("error not found")
)

Functions

func Unread

func Unread(reader io.Reader, prefix []byte) io.Reader

func UnreadConn

func UnreadConn(conn net.Conn, prefix []byte) net.Conn

func UnwrapUnread

func UnwrapUnread(reader io.Reader) (io.Reader, []byte)

func UnwrapUnreadConn

func UnwrapUnreadConn(conn net.Conn) (net.Conn, []byte)

Types

type CMux

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

CMux is an Applicative protocol multiplexer It matches the prefix of each incoming reader against a list of registered patterns and calls the handler for the pattern that most closely matches the Handler.

func NewCMux

func NewCMux() *CMux

NewCMux create a new CMux.

func (*CMux) HandlePrefix

func (m *CMux) HandlePrefix(handler Handler, prefixes ...string) error

HandlePrefix handle the handler that matches the prefix

func (*CMux) Handler

func (m *CMux) Handler(r io.Reader) (handler Handler, prefix []byte, err error)

Handler returns most matching handler and prefix bytes data to use for the given reader.

func (*CMux) NotFound

func (m *CMux) NotFound(handler Handler) error

NotFound handle the handler that unmatched

func (*CMux) ServeConn

func (m *CMux) ServeConn(conn net.Conn)

ServeConn dispatches the reader to the handler whose pattern most closely matches the reader.

type Handler

type Handler interface {
	ServeConn(conn net.Conn)
}

type HandlerFunc

type HandlerFunc func(conn net.Conn)

func (HandlerFunc) ServeConn

func (h HandlerFunc) ServeConn(conn net.Conn)

type MuxListener

type MuxListener struct {
	ErrHandler func(err error) bool
	// contains filtered or unexported fields
}

MuxListener is a multiplexer for network connections

func NewMuxListener

func NewMuxListener(listener net.Listener) *MuxListener

NewMuxListener create a new MuxListener.

func (*MuxListener) MatchPrefix

func (m *MuxListener) MatchPrefix(prefixes ...string) (net.Listener, error)

MatchPrefix returns the net.Listener that matches the prefix

func (*MuxListener) Unmatched

func (m *MuxListener) Unmatched() (net.Listener, error)

Unmatched returns the net.Listener that unmatched

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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