changeset 227:2dd627df4dfb

delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
author Carl Byington <carl@five-ten-sg.com>
date Wed, 09 Jul 2014 09:03:04 -0700
parents ab42094b5dda
children c9a7f33b53a8
files src/com/five_ten_sg/connectbot/service/Relay.java src/com/five_ten_sg/connectbot/service/TerminalMonitor.java
diffstat 2 files changed, 26 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/service/Relay.java	Tue Jul 08 20:57:30 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/Relay.java	Wed Jul 09 09:03:04 2014 -0700
@@ -24,6 +24,8 @@
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CoderResult;
 import java.nio.charset.CodingErrorAction;
+import java.util.Timer;
+import java.util.TimerTask;
 
 import org.apache.harmony.niochar.charset.additional.IBM437;
 
@@ -108,6 +110,8 @@
         int bytesToRead;
         int offset;
         int charWidth;
+        Timer timer = new Timer("relay.blocker", true);
+        TimerTask task = null;
 
         try {
             while (true) {
@@ -115,10 +119,21 @@
                 bytesToRead = byteBuffer.capacity() - byteBuffer.limit();
                 offset = byteBuffer.arrayOffset() + byteBuffer.limit();
 
-                if (transport.willBlock()) buffer.testChanged();
+                if (transport.willBlock()) {
+                    task = new TimerTask(){
+                        public void run() {
+                            buffer.testChanged();
+                        }
+                    };
+                    timer.schedule(task, 10);   // 10 ms delay
 
                 bytesRead = transport.read(byteArray, offset, bytesToRead);
 
+                if (task != null) {
+                    task.cancel();
+                    task = null;
+                }
+
                 if (bytesRead > 0) {
                     byteBuffer.limit(byteBuffer.limit() + bytesRead);
 
@@ -145,5 +160,7 @@
         catch (IOException e) {
             Log.e(TAG, "Problem while handling incoming data in relay thread", e);
         }
+
+        timer.cancel();
     }
 }
--- a/src/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Tue Jul 08 20:57:30 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Wed Jul 09 09:03:04 2014 -0700
@@ -335,6 +335,13 @@
         }
     };
 
+    public void resetWatch() {
+        start_line   = 0;
+        end_line     = 500;
+        start_column = 0;
+        end_column   = 500;
+    };
+
     public void sendScreen(char cmd) {
         char lines   = (char)(buffer.height & 0x0000ffff);
         char columns = (char)(buffer.width & 0x0000ffff);
@@ -349,6 +356,7 @@
         }
 
         monitorWrite(cmd, arg);
+        resetWatch();
     }
 
     public synchronized void activate() {