Susumu Yata
null+****@clear*****
Thu Jul 27 11:52:44 JST 2017
Susumu Yata 2017-07-27 11:52:44 +0900 (Thu, 27 Jul 2017) New Revision: d7eb6802c9e23a6155f279e3029f81dab4cb02b9 https://github.com/groonga/grnci/commit/d7eb6802c9e23a6155f279e3029f81dab4cb02b9 Message: Move client from response to Conn. Modified files: v2/libgrn/client.go v2/libgrn/conn.go v2/libgrn/response.go Modified: v2/libgrn/client.go (+8 -6) =================================================================== --- v2/libgrn/client.go 2017-07-27 11:45:41 +0900 (3de33db) +++ v2/libgrn/client.go 2017-07-27 11:52:44 +0900 (863ad86) @@ -39,12 +39,13 @@ func DialClient(addr string, options *ClientOptions) (*Client, error) { if err != nil { return nil, err } - conns := make(chan *Conn, options.MaxIdleConns) - conns <- conn - return &Client{ + c := &Client{ addr: addr, - idleConns: conns, - }, nil + idleConns: make(chan *Conn, options.MaxIdleConns), + } + c.idleConns <- conn + conn.client = c + return c, nil } // OpenClient opens an existing DB and returns a new Client. @@ -113,11 +114,13 @@ func (c *Client) exec(cmd string, body io.Reader) (grnci.Response, error) { if err != nil { return nil, err } + conn.client = c } else { conn, err = c.baseConn.Dup() if err != nil { return nil, err } + conn.client = c } } resp, err := conn.exec(cmd, body) @@ -125,7 +128,6 @@ func (c *Client) exec(cmd string, body io.Reader) (grnci.Response, error) { conn.Close() return nil, err } - resp.(*response).client = c return resp, nil } Modified: v2/libgrn/conn.go (+1 -0) =================================================================== --- v2/libgrn/conn.go 2017-07-27 11:45:41 +0900 (21acf34) +++ v2/libgrn/conn.go 2017-07-27 11:52:44 +0900 (df94f28) @@ -19,6 +19,7 @@ const ( // Conn is a thread-unsafe GQTP client or DB handle. type Conn struct { + client *Client // Owner client if available ctx *grnCtx // C.grn_ctx db *grnDB // C.grn_obj buf []byte // Copy buffer Modified: v2/libgrn/response.go (+2 -3) =================================================================== --- v2/libgrn/response.go 2017-07-27 11:45:41 +0900 (6883810) +++ v2/libgrn/response.go 2017-07-27 11:52:44 +0900 (209ad86) @@ -10,7 +10,6 @@ import ( // response is a response. type response struct { - client *Client conn *Conn left []byte flags byte @@ -90,7 +89,7 @@ func (r *response) Close() error { if !r.conn.broken { r.conn.ready = true } - if r.client != nil { + if r.conn.client != nil { // Broken connections are closed. if r.conn.broken { if e := r.conn.Close(); e != nil && err != nil { @@ -98,7 +97,7 @@ func (r *response) Close() error { } } select { - case r.client.idleConns <- r.conn: + case r.conn.client.idleConns <- r.conn: default: if e := r.conn.Close(); e != nil && err != nil { err = e -------------- next part -------------- HTML����������������������������... Download