From cf8e2aca04c9a4021448f829e5b264dad25b28c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Fri, 20 Nov 2009 19:23:09 +0100 Subject: Fixed connection leak. diff --git a/Swiften/Network/BoostConnectionServer.cpp b/Swiften/Network/BoostConnectionServer.cpp index 4e83ad5..cea016d 100644 --- a/Swiften/Network/BoostConnectionServer.cpp +++ b/Swiften/Network/BoostConnectionServer.cpp @@ -37,6 +37,7 @@ void BoostConnectionServer::stop() { void BoostConnectionServer::stop(boost::optional e) { if (acceptor_) { acceptor_->close(); + delete acceptor_; acceptor_ = NULL; } MainEventLoop::postEvent(boost::bind(boost::ref(onStopped), e), shared_from_this()); diff --git a/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp b/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp index a5c51aa..926c9ae 100644 --- a/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp +++ b/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp @@ -25,6 +25,9 @@ class BoostConnectionServerTest : public CppUnit::TestFixture { } void tearDown() { + while (eventLoop_->hasEvents()) { + eventLoop_->processEvents(); + } delete eventLoop_; delete boostIOServiceThread_; } diff --git a/Swiften/QA/NetworkTest/BoostConnectionTest.cpp b/Swiften/QA/NetworkTest/BoostConnectionTest.cpp index 9929eaa..af4e003 100644 --- a/Swiften/QA/NetworkTest/BoostConnectionTest.cpp +++ b/Swiften/QA/NetworkTest/BoostConnectionTest.cpp @@ -18,6 +18,7 @@ class BoostConnectionTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(BoostConnectionTest); CPPUNIT_TEST(testDestructor); CPPUNIT_TEST(testDestructor_PendingEvents); + CPPUNIT_TEST(testWrite); CPPUNIT_TEST_SUITE_END(); public: @@ -26,6 +27,7 @@ class BoostConnectionTest : public CppUnit::TestFixture { void setUp() { boostIOServiceThread_ = new BoostIOServiceThread(); eventLoop_ = new DummyEventLoop(); + disconnected = false; } void tearDown() { @@ -51,9 +53,36 @@ class BoostConnectionTest : public CppUnit::TestFixture { eventLoop_->processEvents(); } + void testWrite() { + boost::shared_ptr testling(new BoostConnection(&boostIOServiceThread_->getIOService())); + testling->onConnectFinished.connect(boost::bind(&BoostConnectionTest::doWrite, this, testling.get())); + testling->onDataRead.connect(boost::bind(&BoostConnectionTest::handleDataRead, this, _1)); + testling->onDisconnected.connect(boost::bind(&BoostConnectionTest::handleDisconnected, this)); + testling->connect(HostAddressPort(HostAddress("65.99.222.137"), 5222)); + while (receivedData.isEmpty()) { + Swift::sleep(10); + eventLoop_->processEvents(); + } + testling->disconnect(); + } + + void doWrite(BoostConnection* connection) { + connection->write(ByteArray("")); + } + + void handleDataRead(const ByteArray& data) { + receivedData += data; + } + + void handleDisconnected() { + disconnected = true; + } + private: BoostIOServiceThread* boostIOServiceThread_; DummyEventLoop* eventLoop_; + ByteArray receivedData; + bool disconnected; }; CPPUNIT_TEST_SUITE_REGISTRATION(BoostConnectionTest); -- cgit v0.10.2-6-g49f6