package cmux
Import Path
github.com/soheilhy/cmux (on go.dev)
Dependency Relation
imports 14 packages, and imported by 2 packages
Involved Source Files
buffer.go
cmux.go
Package cmux is a library to multiplex network connections based on
their payload. Using cmux, you can serve different protocols from the
same listener.
matchers.go
patricia.go
Package-Level Type Names (total 6)
CMux is a multiplexer for network connections.
Closes cmux server and stops accepting any connections on listener
HandleError registers an error handler that handles listener errors.
Match returns a net.Listener that sees (i.e., accepts) only
the connections matched by at least one of the matcher.
The order used to call Match determines the priority of matchers.
MatchWithWriters returns a net.Listener that accepts only the
connections that matched by at least of the matcher writers.
Prefer Matchers over MatchWriters, since the latter can write on the
connection before the actual handler.
The order used to call Match determines the priority of matchers.
Serve starts multiplexing the listener. Serve blocks and perhaps
should be invoked concurrently within a go routine.
sets a timeout for the read of matchers
func New(l net.Listener) CMux
func github.com/pancsta/asyncmachine-go/tools/debugger/server.StartRpc(mach *am.Machine, addr string, mux chan<- CMux, fwdAdds []string, enableHttp bool)
ErrNotMatched is returned whenever a connection is not matched by any of
the matchers registered in the multiplexer.
( ErrNotMatched) Error() string
Temporary implements the net.Error interface.
Timeout implements the net.Error interface.
ErrNotMatched : github.com/jbenet/go-temp-err-catcher.Temporary
ErrNotMatched : error
ErrNotMatched : net.Error
ErrorHandler handles an error and returns whether
the mux should continue serving the listener.
func CMux.HandleError(ErrorHandler)
Matcher matches a connection based on its content.
func Any() Matcher
func HTTP1() Matcher
func HTTP1Fast(extMethods ...string) Matcher
func HTTP1HeaderField(name, value string) Matcher
func HTTP1HeaderFieldPrefix(name, valuePrefix string) Matcher
func HTTP2() Matcher
func HTTP2HeaderField(name, value string) Matcher
func HTTP2HeaderFieldPrefix(name, valuePrefix string) Matcher
func PrefixMatcher(strs ...string) Matcher
func TLS(versions ...int) Matcher
func CMux.Match(...Matcher) net.Listener
MatchWriter is a match that can also write response (say to do handshake).
func HTTP2MatchHeaderFieldPrefixSendSettings(name, valuePrefix string) MatchWriter
func HTTP2MatchHeaderFieldSendSettings(name, value string) MatchWriter
func CMux.MatchWithWriters(...MatchWriter) net.Listener
MuxConn wraps a net.Conn and provides transparent sniffing of connection data.
Conn net.Conn
Close closes the connection.
Any blocked Read or Write operations will be unblocked and return errors.
Close may or may not block until any buffered data is sent;
for TCP connections see [*TCPConn.SetLinger].
LocalAddr returns the local network address, if known.
From the io.Reader documentation:
When Read encounters an error or end-of-file condition after
successfully reading n > 0 bytes, it returns the number of
bytes read. It may return the (non-nil) error from the same call
or return the error (and n == 0) from a subsequent call.
An instance of this general case is that a Reader returning
a non-zero number of bytes at the end of the input stream may
return either err == EOF or err == nil. The next Read should
return 0, EOF.
RemoteAddr returns the remote network address, if known.
SetDeadline sets the read and write deadlines associated
with the connection. It is equivalent to calling both
SetReadDeadline and SetWriteDeadline.
A deadline is an absolute time after which I/O operations
fail instead of blocking. The deadline applies to all future
and pending I/O, not just the immediately following call to
Read or Write. After a deadline has been exceeded, the
connection can be refreshed by setting a deadline in the future.
If the deadline is exceeded a call to Read or Write or to other
I/O methods will return an error that wraps os.ErrDeadlineExceeded.
This can be tested using errors.Is(err, os.ErrDeadlineExceeded).
The error's Timeout method will return true, but note that there
are other possible errors for which the Timeout method will
return true even if the deadline has not been exceeded.
An idle timeout can be implemented by repeatedly extending
the deadline after successful Read or Write calls.
A zero value for t means I/O operations will not time out.
SetReadDeadline sets the deadline for future Read calls
and any currently-blocked Read call.
A zero value for t means Read will not time out.
SetWriteDeadline sets the deadline for future Write calls
and any currently-blocked Write call.
Even if write times out, it may return n > 0, indicating that
some of the data was successfully written.
A zero value for t means Write will not time out.
Write writes data to the connection.
Write can be made to time out and return an error after a fixed
time limit; see SetDeadline and SetWriteDeadline.
MuxConn : github.com/miekg/dns.Writer
MuxConn : github.com/pion/datachannel.ReadDeadliner
MuxConn : github.com/pion/datachannel.WriteDeadliner
*MuxConn : github.com/pion/stun.Connection
*MuxConn : github.com/pion/stun/v3.Connection
MuxConn : github.com/prometheus/common/expfmt.Closer
MuxConn : internal/bisect.Writer
MuxConn : io.Closer
*MuxConn : io.ReadCloser
*MuxConn : io.Reader
*MuxConn : io.ReadWriteCloser
*MuxConn : io.ReadWriter
MuxConn : io.WriteCloser
MuxConn : io.Writer
*MuxConn : net.Conn
Package-Level Functions (total 13)
Any is a Matcher that matches any connection.
HTTP1 parses the first line or upto 4096 bytes of the request to see if
the conection contains an HTTP request.
HTTP1Fast only matches the methods in the HTTP request.
This matcher is very optimistic: if it returns true, it does not mean that
the request is a valid HTTP response. If you want a correct but slower HTTP1
matcher, use HTTP1 instead.
HTTP1HeaderField returns a matcher matching the header fields of the first
request of an HTTP 1 connection.
HTTP1HeaderFieldPrefix returns a matcher matching the header fields of the
first request of an HTTP 1 connection. If the header with key name has a
value prefixed with valuePrefix, this will match.
HTTP2 parses the frame header of the first frame to detect whether the
connection is an HTTP2 connection.
HTTP2HeaderField returns a matcher matching the header fields of the first
headers frame.
HTTP2HeaderFieldPrefix returns a matcher matching the header fields of the
first headers frame. If the header with key name has a value prefixed with
valuePrefix, this will match.
HTTP2MatchHeaderFieldPrefixSendSettings matches the header field prefix
and writes the settings to the server. Prefer HTTP2HeaderFieldPrefix over
this one, if the client does not block on receiving a SETTING frame.
HTTP2MatchHeaderFieldSendSettings matches the header field and writes the
settings to the server. Prefer HTTP2HeaderField over this one, if the client
does not block on receiving a SETTING frame.
New instantiates a new connection multiplexer.
PrefixMatcher returns a matcher that matches a connection if it
starts with any of the strings in strs.
TLS matches HTTPS requests.
By default, any TLS handshake packet is matched. An optional whitelist
of versions can be passed in to restrict the matcher, for example:
TLS(tls.VersionTLS11, tls.VersionTLS12)
Package-Level Variables (total 2)
ErrListenerClosed is returned from muxListener.Accept when the underlying
listener is closed.
ErrServerClosed is returned from muxListener.Accept when mux server is closed.
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |