Exit on timeout when receiving
- Could be made optional in the future - Sending messages while receiving results in damaged session state because both save their own state
This commit is contained in:
parent
bd485ec9f7
commit
704f2d76ba
@ -186,7 +186,7 @@ public class Main {
|
|||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
m.receiveMessages(new Manager.ReceiveMessageHandler() {
|
m.receiveMessages(5, true, new Manager.ReceiveMessageHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(TextSecureEnvelope envelope) {
|
public void handleMessage(TextSecureEnvelope envelope) {
|
||||||
System.out.println("Envelope from: " + envelope.getSource());
|
System.out.println("Envelope from: " + envelope.getSource());
|
||||||
@ -233,5 +233,6 @@ public class Main {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m.save();
|
m.save();
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ public class Manager {
|
|||||||
void handleMessage(TextSecureEnvelope envelope);
|
void handleMessage(TextSecureEnvelope envelope);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void receiveMessages(ReceiveMessageHandler handler) throws IOException {
|
public void receiveMessages(int timeoutSeconds, boolean returnOnTimeout, ReceiveMessageHandler handler) throws IOException {
|
||||||
TextSecureMessageReceiver messageReceiver = new TextSecureMessageReceiver(URL, TRUST_STORE, username, password, signalingKey);
|
TextSecureMessageReceiver messageReceiver = new TextSecureMessageReceiver(URL, TRUST_STORE, username, password, signalingKey);
|
||||||
TextSecureMessagePipe messagePipe = null;
|
TextSecureMessagePipe messagePipe = null;
|
||||||
|
|
||||||
@ -197,9 +197,11 @@ public class Manager {
|
|||||||
while (true) {
|
while (true) {
|
||||||
TextSecureEnvelope envelope;
|
TextSecureEnvelope envelope;
|
||||||
try {
|
try {
|
||||||
envelope = messagePipe.read(1, TimeUnit.MINUTES);
|
envelope = messagePipe.read(timeoutSeconds, TimeUnit.SECONDS);
|
||||||
handler.handleMessage(envelope);
|
handler.handleMessage(envelope);
|
||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
|
if (returnOnTimeout)
|
||||||
|
return;
|
||||||
} catch (InvalidVersionException e) {
|
} catch (InvalidVersionException e) {
|
||||||
System.out.println("Ignoring error: " + e.getMessage());
|
System.out.println("Ignoring error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user