Changeset 53536 in vbox for trunk/src/VBox
- Timestamp:
- Dec 14, 2014 9:30:26 PM (10 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/include/internal/socket.h
r53487 r53536 59 59 int rtSocketListen(RTSOCKET hSocket, int cMaxPending); 60 60 int rtSocketAccept(RTSOCKET hSocket, PRTSOCKET phClient, struct sockaddr *pAddr, size_t *pcbAddr); 61 int rtSocketConnect(RTSOCKET hSocket, PCRTNETADDR pAddr );61 int rtSocketConnect(RTSOCKET hSocket, PCRTNETADDR pAddr, RTMSINTERVAL cMillies); 62 62 int rtSocketSetOpt(RTSOCKET hSocket, int iLevel, int iOption, void const *pvValue, int cbValue); 63 63 #endif /* IPRT_INTERNAL_SOCKET_POLLING_ONLY */ -
trunk/src/VBox/Runtime/r3/socket.cpp
r53489 r53536 679 679 { 680 680 rc = rtSocketResolverError(); 681 AssertMsgFailed(("Could not resolve '%s', rc=%Rrc\n", pszAddress, rc));681 //AssertMsgFailed(("Could not resolve '%s', rc=%Rrc\n", pszAddress, rc)); 682 682 return rc; 683 683 } … … 1722 1722 * @param hSocket The socket handle. 1723 1723 * @param pAddr The socket address to connect to. 1724 */ 1725 int rtSocketConnect(RTSOCKET hSocket, PCRTNETADDR pAddr) 1724 * @param cMillies Number of milliseconds to wait for the connect attempt to complete. 1725 * Use RT_INDEFINITE_WAIT to wait for ever. 1726 * Use RT_TCPCLIENTCONNECT_DEFAULT_WAIT to wait for the default time 1727 * configured on the running system. 1728 */ 1729 int rtSocketConnect(RTSOCKET hSocket, PCRTNETADDR pAddr, RTMSINTERVAL cMillies) 1726 1730 { 1727 1731 /* … … 1738 1742 if (RT_SUCCESS(rc)) 1739 1743 { 1740 if (connect(pThis->hNative, &u.Addr, cbAddr) != 0) 1741 rc = rtSocketError(); 1744 if (cMillies == RT_SOCKETCONNECT_DEFAULT_WAIT) 1745 { 1746 if (connect(pThis->hNative, &u.Addr, cbAddr) != 0) 1747 rc = rtSocketError(); 1748 } 1749 else 1750 { 1751 /* 1752 * Switch the socket to nonblocking mode, initiate the connect 1753 * and wait for the socket to become writable or until the timeout 1754 * expires. 1755 */ 1756 rc = rtSocketSwitchBlockingMode(pThis, false /* fBlocking */); 1757 if (RT_SUCCESS(rc)) 1758 { 1759 if (connect(pThis->hNative, &u.Addr, cbAddr) != 0) 1760 { 1761 rc = rtSocketError(); 1762 if (rc == VERR_TRY_AGAIN || rc == VERR_NET_IN_PROGRESS) 1763 { 1764 int rcSock = 0; 1765 fd_set FdSetWriteable; 1766 struct timeval TvTimeout; 1767 1768 TvTimeout.tv_sec = cMillies / RT_MS_1SEC; 1769 TvTimeout.tv_usec = (cMillies % RT_MS_1SEC) * RT_US_1MS; 1770 1771 FD_ZERO(&FdSetWriteable); 1772 FD_SET(pThis->hNative, &FdSetWriteable); 1773 do 1774 { 1775 rcSock = select(pThis->hNative + 1, NULL, &FdSetWriteable, NULL, 1776 cMillies == RT_INDEFINITE_WAIT || cMillies >= INT_MAX 1777 ? NULL 1778 : &TvTimeout); 1779 if (rcSock > 0) 1780 { 1781 int iSockError = 0; 1782 socklen_t cbSockOpt = sizeof(iSockError); 1783 rcSock = getsockopt(pThis->hNative, SOL_SOCKET, SO_ERROR, &iSockError, &cbSockOpt); 1784 if (rcSock == 0) 1785 { 1786 if (iSockError == 0) 1787 rc = VINF_SUCCESS; 1788 else 1789 { 1790 #ifdef RT_OS_WINDOWS 1791 rc = RTErrConvertFromWin32(iSockError); 1792 #else 1793 rc = RTErrConvertFromErrno(iSockError); 1794 #endif 1795 } 1796 } 1797 else 1798 rc = rtSocketError(); 1799 } 1800 else if (rcSock == 0) 1801 rc = VERR_TIMEOUT; 1802 else 1803 rc = rtSocketError(); 1804 } while (rc == VERR_INTERRUPTED); 1805 } 1806 } 1807 1808 rtSocketSwitchBlockingMode(pThis, true /* fBlocking */); 1809 } 1810 } 1742 1811 } 1743 1812 -
trunk/src/VBox/Runtime/r3/tcp.cpp
r48935 r53536 806 806 RTR3DECL(int) RTTcpClientConnect(const char *pszAddress, uint32_t uPort, PRTSOCKET pSock) 807 807 { 808 return RTTcpClientConnectEx(pszAddress, uPort, pSock, NULL);808 return RTTcpClientConnectEx(pszAddress, uPort, pSock, RT_SOCKETCONNECT_DEFAULT_WAIT, NULL); 809 809 } 810 810 811 811 812 812 RTR3DECL(int) RTTcpClientConnectEx(const char *pszAddress, uint32_t uPort, PRTSOCKET pSock, 813 PRTTCPCLIENTCONNECTCANCEL volatile *ppCancelCookie)813 RTMSINTERVAL cMillies, PRTTCPCLIENTCONNECTCANCEL volatile *ppCancelCookie) 814 814 { 815 815 /* … … 838 838 839 839 if (!ppCancelCookie) 840 rc = rtSocketConnect(Sock, &Addr );840 rc = rtSocketConnect(Sock, &Addr, cMillies); 841 841 else 842 842 { … … 844 844 if (ASMAtomicCmpXchgPtr(ppCancelCookie, (PRTTCPCLIENTCONNECTCANCEL)Sock, NULL)) 845 845 { 846 rc = rtSocketConnect(Sock, &Addr );846 rc = rtSocketConnect(Sock, &Addr, cMillies); 847 847 if (ASMAtomicCmpXchgPtr(ppCancelCookie, NULL, (PRTTCPCLIENTCONNECTCANCEL)Sock)) 848 848 RTSocketRelease(Sock); -
trunk/src/VBox/ValidationKit/utils/TestExecServ/TestExecServiceTcp.cpp
r52776 r53536 204 204 RTSOCKET hTcpClient; 205 205 Log2(("Calling RTTcpClientConnect(%s, %u,)...\n", g_szTcpConnectAddr, g_uTcpConnectPort)); 206 int rc = RTTcpClientConnectEx(g_szTcpConnectAddr, g_uTcpConnectPort, &hTcpClient, &g_pTcpConnectCancelCookie); 206 int rc = RTTcpClientConnectEx(g_szTcpConnectAddr, g_uTcpConnectPort, &hTcpClient, 207 RT_SOCKETCONNECT_DEFAULT_WAIT, &g_pTcpConnectCancelCookie); 207 208 Log(("txsTcpRecvPkt: RTTcpClientConnect -> %Rrc\n", rc)); 208 209 if (RT_SUCCESS(rc)) … … 278 279 { 279 280 Log2(("Calling RTTcpClientConnect(%s, %u,)...\n", g_szTcpConnectAddr, g_uTcpConnectPort)); 280 rc = RTTcpClientConnect Ex(g_szTcpConnectAddr, g_uTcpConnectPort, &g_hTcpClient, NULL);281 rc = RTTcpClientConnect(g_szTcpConnectAddr, g_uTcpConnectPort, &g_hTcpClient); 281 282 Log(("txsTcpRecvPkt: RTTcpClientConnect -> %Rrc\n", rc)); 282 283 if (RT_SUCCESS(rc) || txsTcpIsFatalClientConnectStatus(rc))
Note:
See TracChangeset
for help on using the changeset viewer.