mirror of
https://github.com/soheilhy/cmux.git
synced 2025-01-18 18:56:26 +08:00
Mux connections in parallel
This commit launches a go-routine for each accepted connection, to match them in parallel.
This commit is contained in:
parent
fa65c0526e
commit
581432eab8
38
cmux.go
38
cmux.go
@ -103,26 +103,30 @@ func (m *cMux) Serve() error {
|
||||
continue
|
||||
}
|
||||
|
||||
muc := newMuxConn(c)
|
||||
matched := false
|
||||
outer:
|
||||
for _, sl := range m.sls {
|
||||
for _, s := range sl.ss {
|
||||
matched = s(muc.sniffer())
|
||||
muc.reset()
|
||||
if matched {
|
||||
sl.l.cch <- muc
|
||||
break outer
|
||||
}
|
||||
go m.serve(c)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *cMux) serve(c net.Conn) {
|
||||
muc := newMuxConn(c)
|
||||
matched := false
|
||||
outer:
|
||||
for _, sl := range m.sls {
|
||||
for _, s := range sl.ss {
|
||||
matched = s(muc.sniffer())
|
||||
muc.reset()
|
||||
if matched {
|
||||
sl.l.cch <- muc
|
||||
break outer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !matched {
|
||||
c.Close()
|
||||
err := ErrNotMatched{c: c}
|
||||
if !m.handleErr(err) {
|
||||
return err
|
||||
}
|
||||
if !matched {
|
||||
c.Close()
|
||||
err := ErrNotMatched{c: c}
|
||||
if !m.handleErr(err) {
|
||||
m.root.Close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user