mux

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTimeout is the default length of time to wait for bytes we need.
	DefaultTimeout = 10 * time.Second
)

Variables

View Source
var (
	HTTPSNeedBytesNum uint32 = 1
	HTTPNeedBytesNum  uint32 = 3
	YamuxNeedBytesNum uint32 = 2
)

Functions

This section is empty.

Types

type MatchFunc

type MatchFunc func(data []byte) (match bool)
var HTTPMatchFunc MatchFunc = func(data []byte) bool {
	if len(data) < int(HTTPNeedBytesNum) {
		return false
	}

	_, ok := httpHeadBytes[string(data[:3])]
	return ok
}
var HTTPSMatchFunc MatchFunc = func(data []byte) bool {
	if len(data) < int(HTTPSNeedBytesNum) {
		return false
	}
	return data[0] == 0x16
}
var YamuxMatchFunc MatchFunc = func(data []byte) bool {
	if len(data) < int(YamuxNeedBytesNum) {
		return false
	}

	if data[0] == 0 && data[1] <= 0x3 {
		return true
	}
	return false
}

YamuxMatchFunc is a match function for yamux. From https://github.com/hashicorp/yamux/blob/master/spec.md

type Mux

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

func NewMux

func NewMux(ln net.Listener) (mux *Mux)

func (*Mux) DefaultListener

func (mux *Mux) DefaultListener() net.Listener

func (*Mux) Listen

func (mux *Mux) Listen(priority int, needBytesNum uint32, fn MatchFunc) net.Listener

priority

func (*Mux) ListenHTTP

func (mux *Mux) ListenHTTP(priority int) net.Listener

func (*Mux) ListenHTTPS

func (mux *Mux) ListenHTTPS(priority int) net.Listener

func (*Mux) Serve

func (mux *Mux) Serve() error

Serve handles connections from ln and multiplexes then across registered listeners.

func (*Mux) SetKeepAlive

func (mux *Mux) SetKeepAlive(keepAlive time.Duration)

Jump to

Keyboard shortcuts

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