I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 416b0e45 authored by zzz's avatar zzz
Browse files

Prevent two NTCP Pumpers

parent 0ea532c7
No related branches found
No related tags found
No related merge requests found
...@@ -285,9 +285,10 @@ public class CommSystemFacadeImpl extends CommSystemFacade { ...@@ -285,9 +285,10 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
_log.warn("Halting NTCP to change address"); _log.warn("Halting NTCP to change address");
t.stopListening(); t.stopListening();
newAddr.setOptions(newProps); newAddr.setOptions(newProps);
// Give NTCP Pumper time to stop so we don't end up with two... // Wait for NTCP Pumper to stop so we don't end up with two...
// Need better way while (t.isAlive()) {
try { Thread.sleep(5*1000); } catch (InterruptedException ie) {} try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
}
t.restartListening(newAddr); t.restartListening(newAddr);
_log.warn("Changed NTCP Address and started up, address is now " + newAddr); _log.warn("Changed NTCP Address and started up, address is now " + newAddr);
return; return;
......
...@@ -85,6 +85,13 @@ public class EventPumper implements Runnable { ...@@ -85,6 +85,13 @@ public class EventPumper implements Runnable {
_selector.wakeup(); _selector.wakeup();
} }
/**
* Selector can take quite a while to close after calling stopPumping()
*/
public boolean isAlive() {
return _alive || (_selector != null && _selector.isOpen());
}
public void register(ServerSocketChannel chan) { public void register(ServerSocketChannel chan) {
if (_log.shouldLog(Log.DEBUG)) _log.debug("Registering server socket channel"); if (_log.shouldLog(Log.DEBUG)) _log.debug("Registering server socket channel");
synchronized (_wantsRegister) { _wantsRegister.add(chan); } synchronized (_wantsRegister) { _wantsRegister.add(chan); }
......
...@@ -432,6 +432,10 @@ public class NTCPTransport extends TransportImpl { ...@@ -432,6 +432,10 @@ public class NTCPTransport extends TransportImpl {
return bindAddress(); return bindAddress();
} }
public boolean isAlive() {
return _pumper.isAlive();
}
private RouterAddress bindAddress() { private RouterAddress bindAddress() {
if (_myAddress != null) { if (_myAddress != null) {
try { try {
...@@ -538,6 +542,10 @@ public class NTCPTransport extends TransportImpl { ...@@ -538,6 +542,10 @@ public class NTCPTransport extends TransportImpl {
} }
} }
/**
* This doesn't (completely) block, caller should check isAlive()
* before calling startListening() or restartListening()
*/
public void stopListening() { public void stopListening() {
if (_log.shouldLog(Log.DEBUG)) _log.debug("Stopping ntcp transport"); if (_log.shouldLog(Log.DEBUG)) _log.debug("Stopping ntcp transport");
_pumper.stopPumping(); _pumper.stopPumping();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment