Simplify close.

This commit is contained in:
Vladimir Mihailenco 2013-11-04 09:53:48 +02:00
parent bead8d1ea2
commit fe2e33a4f2
1 changed files with 7 additions and 7 deletions

View File

@ -31,7 +31,7 @@ func newConn(netcn net.Conn) *conn {
cn := &conn{ cn := &conn{
cn: netcn, cn: netcn,
} }
cn.rd = bufio.NewReaderSize(cn, 1024) cn.rd = bufio.NewReader(cn)
return cn return cn
} }
@ -53,6 +53,10 @@ func (cn *conn) Write(b []byte) (int, error) {
return cn.cn.Write(b) return cn.cn.Write(b)
} }
func (cn *conn) Close() error {
return cn.cn.Close()
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
type connPool struct { type connPool struct {
@ -129,7 +133,7 @@ func (p *connPool) Put(cn *conn) error {
func (p *connPool) Remove(cn *conn) error { func (p *connPool) Remove(cn *conn) error {
var err error var err error
if cn != nil { if cn != nil {
err = p.closeConn(cn) err = cn.Close()
} }
p.cond.L.Lock() p.cond.L.Lock()
p.size-- p.size--
@ -155,7 +159,7 @@ func (p *connPool) Close() error {
p.cond.L.Lock() p.cond.L.Lock()
for e := p.conns.Front(); e != nil; e = e.Next() { for e := p.conns.Front(); e != nil; e = e.Next() {
if err := p.closeConn(e.Value.(*conn)); err != nil { if err := e.Value.(*conn).Close(); err != nil {
return err return err
} }
} }
@ -165,10 +169,6 @@ func (p *connPool) Close() error {
return nil return nil
} }
func (p *connPool) closeConn(cn *conn) error {
return cn.cn.Close()
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
type singleConnPool struct { type singleConnPool struct {