1
0
Fork 0

Conn, not PoolConn

It's already in the pool package.
master
Philip O'Toole 3 years ago
parent 38eef8ee82
commit 955f2302c4

@ -347,7 +347,7 @@ func (c *Client) dial(nodeAddr string, timeout time.Duration) (net.Conn, error)
} }
func handleConnError(conn net.Conn) { func handleConnError(conn net.Conn) {
if pc, ok := conn.(*pool.PoolConn); ok { if pc, ok := conn.(*pool.Conn); ok {
pc.MarkUnusable() pc.MarkUnusable()
} }
} }

@ -40,7 +40,7 @@ func TestPool_Get_Impl(t *testing.T) {
t.Errorf("Get error: %s", err) t.Errorf("Get error: %s", err)
} }
_, ok := conn.(*PoolConn) _, ok := conn.(*Conn)
if !ok { if !ok {
t.Errorf("Conn is not of type poolConn") t.Errorf("Conn is not of type poolConn")
} }
@ -135,7 +135,7 @@ func TestPool_PutUnusableConn(t *testing.T) {
} }
conn, _ = p.Get() conn, _ = p.Get()
if pc, ok := conn.(*PoolConn); !ok { if pc, ok := conn.(*Conn); !ok {
t.Errorf("impossible") t.Errorf("impossible")
} else { } else {
pc.MarkUnusable() pc.MarkUnusable()

@ -5,17 +5,17 @@ import (
"sync" "sync"
) )
// PoolConn is a wrapper around net.Conn to modify the the behavior of // Conn is a wrapper around net.Conn to modify the the behavior of
// net.Conn's Close() method. // net.Conn's Close() method.
type PoolConn struct { type Conn struct {
net.Conn net.Conn
mu sync.RWMutex mu sync.RWMutex
c *channelPool c *channelPool
unusable bool unusable bool
} }
// Close puts the given connects back to the pool instead of closing it. // Close puts the given connection back into the pool instead of closing it.
func (p *PoolConn) Close() error { func (p *Conn) Close() error {
p.mu.RLock() p.mu.RLock()
defer p.mu.RUnlock() defer p.mu.RUnlock()
@ -29,7 +29,7 @@ func (p *PoolConn) Close() error {
} }
// MarkUnusable marks the connection not usable any more, to let the pool close it instead of returning it to pool. // MarkUnusable marks the connection not usable any more, to let the pool close it instead of returning it to pool.
func (p *PoolConn) MarkUnusable() { func (p *Conn) MarkUnusable() {
p.mu.Lock() p.mu.Lock()
p.unusable = true p.unusable = true
p.mu.Unlock() p.mu.Unlock()
@ -37,7 +37,7 @@ func (p *PoolConn) MarkUnusable() {
// newConn wraps a standard net.Conn to a poolConn net.Conn. // newConn wraps a standard net.Conn to a poolConn net.Conn.
func (c *channelPool) wrapConn(conn net.Conn) net.Conn { func (c *channelPool) wrapConn(conn net.Conn) net.Conn {
p := &PoolConn{c: c} p := &Conn{c: c}
p.Conn = conn p.Conn = conn
return p return p
} }

@ -6,5 +6,5 @@ import (
) )
func TestConn_Impl(t *testing.T) { func TestConn_Impl(t *testing.T) {
var _ net.Conn = new(PoolConn) var _ net.Conn = new(Conn)
} }

Loading…
Cancel
Save