From: <Blu...@us...> - 2009-11-28 23:31:01
|
Revision: 311 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=311&view=rev Author: BlueWolf_ Date: 2009-11-28 23:30:52 +0000 (Sat, 28 Nov 2009) Log Message: ----------- Added reason 'full' to callback.connection_closed Modified Paths: -------------- trunk/client/core/callback.py trunk/client/core/client.py trunk/client/core/parser.py Modified: trunk/client/core/callback.py =================================================================== --- trunk/client/core/callback.py 2009-11-28 23:26:54 UTC (rev 310) +++ trunk/client/core/callback.py 2009-11-28 23:30:52 UTC (rev 311) @@ -35,8 +35,11 @@ reason: A string, representing the reason why it disconnected. - It currently only has two options: - * "server" - Server dropped the connection + It currently has these options: + * "closed" - Server dropped the connection + unexpectedly + * "full" - Server is full and does not except + - more connections * "manual" - Client (you) closed the connection with .close() Modified: trunk/client/core/client.py =================================================================== --- trunk/client/core/client.py 2009-11-28 23:26:54 UTC (rev 310) +++ trunk/client/core/client.py 2009-11-28 23:30:52 UTC (rev 311) @@ -57,7 +57,6 @@ self.__parse = Parser(self.__call, self) self.__is_online = False - self.__disconnect_reason = None self.__do_connect = threading.Event() self.__do_connect.clear() @@ -97,7 +96,7 @@ self.__do_connect.wait() # Wait to connect self.__is_online = True - self.__disconnect_reason = None + disconnect_reason = None self.__sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -121,11 +120,10 @@ try: data = self.__sock.recv(1024) except: - print 'except' - self.__disconnect_reason = "close" + disconnect_reason = "closed" break if not data: - self.__disconnect_reason = "close" + disconnect_reason = "closed" break buffer += data @@ -141,7 +139,7 @@ self.__parse(simplejson.loads(msg)) if self.__is_online: - self.close() + self.close(disconnect_reason) @@ -160,7 +158,7 @@ except: pass - def close(self): + def close(self, reason = "manual"): """ Will close the connection to the server. If the connection in already down, it will raise an exception. This will trigger the @@ -169,23 +167,22 @@ """ if not self.__is_online: - raise ConnectionError("The connection is already " \ - "closed!") + if reason == "manual": + # Annoy the user + raise ConnectionError("The connection is " + \ + "already closed!") + else: + return; - # What's the reason, the meaning of this? - if self.__disconnect_reason == "close": # 42 - reason = "server" - else: - reason = "manual" - self.__do_connect.clear() # Block the thread-loop self.__is_online = False self.__pinger.cancel() self.__pinger = None - self.__sock.shutdown(0) + try: self.__sock.shutdown(0) + except: pass self.__sock.close() self.__sock = None Modified: trunk/client/core/parser.py =================================================================== --- trunk/client/core/parser.py 2009-11-28 23:26:54 UTC (rev 310) +++ trunk/client/core/parser.py 2009-11-28 23:30:52 UTC (rev 311) @@ -30,4 +30,15 @@ head = msg.keys()[0] body = msg[head] - #handle data here later... + func = getattr(self, str(head), None) + if (func): + func(body) + + def disconnect(self, msg): + """ + Called just before the server closes our connection + """ + # reason - Why it's going to disconnect us + + if msg['reason'] == 'full': + self.__client.close("full") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |