Stop loop instead of exit()
This commit is contained in:
parent
6aa34a5585
commit
1bf1343ac5
4 changed files with 18 additions and 7 deletions
|
@ -155,8 +155,14 @@ static std::string getAlias(PurpleBuddy *m_buddy) {
|
|||
|
||||
class SpectrumNetworkPlugin : public NetworkPlugin {
|
||||
public:
|
||||
SpectrumEventLoop *m_loop;
|
||||
SpectrumNetworkPlugin(Config *config, SpectrumEventLoop *loop, const std::string &host, int port) : NetworkPlugin(loop, host, port) {
|
||||
this->config = config;
|
||||
m_loop = loop;
|
||||
}
|
||||
|
||||
void handleExit() {
|
||||
m_loop->stop();
|
||||
}
|
||||
|
||||
void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) {
|
||||
|
|
|
@ -68,6 +68,7 @@ void SpectrumEventLoop::run() {
|
|||
}
|
||||
|
||||
void SpectrumEventLoop::stop() {
|
||||
std::cout << "stopped loop\n";
|
||||
if (!m_isRunning)
|
||||
return;
|
||||
if (m_loop) {
|
||||
|
|
|
@ -83,6 +83,8 @@ class NetworkPlugin {
|
|||
virtual void handleTypedRequest(const std::string &/*user*/, const std::string &/*buddyName*/) {}
|
||||
virtual void handleStoppedTypingRequest(const std::string &/*user*/, const std::string &/*buddyName*/) {}
|
||||
virtual void handleAttentionRequest(const std::string &/*user*/, const std::string &/*buddyName*/, const std::string &/*message*/) {}
|
||||
|
||||
virtual void handleExit() { std::cout << "EXITING\n"; exit(1); }
|
||||
|
||||
|
||||
private:
|
||||
|
@ -113,6 +115,7 @@ class NetworkPlugin {
|
|||
Swift::BoostNetworkFactories *m_factories;
|
||||
Swift::BoostIOServiceThread m_boostIOServiceThread;
|
||||
boost::shared_ptr<Swift::Connection> m_conn;
|
||||
Swift::EventLoop *m_loop;
|
||||
Swift::Timer::ref m_pingTimer;
|
||||
bool m_pingReceived;
|
||||
double m_init_res;
|
||||
|
|
|
@ -49,6 +49,7 @@ NetworkPlugin::NetworkPlugin(Swift::EventLoop *loop, const std::string &host, in
|
|||
m_host = host;
|
||||
m_port = port;
|
||||
m_pingReceived = false;
|
||||
m_loop = loop;
|
||||
m_conn = m_factories->getConnectionFactory()->createConnection();
|
||||
m_conn->onDataRead.connect(boost::bind(&NetworkPlugin::handleDataRead, this, _1));
|
||||
m_conn->onConnectFinished.connect(boost::bind(&NetworkPlugin::_handleConnected, this, _1));
|
||||
|
@ -262,20 +263,20 @@ void NetworkPlugin::handleRoomChanged(const std::string &user, const std::string
|
|||
|
||||
void NetworkPlugin::_handleConnected(bool error) {
|
||||
if (error) {
|
||||
LOG4CXX_ERROR(logger, "Connecting error. Exiting");
|
||||
// LOG4CXX_ERROR(logger, "Connecting error. Exiting");
|
||||
m_pingTimer->stop();
|
||||
exit(1);
|
||||
handleExit();
|
||||
}
|
||||
else {
|
||||
LOG4CXX_INFO(logger, "Connected to NetworkPluginServer");
|
||||
// LOG4CXX_INFO(logger, "Connected to NetworkPluginServer");
|
||||
m_pingTimer->start();
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkPlugin::handleDisconnected() {
|
||||
LOG4CXX_INFO(logger, "Disconnected from NetworkPluginServer. Exiting.");
|
||||
// LOG4CXX_INFO(logger, "Disconnected from NetworkPluginServer. Exiting.");
|
||||
m_pingTimer->stop();
|
||||
exit(1);
|
||||
handleExit();
|
||||
}
|
||||
|
||||
void NetworkPlugin::connect() {
|
||||
|
@ -518,8 +519,8 @@ void NetworkPlugin::sendMemoryUsage() {
|
|||
|
||||
void NetworkPlugin::pingTimeout() {
|
||||
if (m_pingReceived == false) {
|
||||
LOG4CXX_ERROR(logger, "No PING received for long time (NetworkPluginServer crashed?). Exiting");
|
||||
exit(1);
|
||||
// LOG4CXX_ERROR(logger, "No PING received for long time. Exiting");
|
||||
handleExit();
|
||||
}
|
||||
m_pingReceived = false;
|
||||
m_pingTimer->start();
|
||||
|
|
Loading…
Add table
Reference in a new issue