comparison src/com/five_ten_sg/connectbot/service/TerminalMonitor.java @ 399:aeb8c2e6d83a

add queue to buffer monitor socket writes to prevent blocking on socket output stream write
author Carl Byington <carl@five-ten-sg.com>
date Wed, 15 Oct 2014 18:03:27 -0700
parents 2a416391ffc3
children e856ecf87b10
comparison
equal deleted inserted replaced
398:2a416391ffc3 399:aeb8c2e6d83a
93 //Log.i(TAG, String.format("sending %d command", (int)c[1])); 93 //Log.i(TAG, String.format("sending %d command", (int)c[1]));
94 monitor_out.write(charsToBytes(c)); 94 monitor_out.write(charsToBytes(c));
95 } 95 }
96 } 96 }
97 catch (InterruptedException e) { 97 catch (InterruptedException e) {
98 if (!is_closing) Log.e(TAG, "exception in monitorWrite()", e); 98 if (!is_closing) Log.e(TAG, "exception in MyWriter.run()", e);
99 } 99 }
100 catch (IOException e) { 100 catch (IOException e) {
101 Log.i(TAG, "exception in monitorWrite(), monitor died or closed the socket", e); 101 Log.i(TAG, "exception in MyWriter.run(), monitor died or closed the socket", e);
102 } 102 }
103 103
104 try { 104 try {
105 monitor_out.close(); 105 monitor_out.close();
106 } 106 }
107 catch (IOException ee) { 107 catch (IOException e) {
108 Log.e(TAG, "exception in monitorWrite() closing output stream", ee); 108 Log.e(TAG, "exception in MyWriter.run() closing output stream", e);
109 } 109 }
110 monitor_out = null; 110 monitor_out = null;
111 } 111 }
112 } 112 }
113 113
346 return b; 346 return b;
347 } 347 }
348 348
349 349
350 public void monitorWrite(char cmd, char[] c) { 350 public void monitorWrite(char cmd, char[] c) {
351 c[0] = (char)(c.length - 1); // number of chars following 351 try {
352 c[1] = cmd; 352 c[0] = (char)(c.length - 1); // number of chars following
353 pending_commands.put(c); 353 c[1] = cmd;
354 pending_commands.put(c);
355 }
356 catch (InterruptedException e) {
357 Log.e(TAG, "exception in monitorWrite()", e);
358 }
354 }; 359 };
355 360
356 public void resetWatch() { 361 public void resetWatch() {
357 start_line = 0; 362 start_line = 0;
358 end_line = 500; 363 end_line = 500;