From 2d4d4a1425d3f4e189868d36a0cc9fbd4bec4756 Mon Sep 17 00:00:00 2001 From: Andrew Stitcher Date: Fri, 9 May 2008 02:00:04 +0000 Subject: 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 --- cpp/src/qpid/sys/TCPIOPlugin.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'cpp/src/qpid/sys/TCPIOPlugin.cpp') 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 -- cgit v1.2.1