提交 edc7b0f6 作者: Jeromy

update go-peerstream dep

License: MIT
Signed-off-by: 's avatarJeromy <jeromyj@gmail.com>
上级 d58053b2
......@@ -200,7 +200,7 @@
},
{
"ImportPath": "github.com/jbenet/go-peerstream",
"Rev": "f90119e97e8be7b2bdd5e598067b0dc44df63381"
"Rev": "f3ab20739a88aa79306dc039c1b5a39e7afa45d6"
},
{
"ImportPath": "github.com/jbenet/go-random",
......
......@@ -47,6 +47,9 @@ type Conn struct {
closed bool
closeLock sync.Mutex
closing bool
closingLock sync.Mutex
}
func newConn(nconn net.Conn, tconn smux.Conn, s *Swarm) *Conn {
......@@ -115,14 +118,31 @@ func (c *Conn) Streams() []*Stream {
return streams
}
// GoClose spawns off a goroutine to close the connection iff the connection is
// not already being closed and returns immediately
func (c *Conn) GoClose() {
c.closingLock.Lock()
defer c.closingLock.Unlock()
if c.closing {
return
}
c.closing = true
go c.Close()
}
// Close closes this connection
func (c *Conn) Close() error {
c.closeLock.Lock()
defer c.closeLock.Unlock()
if c.closed {
if c.closed == true {
return nil
}
c.closingLock.Lock()
c.closing = true
c.closingLock.Unlock()
c.closed = true
// close streams
......
......@@ -14,6 +14,7 @@ import (
"testing"
ps "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream"
smux "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-stream-muxer"
)
......
......@@ -184,7 +184,7 @@ func (s *Swarm) Conns() []*Conn {
open := make([]*Conn, 0, len(conns))
for _, c := range conns {
if c.smuxConn.IsClosed() {
c.Close()
c.GoClose()
} else {
open = append(open, c)
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论