moved pipes package
Jeromy committed
Oct 27, 2014 at 21:19 UTC
f89cfc11086f788beb9ce85bff2f5a8885d2f5c4
6 files changed
+20
-6
Godeps/_workspace/src/github.com/jbenet/go-msgio/chan.go
+15
-1
@@ -13,7 +13,15 @@ type Chan struct {
13
BufPool *sync.Pool
14
}
15
16
-func NewChan(chanSize int, pool *sync.Pool) *Chan {
16
+func NewChan(chanSize int) *Chan {
17
+ return &Chan{
18
+ MsgChan: make(chan []byte, chanSize),
19
+ ErrChan: make(chan error, 1),
20
+ CloseChan: make(chan bool, 2),
21
+ }
22
+}
23
+
24
+func NewChanWithPool(chanSize int, pool *sync.Pool) *Chan {
25
return &Chan{
26
MsgChan: make(chan []byte, chanSize),
27
ErrChan: make(chan error, 1),
@@ -26,6 +34,12 @@ func (s *Chan) ReadFrom(r io.Reader, maxMsgLen int) {
34
// new buffer per message
35
// if bottleneck, cycle around a set of buffers
36
mr := NewReader(r)
37
+ if s.BufPool == nil {
38
+ s.BufPool = new(sync.Pool)
39
+ s.BufPool.New = func() interface{} {
40
+ return make([]byte, maxMsgLen)
41
+ }
42
+ }
43
Loop:
44
for {
45
bufi := s.BufPool.Get()
crypto/spipe/pipe.go
+1
-1
@@ -6,7 +6,7 @@ import (
6
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
7
peer "github.com/jbenet/go-ipfs/peer"
8
9
- pipes "github.com/jbenet/go-ipfs/pipes"
9
+ pipes "github.com/jbenet/go-ipfs/util/pipes"
10
)
11
12
// SecurePipe objects represent a bi-directional message channel.
crypto/spipe/signedpipe.go
+1
-1
@@ -11,7 +11,7 @@ import (
11
ci "github.com/jbenet/go-ipfs/crypto"
12
pb "github.com/jbenet/go-ipfs/crypto/spipe/internal/pb"
13
"github.com/jbenet/go-ipfs/peer"
14
- "github.com/jbenet/go-ipfs/pipes"
14
+ "github.com/jbenet/go-ipfs/util/pipes"
15
)
16
17
type SignedPipe struct {
net/conn/conn.go
+2
-2
@@ -51,8 +51,8 @@ type msgioPipe struct {
51
52
func newMsgioPipe(size int, pool *sync.Pool) *msgioPipe {
53
return &msgioPipe{
54
- outgoing: msgio.NewChan(size, nil),
55
- incoming: msgio.NewChan(size, pool),
54
+ outgoing: msgio.NewChan(size),
55
+ incoming: msgio.NewChanWithPool(size, pool),
56
}
57
}
58
net/conn/secure_conn.go
+1
-1
@@ -8,8 +8,8 @@ import (
8
9
spipe "github.com/jbenet/go-ipfs/crypto/spipe"
10
peer "github.com/jbenet/go-ipfs/peer"
11
- "github.com/jbenet/go-ipfs/pipes"
11
ctxc "github.com/jbenet/go-ipfs/util/ctxcloser"
12
+ "github.com/jbenet/go-ipfs/util/pipes"
13
)
14
15
// secureConn wraps another Conn object with an encrypted channel.