der[
This commit is contained in:
parent
3cbfc193b4
commit
90e3a4155b
5 changed files with 65 additions and 23 deletions
22
irc.py
22
irc.py
|
@ -19,28 +19,37 @@ class PesterIRC(QtCore.QThread):
|
|||
def IRCConnect(self):
|
||||
server = self.config.server()
|
||||
port = self.config.port()
|
||||
self.cli = IRCClient(PesterHandler, host=server, port=int(port), nick=self.mainwindow.profile().handle, real_name='pcc30', blocking=True)
|
||||
self.cli = IRCClient(PesterHandler, host=server, port=int(port), nick=self.mainwindow.profile().handle, real_name='pcc30', blocking=True, timeout=5)
|
||||
self.cli.command_handler.parent = self
|
||||
self.cli.command_handler.mainwindow = self.mainwindow
|
||||
self.conn = self.cli.connect()
|
||||
self.brokenConnection = False
|
||||
self.stopIRC = None
|
||||
self.registeredIRC = False
|
||||
def run(self):
|
||||
self.IRCConnect()
|
||||
while 1:
|
||||
try:
|
||||
self.updateIRC()
|
||||
res = self.updateIRC()
|
||||
except socket.timeout, se:
|
||||
print "timeout in thread %s" % (self)
|
||||
self.cli.close()
|
||||
self.stopIRC = se
|
||||
return
|
||||
except socket.error, se:
|
||||
if self.registeredIRC:
|
||||
self.stopIRC = None
|
||||
else:
|
||||
self.stopIRC = se
|
||||
return
|
||||
else:
|
||||
if not res:
|
||||
return
|
||||
|
||||
def setConnected(self):
|
||||
self.registeredIRC = True
|
||||
self.connected.emit()
|
||||
def setConnectionBroken(self):
|
||||
print "setconnection broken"
|
||||
self.reconnectIRC()
|
||||
#self.brokenConnection = True
|
||||
@QtCore.pyqtSlot()
|
||||
|
@ -49,15 +58,18 @@ class PesterIRC(QtCore.QThread):
|
|||
res = self.conn.next()
|
||||
except socket.timeout, se:
|
||||
if self.registeredIRC:
|
||||
return
|
||||
return True
|
||||
else:
|
||||
raise se
|
||||
except socket.error, se:
|
||||
raise se
|
||||
except StopIteration:
|
||||
pass
|
||||
return True
|
||||
else:
|
||||
return res
|
||||
@QtCore.pyqtSlot()
|
||||
def reconnectIRC(self):
|
||||
print "reconnectIRC() from thread %s" % (self)
|
||||
self.cli.close()
|
||||
|
||||
@QtCore.pyqtSlot(PesterProfile)
|
||||
|
|
BIN
irc.pyc
BIN
irc.pyc
Binary file not shown.
|
@ -82,7 +82,6 @@ class IRCClient:
|
|||
...
|
||||
"""
|
||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
print "initalizing socket %d" % (self.socket.fileno())
|
||||
self.nick = None
|
||||
self.real_name = None
|
||||
self.host = None
|
||||
|
@ -155,9 +154,8 @@ class IRCClient:
|
|||
self.socket.connect(("%s" % self.host, self.port))
|
||||
if not self.blocking:
|
||||
self.socket.setblocking(0)
|
||||
#if self.timeout:
|
||||
# self.socket.settimeout(self.timeout)
|
||||
self.socket.settimeout(10)
|
||||
if self.timeout:
|
||||
self.socket.settimeout(self.timeout)
|
||||
helpers.nick(self, self.nick)
|
||||
helpers.user(self, self.nick, self.real_name)
|
||||
|
||||
|
@ -169,8 +167,14 @@ class IRCClient:
|
|||
try:
|
||||
buffer += self.socket.recv(1024)
|
||||
except socket.timeout, e:
|
||||
if self._end:
|
||||
break
|
||||
print "timeout in client.py"
|
||||
raise e
|
||||
except socket.error, e:
|
||||
if self._end:
|
||||
break
|
||||
print "error %s" % e
|
||||
try: # a little dance of compatibility to get the errno
|
||||
errno = e.errno
|
||||
except AttributeError:
|
||||
|
@ -180,6 +184,8 @@ class IRCClient:
|
|||
else:
|
||||
raise e
|
||||
else:
|
||||
if self._end:
|
||||
break
|
||||
if len(buffer) == 0 and self.blocking:
|
||||
raise socket.error("Connection closed")
|
||||
|
||||
|
@ -198,18 +204,21 @@ class IRCClient:
|
|||
except socket.timeout, se:
|
||||
raise se
|
||||
except socket.error, se:
|
||||
if self.socket:
|
||||
logging.info('closing socket')
|
||||
print "problem: %s" % (se)
|
||||
if self.socket:
|
||||
logging.info('error: closing socket')
|
||||
self.socket.close()
|
||||
raise se
|
||||
else:
|
||||
if self.socket:
|
||||
logging.info('closing socket')
|
||||
logging.info('finished: closing socket')
|
||||
self.socket.close()
|
||||
yield False
|
||||
def close(self):
|
||||
# with extreme prejudice
|
||||
if self.socket:
|
||||
logging.info('shutdown socket')
|
||||
self._end = True
|
||||
self.socket.shutdown(socket.SHUT_RDWR)
|
||||
|
||||
class IRCApp:
|
||||
|
|
BIN
oyoyo/client.pyc
BIN
oyoyo/client.pyc
Binary file not shown.
|
@ -1725,9 +1725,9 @@ class MainProgram(QtCore.QObject):
|
|||
self.trayicon,
|
||||
QtCore.SLOT('mainWindowClosed()'))
|
||||
|
||||
self.attempts = 0
|
||||
|
||||
self.irc = PesterIRC(self.widget.config, self.widget)
|
||||
self.connect(self.irc, QtCore.SIGNAL('finished()'),
|
||||
self, QtCore.SLOT('restartIRC()'))
|
||||
self.connectWidgets(self.irc, self.widget)
|
||||
|
||||
widget2irc = [('sendMessage(QString, QString)',
|
||||
|
@ -1778,6 +1778,10 @@ class MainProgram(QtCore.QObject):
|
|||
'timeCommand(QString, QString, QString)')
|
||||
]
|
||||
def connectWidgets(self, irc, widget):
|
||||
self.connect(irc, QtCore.SIGNAL('finished()'),
|
||||
self, QtCore.SLOT('restartIRC()'))
|
||||
self.connect(irc, QtCore.SIGNAL('connected()'),
|
||||
self, QtCore.SLOT('connected()'))
|
||||
for c in self.widget2irc:
|
||||
self.connect(widget, QtCore.SIGNAL(c[0]),
|
||||
irc, QtCore.SLOT(c[1]))
|
||||
|
@ -1791,6 +1795,10 @@ class MainProgram(QtCore.QObject):
|
|||
for c in self.irc2widget:
|
||||
self.disconnect(irc, QtCore.SIGNAL(c[0]),
|
||||
widget, QtCore.SLOT(c[1]))
|
||||
self.disconnect(irc, QtCore.SIGNAL('connected()'),
|
||||
self, QtCore.SLOT('connected()'))
|
||||
self.disconnect(self.irc, QtCore.SIGNAL('finished()'),
|
||||
self, QtCore.SLOT('restartIRC()'))
|
||||
|
||||
def showLoading(self, widget, msg="CONN3CT1NG"):
|
||||
self.widget.show()
|
||||
|
@ -1806,27 +1814,40 @@ class MainProgram(QtCore.QObject):
|
|||
sys.exit(0)
|
||||
|
||||
@QtCore.pyqtSlot()
|
||||
def connected(self):
|
||||
self.attempts = 0
|
||||
@QtCore.pyqtSlot()
|
||||
def tryAgain(self):
|
||||
if self.loadingscreen:
|
||||
self.loadingscreen.accept()
|
||||
self.restartIRC()
|
||||
if self.widget.loadingscreen:
|
||||
self.widget.loadingscreen.accept()
|
||||
self.attempts += 1
|
||||
if hasattr(self, 'irc') and self.irc:
|
||||
print "tryagain: reconnectIRC()"
|
||||
self.irc.reconnectIRC()
|
||||
print "finishing"
|
||||
self.irc.quit()
|
||||
else:
|
||||
print "tryagain: restartIRC"
|
||||
self.restartIRC()
|
||||
@QtCore.pyqtSlot()
|
||||
def restartIRC(self):
|
||||
if self.irc:
|
||||
if hasattr(self, 'irc') and self.irc:
|
||||
self.disconnectWidgets(self.irc, self.widget)
|
||||
self.disconnect(self.irc, QtCore.SIGNAL('finished()'),
|
||||
self, QtCore.SLOT('restartIRC()'))
|
||||
stop = self.irc.stopIRC
|
||||
del self.irc
|
||||
else:
|
||||
stop = None
|
||||
if not stop:
|
||||
self.irc = PesterIRC(self.widget.config, self.widget)
|
||||
self.connect(self.irc, QtCore.SIGNAL('finished()'),
|
||||
self, QtCore.SLOT('restartIRC()'))
|
||||
self.connectWidgets(self.irc, self.widget)
|
||||
self.irc.start()
|
||||
self.showLoading(self.widget)
|
||||
if self.attempts == 1:
|
||||
msg = "R3CONN3CT1NG"
|
||||
elif self.attempts > 1:
|
||||
msg = "R3CONN3CT1NG %d" % (self.attempts)
|
||||
else:
|
||||
msg = "CONN3CT1NG"
|
||||
self.showLoading(self.widget, msg)
|
||||
else:
|
||||
self.showLoading(self.widget, "F41L3D: %s" % stop)
|
||||
|
||||
|
|
Loading…
Reference in a new issue