src/hotspot/os/windows/attachListener_windows.cpp
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 51584 d395677d99f3
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   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 
   388   // nothing to do
   379   // nothing to do
   389 }
   380 }
   390 
   381 
   391 int AttachListener::pd_init() {
   382 int AttachListener::pd_init() {
   392   return Win32AttachListener::init();
   383   return Win32AttachListener::init();
       
   384 }
       
   385 
       
   386 // This function is used for Un*x OSes only.
       
   387 // We need not to implement it for Windows.
       
   388 bool AttachListener::check_socket_file() {
       
   389   return false;
   393 }
   390 }
   394 
   391 
   395 bool AttachListener::init_at_startup() {
   392 bool AttachListener::init_at_startup() {
   396   return true;
   393   return true;
   397 }
   394 }