1 /*
2  * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 package nsk.share.jpda;
25 
26 import nsk.share.*;
27 
28 /**
29  * This class implements communicational channel between
30  * debugger and debugee used for synchronization and data exchange.
31  * This channel is based on TCP/IP sockets and works in all
32  * modes (local, remote and manual). In a remote mode
33  * connection to <code>BindServer</code> is used for redirecting IOPipe messages.
34  * In all other modes direct TCP/IP coonnection between two VMs is used.
35  *
36  * @see BindServer
37  */
38 public class IOPipe extends SocketIOPipe {
39 
40     public static final byte PORTS_COUNT = 10;
41     public static final byte NO_PORTS = 0;
42 
43     public static final String PIPE_LOG_PREFIX = "IOPipe> ";
44 
45     private DebugeeProcess debugee;
46 
47     /**
48       * Make <code>IOPipe</code> at debugee's side.
49       *
50       * @deprecated Use DebugeeArgumentHandler.createDebugeeIOPipe(Log) instead.
51       *
52       * @see DebugeeArgumentHandler#createDebugeeIOPipe(Log)
53       */
IOPipe(DebugeeArgumentHandler argumentHandler, Log log)54     public IOPipe(DebugeeArgumentHandler argumentHandler, Log log) {
55         this(log, getTestHost(argumentHandler), argumentHandler.getPipePortNumber(),
56                 (long)argumentHandler.getWaitTime() * 60 * 1000, false);
57     }
58 
59     /**
60       * Make <code>IOPipe</code> at debugger's side
61       * with given <code>Debugee</code> mirror.
62       *
63       * @deprecated Use Debugee.createIOPipe() instead.
64       */
IOPipe(DebugeeProcess debugee)65     public IOPipe(DebugeeProcess debugee) {
66         this(debugee.getLog(),
67                 debugee.getArgumentHandler().getDebugeeHost(),
68                 debugee.getArgumentHandler().getPipePortNumber(),
69                 (long)debugee.getArgumentHandler().getWaitTime() * 60 * 1000,
70                 true);
71 
72         this.debugee = debugee;
73     }
74 
75     /**
76       * Make general <code>IOPipe</code> object with specified parameters.
77       */
IOPipe(Log log, String host, int port, long timeout, boolean listening)78     protected IOPipe(Log log, String host, int port, long timeout, boolean listening) {
79         super("IOPipe", log, PIPE_LOG_PREFIX, host, port, timeout, listening);
80     }
81 
connect()82     protected void connect() {
83         if (listening) {
84             setServerSocket(debugee.getPipeServerSocket());
85             setConnectingProcess(debugee.getProcess());
86         }
87 
88         super.connect();
89     }
90 
91     /**
92      * Get appropriate test host name relying on the provided argumnets.
93      */
getTestHost(DebugeeArgumentHandler argumentHandler)94     private static String getTestHost(DebugeeArgumentHandler argumentHandler) {
95         return argumentHandler.getTestHost();
96     }
97 
98 } // IOPipe
99