viff

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 diff
     1.1 --- a/viff/runtime.py	Tue Apr 21 15:52:17 2009 +0200
     1.2 +++ b/viff/runtime.py	Thu Apr 23 11:21:37 2009 +0200
     1.3 @@ -321,7 +321,7 @@
     1.4                  else:
     1.5                      deq.append(data)
     1.6              except struct.error, e:
     1.7 -                print "*** bad data from Player %d: %s" % (self.peer_id, e)
     1.8 +                self.factory.runtime.abort(self, e)
     1.9  
    1.10      def sendData(self, program_counter, data_type, data):
    1.11          """Send data to the peer.
    1.12 @@ -566,6 +566,19 @@
    1.13          sync.addCallback(stop_reactor)
    1.14          return sync
    1.15  
    1.16 +    def abort(self, protocol, exc):
    1.17 +        """Abort the execution due to an exception.
    1.18 +
    1.19 +        The *protocol* received bad data which resulted in *exc* being
    1.20 +        raised when unpacking.
    1.21 +        """
    1.22 +        print "*** bad data from Player %d: %s" % (protocol.peer_id, exc)
    1.23 +        print "*** aborting!"
    1.24 +        for p in self.protocols.itervalues():
    1.25 +            p.loseConnection()
    1.26 +        reactor.stop()
    1.27 +        print "*** all protocols disconnected"
    1.28 +
    1.29      def wait_for(self, *vars):
    1.30          """Make the runtime wait for the variables given.
    1.31