From 66d5ef4541f0a3a9037ee0f7af7ecc72a318f240 Mon Sep 17 00:00:00 2001 From: siddontang Date: Thu, 23 Oct 2014 13:49:25 +0800 Subject: [PATCH] new conn with size --- client/go/ledis/conn.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/client/go/ledis/conn.go b/client/go/ledis/conn.go index 527b1f3..3d91925 100644 --- a/client/go/ledis/conn.go +++ b/client/go/ledis/conn.go @@ -25,6 +25,9 @@ type Conn struct { br *bufio.Reader bw *bufio.Writer + rSize int + wSize int + lastActive time.Time // Scratch space for formatting argument length. @@ -39,6 +42,16 @@ func NewConn(addr string) *Conn { co := new(Conn) co.addr = addr + co.rSize = 4096 + co.wSize = 4096 + + return co +} + +func NewConnSize(addr string, readSize int, writeSize int) *Conn { + co := NewConn(addr) + co.rSize = readSize + co.wSize = writeSize return co } @@ -119,13 +132,13 @@ func (c *Conn) connect() error { if c.br != nil { c.br.Reset(c.c) } else { - c.br = bufio.NewReader(c.c) + c.br = bufio.NewReaderSize(c.c, c.rSize) } if c.bw != nil { c.bw.Reset(c.c) } else { - c.bw = bufio.NewWriter(c.c) + c.bw = bufio.NewWriterSize(c.c, c.wSize) } return nil @@ -371,9 +384,8 @@ func (c *Conn) readReply() (interface{}, error) { } func (c *Client) newConn(addr string) *Conn { - co := new(Conn) + co := NewConn(addr) co.client = c - co.addr = addr return co }