1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-02 03:28:25 +08:00

moved pipes package

This commit is contained in:
Jeromy
2014-10-27 21:19:22 +00:00
parent 07733b17b3
commit f89cfc1108
6 changed files with 20 additions and 6 deletions

View File

@ -13,7 +13,15 @@ type Chan struct {
BufPool *sync.Pool
}
func NewChan(chanSize int, pool *sync.Pool) *Chan {
func NewChan(chanSize int) *Chan {
return &Chan{
MsgChan: make(chan []byte, chanSize),
ErrChan: make(chan error, 1),
CloseChan: make(chan bool, 2),
}
}
func NewChanWithPool(chanSize int, pool *sync.Pool) *Chan {
return &Chan{
MsgChan: make(chan []byte, chanSize),
ErrChan: make(chan error, 1),
@ -26,6 +34,12 @@ func (s *Chan) ReadFrom(r io.Reader, maxMsgLen int) {
// new buffer per message
// if bottleneck, cycle around a set of buffers
mr := NewReader(r)
if s.BufPool == nil {
s.BufPool = new(sync.Pool)
s.BufPool.New = func() interface{} {
return make([]byte, maxMsgLen)
}
}
Loop:
for {
bufi := s.BufPool.Get()

View File

@ -6,7 +6,7 @@ import (
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
peer "github.com/jbenet/go-ipfs/peer"
pipes "github.com/jbenet/go-ipfs/pipes"
pipes "github.com/jbenet/go-ipfs/util/pipes"
)
// SecurePipe objects represent a bi-directional message channel.

View File

@ -11,7 +11,7 @@ import (
ci "github.com/jbenet/go-ipfs/crypto"
pb "github.com/jbenet/go-ipfs/crypto/spipe/internal/pb"
"github.com/jbenet/go-ipfs/peer"
"github.com/jbenet/go-ipfs/pipes"
"github.com/jbenet/go-ipfs/util/pipes"
)
type SignedPipe struct {

View File

@ -51,8 +51,8 @@ type msgioPipe struct {
func newMsgioPipe(size int, pool *sync.Pool) *msgioPipe {
return &msgioPipe{
outgoing: msgio.NewChan(size, nil),
incoming: msgio.NewChan(size, pool),
outgoing: msgio.NewChan(size),
incoming: msgio.NewChanWithPool(size, pool),
}
}

View File

@ -8,8 +8,8 @@ import (
spipe "github.com/jbenet/go-ipfs/crypto/spipe"
peer "github.com/jbenet/go-ipfs/peer"
"github.com/jbenet/go-ipfs/pipes"
ctxc "github.com/jbenet/go-ipfs/util/ctxcloser"
"github.com/jbenet/go-ipfs/util/pipes"
)
// secureConn wraps another Conn object with an encrypted channel.