VirtualBox

Ignore:
Timestamp:
May 31, 2017 12:46:24 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
115846
Message:

RTSocketSelectOneEx: Addendeum to r115827: Should set RTSOCKET_EVT_ERROR if the socket closed (see for example rtUdpServerListen). Need to consider possible races with rtSocketCloseIt all the way thru the function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/socket.cpp

    r67151 r67170  
    15111511    AssertReturn(!(fEvents & ~RTSOCKET_EVT_VALID_MASK), VERR_INVALID_PARAMETER);
    15121512    AssertReturn(RTMemPoolRefCount(pThis) >= (pThis->cUsers ? 2U : 1U), VERR_CALLER_NO_REFERENCE);
    1513     int const fdMax = (int)pThis->hNative + 1;
    1514     AssertReturn((RTSOCKETNATIVE)(fdMax - 1) == pThis->hNative, VERR_INTERNAL_ERROR_5);
     1513
     1514    RTSOCKETNATIVE hNative = pThis->hNative;
     1515    if (hNative == NIL_RTSOCKETNATIVE)
     1516    {
     1517        /* Socket is already closed? Possible we raced someone calling rtSocketCloseIt.
     1518           Should we return a different status code? */
     1519        *pfEvents = RTSOCKET_EVT_ERROR;
     1520        return VINF_SUCCESS;
     1521    }
     1522
     1523    int const fdMax = (int)hNative + 1;
     1524    AssertReturn((RTSOCKETNATIVE)(fdMax - 1) == hNative, VERR_INTERNAL_ERROR_5);
    15151525
    15161526    *pfEvents = 0;
     
    15271537
    15281538    if (fEvents & RTSOCKET_EVT_READ)
    1529         FD_SET(pThis->hNative, &fdsetR);
     1539        FD_SET(hNative, &fdsetR);
    15301540    if (fEvents & RTSOCKET_EVT_WRITE)
    1531         FD_SET(pThis->hNative, &fdsetW);
     1541        FD_SET(hNative, &fdsetW);
    15321542    if (fEvents & RTSOCKET_EVT_ERROR)
    1533         FD_SET(pThis->hNative, &fdsetE);
     1543        FD_SET(hNative, &fdsetE);
    15341544
    15351545    int rc;
     
    15451555    if (rc > 0)
    15461556    {
    1547         if (pThis->hNative != NIL_RTSOCKETNATIVE)
     1557        if (pThis->hNative == hNative)
    15481558        {
    1549             if (FD_ISSET(pThis->hNative, &fdsetR))
     1559            if (FD_ISSET(hNative, &fdsetR))
    15501560                *pfEvents |= RTSOCKET_EVT_READ;
    1551             if (FD_ISSET(pThis->hNative, &fdsetW))
     1561            if (FD_ISSET(hNative, &fdsetW))
    15521562                *pfEvents |= RTSOCKET_EVT_WRITE;
    1553             if (FD_ISSET(pThis->hNative, &fdsetE))
     1563            if (FD_ISSET(hNative, &fdsetE))
    15541564                *pfEvents |= RTSOCKET_EVT_ERROR;
     1565            rc = VINF_SUCCESS;
    15551566        }
    1556 
    1557         rc = VINF_SUCCESS;
     1567        else
     1568        {
     1569            /* Socket was closed while we waited (rtSocketCloseIt).  Different status code? */
     1570            *pfEvents = RTSOCKET_EVT_ERROR;
     1571            rc = VINF_SUCCESS;
     1572        }
    15581573    }
    15591574    else if (rc == 0)
Note: See TracChangeset for help on using the changeset viewer.

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