consul: ConnPool creates RPC client

This commit is contained in:
Armon Dadgar 2013-12-09 14:52:22 -08:00
parent 1a9a51c5c2
commit ae30ace448
1 changed files with 12 additions and 4 deletions

View File

@ -1,15 +1,18 @@
package consul package consul
import ( import (
"github.com/ugorji/go/codec"
"net" "net"
"net/rpc"
"sync" "sync"
"time" "time"
) )
// Conn is a pooled connection to a Consul server // Conn is a pooled connection to a Consul server
type Conn struct { type Conn struct {
addr net.Addr addr net.Addr
conn *net.TCPConn conn *net.TCPConn
client *rpc.Client
} }
// ConnPool is used to maintain a connection pool to other // 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 // Write the Consul RPC byte to set the mode
conn.Write([]byte{byte(rpcConsul)}) conn.Write([]byte{byte(rpcConsul)})
// Create the RPC client
cc := codec.GoRpc.ClientCodec(conn, &codec.MsgpackHandle{})
client := rpc.NewClientWithCodec(cc)
// Wrap the connection // Wrap the connection
c := &Conn{ c := &Conn{
addr: addr, addr: addr,
conn: conn, conn: conn,
client: client,
} }
return c, nil return c, nil
} }