/
stream.go
97 lines (73 loc) · 1.88 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package h2transport
import (
"net"
"time"
"github.com/docker/spdystream"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/protocol"
)
// Implements MuxedStream AND net.Conn
// Also implements ssh.Channel - add SendRequest and Stderr, as well as CloseWrite
type stream struct {
spdystream *spdystream.Stream
stat network.Stat
con *SPDYConn
}
func (s *stream) CloseWrite() error {
return s.Close()
}
func (s *stream) CloseRead() error {
return s.Close()
}
func (s *stream) spdyStream() *spdystream.Stream {
return s.spdystream
}
func (s *stream) Read(buf []byte) (int, error) {
return s.spdyStream().Read(buf)
}
func (s *stream) Write(buf []byte) (int, error) {
return s.spdyStream().Write(buf)
}
func (s *stream) Close() error {
// Reset is spdystream's full bidirectional close.
// We expose bidirectional close as our `Close`.
// To close only half of the connection, and use other
// spdystream options, just get the stream with:
// ssStream := (*ss.Stream)(stream)
return s.spdyStream().Close()
}
func (s *stream) Reset() error {
return s.spdyStream().Reset()
}
func (s *stream) SetDeadline(t time.Time) error {
return s.spdystream.SetDeadline(t)
}
func (s *stream) SetReadDeadline(t time.Time) error {
return s.spdystream.SetReadDeadline(t)
}
func (s *stream) SetWriteDeadline(t time.Time) error {
return s.spdystream.SetWriteDeadline(t)
}
// net.Conn only
func (c *stream) LocalAddr() net.Addr {
// MultiAddr doesn't implement 'Network', and the format is not
// portable.
return c.con.wsCon.LocalAddr()
}
func (c *stream) RemoteAddr() net.Addr {
return c.con.wsCon.RemoteAddr()
}
func (c *stream) Stat() network.Stat {
return c.stat
}
func (c *stream) Conn() network.Conn {
return c.con
}
func (c *stream) Protocol() protocol.ID {
return ""
}
func (c *stream) ID() string {
return ""
}
func (c *stream) SetProtocol(id protocol.ID) {
}