VirtualBox

Changeset 86415 in vbox


Ignore:
Timestamp:
Oct 2, 2020 11:50:21 AM (4 years ago)
Author:
vboxsync
Message:

IPRT,++: Made RTHandleGetStandard's fLeaveOpen parameter work for sockets too. bugref:9841

Location:
trunk
Files:
5 edited

Legend:

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

    r86414 r86415  
    5757 * @param   fLeaveOpen      Whether closing the returned handle should leave the
    5858 *                          native standard handle open or not.
    59  *                          Note! This currently only works with pipe!
     59 *                          Note! This currently only works with pipes and
     60 *                                sockets!
    6061 * @param   ph              Pointer to the generic handle.  This will contain
    6162 *                          the most appropriate IPRT handle on success.
  • trunk/src/VBox/Runtime/include/internal/socket.h

    r82968 r86415  
    5656#ifndef IPRT_INTERNAL_SOCKET_POLLING_ONLY
    5757DECLHIDDEN(int) rtSocketResolverError(void);
    58 DECLHIDDEN(int) rtSocketCreateForNative(RTSOCKETINT **ppSocket, RTSOCKETNATIVE hNative);
     58DECLHIDDEN(int) rtSocketCreateForNative(RTSOCKETINT **ppSocket, RTSOCKETNATIVE hNative, bool fLeaveOpen);
    5959DECLHIDDEN(int) rtSocketCreate(PRTSOCKET phSocket, int iDomain, int iType, int iProtocol);
    6060DECLHIDDEN(int) rtSocketCreateTcpPair(RTSOCKET *phServer, RTSOCKET *phClient);
  • trunk/src/VBox/Runtime/r3/posix/RTHandleGetStandard-posix.cpp

    r86414 r86415  
    120120
    121121        case RTHANDLETYPE_SOCKET:
    122             /** @todo fLeaveOpen   */
    123             rc = rtSocketCreateForNative(&h.u.hSocket, fd);
     122            rc = rtSocketCreateForNative(&h.u.hSocket, fd, fLeaveOpen);
    124123            break;
    125124
  • trunk/src/VBox/Runtime/r3/socket.cpp

    r82968 r86415  
    149149     * currently. */
    150150    bool                fBlocking;
     151    /** Whether to leave the native socket open rather than closing it (for
     152     * RTHandleGetStandard). */
     153    bool                fLeaveOpen;
    151154#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
    152155    /** The pollset currently polling this socket.  This is NIL if no one is
     
    496499 * @param   ppSocket        Where to return the IPRT socket handle.
    497500 * @param   hNative         The native handle.
    498  */
    499 DECLHIDDEN(int) rtSocketCreateForNative(RTSOCKETINT **ppSocket, RTSOCKETNATIVE hNative)
     501 * @param   fLeaveOpen      Whether to leave the native socket handle open when
     502 *                          closed.
     503 */
     504DECLHIDDEN(int) rtSocketCreateForNative(RTSOCKETINT **ppSocket, RTSOCKETNATIVE hNative, bool fLeaveOpen)
    500505{
    501506    RTSOCKETINT *pThis = (RTSOCKETINT *)RTMemPoolAlloc(RTMEMPOOL_DEFAULT, sizeof(*pThis));
     
    506511    pThis->hNative          = hNative;
    507512    pThis->fClosed          = false;
     513    pThis->fLeaveOpen       = fLeaveOpen;
    508514    pThis->fBlocking        = true;
    509515#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
     
    539545#endif
    540546    AssertPtrReturn(phSocket, VERR_INVALID_POINTER);
    541     return rtSocketCreateForNative(phSocket, uNative);
     547    return rtSocketCreateForNative(phSocket, uNative, false /*fLeaveOpen*/);
    542548}
    543549
     
    579585     * Wrap it.
    580586     */
    581     int rc = rtSocketCreateForNative(phSocket, hNative);
     587    int rc = rtSocketCreateForNative(phSocket, hNative, false /*fLeaveOpen*/);
    582588    if (RT_FAILURE(rc))
    583589    {
     
    724730    if (RT_SUCCESS(rc))
    725731    {
    726         rc = rtSocketCreateForNative(phServer, hServer);
     732        rc = rtSocketCreateForNative(phServer, hServer, false /*fLeaveOpen*/);
    727733        if (RT_SUCCESS(rc))
    728734        {
    729             rc = rtSocketCreateForNative(phClient, hClient);
     735            rc = rtSocketCreateForNative(phClient, hClient, false /*fLeaveOpen*/);
    730736            if (RT_SUCCESS(rc))
    731737                return VINF_SUCCESS;
     
    806812            pThis->hNative = NIL_RTSOCKETNATIVE;
    807813
    808 #ifdef RT_OS_WINDOWS
    809             AssertReturn(g_pfnclosesocket, VERR_NET_NOT_UNSUPPORTED);
    810             if (g_pfnclosesocket(hNative))
     814            if (!pThis->fLeaveOpen)
     815            {
     816#ifdef RT_OS_WINDOWS
     817                AssertReturn(g_pfnclosesocket, VERR_NET_NOT_UNSUPPORTED);
     818                if (g_pfnclosesocket(hNative))
    811819#else
    812             if (close(hNative))
    813 #endif
    814             {
    815                 rc = rtSocketError();
    816 #ifdef RT_OS_WINDOWS
    817                 AssertMsgFailed(("closesocket(%p) -> %Rrc\n", (uintptr_t)hNative, rc));
     820                if (close(hNative))
     821#endif
     822                {
     823                    rc = rtSocketError();
     824#ifdef RT_OS_WINDOWS
     825                    AssertMsgFailed(("closesocket(%p) -> %Rrc\n", (uintptr_t)hNative, rc));
    818826#else
    819                 AssertMsgFailed(("close(%d) -> %Rrc\n", hNative, rc));
    820 #endif
     827                    AssertMsgFailed(("close(%d) -> %Rrc\n", hNative, rc));
     828#endif
     829                }
    821830            }
    822831        }
     
    22992308         * Wrap the client socket.
    23002309         */
    2301         rc = rtSocketCreateForNative(phClient, hNativeClient);
     2310        rc = rtSocketCreateForNative(phClient, hNativeClient, false /*fLeaveOpen*/);
    23022311        if (RT_FAILURE(rc))
    23032312        {
  • trunk/src/VBox/Runtime/r3/win/RTHandleGetStandard-win.cpp

    r86414 r86415  
    114114
    115115        case RTHANDLETYPE_SOCKET:
    116             /** @todo fLeaveOpen */
    117             rc = rtSocketCreateForNative(&h.u.hSocket, (RTHCUINTPTR)hNative);
     116            rc = rtSocketCreateForNative(&h.u.hSocket, (RTHCUINTPTR)hNative, fLeaveOpen);
    118117            break;
    119118
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