Author: astitcher Date: Fri Oct 9 03:37:37 2009 New Revision: 823387 URL: http://svn.apache.org/viewvc?rev=823387&view=rev Log: Fix memory usage error in AsynchConnector
Modified: qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIO.h qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp qpid/trunk/qpid/cpp/src/qpid/sys/posix/AsynchIO.cpp Modified: qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIO.h URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIO.h?rev=823387&r1=823386&r2=823387&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIO.h (original) +++ qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIO.h Fri Oct 9 03:37:37 2009 @@ -57,7 +57,7 @@ class AsynchConnector { public: typedef boost::function1<void, const Socket&> ConnectedCallback; - typedef boost::function2<void, int, std::string> FailedCallback; + typedef boost::function3<void, const Socket&, int, const std::string&> FailedCallback; // Call create() to allocate a new AsynchConnector object with the // specified poller, addressing, and callbacks. @@ -70,7 +70,7 @@ std::string hostname, uint16_t port, ConnectedCallback connCb, - FailedCallback failCb = 0); + FailedCallback failCb); protected: AsynchConnector() {} Modified: qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp?rev=823387&r1=823386&r2=823387&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp (original) +++ qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp Fri Oct 9 03:37:37 2009 @@ -46,7 +46,7 @@ void accept(Poller::shared_ptr, ConnectionCodec::Factory*); void connect(Poller::shared_ptr, const std::string& host, int16_t port, ConnectionCodec::Factory*, - boost::function2<void, int, std::string> failed); + ConnectFailedCallback); uint16_t getPort() const; std::string getHost() const; @@ -54,6 +54,7 @@ private: void established(Poller::shared_ptr, const Socket&, ConnectionCodec::Factory*, bool isClient); + void connectFailed(const Socket&, int, const std::string&, ConnectFailedCallback); }; // Static instance to initialise plugin @@ -118,6 +119,15 @@ acceptor->start(poller); } +void AsynchIOProtocolFactory::connectFailed( + const Socket& s, int ec, const std::string& emsg, + ConnectFailedCallback failedCb) +{ + failedCb(ec, emsg); + s.close(); + delete &s; +} + void AsynchIOProtocolFactory::connect( Poller::shared_ptr poller, const std::string& host, int16_t port, @@ -131,13 +141,14 @@ // is no longer needed. Socket* socket = new Socket(); - AsynchConnector::create (*socket, - poller, - host, - port, - boost::bind(&AsynchIOProtocolFactory::established, - this, poller, _1, fact, true), - failed); + AsynchConnector::create(*socket, + poller, + host, + port, + boost::bind(&AsynchIOProtocolFactory::established, + this, poller, _1, fact, true), + boost::bind(&AsynchIOProtocolFactory::connectFailed, + this, _1, _2, _3, failed)); } }} // namespace qpid::sys Modified: qpid/trunk/qpid/cpp/src/qpid/sys/posix/AsynchIO.cpp URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/posix/AsynchIO.cpp?rev=823387&r1=823386&r2=823387&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/sys/posix/AsynchIO.cpp (original) +++ qpid/trunk/qpid/cpp/src/qpid/sys/posix/AsynchIO.cpp Fri Oct 9 03:37:37 2009 @@ -161,7 +161,7 @@ private: void connComplete(DispatchHandle& handle); - void failure(int, std::string); + void failure(int, const std::string&); private: ConnectedCallback connCallback; @@ -174,7 +174,7 @@ std::string hostname, uint16_t port, ConnectedCallback connCb, - FailedCallback failCb = 0); + FailedCallback failCb); }; AsynchConnector::AsynchConnector(const Socket& s, @@ -196,7 +196,7 @@ socket.connect(hostname, port); startWatch(poller); } catch(std::exception& e) { - failure(-1, std::string(e.what())); + failure(-1, e.what()); } } @@ -209,17 +209,13 @@ connCallback(socket); DispatchHandle::doDelete(); } else { - failure(errCode, std::string(strError(errCode))); + failure(errCode, strError(errCode)); } } -void AsynchConnector::failure(int errCode, std::string message) +void AsynchConnector::failure(int errCode, const std::string& message) { - if (failCallback) - failCallback(errCode, message); - - socket.close(); - delete &socket; + failCallback(socket, errCode, message); DispatchHandle::doDelete(); } --------------------------------------------------------------------- Apache Qpid - AMQP Messaging Implementation Project: http://qpid.apache.org Use/Interact: mailto:commits-subscr...@qpid.apache.org