summaryrefslogtreecommitdiff
path: root/distbuild
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@gmail.com>2014-10-01 16:24:47 +0000
committerRichard Maw <richard.maw@gmail.com>2014-10-01 16:24:47 +0000
commit01060c72158893863162acec85f576c442fc49ff (patch)
tree577ba011a02f11f8b8343647b9af6b5cc4a793b4 /distbuild
parentce2de6bd60db874f26502350a75de10faa1bf220 (diff)
downloadmorph-01060c72158893863162acec85f576c442fc49ff.tar.gz
distbuild: allow daemons to bind to ephemeral ports
You can bind to an ephemeral port by passing 0 as the port number. To work out which port you actually got, you need to call getsockname(). To facilitate being able to spawn multiple copies of the daemons for testing environments, you can pass a -file option, which will make the daemon write which port it actually bound to. If this path is a fifo, reading from it in the spawner process will allow synchronisation of only spawning services that require that port to be ready after it is.
Diffstat (limited to 'distbuild')
-rw-r--r--distbuild/sockserv.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/distbuild/sockserv.py b/distbuild/sockserv.py
index a5215e79..68991a93 100644
--- a/distbuild/sockserv.py
+++ b/distbuild/sockserv.py
@@ -26,15 +26,20 @@ class ListenServer(StateMachine):
'''Listen for new connections on a port, send events for them.'''
- def __init__(self, addr, port, machine, extra_args=None):
+ def __init__(self, addr, port, machine, extra_args=None, port_file=''):
StateMachine.__init__(self, 'listening')
self._addr = addr
self._port = port
self._machine = machine
self._extra_args = extra_args or []
+ self._port_file = port_file
def setup(self):
src = ListeningSocketEventSource(self._addr, self._port)
+ if self._port_file:
+ host, port = src.sock.getsockname()
+ with open(self._port_file, 'w') as f:
+ f.write(port)
self.mainloop.add_event_source(src)
spec = [