109 |
109 |
110 _strpath = _bytespath |
110 _strpath = _bytespath |
111 |
111 |
112 # For Windows support |
112 # For Windows support |
113 wifexited = getattr(os, "WIFEXITED", lambda x: False) |
113 wifexited = getattr(os, "WIFEXITED", lambda x: False) |
|
114 |
|
115 # Whether to use IPv6 |
|
116 def checkipv6available(port=20058): |
|
117 """return true if we can listen on localhost's IPv6 ports""" |
|
118 family = getattr(socket, 'AF_INET6', None) |
|
119 if family is None: |
|
120 return False |
|
121 try: |
|
122 s = socket.socket(family, socket.SOCK_STREAM) |
|
123 s.bind(('localhost', port)) |
|
124 s.close() |
|
125 return True |
|
126 except socket.error as exc: |
|
127 if exc.errno == errno.EADDRINUSE: |
|
128 return True |
|
129 elif exc.errno in (errno.EADDRNOTAVAIL, errno.EPROTONOSUPPORT): |
|
130 return False |
|
131 else: |
|
132 raise |
|
133 else: |
|
134 return False |
|
135 |
|
136 useipv6 = checkipv6available() |
114 |
137 |
115 def checkportisavailable(port): |
138 def checkportisavailable(port): |
116 """return true if a port seems free to bind on localhost""" |
139 """return true if a port seems free to bind on localhost""" |
117 families = [getattr(socket, i, None) |
140 families = [getattr(socket, i, None) |
118 for i in ('AF_INET', 'AF_INET6') |
141 for i in ('AF_INET', 'AF_INET6') |