summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton <anton@picapica>2015-04-13 18:48:55 +0400
committerAnton <anton@picapica>2015-04-13 18:48:55 +0400
commitd457810baf8647e59cdb8485b9f22d3d7f324cd3 (patch)
tree7d9cc977816b42cc327957afc9cf88bd1548242e
parentf4077f1b6e6ad81ea9c4b8b205e48f73c218ccf8 (diff)
downloadpica-pica-d457810baf8647e59cdb8485b9f22d3d7f324cd3.tar.gz
pica-pica-d457810baf8647e59cdb8485b9f22d3d7f324cd3.zip
Fixed reconnect and explicit disconnect behavior
-rw-r--r--pica-client/skynet.cpp12
-rw-r--r--pica-client/skynet.h1
2 files changed, 7 insertions, 6 deletions
diff --git a/pica-client/skynet.cpp b/pica-client/skynet.cpp
index 54b1a85..63da308 100644
--- a/pica-client/skynet.cpp
+++ b/pica-client/skynet.cpp
@@ -13,6 +13,7 @@ SkyNet::SkyNet()
: nodes(config_dbname), QObject(0)
{
self_aware = false;
+ reconnect_enabled = false;
PICA_client_callbacks cbs = {
newmsg_cb,
@@ -38,6 +39,7 @@ nodelink = NULL;
connect(this, SIGNAL(PeerCertificateReceived(QByteArray,QString,bool*)), this, SLOT(verify_peer_cert(QByteArray,QString,bool*)),Qt::DirectConnection);
+timer_id = startTimer(10000);
}
void SkyNet::nodethread_finished()
@@ -97,8 +99,6 @@ void SkyNet::nodethread_connected(QString addr, quint16 port, NodeThread *thread
write_mutex.unlock();
}
- //start timer
- timer_id = startTimer(10000);
}
}
@@ -191,9 +191,8 @@ void SkyNet::timerEvent(QTimerEvent *e)
write_mutex.unlock();
}
}
-else
+else if (threads.count() == 0 && reconnect_enabled)
{
- killTimer(e->timerId());
Accounts::AccountRecord acc = this->CurrentAccount();
Join(acc);
}
@@ -204,6 +203,7 @@ void SkyNet::Join(Accounts::AccountRecord &accrec)
QList<Nodes::NodeRecord> nodelist;
skynet_account = accrec;
nodelist = nodes.GetNodes();
+ reconnect_enabled = true;
if (nodelist.count()==0)
{
@@ -228,8 +228,8 @@ void SkyNet::Exit()
threads[i]->CloseThread();
self_aware = false;
-
- killTimer(timer_id);
+ reconnect_enabled = false;
+ emit LostSelfAwareness();
}
bool SkyNet::isSelfAware()
diff --git a/pica-client/skynet.h b/pica-client/skynet.h
index 5aeb332..ebc78ff 100644
--- a/pica-client/skynet.h
+++ b/pica-client/skynet.h
@@ -68,6 +68,7 @@ private:
QMap<QByteArray, QList<QString> > msgqueues;
QMap<QByteArray, QList<QString> > sndfilequeues;
int timer_id;
+ bool reconnect_enabled;
void timerEvent(QTimerEvent * e);