VirtualBox

Changeset 58295 in vbox


Ignore:
Timestamp:
Oct 18, 2015 1:28:34 PM (9 years ago)
Author:
vboxsync
Message:

iprt: Added RTLocalIpcSessionReadNB on posix systems.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/localipc.h

    r58293 r58295  
    161161
    162162/**
     163 * Receive pending data from the other end of an local IPC session.
     164 *
     165 * This will not block to wait for data.
     166 *
     167 * @returns IPRT status code.
     168 * @retval  VINF_TRY_AGAIN if no pending data (*pcbRead is set to 0).
     169 * @retval  VERR_CANCELLED if a previous operation was cancelled by
     170 *          RTLocalIpcSessionCancel (this operation isn't cancellable).
     171 *
     172 * @param   hSession            The session handle.
     173 * @param   pvBuf               Where to store the data.
     174 * @param   cbToRead            How much to read (upper limit).
     175 * @param   pcbRead             Where to return exactly how much was read.
     176 */
     177RTDECL(int) RTLocalIpcSessionReadNB(RTLOCALIPCSESSION hSession, void *pvBuf, size_t cbToRead, size_t *pcbRead);
     178
     179/**
    163180 * Send data to the other end of an local IPC session.
    164181 *
     
    190207
    191208/**
    192  * Wait for data to become ready for reading or for the
    193  * session to be disconnected.
     209 * Wait for data to become ready for reading or for the session to be
     210 * disconnected.
    194211 *
    195212 * @returns IPRT status code.
     
    212229 *
    213230 * Not all methods are cancellable, only those which are specfied
    214  * returning VERR_CANCELLED. The others are assumed to not be blocking
    215  * for ever and ever.
     231 * returning VERR_CANCELLED.  The others are assumed to not be blocking
     232 * for ever and ever.  However, the cancel is sticky, so the session must
     233 * basically be trashed (closed) after calling this method.
    216234 *
    217235 * @returns IPRT status code.
  • trunk/include/iprt/mangling.h

    r58285 r58295  
    742742# define RTLocalIpcSessionCancel                        RT_MANGLER(RTLocalIpcSessionCancel)
    743743# define RTLocalIpcSessionRead                          RT_MANGLER(RTLocalIpcSessionRead)
     744# define RTLocalIpcSessionReadNB                        RT_MANGLER(RTLocalIpcSessionReadNB)
    744745# define RTLocalIpcSessionWrite                         RT_MANGLER(RTLocalIpcSessionWrite)
    745746# define RTLocalIpcSessionFlush                         RT_MANGLER(RTLocalIpcSessionFlush)
  • trunk/src/VBox/Runtime/r3/posix/localipc-posix.cpp

    r58294 r58295  
    727727
    728728
     729RTDECL(int) RTLocalIpcSessionReadNB(RTLOCALIPCSESSION hSession, void *pvBuf, size_t cbToRead, size_t *pcbRead)
     730{
     731    /*
     732     * Validate input.
     733     */
     734    PRTLOCALIPCSESSIONINT pThis = hSession;
     735    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     736    AssertReturn(pThis->u32Magic == RTLOCALIPCSESSION_MAGIC, VERR_INVALID_HANDLE);
     737
     738    /*
     739     * Do the job.
     740     */
     741    rtLocalIpcSessionRetain(pThis);
     742
     743    int rc = RTCritSectEnter(&pThis->CritSect);
     744    if (RT_SUCCESS(rc))
     745    {
     746        if (pThis->hReadThread == NIL_RTTHREAD)
     747        {
     748            pThis->hReadThread = RTThreadSelf(); /* not really required, but whatever. */
     749
     750            for (;;)
     751            {
     752                if (!pThis->fCancelled)
     753                {
     754                    rc = RTSocketReadNB(pThis->hSocket, pvBuf, cbToRead, pcbRead);
     755
     756                    /* Detect broken pipe. */
     757                    if (rc == VINF_SUCCESS)
     758                    {
     759                        if (!pcbRead || *pcbRead)
     760                        { /* likely */ }
     761                        else if (rtLocalIpcPosixHasHup(pThis))
     762                            rc = VERR_BROKEN_PIPE;
     763                    }
     764                    else if (rc == VERR_NET_CONNECTION_RESET_BY_PEER || rc == VERR_NET_SHUTDOWN)
     765                        rc = VERR_BROKEN_PIPE;
     766
     767                    if (rc == VERR_INTERRUPTED)
     768                        continue;
     769                }
     770                else
     771                    rc = VERR_CANCELLED;
     772                break;
     773            }
     774
     775            pThis->hReadThread = NIL_RTTHREAD;
     776        }
     777        int rc2 = RTCritSectLeave(&pThis->CritSect);
     778        AssertStmt(RT_SUCCESS(rc2), rc = RT_SUCCESS(rc) ? rc2 : rc);
     779    }
     780
     781    rtLocalIpcSessionRelease(pThis);
     782    return rc;
     783}
     784
     785
    729786RTDECL(int) RTLocalIpcSessionWrite(RTLOCALIPCSESSION hSession, const void *pvBuf, size_t cbToWrite)
    730787{
  • trunk/src/VBox/Runtime/r3/socket.cpp

    r58282 r58295  
    12201220    if (cbRead >= 0)
    12211221        *pcbRead = cbRead;
    1222     else if (errno == EAGAIN)
     1222    else if (   errno == EAGAIN
     1223# ifdef EWOULDBLOCK
     1224             || errno == EWOULDBLOCK
     1225# endif
     1226             )
    12231227    {
    12241228        *pcbRead = 0;
     
    12721276    if (cbWritten >= 0)
    12731277        *pcbWritten = cbWritten;
    1274     else if (errno == EAGAIN)
     1278    else if (   errno == EAGAIN
     1279# ifdef EWOULDBLOCK
     1280             || errno == EWOULDBLOCK
     1281# endif
     1282            )
    12751283    {
    12761284        *pcbWritten = 0;
  • trunk/src/VBox/Runtime/testcase/tstRTLocalIpc.cpp

    r58291 r58295  
    9292    RTTESTI_CHECK_RC_RETV(rc = RTLocalIpcSessionConnect(&hIpcSession, "BasicTest", 0), VERR_FILE_NOT_FOUND);
    9393    if (RT_SUCCESS(rc)) RTLocalIpcSessionClose(hIpcSession);
    94     RTTESTI_CHECK_RC(RTLocalIpcServerCancel(hIpcServer), VERR_INVALID_HANDLE);
    95     RTTESTI_CHECK_RC(RTLocalIpcServerDestroy(hIpcServer), VERR_INVALID_HANDLE);
     94    //RTTESTI_CHECK_RC(RTLocalIpcServerCancel(hIpcServer), VERR_INVALID_HANDLE);  - accessing freed memory, bad idea.
     95    //RTTESTI_CHECK_RC(RTLocalIpcServerDestroy(hIpcServer), VERR_INVALID_HANDLE); - accessing freed memory, bad idea.
    9696}
    9797
     
    273273    RTTESTI_CHECK_RC(RTLocalIpcSessionWaitForData(hClientSession, 0 /*cMsTimeout*/), VERR_TIMEOUT);
    274274    RTTESTI_CHECK_RC(RTLocalIpcSessionWaitForData(hClientSession, 8 /*cMsTimeout*/), VERR_TIMEOUT);
     275    uint8_t abBuf[4];
     276    size_t cbRead = _4M-1;
     277#ifndef RT_OS_WINDOWS
     278    RTTESTI_CHECK_RC(RTLocalIpcSessionReadNB(hClientSession, abBuf, sizeof(abBuf), &cbRead), VINF_TRY_AGAIN);
     279    RTTESTI_CHECK(cbRead == 0);
     280#endif
    275281
    276282    /* Trigger server disconnect. */
     
    291297
    292298        RTTESTI_CHECK_RC(RTLocalIpcSessionWrite(hClientSession, RT_STR_TUPLE("broken")), VERR_BROKEN_PIPE);
    293         uint8_t abBuf[4];
    294299        RTTESTI_CHECK_RC(RTLocalIpcSessionRead(hClientSession, abBuf, sizeof(abBuf), NULL), VERR_BROKEN_PIPE);
    295         size_t cbRead = _4M-1;
     300        cbRead = _4M-1;
    296301        RTTESTI_CHECK_RC(RTLocalIpcSessionRead(hClientSession, abBuf, sizeof(abBuf), &cbRead), VERR_BROKEN_PIPE);
     302#ifndef RT_OS_WINDOWS
     303        cbRead = _1G/2;
     304        RTTESTI_CHECK_RC(RTLocalIpcSessionReadNB(hClientSession, abBuf, sizeof(abBuf), &cbRead), VERR_BROKEN_PIPE);
     305#endif
    297306
    298307        RTAssertSetMayPanic(fMayPanic);
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