You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2006/11/28 18:49:31 UTC

svn commit: r480141 [16/38] - in /harmony/enhanced/jdktools/trunk/modules/jpda: ./ doc/ doc/images/ make/ src/ src/common/ src/common/other/ src/common/other/jpda/ src/common/other/jpda/jdwp/ src/common/other/jpda/jdwp/agent/ src/common/other/jpda/jdwp...

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/transport/dt_socket/SocketTransport.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/transport/dt_socket/SocketTransport.cpp?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/transport/dt_socket/SocketTransport.cpp (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/transport/dt_socket/SocketTransport.cpp Tue Nov 28 09:49:08 2006
@@ -0,0 +1,923 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Viacheslav G. Rybalov
+ * @version $Revision: 1.13 $
+ */
+// SocketTransport.cpp
+//
+
+/**
+ * This is implementation of JDWP Agent TCP/IP Socket transport.
+ * Main module.
+ */
+
+#include "SocketTransport_pd.h"
+
+/**
+ * This function sets into internalEnv struct message and status code of last transport error
+ */
+static void 
+SetLastTranError(jdwpTransportEnv* env, const char* messagePtr, int errorStatus)
+{
+    internalEnv* ienv = (internalEnv*)env->functions->reserved1;
+    if (ienv->lastError != 0) {
+        ienv->lastError->insertError(messagePtr, errorStatus);
+    } else {
+        ienv->lastError = new(ienv->alloc, ienv->free) LastTransportError(messagePtr, errorStatus, ienv->alloc, ienv->free);
+    }
+    return;
+} // SetLastTranError
+
+/**
+ * This function sets into internalEnv struct prefix message for last transport error
+ */
+static void 
+SetLastTranErrorMessagePrefix(jdwpTransportEnv* env, const char* messagePrefix)
+{
+    internalEnv* ienv = (internalEnv*)env->functions->reserved1;
+    if (ienv->lastError != 0) {
+        ienv->lastError->addErrorMessagePrefix(messagePrefix);
+    }
+    return;
+} // SetLastTranErrorMessagePrefix
+
+
+/**
+ * The timeout used for invocation of select function in SelectRead and SelectSend methods
+ */
+static const jint cycle = 1000; // wait cycle in milliseconds 
+
+/**
+ * This function is used to determine the read status of socket (in terms of select function).
+ * The function avoids absolutely blocking select
+ */
+static jdwpTransportError 
+SelectRead(jdwpTransportEnv* env, SOCKET sckt, jlong deadline = 0) {
+
+    jlong currentTimeout = cycle;
+    while ((deadline == 0) || ((currentTimeout = (deadline - GetTickCount())) > 0)) {
+        currentTimeout = currentTimeout < cycle ? currentTimeout : cycle;
+        TIMEVAL tv = {(long)(currentTimeout / 1000), (long)(currentTimeout % 1000)};
+        fd_set fdread;
+        FD_ZERO(&fdread);
+        FD_SET(sckt, &fdread);
+
+        int ret = select((int)sckt + 1, &fdread, NULL, NULL, &tv);
+        if (ret == SOCKET_ERROR) {
+            int err = GetLastErrorStatus();
+            // ignore signal interruption
+            if (err != SOCKET_ERROR_EINTR) {
+                SetLastTranError(env, "socket error", err);
+                return JDWPTRANSPORT_ERROR_IO_ERROR;
+            }
+        }
+        if ((ret > 0) && (FD_ISSET(sckt, &fdread))) {
+            return JDWPTRANSPORT_ERROR_NONE; //timeout is not occurred
+        }
+    }
+    SetLastTranError(env, "timeout occurred", 0);
+    return JDWPTRANSPORT_ERROR_TIMEOUT; //timeout occurred
+} // SelectRead
+
+/**
+ * This function is used to determine the send status of socket (in terms of select function).
+ * The function avoids absolutely blocking select
+ */
+static jdwpTransportError 
+SelectSend(jdwpTransportEnv* env, SOCKET sckt, jlong deadline = 0) {
+
+    jlong currentTimeout = cycle;
+    while ((deadline == 0) || ((currentTimeout = (deadline - GetTickCount())) > 0)) {
+        currentTimeout = currentTimeout < cycle ? currentTimeout : cycle;
+        TIMEVAL tv = {(long)(currentTimeout / 1000), (long)(currentTimeout % 1000)};
+        fd_set fdwrite;
+        FD_ZERO(&fdwrite);
+        FD_SET(sckt, &fdwrite);
+
+        int ret = select((int)sckt + 1, NULL, &fdwrite, NULL, &tv);
+        if (ret == SOCKET_ERROR) {
+            int err = GetLastErrorStatus();
+            // ignore signal interruption
+            if (err != SOCKET_ERROR_EINTR) {
+                SetLastTranError(env, "socket error", err);
+                return JDWPTRANSPORT_ERROR_IO_ERROR;
+            }
+        }
+        if ((ret > 0) && (FD_ISSET(sckt, &fdwrite))) {
+            return JDWPTRANSPORT_ERROR_NONE; //timeout is not occurred
+        }
+    }
+    SetLastTranError(env, "timeout occurred", 0);
+    return JDWPTRANSPORT_ERROR_TIMEOUT; //timeout occurred
+} // SelectRead
+
+/**
+ * This function sends data on a connected socket
+ */
+static jdwpTransportError
+SendData(jdwpTransportEnv* env, SOCKET sckt, const char* data, int dataLength, jlong deadline = 0)
+{
+    long left = dataLength;
+    long off = 0;
+    int ret;
+
+    while (left > 0) {
+        jdwpTransportError err = SelectSend(env, sckt, deadline);
+        if (err != JDWPTRANSPORT_ERROR_NONE) {
+            return err;
+        }
+        ret = send(sckt, (data + off), left, 0);
+        if (ret == SOCKET_ERROR) {
+            int err = GetLastErrorStatus();
+            // ignore signal interruption
+            if (err != SOCKET_ERROR_EINTR) {
+                SetLastTranError(env, "socket error", err);
+                return JDWPTRANSPORT_ERROR_IO_ERROR;
+            }
+        }
+        left -= ret;
+        off += ret;
+    } //while
+    return JDWPTRANSPORT_ERROR_NONE;
+} //SendData
+
+/**
+ * This function receives data from a connected socket
+ */
+static jdwpTransportError
+ReceiveData(jdwpTransportEnv* env, SOCKET sckt, char* buffer, int dataLength, jlong deadline = 0, int* readByte = 0)
+{
+    long left = dataLength;
+    long off = 0;
+    int ret;
+
+    if (readByte != 0) {
+        *readByte = 0;
+    }
+
+    while (left > 0) {
+        jdwpTransportError err = SelectRead(env, sckt, deadline);
+        if (err != JDWPTRANSPORT_ERROR_NONE) {
+            return err;
+        }
+        ret = recv(sckt, (buffer + off), left, 0);
+        if (ret == SOCKET_ERROR) {
+            int err = GetLastErrorStatus();
+            // ignore signal interruption
+            if (err != SOCKET_ERROR_EINTR) {
+                SetLastTranError(env, "data receiving failed", err);
+                return JDWPTRANSPORT_ERROR_IO_ERROR;
+            }
+        }
+        if (ret == 0) {
+            SetLastTranError(env, "premature EOF", 0);
+            return JDWPTRANSPORT_ERROR_IO_ERROR;
+        }
+        left -= ret;
+        off += ret;
+        if (readByte != 0) {
+            *readByte = off;
+        }
+    } //while
+    return JDWPTRANSPORT_ERROR_NONE;
+} // ReceiveData
+
+/**
+ * This function enable/disables socket blocking mode 
+ */
+static bool 
+SetSocketBlockingMode(jdwpTransportEnv* env, SOCKET sckt, bool isBlocked)
+{
+    unsigned long ul = isBlocked ? 0 : 1;
+    if (ioctlsocket(sckt, FIONBIO, &ul) == SOCKET_ERROR) {
+        SetLastTranError(env, "socket error", GetLastErrorStatus());
+        return false;
+    }
+    return true;
+} // SetSocketBlockingMode()
+
+/**
+ * This function performes handshake procedure
+ */
+static jdwpTransportError 
+CheckHandshaking(jdwpTransportEnv* env, SOCKET sckt, jlong handshakeTimeout)
+{
+    const char* handshakeString = "JDWP-Handshake";
+    char receivedString[14]; //length of "JDWP-Handshake"
+
+    jlong deadline = (handshakeTimeout == 0) ? 0 : (jlong)GetTickCount() + handshakeTimeout;
+
+    jdwpTransportError err;
+    err = SendData(env, sckt, handshakeString, (int)strlen(handshakeString), deadline);
+    if (err != JDWPTRANSPORT_ERROR_NONE) {
+        SetLastTranErrorMessagePrefix(env, "'JDWP-Handshake' sending error: ");
+        return err;
+    }
+
+    err = ReceiveData(env, sckt, receivedString, (int)strlen(handshakeString), deadline);
+    if (err != JDWPTRANSPORT_ERROR_NONE) {
+        SetLastTranErrorMessagePrefix(env, "'JDWP-Handshake' receiving error: ");
+        return err;
+    }
+
+    if (memcmp(receivedString, handshakeString, 14) != 0) {
+        SetLastTranError(env, "handshake error, 'JDWP-Handshake' is not received", 0);
+        return JDWPTRANSPORT_ERROR_IO_ERROR;
+    }
+
+    return JDWPTRANSPORT_ERROR_NONE;
+}// CheckHandshaking
+
+/**
+ * This function decodes address and populates sockaddr_in structure
+ */
+static jdwpTransportError
+DecodeAddress(jdwpTransportEnv* env, const char *address, struct sockaddr_in *sa, bool isServer) 
+{
+    memset(sa, 0, sizeof(struct sockaddr_in));
+    sa->sin_family = AF_INET;
+
+    if ((address == 0) || (*address == 0)) {  //empty address
+        sa->sin_addr.s_addr = isServer ? htonl(INADDR_ANY) : inet_addr("127.0.0.1");
+        sa->sin_port = 0;
+        return JDWPTRANSPORT_ERROR_NONE;
+    }
+
+    char* colon = strchr(address, ':');
+    if (colon == 0) {  //address is like "port"
+        sa->sin_port = htons((u_short)atoi(address));
+        sa->sin_addr.s_addr = isServer ? htonl(INADDR_ANY) : inet_addr("127.0.0.1");
+    } else { //address is like "host:port"
+        sa->sin_port = htons((u_short)atoi(colon + 1));
+
+        char *hostName = (char*)(((internalEnv*)env->functions->reserved1)
+            ->alloc)((jint)(colon - address + 1));
+        if (hostName == 0) {
+            SetLastTranError(env, "out of memory", 0);
+            return JDWPTRANSPORT_ERROR_OUT_OF_MEMORY;
+        }
+        memcpy(hostName, address, colon - address);
+        hostName[colon - address] = '\0';
+        sa->sin_addr.s_addr = inet_addr(hostName);
+        if (sa->sin_addr.s_addr == INADDR_NONE) {
+            struct hostent *host = gethostbyname(hostName);
+            if (host == 0) {
+                SetLastTranError(env, "unable to resolve host name", 0);
+                (((internalEnv*)env->functions->reserved1)->free)(hostName);
+                return JDWPTRANSPORT_ERROR_IO_ERROR;
+            }
+            memcpy(&(sa->sin_addr), host->h_addr_list[0], host->h_length);
+        } //if
+        (((internalEnv*)env->functions->reserved1)->free)(hostName);
+    } //if
+    return JDWPTRANSPORT_ERROR_NONE;
+} //DecodeAddress
+
+/**
+ * This function implements jdwpTransportEnv::GetCapabilities
+ */
+static jdwpTransportError JNICALL
+TCPIPSocketTran_GetCapabilities(jdwpTransportEnv* env, 
+        JDWPTransportCapabilities* capabilitiesPtr) 
+{
+    memset(capabilitiesPtr, 0, sizeof(JDWPTransportCapabilities));
+    capabilitiesPtr->can_timeout_attach = 1;
+    capabilitiesPtr->can_timeout_accept = 1;
+    capabilitiesPtr->can_timeout_handshake = 1;
+
+    return JDWPTRANSPORT_ERROR_NONE;
+} //TCPIPSocketTran_GetCapabilities
+
+/**
+ * This function implements jdwpTransportEnv::Close
+ */
+static jdwpTransportError JNICALL 
+TCPIPSocketTran_Close(jdwpTransportEnv* env)
+{
+    SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket;
+    if (envClientSocket == INVALID_SOCKET) {
+        return JDWPTRANSPORT_ERROR_NONE;
+    }
+
+    ((internalEnv*)env->functions->reserved1)->envClientSocket = INVALID_SOCKET;
+
+    int err;
+    err = shutdown(envClientSocket, SD_BOTH);
+    if (err == SOCKET_ERROR) {
+        SetLastTranError(env, "close socket failed", GetLastErrorStatus());
+        return JDWPTRANSPORT_ERROR_IO_ERROR;
+    }
+
+    err = closesocket(envClientSocket);
+    if (err == SOCKET_ERROR) {
+        SetLastTranError(env, "close socket failed", GetLastErrorStatus());
+        return JDWPTRANSPORT_ERROR_IO_ERROR;
+    }
+
+    return JDWPTRANSPORT_ERROR_NONE;
+} //TCPIPSocketTran_Close
+
+/**
+ * This function sets socket options SO_REUSEADDR and TCP_NODELAY
+ */
+static bool 
+SetSocketOptions(jdwpTransportEnv* env, SOCKET sckt) 
+{
+    BOOL isOn = TRUE;
+    if (setsockopt(sckt, SOL_SOCKET, SO_REUSEADDR, (const char*)&isOn, sizeof(isOn)) == SOCKET_ERROR) {                                                              
+        SetLastTranError(env, "setsockopt(SO_REUSEADDR) failed", GetLastErrorStatus());
+        return false;
+    }
+    if (setsockopt(sckt, IPPROTO_TCP, TCP_NODELAY, (const char*)&isOn, sizeof(isOn)) == SOCKET_ERROR) {
+        SetLastTranError(env, "setsockopt(TCPNODELAY) failed", GetLastErrorStatus());
+        return false;
+    }
+    return true;
+} // SetSocketOptions()
+
+/**
+ * This function implements jdwpTransportEnv::Attach
+ */
+static jdwpTransportError JNICALL 
+TCPIPSocketTran_Attach(jdwpTransportEnv* env, const char* address,
+        jlong attachTimeout, jlong handshakeTimeout)
+{
+    if ((address == 0) || (*address == 0)) {
+        SetLastTranError(env, "address is missing", 0);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT;
+    }
+
+    if (attachTimeout < 0) {
+        SetLastTranError(env, "attachTimeout timeout is negative", 0);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT;
+    }
+
+    if (handshakeTimeout < 0) {
+        SetLastTranError(env, "handshakeTimeout timeout is negative", 0);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT;
+    }
+
+    SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket;
+    if (envClientSocket != INVALID_SOCKET) {
+        SetLastTranError(env, "there is already an open connection to the debugger", 0);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ;
+    }
+
+    SOCKET envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket;
+    if (envServerSocket != INVALID_SOCKET) {
+        SetLastTranError(env, "transport is currently in listen mode", 0);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ;
+    }
+
+    struct sockaddr_in serverSockAddr;
+    jdwpTransportError res = DecodeAddress(env, address, &serverSockAddr, false);
+    if (res != JDWPTRANSPORT_ERROR_NONE) {
+        return res;
+    }
+
+    SOCKET clientSocket = socket(AF_INET, SOCK_STREAM, 0);
+    if (clientSocket == INVALID_SOCKET) {
+        SetLastTranError(env, "unable to create socket", GetLastErrorStatus());
+        return JDWPTRANSPORT_ERROR_IO_ERROR;
+    }
+    
+    if (!SetSocketOptions(env, clientSocket)) {
+        return JDWPTRANSPORT_ERROR_IO_ERROR;
+    }
+
+    if (attachTimeout == 0) {
+        if (!SetSocketBlockingMode(env, clientSocket, true)) {
+            return JDWPTRANSPORT_ERROR_IO_ERROR;
+        }
+        int err = connect(clientSocket, (struct sockaddr *)&serverSockAddr, sizeof(serverSockAddr));
+        if (err == SOCKET_ERROR) {
+            SetLastTranError(env, "connection failed", GetLastErrorStatus());
+            SetSocketBlockingMode(env, clientSocket, false);
+            return JDWPTRANSPORT_ERROR_IO_ERROR;
+        }
+        if (!SetSocketBlockingMode(env, clientSocket, false)) {
+            return JDWPTRANSPORT_ERROR_IO_ERROR;
+        }
+    } else {
+        if (!SetSocketBlockingMode(env, clientSocket, false)) {
+            return JDWPTRANSPORT_ERROR_IO_ERROR;
+        }
+        int err = connect(clientSocket, (struct sockaddr *)&serverSockAddr, sizeof(serverSockAddr));
+        if (err == SOCKET_ERROR) {
+            if (GetLastErrorStatus() != SOCKETWOULDBLOCK) {
+                SetLastTranError(env, "connection failed", GetLastErrorStatus());
+                return JDWPTRANSPORT_ERROR_IO_ERROR;
+            } else {  
+                fd_set fdwrite;
+                FD_ZERO(&fdwrite);
+                FD_SET(clientSocket, &fdwrite);
+                TIMEVAL tv = {(long)(attachTimeout / 1000), (long)(attachTimeout % 1000)};
+
+                int ret = select((int)clientSocket + 1, NULL, &fdwrite, NULL, &tv);
+                if (ret == SOCKET_ERROR) {
+                    SetLastTranError(env, "socket error", GetLastErrorStatus());
+                    return JDWPTRANSPORT_ERROR_IO_ERROR;
+                }
+                if ((ret != 1) || !(FD_ISSET(clientSocket, &fdwrite))) {
+                    SetLastTranError(env, "timeout occurred", 0);
+                    return JDWPTRANSPORT_ERROR_IO_ERROR;
+                }
+            }
+        }
+    }
+
+    EnterCriticalSendSection(env);
+    EnterCriticalReadSection(env);
+    ((internalEnv*)env->functions->reserved1)->envClientSocket = clientSocket;
+    res = CheckHandshaking(env, clientSocket, (long)handshakeTimeout);
+    LeaveCriticalReadSection(env);
+    LeaveCriticalSendSection(env);
+    if (res != JDWPTRANSPORT_ERROR_NONE) {
+        TCPIPSocketTran_Close(env);
+        return res;
+    }
+
+    return JDWPTRANSPORT_ERROR_NONE;
+} //TCPIPSocketTran_Attach
+
+/**
+ * This function implements jdwpTransportEnv::StartListening
+ */
+static jdwpTransportError JNICALL 
+TCPIPSocketTran_StartListening(jdwpTransportEnv* env, const char* address, 
+        char** actualAddress)
+{
+    SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket;
+    if (envClientSocket != INVALID_SOCKET) {
+        SetLastTranError(env, "there is already an open connection to the debugger", 0);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ;
+    }
+
+    SOCKET envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket;
+    if (envServerSocket != INVALID_SOCKET) {
+        SetLastTranError(env, "transport is currently in listen mode", 0);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ;
+    }
+
+    jdwpTransportError res;
+    struct sockaddr_in serverSockAddr;
+    res = DecodeAddress(env, address, &serverSockAddr, true);
+    if (res != JDWPTRANSPORT_ERROR_NONE) {
+        return res;
+    }
+
+    SOCKET serverSocket = socket(AF_INET, SOCK_STREAM, 0);
+    if (serverSocket == INVALID_SOCKET) {
+        SetLastTranError(env, "unable to create socket", GetLastErrorStatus());
+        return JDWPTRANSPORT_ERROR_IO_ERROR;
+    }
+
+    if (!SetSocketOptions(env, serverSocket)) {
+        return JDWPTRANSPORT_ERROR_IO_ERROR;
+    }
+
+    int err;
+
+    err = bind(serverSocket, (struct sockaddr *)&serverSockAddr, sizeof(serverSockAddr));
+    if (err == SOCKET_ERROR) {
+        SetLastTranError(env, "connection failed", GetLastErrorStatus());
+        return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ;
+    }
+
+    err = listen(serverSocket, SOMAXCONN);
+    if (err == SOCKET_ERROR) {
+        SetLastTranError(env, "listen start failed", GetLastErrorStatus());
+        return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ;
+    }
+
+    if (!SetSocketBlockingMode(env, serverSocket, false)) {
+        return JDWPTRANSPORT_ERROR_IO_ERROR;
+    }
+
+    ((internalEnv*)env->functions->reserved1)->envServerSocket = serverSocket;
+
+    socklen_t len = sizeof(serverSockAddr);
+    err = getsockname(serverSocket, (struct sockaddr *)&serverSockAddr, &len);
+    if (err == SOCKET_ERROR) {
+        SetLastTranError(env, "socket error", GetLastErrorStatus());
+        return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ;
+    }
+
+    char* retAddress = 0;
+    char portName[6];
+    sprintf(portName, "%d", ntohs(serverSockAddr.sin_port)); //instead of itoa()
+
+    char hostName[NI_MAXHOST];
+    if (getnameinfo((struct sockaddr *)&serverSockAddr, len, hostName, sizeof(hostName), NULL, 0, 0)) {
+        return JDWPTRANSPORT_ERROR_IO_ERROR;
+    }
+    if (strcmp(hostName, "0.0.0.0") == 0) {
+        gethostname(hostName, sizeof(hostName));
+    }
+
+    retAddress = (char*)(((internalEnv*)env->functions->reserved1)
+        ->alloc)((jint)(strlen(hostName) + strlen(portName) + 2)); 
+    if (retAddress == 0) {
+        SetLastTranError(env, "out of memory", 0);
+        return JDWPTRANSPORT_ERROR_OUT_OF_MEMORY;
+    }
+    sprintf(retAddress, "%s:%s", hostName, portName);
+    *actualAddress = retAddress;
+
+    return JDWPTRANSPORT_ERROR_NONE;
+} //TCPIPSocketTran_StartListening
+
+/**
+ * This function implements jdwpTransportEnv::StopListening
+ */
+static jdwpTransportError JNICALL 
+TCPIPSocketTran_StopListening(jdwpTransportEnv* env)
+{
+    SOCKET envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket;
+    if (envServerSocket == INVALID_SOCKET) {
+        return JDWPTRANSPORT_ERROR_NONE;
+    }
+
+    if (closesocket(envServerSocket) == SOCKET_ERROR) {
+        SetLastTranError(env, "close socket failed", GetLastErrorStatus());
+        return JDWPTRANSPORT_ERROR_IO_ERROR;
+    }
+
+    ((internalEnv*)env->functions->reserved1)->envServerSocket = INVALID_SOCKET;
+
+    return JDWPTRANSPORT_ERROR_NONE;
+} //TCPIPSocketTran_StopListening
+
+/**
+ * This function implements jdwpTransportEnv::Accept
+ */
+static jdwpTransportError JNICALL 
+TCPIPSocketTran_Accept(jdwpTransportEnv* env, jlong acceptTimeout,
+        jlong handshakeTimeout)
+{
+    if (acceptTimeout < 0) {
+        SetLastTranError(env, "acceptTimeout timeout is negative", 0);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT;
+    }
+
+    if (handshakeTimeout < 0) {
+        SetLastTranError(env, "handshakeTimeout timeout is negative", 0);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT;
+    }
+
+    SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket;
+    if (envClientSocket != INVALID_SOCKET) {
+        SetLastTranError(env, "there is already an open connection to the debugger", 0);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ;
+    }
+
+    SOCKET envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket;
+    if (envServerSocket == INVALID_SOCKET) {
+        SetLastTranError(env, "transport is not currently in listen mode", 0);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ;
+    }
+
+    struct sockaddr serverSockAddr;
+    socklen_t len = sizeof(serverSockAddr);
+    int res = getsockname(envServerSocket, &serverSockAddr, &len);
+    if (res == SOCKET_ERROR) {
+        SetLastTranError(env, "connection failed", GetLastErrorStatus());
+        return JDWPTRANSPORT_ERROR_IO_ERROR;
+    }
+
+    jlong deadline = (acceptTimeout == 0) ? 0 : (jlong)GetTickCount() + acceptTimeout;
+    jdwpTransportError err = SelectRead(env, envServerSocket, deadline);
+    if (err != JDWPTRANSPORT_ERROR_NONE) {
+        return err;
+    }
+
+    SOCKET clientSocket = accept(envServerSocket, &serverSockAddr, &len);
+    if (clientSocket == INVALID_SOCKET) {
+        SetLastTranError(env, "socket accept failed", GetLastErrorStatus());
+        return JDWPTRANSPORT_ERROR_IO_ERROR;
+    }
+
+    if (!SetSocketBlockingMode(env, clientSocket, false)) {
+        return JDWPTRANSPORT_ERROR_IO_ERROR;
+    }
+
+    EnterCriticalSendSection(env);
+    EnterCriticalReadSection(env);
+    ((internalEnv*)env->functions->reserved1)->envClientSocket = clientSocket;
+
+    err = CheckHandshaking(env, clientSocket, (long)handshakeTimeout);
+    LeaveCriticalReadSection(env);
+    LeaveCriticalSendSection(env);
+    if (err != JDWPTRANSPORT_ERROR_NONE) {
+        TCPIPSocketTran_Close(env);
+        return err;
+    }
+
+    return JDWPTRANSPORT_ERROR_NONE;
+} //TCPIPSocketTran_Accept
+
+/**
+ * This function implements jdwpTransportEnv::IsOpen
+ */
+static jboolean JNICALL 
+TCPIPSocketTran_IsOpen(jdwpTransportEnv* env)
+{
+    SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket;
+    if (envClientSocket == INVALID_SOCKET) {
+        return JNI_FALSE;
+    }
+    return JNI_TRUE;
+} //TCPIPSocketTran_IsOpen
+
+/**
+ * This function read packet
+ */
+static jdwpTransportError
+ReadPacket(jdwpTransportEnv* env, SOCKET envClientSocket, jdwpPacket* packet)
+{
+    jdwpTransportError err;
+    int length;
+    int readBytes = 0;
+    err = ReceiveData(env, envClientSocket, (char *)&length, sizeof(jint), 0, &readBytes);
+    if (err != JDWPTRANSPORT_ERROR_NONE) {
+        if (readBytes == 0) {
+            packet->type.cmd.len = 0;
+            return JDWPTRANSPORT_ERROR_NONE;
+        }
+        return err;
+    }
+
+    packet->type.cmd.len = (jint)ntohl(length);
+    
+    int id;
+    err = ReceiveData(env, envClientSocket, (char *)&(id), sizeof(jint));
+    if (err != JDWPTRANSPORT_ERROR_NONE) {
+        return err;
+    }
+
+    packet->type.cmd.id = (jint)ntohl(id);
+
+    err = ReceiveData(env, envClientSocket, (char *)&(packet->type.cmd.flags), sizeof(jbyte));
+    if (err != JDWPTRANSPORT_ERROR_NONE) {
+        return err;
+    }
+
+    if (packet->type.cmd.flags & JDWPTRANSPORT_FLAGS_REPLY) {
+        u_short errorCode;
+        err = ReceiveData(env, envClientSocket, (char*)&(errorCode), sizeof(jshort));
+        if (err != JDWPTRANSPORT_ERROR_NONE) {
+            return err;
+        }
+        packet->type.reply.errorCode = (jshort)ntohs(errorCode); 
+    } else {
+        err = ReceiveData(env, envClientSocket, (char*)&(packet->type.cmd.cmdSet), sizeof(jbyte));
+        if (err != JDWPTRANSPORT_ERROR_NONE) {
+            return err;
+        }
+ 
+        err = ReceiveData(env, envClientSocket, (char*)&(packet->type.cmd.cmd), sizeof(jbyte));
+        if (err != JDWPTRANSPORT_ERROR_NONE) {
+            return err;
+        }
+    } //if
+
+    int dataLength = packet->type.cmd.len - 11;
+    if (dataLength < 0) {
+        SetLastTranError(env, "invalid packet length received", 0);
+        return JDWPTRANSPORT_ERROR_IO_ERROR;
+    } else if (dataLength == 0) {
+        packet->type.cmd.data = 0;
+    } else {
+        packet->type.cmd.data = (jbyte*)(((internalEnv*)env->functions->reserved1)->alloc)(dataLength);
+        if (packet->type.cmd.data == 0) {
+            SetLastTranError(env, "out of memory", 0);
+            return JDWPTRANSPORT_ERROR_OUT_OF_MEMORY;
+        }
+        err = ReceiveData(env, envClientSocket, (char *)packet->type.cmd.data, dataLength);
+        if (err != JDWPTRANSPORT_ERROR_NONE) {
+            (((internalEnv*)env->functions->reserved1)->free)(packet->type.cmd.data);
+            return err;
+        }
+    } //if
+    return JDWPTRANSPORT_ERROR_NONE;
+}
+
+/**
+ * This function implements jdwpTransportEnv::ReadPacket
+ */
+static jdwpTransportError JNICALL 
+TCPIPSocketTran_ReadPacket(jdwpTransportEnv* env, jdwpPacket* packet)
+{
+    if (packet == 0) {
+        SetLastTranError(env, "packet is 0", 0);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT;
+    }
+
+    SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket;
+    if (envClientSocket == INVALID_SOCKET) {
+        SetLastTranError(env, "there isn't an open connection to a debugger", 0);
+        LeaveCriticalReadSection(env);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ;
+    }
+
+    EnterCriticalReadSection(env);
+    jdwpTransportError err = ReadPacket(env, envClientSocket, packet);
+    LeaveCriticalReadSection(env);
+    return JDWPTRANSPORT_ERROR_NONE;
+} //TCPIPSocketTran_ReadPacket
+
+/**
+ * This function implements jdwpTransportEnv::WritePacket
+ */
+static jdwpTransportError 
+WritePacket(jdwpTransportEnv* env, SOCKET envClientSocket, const jdwpPacket* packet)
+{
+    int packetLength = packet->type.cmd.len;
+    if (packetLength < 11) {
+        SetLastTranError(env, "invalid packet length", 0);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT;
+    }
+
+    char* data = (char*)packet->type.cmd.data;
+    if ((packetLength > 11) && (data == 0)) {
+        SetLastTranError(env, "packet length is greater than 11 but the packet data field is 0", 0);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT;
+    }
+
+    int dataLength = packetLength - 11;
+    packetLength = htonl(packetLength);
+
+    jdwpTransportError err;
+    err = SendData(env, envClientSocket, (char*)&packetLength, sizeof(jint));
+    if (err != JDWPTRANSPORT_ERROR_NONE) {
+        return err;
+    }
+
+    int id = htonl(packet->type.cmd.id);
+
+    err = SendData(env, envClientSocket, (char*)&id, sizeof(jint));
+    if (err != JDWPTRANSPORT_ERROR_NONE) {
+        return err;
+    }
+
+    err = SendData(env, envClientSocket, (char*)&(packet->type.cmd.flags), sizeof(jbyte));
+    if (err != JDWPTRANSPORT_ERROR_NONE) {
+        return err;
+    }
+
+    if (packet->type.cmd.flags & JDWPTRANSPORT_FLAGS_REPLY) {
+        u_short errorCode = htons(packet->type.reply.errorCode);
+        err = SendData(env, envClientSocket, (char*)&errorCode, sizeof(jshort));
+        if (err != JDWPTRANSPORT_ERROR_NONE) {
+            return err;
+        }
+    } else {
+        err = SendData(env, envClientSocket, (char*)&(packet->type.cmd.cmdSet), sizeof(jbyte));
+        if (err != JDWPTRANSPORT_ERROR_NONE) {
+            return err;
+        }
+        err = SendData(env, envClientSocket, (char*)&(packet->type.cmd.cmd), sizeof(jbyte));
+        if (err != JDWPTRANSPORT_ERROR_NONE) {
+            return err;
+        }
+    } //if
+    
+    if (data != 0) {
+        err = SendData(env, envClientSocket, data, dataLength);
+        if (err != JDWPTRANSPORT_ERROR_NONE) {
+            return err;
+        }
+    } //if
+    return JDWPTRANSPORT_ERROR_NONE;
+}
+
+/**
+ * This function send packet
+ */
+static jdwpTransportError JNICALL 
+TCPIPSocketTran_WritePacket(jdwpTransportEnv* env, const jdwpPacket* packet)
+{
+
+    if (packet == 0) {
+        SetLastTranError(env, "packet is 0", 0);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT;
+    }
+
+    SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket;
+    if (envClientSocket == INVALID_SOCKET) {
+        SetLastTranError(env, "there isn't an open connection to a debugger", 0);
+        LeaveCriticalSendSection(env);
+        return JDWPTRANSPORT_ERROR_ILLEGAL_STATE;
+    }
+
+    EnterCriticalSendSection(env);
+    jdwpTransportError err = WritePacket(env, envClientSocket, packet);
+    LeaveCriticalSendSection(env);
+    return err;
+} //TCPIPSocketTran_WritePacket
+
+/**
+ * This function implements jdwpTransportEnv::GetLastError
+ */
+static jdwpTransportError JNICALL 
+TCPIPSocketTran_GetLastError(jdwpTransportEnv* env, char** message)
+{
+    *message = ((internalEnv*)env->functions->reserved1)->lastError->GetLastErrorMessage();
+    if (*message == 0) {
+        return JDWPTRANSPORT_ERROR_MSG_NOT_AVAILABLE;
+    }
+    return JDWPTRANSPORT_ERROR_NONE;
+} //TCPIPSocketTran_GetLastError
+
+/**
+ * This function must be called by agent when the library is loaded
+ */
+extern "C" JNIEXPORT jint JNICALL 
+jdwpTransport_OnLoad(JavaVM *vm, jdwpTransportCallback* callback,
+             jint version, jdwpTransportEnv** env)
+{
+    if (version != JDWPTRANSPORT_VERSION_1_0) {
+        return JNI_EVERSION;
+    }
+
+    internalEnv* iEnv = (internalEnv*)callback->alloc(sizeof(internalEnv));
+    if (iEnv == 0) {
+        return JNI_ENOMEM;
+    }
+    iEnv->jvm = vm;
+    iEnv->alloc = callback->alloc;
+    iEnv->free = callback->free;
+    iEnv->lastError = 0;
+    iEnv->envClientSocket = INVALID_SOCKET;
+    iEnv->envServerSocket = INVALID_SOCKET;
+
+    jdwpTransportNativeInterface_* envTNI = (jdwpTransportNativeInterface_*)callback
+        ->alloc(sizeof(jdwpTransportNativeInterface_));
+    if (envTNI == 0) {
+        callback->free(iEnv);
+        return JNI_ENOMEM;
+    }
+
+    envTNI->GetCapabilities = &TCPIPSocketTran_GetCapabilities;
+    envTNI->Attach = &TCPIPSocketTran_Attach;
+    envTNI->StartListening = &TCPIPSocketTran_StartListening;
+    envTNI->StopListening = &TCPIPSocketTran_StopListening;
+    envTNI->Accept = &TCPIPSocketTran_Accept;
+    envTNI->IsOpen = &TCPIPSocketTran_IsOpen;
+    envTNI->Close = &TCPIPSocketTran_Close;
+    envTNI->ReadPacket = &TCPIPSocketTran_ReadPacket;
+    envTNI->WritePacket = &TCPIPSocketTran_WritePacket;
+    envTNI->GetLastError = &TCPIPSocketTran_GetLastError;
+    envTNI->reserved1 = iEnv;
+
+    _jdwpTransportEnv* resEnv = (_jdwpTransportEnv*)callback
+        ->alloc(sizeof(_jdwpTransportEnv));
+    if (resEnv == 0) {
+        callback->free(iEnv);
+        callback->free(envTNI);
+        return JNI_ENOMEM;
+    }
+
+    resEnv->functions = envTNI;
+    *env = resEnv;
+
+    InitializeCriticalSections(resEnv);
+
+    return JNI_OK;
+} //jdwpTransport_OnLoad
+
+/**
+ * This function may be called by agent before the library unloading.
+ * The function is not defined in JDWP Transport Interface specification.
+ */
+extern "C" JNIEXPORT void JNICALL 
+jdwpTransport_UnLoad(jdwpTransportEnv** env)
+{
+    DeleteCriticalSections(*env);
+    TCPIPSocketTran_Close(*env);
+    TCPIPSocketTran_StopListening(*env);
+    void (*unLoadFree)(void *buffer) = ((internalEnv*)(*env)->functions->reserved1)->free;
+    if (((internalEnv*)(*env)->functions->reserved1)->lastError != 0){
+        delete (((internalEnv*)(*env)->functions->reserved1)->lastError);
+    }
+    unLoadFree((void*)(*env)->functions->reserved1);
+    unLoadFree((void*)(*env)->functions);
+    unLoadFree((void*)(*env));
+} //jdwpTransport_UnLoad
+

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/transport/dt_socket/SocketTransport.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/transport/dt_socket/SocketTransport.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/transport/dt_socket/SocketTransport.h?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/transport/dt_socket/SocketTransport.h (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/transport/dt_socket/SocketTransport.h Tue Nov 28 09:49:08 2006
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, 
+ * as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Viacheslav G. Rybalov
+ * @version $Revision: 1.5.2.1 $
+ */
+
+/**
+ * @file
+ * SocketTransport.h
+ *
+ * Internal data for the jdwp transport environment.
+ * The given TCP/IP Socket transport supports multiple environments, 
+ * so the struct is allocated for each environment.
+ */
+
+#ifndef _SOCKETTRANSPORT_H
+#define _SOCKETTRANSPORT_H
+
+struct internalEnv {
+    JavaVM *jvm;                    // the JNI invocation interface, provided 
+                                    // by the agent 
+    void* (*alloc)(jint numBytes);  // the function allocating an area of memory, 
+                                    // provided by the agent 
+    void (*free)(void *buffer);     // the function deallocating an area of memory, 
+                                    // provided by the agent
+    SOCKET envClientSocket;         // the client socket, INVALID_SOCKET if closed
+    SOCKET envServerSocket;         // the server socket, INVALID_SOCKET if closed
+    LastTransportError* lastError;  // last errors
+    CriticalSection readLock;       // the critical-section lock object for socket
+                                    // read operations
+    CriticalSection sendLock;       // the critical-section lock object for socket
+                                    // send operations
+};
+
+#endif // _SOCKETTRANSPORT_H
+

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/common/other/jpda/jdwp/transport/dt_socket/SocketTransport.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/linux/other/jpda/jdwp/agent/core/TransportManager_pd.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/linux/other/jpda/jdwp/agent/core/TransportManager_pd.cpp?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/linux/other/jpda/jdwp/agent/core/TransportManager_pd.cpp (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/linux/other/jpda/jdwp/agent/core/TransportManager_pd.cpp Tue Nov 28 09:49:08 2006
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Viacheslav G. Rybalov
+ * @version $Revision: 1.14 $
+ */
+
+// TransportManager_pd.cpp
+//
+
+/**
+ * This header file includes platform depended definitions for types, 
+ * constants, include statements and functions for Linux platform.
+ */
+
+#include "TransportManager_pd.h"
+#include "TransportManager.h"
+
+using namespace jdwp;
+
+const char* TransportManager::onLoadDecFuncName = "jdwpTransport_OnLoad";
+const char* TransportManager::unLoadDecFuncName = "jdwpTransport_UnLoad";
+const char TransportManager::pathSeparator = ':';
+
+void TransportManager::StartDebugger(const char* command) throw(AgentException)
+{
+    throw NotImplementedException();
+}
+
+ProcPtr jdwp::GetProcAddress(LoadedLibraryHandler libHandler, const char* procName)
+{
+    dlerror();
+    ProcPtr res = (ProcPtr)dlsym(libHandler, procName);
+    char* errorMessage = 0;
+    if (errorMessage = dlerror()) {
+        JDWP_TRACE_PROG("free library failed (error: " << errorMessage << ")");
+    }
+    return res;
+}
+
+bool jdwp::FreeLibrary(LoadedLibraryHandler libHandler)
+{
+    dlerror();
+    if (dlclose(libHandler) != 0) {
+        JDWP_TRACE_PROG("free library failed (error: " << dlerror() << ")");
+        return false;
+    }
+    return true;
+}
+
+LoadedLibraryHandler TransportManager::LoadTransport(const char* dirName, const char* transportName)
+{
+    JDWP_ASSERT(transportName != 0);
+    dlerror();
+    char* transportFullName = 0;
+    if (dirName == 0) {
+        size_t length = strlen(transportName) + 7;
+        transportFullName = static_cast<char *>(GetMemoryManager().Allocate(length JDWP_FILE_LINE));
+        sprintf(transportFullName, "lib%s.so", transportName);
+    } else {
+        size_t length = strlen(dirName) + strlen(transportName) + 8;
+        transportFullName = static_cast<char *>(GetMemoryManager().Allocate(length JDWP_FILE_LINE));
+        sprintf(transportFullName, "%s/lib%s.so", dirName, transportName);
+    }
+    AgentAutoFree afv(transportFullName JDWP_FILE_LINE);
+    LoadedLibraryHandler res = dlopen(transportFullName, RTLD_LAZY);
+    if (res == 0) {
+        JDWP_TRACE_PROG("loading of " << transportFullName << " failed (error: " << dlerror() << ")");
+    } else {
+        JDWP_TRACE_PROG("transport " << transportFullName << " loaded");
+    }
+    return res;
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/linux/other/jpda/jdwp/agent/core/TransportManager_pd.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/linux/other/jpda/jdwp/agent/core/TransportManager_pd.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/linux/other/jpda/jdwp/agent/core/TransportManager_pd.h?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/linux/other/jpda/jdwp/agent/core/TransportManager_pd.h (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/linux/other/jpda/jdwp/agent/core/TransportManager_pd.h Tue Nov 28 09:49:08 2006
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, 
+ * as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Viacheslav G. Rybalov
+ * @version $Revision: 1.6.2.1 $
+ */
+
+/**
+ * @file
+ * TransportManager_pd.h
+ *
+ * The given header file includes platform depended declarations for types
+ * and constants, and statements and functions for the Linux platform.  
+ */
+
+#ifndef _TRANSPORT_MANAGER_PD_H_
+#define _TRANSPORT_MANAGER_PD_H_
+
+#include <dlfcn.h>
+#include <unistd.h>
+
+namespace jdwp {
+
+    typedef void* LoadedLibraryHandler;
+
+    typedef void (*ProcPtr)();
+
+    ProcPtr GetProcAddress(LoadedLibraryHandler libHandler, const char* procName);
+
+    bool FreeLibrary(LoadedLibraryHandler libHandler);
+
+}//jdwp
+
+#endif // _TRANSPORT_MANAGER_PD_H_

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/linux/other/jpda/jdwp/agent/core/TransportManager_pd.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/linux/other/jpda/jdwp/transport/dt_socket/SocketTransport_pd.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/linux/other/jpda/jdwp/transport/dt_socket/SocketTransport_pd.h?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/linux/other/jpda/jdwp/transport/dt_socket/SocketTransport_pd.h (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/linux/other/jpda/jdwp/transport/dt_socket/SocketTransport_pd.h Tue Nov 28 09:49:08 2006
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, 
+ * as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Viacheslav G. Rybalov
+ * @version $Revision: 1.5.2.1 $
+ */
+
+/**
+ * @file
+ * SocketTransport_pd.h
+ *
+ * The given header file includes platform depended declarations and definitions 
+ * for types, constants, include statements and functions for the Linux platform.
+ */
+
+#ifndef _SOCKETTRANSPORT_PD_H
+#define _SOCKETTRANSPORT_PD_H
+
+
+#include <pthread.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <arpa/inet.h>
+#include <netinet/tcp.h> 
+#include <pthread.h>
+
+typedef pthread_mutex_t CriticalSection;
+typedef int SOCKET;
+typedef pthread_t ThreadId_t;
+
+#include "jdwpTransport.h"
+#include "LastTransportError.h"
+#include "SocketTransport.h"
+
+typedef timeval TIMEVAL;
+typedef int BOOL;
+
+const int TRUE = 1;
+const int SOCKET_ERROR = -1;
+const int SOCKET_ERROR_EINTR = EINTR;
+const int INVALID_SOCKET = -1;
+const int SD_BOTH = 2;
+const int SOCKETWOULDBLOCK = EINPROGRESS;
+
+/**
+ * Returns the error status for the last failed operation. 
+ */
+static inline int
+GetLastErrorStatus()
+{
+    return errno;
+}
+
+/**
+ * Retrieves the number of milliseconds, substitute for the corresponding Win32 
+ * function.
+ */
+static inline long 
+GetTickCount(void)
+{
+    struct timeval t;
+    gettimeofday(&t, 0);
+    return t.tv_sec * 1000 + (t.tv_usec/1000);
+}
+
+/**
+ * Closes socket, substitute for the corresponding Win32 function.
+ */
+static inline int 
+closesocket(SOCKET s)
+{
+    return close(s);
+}
+
+/**
+ * Closes socket, substitute for the corresponding Win32 function.
+ */
+static inline int 
+ioctlsocket( SOCKET s, long cmd, u_long* argp)
+{
+    return ioctl(s, cmd, argp);
+}
+
+/**
+ * Initializes critical-section lock objects.
+ */
+static inline void
+InitializeCriticalSections(jdwpTransportEnv* env)
+{
+    pthread_mutex_init(&(((internalEnv*)env->functions->reserved1)->readLock), 0);
+    pthread_mutex_init(&(((internalEnv*)env->functions->reserved1)->sendLock), 0);
+}
+ 
+/**
+ * Releases all resources used by critical-section lock objects.
+ */
+static inline void
+DeleteCriticalSections(jdwpTransportEnv* env)
+{
+    pthread_mutex_destroy(&(((internalEnv*)env->functions->reserved1)->readLock));
+    pthread_mutex_destroy(&(((internalEnv*)env->functions->reserved1)->sendLock));
+}
+
+/**
+ * Waits for ownership of the read critical-section object.
+ */
+static inline void
+EnterCriticalReadSection(jdwpTransportEnv* env)
+{
+    pthread_mutex_lock(&(((internalEnv*)env->functions->reserved1)->readLock));
+}
+
+/**
+ * Waits for ownership of the send critical-section object.
+ */
+static inline void
+EnterCriticalSendSection(jdwpTransportEnv* env)
+{
+    pthread_mutex_lock(&(((internalEnv*)env->functions->reserved1)->sendLock));
+}
+
+/**
+ * Releases ownership of the read critical-section object.
+ */
+static inline void
+LeaveCriticalReadSection(jdwpTransportEnv* env)
+{
+    pthread_mutex_unlock(&(((internalEnv*)env->functions->reserved1)->readLock));
+}
+
+/**
+ * Releases ownership of the send critical-section object.
+ */
+static inline void
+LeaveCriticalSendSection(jdwpTransportEnv* env)
+{
+    pthread_mutex_unlock(&(((internalEnv*)env->functions->reserved1)->sendLock));
+}
+
+static inline ThreadId_t 
+GetCurrentThreadId()
+{
+    return pthread_self();
+} // GetCurrentThreadId()
+
+static inline bool 
+ThreadId_equal(ThreadId_t treadId1, ThreadId_t treadId2)
+{
+    return pthread_equal(treadId1, treadId2) != 0 ? true : false;
+} // ThreadId_equal()
+
+#endif //_SOCKETTRANSPORT_PD_H

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/linux/other/jpda/jdwp/transport/dt_socket/SocketTransport_pd.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/agent/core/TransportManager_pd.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/agent/core/TransportManager_pd.cpp?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/agent/core/TransportManager_pd.cpp (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/agent/core/TransportManager_pd.cpp Tue Nov 28 09:49:08 2006
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Viacheslav G. Rybalov
+ * @version $Revision: 1.10 $
+ */
+// TransportManager_pd.cpp
+//
+
+/**
+ * This header file includes platform depended definitions for types, 
+ * constants, include statements and functions for Win32 platform.
+ */
+
+#include "TransportManager_pd.h"
+#include "TransportManager.h"
+#include <process.h>
+
+using namespace jdwp;
+
+const char* TransportManager::onLoadDecFuncName = "_jdwpTransport_OnLoad@16";
+const char* TransportManager::unLoadDecFuncName = "_jdwpTransport_UnLoad@4";
+const char TransportManager::pathSeparator = ';';
+
+void TransportManager::StartDebugger(const char* command) throw(AgentException)
+{
+    throw NotImplementedException();
+}
+
+LoadedLibraryHandler TransportManager::LoadTransport(const char* dirName, const char* transportName)
+{
+    JDWP_ASSERT(transportName != 0);
+    char* transportFullName = 0;
+    if (dirName == 0) {
+        size_t length = strlen(transportName) + 5;
+        transportFullName = static_cast<char *>(GetMemoryManager().Allocate(length JDWP_FILE_LINE));
+        sprintf(transportFullName, "%s.dll", transportName);
+    } else {
+        size_t length = strlen(dirName) + strlen(transportName) + 6;
+        transportFullName = static_cast<char *>(GetMemoryManager().Allocate(length JDWP_FILE_LINE));
+        sprintf(transportFullName, "%s\\%s.dll", dirName, transportName);
+    }
+    AgentAutoFree afv(transportFullName JDWP_FILE_LINE);
+    LoadedLibraryHandler res = LoadLibrary(transportFullName);
+    if (res == 0) {
+        JDWP_TRACE_PROG("loading of " << transportFullName << " failed (error code: " << GetLastError() << ")");
+    } else {
+        JDWP_TRACE_PROG("transport " << transportFullName << " loaded");
+    }
+    return res;
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/agent/core/TransportManager_pd.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/agent/core/TransportManager_pd.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/agent/core/TransportManager_pd.h?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/agent/core/TransportManager_pd.h (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/agent/core/TransportManager_pd.h Tue Nov 28 09:49:08 2006
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, 
+ * as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Viacheslav G. Rybalov
+ * @version $Revision: 1.5.2.1 $
+ */
+
+/**
+ * @file
+ * TransportManager_pd.h
+ *
+ * The given header file includes platform depended declarations for types, 
+ * constants, include statements and functions for the Win32 platform.
+ */
+
+#ifndef _TRANSPORT_MANAGER_PD_H_
+#define _TRANSPORT_MANAGER_PD_H_
+
+#define WIN32_LEAN_AND_MEAN  // Exclude rarely-used stuff from Windows headers
+// Windows Header Files:
+#include <windows.h>
+
+namespace jdwp {
+
+    typedef HMODULE LoadedLibraryHandler;
+
+}//jdwp
+
+#endif // _TRANSPORT_MANAGER_PD_H_

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/agent/core/TransportManager_pd.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/transport/dt_socket/SocketTransport_pd.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/transport/dt_socket/SocketTransport_pd.cpp?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/transport/dt_socket/SocketTransport_pd.cpp (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/transport/dt_socket/SocketTransport_pd.cpp Tue Nov 28 09:49:08 2006
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Viacheslav G. Rybalov
+ * @version $Revision: 1.3 $
+ */
+// SocketTransport_pd.cpp
+//
+
+#include "SocketTransport_pd.h"
+
+/**
+ * This function the optional entry point into a dynamic-link library (DLL).
+ * It invokes WSAStartup() and WSACleanup() functions.
+ */
+BOOL APIENTRY 
+DllMain(HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
+{
+    WSADATA wsStartData;
+    if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
+        WSAStartup(MAKEWORD(1,1), &wsStartData);
+    } else if (ul_reason_for_call == DLL_PROCESS_DETACH) {
+        WSACleanup();
+    }
+    return TRUE;
+} //DllMain

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/transport/dt_socket/SocketTransport_pd.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/transport/dt_socket/SocketTransport_pd.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/transport/dt_socket/SocketTransport_pd.h?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/transport/dt_socket/SocketTransport_pd.h (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/transport/dt_socket/SocketTransport_pd.h Tue Nov 28 09:49:08 2006
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, 
+ * as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Viacheslav G. Rybalov
+ * @version $Revision: 1.7.2.1 $
+ */
+
+/**
+ * @file
+ * SocketTransport_pd.h
+ *
+ * The given header file includes platform depended declarations and definitions 
+ * for types, constants, include statements and functions for the Win32 platform.
+ */
+
+#ifndef _SOCKETTRANSPORT_PD_H
+#define _SOCKETTRANSPORT_PD_H
+
+#include <Winsock2.h>
+#include <Ws2tcpip.h>
+
+typedef CRITICAL_SECTION CriticalSection;
+typedef DWORD ThreadId_t;
+
+#include "jdwpTransport.h"
+#include "LastTransportError.h"
+#include "SocketTransport.h"
+
+typedef int socklen_t;
+
+const int SOCKETWOULDBLOCK = WSAEWOULDBLOCK;
+const int SOCKET_ERROR_EINTR = WSAEINTR;
+
+/**
+ * Returns the error status for the last failed operation. 
+ */
+static inline int
+GetLastErrorStatus()
+{
+    return WSAGetLastError();
+} //GetLastErrorStatus()
+
+/**
+ * Initializes critical section lock objects.
+ */
+static inline void
+InitializeCriticalSections(jdwpTransportEnv* env)
+{
+    InitializeCriticalSection(&(((internalEnv*)env->functions->reserved1)->readLock));
+    InitializeCriticalSection(&(((internalEnv*)env->functions->reserved1)->sendLock));
+} //InitializeCriticalSections()
+
+/**
+ * Releases all resources used by critical-section lock objects.
+ */
+static inline void
+DeleteCriticalSections(jdwpTransportEnv* env)
+{
+    DeleteCriticalSection(&(((internalEnv*)env->functions->reserved1)->readLock));
+    DeleteCriticalSection(&(((internalEnv*)env->functions->reserved1)->sendLock));
+} //DeleteCriticalSections()
+
+/**
+ * Waits for ownership of the read critical-section object.
+ */
+static inline void
+EnterCriticalReadSection(jdwpTransportEnv* env)
+{
+    EnterCriticalSection(&(((internalEnv*)env->functions->reserved1)->readLock));
+} //EnterCriticalReadSection()
+
+/**
+ * Waits for ownership of the send critical-section object.
+ */
+static inline void
+EnterCriticalSendSection(jdwpTransportEnv* env)
+{
+    EnterCriticalSection(&(((internalEnv*)env->functions->reserved1)->sendLock));
+} //EnterCriticalSendSection()
+
+/**
+ * Releases ownership of the read critical-section object.
+ */
+static inline void
+LeaveCriticalReadSection(jdwpTransportEnv* env)
+{
+    LeaveCriticalSection(&(((internalEnv*)env->functions->reserved1)->readLock));
+} //LeaveCriticalReadSection()
+
+/**
+ * Releases ownership of the send critical-section object.
+ */
+static inline void
+LeaveCriticalSendSection(jdwpTransportEnv* env)
+{
+    LeaveCriticalSection(&(((internalEnv*)env->functions->reserved1)->sendLock));
+} //LeaveCriticalSendSection()
+
+static inline bool ThreadId_equal(ThreadId_t treadId1, ThreadId_t treadId2)
+{
+    return (treadId1 == treadId2);
+} // ThreadId_equal()
+
+#endif // _SOCKETTRANSPORT_PD_H

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/src/windows/other/jpda/jdwp/transport/dt_socket/SocketTransport_pd.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/Breakpoint.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/Breakpoint.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/Breakpoint.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/Breakpoint.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Aleksey V. Yantsen
+ * @version $Revision: 1.2 $
+ */
+
+/**
+ * Created on 12.03.2004
+ */
+package org.apache.harmony.jpda.tests.framework;
+
+/**
+ * This class provides info about breakpoint.
+ */
+public class Breakpoint {
+    public String className;
+    public String methodName;
+    public long   index;
+
+    /**
+     * Creates Breakpoint instance with default values.
+     */
+    Breakpoint() {
+        className = new String();
+        methodName = new String();
+        index = 0;
+    }
+
+    /**
+     * Creates Breakpoint instance with given data.
+     * 
+     * @param clazz Class in which breakpoint is created
+     * @param method Method in which breakpoint is created
+     * @param location Location within the method
+     */
+    public Breakpoint(String clazz, String method, int location) {
+        className = clazz;
+        methodName = method;
+        index = location;
+    }
+}
\ No newline at end of file

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/Breakpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/DebuggeeRegister.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/DebuggeeRegister.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/DebuggeeRegister.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/DebuggeeRegister.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.4 $
+ */
+
+/**
+ * Created on 04.02.2005
+ */
+package org.apache.harmony.jpda.tests.framework;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * This class defines an interface to keep an information about all started
+ * debuggees.
+ * <p>
+ * As a rule JPDA tests consist of two parts: the test that represents a
+ * part of the debugger-side application and the debuggee part. It is a good
+ * practice if the JPDA tests control debuggee's lifecycle (usually via JDWP
+ * channel), but in some cases it can not be done, for example because of
+ * product bugs.
+ * <p>
+ * This class is aimed to be an additional facility to stop each debuggee
+ * activity if it can not be done by the test in the regular way via JDWP
+ * channel.
+ */
+public class DebuggeeRegister {
+
+    LinkedList registered = new LinkedList();
+    
+    /**
+     * Registers started debuggee.
+     * 
+     * @param debuggee <code>DebuggeeWrapper</code> of the new started
+     * debuggee to register
+     */
+    public void register(DebuggeeWrapper debuggee) {
+       registered.add(debuggee); 
+    }
+
+    /**
+     * Unregisters specified debuggee.
+     * 
+     * @param debuggee <code>DebuggeeWrapper</code> of the debuggee to unregister
+     * returns true if debuggee was registered
+     */
+    public boolean unregister(DebuggeeWrapper debuggee) {
+        return registered.remove(debuggee);
+    }
+
+    /**
+     * Returns list of all registered DebuggeeWrappers.
+     * 
+     * @return array of DebuggeeWrappers
+     */
+    public List getAllRegistered() {
+        return registered;
+    }
+
+    /**
+     * Stops each of registered DebuggeeWrappers by invoking DebuggeeWrapper.stop().
+     */
+    public void stopAllRegistered() {
+        for (Iterator iter = registered.iterator(); iter.hasNext(); ) {
+            DebuggeeWrapper wrapper = (DebuggeeWrapper)iter.next();
+            if (wrapper != null) {
+                wrapper.stop();
+            }
+        }
+        registered.clear();
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/DebuggeeRegister.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/DebuggeeSynchronizer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/DebuggeeSynchronizer.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/DebuggeeSynchronizer.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/DebuggeeSynchronizer.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.3 $
+ */
+
+/**
+ * Created on 29.01.2005
+ */
+package org.apache.harmony.jpda.tests.framework;
+
+/**
+ * This interface is aimed to provide another way to synchronize execution of
+ * debugger and debuggee beyond the scope of JDWP channel.
+ * <p>
+ * Synchronization is performed by sending text messages. As an example,
+ * it can be implemented via TCP/IP sockets.
+ */
+public interface DebuggeeSynchronizer {
+
+    /**
+     * Sends specified string <code>message</code> to the channel.
+     * 
+     * @param message message to be sent
+     */
+    abstract public void sendMessage(String message);
+
+    /**
+     * Waits for specified message. If received string is equal to
+     * <code>message</code> then <code>true</code> returns.
+     *  
+     * @param message expected message
+     * @return <code>true</code> if received message is equal to
+     *         expected or <code>false</code> otherwise
+     */
+    abstract public boolean receiveMessage(String message);
+
+    /**
+     * Waits for any message from synchronized channel. 
+     *  
+     * @return received message
+     */
+    abstract public String receiveMessage();
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/DebuggeeSynchronizer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/DebuggeeWrapper.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/DebuggeeWrapper.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/DebuggeeWrapper.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/DebuggeeWrapper.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.4 $
+ */
+
+/**
+ * Created on 26.01.2005
+ */
+package org.apache.harmony.jpda.tests.framework;
+
+/**
+ * This class represents debuggee VM on debugger side.
+ * <p>
+ * This abstract class defines a set of commands to control debuggee VM.
+ * To provide the safely start up and shoot down of debuggee, an instance of
+ * <code>DebuggeeWrapper</code> should be registered in <code>DebuggeeRegister</code>.
+ * 
+ * @see DebuggeeRegister
+ */
+public abstract class DebuggeeWrapper {
+
+    protected TestOptions settings;
+    protected LogWriter logWriter;
+
+    /**
+     * Creates an instance of <code>DebuggeeWrapper</code>. 
+     * 
+     * @param settings specifies parameters for debuggee start
+     * @param logWriter provides unified facilities for logging 
+     */
+    public DebuggeeWrapper(TestOptions settings, LogWriter logWriter) {
+        super();
+        this.settings = settings;
+        this.logWriter = logWriter;
+    }
+
+    /**
+     * An implementation of this method must initiate the debuggee to start.
+     */
+    public abstract void start();
+
+    /**
+     * An implementation of this method must cause the debuggee to stop.
+     */
+    public abstract void stop();
+
+    /**
+     * An implementation of this method must cause the debuggee to exit
+     * with specified <code>exitStatus</code> .
+     * 
+     * @param exitStatus
+     */
+    public abstract void exit(int exitStatus);
+
+    /**
+     * An implementation of this method must cause the debuggee to resume.
+     */
+    public abstract void resume();
+
+    /**
+     * An implementation of this method must cause the debuggee to dispose.
+     */
+    public abstract void dispose();
+
+    /**
+     * Return associated logWriter object. 
+     * 
+     * @return associated logWriter
+     */
+    public LogWriter getLogWriter() {
+        return logWriter;
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/DebuggeeWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/LogWriter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/LogWriter.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/LogWriter.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/LogWriter.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.3 $
+ */
+
+/**
+ * Created on 29.01.2005
+ */
+package org.apache.harmony.jpda.tests.framework;
+
+/**
+ * This class defines minimal set of methods logging test execution.
+ */
+public abstract class LogWriter {
+
+    protected String prefix;
+
+    /**
+     * Creates instance of the class with given prefix for log messages.
+     *   
+     * @param prefix - specifies a prefix string
+     */
+    public LogWriter(String prefix) {
+        super();
+        setPrefix(prefix);
+    }
+
+    /**
+     * Returns prefix for messages.
+     * 
+     * @return prefix for messages
+     */
+    public synchronized String getPrefix() {
+        return prefix;
+    }
+
+    /**
+     * Sets prefix for messages.
+     * 
+     * @param prefix to be set
+     */
+    public synchronized void setPrefix(String prefix) {
+        this.prefix = prefix;
+    }
+
+    /**
+     * Prints message to this log.
+     * 
+     * @param message message to be printed
+     */
+    public abstract void printError(String message);
+
+    /**
+     * Prints exception info to this log with explaining message.
+     * 
+     * @param message message to be printed
+     * @param throwable exception to be printed
+     */
+    public abstract void printError(String message, Throwable throwable);
+
+    /**
+     * Prints exception info to this log with explaining message.
+     * 
+     * @param throwable exception to be printed
+     */
+    public abstract void printError(Throwable throwable);
+
+    /**
+     * Prints string to this log w/o line feed.
+     * 
+     * @param message message to be printed
+     */
+    public abstract void print(String message);
+
+    /**
+     * Prints a string to this log with line feed.
+     * 
+     * @param message message to be printed
+     */
+    public abstract void println(String message);
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/LogWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/StreamRedirector.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/StreamRedirector.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/StreamRedirector.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/StreamRedirector.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.3 $
+ */
+
+/**
+ * Created on 29.01.2005
+ */
+package org.apache.harmony.jpda.tests.framework;
+
+import java.io.InputStreamReader;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * <p>This class provides redirection of debuggee output and error streams to logWriter.
+ */
+public class StreamRedirector extends Thread {
+
+    String name;
+    LogWriter logWriter;
+    BufferedReader br;
+    boolean doExit;
+
+    /**
+     * Creates new redirector for the specified stream.
+     * 
+     * @param is stream to be redirected
+     * @param logWriter logWriter to redirect stream to
+     * @param name stream name used as prefix for redirected output
+     */
+    public StreamRedirector(InputStream is, LogWriter logWriter, String name) {
+        super("Redirector for " + name);
+        this.name = name;
+        this.logWriter = logWriter;
+        InputStreamReader isr = new InputStreamReader(is);
+        br = new BufferedReader(isr, 1024);
+        doExit = false;
+    }
+
+    /**
+     * Reads all lines from stream and puts them to logWriter.
+     */
+    public void run() {
+        logWriter.println("Redirector started: " + name);
+        try {
+            String line = "";
+            while (!doExit) {
+                try {
+                    line = br.readLine();
+                    if (line == null)
+                        break;
+                    
+                    logWriter.println(name + "> " + line);
+                } catch (IllegalStateException e) {
+                     //logWriter.printError("Illegal state exception! " + e);
+                    //ignore
+                }
+                
+            }
+            logWriter.println("Redirector completed: " + name);
+        } catch (IOException e) {
+            logWriter.printError(e);
+        }
+    }
+
+    /**
+     * Notifies redirector to stop stream redirection.
+     */
+    public void exit() {
+        doExit = true;
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/StreamRedirector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/TestErrorException.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/TestErrorException.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/TestErrorException.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/TestErrorException.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.5 $
+ */
+
+/**
+ * Created on 02.02.2005
+ */
+package org.apache.harmony.jpda.tests.framework;
+
+/**
+ * Unchecked exception to be thrown in JPDA tests and framework if any error occurs.
+ */
+public class TestErrorException extends RuntimeException {
+
+    /**
+     * Serialization id.
+     */
+    private static final long serialVersionUID = -3946549945049751489L;
+
+    /**
+     * Hide the default constructor but make it visible from 
+     * derived classes.   
+     */
+    protected TestErrorException() {
+    }
+    
+    /**
+     * Creates new exception instance with explaining message.
+     * 
+     * @param message cause explaining message
+     */
+    public TestErrorException(String message) {
+        super(message);
+    }
+
+    /**
+     * Creates new exception instance to enwrap other exception with explaining message.
+     * 
+     * @param message explaining message
+     * @param throwable exception to enwrap
+     */
+    public TestErrorException(String message, Throwable throwable) {
+        super(message, throwable);
+    }
+
+    /**
+     * Creates new exception instance to enwrap other exception w/o explaining message.
+     * 
+     * @param throwable exception to enwrap
+     */
+    public TestErrorException(Throwable throwable) {
+        super(throwable);
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/framework/TestErrorException.java
------------------------------------------------------------------------------
    svn:eol-style = native