changeset 234:766176d84e73

delay testChanged() by 10ms for async transports
author Carl Byington <carl@five-ten-sg.com>
date Thu, 10 Jul 2014 11:25:46 -0700
parents 2626bf2a8cea
children ea49747c5447
files src/com/five_ten_sg/connectbot/service/Relay.java
diffstat 1 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/service/Relay.java	Thu Jul 10 10:44:09 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/Relay.java	Thu Jul 10 11:25:46 2014 -0700
@@ -111,11 +111,7 @@
         int offset;
         int charWidth;
         Timer timer = new Timer("relay.blocker", true);
-        TimerTask task = new TimerTask() {
-                             public void run() {
-                                 buffer.testChanged();
-                             }
-                         };
+        TimerTask task = null;
 
         try {
             while (true) {
@@ -124,11 +120,20 @@
                 offset = byteBuffer.arrayOffset() + byteBuffer.limit();
 
                 if (transport.willBlock()) {
+                    task = new TimerTask() {
+                        public void run() {
+                            buffer.testChanged();
+                        }
+                    };
                     timer.schedule(task, 10);   // 10 ms delay
                 }
 
                 bytesRead = transport.read(byteArray, offset, bytesToRead);
-                task.cancel();
+
+                if (task != null) {
+                    task.cancel();
+                    task = null;
+                }
 
                 if (bytesRead > 0) {
                     byteBuffer.limit(byteBuffer.limit() + bytesRead);