| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Constrained Network Server. Serves files with supplied network constraints. | 6 """Constrained Network Server. Serves files with supplied network constraints. |
| 7 | 7 |
| 8 The CNS exposes a web based API allowing network constraints to be imposed on | 8 The CNS exposes a web based API allowing network constraints to be imposed on |
| 9 file serving. | 9 file serving. |
| 10 | 10 |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 log_level = _DEFAULT_LOG_LEVEL | 320 log_level = _DEFAULT_LOG_LEVEL |
| 321 if verbose: | 321 if verbose: |
| 322 log_level = logging.DEBUG | 322 log_level = logging.DEBUG |
| 323 logging.basicConfig(level=log_level, format='[%(threadName)s] %(message)s') | 323 logging.basicConfig(level=log_level, format='[%(threadName)s] %(message)s') |
| 324 | 324 |
| 325 | 325 |
| 326 def Main(): | 326 def Main(): |
| 327 """Configure and start the ConstrainedNetworkServer.""" | 327 """Configure and start the ConstrainedNetworkServer.""" |
| 328 options = ParseArgs() | 328 options = ParseArgs() |
| 329 | 329 |
| 330 try: |
| 331 traffic_control.CheckRequirements() |
| 332 except traffic_control.TrafficControlError as e: |
| 333 cherrypy.log(e.msg) |
| 334 return |
| 335 |
| 330 cherrypy.config.update( | 336 cherrypy.config.update( |
| 331 {'server.socket_host': '::', 'server.socket_port': options.port}) | 337 {'server.socket_host': '::', 'server.socket_port': options.port}) |
| 332 | 338 |
| 333 if options.threads: | 339 if options.threads: |
| 334 cherrypy.config.update({'server.thread_pool': options.threads}) | 340 cherrypy.config.update({'server.thread_pool': options.threads}) |
| 335 | 341 |
| 336 # Setup port allocator here so we can call cleanup on failures/exit. | 342 # Setup port allocator here so we can call cleanup on failures/exit. |
| 337 pa = PortAllocator(options.port_range, expiry_time_secs=options.expiry_time) | 343 pa = PortAllocator(options.port_range, expiry_time_secs=options.expiry_time) |
| 338 | 344 |
| 339 try: | 345 try: |
| 340 cherrypy.quickstart(ConstrainedNetworkServer(options, pa)) | 346 cherrypy.quickstart(ConstrainedNetworkServer(options, pa)) |
| 341 finally: | 347 finally: |
| 342 # Disable Ctrl-C handler to prevent interruption of cleanup. | 348 # Disable Ctrl-C handler to prevent interruption of cleanup. |
| 343 signal.signal(signal.SIGINT, lambda signal, frame: None) | 349 signal.signal(signal.SIGINT, lambda signal, frame: None) |
| 344 pa.Cleanup(options.interface, all_ports=True) | 350 pa.Cleanup(options.interface, all_ports=True) |
| 345 | 351 |
| 346 | 352 |
| 347 if __name__ == '__main__': | 353 if __name__ == '__main__': |
| 348 Main() | 354 Main() |
| OLD | NEW |