changeset 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 63780d4fa8c3
children 74d527fe7f5f
files src/org/tn5250j/framework/tn5250/DataStreamProducer.java
diffstat 1 files changed, 42 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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;
         }