From 90e3a4155b60bb85a3cb44fb732a3e361f5a83e4 Mon Sep 17 00:00:00 2001 From: Stephen Dranger Date: Sat, 19 Feb 2011 20:38:06 -0600 Subject: [PATCH] der[ --- irc.py | 22 +++++++++++++++++----- irc.pyc | Bin 14658 -> 14880 bytes oyoyo/client.py | 23 ++++++++++++++++------- oyoyo/client.pyc | Bin 10504 -> 10670 bytes pesterchum.py | 43 ++++++++++++++++++++++++++++++++----------- 5 files changed, 65 insertions(+), 23 deletions(-) diff --git a/irc.py b/irc.py index 2ab9dfe..979e401 100644 --- a/irc.py +++ b/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) diff --git a/irc.pyc b/irc.pyc index 6316cb7d77e19b60338b929a5b0cac538f4a7de9..c529c5e2574dc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Tl~n0#4lFGPBMltIB>CK(Q0!Yy;Ju} z7a|O_Box$i5dRjFG*jQDTZF=e<`Dg`KB}|yv-Klw!c}@ zEN`Ac&4iA!&pds!G-fw6hD028kM6)Fj-X@A~n}HM@C26d&N?)YIjh~qvnrW)i zFEJ~vwAOU#vvN!e%{BT8Te;k|nI+-DNiB1WY%evcYf0;CbiU=~>Q9MoMGw)@)<%7u zGOZVrMQdRD1=n^yW$bQl=D^Jf;pSLdmHr0Jw_V<5WrfS?|F?3ay-MGtlkKlf-W|(X zJAL+^RxrV~)L;-0&Vr0BbVT(n%65D(BlZ%I;B6cAldA6G7{`m zwsYEi0S5?i(RH)t2rtZIfMWpEu$cus33y7WHf5f{@>#%hfCWGbaGJhz{|9qi)#MjJgUzgHc&?*R4yHm6L`!^d&< zH~@jlG~(IL{A6v*@r{SW9D@|4x01De!#ibMzzSfMAt6@d^yi-1N@+&SCUcxV?pfEr zzx}1&8eNbugjaEN3JPBa{MUeBC>Vuj^2q0A&z|6I9{lNmL?EG^W0^2ioaKS-B?tlsl<0d>hv`yZVQdYjiwu(B z)x7OX>fNQKtnFBVjZ4rG6@y++^7Zy)v8`I0-F@A&-^BP^^!lb#ecWxHvvismE_WJ2I$` zh+|Mt91%h1_Ta2{)3*E(Dw+kso9%l#n_uKv`={je#-Fd9qXSQz!Bzerugt4}uK>OZ zKx3Ha0rLQv6;dQpc;CX=w*lV+;F;$8fD!uo=;uO>y!;*gWwcN!349Hb9qeGO L(BH@U^)LPnkLNOq diff --git a/oyoyo/client.py b/oyoyo/client.py index f9db258..ca49978 100644 --- a/oyoyo/client.py +++ b/oyoyo/client.py @@ -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: diff --git a/oyoyo/client.pyc b/oyoyo/client.pyc index 6a2701c5b06480a9138cea97b5d1de2ed11a3f62..31c4e50a7b7e397e38ad5523634415ac9aa0b574 100644 GIT binary patch delta 1895 zcmZ`)PfT285TAMMTiE{#EbOwd^zpB3+EQqZDXl$JtAQAy_(4kzM7r#IlviLMy!X*` zBLpLf(Zp!tcdLnK6OC!J@#NX7iC&DJj9L$J(!|7r2WP&=Mr`8Yo1Hf^-^_3Re6#O} z&*!7x{E>?Pu>Ux^5W%8RallUK>MN4?O;dv!X+|WtUZDVX8#laf_#C;0Qv9jQqfOG8CHeqU- ziux8p?J}ai(4jAE|IdXe_n>=fx~`kycEWy(O6D$%w!%FFya?dVs)5HIzXZJfR6unz zH(b=k;gDe~-ENT7yBOGUrE>EJokm3VY7ngi0&%C)z}rL?Wgpzaoo@jb7i*g*v&%5p z7-bjJne4;KOs*X(ZR$ddp);fic>UA};t=elu5u`LOKQ0*+dX~^{Xcdob)&00A^Qo1 zou*04G(PUSif4c(CCKr}xLc05D=oKXR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