consul: ConnPool creates RPC client
This commit is contained in:
parent
03bd66c8fa
commit
f7f743dfa9
|
@ -1,7 +1,9 @@
|
|||
package consul
|
||||
|
||||
import (
|
||||
"github.com/ugorji/go/codec"
|
||||
"net"
|
||||
"net/rpc"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
@ -10,6 +12,7 @@ import (
|
|||
type Conn struct {
|
||||
addr net.Addr
|
||||
conn *net.TCPConn
|
||||
client *rpc.Client
|
||||
}
|
||||
|
||||
// ConnPool is used to maintain a connection pool to other
|
||||
|
@ -104,10 +107,15 @@ func (p *ConnPool) getNewConn(addr net.Addr) (*Conn, error) {
|
|||
// Write the Consul RPC byte to set the mode
|
||||
conn.Write([]byte{byte(rpcConsul)})
|
||||
|
||||
// Create the RPC client
|
||||
cc := codec.GoRpc.ClientCodec(conn, &codec.MsgpackHandle{})
|
||||
client := rpc.NewClientWithCodec(cc)
|
||||
|
||||
// Wrap the connection
|
||||
c := &Conn{
|
||||
addr: addr,
|
||||
conn: conn,
|
||||
client: client,
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue