Changeset 5756 in vbox for trunk/src/VBox
- Timestamp:
- Nov 15, 2007 1:41:03 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Serial/DrvNamedPipe.cpp
r4372 r5756 70 70 #ifdef RT_OS_WINDOWS 71 71 /* File handle of the named pipe. */ 72 RTFILE NamedPipe;72 HANDLE NamedPipe; 73 73 /* Overlapped structure for writes. */ 74 74 OVERLAPPED OverlappedWrite; … … 104 104 Assert(pvBuf); 105 105 #ifdef RT_OS_WINDOWS 106 if (pData->NamedPipe != NIL_RTFILE)106 if (pData->NamedPipe != INVALID_HANDLE_VALUE) 107 107 { 108 108 DWORD cbReallyRead; 109 109 pData->OverlappedRead.Offset = 0; 110 110 pData->OverlappedRead.OffsetHigh = 0; 111 if (!ReadFile( (HANDLE)pData->NamedPipe, pvBuf, *cbRead, &cbReallyRead, &pData->OverlappedRead))111 if (!ReadFile(pData->NamedPipe, pvBuf, *cbRead, &cbReallyRead, &pData->OverlappedRead)) 112 112 { 113 113 DWORD uError = GetLastError(); … … 129 129 130 130 /* Wait for incoming bytes. */ 131 if (GetOverlappedResult( (HANDLE)pData->NamedPipe, &pData->OverlappedRead, &cbReallyRead, TRUE) == FALSE)131 if (GetOverlappedResult(pData->NamedPipe, &pData->OverlappedRead, &cbReallyRead, TRUE) == FALSE) 132 132 uError = GetLastError(); 133 133 } … … 148 148 149 149 { 150 RTFILE tmp = pData->NamedPipe; 151 FlushFileBuffers((HANDLE)tmp); 152 DisconnectNamedPipe((HANDLE)tmp); 150 FlushFileBuffers(pData->NamedPipe); 151 DisconnectNamedPipe(pData->NamedPipe); 153 152 if (!pData->fIsServer) 154 153 { 155 pData->NamedPipe = NIL_RTFILE;156 RTFileClose(tmp);154 CloseHandle(pData->NamedPipe); 155 pData->NamedPipe = INVALID_HANDLE_VALUE; 157 156 } 158 157 /* pretend success */ … … 202 201 Assert(pvBuf); 203 202 #ifdef RT_OS_WINDOWS 204 if (pData->NamedPipe != NIL_RTFILE)203 if (pData->NamedPipe != INVALID_HANDLE_VALUE) 205 204 { 206 205 unsigned cbWritten; 207 206 pData->OverlappedWrite.Offset = 0; 208 207 pData->OverlappedWrite.OffsetHigh = 0; 209 if (!WriteFile( (HANDLE)pData->NamedPipe, pvBuf, *cbWrite, NULL, &pData->OverlappedWrite))208 if (!WriteFile(pData->NamedPipe, pvBuf, *cbWrite, NULL, &pData->OverlappedWrite)) 210 209 { 211 210 DWORD uError = GetLastError(); … … 226 225 { 227 226 /* Wait for the write to complete. */ 228 if (GetOverlappedResult( (HANDLE)pData->NamedPipe, &pData->OverlappedWrite, (DWORD *)&cbWritten, TRUE) == FALSE)227 if (GetOverlappedResult(pData->NamedPipe, &pData->OverlappedWrite, (DWORD *)&cbWritten, TRUE) == FALSE) 229 228 uError = GetLastError(); 230 229 } … … 238 237 || rc == VERR_BROKEN_PIPE) 239 238 { 240 RTFILE tmp = pData->NamedPipe; 241 FlushFileBuffers((HANDLE)tmp); 242 DisconnectNamedPipe((HANDLE)tmp); 239 FlushFileBuffers(pData->NamedPipe); 240 DisconnectNamedPipe(pData->NamedPipe); 243 241 if (!pData->fIsServer) 244 242 { 245 pData->NamedPipe = NIL_RTFILE;246 RTFileClose(tmp);243 CloseHandle(pData->NamedPipe); 244 pData->NamedPipe = INVALID_HANDLE_VALUE; 247 245 } 248 246 /* pretend success */ … … 317 315 int rc = VINF_SUCCESS; 318 316 #ifdef RT_OS_WINDOWS 319 RTFILE NamedPipe = pData->NamedPipe;317 HANDLE NamedPipe = pData->NamedPipe; 320 318 HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, 0); 321 319 #endif … … 329 327 overlapped.hEvent = hEvent; 330 328 331 BOOL fConnected = ConnectNamedPipe( (HANDLE)NamedPipe, &overlapped);329 BOOL fConnected = ConnectNamedPipe(NamedPipe, &overlapped); 332 330 if ( !fConnected 333 331 && !pData->fShutdown) … … 340 338 341 339 hrc = 0; 342 if (GetOverlappedResult( (HANDLE)pData->NamedPipe, &overlapped, &dummy, TRUE) == FALSE)340 if (GetOverlappedResult(pData->NamedPipe, &overlapped, &dummy, TRUE) == FALSE) 343 341 hrc = GetLastError(); 344 342 … … 417 415 pData->fIsServer = false; 418 416 #ifdef RT_OS_WINDOWS 419 pData->NamedPipe = NIL_RTFILE;417 pData->NamedPipe = INVALID_HANDLE_VALUE; 420 418 #else /* !RT_OS_WINDOWS */ 421 419 pData->LocalSocketServer = NIL_RTSOCKET; … … 464 462 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("NamedPipe#%d failed to create named pipe %s"), pDrvIns->iInstance, pszLocation); 465 463 } 466 pData->NamedPipe = (HFILE)hPipe;464 pData->NamedPipe = hPipe; 467 465 468 466 rc = RTThreadCreate(&pData->ListenThread, drvNamedPipeListenLoop, (void *)pData, 0, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "NamedPipe"); … … 476 474 { 477 475 /* Connect to the named pipe. */ 478 rc = RTFileOpen(&pData->NamedPipe, pszLocation, RTFILE_O_READWRITE); 479 if (VBOX_FAILURE(rc)) 476 HANDLE hPipe = CreateFile(pData->pszLocation, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); 477 if (hPipe == INVALID_HANDLE_VALUE) 478 { 479 rc = RTErrConvertFromWin32(GetLastError()); 480 LogRel(("NamedPipe%d: CreateFile failed rc=%Vrc\n", pData->pDrvIns->iInstance)); 480 481 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("NamedPipe#%d failed to connect to named pipe %s"), pDrvIns->iInstance, pszLocation); 482 } 483 pData->NamedPipe = hPipe; 481 484 } 482 485 … … 571 574 572 575 #ifdef RT_OS_WINDOWS 573 if (pData->NamedPipe != NIL_RTFILE) 574 { 575 FlushFileBuffers((HANDLE)pData->NamedPipe); 576 if (!pData->fIsServer) 577 DisconnectNamedPipe((HANDLE)pData->NamedPipe); 578 579 RTFileClose(pData->NamedPipe); 580 pData->NamedPipe = NIL_RTFILE; 576 if (pData->NamedPipe != INVALID_HANDLE_VALUE) 577 { 578 if (pData->fIsServer) 579 { 580 FlushFileBuffers(pData->NamedPipe); 581 DisconnectNamedPipe(pData->NamedPipe); 582 } 583 584 CloseHandle(pData->NamedPipe); 585 pData->NamedPipe = INVALID_HANDLE_VALUE; 581 586 CloseHandle(pData->OverlappedRead.hEvent); 582 587 CloseHandle(pData->OverlappedWrite.hEvent); 583 588 } 584 /* Wake up listen thread */ 585 RTSemEventSignal(pData->ListenSem); 586 RTSemEventDestroy(pData->ListenSem); 589 if (pData->fIsServer) 590 { 591 /* Wake up listen thread */ 592 RTSemEventSignal(pData->ListenSem); 593 RTSemEventDestroy(pData->ListenSem); 594 } 587 595 #else /* !RT_OS_WINDOWS */ 588 596 if (pData->fIsServer)
Note:
See TracChangeset
for help on using the changeset viewer.