changeset 1171:0e3d8a3d3b15

Add abort method in Runtime to deal with bad data.
author Martin Geisler <mg@cs.au.dk>
date Thu, 23 Apr 2009 11:21:37 +0200
parents 98eb6e0cfa88
children 38e4007378df
files viff/runtime.py
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/viff/runtime.py	Tue Apr 21 15:52:17 2009 +0200
+++ b/viff/runtime.py	Thu Apr 23 11:21:37 2009 +0200
@@ -321,7 +321,7 @@
                 else:
                     deq.append(data)
             except struct.error, e:
-                print "*** bad data from Player %d: %s" % (self.peer_id, e)
+                self.factory.runtime.abort(self, e)
 
     def sendData(self, program_counter, data_type, data):
         """Send data to the peer.
@@ -566,6 +566,19 @@
         sync.addCallback(stop_reactor)
         return sync
 
+    def abort(self, protocol, exc):
+        """Abort the execution due to an exception.
+
+        The *protocol* received bad data which resulted in *exc* being
+        raised when unpacking.
+        """
+        print "*** bad data from Player %d: %s" % (protocol.peer_id, exc)
+        print "*** aborting!"
+        for p in self.protocols.itervalues():
+            p.loseConnection()
+        reactor.stop()
+        print "*** all protocols disconnected"
+
     def wait_for(self, *vars):
         """Make the runtime wait for the variables given.