diff options
author | Kenny Root <kenny@the-b.org> | 2013-04-11 21:01:32 -0700 |
---|---|---|
committer | Kenny Root <kenny@the-b.org> | 2013-04-11 21:01:32 -0700 |
commit | d8e49ec3f297f9ba0991762eb2cddbc00ed634d2 (patch) | |
tree | aac59c707c980e90202241c7a9c306ab9d278a1c /src/com/trilead/ssh2/channel/LocalAcceptThread.java | |
parent | 847af5046fb7d2dbcc668cecf81f1726b7c48bd9 (diff) | |
download | connectbot-d8e49ec3f297f9ba0991762eb2cddbc00ed634d2.tar.gz connectbot-d8e49ec3f297f9ba0991762eb2cddbc00ed634d2.tar.bz2 connectbot-d8e49ec3f297f9ba0991762eb2cddbc00ed634d2.zip |
Fix line endings
Diffstat (limited to 'src/com/trilead/ssh2/channel/LocalAcceptThread.java')
-rw-r--r-- | src/com/trilead/ssh2/channel/LocalAcceptThread.java | 270 |
1 files changed, 135 insertions, 135 deletions
diff --git a/src/com/trilead/ssh2/channel/LocalAcceptThread.java b/src/com/trilead/ssh2/channel/LocalAcceptThread.java index 885b41f..0d1bb35 100644 --- a/src/com/trilead/ssh2/channel/LocalAcceptThread.java +++ b/src/com/trilead/ssh2/channel/LocalAcceptThread.java @@ -1,135 +1,135 @@ -
-package com.trilead.ssh2.channel;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-
-/**
- * LocalAcceptThread.
- *
- * @author Christian Plattner, plattner@trilead.com
- * @version $Id: LocalAcceptThread.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
- */
-public class LocalAcceptThread extends Thread implements IChannelWorkerThread
-{
- ChannelManager cm;
- String host_to_connect;
- int port_to_connect;
-
- 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, 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 void run()
- {
- try
- {
- cm.registerThread(this);
- }
- 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());
-
- }
- catch (IOException e)
- {
- /* Simply close the local socket and wait for the next incoming connection */
-
- try
- {
- s.close();
- }
- catch (IOException ignore)
- {
- }
-
- continue;
- }
-
- try
- {
- r2l = new StreamForwarder(cn, null, s, 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, "Weird error during creation of StreamForwarder (" + e.getMessage() + ")",
- true);
- }
- catch (IOException ignore)
- {
- }
-
- continue;
- }
-
- 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 e)
- {
- }
- }
-}
+ +package com.trilead.ssh2.channel; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * LocalAcceptThread. + * + * @author Christian Plattner, plattner@trilead.com + * @version $Id: LocalAcceptThread.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $ + */ +public class LocalAcceptThread extends Thread implements IChannelWorkerThread +{ + ChannelManager cm; + String host_to_connect; + int port_to_connect; + + 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, 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 void run() + { + try + { + cm.registerThread(this); + } + 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()); + + } + catch (IOException e) + { + /* Simply close the local socket and wait for the next incoming connection */ + + try + { + s.close(); + } + catch (IOException ignore) + { + } + + continue; + } + + try + { + r2l = new StreamForwarder(cn, null, s, 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, "Weird error during creation of StreamForwarder (" + e.getMessage() + ")", + true); + } + catch (IOException ignore) + { + } + + continue; + } + + 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 e) + { + } + } +} |