Mercurial > 510Connectbot
comparison src/ch/ethz/ssh2/channel/LocalAcceptThread.java @ 307:071eccdff8ea ganymed
fix java formatting
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 30 Jul 2014 14:16:58 -0700 |
parents | 91a31873c42a |
children |
comparison
equal
deleted
inserted
replaced
305:d2b303406d63 | 307:071eccdff8ea |
---|---|
9 import java.net.ServerSocket; | 9 import java.net.ServerSocket; |
10 import java.net.Socket; | 10 import java.net.Socket; |
11 | 11 |
12 /** | 12 /** |
13 * LocalAcceptThread. | 13 * LocalAcceptThread. |
14 * | 14 * |
15 * @author Christian Plattner | 15 * @author Christian Plattner |
16 * @version 2.50, 03/15/10 | 16 * @version 2.50, 03/15/10 |
17 */ | 17 */ |
18 public class LocalAcceptThread extends Thread implements IChannelWorkerThread | 18 public class LocalAcceptThread extends Thread implements IChannelWorkerThread { |
19 { | 19 ChannelManager cm; |
20 ChannelManager cm; | 20 String host_to_connect; |
21 String host_to_connect; | 21 int port_to_connect; |
22 int port_to_connect; | |
23 | 22 |
24 final ServerSocket ss; | 23 final ServerSocket ss; |
25 | 24 |
26 public LocalAcceptThread(ChannelManager cm, int local_port, String host_to_connect, int port_to_connect) | 25 public LocalAcceptThread(ChannelManager cm, int local_port, String host_to_connect, int port_to_connect) |
27 throws IOException | 26 throws IOException { |
28 { | 27 this.cm = cm; |
29 this.cm = cm; | 28 this.host_to_connect = host_to_connect; |
30 this.host_to_connect = host_to_connect; | 29 this.port_to_connect = port_to_connect; |
31 this.port_to_connect = port_to_connect; | 30 ss = new ServerSocket(local_port); |
31 } | |
32 | 32 |
33 ss = new ServerSocket(local_port); | 33 public LocalAcceptThread(ChannelManager cm, InetSocketAddress localAddress, String host_to_connect, |
34 } | 34 int port_to_connect) throws IOException { |
35 this.cm = cm; | |
36 this.host_to_connect = host_to_connect; | |
37 this.port_to_connect = port_to_connect; | |
38 ss = new ServerSocket(); | |
39 ss.bind(localAddress); | |
40 } | |
35 | 41 |
36 public LocalAcceptThread(ChannelManager cm, InetSocketAddress localAddress, String host_to_connect, | 42 public ServerSocket getServerSocket() { |
37 int port_to_connect) throws IOException | 43 return ss; |
38 { | 44 } |
39 this.cm = cm; | |
40 this.host_to_connect = host_to_connect; | |
41 this.port_to_connect = port_to_connect; | |
42 | 45 |
43 ss = new ServerSocket(); | 46 @Override |
44 ss.bind(localAddress); | 47 public void run() { |
45 } | 48 try { |
49 cm.registerThread(this); | |
50 } | |
51 catch (IOException e) { | |
52 stopWorking(); | |
53 return; | |
54 } | |
46 | 55 |
47 public ServerSocket getServerSocket() | 56 while (true) { |
48 { | 57 Socket s = null; |
49 return ss; | |
50 } | |
51 | |
52 @Override | |
53 public void run() | |
54 { | |
55 try | |
56 { | |
57 cm.registerThread(this); | |
58 } | |
59 catch (IOException e) | |
60 { | |
61 stopWorking(); | |
62 return; | |
63 } | |
64 | 58 |
65 while (true) | 59 try { |
66 { | 60 s = ss.accept(); |
67 Socket s = null; | 61 } |
62 catch (IOException e) { | |
63 stopWorking(); | |
64 return; | |
65 } | |
68 | 66 |
69 try | 67 Channel cn = null; |
70 { | 68 StreamForwarder r2l = null; |
71 s = ss.accept(); | 69 StreamForwarder l2r = null; |
72 } | |
73 catch (IOException e) | |
74 { | |
75 stopWorking(); | |
76 return; | |
77 } | |
78 | 70 |
79 Channel cn = null; | 71 try { |
80 StreamForwarder r2l = null; | 72 /* This may fail, e.g., if the remote port is closed (in optimistic terms: not open yet) */ |
81 StreamForwarder l2r = null; | 73 cn = cm.openDirectTCPIPChannel(host_to_connect, port_to_connect, s.getInetAddress().getHostAddress(), s |
74 .getPort()); | |
75 } | |
76 catch (IOException e) { | |
77 /* Simply close the local socket and wait for the next incoming connection */ | |
78 try { | |
79 s.close(); | |
80 } | |
81 catch (IOException ignore) { | |
82 } | |
82 | 83 |
83 try | 84 continue; |
84 { | 85 } |
85 /* This may fail, e.g., if the remote port is closed (in optimistic terms: not open yet) */ | |
86 | 86 |
87 cn = cm.openDirectTCPIPChannel(host_to_connect, port_to_connect, s.getInetAddress().getHostAddress(), s | 87 try { |
88 .getPort()); | 88 r2l = new StreamForwarder(cn, null, null, cn.stdoutStream, s.getOutputStream(), "RemoteToLocal"); |
89 l2r = new StreamForwarder(cn, r2l, s, s.getInputStream(), cn.stdinStream, "LocalToRemote"); | |
90 } | |
91 catch (IOException e) { | |
92 try { | |
93 /* This message is only visible during debugging, since we discard the channel immediatelly */ | |
94 cn.cm.closeChannel(cn, e, true); | |
95 } | |
96 catch (IOException ignore) { | |
97 } | |
89 | 98 |
90 } | 99 continue; |
91 catch (IOException e) | 100 } |
92 { | |
93 /* Simply close the local socket and wait for the next incoming connection */ | |
94 | 101 |
95 try | 102 r2l.setDaemon(true); |
96 { | 103 l2r.setDaemon(true); |
97 s.close(); | 104 r2l.start(); |
98 } | 105 l2r.start(); |
99 catch (IOException ignore) | 106 } |
100 { | 107 } |
101 } | |
102 | 108 |
103 continue; | 109 public void stopWorking() { |
104 } | 110 try { |
105 | 111 /* This will lead to an IOException in the ss.accept() call */ |
106 try | 112 ss.close(); |
107 { | 113 } |
108 r2l = new StreamForwarder(cn, null, null, cn.stdoutStream, s.getOutputStream(), "RemoteToLocal"); | 114 catch (IOException ignored) { |
109 l2r = new StreamForwarder(cn, r2l, s, s.getInputStream(), cn.stdinStream, "LocalToRemote"); | 115 } |
110 } | 116 } |
111 catch (IOException e) | |
112 { | |
113 try | |
114 { | |
115 /* This message is only visible during debugging, since we discard the channel immediatelly */ | |
116 cn.cm.closeChannel(cn, e, true); | |
117 } | |
118 catch (IOException ignore) | |
119 { | |
120 } | |
121 | |
122 continue; | |
123 } | |
124 | |
125 r2l.setDaemon(true); | |
126 l2r.setDaemon(true); | |
127 r2l.start(); | |
128 l2r.start(); | |
129 } | |
130 } | |
131 | |
132 public void stopWorking() | |
133 { | |
134 try | |
135 { | |
136 /* This will lead to an IOException in the ss.accept() call */ | |
137 ss.close(); | |
138 } | |
139 catch (IOException ignored) | |
140 { | |
141 } | |
142 } | |
143 } | 117 } |