From ee4b1ce9dd74aec666154f7b4dc3d7d1afe3dfcd Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Mon, 9 Dec 2013 14:29:20 -0800 Subject: [PATCH] consul: Write the byte to set the RPC mode --- consul/pool.go | 7 ++++++- consul/raft_rpc.go | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/consul/pool.go b/consul/pool.go index a9bb49dfff..c46182e2c2 100644 --- a/consul/pool.go +++ b/consul/pool.go @@ -14,7 +14,9 @@ type Conn struct { // ConnPool is used to maintain a connection pool to other // Consul servers. This is used to reduce the latency of -// RPC requests between servers +// RPC requests between servers. It is only used to pool +// connections in the rpcConsul mode. Raft connections +// are pooled seperately. type ConnPool struct { sync.Mutex @@ -99,6 +101,9 @@ func (p *ConnPool) getNewConn(addr net.Addr) (*Conn, error) { conn.SetKeepAlive(true) conn.SetNoDelay(true) + // Write the Consul RPC byte to set the mode + conn.Write([]byte{byte(rpcConsul)}) + // Wrap the connection c := &Conn{ addr: addr, diff --git a/consul/raft_rpc.go b/consul/raft_rpc.go index 1215212384..6c29a7c65e 100644 --- a/consul/raft_rpc.go +++ b/consul/raft_rpc.go @@ -74,5 +74,12 @@ func (l *RaftLayer) Addr() net.Addr { // Dial is used to create a new outgoing connection func (l *RaftLayer) Dial(address string, timeout time.Duration) (net.Conn, error) { - return net.DialTimeout("tcp", address, timeout) + conn, err := net.DialTimeout("tcp", address, timeout) + if err != nil { + return nil, err + } + + // Write the Raft byte to set the mode + conn.Write([]byte{byte(rpcRaft)}) + return conn, err }