Attempt to disconnect on thread interrupt
This commit is contained in:
parent
9c2d8589bf
commit
c9c0806e0d
@ -206,7 +206,8 @@ public class BitmessageContext {
|
||||
try {
|
||||
t.join();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
LOG.info("Thread was interrupted. Trying to shut down synchronization and returning.");
|
||||
t.interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,9 @@ import java.net.InetAddress;
|
||||
public interface NetworkHandler {
|
||||
/**
|
||||
* Connects to the trusted host, fetches and offers new messages and disconnects afterwards.
|
||||
* <p>
|
||||
* An implementation should disconnect if either the timeout is reached or the returned thread is interrupted.
|
||||
* </p>
|
||||
*/
|
||||
Thread synchronize(InetAddress trustedHost, int port, MessageListener listener, long timeoutInSeconds);
|
||||
|
||||
|
@ -130,6 +130,9 @@ public class Connection {
|
||||
|
||||
@SuppressWarnings("RedundantIfStatement")
|
||||
private boolean syncFinished(NetworkMessage msg) {
|
||||
if (Thread.interrupted()) {
|
||||
return true;
|
||||
}
|
||||
if (syncTimeout == 0 || state != ACTIVE) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user