summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-06-18 21:17:26 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-06-18 21:27:59 (GMT)
commit154bf14ac15fc7bff918c20814b29b5cc3bc5ba4 (patch)
tree28f18493bb6bc1cbf85b90f391daa6c4e1ecb3aa /Swiften/Network
parentb763087e13f25e08aa51a6568b03727f136de34e (diff)
downloadswift-154bf14ac15fc7bff918c20814b29b5cc3bc5ba4.zip
swift-154bf14ac15fc7bff918c20814b29b5cc3bc5ba4.tar.bz2
Fix crash on reconnect.
BoostTimer isn't supposed to be constructed as a non-shared-ptr. Making constructor private to avoid this error in the future.
Diffstat (limited to 'Swiften/Network')
-rw-r--r--Swiften/Network/BoostConnection.h9
-rw-r--r--Swiften/Network/BoostConnectionFactory.cpp2
-rw-r--r--Swiften/Network/BoostConnectionServer.cpp2
-rw-r--r--Swiften/Network/BoostConnectionServer.h9
-rw-r--r--Swiften/Network/BoostTimer.h8
-rw-r--r--Swiften/Network/BoostTimerFactory.cpp2
-rw-r--r--Swiften/Network/Timer.h2
-rw-r--r--Swiften/Network/TimerFactory.h6
8 files changed, 31 insertions, 9 deletions
diff --git a/Swiften/Network/BoostConnection.h b/Swiften/Network/BoostConnection.h
index abe7eeb..8d3d444 100644
--- a/Swiften/Network/BoostConnection.h
+++ b/Swiften/Network/BoostConnection.h
@@ -22,9 +22,14 @@ namespace boost {
namespace Swift {
class BoostConnection : public Connection, public EventOwner, public boost::enable_shared_from_this<BoostConnection> {
public:
- BoostConnection(boost::asio::io_service* ioService);
+ typedef boost::shared_ptr<BoostConnection> ref;
+
~BoostConnection();
+ static ref create(boost::asio::io_service* ioService) {
+ return ref(new BoostConnection(ioService));
+ }
+
virtual void listen();
virtual void connect(const HostAddressPort& address);
virtual void disconnect();
@@ -35,6 +40,8 @@ namespace Swift {
}
private:
+ BoostConnection(boost::asio::io_service* ioService);
+
void handleConnectFinished(const boost::system::error_code& error);
void handleSocketRead(const boost::system::error_code& error, size_t bytesTransferred);
void handleDataWritten(const boost::system::error_code& error);
diff --git a/Swiften/Network/BoostConnectionFactory.cpp b/Swiften/Network/BoostConnectionFactory.cpp
index f84a26e..7ba9f48 100644
--- a/Swiften/Network/BoostConnectionFactory.cpp
+++ b/Swiften/Network/BoostConnectionFactory.cpp
@@ -13,7 +13,7 @@ BoostConnectionFactory::BoostConnectionFactory(boost::asio::io_service* ioServic
}
boost::shared_ptr<Connection> BoostConnectionFactory::createConnection() {
- return boost::shared_ptr<Connection>(new BoostConnection(ioService));
+ return BoostConnection::create(ioService);
}
}
diff --git a/Swiften/Network/BoostConnectionServer.cpp b/Swiften/Network/BoostConnectionServer.cpp
index 51c1203..febe6c9 100644
--- a/Swiften/Network/BoostConnectionServer.cpp
+++ b/Swiften/Network/BoostConnectionServer.cpp
@@ -50,7 +50,7 @@ void BoostConnectionServer::stop(boost::optional<Error> e) {
}
void BoostConnectionServer::acceptNextConnection() {
- boost::shared_ptr<BoostConnection> newConnection(new BoostConnection(&acceptor_->io_service()));
+ BoostConnection::ref newConnection(BoostConnection::create(&acceptor_->io_service()));
acceptor_->async_accept(newConnection->getSocket(),
boost::bind(&BoostConnectionServer::handleAccept, shared_from_this(), newConnection, boost::asio::placeholders::error));
}
diff --git a/Swiften/Network/BoostConnectionServer.h b/Swiften/Network/BoostConnectionServer.h
index 311be4b..3a3c096 100644
--- a/Swiften/Network/BoostConnectionServer.h
+++ b/Swiften/Network/BoostConnectionServer.h
@@ -18,18 +18,25 @@
namespace Swift {
class BoostConnectionServer : public ConnectionServer, public EventOwner, public boost::enable_shared_from_this<BoostConnectionServer> {
public:
+ typedef boost::shared_ptr<BoostConnectionServer> ref;
+
enum Error {
Conflict,
UnknownError
};
- BoostConnectionServer(int port, boost::asio::io_service* ioService);
+ static ref create(int port, boost::asio::io_service* ioService) {
+ return ref(new BoostConnectionServer(port, ioService));
+ }
+
void start();
void stop();
boost::signal<void (boost::optional<Error>)> onStopped;
private:
+ BoostConnectionServer(int port, boost::asio::io_service* ioService);
+
void stop(boost::optional<Error> e);
void acceptNextConnection();
void handleAccept(boost::shared_ptr<BoostConnection> newConnection, const boost::system::error_code& error);
diff --git a/Swiften/Network/BoostTimer.h b/Swiften/Network/BoostTimer.h
index 85db864..f48cb36 100644
--- a/Swiften/Network/BoostTimer.h
+++ b/Swiften/Network/BoostTimer.h
@@ -16,12 +16,18 @@
namespace Swift {
class BoostTimer : public Timer, public EventOwner, public boost::enable_shared_from_this<BoostTimer> {
public:
- BoostTimer(int milliseconds, boost::asio::io_service* service);
+ typedef boost::shared_ptr<BoostTimer> ref;
+
+ static ref create(int milliseconds, boost::asio::io_service* service) {
+ return ref(new BoostTimer(milliseconds, service));
+ }
virtual void start();
virtual void stop();
private:
+ BoostTimer(int milliseconds, boost::asio::io_service* service);
+
void handleTimerTick(const boost::system::error_code& error);
private:
diff --git a/Swiften/Network/BoostTimerFactory.cpp b/Swiften/Network/BoostTimerFactory.cpp
index 7eec197..b22525c 100644
--- a/Swiften/Network/BoostTimerFactory.cpp
+++ b/Swiften/Network/BoostTimerFactory.cpp
@@ -13,7 +13,7 @@ BoostTimerFactory::BoostTimerFactory(boost::asio::io_service* ioService) : ioSer
}
boost::shared_ptr<Timer> BoostTimerFactory::createTimer(int milliseconds) {
- return boost::shared_ptr<Timer>(new BoostTimer(milliseconds, ioService));
+ return BoostTimer::create(milliseconds, ioService);
}
}
diff --git a/Swiften/Network/Timer.h b/Swiften/Network/Timer.h
index 873837d..278a8fb 100644
--- a/Swiften/Network/Timer.h
+++ b/Swiften/Network/Timer.h
@@ -11,6 +11,8 @@
namespace Swift {
class Timer {
public:
+ typedef boost::shared_ptr<Timer> ref;
+
virtual ~Timer();
virtual void start() = 0;
diff --git a/Swiften/Network/TimerFactory.h b/Swiften/Network/TimerFactory.h
index 558426c..44c87b6 100644
--- a/Swiften/Network/TimerFactory.h
+++ b/Swiften/Network/TimerFactory.h
@@ -8,13 +8,13 @@
#include <boost/shared_ptr.hpp>
-namespace Swift {
- class Timer;
+#include "Swiften/Network/Timer.h"
+namespace Swift {
class TimerFactory {
public:
virtual ~TimerFactory();
- virtual boost::shared_ptr<Timer> createTimer(int milliseconds) = 0;
+ virtual Timer::ref createTimer(int milliseconds) = 0;
};
}