/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* A transport service based on a TCP connection between the
* debugger and debugee.
*/
/**
* The listener returned by startListening encapsulates
* the ServerSocket.
*/
}
return ss;
}
/*
* Returns the string representation of the address that this
* listen key represents.
*/
/*
* If bound to the wildcard address then use current local
* hostname. In the event that we don't know our own hostname
* then assume that host supports IPv4 and return something to
* represent the loopback address.
*/
if (address.isAnyLocalAddress()) {
try {
} catch (UnknownHostException uhe) {
try {
} catch (UnknownHostException x) {
throw new InternalError("unable to get local hostname");
}
}
}
/*
* Now decide if we return a hostname or IP address. Where possible
* return a hostname but in the case that we are bound to an
* address that isn't registered in the name service then we
* return an address.
*/
if (address instanceof Inet6Address) {
} else {
}
} else {
}
/*
* Finally return "hostname:port", "ipv4-address:port" or
* "[ipv6-address]:port".
*/
}
return address();
}
}
/**
* Handshake with the debuggee
*/
s.setSoTimeout((int)timeout);
int received = 0;
int n;
try {
} catch (SocketTimeoutException x) {
throw new IOException("handshake timeout");
}
if (n < 0) {
s.close();
throw new IOException("handshake failed - connection prematurally closed");
}
received += n;
}
if (b[i] != hello[i]) {
throw new IOException("handshake failed - unrecognized message from target VM");
}
}
// disable read timeout
s.setSoTimeout(0);
}
/**
* No-arg constructor
*/
public SocketTransportService() {
}
/**
* The name of this transport service
*/
return "Socket";
}
/**
* Return localized description of this transport service
*/
synchronized (this) {
}
}
}
/**
* Return the capabilities of this transport service
*/
return new SocketTransportServiceCapabilities();
}
/**
* Attach to the specified address with optional attach and handshake
* timeout.
*/
throws IOException {
throw new NullPointerException("address is null");
}
throw new IllegalArgumentException("timeout is negative");
}
if (splitIndex < 0) {
} else {
}
int port;
try {
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
"unable to parse port number in address");
}
// open TCP connection to VM
try {
} catch (SocketTimeoutException exc) {
try {
s.close();
} catch (IOException x) { }
throw new TransportTimeoutException("timed out trying to establish connection");
}
// handshake with the target VM
try {
} catch (IOException exc) {
try {
s.close();
} catch (IOException x) { }
throw exc;
}
return new SocketConnection(s);
}
/*
* Listen on the specified address and port. Return a listener
* that encapsulates the ServerSocket.
*/
if (localaddress == null) {
} else {
}
return new SocketListenKey(ss);
}
/**
* Listen on the specified address
*/
// use ephemeral port if address isn't specified.
address = "0";
}
if (splitIndex >= 0) {
}
int port;
try {
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
"unable to parse port number in address");
}
}
/**
* Listen on the default address
*/
}
/**
* Stop the listener
*/
if (!(listener instanceof SocketListenKey)) {
throw new IllegalArgumentException("Invalid listener");
}
synchronized (listener) {
// if the ServerSocket has been closed it means
// the listener is invalid
throw new IllegalArgumentException("Invalid listener");
}
}
}
/**
* Accept a connection from a debuggee and handshake with it.
*/
public Connection accept(ListenKey listener, long acceptTimeout, long handshakeTimeout) throws IOException {
throw new IllegalArgumentException("timeout is negative");
}
if (!(listener instanceof SocketListenKey)) {
throw new IllegalArgumentException("Invalid listener");
}
// obtain the ServerSocket from the listener - if the
// socket is closed it means the listener is invalid
synchronized (listener) {
throw new IllegalArgumentException("Invalid listener");
}
}
// from here onwards it's possible that the ServerSocket
// may be closed by a call to stopListening - that's okay
// because the ServerSocket methods will throw an
// IOException indicating the socket is closed.
//
// Additionally, it's possible that another thread calls accept
// with a different accept timeout - that creates a same race
// condition between setting the timeout and calling accept.
// As it is such an unlikely scenario (requires both threads
// to be using the same listener we've chosen to ignore the issue).
Socket s;
try {
} catch (SocketTimeoutException x) {
throw new TransportTimeoutException("timeout waiting for connection");
}
// handshake here
return new SocketConnection(s);
}
return name();
}
}
/*
* The Connection returned by attach and accept is one of these
*/
private boolean closed = false;
socket.setTcpNoDelay(true);
}
synchronized (closeLock) {
if (closed) {
return;
}
socketInput.close();
closed = true;
}
}
public boolean isOpen() {
synchronized (closeLock) {
return !closed;
}
}
if (!isOpen()) {
throw new ClosedConnectionException("connection is closed");
}
synchronized (receiveLock) {
// length
try {
} catch (IOException ioe) {
if (!isOpen()) {
throw new ClosedConnectionException("connection is closed");
} else {
throw ioe;
}
}
// EOF
if (b1<0) {
return new byte[0];
}
throw new IOException("protocol error - premature EOF");
}
if (len < 0) {
throw new IOException("protocol error - invalid length");
}
byte b[] = new byte[len];
b[0] = (byte)b1;
b[1] = (byte)b2;
b[2] = (byte)b3;
b[3] = (byte)b4;
int off = 4;
while (len > 0) {
int count;
try {
} catch (IOException ioe) {
if (!isOpen()) {
throw new ClosedConnectionException("connection is closed");
} else {
throw ioe;
}
}
if (count < 0) {
throw new IOException("protocol error - premature EOF");
}
}
return b;
}
}
if (!isOpen()) {
throw new ClosedConnectionException("connection is closed");
}
/*
* Check the packet size
*/
if (b.length < 11) {
throw new IllegalArgumentException("packet is insufficient size");
}
if (len < 11) {
throw new IllegalArgumentException("packet is insufficient size");
}
/*
* Check that the byte array contains the complete packet
*/
throw new IllegalArgumentException("length mis-match");
}
synchronized (sendLock) {
try {
/*
* Send the packet (ignoring any bytes that follow
* the packet in the byte array).
*/
} catch (IOException ioe) {
if (!isOpen()) {
throw new ClosedConnectionException("connection is closed");
} else {
throw ioe;
}
}
}
}
}
/*
* The capabilities of the socket transport service
*/
public boolean supportsMultipleConnections() {
return true;
}
public boolean supportsAttachTimeout() {
return true;
}
public boolean supportsAcceptTimeout() {
return true;
}
public boolean supportsHandshakeTimeout() {
return true;
}
}