Mercurial > 510Connectbot
comparison src/com/five_ten_sg/connectbot/service/Relay.java @ 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 | 77ac18bc1b2f |
children | c9a7f33b53a8 |
comparison
equal
deleted
inserted
replaced
226:ab42094b5dda | 227:2dd627df4dfb |
---|---|
22 import java.nio.CharBuffer; | 22 import java.nio.CharBuffer; |
23 import java.nio.charset.Charset; | 23 import java.nio.charset.Charset; |
24 import java.nio.charset.CharsetDecoder; | 24 import java.nio.charset.CharsetDecoder; |
25 import java.nio.charset.CoderResult; | 25 import java.nio.charset.CoderResult; |
26 import java.nio.charset.CodingErrorAction; | 26 import java.nio.charset.CodingErrorAction; |
27 import java.util.Timer; | |
28 import java.util.TimerTask; | |
27 | 29 |
28 import org.apache.harmony.niochar.charset.additional.IBM437; | 30 import org.apache.harmony.niochar.charset.additional.IBM437; |
29 | 31 |
30 import com.five_ten_sg.connectbot.transport.AbsTransport; | 32 import com.five_ten_sg.connectbot.transport.AbsTransport; |
31 import android.graphics.Paint; | 33 import android.graphics.Paint; |
106 int bytesRead = 0; | 108 int bytesRead = 0; |
107 byteBuffer.limit(0); | 109 byteBuffer.limit(0); |
108 int bytesToRead; | 110 int bytesToRead; |
109 int offset; | 111 int offset; |
110 int charWidth; | 112 int charWidth; |
113 Timer timer = new Timer("relay.blocker", true); | |
114 TimerTask task = null; | |
111 | 115 |
112 try { | 116 try { |
113 while (true) { | 117 while (true) { |
114 charWidth = bridge.charWidth; | 118 charWidth = bridge.charWidth; |
115 bytesToRead = byteBuffer.capacity() - byteBuffer.limit(); | 119 bytesToRead = byteBuffer.capacity() - byteBuffer.limit(); |
116 offset = byteBuffer.arrayOffset() + byteBuffer.limit(); | 120 offset = byteBuffer.arrayOffset() + byteBuffer.limit(); |
117 | 121 |
118 if (transport.willBlock()) buffer.testChanged(); | 122 if (transport.willBlock()) { |
123 task = new TimerTask(){ | |
124 public void run() { | |
125 buffer.testChanged(); | |
126 } | |
127 }; | |
128 timer.schedule(task, 10); // 10 ms delay | |
119 | 129 |
120 bytesRead = transport.read(byteArray, offset, bytesToRead); | 130 bytesRead = transport.read(byteArray, offset, bytesToRead); |
131 | |
132 if (task != null) { | |
133 task.cancel(); | |
134 task = null; | |
135 } | |
121 | 136 |
122 if (bytesRead > 0) { | 137 if (bytesRead > 0) { |
123 byteBuffer.limit(byteBuffer.limit() + bytesRead); | 138 byteBuffer.limit(byteBuffer.limit() + bytesRead); |
124 | 139 |
125 synchronized (this) { | 140 synchronized (this) { |
143 } | 158 } |
144 } | 159 } |
145 catch (IOException e) { | 160 catch (IOException e) { |
146 Log.e(TAG, "Problem while handling incoming data in relay thread", e); | 161 Log.e(TAG, "Problem while handling incoming data in relay thread", e); |
147 } | 162 } |
163 | |
164 timer.cancel(); | |
148 } | 165 } |
149 } | 166 } |