forked from libp2p/go-libp2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream.go
64 lines (47 loc) · 1.15 KB
/
stream.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package yamux
import (
"time"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-yamux/v4"
)
// stream implements mux.MuxedStream over yamux.Stream.
type stream yamux.Stream
var _ network.MuxedStream = &stream{}
func (s *stream) Read(b []byte) (n int, err error) {
n, err = s.yamux().Read(b)
if err == yamux.ErrStreamReset {
err = network.ErrReset
}
return n, err
}
func (s *stream) Write(b []byte) (n int, err error) {
n, err = s.yamux().Write(b)
if err == yamux.ErrStreamReset {
err = network.ErrReset
}
return n, err
}
func (s *stream) Close() error {
return s.yamux().Close()
}
func (s *stream) Reset() error {
return s.yamux().Reset()
}
func (s *stream) CloseRead() error {
return s.yamux().CloseRead()
}
func (s *stream) CloseWrite() error {
return s.yamux().CloseWrite()
}
func (s *stream) SetDeadline(t time.Time) error {
return s.yamux().SetDeadline(t)
}
func (s *stream) SetReadDeadline(t time.Time) error {
return s.yamux().SetReadDeadline(t)
}
func (s *stream) SetWriteDeadline(t time.Time) error {
return s.yamux().SetWriteDeadline(t)
}
func (s *stream) yamux() *yamux.Stream {
return (*yamux.Stream)(s)
}