~ubuntu-branches/ubuntu/jaunty/quassel/jaunty

« back to all changes in this revision

Viewing changes to src/core/corenetwork.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2009-02-13 10:36:45 UTC
  • mfrom: (1.1.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20090213103645-skjf7s3h3j9ly3o2
Tags: 0.4.0~git090213-0ubuntu1
* New upstream git snapshot
  - Continued bug fixing

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    _previousConnectionAttemptFailed(false),
41
41
    _lastUsedServerIndex(0),
42
42
 
43
 
    _gotPong(true),
 
43
    _lastPingTime(0),
44
44
 
45
45
    // TODO make autowho configurable (possibly per-network)
46
46
    _autoWhoEnabled(true),
189
189
    _autoReconnectTimer.stop();
190
190
    _autoReconnectCount = 0; // prohibiting auto reconnect
191
191
  }
 
192
  disablePingTimeout();
192
193
 
193
194
  IrcUser *me_ = me();
194
195
  if(me_) {
204
205
  else
205
206
    _quitReason = reason;
206
207
 
207
 
  displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Disconnecting."));
 
208
  displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Disconnecting. (%1)").arg((!requested && !withReconnect) ? tr("Core Shutdown") : reason));
208
209
  switch(socket.state()) {
209
 
  case QAbstractSocket::UnconnectedState:
210
 
    socketDisconnected();
211
 
    break;
212
210
  case QAbstractSocket::ConnectedState:
213
211
    userInputHandler()->issueQuit(_quitReason);
214
 
  default:
215
 
    if(!requested) {
216
 
      socket.close();
217
 
      socketDisconnected();
218
 
    } else {
 
212
    if(requested || withReconnect) {
219
213
      // the irc server has 10 seconds to close the socket
220
214
      _socketCloseTimer.start(10000);
 
215
      break;
221
216
    }
 
217
  default:
 
218
    socket.close();
 
219
    socketDisconnected();
222
220
  }
223
221
}
224
222
 
338
336
}
339
337
 
340
338
void CoreNetwork::socketDisconnected() {
341
 
  _pingTimer.stop();
342
 
  resetPong();
 
339
  disablePingTimeout();
343
340
 
344
341
  _autoWhoCycleTimer.stop();
345
342
  _autoWhoTimer.stop();
420
417
 
421
418
  sendPerform();
422
419
 
423
 
  resetPong();
424
 
  _pingTimer.start();
 
420
  enablePingTimeout();
425
421
 
426
422
  if(_autoWhoEnabled) {
427
423
    _autoWhoCycleTimer.start();
517
513
}
518
514
 
519
515
void CoreNetwork::sendPing() {
520
 
  if(!gotPong()) {
 
516
  uint now = QDateTime::currentDateTime().toTime_t();
 
517
  if(_lastPingTime != 0 && now - _lastPingTime <= (uint)(_pingTimer.interval() / 1000) + 1) {
 
518
    // the second check compares the actual elapsed time since the last ping and the pingTimer interval
 
519
    // if the interval is shorter then the actual elapsed time it means that this thread was somehow blocked
 
520
    // and unable to even handle a ping answer. So we ignore those misses.
521
521
    disconnectFromIrc(false, QString("No Ping reply in %1 seconds.").arg(_pingTimer.interval() / 1000), true /* withReconnect */);
522
522
  } else {
523
 
    _gotPong = false;
 
523
    _lastPingTime = now;
524
524
    userInputHandler()->handlePing(BufferInfo(), QString());
525
525
  }
526
526
}
527
527
 
 
528
void CoreNetwork::enablePingTimeout() {
 
529
  resetPingTimeout();
 
530
  _pingTimer.start();
 
531
}
 
532
 
 
533
void CoreNetwork::disablePingTimeout() {
 
534
  _pingTimer.stop();
 
535
  resetPingTimeout();
 
536
}
 
537
 
528
538
void CoreNetwork::sendAutoWho() {
529
539
  while(!_autoWhoQueue.isEmpty()) {
530
540
    QString chan = _autoWhoQueue.takeFirst();