kubo/p2p/net/mock/mock_stream.go
2015-01-24 09:13:44 -08:00

33 lines
490 B
Go

package mocknet
import (
"io"
inet "github.com/jbenet/go-ipfs/p2p/net"
)
// stream implements inet.Stream
type stream struct {
io.Reader
io.Writer
conn *conn
}
func (s *stream) Close() error {
s.conn.removeStream(s)
if r, ok := (s.Reader).(io.Closer); ok {
r.Close()
}
if w, ok := (s.Writer).(io.Closer); ok {
w.Close()
}
s.conn.net.notifyAll(func(n inet.Notifiee) {
n.ClosedStream(s.conn.net, s)
})
return nil
}
func (s *stream) Conn() inet.Conn {
return s.conn
}