-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conn.go
51 lines (44 loc) · 945 Bytes
/
conn.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
package greddis
import (
"bufio"
"net"
"sync/atomic"
"time"
)
type conn struct {
conn net.Conn
arrw *ArrayWriter
res *Result
r *Reader
created time.Time
toBeClosed int64 // only for use with atomics
inUse int64 // only for use with atomics
}
func newConn(c net.Conn, initBufSize int) *conn {
r := NewReader(bufio.NewReaderSize(c, initBufSize))
return &conn{
conn: c,
r: r,
arrw: NewArrayWriter((bufio.NewWriter(c))),
res: NewResult(r),
created: time.Now(),
toBeClosed: 0,
inUse: 0,
}
}
func (c *conn) getToBeClosed() bool {
return (atomic.LoadInt64(&c.toBeClosed) == 1)
}
func (c *conn) setToBeClosed() {
atomic.StoreInt64(&c.toBeClosed, 1)
}
func (c *conn) getInUse() bool {
return (atomic.LoadInt64(&c.inUse) == 1)
}
func (c *conn) setInUse(yes bool) {
var truth int64
if yes {
truth = 1
}
atomic.StoreInt64(&c.inUse, truth)
}