Commit 2253d08d authored by Juan Benet's avatar Juan Benet

Merge pull request #2048 from ipfs/deps/go-peerstream

update go-peerstream dep
parents d58053b2 edc7b0f6
......@@ -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 is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment