mock_stream.go 490 Bytes
Newer Older
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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 {
22
		w.Close()
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
23
	}
24
25
26
	s.conn.net.notifyAll(func(n inet.Notifiee) {
		n.ClosedStream(s.conn.net, s)
	})
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
27
28
29
30
31
32
	return nil
}

func (s *stream) Conn() inet.Conn {
	return s.conn
}