comparison src/com/five_ten_sg/connectbot/service/TerminalMonitor.java @ 417:4dcc071e1feb

monitor failure should not kill the TE
author Carl Byington <carl@five-ten-sg.com>
date Wed, 29 Oct 2014 12:12:48 -0700
parents 057854c77217
children 39533be5cbe9
comparison
equal deleted inserted replaced
416:07c1da90deab 417:4dcc071e1feb
179 try { 179 try {
180 Thread.sleep(100); 180 Thread.sleep(100);
181 monitor_socket = new Socket(serverAddr, MONITORPORT); 181 monitor_socket = new Socket(serverAddr, MONITORPORT);
182 } 182 }
183 catch (Exception e) { 183 catch (Exception e) {
184 monitor_socket = null;
184 Log.e(TAG, "exception connecting to monitor socket", e); 185 Log.e(TAG, "exception connecting to monitor socket", e);
185 tries = tries + 1; 186 tries = tries + 1;
186 } 187 }
187 } 188 }
188 Log.i(TAG, "connected to monitor socket, send init " + init); 189 if (monitor_socket != null) {
189 monitor_in = monitor_socket.getInputStream(); 190 Log.i(TAG, "connected to monitor socket, send init " + init);
190 monitor_out = monitor_socket.getOutputStream(); 191 monitor_in = monitor_socket.getInputStream();
191 monitor_reader = new MyReader(monitor_in); 192 monitor_out = monitor_socket.getOutputStream();
192 monitor_reader.start(); 193 monitor_reader = new MyReader(monitor_in);
193 String x = " " + init; 194 monitor_reader.start();
194 monitorWrite(MONITOR_CMD_INIT, x.toCharArray()); 195 String x = " " + init;
195 char [] c; 196 monitorWrite(MONITOR_CMD_INIT, x.toCharArray());
196 197 char [] c;
197 while (true) { 198
198 c = pending_commands.poll(); 199 while (true) {
199 200 c = pending_commands.poll();
200 if (c == null) break; 201
201 202 if (c == null) break;
202 monitorWrite(c[1], c); 203
204 monitorWrite(c[1], c);
205 }
203 } 206 }
204 } 207 }
205 catch (IOException e) { 208 catch (IOException e) {
206 Log.e(TAG, "exception in onServiceConnected()", e); 209 Log.e(TAG, "exception in onServiceConnected()", e);
207 } 210 }
329 //Log.i(TAG, String.format("sending %d command", (int)cmd)); 332 //Log.i(TAG, String.format("sending %d command", (int)cmd));
330 monitor_out.write(charsToBytes(c)); 333 monitor_out.write(charsToBytes(c));
331 } 334 }
332 else { 335 else {
333 c[1] = cmd; 336 c[1] = cmd;
334 pending_commands.put(c); 337 pending_commands.offer(c);
335 } 338 }
336 } 339 }
337 catch (InterruptedException e) { 340 catch (InterruptedException e) {
338 Log.e(TAG, "exception in monitorWrite()", e); 341 Log.e(TAG, "exception in monitorWrite()", e);
339 } 342 }