comparison src/org/tn5250j/framework/tn5250/tnvt.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 33eb63352be5
children 9204fe526e65
comparison
equal deleted inserted replaced
98:16e023784917 99:eda03b809f48
75 import java.net.Socket; 75 import java.net.Socket;
76 import java.util.Arrays; 76 import java.util.Arrays;
77 import java.util.Properties; 77 import java.util.Properties;
78 import java.util.concurrent.ArrayBlockingQueue; 78 import java.util.concurrent.ArrayBlockingQueue;
79 import java.util.concurrent.BlockingQueue; 79 import java.util.concurrent.BlockingQueue;
80 80 import java.util.concurrent.TimeUnit;
81 import javax.net.ssl.SSLSocket; 81 import javax.net.ssl.SSLSocket;
82 82
83 import android.content.Intent; 83 import android.content.Intent;
84 import android.net.Uri; 84 import android.net.Uri;
85 import android.util.Log; 85 import android.util.Log;
138 private int readType; 138 private int readType;
139 private boolean enhanced = true; 139 private boolean enhanced = true;
140 private boolean cursorOn = false; 140 private boolean cursorOn = false;
141 private String hostname = ""; 141 private String hostname = "";
142 private int port = 23; 142 private int port = 23;
143 private vt320 buffer;
143 private boolean connected = false; 144 private boolean connected = false;
144 private boolean support132 = true; 145 private boolean support132 = true;
145 private ByteArrayOutputStream baosp = null; 146 private ByteArrayOutputStream baosp = null;
146 private ByteArrayOutputStream baosrsp = null; 147 private ByteArrayOutputStream baosrsp = null;
147 private int devSeq = -1; 148 private int devSeq = -1;
258 259
259 public final boolean connect(String hostname, int port, String encryption, String homeDirectory, vt320 buffer) { 260 public final boolean connect(String hostname, int port, String encryption, String homeDirectory, vt320 buffer) {
260 try { 261 try {
261 this.hostname = hostname; 262 this.hostname = hostname;
262 this.port = port; 263 this.port = port;
264 this.buffer = buffer;
263 265
264 try { 266 try {
265 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT, 267 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
266 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED,"X - Connecting"); 268 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED,"X - Connecting");
267 } catch (Exception exc) { 269 } catch (Exception exc) {
296 } catch (Exception excc) { 298 } catch (Exception excc) {
297 Log.w(TAG,"setCursorOff " + excc.getMessage()); 299 Log.w(TAG,"setCursorOff " + excc.getMessage());
298 300
299 } 301 }
300 302
301 producer = new DataStreamProducer(this, bin, buffer, dsq, abyte0); 303 producer = new DataStreamProducer(this, bin, dsq, abyte0);
302 pthread = new Thread(producer); 304 pthread = new Thread(producer);
303 // pthread.setPriority(pthread.MIN_PRIORITY); 305 // pthread.setPriority(pthread.MIN_PRIORITY);
304 pthread.setPriority(Thread.NORM_PRIORITY); 306 pthread.setPriority(Thread.NORM_PRIORITY);
305 // pthread.setPriority(Thread.NORM_PRIORITY / 2); 307 // pthread.setPriority(Thread.NORM_PRIORITY / 2);
306 pthread.start(); 308 pthread.start();
984 bk = new Stream5250(); 986 bk = new Stream5250();
985 987
986 while (keepTrucking) { 988 while (keepTrucking) {
987 989
988 try { 990 try {
989 bk.initialize((byte[]) dsq.take()); 991 Object e = dsq.poll(0L, TimeUnit.SECONDS);
992 if (e == null) {
993 buffer.testChanged();
994 e = dsq.take();
995 };
996 bk.initialize((byte[])e);
990 } catch (InterruptedException ie) { 997 } catch (InterruptedException ie) {
991 Log.w(TAG," vt thread interrupted and stopping "); 998 Log.w(TAG," vt thread interrupted and stopping ");
992 keepTrucking = false; 999 keepTrucking = false;
993 continue; 1000 continue;
994 } 1001 }