From 33a57eda756e2136475cf45d3aa2051127d738fe Mon Sep 17 00:00:00 2001 From: Forrest Voight Date: Mon, 30 Jan 2012 14:07:57 -0500 Subject: [PATCH] retry binding to p2p port in the background if it is busy --- p2pool/p2p.py | 15 +++++++++++++-- 1 files changed, 13 insertions(+), 2 deletions(-) diff --git a/p2pool/p2p.py b/p2pool/p2p.py index 4aa8c90..f562b9c 100644 --- a/p2pool/p2p.py +++ b/p2pool/p2p.py @@ -3,7 +3,7 @@ from __future__ import division import random import time -from twisted.internet import defer, protocol, reactor +from twisted.internet import defer, error, protocol, reactor from twisted.python import log import p2pool @@ -250,7 +250,18 @@ class ServerFactory(protocol.ServerFactory): assert not self.running self.running = True - self.listen_port = reactor.listenTCP(self.node.port, self) + def attempt_listen(): + if not self.running: + return + try: + self.listen_port = reactor.listenTCP(self.node.port, self) + except error.CannotListenError, e: + if e.socketError.errno != 98: + raise + print 'P2P port busy, retrying listening in 3 seconds.' + reactor.callLater(3, attempt_listen) + attempt_listen() + def stop(self): assert self.running self.running = False -- 1.7.1