face/tcp: Add map of remoteEndpoint-Face within channel
If connect operation requested twice for the same remote endpoint (and
the first connection was successful), the second request will call
FaceCreated callback immediately (or after endpoint resolution) with the
previously created face.
refs: #1132, #1134
Change-Id: I5f7e5237a42289a96d7fd9d16bda47fc7cda4dfc
diff --git a/daemon/face/tcp-channel.cpp b/daemon/face/tcp-channel.cpp
index bbefa44..9da453e 100644
--- a/daemon/face/tcp-channel.cpp
+++ b/daemon/face/tcp-channel.cpp
@@ -42,6 +42,12 @@
const TcpChannel::ConnectFailedCallback& onConnectFailed,
const time::Duration& timeout/* = time::seconds(4)*/)
{
+ ChannelFaceMap::iterator i = m_channelFaces.find(remoteEndpoint);
+ if (i != m_channelFaces.end()) {
+ onFaceCreated(i->second);
+ return;
+ }
+
shared_ptr<ip::tcp::socket> clientSocket =
make_shared<ip::tcp::socket>(boost::ref(m_ioService));
@@ -116,6 +122,9 @@
*/
shared_ptr<TcpFace> face = make_shared<TcpFace>(1, boost::cref(socket));
onFaceCreated(face);
+
+ tcp::Endpoint remoteEndpoint = socket->remote_endpoint();
+ m_channelFaces[remoteEndpoint] = face;
}
void