8// prefixConn is a net.Conn with a buffer from which the first reads are satisfied.
9// used for STARTTLS where already did a buffered read of initial TLS data.
10type prefixConn struct {
15func (c *prefixConn) Read(buf []byte) (int, error) {
16 if len(c.prefix) > 0 {
17 n := min(len(buf), len(c.prefix))
18 copy(buf[:n], c.prefix[:n])
19 c.prefix = c.prefix[n:]
20 if len(c.prefix) == 0 {
25 return c.Conn.Read(buf)
28// xprefixConn checks if there are any buffered unconsumed reads. If not, it
29// returns c.conn. Otherwise, it returns a *prefixConn from which the buffered data
30// can be read followed by data from c.conn.
31func (c *Conn) xprefixConn() net.Conn {
37 buf := make([]byte, n)
38 _, err := io.ReadFull(c.br, buf)
39 c.xcheckf(err, "get buffered data")
40 return &prefixConn{buf, c.conn}