listener

package
v0.0.0-...-996fa4a Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrListenerClosed = errListenerClosed("mux: listener closed")

ErrListenerClosed is returned from muxListener.Accept when the underlying listener is closed.

Functions

This section is empty.

Types

type Config

type Config struct {
	TLS       *tls.Config // The TLS/SSL configuration.
	FlushRate int         // The maximum flush rate (QPS) per connection.
}

Config represents the configuration of the listener.

type Conn

type Conn struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Conn wraps a net.Conn and provides transparent sniffing of connection data.

func (*Conn) Close

func (m *Conn) Close() error

Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.

func (*Conn) Flush

func (m *Conn) Flush() (n int, err error)

Flush flushes the underlying buffer by writing into the underlying connection.

func (*Conn) Len

func (m *Conn) Len() (n int)

Len returns the pending buffer size.

func (*Conn) LocalAddr

func (m *Conn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*Conn) Read

func (m *Conn) Read(p []byte) (int, error)

Read reads the block of data from the underlying buffer.

func (*Conn) RemoteAddr

func (m *Conn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*Conn) SetDeadline

func (m *Conn) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.

func (*Conn) SetReadDeadline

func (m *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future Read calls and any currently-blocked Read call.

func (*Conn) SetWriteDeadline

func (m *Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for future Write calls and any currently-blocked Write call.

func (*Conn) Write

func (m *Conn) Write(p []byte) (int, error)

Write writes the block of data into the underlying buffer.

type ErrNotMatched

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

ErrNotMatched is returned whenever a connection is not matched by any of the matchers registered in the multiplexer.

func (ErrNotMatched) Error

func (e ErrNotMatched) Error() string

func (ErrNotMatched) Temporary

func (e ErrNotMatched) Temporary() bool

Temporary implements the net.Error interface.

func (ErrNotMatched) Timeout

func (e ErrNotMatched) Timeout() bool

Timeout implements the net.Error interface.

type ErrorHandler

type ErrorHandler func(error) bool

ErrorHandler handles an error and notifies the listener on whether it should continue serving.

type Listener

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

Listener represents a listener used for multiplexing protocols.

func New

func New(address string, config Config) (*Listener, error)

New announces on the local network address laddr. The syntax of laddr is "host:port", like "127.0.0.1:8080". If host is omitted, as in ":8080", New listens on all available interfaces instead of just the interface with the given host address. Listening on a hostname is not recommended because this creates a socket for at most one of its IP addresses.

func (*Listener) Accept

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

Accept waits for and returns the next connection to the listener.

func (*Listener) Addr

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

Addr returns the listener's network address.

func (*Listener) Close

func (m *Listener) Close() error

Close closes the listener

func (*Listener) HandleError

func (m *Listener) HandleError(h ErrorHandler)

HandleError registers an error handler that handles listener errors.

func (*Listener) Match

func (m *Listener) Match(matchers ...Matcher) net.Listener

Match returns a net.Listener that sees (i.e., accepts) only the connections matched by at least one of the matcher.

func (*Listener) Serve

func (m *Listener) Serve() error

Serve starts multiplexing the listener.

func (*Listener) ServeAsync

func (m *Listener) ServeAsync(matcher Matcher, serve func(l net.Listener) error)

ServeAsync adds a protocol based on the matcher and serves it.

func (*Listener) SetReadTimeout

func (m *Listener) SetReadTimeout(t time.Duration)

SetReadTimeout sets a timeout for the read of matchers.

type Matcher

type Matcher func(io.Reader) bool

Matcher matches a connection based on its content.

func MatchAny

func MatchAny() Matcher

MatchAny matches any connection.

func MatchHTTP

func MatchHTTP(extMethods ...string) Matcher

MatchHTTP only matches the methods in the HTTP request.

func MatchPrefix

func MatchPrefix(strs ...string) Matcher

MatchPrefix returns a matcher that matches a connection if it starts with any of the strings in strs.

type Server

type Server interface {
	Serve(listener net.Listener)
}

Server represents a server which can serve requests.

Jump to

Keyboard shortcuts

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