summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/sys/TCPIOPlugin.cpp
diff options
context:
space:
mode:
authorAndrew Stitcher <astitcher@apache.org>2008-05-09 02:00:04 +0000
committerAndrew Stitcher <astitcher@apache.org>2008-05-09 02:00:04 +0000
commit2d4d4a1425d3f4e189868d36a0cc9fbd4bec4756 (patch)
tree7413a08c12494e5c5551b3f09ad35f29804d66a3 /cpp/src/qpid/sys/TCPIOPlugin.cpp
parent266fbd3880a49ea4f6a221231027408a32033687 (diff)
downloadqpid-python-2d4d4a1425d3f4e189868d36a0cc9fbd4bec4756.tar.gz
QPID-1040: Patch from Ted Ross: Asynchronous Connector
Code to allow non-blocking connection of new sockets git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@654666 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/sys/TCPIOPlugin.cpp')
-rw-r--r--cpp/src/qpid/sys/TCPIOPlugin.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/cpp/src/qpid/sys/TCPIOPlugin.cpp b/cpp/src/qpid/sys/TCPIOPlugin.cpp
index 65ea380b07..045bc56e90 100644
--- a/cpp/src/qpid/sys/TCPIOPlugin.cpp
+++ b/cpp/src/qpid/sys/TCPIOPlugin.cpp
@@ -101,16 +101,20 @@ void AsynchIOProtocolFactory::accept(Poller::shared_ptr poller, ConnectionCodec:
boost::bind(&AsynchIOProtocolFactory::established, this, poller, _1, fact, false)));
acceptor->start(poller);
}
-
+
void AsynchIOProtocolFactory::connect(
Poller::shared_ptr poller,
const std::string& host, int16_t port,
ConnectionCodec::Factory* f)
{
- Socket* socket = new Socket();//Should be deleted by handle when socket closes
- socket->connect(host, port);
-
- established(poller, *socket, f, true);
+ // Note that the following logic does not cause a memory leak.
+ // The allocated Socket is freed either by the AsynchConnector
+ // upon connection failure or by the AsynchIO upon connection
+ // shutdown. The allocated AsynchConnector frees itself when it
+ // is no longer needed.
+ Socket* socket = new Socket();
+ new AsynchConnector(*socket, poller, host, port,
+ boost::bind(&AsynchIOProtocolFactory::established, this, poller, _1, f, true));
}
}} // namespace qpid::sys