88from twisted import plugin
99from twisted .python import usage , log
1010from twisted .internet import reactor , defer
11+ from twisted .internet .error import CannotListenError
1112from twisted .application import service
1213
1314from .recast import CastFactory
@@ -33,9 +34,11 @@ def __init__(self, config):
3334 self .tcptimeout = float (config .get ('tcptimeout' , '15.0' ))
3435 self .commitperiod = float (config .get ('commitInterval' , '5.0' ))
3536 self .maxActive = int (config .get ('maxActive' , '20' ))
36- self .bind = config .get ('bind' , '' )
37+ self .bind , _sep , portn = config .get ('bind' , '' ). strip (). partition ( ': ' )
3738 self .addrlist = []
3839
40+ self .port = int (portn or '0' )
41+
3942 for addr in config .get ('addrlist' , '' ).split (',' ):
4043 if not addr :
4144 continue
@@ -67,9 +70,13 @@ def privilegedStartService(self):
6770 # Attaching CastFactory to ProcessorController
6871 self .tcpFactory .commit = self .ctrl .commit
6972
70- self .tcp = self .reactor .listenTCP (0 , self .tcpFactory ,
73+ self .tcp = self .reactor .listenTCP (self . port , self .tcpFactory ,
7174 interface = self .bind )
72- self .tcp .startListening ()
75+ try :
76+ self .tcp .startListening ()
77+ except CannotListenError :
78+ pass # older Twisted required this.
79+ # newer Twisted errors. sigh...
7380
7481 # Find out which port is in use
7582 addr = self .tcp .getHost ()
@@ -82,7 +89,8 @@ def privilegedStartService(self):
8289 udpaddrs = self .addrlist ,
8390 period = self .annperiod )
8491
85- self .udp = SharedUDP (0 , self .udpProto , reactor = self .reactor )
92+ self .udp = SharedUDP (self .port , self .udpProto , reactor = self .reactor ,
93+ interface = self .bind )
8694 self .udp .startListening ()
8795
8896 # This will start up plugin Processors
0 commit comments