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 {
19 if n > len(c.prefix) {
22 copy(buf[:n], c.prefix[:n])
23 c.prefix = c.prefix[n:]
24 if len(c.prefix) == 0 {
29 return c.Conn.Read(buf)
32// xprefixConn returns either the original net.Conn passed as parameter, or returns
33// a *prefixConn returning the buffered data available in br followed data from the
35func xprefixConn(c net.Conn, br *bufio.Reader) net.Conn {
41 buf := make([]byte, n)
42 _, err := io.ReadFull(c, buf)
43 xcheckf(err, "get buffered data")
44 return &prefixConn{buf, c}