multiconn: close fanIn + error
Juan Batiz-Benet committed
Dec 13, 2014 at 04:56 UTC
129eca0d824f266fce4ec2dfe9b40cb56202831a
1 file changed
+7
-1
net/conn/multiconn.go
+7
-1
@@ -2,6 +2,7 @@ package conn
2
3
import (
4
"errors"
5
+ "fmt"
6
"sync"
7
8
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
@@ -179,6 +180,7 @@ func (c *MultiConn) close() error {
180
181
// close underlying connections
182
CloseConns(conns...)
183
+ close(c.fanIn)
184
return nil
185
}
186
@@ -266,7 +268,10 @@ func (c *MultiConn) Write(buf []byte) (int, error) {
268
269
// ReadMsg reads data, net.Conn style
270
func (c *MultiConn) ReadMsg() ([]byte, error) {
269
- next := <-c.fanIn
271
+ next, ok := <-c.fanIn
272
+ if !ok {
273
+ return nil, fmt.Errorf("multiconn closed")
274
+ }
275
return next, nil
276
}
277
@@ -281,6 +286,7 @@ func (c *MultiConn) WriteMsg(buf []byte) error {
286
287
// ReleaseMsg releases a buffer
288
func (c *MultiConn) ReleaseMsg(m []byte) {
289
+ // here, we dont know where it came from. hm.
290
for _, c := range c.getConns() {
291
c.ReleaseMsg(m)
292
}