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); | ||||
|                 } | ||||
|                 try { | ||||
|                     m.receiveMessages(new Manager.ReceiveMessageHandler() { | ||||
|                     m.receiveMessages(5, true, new Manager.ReceiveMessageHandler() { | ||||
|                         @Override | ||||
|                         public void handleMessage(TextSecureEnvelope envelope) { | ||||
|                             System.out.println("Envelope from: " + envelope.getSource()); | ||||
| @ -233,5 +233,6 @@ public class Main { | ||||
|                 break; | ||||
|         } | ||||
|         m.save(); | ||||
|         System.exit(0); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -187,7 +187,7 @@ public class Manager { | ||||
|         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); | ||||
|         TextSecureMessagePipe messagePipe = null; | ||||
| 
 | ||||
| @ -197,9 +197,11 @@ public class Manager { | ||||
|             while (true) { | ||||
|                 TextSecureEnvelope envelope; | ||||
|                 try { | ||||
|                     envelope = messagePipe.read(1, TimeUnit.MINUTES); | ||||
|                     envelope = messagePipe.read(timeoutSeconds, TimeUnit.SECONDS); | ||||
|                     handler.handleMessage(envelope); | ||||
|                 } catch (TimeoutException e) { | ||||
|                     if (returnOnTimeout) | ||||
|                         return; | ||||
|                 } catch (InvalidVersionException e) { | ||||
|                     System.out.println("Ignoring error: " + e.getMessage()); | ||||
|                 } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 AsamK
						AsamK