diff options
author | Kenny Root <kenny@the-b.org> | 2009-06-15 16:35:59 +0000 |
---|---|---|
committer | Kenny Root <kenny@the-b.org> | 2009-06-15 16:35:59 +0000 |
commit | 534184380cd7762bc1be3c5174af001e33f9b08d (patch) | |
tree | e0644be305ec82ce9ec51f66333deaec3a96070f /src/org/connectbot/service/Relay.java | |
parent | 2adc14e72659787a09aa4b9b40334dc0e1df9194 (diff) | |
download | connectbot-534184380cd7762bc1be3c5174af001e33f9b08d.tar.gz connectbot-534184380cd7762bc1be3c5174af001e33f9b08d.tar.bz2 connectbot-534184380cd7762bc1be3c5174af001e33f9b08d.zip |
Add multiple transports
git-svn-id: https://connectbot.googlecode.com/svn/trunk/connectbot@298 df292f66-193f-0410-a5fc-6d59da041ff2
Diffstat (limited to 'src/org/connectbot/service/Relay.java')
-rw-r--r-- | src/org/connectbot/service/Relay.java | 72 |
1 files changed, 16 insertions, 56 deletions
diff --git a/src/org/connectbot/service/Relay.java b/src/org/connectbot/service/Relay.java index 5b9fe3f..8ac4efc 100644 --- a/src/org/connectbot/service/Relay.java +++ b/src/org/connectbot/service/Relay.java @@ -21,18 +21,15 @@ package org.connectbot.service; import gnu.java.nio.charset.Cp437; import java.io.IOException; -import java.io.InputStream; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CodingErrorAction; -import android.util.Log; - -import com.trilead.ssh2.ChannelCondition; -import com.trilead.ssh2.Session; +import org.connectbot.transport.AbsTransport; +import android.util.Log; import de.mud.terminal.vt320; /** @@ -43,21 +40,12 @@ public class Relay implements Runnable { private static final int BUFFER_SIZE = 4096; - private static final int CONDITIONS = - ChannelCondition.STDOUT_DATA - | ChannelCondition.STDERR_DATA - | ChannelCondition.CLOSED - | ChannelCondition.EOF; - private TerminalBridge bridge; private Charset currentCharset; private CharsetDecoder decoder; - private Session session; - - private InputStream stdout; - private InputStream stderr; + private AbsTransport transport; private vt320 buffer; @@ -67,12 +55,10 @@ public class Relay implements Runnable { private byte[] byteArray; private char[] charArray; - public Relay(TerminalBridge bridge, Session session, InputStream stdout, InputStream stderr, vt320 buffer, String encoding) { + public Relay(TerminalBridge bridge, AbsTransport transport, vt320 buffer, String encoding) { setCharset(encoding); this.bridge = bridge; - this.session = session; - this.stdout = stdout; - this.stderr = stderr; + this.transport = transport; this.buffer = buffer; } @@ -104,47 +90,21 @@ public class Relay implements Runnable { int bytesRead = 0; - int newConditions = 0; - - while((newConditions & ChannelCondition.CLOSED) == 0) { - try { - newConditions = session.waitForCondition(CONDITIONS, 0); - if ((newConditions & ChannelCondition.STDOUT_DATA) != 0) { - while (stdout.available() > 0) { - bytesRead = stdout.read(byteArray, 0, BUFFER_SIZE); - - byteBuffer.position(0); - byteBuffer.limit(bytesRead); - decoder.decode(byteBuffer, charBuffer, false); - buffer.putString(charArray, 0, charBuffer.position()); - charBuffer.clear(); - } + try { + while (true) { + bytesRead = transport.read(byteArray, 0, BUFFER_SIZE); + if (bytesRead > 0) { + byteBuffer.position(0); + byteBuffer.limit(bytesRead); + decoder.decode(byteBuffer, charBuffer, false); + buffer.putString(charArray, 0, charBuffer.position()); + charBuffer.clear(); bridge.redraw(); } - - if ((newConditions & ChannelCondition.STDERR_DATA) != 0) - logAndDiscard(stderr); - - if ((newConditions & ChannelCondition.EOF) != 0) { - // The other side closed our channel, so let's disconnect. - // TODO review whether any tunnel is in use currently. - bridge.dispatchDisconnect(false); - break; - } - } catch (IOException e) { - Log.e(TAG, "Problem while handling incoming data in relay thread", e); - break; } - } - - } - - private void logAndDiscard(InputStream stream) throws IOException { - int bytesAvail; - while ((bytesAvail = stream.available()) > 0) { - stream.skip(bytesAvail); - Log.d(TAG, String.format("Discarded %d bytes from stderr", bytesAvail)); + } catch (IOException e) { + Log.e(TAG, "Problem while handling incoming data in relay thread", e); } } } |