9// prefixConn is a net.Conn with a buffer from which the first reads are satisfied.
10// used for STARTTLS where already did a buffered read of initial TLS data.
11type prefixConn struct {
16func (c *prefixConn) Read(buf []byte) (int, error) {
17 if len(c.prefix) > 0 {
18 n := min(len(buf), len(c.prefix))
19 copy(buf[:n], c.prefix[:n])
20 c.prefix = c.prefix[n:]
21 if len(c.prefix) == 0 {
26 return c.Conn.Read(buf)
29// xprefixConn returns either the original net.Conn passed as parameter, or returns
30// a *prefixConn returning the buffered data available in br followed data from the
32func xprefixConn(c net.Conn, br *bufio.Reader) net.Conn {
38 buf := make([]byte, n)
39 _, err := io.ReadFull(c, buf)
40 xcheckf(err, "get buffered data")
41 return &prefixConn{buf, c}