comparison app/src/main/java/ch/ethz/ssh2/channel/RemoteAcceptThread.java @ 438:d29cce60f393

migrate from Eclipse to Android Studio
author Carl Byington <carl@five-ten-sg.com>
date Thu, 03 Dec 2015 11:23:55 -0800
parents src/ch/ethz/ssh2/channel/RemoteAcceptThread.java@071eccdff8ea
children
comparison
equal deleted inserted replaced
437:208b31032318 438:d29cce60f393
1 /*
2 * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 * Please refer to the LICENSE.txt for licensing details.
4 */
5 package ch.ethz.ssh2.channel;
6
7 import java.io.IOException;
8 import java.net.Socket;
9
10 import ch.ethz.ssh2.log.Logger;
11
12 /**
13 * RemoteAcceptThread.
14 *
15 * @author Christian Plattner
16 * @version $Id: RemoteAcceptThread.java 119 2014-04-12 20:30:58Z dkocher@sudo.ch $
17 */
18 public class RemoteAcceptThread extends Thread {
19 private static final Logger log = Logger.getLogger(RemoteAcceptThread.class);
20
21 Channel c;
22
23 String remoteConnectedAddress;
24 int remoteConnectedPort;
25 String remoteOriginatorAddress;
26 int remoteOriginatorPort;
27 String targetAddress;
28 int targetPort;
29
30 Socket s;
31
32 public RemoteAcceptThread(Channel c, String remoteConnectedAddress, int remoteConnectedPort,
33 String remoteOriginatorAddress, int remoteOriginatorPort, String targetAddress, int targetPort) {
34 this.c = c;
35 this.remoteConnectedAddress = remoteConnectedAddress;
36 this.remoteConnectedPort = remoteConnectedPort;
37 this.remoteOriginatorAddress = remoteOriginatorAddress;
38 this.remoteOriginatorPort = remoteOriginatorPort;
39 this.targetAddress = targetAddress;
40 this.targetPort = targetPort;
41 log.debug("RemoteAcceptThread: " + remoteConnectedAddress + "/" + remoteConnectedPort + ", R: "
42 + remoteOriginatorAddress + "/" + remoteOriginatorPort);
43 }
44
45 @Override
46 public void run() {
47 try {
48 c.cm.sendOpenConfirmation(c);
49 s = new Socket(targetAddress, targetPort);
50 StreamForwarder r2l = new StreamForwarder(c, null, null, c.getStdoutStream(), s.getOutputStream(),
51 "RemoteToLocal");
52 StreamForwarder l2r = new StreamForwarder(c, null, null, s.getInputStream(), c.getStdinStream(),
53 "LocalToRemote");
54 /* No need to start two threads, one can be executed in the current thread */
55 r2l.setDaemon(true);
56 r2l.start();
57 l2r.run();
58
59 while (r2l.isAlive()) {
60 try {
61 r2l.join();
62 }
63 catch (InterruptedException ignored) {
64 }
65 }
66
67 /* If the channel is already closed, then this is a no-op */
68 c.cm.closeChannel(c, "EOF on both streams reached.", true);
69 s.close();
70 }
71 catch (IOException e) {
72 log.warning("IOException in proxy code: " + e.getMessage());
73
74 try {
75 c.cm.closeChannel(c, e, true);
76 }
77 catch (IOException ignored) {
78 }
79
80 try {
81 if (s != null)
82 s.close();
83 }
84 catch (IOException ignored) {
85 }
86 }
87 }
88 }