ia64/xen-unstable

changeset 6883:36f8c5900e86

O_REUSEADDR is not enough to ensure we don't get address in use errors when
xend dies from a signal.

We implement a 30 second time to ensure we don't fail if we don't have to.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
author shand@ubuntu.eng.hq.xensource.com
date Wed Sep 14 17:46:40 2005 -0800 (2005-09-14)
parents 7985a4d8bae9
children bd477fcd32ab
files tools/python/xen/web/tcp.py
line diff
     1.1 --- a/tools/python/xen/web/tcp.py	Wed Sep 14 17:45:51 2005 -0800
     1.2 +++ b/tools/python/xen/web/tcp.py	Wed Sep 14 17:46:40 2005 -0800
     1.3 @@ -18,6 +18,7 @@
     1.4  import sys
     1.5  import socket
     1.6  import types
     1.7 +import time
     1.8  
     1.9  from connection import *
    1.10  from protocol import *
    1.11 @@ -35,8 +36,25 @@ class TCPListener(SocketListener):
    1.12      def createSocket(self):
    1.13          sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    1.14          sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    1.15 -        addr = (self.interface, self.port)
    1.16 -        sock.bind(addr)
    1.17 +
    1.18 +        # SO_REUSEADDR does not always ensure that we do not get an address
    1.19 +        # in use error when restarted quickly
    1.20 +        # we implement a timeout to try and avoid failing unnecessarily
    1.21 +
    1.22 +        timeout = time.time() + 30
    1.23 +        again = True
    1.24 +        while again and time.time() < timeout:
    1.25 +            again = False
    1.26 +            try:
    1.27 +                sock.bind((self.interface, self.port))
    1.28 +            except socket.error, (errno, strerrno):
    1.29 +                if errno == 98:
    1.30 +                    again = True
    1.31 +                else:
    1.32 +                    raise socket.error(errno, strerrno)
    1.33 +        if again:
    1.34 +            raise socket.error(98, "address in use")
    1.35 +                
    1.36          return sock
    1.37  
    1.38      def acceptConnection(self, sock, protocol, addr):