Mercurial > 510Connectbot
comparison src/com/trilead/ssh2/channel/RemoteAcceptThread.java @ 0:0ce5cc452d02
initial version
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 22 May 2014 10:41:19 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:0ce5cc452d02 |
---|---|
1 | |
2 package com.trilead.ssh2.channel; | |
3 | |
4 import java.io.IOException; | |
5 import java.net.Socket; | |
6 | |
7 import com.trilead.ssh2.log.Logger; | |
8 | |
9 | |
10 /** | |
11 * RemoteAcceptThread. | |
12 * | |
13 * @author Christian Plattner, plattner@trilead.com | |
14 * @version $Id: RemoteAcceptThread.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $ | |
15 */ | |
16 public class RemoteAcceptThread extends Thread { | |
17 private static final Logger log = Logger.getLogger(RemoteAcceptThread.class); | |
18 | |
19 Channel c; | |
20 | |
21 String remoteConnectedAddress; | |
22 int remoteConnectedPort; | |
23 String remoteOriginatorAddress; | |
24 int remoteOriginatorPort; | |
25 String targetAddress; | |
26 int targetPort; | |
27 | |
28 Socket s; | |
29 | |
30 public RemoteAcceptThread(Channel c, String remoteConnectedAddress, int remoteConnectedPort, | |
31 String remoteOriginatorAddress, int remoteOriginatorPort, String targetAddress, int targetPort) { | |
32 this.c = c; | |
33 this.remoteConnectedAddress = remoteConnectedAddress; | |
34 this.remoteConnectedPort = remoteConnectedPort; | |
35 this.remoteOriginatorAddress = remoteOriginatorAddress; | |
36 this.remoteOriginatorPort = remoteOriginatorPort; | |
37 this.targetAddress = targetAddress; | |
38 this.targetPort = targetPort; | |
39 | |
40 if (log.isEnabled()) | |
41 log.log(20, "RemoteAcceptThread: " + remoteConnectedAddress + "/" + remoteConnectedPort + ", R: " | |
42 + remoteOriginatorAddress + "/" + remoteOriginatorPort); | |
43 } | |
44 | |
45 public void run() { | |
46 try { | |
47 c.cm.sendOpenConfirmation(c); | |
48 s = new Socket(targetAddress, targetPort); | |
49 StreamForwarder r2l = new StreamForwarder(c, null, s, c.getStdoutStream(), s.getOutputStream(), | |
50 "RemoteToLocal"); | |
51 StreamForwarder l2r = new StreamForwarder(c, null, null, s.getInputStream(), c.getStdinStream(), | |
52 "LocalToRemote"); | |
53 /* No need to start two threads, one can be executed in the current thread */ | |
54 r2l.setDaemon(true); | |
55 r2l.start(); | |
56 l2r.run(); | |
57 | |
58 while (r2l.isAlive()) { | |
59 try { | |
60 r2l.join(); | |
61 } | |
62 catch (InterruptedException e) { | |
63 } | |
64 } | |
65 | |
66 /* If the channel is already closed, then this is a no-op */ | |
67 c.cm.closeChannel(c, "EOF on both streams reached.", true); | |
68 s.close(); | |
69 } | |
70 catch (IOException e) { | |
71 log.log(50, "IOException in proxy code: " + e.getMessage()); | |
72 | |
73 try { | |
74 c.cm.closeChannel(c, "IOException in proxy code (" + e.getMessage() + ")", true); | |
75 } | |
76 catch (IOException e1) { | |
77 } | |
78 | |
79 try { | |
80 if (s != null) | |
81 s.close(); | |
82 } | |
83 catch (IOException e1) { | |
84 } | |
85 } | |
86 } | |
87 } |