ia64/xen-unstable

changeset 4670:629cd2d0d581

bitkeeper revision 1.1327.2.10 (426fa4e4eW-9e4FXXSNCILoSYO6KKA)

Add error handling so that disconnecting from a console
producing fast output doesn't cause an error loop.

Signed-off-by: Mike Wray <mike.wray@hp.com>
author mjw@wray-m-3.hpl.hp.com
date Wed Apr 27 14:42:44 2005 +0000 (2005-04-27)
parents 369e382b2f81
children 7719c5e6954d
files tools/python/xen/xend/server/console.py
line diff
     1.1 --- a/tools/python/xen/xend/server/console.py	Wed Apr 27 14:04:44 2005 +0000
     1.2 +++ b/tools/python/xen/xend/server/console.py	Wed Apr 27 14:42:44 2005 +0000
     1.3 @@ -2,7 +2,8 @@
     1.4  
     1.5  import socket
     1.6  import threading
     1.7 -
     1.8 +from errno import EAGAIN, EINTR, EWOULDBLOCK
     1.9 +    
    1.10  from xen.web import reactor, protocol
    1.11  
    1.12  from xen.lowlevel import xu
    1.13 @@ -278,15 +279,20 @@ class ConsoleDev(Dev):
    1.14              self.lock.acquire()
    1.15              if self.closed():
    1.16                  return -1
    1.17 -            if not self.conn:
    1.18 -                return 0
    1.19 -            while not self.obuf.empty():
    1.20 +            writes = 0
    1.21 +            while self.conn and (writes < 100) and (not self.obuf.empty()):
    1.22                  try:
    1.23 +                    writes += 1
    1.24                      bytes = self.conn.write(self.obuf.peek())
    1.25                      if bytes > 0:
    1.26                          self.obuf.discard(bytes)
    1.27 -                except socket.error:
    1.28 -                    pass
    1.29 +                except socket.error, err:
    1.30 +                    if err.args[0] in (EWOULDBLOCK, EAGAIN, EINTR):
    1.31 +                        pass
    1.32 +                    else:
    1.33 +                        self.disconnect()
    1.34 +                        break
    1.35 +                        
    1.36          finally:
    1.37              self.lock.release()
    1.38          return 0