Mercurial > 510Connectbot
diff src/ch/ethz/ssh2/channel/LocalAcceptThread.java @ 308:42b15aaa7ac7 ganymed
merge
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 30 Jul 2014 14:21:50 -0700 |
parents | 071eccdff8ea |
children |
line wrap: on
line diff
--- a/src/ch/ethz/ssh2/channel/LocalAcceptThread.java Wed Jul 30 13:38:04 2014 -0700 +++ b/src/ch/ethz/ssh2/channel/LocalAcceptThread.java Wed Jul 30 14:21:50 2014 -0700 @@ -11,133 +11,107 @@ /** * LocalAcceptThread. - * + * * @author Christian Plattner * @version 2.50, 03/15/10 */ -public class LocalAcceptThread extends Thread implements IChannelWorkerThread -{ - ChannelManager cm; - String host_to_connect; - int port_to_connect; +public class LocalAcceptThread extends Thread implements IChannelWorkerThread { + ChannelManager cm; + String host_to_connect; + int port_to_connect; - final ServerSocket ss; + final ServerSocket ss; - public LocalAcceptThread(ChannelManager cm, int local_port, String host_to_connect, int port_to_connect) - throws IOException - { - this.cm = cm; - this.host_to_connect = host_to_connect; - this.port_to_connect = port_to_connect; - - ss = new ServerSocket(local_port); - } + public LocalAcceptThread(ChannelManager cm, int local_port, String host_to_connect, int port_to_connect) + throws IOException { + this.cm = cm; + this.host_to_connect = host_to_connect; + this.port_to_connect = port_to_connect; + ss = new ServerSocket(local_port); + } - public LocalAcceptThread(ChannelManager cm, InetSocketAddress localAddress, String host_to_connect, - int port_to_connect) throws IOException - { - this.cm = cm; - this.host_to_connect = host_to_connect; - this.port_to_connect = port_to_connect; - - ss = new ServerSocket(); - ss.bind(localAddress); - } + public LocalAcceptThread(ChannelManager cm, InetSocketAddress localAddress, String host_to_connect, + int port_to_connect) throws IOException { + this.cm = cm; + this.host_to_connect = host_to_connect; + this.port_to_connect = port_to_connect; + ss = new ServerSocket(); + ss.bind(localAddress); + } - public ServerSocket getServerSocket() - { - return ss; - } - - @Override - public void run() - { - try - { - cm.registerThread(this); - } - catch (IOException e) - { - stopWorking(); - return; - } + public ServerSocket getServerSocket() { + return ss; + } - while (true) - { - Socket s = null; + @Override + public void run() { + try { + cm.registerThread(this); + } + catch (IOException e) { + stopWorking(); + return; + } - try - { - s = ss.accept(); - } - catch (IOException e) - { - stopWorking(); - return; - } + while (true) { + Socket s = null; + + try { + s = ss.accept(); + } + catch (IOException e) { + stopWorking(); + return; + } - Channel cn = null; - StreamForwarder r2l = null; - StreamForwarder l2r = null; - - try - { - /* This may fail, e.g., if the remote port is closed (in optimistic terms: not open yet) */ - - cn = cm.openDirectTCPIPChannel(host_to_connect, port_to_connect, s.getInetAddress().getHostAddress(), s - .getPort()); + Channel cn = null; + StreamForwarder r2l = null; + StreamForwarder l2r = null; - } - catch (IOException e) - { - /* Simply close the local socket and wait for the next incoming connection */ + try { + /* This may fail, e.g., if the remote port is closed (in optimistic terms: not open yet) */ + cn = cm.openDirectTCPIPChannel(host_to_connect, port_to_connect, s.getInetAddress().getHostAddress(), s + .getPort()); + } + catch (IOException e) { + /* Simply close the local socket and wait for the next incoming connection */ + try { + s.close(); + } + catch (IOException ignore) { + } - try - { - s.close(); - } - catch (IOException ignore) - { - } - - continue; - } + continue; + } - try - { - r2l = new StreamForwarder(cn, null, null, cn.stdoutStream, s.getOutputStream(), "RemoteToLocal"); - l2r = new StreamForwarder(cn, r2l, s, s.getInputStream(), cn.stdinStream, "LocalToRemote"); - } - catch (IOException e) - { - try - { - /* This message is only visible during debugging, since we discard the channel immediatelly */ - cn.cm.closeChannel(cn, e, true); - } - catch (IOException ignore) - { - } + try { + r2l = new StreamForwarder(cn, null, null, cn.stdoutStream, s.getOutputStream(), "RemoteToLocal"); + l2r = new StreamForwarder(cn, r2l, s, s.getInputStream(), cn.stdinStream, "LocalToRemote"); + } + catch (IOException e) { + try { + /* This message is only visible during debugging, since we discard the channel immediatelly */ + cn.cm.closeChannel(cn, e, true); + } + catch (IOException ignore) { + } - continue; - } + continue; + } - r2l.setDaemon(true); - l2r.setDaemon(true); - r2l.start(); - l2r.start(); - } - } + r2l.setDaemon(true); + l2r.setDaemon(true); + r2l.start(); + l2r.start(); + } + } - public void stopWorking() - { - try - { - /* This will lead to an IOException in the ss.accept() call */ - ss.close(); - } - catch (IOException ignored) - { - } - } + public void stopWorking() { + try { + /* This will lead to an IOException in the ss.accept() call */ + ss.close(); + } + catch (IOException ignored) { + } + } }