File: connection_helper.go

package info (click to toggle)
golang-gopkg-rethinkdb-rethinkdb-go.v6 6.2.1-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,736 kB
  • sloc: python: 1,382; makefile: 16; sh: 9
file content (30 lines) | stat: -rw-r--r-- 589 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package rethinkdb

import (
	"golang.org/x/net/context"
	"io"
)

// Write 'data' to conn
func (c *Connection) writeData(data []byte) error {
	_, err := c.Conn.Write(data[:])

	return err
}

func (c *Connection) read(buf []byte) (total int, err error) {
	return io.ReadFull(c.Conn, buf)
}

func (c *Connection) contextFromConnectionOpts() context.Context {
	// back compatibility
	min := c.opts.ReadTimeout
	if c.opts.WriteTimeout < min {
		min = c.opts.WriteTimeout
	}
	if min == 0 {
		return context.Background()
	}
	ctx, _ := context.WithTimeout(context.Background(), min)
	return ctx
}