changeset 15:1588e359a972

queue pending monitor commands until socket is open
author Carl Byington <carl@five-ten-sg.com>
date Thu, 29 May 2014 12:40:27 -0700
parents ab7313512aba
children 48a8daea9221
files libs/armeabi/libcom_google_ase_Exec.so libs/x86/libcom_google_ase_Exec.so res/values/version.xml src/com/five_ten_sg/connectbot/service/TerminalBridge.java src/com/five_ten_sg/connectbot/service/TerminalMonitor.java
diffstat 5 files changed, 29 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
Binary file libs/armeabi/libcom_google_ase_Exec.so has changed
Binary file libs/x86/libcom_google_ase_Exec.so has changed
--- a/res/values/version.xml	Thu May 22 10:46:17 2014 -0700
+++ b/res/values/version.xml	Thu May 29 12:40:27 2014 -0700
@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-	<string name="msg_version" translatable="false">510 ConnectBot 1.7.2-1 (e11983ee7321+ 2014-04-20)</string>
+	<string name="msg_version" translatable="false">510Connectbot 1.7.2-1 (ab7313512aba+ 2014-05-29)</string>
 </resources>
--- a/src/com/five_ten_sg/connectbot/service/TerminalBridge.java	Thu May 22 10:46:17 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/TerminalBridge.java	Thu May 29 12:40:27 2014 -0700
@@ -214,10 +214,10 @@
             @Override
             public void write(byte[] b) {
                 try {
-                    if (b != null && transport != null)
+                    if (b != null && transport != null) {
                         if (monitor != null) monitor.hostData(b);
-
-                    transport.write(b);
+                        transport.write(b);
+                    }    
                 }
                 catch (IOException e) {
                     Log.e(TAG, "Problem writing outgoing data in vt320() thread", e);
@@ -226,10 +226,10 @@
             @Override
             public void write(int b) {
                 try {
-                    if (transport != null)
+                    if (transport != null) {
                         if (monitor != null) monitor.hostData(b);
-
-                    transport.write(b);
+                        transport.write(b);
+                    }    
                 }
                 catch (IOException e) {
                     Log.e(TAG, "Problem writing outgoing data in vt320() thread", e);
--- a/src/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Thu May 22 10:46:17 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Thu May 29 12:40:27 2014 -0700
@@ -16,6 +16,9 @@
 import java.net.Socket;
 import java.nio.charset.Charset;
 import java.util.HashMap;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
 
 public class TerminalMonitor {
     public final static String TAG = "ConnectBot.TerminalMonitor";
@@ -50,6 +53,7 @@
     private InputStream         monitor_in     = null;
     private OutputStream        monitor_out    = null;
     private MyReader            monitor_reader = null;
+    private BlockingQueue<char[]> pending_commands = new ArrayBlockingQueue<char[]>(100);
     private MyServiceConnection monitor_connection = new MyServiceConnection();
 
     class MyReader extends Thread {
@@ -141,6 +145,12 @@
                 monitor_reader.start();
                 String x = "  " + init;
                 monitorWrite(MONITOR_CMD_INIT, x.toCharArray());
+                char [] c;
+                while (true) {
+                    c = pending_commands.poll();
+                    if (c == null) break;
+                    monitorWrite(c[1], c);
+                }
             }
             catch (IOException e) {
                 Log.e(TAG, "exception in onServiceConnected()", e);
@@ -260,6 +270,13 @@
                 //Log.i(TAG, String.format("sending %d command", (int)cmd));
                 monitor_out.write(charsToBytes(c));
             }
+            else {
+                c[1] = cmd;
+                pending_commands.put(c);
+            }
+        }
+        catch (InterruptedException e) {
+            Log.e(TAG, "exception in monitorWrite()", e);
         }
         catch (IOException e) {
             Log.i(TAG, "exception in monitorWrite(), monitor died or closed the socket", e);
@@ -331,9 +348,11 @@
 
     public synchronized void setField(int l, int c, char[] data, int offset) {
         Log.i(TAG, "setField()");
-        byte[] d = charsToBytes(data);
-        byte[] b = new byte[d.length - offset];
-        System.arraycopy(d, offset, b, 0, d.length - offset);
+        byte[] b = new byte[data.length - offset];
+        int i;
+        for (i=0; i<b.length; i++) {
+            b[i] = (byte)(data[i+offset] & 0x00ff);
+        }
         buffer.write(b);
     }