mirror of
https://github.com/soheilhy/cmux.git
synced 2024-11-10 03:31:52 +08:00
Cleanup code in cmux and bench_test.
This commit is a partial cherry pick of pull request #3, for code cleanup.
This commit is contained in:
parent
89dd8ce1fd
commit
563c371a98
@ -17,8 +17,6 @@ func (c *mockConn) Read(b []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkCMuxConn(b *testing.B) {
|
func BenchmarkCMuxConn(b *testing.B) {
|
||||||
b.StopTimer()
|
|
||||||
|
|
||||||
benchHTTPPayload := make([]byte, 4096)
|
benchHTTPPayload := make([]byte, 4096)
|
||||||
copy(benchHTTPPayload, []byte("GET http://www.w3.org/ HTTP/1.1"))
|
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++ {
|
for i := 0; i < b.N; i++ {
|
||||||
c := &mockConn{
|
c := &mockConn{
|
||||||
|
6
cmux.go
6
cmux.go
@ -109,14 +109,12 @@ func (m *cMux) Serve() error {
|
|||||||
|
|
||||||
func (m *cMux) serve(c net.Conn) {
|
func (m *cMux) serve(c net.Conn) {
|
||||||
muc := newMuxConn(c)
|
muc := newMuxConn(c)
|
||||||
matched := false
|
|
||||||
for _, sl := range m.sls {
|
for _, sl := range m.sls {
|
||||||
for _, s := range sl.ss {
|
for _, s := range sl.ss {
|
||||||
matched = s(muc.sniffer())
|
matched := s(muc.sniffer())
|
||||||
muc.reset()
|
muc.reset()
|
||||||
if matched {
|
if matched {
|
||||||
select {
|
select {
|
||||||
// TODO(soheil): threre is a possiblity of having unclosed connection.
|
|
||||||
case sl.l.connc <- muc:
|
case sl.l.connc <- muc:
|
||||||
case <-sl.l.donec:
|
case <-sl.l.donec:
|
||||||
c.Close()
|
c.Close()
|
||||||
@ -126,13 +124,11 @@ func (m *cMux) serve(c net.Conn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !matched {
|
|
||||||
c.Close()
|
c.Close()
|
||||||
err := ErrNotMatched{c: c}
|
err := ErrNotMatched{c: c}
|
||||||
if !m.handleErr(err) {
|
if !m.handleErr(err) {
|
||||||
m.root.Close()
|
m.root.Close()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *cMux) HandleError(h ErrorHandler) {
|
func (m *cMux) HandleError(h ErrorHandler) {
|
||||||
|
Loading…
Reference in New Issue
Block a user