-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_nobench.go
58 lines (51 loc) · 1.08 KB
/
client_nobench.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// +build !riak
package rkive
import (
"net"
"sync"
)
// Client represents a pool of connections
// to a Riak cluster.
type Client struct {
conns int32 // total live conns
pad1 [4]byte //
inuse int32 // conns in use
pad2 [4]byte //
tag int32 // 0 = open; 1 = closed; others reserved
pad3 [4]byte //
id []byte // client ID for writeClientID
pool sync.Pool // connection pool
addrs []*net.TCPAddr // addresses to dial
}
func (c *Client) doBuf(code byte, msg []byte) ([]byte, byte, error) {
var retried bool
try:
node, err := c.popConn()
if err != nil {
return nil, 0, err
}
msg[4] = code
_, err = node.Write(msg)
if err != nil {
go c.err(node)
// it could be the case that we pulled
// a bad connection from the pool - we'll
// attempt one retry
if !retried {
retried = true
goto try
}
return nil, 0, err
}
if err != nil {
c.err(node)
return nil, 0, err
}
msg, code, err = readResponse(node, msg)
if err == nil {
c.done(node)
} else {
c.err(node)
}
return msg, code, nil
}