# HG changeset patch # User Carl Byington # Date 1411077074 25200 # Node ID 24186858750f63d7df57d0cdde2efc566d22e16b # Parent 63780d4fa8c3524e33dbbfc707a9d77109ffd735 add test buffer changed when input stream runs dry, similar to async test diff -r 63780d4fa8c3 -r 24186858750f src/org/tn5250j/framework/tn5250/DataStreamProducer.java --- a/src/org/tn5250j/framework/tn5250/DataStreamProducer.java Tue Sep 16 16:23:37 2014 -0700 +++ b/src/org/tn5250j/framework/tn5250/DataStreamProducer.java Thu Sep 18 14:51:14 2014 -0700 @@ -9,6 +9,8 @@ import java.io.IOException; import java.net.SocketException; import java.util.concurrent.BlockingQueue; +import java.util.Timer; +import java.util.TimerTask; import org.tn5250j.encoding.ICodePage; @@ -144,15 +146,30 @@ baosin.reset(); int j = -1; int i = 0; + Timer timer = new Timer("data.stream", true); + TimerTask task = null; while (!done) { - try { - if (bin.available() == 0) dsq.put(new Integer(0)); // trigger buffer.testChanged() + if (bin.available() == 0) { + task = new TimerTask() { + public void run() { + try { + dsq.put(new Integer(0)); // trigger buffer.testChanged() + } + catch (Exception ex) { + Log.w(TAG, "readIncoming error " + ex.getMessage()); + } + } + }; + timer.schedule(task, 10); // 10 ms delay } - catch (Exception ex) { - Log.w(TAG, "readIncoming error " + ex.getMessage()); + + i = bin.read(); + + if (task != null) { + task.cancel(); + task = null; } - i = bin.read(); // WVL - LDC : 16/07/2003 : TR.000345 // The inStream return -1 when end-of-stream is reached. This @@ -223,14 +240,28 @@ } if (negotiate) { - // get the negotiation option - try { - if (bin.available() == 0) dsq.put(new Integer(0)); // trigger buffer.testChanged() + if (bin.available() == 0) { + task = new TimerTask() { + public void run() { + try { + dsq.put(new Integer(0)); // trigger buffer.testChanged() + } + catch (Exception ex) { + Log.w(TAG, "readIncoming error " + ex.getMessage()); + } + } + }; + timer.schedule(task, 10); // 10 ms delay } - catch (Exception ex) { - Log.w(TAG, "readIncoming error " + ex.getMessage()); + + // get the negotiation option + baosin.write(bin.read()); + + if (task != null) { + task.cancel(); + task = null; } - baosin.write(bin.read()); + vt.negotiate(rBytes); return null; }