Changeset 15655 in vbox
- Timestamp:
- Dec 18, 2008 1:28:02 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/tcp.cpp
r15509 r15655 144 144 /** 145 145 * Get the last error as an iprt status code. 146 * 146 147 * @returns iprt status code. 147 148 */ 148 DECLINLINE(int) rtTcpError( bool fHErrNo)149 DECLINLINE(int) rtTcpError(void) 149 150 { 150 151 #ifdef RT_OS_WINDOWS 151 152 return RTErrConvertFromWin32(WSAGetLastError()); 152 153 #else 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); 154 return RTErrConvertFromErrno(errno); 155 #endif 156 } 157 158 159 /** 160 * Resets the last error. 161 */ 162 DECLINLINE(void) rtTcpErrorReset(void) 163 { 164 #ifdef RT_OS_WINDOWS 165 WSASetLastError(0); 166 #else 167 errno = 0; 168 #endif 169 } 170 171 172 /** 173 * Get the last resolver error as an iprt status code. 174 * 175 * @returns iprt status code. 176 */ 177 DECLINLINE(int) rtTcpResolverError(void) 178 { 179 #ifdef RT_OS_WINDOWS 180 return RTErrConvertFromWin32(WSAGetLastError()); 181 #else 182 switch (h_errno) 183 { 184 case HOST_NOT_FOUND: 185 return VERR_NET_HOST_NOT_FOUND; 186 case NO_DATA: 187 return VERR_NET_ADDRESS_NOT_AVAILABLE; 188 case NO_RECOVERY: 189 return VERR_IO_GEN_FAILURE; 190 case TRY_AGAIN: 191 return VERR_TRY_AGAIN; 192 193 default: 194 return VERR_UNRESOLVED_ERROR; 195 } 175 196 #endif 176 197 } … … 338 359 if (!pHostEnt) 339 360 { 340 rc = rtTcp Error(true);361 rc = rtTcpResolverError(); 341 362 AssertMsgFailed(("Could not get host address rc=%Rrc\n", rc)); 342 363 return rc; … … 397 418 else 398 419 { 399 rc = rtTcpError( false);420 rc = rtTcpError(); 400 421 AssertMsgFailed(("listen() %Rrc\n", rc)); 401 422 } … … 403 424 else 404 425 { 405 rc = rtTcpError( false);426 rc = rtTcpError(); 406 427 } 407 428 } 408 429 else 409 430 { 410 rc = rtTcpError( false);431 rc = rtTcpError(); 411 432 AssertMsgFailed(("setsockopt() %Rrc\n", rc)); 412 433 } … … 415 436 else 416 437 { 417 rc = rtTcpError( false);438 rc = rtTcpError(); 418 439 AssertMsgFailed(("socket() %Rrc\n", rc)); 419 440 } … … 741 762 for (;;) 742 763 { 764 rtTcpErrorReset(); 743 765 ssize_t cbBytesRead = recv(Sock, (char *)pvBuffer + cbRead, cbToRead, MSG_NOSIGNAL); 744 766 if (cbBytesRead < 0) 745 return rtTcpError( false);746 if (cbBytesRead == 0 && rtTcpError( false))747 return rtTcpError( false);767 return rtTcpError(); 768 if (cbBytesRead == 0 && rtTcpError()) 769 return rtTcpError(); 748 770 if (pcbRead) 749 771 { … … 772 794 ssize_t cbWritten = send(Sock, (const char *)pvBuffer, cbBuffer, MSG_NOSIGNAL); 773 795 if (cbWritten < 0) 774 return rtTcpError( false);796 return rtTcpError(); 775 797 AssertMsg(cbBuffer >= (size_t)cbWritten, ("Wrote more than we requested!!! cbWritten=%d cbBuffer=%d rtTcpError()=%d\n", 776 cbWritten, cbBuffer, rtTcpError( false)));798 cbWritten, cbBuffer, rtTcpError())); 777 799 cbBuffer -= cbWritten; 778 800 pvBuffer = (char *)pvBuffer + cbWritten; … … 816 838 if (rc == 0) 817 839 return VERR_TIMEOUT; 818 return rtTcpError( false);840 return rtTcpError(); 819 841 } 820 842 … … 856 878 if (!pHostEnt) 857 879 { 858 rc = rtTcpError( false);880 rc = rtTcpError(); 859 881 AssertMsgFailed(("Could not resolve '%s', rc=%Rrc\n", pszAddress, rc)); 860 882 return rc; … … 877 899 return VINF_SUCCESS; 878 900 } 879 rc = rtTcpError( false);901 rc = rtTcpError(); 880 902 rtTcpClose(Sock, "RTTcpClientConnect"); 881 903 } 882 904 else 883 rc = rtTcpError( false);905 rc = rtTcpError(); 884 906 return rc; 885 907 } … … 911 933 if (!rc) 912 934 return VINF_SUCCESS; 913 rc = rtTcpError( false);935 rc = rtTcpError(); 914 936 AssertMsgFailed(("\"%s\": close(%d) -> %Rrc\n", pszMsg, Sock, rc)); 915 937 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.