From 563c371a98206ead2d09081788e771da63c0126f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sat, 19 Dec 2015 22:34:29 -0500 Subject: [PATCH] Cleanup code in cmux and bench_test. This commit is a partial cherry pick of pull request #3, for code cleanup. --- bench_test.go | 4 +--- cmux.go | 14 +++++--------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/bench_test.go b/bench_test.go index d5c24d9..6f3ef1e 100644 --- a/bench_test.go +++ b/bench_test.go @@ -17,8 +17,6 @@ func (c *mockConn) Read(b []byte) (n int, err error) { } func BenchmarkCMuxConn(b *testing.B) { - b.StopTimer() - benchHTTPPayload := make([]byte, 4096) copy(benchHTTPPayload, []byte("GET http://www.w3.org/ HTTP/1.1")) @@ -33,7 +31,7 @@ func BenchmarkCMuxConn(b *testing.B) { } }() - b.StartTimer() + b.ResetTimer() for i := 0; i < b.N; i++ { c := &mockConn{ diff --git a/cmux.go b/cmux.go index 8f268e4..bb59ef7 100644 --- a/cmux.go +++ b/cmux.go @@ -109,14 +109,12 @@ func (m *cMux) Serve() error { func (m *cMux) serve(c net.Conn) { muc := newMuxConn(c) - matched := false for _, sl := range m.sls { for _, s := range sl.ss { - matched = s(muc.sniffer()) + matched := s(muc.sniffer()) muc.reset() if matched { select { - // TODO(soheil): threre is a possiblity of having unclosed connection. case sl.l.connc <- muc: case <-sl.l.donec: c.Close() @@ -126,12 +124,10 @@ func (m *cMux) serve(c net.Conn) { } } - if !matched { - c.Close() - err := ErrNotMatched{c: c} - if !m.handleErr(err) { - m.root.Close() - } + c.Close() + err := ErrNotMatched{c: c} + if !m.handleErr(err) { + m.root.Close() } }