mux

package
v0.10.9 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 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
	}

	if data[0] == 0x16 {
		return true
	} else {
		return false
	}
}
var YamuxMatchFunc MatchFunc = func(data []byte) bool {
	if len(data) < int(YamuxNeedBytesNum) {
		return false
	}

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

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