From 7a32f8efd6dc2baa40a713b9326b48643dba3e36 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Fri, 5 Feb 2010 19:17:46 +0000 Subject: [PATCH] Try yet again to prevent two NTCP pumpers --- .../router/transport/ntcp/NTCPTransport.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java b/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java index 41ad29e23c..afee2bac07 100644 --- a/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java +++ b/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java @@ -421,7 +421,18 @@ public class NTCPTransport extends TransportImpl { private static final int NUM_CONCURRENT_READERS = 3; private static final int NUM_CONCURRENT_WRITERS = 3; + /** + * Called by TransportManager. + * Caller should stop the transport first, then + * verify stopped with isAlive() + * Unfortunately TransportManager doesn't do that, so we + * check here to prevent two pumpers. + * @return appears to be ignored by caller + */ public synchronized RouterAddress startListening() { + // try once again to prevent two pumpers which is fatal + if (_pumper.isAlive()) + return _myAddress != null ? _myAddress.toRouterAddress() : null; if (_log.shouldLog(Log.WARN)) _log.warn("Starting ntcp transport listening"); _finisher.start(); _pumper.startPumping(); @@ -433,7 +444,17 @@ public class NTCPTransport extends TransportImpl { return bindAddress(); } + /** + * Only called by CSFI. + * Caller should stop the transport first, then + * verify stopped with isAlive() + * @return appears to be ignored by caller + */ public synchronized RouterAddress restartListening(RouterAddress addr) { + // try once again to prevent two pumpers which is fatal + // we could just return null since the return value is ignored + if (_pumper.isAlive()) + return _myAddress != null ? _myAddress.toRouterAddress() : null; if (_log.shouldLog(Log.WARN)) _log.warn("Restarting ntcp transport listening"); _finisher.start(); _pumper.startPumping(); @@ -452,6 +473,7 @@ public class NTCPTransport extends TransportImpl { return _pumper.isAlive(); } + /** call from synchronized method */ private RouterAddress bindAddress() { if (_myAddress != null) { try { -- GitLab