From a34b9e649c6041bc69d522dfc3d7005b3c60e1b0 Mon Sep 17 00:00:00 2001 From: daniel-Jones Date: Fri, 16 Jun 2017 16:04:25 +0930 Subject: added irc reconnect when it has detected a closed connection --- qt/RGBController/irc.cpp | 19 +++++++++++++++++-- qt/RGBController/irc.h | 5 +++++ 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'qt') diff --git a/qt/RGBController/irc.cpp b/qt/RGBController/irc.cpp index 9c3c14d..4365e19 100644 --- a/qt/RGBController/irc.cpp +++ b/qt/RGBController/irc.cpp @@ -2,7 +2,7 @@ irc::irc(QObject *parent) : QObject(parent) { - + } void irc::setup(QString srv, int p, QString c, QString n) @@ -15,6 +15,8 @@ void irc::setup(QString srv, int p, QString c, QString n) /* setup socket, connect signal/slot */ socket = new QTcpSocket(this); connect(socket, SIGNAL(readyRead()), this, SLOT(read())); + contest = new QTimer(this); + connect(contest, SIGNAL(timeout()), this, SLOT(testcon())); /* connect */ con(); } @@ -37,7 +39,6 @@ void irc::read() handle(line); if(socket->canReadLine()) read(); - } void irc::con() @@ -47,12 +48,14 @@ void irc::con() socket->write(buf.toUtf8()); buf = "USER " + name + " 8 * :" + name + "\r\n"; socket->write(buf.toUtf8()); + contest->start(60000); } void irc::discon() { socket->write("QUIT :elegant quit \r\n"); socket->close(); + contest->stop(); } void irc::handle(QString str) @@ -94,3 +97,15 @@ void irc::sendmsg(QString msg) buf = "PRIVMSG " + channel + " :" + msg + " \r\n"; socket->write(buf.toUtf8()); } + +void irc::testcon() +{ + qDebug() << socket->state(); + if (socket->state() == QAbstractSocket::UnconnectedState) + { + qDebug() << "reconnect needed"; + discon(); + name = name + "_"; + con(); + } +} diff --git a/qt/RGBController/irc.h b/qt/RGBController/irc.h index b9bdefc..d6c88e6 100644 --- a/qt/RGBController/irc.h +++ b/qt/RGBController/irc.h @@ -3,6 +3,7 @@ #include #include +#include class irc : public QObject { @@ -19,10 +20,14 @@ class irc : public QObject QString channel; QString name; QString buf; + int pingcount; + QTimer *contest; + private slots: void read(); void con(); void handle(QString str); + void testcon(); signals: void sendcmd(QString cmd); -- cgit v1.2.3