| OLD | NEW |
| 1 # Copyright (C) 2011 Google Inc. All rights reserved. | 1 # Copyright (C) 2011 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 _log.debug("Server isn't running at all") | 248 _log.debug("Server isn't running at all") |
| 249 self._log_errors_from_subprocess() | 249 self._log_errors_from_subprocess() |
| 250 raise ServerError("Server exited") | 250 raise ServerError("Server exited") |
| 251 | 251 |
| 252 for mapping in self._mappings: | 252 for mapping in self._mappings: |
| 253 s = socket.socket() | 253 s = socket.socket() |
| 254 port = mapping['port'] | 254 port = mapping['port'] |
| 255 try: | 255 try: |
| 256 s.connect(('localhost', port)) | 256 s.connect(('localhost', port)) |
| 257 _log.debug("Server running on %d", port) | 257 _log.debug("Server running on %d", port) |
| 258 except IOError as e: | 258 except IOError as error: |
| 259 if e.errno not in (errno.ECONNREFUSED, errno.ECONNRESET): | 259 if error.errno not in (errno.ECONNREFUSED, errno.ECONNRESET): |
| 260 raise | 260 raise |
| 261 _log.debug("Server NOT running on %d: %s", port, e) | 261 _log.debug("Server NOT running on %d: %s", port, error) |
| 262 return False | 262 return False |
| 263 finally: | 263 finally: |
| 264 s.close() | 264 s.close() |
| 265 return True | 265 return True |
| 266 | 266 |
| 267 def _check_that_all_ports_are_available(self): | 267 def _check_that_all_ports_are_available(self): |
| 268 for mapping in self._mappings: | 268 for mapping in self._mappings: |
| 269 s = socket.socket() | 269 s = socket.socket() |
| 270 if not self._platform.is_win(): | 270 if not self._platform.is_win(): |
| 271 s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | 271 s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
| 272 port = mapping['port'] | 272 port = mapping['port'] |
| 273 try: | 273 try: |
| 274 s.bind(('localhost', port)) | 274 s.bind(('localhost', port)) |
| 275 except IOError as e: | 275 except IOError as error: |
| 276 if e.errno in (errno.EALREADY, errno.EADDRINUSE): | 276 if error.errno in (errno.EALREADY, errno.EADDRINUSE): |
| 277 raise ServerError('Port %d is already in use.' % port) | 277 raise ServerError('Port %d is already in use.' % port) |
| 278 elif self._platform.is_win() and e.errno in (errno.WSAEACCES,):
# pylint: disable=no-member | 278 elif self._platform.is_win() and error.errno in (errno.WSAEACCES
,): # pylint: disable=no-member |
| 279 raise ServerError('Port %d is already in use.' % port) | 279 raise ServerError('Port %d is already in use.' % port) |
| 280 else: | 280 else: |
| 281 raise | 281 raise |
| 282 finally: | 282 finally: |
| 283 s.close() | 283 s.close() |
| 284 _log.debug('all ports are available') | 284 _log.debug('all ports are available') |
| OLD | NEW |