VirtualBox

Ignore:
Timestamp:
Jun 21, 2022 2:34:48 PM (3 years ago)
Author:
vboxsync
Message:

VBoxControl/waitGuestProperty: Simplified the buffer-resizing wait loop.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxControl/VBoxControl.cpp

    r94184 r95326  
    15191519     * of space here in case the maximum values are raised. */
    15201520    void *pvBuf = NULL;
    1521     uint32_t cbBuf = GUEST_PROP_MAX_NAME_LEN + GUEST_PROP_MAX_VALUE_LEN + GUEST_PROP_MAX_FLAGS_LEN + 1024;
     1521    uint32_t cbBuf = GUEST_PROP_MAX_NAME_LEN + GUEST_PROP_MAX_VALUE_LEN + GUEST_PROP_MAX_FLAGS_LEN + _1K;
    15221522    /* Because there is a race condition between our reading the size of a
    15231523     * property and the guest updating it, we loop a few times here and
    15241524     * hope.  Actually this should never go wrong, as we are generous
    15251525     * enough with buffer space. */
    1526     bool fFinished = false;
    1527     for (unsigned i = 0; (RT_SUCCESS(rc) || rc == VERR_BUFFER_OVERFLOW) && !fFinished && i < 10; i++)
    1528     {
    1529         void *pvTmpBuf = RTMemRealloc(pvBuf, cbBuf);
    1530         if (NULL == pvTmpBuf)
    1531         {
    1532             rc = VERR_NO_MEMORY;
    1533             VBoxControlError("Out of memory\n");
    1534         }
    1535         else
    1536         {
    1537             pvBuf = pvTmpBuf;
     1526    for (unsigned iTry = 0; ; iTry++)
     1527    {
     1528        pvBuf = RTMemRealloc(pvBuf, cbBuf);
     1529        if (pvBuf != NULL)
     1530        {
    15381531            rc = VbglR3GuestPropWait(u32ClientId, pszPatterns, pvBuf, cbBuf,
    15391532                                     u64TimestampIn, u32Timeout,
    15401533                                     &pszName, &pszValue, &u64TimestampOut,
    15411534                                     &pszFlags, &cbBuf, &fWasDeleted);
    1542         }
    1543         if (VERR_BUFFER_OVERFLOW == rc)
    1544             /* Leave a bit of extra space to be safe */
    1545             cbBuf += 1024;
     1535            if (rc == VERR_BUFFER_OVERFLOW && iTry < 10)
     1536            {
     1537                cbBuf += _1K; /* Add a bit of extra space to be on the safe side. */
     1538                continue;
     1539            }
     1540            if (rc == VERR_TOO_MUCH_DATA)
     1541                VBoxControlError("Temporarily unable to get a notification\n");
     1542            else if (rc == VERR_INTERRUPTED)
     1543                VBoxControlError("The request timed out or was interrupted\n");
     1544            else if (RT_FAILURE(rc) && rc != VERR_NOT_FOUND)
     1545                VBoxControlError("Failed to get a notification, error %Rrc\n", rc);
     1546        }
    15461547        else
    1547             fFinished = true;
    1548         if (rc == VERR_TOO_MUCH_DATA)
    1549             VBoxControlError("Temporarily unable to get a notification\n");
    1550         else if (rc == VERR_INTERRUPTED)
    1551             VBoxControlError("The request timed out or was interrupted\n");
    1552         else if (RT_FAILURE(rc) && rc != VERR_NOT_FOUND)
    1553             VBoxControlError("Failed to get a notification, error %Rrc\n", rc);
     1548        {
     1549            VBoxControlError("Out of memory\n");
     1550            rc = VERR_NO_MEMORY;
     1551        }
     1552        break;
    15541553    }
    15551554
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