| 1 | package rethinkdb |
| 2 | |
| 3 | import ( |
| 4 | "golang.org/x/net/context" |
| 5 | "io" |
| 6 | ) |
| 7 | |
| 8 | // Write 'data' to conn |
| 9 | func (c *Connection) writeData(data []byte) error { |
| 10 | _, err := c.Conn.Write(data[:]) |
| 11 | |
| 12 | return err |
| 13 | } |
| 14 | |
| 15 | func (c *Connection) read(buf []byte) (total int, err error) { |
| 16 | return io.ReadFull(c.Conn, buf) |
| 17 | } |
| 18 | |
| 19 | func (c *Connection) contextFromConnectionOpts() context.Context { |
| 20 | // back compatibility |
| 21 | min := c.opts.ReadTimeout |
| 22 | if c.opts.WriteTimeout < min { |
| 23 | min = c.opts.WriteTimeout |
| 24 | } |
| 25 | if min == 0 { |
| 26 | return context.Background() |
| 27 | } |
| 28 | ctx, _ := context.WithTimeout(context.Background(), min) |
| 29 | return ctx |
| 30 | } |