Changeset 37596 in vbox for trunk/src/VBox/Main
- Timestamp:
- Jun 22, 2011 7:30:06 PM (14 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/USBProxyService.h
r36993 r37596 256 256 private: 257 257 /** File handle to the '/proc/bus/usb/devices' file. */ 258 RTFILE m File;258 RTFILE mhFile; 259 259 /** Pipe used to interrupt wait(), the read end. */ 260 RT FILE mWakeupPipeR;260 RTPIPE mhWakeupPipeR; 261 261 /** Pipe used to interrupt wait(), the write end. */ 262 RT FILE mWakeupPipeW;262 RTPIPE mhWakeupPipeW; 263 263 /** The root of usbfs. */ 264 264 Utf8Str mDevicesRoot; -
trunk/src/VBox/Main/src-server/linux/USBProxyServiceLinux.cpp
r36997 r37596 39 39 #include <iprt/param.h> 40 40 #include <iprt/path.h> 41 #include <iprt/pipe.h> 41 42 #include <iprt/stream.h> 42 43 #include <iprt/linux/sysfs.h> … … 60 61 */ 61 62 USBProxyServiceLinux::USBProxyServiceLinux(Host *aHost) 62 : USBProxyService(aHost), m File(NIL_RTFILE), mWakeupPipeR(NIL_RTFILE),63 m WakeupPipeW(NIL_RTFILE), mUsingUsbfsDevices(true /* see init */),63 : USBProxyService(aHost), mhFile(NIL_RTFILE), mhWakeupPipeR(NIL_RTPIPE), 64 mhWakeupPipeW(NIL_RTPIPE), mUsingUsbfsDevices(true /* see init */), 64 65 mUdevPolls(0), mpWaiter(NULL) 65 66 #ifdef UNIT_TEST … … 209 210 if (pszDevices) 210 211 { 211 rc = RTFileOpen(&m File, pszDevices, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);212 rc = RTFileOpen(&mhFile, pszDevices, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 212 213 if (RT_SUCCESS(rc)) 213 214 { 214 int pipes[2];215 if ( !pipe(pipes))215 rc = RTPipeCreate(&mhWakeupPipeR, &mhWakeupPipeW, 0 /*fFlags*/); 216 if (RT_SUCCESS(rc)) 216 217 { 217 /* Set close on exec (race here!) */ 218 if ( fcntl(pipes[0], F_SETFD, FD_CLOEXEC) >= 0 219 && fcntl(pipes[1], F_SETFD, FD_CLOEXEC) >= 0) 218 /* 219 * Start the poller thread. 220 */ 221 rc = start(); 222 if (RT_SUCCESS(rc)) 220 223 { 221 mWakeupPipeR = pipes[0]; 222 mWakeupPipeW = pipes[1]; 223 /* 224 * Start the poller thread. 225 */ 226 rc = start(); 227 if (RT_SUCCESS(rc)) 228 { 229 RTStrFree(pszDevices); 230 LogFlowThisFunc(("returns successfully - mWakeupPipeR/W=%d/%d\n", 231 mWakeupPipeR, mWakeupPipeW)); 232 return VINF_SUCCESS; 233 } 234 235 RTFileClose(mWakeupPipeR); 236 RTFileClose(mWakeupPipeW); 237 mWakeupPipeW = mWakeupPipeR = NIL_RTFILE; 224 RTStrFree(pszDevices); 225 LogFlowThisFunc(("returns successfully\n")); 226 return VINF_SUCCESS; 238 227 } 239 else 240 { 241 rc = RTErrConvertFromErrno(errno); 242 Log(("USBProxyServiceLinux::USBProxyServiceLinux: fcntl failed, errno=%d\n", errno)); 243 close(pipes[0]); 244 close(pipes[1]); 245 } 228 229 RTPipeClose(mhWakeupPipeR); 230 RTPipeClose(mhWakeupPipeW); 231 mhWakeupPipeW = mhWakeupPipeR = NIL_RTPIPE; 246 232 } 247 233 else 248 { 249 rc = RTErrConvertFromErrno(errno); 250 Log(("USBProxyServiceLinux::USBProxyServiceLinux: pipe failed, errno=%d\n", errno)); 251 } 252 RTFileClose(mFile); 234 Log(("USBProxyServiceLinux::USBProxyServiceLinux: RTFilePipe failed with rc=%Rrc\n", rc)); 235 RTFileClose(mhFile); 253 236 } 254 237 … … 332 315 * Free resources. 333 316 */ 334 if (mFile != NIL_RTFILE) 335 { 336 RTFileClose(mFile); 337 mFile = NIL_RTFILE; 338 } 339 340 if (mWakeupPipeR != NIL_RTFILE) 341 RTFileClose(mWakeupPipeR); 342 if (mWakeupPipeW != NIL_RTFILE) 343 RTFileClose(mWakeupPipeW); 344 mWakeupPipeW = mWakeupPipeR = NIL_RTFILE; 317 RTFileClose(mhFile); 318 mhFile = NIL_RTFILE; 319 320 RTPipeClose(mhWakeupPipeR); 321 RTPipeClose(mhWakeupPipeW); 322 mhWakeupPipeW = mhWakeupPipeR = NIL_RTPIPE; 345 323 } 346 324 … … 434 412 435 413 memset(&PollFds, 0, sizeof(PollFds)); 436 PollFds[0].fd = mFile;414 PollFds[0].fd = RTFileToNative(mhFile); 437 415 PollFds[0].events = POLLIN; 438 PollFds[1].fd = mWakeupPipeR;416 PollFds[1].fd = RTPipeToNative(mhWakeupPipeR); 439 417 PollFds[1].events = POLLIN | POLLERR | POLLHUP; 440 418 … … 448 426 { 449 427 char szBuf[WAKE_UP_STRING_LEN]; 450 rc = RT FileRead(mWakeupPipeR, szBuf, sizeof(szBuf), NULL);428 rc = RTPipeReadBlocking(mhWakeupPipeR, szBuf, sizeof(szBuf), NULL); 451 429 AssertRC(rc); 452 430 } … … 484 462 } 485 463 #endif /* VBOX_USB_WITH_SYSFS */ 486 int rc = RT FileWrite(mWakeupPipeW, WAKE_UP_STRING, WAKE_UP_STRING_LEN, NULL);464 int rc = RTPipeWriteBlocking(mhWakeupPipeW, WAKE_UP_STRING, WAKE_UP_STRING_LEN, NULL); 487 465 if (RT_SUCCESS(rc)) 488 RT FileFlush(mWakeupPipeW);466 RTPipeFlush(mhWakeupPipeW); 489 467 LogFlowFunc(("returning %Rrc\n", rc)); 490 468 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.