VirtualBox

Changeset 26784 in vbox for trunk


Ignore:
Timestamp:
Feb 25, 2010 11:56:52 AM (15 years ago)
Author:
vboxsync
Message:

iprt/pipe.h++: Adjusted RTPipeWrite[Blocking] behavior wrt to zero byte writes and broken pipes. (darwin will return EPIPE, linux does not.)

Location:
trunk
Files:
3 edited

Legend:

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

    r26774 r26784  
    118118 * @returns IPRT status code.
    119119 * @retval  VERR_WRONG_ORDER if racing a call to RTPipeWriteBlocking.
    120  * @retval  VERR_BROKEN_PIPE if the remote party has disconnected.
     120 * @retval  VERR_BROKEN_PIPE if the remote party has disconnected.  Does not
     121 *          trigger when @a cbToWrite is 0.
    121122 * @retval  VINF_TRY_AGAIN if no data was written.  @a *pcbWritten will be set
    122123 *          to 0.
     
    135136 * @returns IPRT status code.
    136137 * @retval  VERR_WRONG_ORDER if racing a call to RTPipeWrite.
    137  * @retval  VERR_BROKEN_PIPE if the remote party has disconnected.
     138 * @retval  VERR_BROKEN_PIPE if the remote party has disconnected.  Does not
     139 *          trigger when @a cbToWrite is 0.
    138140 * @retval  VERR_ACCESS_DENIED if it's a read pipe.
    139141 *
  • trunk/src/VBox/Runtime/r3/posix/pipe-posix.cpp

    r26774 r26784  
    378378    if (RT_SUCCESS(rc))
    379379    {
    380         do
     380        while (cbToRead > 0)
    381381        {
    382382            ssize_t cbRead = read(pThis->fd, pvBuf, RT_MIN(cbToRead, SSIZE_MAX));
     
    395395            pvBuf     = (char *)pvBuf + cbRead;
    396396            cbToRead -= cbRead;
    397         } while (cbToRead > 0);
     397        }
    398398
    399399        ASMAtomicDecU32(&pThis->u32State);
     
    415415    if (RT_SUCCESS(rc))
    416416    {
    417         ssize_t cbWritten = write(pThis->fd, pvBuf, RT_MIN(cbToWrite, SSIZE_MAX));
    418         if (cbWritten >= 0)
    419             *pcbWritten = cbWritten;
    420         else if (errno == EAGAIN)
    421         {
    422             *pcbWritten = 0;;
    423             rc = VINF_TRY_AGAIN;
     417        if (cbToWrite)
     418        {
     419            ssize_t cbWritten = write(pThis->fd, pvBuf, RT_MIN(cbToWrite, SSIZE_MAX));
     420            if (cbWritten >= 0)
     421                *pcbWritten = cbWritten;
     422            else if (errno == EAGAIN)
     423            {
     424                *pcbWritten = 0;;
     425                rc = VINF_TRY_AGAIN;
     426            }
     427            else
     428                rc = RTErrConvertFromErrno(errno);
    424429        }
    425430        else
    426             rc = RTErrConvertFromErrno(errno);
     431            *pcbWritten = 0;
    427432
    428433        ASMAtomicDecU32(&pThis->u32State);
     
    471476
    472477    if (fsync(pThis->fd))
     478    {
     479        if (errno == EINVAL || errno == ENOTSUP)
     480            return VERR_NOT_SUPPORTED;
    473481        return RTErrConvertFromErrno(errno);
     482    }
    474483    return VINF_SUCCESS;
    475484}
  • trunk/src/VBox/Runtime/testcase/tstRTPipe.cpp

    r26775 r26784  
    140140    RTTESTI_CHECK_RC_RETV(RTPipeCreate(&hPipeR, &hPipeW, RTPIPE_C_INHERIT_READ | RTPIPE_C_INHERIT_WRITE), VINF_SUCCESS);
    141141    int rc = RTPipeFlush(hPipeW);
    142     RTTESTI_CHECK(rc == VERR_NOT_SUPPORTED || rc == VINF_SUCCESS);
     142    RTTESTI_CHECK_MSG(rc == VERR_NOT_SUPPORTED || rc == VINF_SUCCESS, ("%Rrc\n", rc));
    143143    RTTESTI_CHECK_RC_RETV(RTPipeClose(hPipeR), VINF_SUCCESS);
    144144    RTTESTI_CHECK_RC_RETV(RTPipeClose(hPipeW), VINF_SUCCESS);
     
    223223    RTTESTI_CHECK_RC_RETV(RTPipeClose(hPipeR), VINF_SUCCESS);
    224224    cbWritten = ~(size_t)2;
    225     RTTESTI_CHECK_RC(RTPipeWrite(hPipeW, "", 0, &cbWritten), VERR_BROKEN_PIPE);
    226     RTTESTI_CHECK(cbWritten == ~(size_t)2);
     225    RTTESTI_CHECK_RC(RTPipeWrite(hPipeW, "", 0, &cbWritten), VINF_SUCCESS);
     226    RTTESTI_CHECK(cbWritten == 0);
    227227    cbWritten = ~(size_t)2;
    228228    RTTESTI_CHECK_RC(RTPipeWrite(hPipeW, "4", 1, &cbWritten), VERR_BROKEN_PIPE);
     
    233233    RTTESTI_CHECK_RC_RETV(RTPipeClose(hPipeW), VINF_SUCCESS);
    234234    cbRead = ~(size_t)0;
    235     RTTESTI_CHECK_RC(RTPipeRead(hPipeR, abBuf, 0, &cbRead), VINF_SUCCESS);         // !?
     235    RTTESTI_CHECK_RC(RTPipeRead(hPipeR, abBuf, 0, &cbRead), VINF_SUCCESS);
    236236    RTTESTI_CHECK(cbRead == 0);
    237237    cbRead = ~(size_t)3;
     
    284284    RTTESTI_CHECK(!memcmp(abBuf, "42!", 3));
    285285    RTTESTI_CHECK_RC(RTPipeClose(hPipeR), VINF_SUCCESS);
    286     RTTESTI_CHECK_RC_RETV(RTPipeWriteBlocking(hPipeW, "", 0), VERR_BROKEN_PIPE);
     286    RTTESTI_CHECK_RC_RETV(RTPipeWriteBlocking(hPipeW, "", 0), VINF_SUCCESS);
    287287    RTTESTI_CHECK_RC_RETV(RTPipeWriteBlocking(hPipeW, "42", 2), VERR_BROKEN_PIPE);
    288288    RTTESTI_CHECK_RC(RTPipeClose(hPipeW), VINF_SUCCESS);
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