mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Interrupt all messaging sessions when the app starts shutting down.
This makes it more likely that connections will be closed cleanly. However, the interrupt() method is currently ineffective for incoming sessions as it won't interrupt a blocking read, e.g. when the packet reader is waiting for a packet.
This commit is contained in:
@@ -30,6 +30,7 @@ import org.briarproject.api.event.MessageToRequestEvent;
|
||||
import org.briarproject.api.event.RemoteRetentionTimeUpdatedEvent;
|
||||
import org.briarproject.api.event.RemoteSubscriptionsUpdatedEvent;
|
||||
import org.briarproject.api.event.RemoteTransportsUpdatedEvent;
|
||||
import org.briarproject.api.event.ShutdownEvent;
|
||||
import org.briarproject.api.event.TransportRemovedEvent;
|
||||
import org.briarproject.api.messaging.Ack;
|
||||
import org.briarproject.api.messaging.MessagingSession;
|
||||
@@ -169,6 +170,8 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
|
||||
(RemoteTransportsUpdatedEvent) e;
|
||||
if(r.getContactId().equals(contactId))
|
||||
dbExecutor.execute(new GenerateTransportAcks());
|
||||
} else if(e instanceof ShutdownEvent) {
|
||||
interrupt();
|
||||
} else if(e instanceof TransportRemovedEvent) {
|
||||
TransportRemovedEvent t = (TransportRemovedEvent) e;
|
||||
if(t.getTransportId().equals(transportId)) interrupt();
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.briarproject.api.event.ContactRemovedEvent;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.event.ShutdownEvent;
|
||||
import org.briarproject.api.event.TransportRemovedEvent;
|
||||
import org.briarproject.api.messaging.Ack;
|
||||
import org.briarproject.api.messaging.Message;
|
||||
@@ -108,8 +109,7 @@ class IncomingSession implements MessagingSession, EventListener {
|
||||
}
|
||||
|
||||
public void interrupt() {
|
||||
// This won't interrupt a blocking read, but the read will throw an
|
||||
// exception when the transport connection is closed
|
||||
// FIXME: This won't interrupt a blocking read
|
||||
interrupted = true;
|
||||
}
|
||||
|
||||
@@ -117,6 +117,8 @@ class IncomingSession implements MessagingSession, EventListener {
|
||||
if(e instanceof ContactRemovedEvent) {
|
||||
ContactRemovedEvent c = (ContactRemovedEvent) e;
|
||||
if(c.getContactId().equals(contactId)) interrupt();
|
||||
} else if(e instanceof ShutdownEvent) {
|
||||
interrupt();
|
||||
} else if(e instanceof TransportRemovedEvent) {
|
||||
TransportRemovedEvent t = (TransportRemovedEvent) e;
|
||||
if(t.getTransportId().equals(transportId)) interrupt();
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.briarproject.api.event.ContactRemovedEvent;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.event.ShutdownEvent;
|
||||
import org.briarproject.api.event.TransportRemovedEvent;
|
||||
import org.briarproject.api.messaging.Ack;
|
||||
import org.briarproject.api.messaging.MessagingSession;
|
||||
@@ -121,6 +122,8 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
|
||||
if(e instanceof ContactRemovedEvent) {
|
||||
ContactRemovedEvent c = (ContactRemovedEvent) e;
|
||||
if(c.getContactId().equals(contactId)) interrupt();
|
||||
} else if(e instanceof ShutdownEvent) {
|
||||
interrupt();
|
||||
} else if(e instanceof TransportRemovedEvent) {
|
||||
TransportRemovedEvent t = (TransportRemovedEvent) e;
|
||||
if(t.getTransportId().equals(transportId)) interrupt();
|
||||
|
||||
Reference in New Issue
Block a user