Commit e7bae7d9 authored by AlexStocks's avatar AlexStocks

Fix: use connection

parent f46473b9
......@@ -4,10 +4,13 @@ import (
"math/rand"
"sync"
"time"
)
import (
"github.com/AlexStocks/getty"
"github.com/AlexStocks/goext/sync/atomic"
"github.com/AlexStocks/goext/log"
jerrors "github.com/juju/errors"
)
......@@ -63,12 +66,17 @@ func (c *Client) Call(typ CodecType, addr, service, method string, args interfac
resp := NewPendingResponse()
resp.reply = reply
var err error
var session getty.Session
session, err = c.selectSession(typ, addr)
var (
err error
session getty.Session
conn *gettyRPCClientConn
)
conn, session, err = c.selectSession(typ, addr)
gxlog.CError("conn:%p, session:%p", conn, session)
if err != nil || session == nil {
return errSessionNotExist
}
defer c.pool.release(conn, err)
if err = c.transfer(session, typ, b, resp); err != nil {
return jerrors.Trace(err)
......@@ -92,12 +100,12 @@ func (c *Client) Close() {
c.pool = nil
}
func (c *Client) selectSession(typ CodecType, addr string) (getty.Session, error) {
func (c *Client) selectSession(typ CodecType, addr string) (*gettyRPCClientConn, getty.Session, error) {
rpcConn, err := c.pool.getConn(typ.String(), addr)
if err != nil {
return nil, jerrors.Trace(err)
return nil, nil, jerrors.Trace(err)
}
return rpcConn.selectSession(), nil
return rpcConn, rpcConn.selectSession(), nil
}
func (c *Client) heartbeat(session getty.Session, typ CodecType) error {
......
......@@ -326,7 +326,7 @@ func NewGettyRPCRequest() RPCPackage {
func (req *GettyRPCRequest) Marshal(sz CodecType, buf *bytes.Buffer) (int, error) {
codec := Codecs[sz]
if codec == nil {
return 0, jerrors.Errorf("can not find codec for %d", sz)
return 0, jerrors.Errorf("can not find codec for %s", sz)
}
headerData, err := codec.Encode(req.header)
if err != nil {
......
package rpc
import "time"
import (
"time"
)
import (
jerrors "github.com/juju/errors"
......
......@@ -277,8 +277,6 @@ func (p *gettyRPCClientConnPool) getConn(protocol, addr string) (*gettyRPCClient
continue
}
p.Unlock()
return conn, nil
}
......@@ -291,7 +289,7 @@ func (p *gettyRPCClientConnPool) release(conn *gettyRPCClientConn, err error) {
return
}
if err != nil {
conn.close() //
conn.close()
return
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment