mirror of
https://github.com/soheilhy/cmux.git
synced 2025-10-17 20:58:14 +08:00
Compare commits
6 Commits
devel-opti
...
fix-patric
Author | SHA1 | Date | |
---|---|---|---|
|
df31d48636 | ||
|
fd01d3cc6c | ||
|
f952454ed9 | ||
|
00342b4d79 | ||
|
cd9b7d74b9 | ||
|
9d1e2a64dd |
@@ -24,4 +24,5 @@ before_script:
|
||||
- if [[ $TRAVIS_GO_VERSION == 1.6* ]]; then go tool vet --shadow .; fi
|
||||
|
||||
script:
|
||||
- go test -v ./...
|
||||
- go test -bench . -v ./...
|
||||
- go test -race -bench . -v ./...
|
||||
|
11
CONTRIBUTORS
Normal file
11
CONTRIBUTORS
Normal file
@@ -0,0 +1,11 @@
|
||||
# The list of people who have contributed code to the cmux repository.
|
||||
#
|
||||
# Auto-generated with:
|
||||
# git log --oneline --pretty=format:'%an <%aE>' | sort -u
|
||||
#
|
||||
Dmitri Shuralyov <shurcooL@gmail.com>
|
||||
Ethan Mosbaugh <emosbaugh@gmail.com>
|
||||
Soheil Hassas Yeganeh <soheil.h.y@gmail.com>
|
||||
Soheil Hassas Yeganeh <soheil@cs.toronto.edu>
|
||||
Tamir Duberstein <tamir@cockroachlabs.com>
|
||||
Tamir Duberstein <tamird@gmail.com>
|
@@ -74,3 +74,10 @@ gRPC server please match with writers:
|
||||
```go
|
||||
grpcl := m.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc"))
|
||||
```
|
||||
|
||||
# Copyright and License
|
||||
Copyright 2016 The CMux Authors. All rights reserved.
|
||||
|
||||
See [CONTRIBUTORS](https://github.com/soheilhy/cmux/blob/master/CONTRIBUTORS)
|
||||
for the CMux Authors. Code is released under
|
||||
[the Apache 2 license](https://github.com/soheilhy/cmux/blob/master/LICENSE).
|
||||
|
@@ -1,3 +1,17 @@
|
||||
// Copyright 2016 The CMux Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package cmux
|
||||
|
||||
import (
|
||||
@@ -48,12 +62,14 @@ func BenchmarkCMuxConnHTTP1(b *testing.B) {
|
||||
wg.Add(b.N)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c := &mockConn{
|
||||
r: bytes.NewReader(benchHTTP1Payload),
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
wg.Add(1)
|
||||
m.serve(&mockConn{
|
||||
r: bytes.NewReader(benchHTTP1Payload),
|
||||
}, donec, &wg)
|
||||
}
|
||||
m.serve(c, donec, &wg)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkCMuxConnHTTP2(b *testing.B) {
|
||||
@@ -66,12 +82,14 @@ func BenchmarkCMuxConnHTTP2(b *testing.B) {
|
||||
wg.Add(b.N)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c := &mockConn{
|
||||
r: bytes.NewReader(benchHTTP2Payload),
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
wg.Add(1)
|
||||
m.serve(&mockConn{
|
||||
r: bytes.NewReader(benchHTTP2Payload),
|
||||
}, donec, &wg)
|
||||
}
|
||||
m.serve(c, donec, &wg)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkCMuxConnHTTP1n2(b *testing.B) {
|
||||
@@ -84,15 +102,16 @@ func BenchmarkCMuxConnHTTP1n2(b *testing.B) {
|
||||
|
||||
donec := make(chan struct{})
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(b.N)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c := &mockConn{
|
||||
r: bytes.NewReader(benchHTTP2Payload),
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
wg.Add(1)
|
||||
m.serve(&mockConn{
|
||||
r: bytes.NewReader(benchHTTP2Payload),
|
||||
}, donec, &wg)
|
||||
}
|
||||
m.serve(c, donec, &wg)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkCMuxConnHTTP2n1(b *testing.B) {
|
||||
@@ -105,13 +124,14 @@ func BenchmarkCMuxConnHTTP2n1(b *testing.B) {
|
||||
|
||||
donec := make(chan struct{})
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(b.N)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c := &mockConn{
|
||||
r: bytes.NewReader(benchHTTP1Payload),
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
wg.Add(1)
|
||||
m.serve(&mockConn{
|
||||
r: bytes.NewReader(benchHTTP1Payload),
|
||||
}, donec, &wg)
|
||||
}
|
||||
m.serve(c, donec, &wg)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
14
buffer.go
14
buffer.go
@@ -1,3 +1,17 @@
|
||||
// Copyright 2016 The CMux Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package cmux
|
||||
|
||||
import (
|
||||
|
14
cmux.go
14
cmux.go
@@ -1,3 +1,17 @@
|
||||
// Copyright 2016 The CMux Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package cmux
|
||||
|
||||
import (
|
||||
|
14
cmux_test.go
14
cmux_test.go
@@ -1,3 +1,17 @@
|
||||
// Copyright 2016 The CMux Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package cmux
|
||||
|
||||
import (
|
||||
|
18
doc.go
Normal file
18
doc.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright 2016 The CMux Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
// Package cmux is a library to multiplex network connections based on
|
||||
// their payload. Using cmux, you can serve different protocols from the
|
||||
// same listener.
|
||||
package cmux
|
@@ -1,3 +1,17 @@
|
||||
// Copyright 2016 The CMux Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package cmux_test
|
||||
|
||||
import (
|
||||
|
@@ -1,3 +1,17 @@
|
||||
// Copyright 2016 The CMux Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package cmux_test
|
||||
|
||||
import (
|
||||
|
@@ -1,3 +1,17 @@
|
||||
// Copyright 2016 The CMux Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package cmux_test
|
||||
|
||||
import (
|
||||
|
14
matchers.go
14
matchers.go
@@ -1,3 +1,17 @@
|
||||
// Copyright 2016 The CMux Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package cmux
|
||||
|
||||
import (
|
||||
|
32
patricia.go
32
patricia.go
@@ -1,3 +1,17 @@
|
||||
// Copyright 2016 The CMux Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package cmux
|
||||
|
||||
import (
|
||||
@@ -8,8 +22,8 @@ import (
|
||||
// patriciaTree is a simple patricia tree that handles []byte instead of string
|
||||
// and cannot be changed after instantiation.
|
||||
type patriciaTree struct {
|
||||
root *ptNode
|
||||
buf []byte // preallocated buffer to read data while matching
|
||||
root *ptNode
|
||||
maxDepth int // max depth of the tree.
|
||||
}
|
||||
|
||||
func newPatriciaTree(bs ...[]byte) *patriciaTree {
|
||||
@@ -20,8 +34,8 @@ func newPatriciaTree(bs ...[]byte) *patriciaTree {
|
||||
}
|
||||
}
|
||||
return &patriciaTree{
|
||||
root: newNode(bs),
|
||||
buf: make([]byte, max+1),
|
||||
root: newNode(bs),
|
||||
maxDepth: max + 1,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,13 +48,15 @@ func newPatriciaTreeString(strs ...string) *patriciaTree {
|
||||
}
|
||||
|
||||
func (t *patriciaTree) matchPrefix(r io.Reader) bool {
|
||||
n, _ := io.ReadFull(r, t.buf)
|
||||
return t.root.match(t.buf[:n], true)
|
||||
buf := make([]byte, t.maxDepth)
|
||||
n, _ := io.ReadFull(r, buf)
|
||||
return t.root.match(buf[:n], true)
|
||||
}
|
||||
|
||||
func (t *patriciaTree) match(r io.Reader) bool {
|
||||
n, _ := io.ReadFull(r, t.buf)
|
||||
return t.root.match(t.buf[:n], false)
|
||||
buf := make([]byte, t.maxDepth)
|
||||
n, _ := io.ReadFull(r, buf)
|
||||
return t.root.match(buf[:n], false)
|
||||
}
|
||||
|
||||
type ptNode struct {
|
||||
|
@@ -1,3 +1,17 @@
|
||||
// Copyright 2016 The CMux Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package cmux
|
||||
|
||||
import (
|
||||
|
Reference in New Issue
Block a user