changeset 233:2626bf2a8cea

delay testChanged() by 10ms for async transports
author Carl Byington <carl@five-ten-sg.com>
date Thu, 10 Jul 2014 10:44:09 -0700
parents 83d633b281cb
children 766176d84e73
files src/com/five_ten_sg/connectbot/service/Relay.java
diffstat 1 files changed, 6 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/service/Relay.java	Wed Jul 09 15:23:30 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/Relay.java	Thu Jul 10 10:44:09 2014 -0700
@@ -111,7 +111,11 @@
         int offset;
         int charWidth;
         Timer timer = new Timer("relay.blocker", true);
-        TimerTask task = null;
+        TimerTask task = new TimerTask() {
+                             public void run() {
+                                 buffer.testChanged();
+                             }
+                         };
 
         try {
             while (true) {
@@ -120,20 +124,11 @@
                 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);
-
-                if (task != null) {
-                    task.cancel();
-                    task = null;
-                }
+                task.cancel();
 
                 if (bytesRead > 0) {
                     byteBuffer.limit(byteBuffer.limit() + bytesRead);