src/hotspot/os/windows/attachListener_windows.cpp
changeset 55597 a128ba0b5f94
parent 51584 d395677d99f3
child 55682 70fab3a8ff02
equal deleted inserted replaced
55596:d01b345865d7 55597:a128ba0b5f94
   270 }
   270 }
   271 
   271 
   272 
   272 
   273 // open the pipe to the client
   273 // open the pipe to the client
   274 HANDLE Win32AttachOperation::open_pipe() {
   274 HANDLE Win32AttachOperation::open_pipe() {
   275   HANDLE hPipe;
   275   HANDLE hPipe = ::CreateFile( pipe(),  // pipe name
   276 
       
   277   hPipe = ::CreateFile( pipe(),  // pipe name
       
   278                         GENERIC_WRITE,   // write only
   276                         GENERIC_WRITE,   // write only
   279                         0,              // no sharing
   277                         0,              // no sharing
   280                         NULL,           // default security attributes
   278                         NULL,           // default security attributes
   281                         OPEN_EXISTING,  // opens existing pipe
   279                         OPEN_EXISTING,  // opens existing pipe
   282                         0,              // default attributes
   280                         0,              // default attributes
   283                         NULL);          // no template file
   281                         NULL);          // no template file
   284 
       
   285   if (hPipe != INVALID_HANDLE_VALUE) {
       
   286     // shouldn't happen as there is a pipe created per operation
       
   287     if (::GetLastError() == ERROR_PIPE_BUSY) {
       
   288       ::CloseHandle(hPipe);
       
   289       return INVALID_HANDLE_VALUE;
       
   290     }
       
   291   }
       
   292   return hPipe;
   282   return hPipe;
   293 }
   283 }
   294 
   284 
   295 // write to the pipe
   285 // write to the pipe
   296 BOOL Win32AttachOperation::write_pipe(HANDLE hPipe, char* buf, int len) {
   286 BOOL Win32AttachOperation::write_pipe(HANDLE hPipe, char* buf, int len) {
   305     if (!fSuccess) {
   295     if (!fSuccess) {
   306       return fSuccess;
   296       return fSuccess;
   307     }
   297     }
   308     buf += nwrote;
   298     buf += nwrote;
   309     len -= nwrote;
   299     len -= nwrote;
   310   }
   300   } while (len > 0);
   311   while (len > 0);
       
   312   return TRUE;
   301   return TRUE;
   313 }
   302 }
   314 
   303 
   315 // Complete the operation:
   304 // Complete the operation:
   316 //   - open the pipe to the client
   305 //   - open the pipe to the client
   324   thread->set_suspend_equivalent();
   313   thread->set_suspend_equivalent();
   325   // cleared by handle_special_suspend_equivalent_condition() or
   314   // cleared by handle_special_suspend_equivalent_condition() or
   326   // java_suspend_self() via check_and_wait_while_suspended()
   315   // java_suspend_self() via check_and_wait_while_suspended()
   327 
   316 
   328   HANDLE hPipe = open_pipe();
   317   HANDLE hPipe = open_pipe();
       
   318   int lastError = (int)::GetLastError();
   329   if (hPipe != INVALID_HANDLE_VALUE) {
   319   if (hPipe != INVALID_HANDLE_VALUE) {
   330     BOOL fSuccess;
   320     BOOL fSuccess;
   331 
   321 
   332     char msg[32];
   322     char msg[32];
   333     _snprintf(msg, sizeof(msg), "%d\n", result);
   323     _snprintf(msg, sizeof(msg), "%d\n", result);
   335 
   325 
   336     fSuccess = write_pipe(hPipe, msg, (int)strlen(msg));
   326     fSuccess = write_pipe(hPipe, msg, (int)strlen(msg));
   337     if (fSuccess) {
   327     if (fSuccess) {
   338       fSuccess = write_pipe(hPipe, (char*)result_stream->base(), (int)(result_stream->size()));
   328       fSuccess = write_pipe(hPipe, (char*)result_stream->base(), (int)(result_stream->size()));
   339     }
   329     }
       
   330     lastError = (int)::GetLastError();
   340 
   331 
   341     // Need to flush buffers
   332     // Need to flush buffers
   342     FlushFileBuffers(hPipe);
   333     FlushFileBuffers(hPipe);
   343     CloseHandle(hPipe);
   334     CloseHandle(hPipe);
   344 
   335 
   345     if (fSuccess) {
   336     if (fSuccess) {
   346       log_debug(attach)("wrote result of attach operation %s to pipe %s", name(), pipe());
   337       log_debug(attach)("wrote result of attach operation %s to pipe %s", name(), pipe());
   347     } else {
   338     } else {
   348       log_error(attach)("failure writing result of operation %s to pipe %s", name(), pipe());
   339       log_error(attach)("failure (%d) writing result of operation %s to pipe %s", lastError, name(), pipe());
   349     }
   340     }
   350   } else {
   341   } else {
   351     log_error(attach)("could not open pipe %s to send result of operation %s", pipe(), name());
   342     log_error(attach)("could not open (%d) pipe %s to send result of operation %s", lastError, pipe(), name());
   352   }
   343   }
   353 
   344 
   354   DWORD res = ::WaitForSingleObject(Win32AttachListener::mutex(), INFINITE);
   345   DWORD res = ::WaitForSingleObject(Win32AttachListener::mutex(), INFINITE);
   355   if (res == WAIT_OBJECT_0) {
   346   if (res == WAIT_OBJECT_0) {
   356 
   347