Skip to content
This repository was archived by the owner on Aug 19, 2022. It is now read-only.

Commit fbb6727

Browse files
only use the teeConn for reading the first handshake message
1 parent 00f3b99 commit fbb6727

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

conn.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,23 @@ func (c *teeConn) Read(b []byte) (int, error) {
6666
}
6767

6868
type wrappedConn struct {
69+
// Before reading the first handshake message, this is a *teeConn.
70+
// After reading the first handshake message, we switch it to the rawConn.
6971
net.Conn
7072

73+
rawConn net.Conn
7174
hasReadFirstMessage bool
72-
raw bytes.Buffer // contains a copy of every byte of the first handshake message we read from the wire
75+
raw *bytes.Buffer // contains a copy of every byte of the first handshake message we read from the wire
7376

7477
hand bytes.Buffer // used to store the first handshake message until we've completely read it
75-
7678
}
7779

7880
func newWrappedConn(c net.Conn) net.Conn {
79-
wc := &wrappedConn{}
80-
wc.Conn = newTeeConn(c, &wc.raw)
81+
wc := &wrappedConn{
82+
raw: &bytes.Buffer{},
83+
rawConn: c,
84+
}
85+
wc.Conn = newTeeConn(c, wc.raw)
8186
return wc
8287
}
8388

@@ -92,6 +97,8 @@ func (c *wrappedConn) Read(b []byte) (int, error) {
9297
if c.raw.Len() > 0 {
9398
n, err := c.raw.Read(b)
9499
if err == io.EOF || c.raw.Len() == 0 {
100+
c.raw = nil
101+
c.Conn = c.rawConn
95102
c.hasReadFirstMessage = true
96103
err = nil
97104
}

0 commit comments

Comments
 (0)