1
0
Fork 0

Reorder unexpected function

master
Philip O'Toole 9 months ago
parent 301ed85e23
commit e8ea575a57

@ -161,6 +161,29 @@ func (mux *Mux) Stats() (interface{}, error) {
return s, nil
}
// Listen returns a Layer associated with the given header. Any connection
// accepted by mux is multiplexed based on the initial header byte.
func (mux *Mux) Listen(header byte) *Layer {
// Ensure two listeners are not created for the same header byte.
if _, ok := mux.m[header]; ok {
panic(fmt.Sprintf("listener already registered under header byte: %d", header))
}
// Create a new listener and assign it.
ln := &listener{
c: make(chan net.Conn),
}
mux.m[header] = ln
layer := &Layer{
ln: ln,
addr: mux.addr,
}
layer.dialer = NewDialer(header, mux.tlsConfig)
return layer
}
func (mux *Mux) handleConn(conn net.Conn) {
stats.Add(numConnectionsHandled, 1)
@ -201,29 +224,6 @@ func (mux *Mux) handleConn(conn net.Conn) {
handler.c <- conn
}
// Listen returns a Layer associated with the given header. Any connection
// accepted by mux is multiplexed based on the initial header byte.
func (mux *Mux) Listen(header byte) *Layer {
// Ensure two listeners are not created for the same header byte.
if _, ok := mux.m[header]; ok {
panic(fmt.Sprintf("listener already registered under header byte: %d", header))
}
// Create a new listener and assign it.
ln := &listener{
c: make(chan net.Conn),
}
mux.m[header] = ln
layer := &Layer{
ln: ln,
addr: mux.addr,
}
layer.dialer = NewDialer(header, mux.tlsConfig)
return layer
}
// listener is a receiver for connections received by Mux.
type listener struct {
c chan net.Conn

Loading…
Cancel
Save