_previousConnectionAttemptFailed(false),
_lastUsedServerIndex(0),
+ _gotPong(true),
+
// TODO make autowho configurable (possibly per-network)
_autoWhoEnabled(true),
_autoWhoInterval(90),
_socketCloseTimer.setSingleShot(true);
connect(&_socketCloseTimer, SIGNAL(timeout()), this, SLOT(socketCloseTimeout()));
- _pingTimer.setInterval(60000);
+ _pingTimer.setInterval(30000);
connect(&_pingTimer, SIGNAL(timeout()), this, SLOT(sendPing()));
_autoWhoTimer.setInterval(_autoWhoDelay * 1000);
#endif
}
-void CoreNetwork::disconnectFromIrc(bool requested, const QString &reason) {
+void CoreNetwork::disconnectFromIrc(bool requested, const QString &reason, bool withReconnect) {
_quitRequested = requested; // see socketDisconnected();
- _autoReconnectTimer.stop();
- _autoReconnectCount = 0; // prohibiting auto reconnect
+ if(!withReconnect) {
+ _autoReconnectTimer.stop();
+ _autoReconnectCount = 0; // prohibiting auto reconnect
+ }
IrcUser *me_ = me();
if(me_) {
Core::setUserModes(userId(), networkId(), me_->userModes());
}
+ if(reason.isEmpty() && identityPtr())
+ _quitReason = identityPtr()->quitReason();
+ else
+ _quitReason = reason;
+
displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Disconnecting."));
- if(socket.state() == QAbstractSocket::UnconnectedState) {
- socketDisconnected();
- } else if(socket.state() < QAbstractSocket::ConnectedState || !requested) {
- // we might be in a state waiting for a timeout...
- // or (!requested) this is a core shutdown...
- // in both cases we don't really care... set a disconnected state
- socket.close();
+ switch(socket.state()) {
+ case QAbstractSocket::UnconnectedState:
socketDisconnected();
- } else {
- // quit gracefully if it's user requested quit
- if(reason.isEmpty() && identityPtr())
- _quitReason = identityPtr()->quitReason();
- else
- _quitReason = reason;
+ break;
+ case QAbstractSocket::ConnectedState:
userInputHandler()->issueQuit(_quitReason);
- // the irc server has 10 seconds to close the socket
- _socketCloseTimer.start(10000);
+ default:
+ if(!requested) {
+ socket.close();
+ socketDisconnected();
+ } else {
+ // the irc server has 10 seconds to close the socket
+ _socketCloseTimer.start(10000);
+ }
}
}
void CoreNetwork::socketDisconnected() {
_pingTimer.stop();
+ resetPong();
+
_autoWhoCycleTimer.stop();
_autoWhoTimer.stop();
_autoWhoQueue.clear();
sendPerform();
+ resetPong();
_pingTimer.start();
if(_autoWhoEnabled) {
}
void CoreNetwork::sendPing() {
- userInputHandler()->handlePing(BufferInfo(), QString());
+ if(!gotPong()) {
+ disconnectFromIrc(false, QString("No Ping reply in %1 seconds.").arg(_pingTimer.interval() / 1000), true /* withReconnect */);
+ } else {
+ _gotPong = false;
+ userInputHandler()->handlePing(BufferInfo(), QString());
+ }
}
void CoreNetwork::sendAutoWho() {
virtual void setAutoReconnectRetries(quint16);
void connectToIrc(bool reconnecting = false);
- void disconnectFromIrc(bool requested = true, const QString &reason = QString());
+ void disconnectFromIrc(bool requested = true, const QString &reason = QString(), bool withReconnect = false);
void userInput(BufferInfo bufferInfo, QString msg);
void putRawLine(QByteArray input);
Server usedServer() const;
+ inline void resetPong() { _gotPong = true; }
+ inline bool gotPong() { return _gotPong; }
+
signals:
void recvRawServerMsg(QString);
void displayStatusMsg(QString);
int _lastUsedServerIndex;
QTimer _pingTimer;
+ bool _gotPong;
bool _autoWhoEnabled;
QStringList _autoWhoQueue;