ia64/xen-unstable

changeset 6889:7ce64f021a2c

Cleanup timeout code for when socket is already in use.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Thu Sep 15 08:59:35 2005 +0000 (2005-09-15)
parents 6da7a6d8b575
children 19b458d4ba93 6e5cb98eff28
files tools/python/xen/web/tcp.py
line diff
     1.1 --- a/tools/python/xen/web/tcp.py	Thu Sep 15 08:56:13 2005 +0000
     1.2 +++ b/tools/python/xen/web/tcp.py	Thu Sep 15 08:59:35 2005 +0000
     1.3 @@ -19,6 +19,7 @@ import sys
     1.4  import socket
     1.5  import types
     1.6  import time
     1.7 +import errno
     1.8  
     1.9  from connection import *
    1.10  from protocol import *
    1.11 @@ -40,22 +41,16 @@ class TCPListener(SocketListener):
    1.12          # SO_REUSEADDR does not always ensure that we do not get an address
    1.13          # in use error when restarted quickly
    1.14          # we implement a timeout to try and avoid failing unnecessarily
    1.15 -
    1.16          timeout = time.time() + 30
    1.17 -        again = True
    1.18 -        while again and time.time() < timeout:
    1.19 -            again = False
    1.20 +        while True:
    1.21              try:
    1.22                  sock.bind((self.interface, self.port))
    1.23 -            except socket.error, (errno, strerrno):
    1.24 -                if errno == 98:
    1.25 -                    again = True
    1.26 +                return sock
    1.27 +            except socket.error, (_errno, strerrno):
    1.28 +                if _errno == errno.EADDRINUSE and time.time() < timeout:
    1.29 +                    time.sleep(0.5)
    1.30                  else:
    1.31 -                    raise socket.error(errno, strerrno)
    1.32 -        if again:
    1.33 -            raise socket.error(98, "address in use")
    1.34 -                
    1.35 -        return sock
    1.36 +                    raise
    1.37  
    1.38      def acceptConnection(self, sock, protocol, addr):
    1.39          return TCPServerConnection(sock, protocol, addr, self)