Test connection by pinging server if no recent pings from server

This commit is contained in:
Kiooeht 2011-06-23 09:02:20 -07:00
parent c45f7ea070
commit d1920d2cca
3 changed files with 28 additions and 0 deletions

View file

@ -48,6 +48,7 @@ CHANGELOG
* Third beep sound for when your initials are mentioned in memos - Kiooeht [evacipatedBox] (Idea: Lexi [lexicalNuance]) * Third beep sound for when your initials are mentioned in memos - Kiooeht [evacipatedBox] (Idea: Lexi [lexicalNuance])
* Ctrl + click to copy links - Kiooeht [evacipatedBox] * Ctrl + click to copy links - Kiooeht [evacipatedBox]
* Say something when server is full - Kiooeht [evacipatedBox] * Say something when server is full - Kiooeht [evacipatedBox]
* Ping server if no ping from server to test connection - Kiooeht [evacipatedBox] (Idea: Lexi [lexicalNuance])
* Bug fixes * Bug fixes
* Logviewer updates - Kiooeht [evacipatedBox] * Logviewer updates - Kiooeht [evacipatedBox]
* Memo scrollbar thing - Kiooeht [evacipatedBox] * Memo scrollbar thing - Kiooeht [evacipatedBox]

12
irc.py
View file

@ -5,6 +5,7 @@ from oyoyo import helpers
import logging import logging
import random import random
import socket import socket
from time import time
from dataobjs import Mood, PesterProfile from dataobjs import Mood, PesterProfile
from generic import PesterList from generic import PesterList
@ -266,6 +267,13 @@ class PesterIRC(QtCore.QThread):
except socket.error: except socket.error:
self.setConnectionBroken() self.setConnectionBroken()
@QtCore.pyqtSlot()
def pingServer(self):
try:
self.cli.send("PING %s" % int(time()))
except socket.error:
self.setConnectionBroken()
moodUpdated = QtCore.pyqtSignal(QtCore.QString, Mood) moodUpdated = QtCore.pyqtSignal(QtCore.QString, Mood)
colorUpdated = QtCore.pyqtSignal(QtCore.QString, QtGui.QColor) colorUpdated = QtCore.pyqtSignal(QtCore.QString, QtGui.QColor)
messageReceived = QtCore.pyqtSignal(QtCore.QString, QtCore.QString) messageReceived = QtCore.pyqtSignal(QtCore.QString, QtCore.QString)
@ -471,6 +479,10 @@ class PesterHandler(DefaultCommandHandler):
def toomanypeeps(self, *stuff): def toomanypeeps(self, *stuff):
self.parent.tooManyPeeps.emit() self.parent.tooManyPeeps.emit()
def ping(self, prefix, server):
self.parent.mainwindow.lastping = int(time())
self.client.send('PONG', server)
def getMood(self, *chums): def getMood(self, *chums):
chumglub = "GETMOOD " chumglub = "GETMOOD "
for c in chums: for c in chums:

View file

@ -1641,6 +1641,12 @@ class PesterWindow(MovingWindow):
self.connect(self, QtCore.SIGNAL('pcUpdate(QString, QString)'), self.connect(self, QtCore.SIGNAL('pcUpdate(QString, QString)'),
self, QtCore.SLOT('updateMsg(QString, QString)')) self, QtCore.SLOT('updateMsg(QString, QString)'))
self.pingtimer = QtCore.QTimer()
self.connect(self.pingtimer, QtCore.SIGNAL('timeout()'),
self, QtCore.SLOT('checkPing()'))
self.lastping = int(time())
self.pingtimer.start(1000*10)
@QtCore.pyqtSlot(QtCore.QString, QtCore.QString) @QtCore.pyqtSlot(QtCore.QString, QtCore.QString)
def updateMsg(self, ver, url): def updateMsg(self, ver, url):
if not hasattr(self, 'updatemenu'): if not hasattr(self, 'updatemenu'):
@ -1663,6 +1669,12 @@ class PesterWindow(MovingWindow):
def noUpdatePC(self): def noUpdatePC(self):
self.updatemenu = None self.updatemenu = None
@QtCore.pyqtSlot()
def checkPing(self):
curtime = int(time())
if curtime - self.lastping > 300:
self.pingServer.emit()
def profile(self): def profile(self):
return self.userprofile.chat return self.userprofile.chat
def closeConversations(self, switch=False): def closeConversations(self, switch=False):
@ -2880,6 +2892,7 @@ class PesterWindow(MovingWindow):
closeSignal = QtCore.pyqtSignal() closeSignal = QtCore.pyqtSignal()
reconnectIRC = QtCore.pyqtSignal() reconnectIRC = QtCore.pyqtSignal()
gainAttention = QtCore.pyqtSignal(QtGui.QWidget) gainAttention = QtCore.pyqtSignal(QtGui.QWidget)
pingServer = QtCore.pyqtSignal()
class PesterTray(QtGui.QSystemTrayIcon): class PesterTray(QtGui.QSystemTrayIcon):
def __init__(self, icon, mainwindow, parent): def __init__(self, icon, mainwindow, parent):
@ -3038,6 +3051,8 @@ class MainProgram(QtCore.QObject):
'channelNames(QString)'), 'channelNames(QString)'),
('inviteChum(QString, QString)', ('inviteChum(QString, QString)',
'inviteChum(QString, QString)'), 'inviteChum(QString, QString)'),
('pingServer()',
'pingServer()'),
('reconnectIRC()', 'reconnectIRC()') ('reconnectIRC()', 'reconnectIRC()')
] ]
# IRC --> Main window # IRC --> Main window