jdk/src/share/transport/socket/socketTransport.c
changeset 3723 a27278866f80
parent 1247 b4c26443dee5
child 5506 202f599c92aa
equal deleted inserted replaced
3722:08849c86a297 3723:a27278866f80
   132     return JDWPTRANSPORT_ERROR_NONE;
   132     return JDWPTRANSPORT_ERROR_NONE;
   133 }
   133 }
   134 
   134 
   135 static jdwpTransportError
   135 static jdwpTransportError
   136 handshake(int fd, jlong timeout) {
   136 handshake(int fd, jlong timeout) {
   137     char *hello = "JDWP-Handshake";
   137     const char *hello = "JDWP-Handshake";
   138     char b[16];
   138     char b[16];
   139     int rv, received, i;
   139     int rv, helloLen, received;
   140 
   140 
   141     if (timeout > 0) {
   141     if (timeout > 0) {
   142         dbgsysConfigureBlocking(fd, JNI_FALSE);
   142         dbgsysConfigureBlocking(fd, JNI_FALSE);
   143     }
   143     }
       
   144     helloLen = (int)strlen(hello);
   144     received = 0;
   145     received = 0;
   145     while (received < (int)strlen(hello)) {
   146     while (received < helloLen) {
   146         int n;
   147         int n;
   147         char *buf;
   148         char *buf;
   148         if (timeout > 0) {
   149         if (timeout > 0) {
   149             rv = dbgsysPoll(fd, JNI_TRUE, JNI_FALSE, (long)timeout);
   150             rv = dbgsysPoll(fd, JNI_TRUE, JNI_FALSE, (long)timeout);
   150             if (rv <= 0) {
   151             if (rv <= 0) {
   152                 return JDWPTRANSPORT_ERROR_IO_ERROR;
   153                 return JDWPTRANSPORT_ERROR_IO_ERROR;
   153             }
   154             }
   154         }
   155         }
   155         buf = b;
   156         buf = b;
   156         buf += received;
   157         buf += received;
   157         n = dbgsysRecv(fd, buf, (int)strlen(hello)-received, 0);
   158         n = dbgsysRecv(fd, buf, helloLen-received, 0);
   158         if (n == 0) {
   159         if (n == 0) {
   159             setLastError(0, "handshake failed - connection prematurally closed");
   160             setLastError(0, "handshake failed - connection prematurally closed");
   160             return JDWPTRANSPORT_ERROR_IO_ERROR;
   161             return JDWPTRANSPORT_ERROR_IO_ERROR;
   161         }
   162         }
   162         if (n < 0) {
   163         if (n < 0) {
   165         received += n;
   166         received += n;
   166     }
   167     }
   167     if (timeout > 0) {
   168     if (timeout > 0) {
   168         dbgsysConfigureBlocking(fd, JNI_TRUE);
   169         dbgsysConfigureBlocking(fd, JNI_TRUE);
   169     }
   170     }
   170     for (i=0; i<(int)strlen(hello); i++) {
   171     if (strncmp(b, hello, received) != 0) {
   171         if (b[i] != hello[i]) {
   172         char msg[80+2*16];
   172             char msg[64];
   173         b[received] = '\0';
   173             strcpy(msg, "handshake failed - received >");
   174         /*
   174             strncat(msg, b, strlen(hello));
   175          * We should really use snprintf here but it's not available on Windows.
   175             strcat(msg, "< - excepted >");
   176          * We can't use jio_snprintf without linking the transport against the VM.
   176             strcat(msg, hello);
   177          */
   177             strcat(msg, "<");
   178         sprintf(msg, "handshake failed - received >%s< - expected >%s<", b, hello);
   178             setLastError(0, msg);
   179         setLastError(0, msg);
   179             return JDWPTRANSPORT_ERROR_IO_ERROR;
   180         return JDWPTRANSPORT_ERROR_IO_ERROR;
   180         }
   181     }
   181     }
   182 
   182 
   183     if (dbgsysSend(fd, (char*)hello, helloLen, 0) != helloLen) {
   183     if (dbgsysSend(fd, hello, (int)strlen(hello), 0) != (int)strlen(hello)) {
       
   184         RETURN_IO_ERROR("send failed during handshake");
   184         RETURN_IO_ERROR("send failed during handshake");
   185     }
   185     }
   186     return JDWPTRANSPORT_ERROR_NONE;
   186     return JDWPTRANSPORT_ERROR_NONE;
   187 }
   187 }
   188 
   188