VirtualBox

Changeset 15509 in vbox


Ignore:
Timestamp:
Dec 15, 2008 3:10:55 PM (16 years ago)
Author:
vboxsync
Message:

Runtime/TCP: add proper handling of error codes from resolver. Platform-dependent, so squeezed it a bit into the existing code.

File:
1 edited

Legend:

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

    r13837 r15509  
    146146 * @returns iprt status code.
    147147 */
    148 DECLINLINE(int) rtTcpError(void)
     148DECLINLINE(int) rtTcpError(bool fHErrNo)
    149149{
    150150#ifdef RT_OS_WINDOWS
    151151    return RTErrConvertFromWin32(WSAGetLastError());
    152152#else
    153     return RTErrConvertFromErrno(errno);
     153    if (fHErrNo)
     154    {
     155        switch (h_errno)
     156        {
     157            case HOST_NOT_FOUND:
     158                return VERR_NET_HOST_NOT_FOUND;
     159                break;
     160            case NO_DATA:
     161                return VERR_NET_ADDRESS_NOT_AVAILABLE;
     162                break;
     163            case NO_RECOVERY:
     164                return VERR_IO_GEN_FAILURE;
     165                break;
     166            case TRY_AGAIN:
     167                return VERR_TRY_AGAIN;
     168                break;
     169            default:
     170                return VERR_UNRESOLVED_ERROR;
     171        }
     172    }
     173    else
     174        return RTErrConvertFromErrno(errno);
    154175#endif
    155176}
     
    317338            if (!pHostEnt)
    318339            {
    319                 rc = rtTcpError();
     340                rc = rtTcpError(true);
    320341                AssertMsgFailed(("Could not get host address rc=%Rrc\n", rc));
    321342                return rc;
     
    376397                else
    377398                {
    378                     rc = rtTcpError();
     399                    rc = rtTcpError(false);
    379400                    AssertMsgFailed(("listen() %Rrc\n", rc));
    380401                }
     
    382403            else
    383404            {
    384                 rc = rtTcpError();
     405                rc = rtTcpError(false);
    385406            }
    386407        }
    387408        else
    388409        {
    389             rc = rtTcpError();
     410            rc = rtTcpError(false);
    390411            AssertMsgFailed(("setsockopt() %Rrc\n", rc));
    391412        }
     
    394415    else
    395416    {
    396         rc = rtTcpError();
     417        rc = rtTcpError(false);
    397418        AssertMsgFailed(("socket() %Rrc\n", rc));
    398419    }
     
    722743        ssize_t cbBytesRead = recv(Sock, (char *)pvBuffer + cbRead, cbToRead, MSG_NOSIGNAL);
    723744        if (cbBytesRead < 0)
    724             return rtTcpError();
    725         if (cbBytesRead == 0 && rtTcpError())
    726             return rtTcpError();
     745            return rtTcpError(false);
     746        if (cbBytesRead == 0 && rtTcpError(false))
     747            return rtTcpError(false);
    727748        if (pcbRead)
    728749        {
     
    751772        ssize_t cbWritten = send(Sock, (const char *)pvBuffer, cbBuffer, MSG_NOSIGNAL);
    752773        if (cbWritten < 0)
    753             return rtTcpError();
     774            return rtTcpError(false);
    754775        AssertMsg(cbBuffer >= (size_t)cbWritten, ("Wrote more than we requested!!! cbWritten=%d cbBuffer=%d rtTcpError()=%d\n",
    755                                                   cbWritten, cbBuffer, rtTcpError()));
     776                                                  cbWritten, cbBuffer, rtTcpError(false)));
    756777        cbBuffer -= cbWritten;
    757778        pvBuffer = (char *)pvBuffer + cbWritten;
     
    795816    if (rc == 0)
    796817        return VERR_TIMEOUT;
    797     return rtTcpError();
     818    return rtTcpError(false);
    798819}
    799820
     
    835856        if (!pHostEnt)
    836857        {
    837             rc = rtTcpError();
     858            rc = rtTcpError(false);
    838859            AssertMsgFailed(("Could not resolve '%s', rc=%Rrc\n", pszAddress, rc));
    839860            return rc;
     
    856877            return VINF_SUCCESS;
    857878        }
    858         rc = rtTcpError();
     879        rc = rtTcpError(false);
    859880        rtTcpClose(Sock, "RTTcpClientConnect");
    860881    }
    861882    else
    862         rc = rtTcpError();
     883        rc = rtTcpError(false);
    863884    return rc;
    864885}
     
    890911    if (!rc)
    891912        return VINF_SUCCESS;
    892     rc = rtTcpError();
     913    rc = rtTcpError(false);
    893914    AssertMsgFailed(("\"%s\": close(%d) -> %Rrc\n", pszMsg, Sock, rc));
    894915    return rc;
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