From b5a74a26ee6548b493cdece5a05f4fcba71c0012 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 7 Jun 2012 10:17:30 +1200 Subject: Let Pathod pick an arbitrary empty port if -p 0 is specified. --- libpathod/pathod.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'libpathod/pathod.py') diff --git a/libpathod/pathod.py b/libpathod/pathod.py index ca24c62c..6b3deaa6 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -205,11 +205,24 @@ class PathodApp(tornado.web.Application): # begin nocover -def run(application, port, ssl_options): +def make_server(application, port, address, ssl_options): + """ + Returns the bound port. This will match the passed port, unless the + passed port was 0. In that case, an arbitrary empty port will be bound + to, and this new port will be returned. + """ http_server = tornado.httpserver.HTTPServer( application, ssl_options=ssl_options ) - http_server.listen(port) - tornado.ioloop.IOLoop.instance().start() + http_server.listen(port, address) + port = port + for i in http_server._sockets.values(): + sn = i.getsockname() + if sn[0] == address: + port = sn[1] + return port + +def run(): + tornado.ioloop.IOLoop.instance().start() -- cgit v1.2.3