Mercurial > 510Connectbot
comparison src/org/tn5250j/framework/tn5250/DataStreamProducer.java @ 394:24186858750f
add test buffer changed when input stream runs dry, similar to async test
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 18 Sep 2014 14:51:14 -0700 |
parents | 7ac1a0b02f44 |
children |
comparison
equal
deleted
inserted
replaced
393:63780d4fa8c3 | 394:24186858750f |
---|---|
7 import java.io.FileNotFoundException; | 7 import java.io.FileNotFoundException; |
8 import java.io.FileOutputStream; | 8 import java.io.FileOutputStream; |
9 import java.io.IOException; | 9 import java.io.IOException; |
10 import java.net.SocketException; | 10 import java.net.SocketException; |
11 import java.util.concurrent.BlockingQueue; | 11 import java.util.concurrent.BlockingQueue; |
12 import java.util.Timer; | |
13 import java.util.TimerTask; | |
12 | 14 |
13 import org.tn5250j.encoding.ICodePage; | 15 import org.tn5250j.encoding.ICodePage; |
14 | 16 |
15 import android.util.Log; | 17 import android.util.Log; |
16 | 18 |
142 boolean done = false; | 144 boolean done = false; |
143 boolean negotiate = false; | 145 boolean negotiate = false; |
144 baosin.reset(); | 146 baosin.reset(); |
145 int j = -1; | 147 int j = -1; |
146 int i = 0; | 148 int i = 0; |
149 Timer timer = new Timer("data.stream", true); | |
150 TimerTask task = null; | |
147 | 151 |
148 while (!done) { | 152 while (!done) { |
149 try { | 153 if (bin.available() == 0) { |
150 if (bin.available() == 0) dsq.put(new Integer(0)); // trigger buffer.testChanged() | 154 task = new TimerTask() { |
151 } | 155 public void run() { |
152 catch (Exception ex) { | 156 try { |
153 Log.w(TAG, "readIncoming error " + ex.getMessage()); | 157 dsq.put(new Integer(0)); // trigger buffer.testChanged() |
154 } | 158 } |
159 catch (Exception ex) { | |
160 Log.w(TAG, "readIncoming error " + ex.getMessage()); | |
161 } | |
162 } | |
163 }; | |
164 timer.schedule(task, 10); // 10 ms delay | |
165 } | |
166 | |
155 i = bin.read(); | 167 i = bin.read(); |
168 | |
169 if (task != null) { | |
170 task.cancel(); | |
171 task = null; | |
172 } | |
156 | 173 |
157 // WVL - LDC : 16/07/2003 : TR.000345 | 174 // WVL - LDC : 16/07/2003 : TR.000345 |
158 // The inStream return -1 when end-of-stream is reached. This | 175 // The inStream return -1 when end-of-stream is reached. This |
159 // happens e.g. when the connection is closed from the AS/400. | 176 // happens e.g. when the connection is closed from the AS/400. |
160 // So we stop in this case! | 177 // So we stop in this case! |
221 if (dumpBytes) { | 238 if (dumpBytes) { |
222 dump(rBytes); | 239 dump(rBytes); |
223 } | 240 } |
224 | 241 |
225 if (negotiate) { | 242 if (negotiate) { |
243 if (bin.available() == 0) { | |
244 task = new TimerTask() { | |
245 public void run() { | |
246 try { | |
247 dsq.put(new Integer(0)); // trigger buffer.testChanged() | |
248 } | |
249 catch (Exception ex) { | |
250 Log.w(TAG, "readIncoming error " + ex.getMessage()); | |
251 } | |
252 } | |
253 }; | |
254 timer.schedule(task, 10); // 10 ms delay | |
255 } | |
256 | |
226 // get the negotiation option | 257 // get the negotiation option |
227 try { | |
228 if (bin.available() == 0) dsq.put(new Integer(0)); // trigger buffer.testChanged() | |
229 } | |
230 catch (Exception ex) { | |
231 Log.w(TAG, "readIncoming error " + ex.getMessage()); | |
232 } | |
233 baosin.write(bin.read()); | 258 baosin.write(bin.read()); |
259 | |
260 if (task != null) { | |
261 task.cancel(); | |
262 task = null; | |
263 } | |
264 | |
234 vt.negotiate(rBytes); | 265 vt.negotiate(rBytes); |
235 return null; | 266 return null; |
236 } | 267 } |
237 | 268 |
238 return rBytes; | 269 return rBytes; |