@@ -26,7 +26,8 @@ import (
26
26
// different from most net.Conn implementations where only the
27
27
// reading/writing goroutines are interrupted but the connection is kept alive.
28
28
//
29
- // The Addr methods will return a mock net.Addr.
29
+ // The Addr methods will return a mock net.Addr that returns "websocket" for Network
30
+ // and "websocket/unknown-addr" for String.
30
31
//
31
32
// A received StatusNormalClosure close frame will be translated to EOF when reading.
32
33
func NetConn (c * Conn ) net.Conn {
@@ -37,11 +38,15 @@ func NetConn(c *Conn) net.Conn {
37
38
var cancel context.CancelFunc
38
39
nc .writeContext , cancel = context .WithCancel (context .Background ())
39
40
nc .writeTimer = time .AfterFunc (math .MaxInt64 , cancel )
40
- nc .writeTimer .Stop ()
41
+ if ! nc .writeTimer .Stop () {
42
+ <- nc .writeTimer .C
43
+ }
41
44
42
45
nc .readContext , cancel = context .WithCancel (context .Background ())
43
46
nc .readTimer = time .AfterFunc (math .MaxInt64 , cancel )
44
- nc .readTimer .Stop ()
47
+ if ! nc .readTimer .Stop () {
48
+ <- nc .readTimer .C
49
+ }
45
50
46
51
return nc
47
52
}
@@ -103,23 +108,23 @@ func (c *netConn) Read(p []byte) (int, error) {
103
108
return n , err
104
109
}
105
110
106
- type unknownAddr struct {
111
+ type websocketAddr struct {
107
112
}
108
113
109
- func (a unknownAddr ) Network () string {
110
- return "unknown "
114
+ func (a websocketAddr ) Network () string {
115
+ return "websocket "
111
116
}
112
117
113
- func (a unknownAddr ) String () string {
114
- return "unknown"
118
+ func (a websocketAddr ) String () string {
119
+ return "websocket/ unknown-addr "
115
120
}
116
121
117
122
func (c * netConn ) RemoteAddr () net.Addr {
118
- return unknownAddr {}
123
+ return websocketAddr {}
119
124
}
120
125
121
126
func (c * netConn ) LocalAddr () net.Addr {
122
- return unknownAddr {}
127
+ return websocketAddr {}
123
128
}
124
129
125
130
func (c * netConn ) SetDeadline (t time.Time ) error {
0 commit comments