comparison src/org/tn5250j/framework/tn5250/DataStreamProducer.java @ 99:eda03b809f48

move blocking test from socket read to queue take
author Carl Byington <carl@five-ten-sg.com>
date Tue, 17 Jun 2014 15:13:41 -0700
parents 16e023784917
children 77ac18bc1b2f
comparison
equal deleted inserted replaced
98:16e023784917 99:eda03b809f48
12 12
13 import org.tn5250j.encoding.ICodePage; 13 import org.tn5250j.encoding.ICodePage;
14 14
15 import android.util.Log; 15 import android.util.Log;
16 16
17 import de.mud.terminal.vt320;
18
19 17
20 public class DataStreamProducer implements Runnable { 18 public class DataStreamProducer implements Runnable {
21 private static final String TAG = "DataStreamProducer"; 19 private static final String TAG = "DataStreamProducer";
22 private tnvt vt; 20 private tnvt vt;
23 private BufferedInputStream bin; 21 private BufferedInputStream bin;
24 private vt320 buffer;
25 private ByteArrayOutputStream baosin; 22 private ByteArrayOutputStream baosin;
26 private Thread me; 23 private Thread me;
27 private byte[] saveStream; 24 private byte[] saveStream;
28 private final BlockingQueue<Object> dsq; 25 private final BlockingQueue<Object> dsq;
29 private byte[] abyte2; 26 private byte[] abyte2;
32 private boolean dumpBytes = false; 29 private boolean dumpBytes = false;
33 private ICodePage codePage; 30 private ICodePage codePage;
34 31
35 32
36 33
37 public DataStreamProducer(tnvt vt, BufferedInputStream bin, vt320 buffer, BlockingQueue<Object> queue, byte[] init) { 34 public DataStreamProducer(tnvt vt, BufferedInputStream bin, BlockingQueue<Object> queue, byte[] init) {
38 this.bin = bin; 35 this.bin = bin;
39 this.vt = vt; 36 this.vt = vt;
40 this.buffer = buffer;
41 baosin = new ByteArrayOutputStream(); 37 baosin = new ByteArrayOutputStream();
42 dsq = queue; 38 dsq = queue;
43 abyte2 = init; 39 abyte2 = init;
44 } 40 }
45 41
165 baosin.reset(); 161 baosin.reset();
166 int j = -1; 162 int j = -1;
167 int i = 0; 163 int i = 0;
168 164
169 while(!done) { 165 while(!done) {
170 if (bin.available() == 0) buffer.testChanged();
171 i = bin.read(); 166 i = bin.read();
172 167
173 // WVL - LDC : 16/07/2003 : TR.000345 168 // WVL - LDC : 16/07/2003 : TR.000345
174 // The inStream return -1 when end-of-stream is reached. This 169 // The inStream return -1 when end-of-stream is reached. This
175 // happens e.g. when the connection is closed from the AS/400. 170 // happens e.g. when the connection is closed from the AS/400.
237 dump(rBytes); 232 dump(rBytes);
238 } 233 }
239 234
240 if (negotiate) { 235 if (negotiate) {
241 // get the negotiation option 236 // get the negotiation option
242 if (bin.available() == 0) buffer.testChanged();
243 baosin.write(bin.read()); 237 baosin.write(bin.read());
244 vt.negotiate(rBytes); 238 vt.negotiate(rBytes);
245 239
246 return null; 240 return null;
247 } 241 }