VirtualBox

Changeset 33729 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Nov 3, 2010 3:13:21 PM (14 years ago)
Author:
vboxsync
Message:

Serial/DevHostSerial: properly handle non-blocking I/O

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Serial/DrvHostSerial.cpp

    r33728 r33729  
    501501         * Write the character to the host device.
    502502         */
    503 #ifdef RT_OS_DARWIN
    504503        while (pThread->enmState == PDMTHREADSTATE_RUNNING)
    505504        {
     
    593592            }
    594593        } /* write loop */
    595 
    596 #else /* old code */
    597         uint32_t iTail;
    598         while (   pThread->enmState == PDMTHREADSTATE_RUNNING
    599                && (iTail = ASMAtomicUoReadU32(&pThis->iSendQueueTail)) != ASMAtomicUoReadU32(&pThis->iSendQueueHead))
    600         {
    601             /** @todo process more than one byte? */
    602             unsigned cbProcessed = 1;
    603             uint8_t abBuf[1];
    604             abBuf[0] = pThis->aSendQueue[iTail];
    605 
    606 # if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
    607 
    608             rc = RTFileWrite(pThis->DeviceFile, abBuf, cbProcessed, NULL);
    609 
    610 # elif defined(RT_OS_WINDOWS)
    611 
    612             DWORD cbBytesWritten;
    613             memset(&pThis->overlappedSend, 0, sizeof(pThis->overlappedSend));
    614             pThis->overlappedSend.hEvent = pThis->hEventSend;
    615 
    616             if (!WriteFile(pThis->hDeviceFile, abBuf, cbProcessed, &cbBytesWritten, &pThis->overlappedSend))
    617             {
    618                 dwRet = GetLastError();
    619                 if (dwRet == ERROR_IO_PENDING)
    620                 {
    621                     /*
    622                      * write blocked, wait ...
    623                      */
    624                     dwRet = WaitForMultipleObjects(2, haWait, FALSE, INFINITE);
    625                     if (dwRet != WAIT_OBJECT_0)
    626                     {
    627                         AssertMsg(pThread->enmState != PDMTHREADSTATE_RUNNING, ("The halt event semaphore is set but the thread is still in running state\n"));
    628                         break;
    629                     }
    630                 }
    631                 else
    632                     rc = RTErrConvertFromWin32(dwRet);
    633             }
    634 
    635 # endif
    636 
    637             if (RT_SUCCESS(rc))
    638             {
    639                 Assert(cbProcessed == 1);
    640                 ASMAtomicWriteU32(&pThis->iSendQueueTail, (iTail + 1) & CHAR_MAX_SEND_QUEUE_MASK);
    641             }
    642             else if (RT_FAILURE(rc))
    643             {
    644                 LogRel(("HostSerial#%d: Serial Write failed with %Rrc; terminating send thread\n", pDrvIns->iInstance, rc));
    645                 return rc;
    646             }
    647         }
    648 #endif /* old code */
    649594    }
    650595
     
    13641309    uint32_t fOpen = RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE;
    13651310# ifdef RT_OS_LINUX
    1366     /* This seems to be necessary on some Linux hosts, otherwise we hang here forever.
    1367      * Surprisingly, I've never seen VERR_TRY_AGAIN as result even if RTFileOpen()
    1368      * would block without that flag. */
     1311    /* This seems to be necessary on some Linux hosts, otherwise we hang here forever. */
    13691312    fOpen |= RTFILE_O_NON_BLOCK;
    13701313# endif
    13711314    rc = RTFileOpen(&pThis->DeviceFile, pThis->pszDevicePath, fOpen);
    13721315# ifdef RT_OS_LINUX
     1316    /* RTFILE_O_NON_BLOCK not supported? */
    13731317    if (rc == VERR_INVALID_PARAMETER)
    13741318        rc = RTFileOpen(&pThis->DeviceFile, pThis->pszDevicePath, fOpen & ~RTFILE_O_NON_BLOCK);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette