- private static final int buffer_size = 1024;
-
- private byte[] buffer = new byte[buffer_size];
- private int buffer_len = 0;
- private int buffer_off = 0;
-
- public int getchar() {
- while (buffer_off == buffer_len) {
- try {
- wait_connected();
- buffer_len = input.read(buffer);
- buffer_off = 0;
- } catch (IOException e) {
- if (D) Log.d(TAG, "getchar IOException");
- disconnected();
- return AltosLink.ERROR;
- } catch (java.lang.InterruptedException e) {
- if (D) Log.d(TAG, "getchar Interrupted");
- disconnected();
- return AltosLink.ERROR;
- }
- }
- return buffer[buffer_off++];
- }
-
- public void closing() {
- synchronized(closing_lock) {
- if (D) Log.d(TAG, "Marked closing true");
- closing = true;
- }
- }
-
-
- public void close() {
- if (D) Log.d(TAG, "close(): begin");
-
- closing();
-
- synchronized(this) {
- if (D) Log.d(TAG, "close(): synched");
-
- if (socket != null) {
- if (D) Log.d(TAG, "close(): Closing socket");
- try {
- socket.close();
- } catch (IOException e) {
- if (D) Log.e(TAG, "close(): unable to close() socket");
- }
- socket = null;
- }
- connect_thread = null;
- if (input_thread != null) {
- if (D) Log.d(TAG, "close(): stopping input_thread");
- try {
- if (D) Log.d(TAG, "close(): input_thread.interrupt().....");
- input_thread.interrupt();
- if (D) Log.d(TAG, "close(): input_thread.join().....");
- input_thread.join();
- } catch (Exception e) {}
- input_thread = null;
- }
- input = null;
- output = null;
- notifyAll();
- }
- }
-
-
- // We override this method so that we can add some debugging. Not 100% elegant, but more useful
- // than debugging one char at a time above in getchar()!
- public void add_reply(AltosLine line) throws InterruptedException {
- if (D) Log.d(TAG, String.format("Got REPLY: %s", line.line));
- super.add_reply(line);
- }
-
- //public void flush_output() { super.flush_output(); }
-