- Timestamp:
- Dec 30, 2017 12:11:56 PM (7 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/socket.cpp
r70244 r70393 182 182 183 183 184 /********************************************************************************************************************************* 185 * Global Variables * 186 *********************************************************************************************************************************/ 187 #ifdef RT_OS_WINDOWS 188 /** Indicates that we've successfully initialized winsock. */ 189 static uint32_t volatile g_uWinSockInitedVersion = 0; 190 #endif 191 192 193 #ifdef RT_OS_WINDOWS 194 /** 195 * Initializes winsock for the process. 196 * 197 * @returns IPRT status code. 198 */ 199 static int rtSocketInitWinsock(void) 200 { 201 if (g_uWinSockInitedVersion != 0) 202 return VINF_SUCCESS; 203 204 if ( !g_pfnWSAGetLastError 205 || !g_pfnWSAStartup 206 || !g_pfnsocket 207 || !g_pfnclosesocket) 208 return VERR_NET_INIT_FAILED; 209 210 /* 211 * Initialize winsock. Try with 2.2 and back down till we get something that works. 212 */ 213 static const WORD s_awVersions[] = 214 { 215 MAKEWORD(2, 2), 216 MAKEWORD(2, 1), 217 MAKEWORD(2, 0), 218 MAKEWORD(1, 1), 219 MAKEWORD(1, 0), 220 }; 221 for (uint32_t i = 0; i < RT_ELEMENTS(s_awVersions); i++) 222 { 223 WSADATA wsaData; 224 RT_ZERO(wsaData); 225 int rcWsa = g_pfnWSAStartup(s_awVersions[i], &wsaData); 226 if (rcWsa == 0) 227 { 228 Assert(wsaData.wVersion >= s_awVersions[i]); 229 ASMAtomicWriteU32(&g_uWinSockInitedVersion, s_awVersions[i]); 230 return VINF_SUCCESS; 231 } 232 AssertLogRelMsg(rcWsa == WSAVERNOTSUPPORTED, ("rcWsa=%d (winsock version %#x)\n", rcWsa, s_awVersions[i])); 233 } 234 LogRel(("Failed to init winsock!\n")); 235 return VERR_NET_INIT_FAILED; 236 } 237 #endif 238 239 184 240 /** 185 241 * Get the last error as an iprt status code. … … 363 419 { 364 420 #ifdef RT_OS_WINDOWS 365 AssertReturn(g_pfnioctlsocket, VERR_N OT_SUPPORTED);421 AssertReturn(g_pfnioctlsocket, VERR_NET_NOT_UNSUPPORTED); 366 422 u_long uBlocking = fBlocking ? 0 : 1; 367 423 if (g_pfnioctlsocket(pThis->hNative, FIONBIO, &uBlocking)) … … 458 514 { 459 515 #ifdef RT_OS_WINDOWS 460 AssertReturn(g_pfnsocket, VERR_NOT_SUPPORTED); 461 AssertReturn(g_pfnclosesocket, VERR_NOT_SUPPORTED); 462 AssertReturn(g_pfnWSAStartup, VERR_NOT_SUPPORTED); 516 AssertReturn(g_pfnsocket, VERR_NET_NOT_UNSUPPORTED); 517 AssertReturn(g_pfnclosesocket, VERR_NET_NOT_UNSUPPORTED); 463 518 464 519 /* Initialize WinSock. */ 465 WORD const wVersionRequested = MAKEWORD(1, 1); 466 WSADATA wsaData; 467 RT_ZERO(wsaData); 468 int rcWsa = g_pfnWSAStartup(wVersionRequested, &wsaData); 469 AssertMsgReturn(wsaData.wVersion >= wVersionRequested && rcWsa == 0, 470 ("Wrong winsock version %#x rcWsa=%#x (%d)\n", wsaData.wVersion, rcWsa, rcWsa), 471 VERR_NOT_SUPPORTED); 520 int rc2 = rtSocketInitWinsock(); 521 if (RT_FAILURE(rc2)) 522 return rc2; 472 523 #endif 473 524 … … 538 589 539 590 #ifdef RT_OS_WINDOWS 540 AssertReturn(g_pfnclosesocket, VERR_N OT_SUPPORTED);591 AssertReturn(g_pfnclosesocket, VERR_NET_NOT_UNSUPPORTED); 541 592 if (g_pfnclosesocket(hNative)) 542 593 #else … … 695 746 #ifdef RT_OS_WINDOWS 696 747 /* Initialize WinSock and check version before we call gethostbyname. */ 697 if ( !g_pfnWSAStartup 698 || !g_pfngethostbyname) 699 return VERR_NOT_SUPPORTED; 700 WORD const wVersionRequested = MAKEWORD(1, 1); 701 WSADATA wsaData; 702 RT_ZERO(wsaData); 703 int rcWsa = g_pfnWSAStartup(wVersionRequested, &wsaData); 704 AssertMsgReturn(wsaData.wVersion >= wVersionRequested && rcWsa == 0, 705 ("Wrong winsock version %#x rcWsa=%#x (%d)\n", wsaData.wVersion, rcWsa, rcWsa), 706 VERR_NOT_SUPPORTED); 748 if (!g_pfngethostbyname) 749 return VERR_NET_NOT_UNSUPPORTED; 750 751 int rc2 = rtSocketInitWinsock(); 752 if (RT_FAILURE(rc2)) 753 return rc2; 754 707 755 # define gethostbyname g_pfngethostbyname 708 756 #endif … … 783 831 * Winsock2 init 784 832 */ 785 if ( !g_pfnWSAStartup 786 || !g_pfngetaddrinfo 833 if ( !g_pfngetaddrinfo 787 834 || !g_pfnfreeaddrinfo) 788 return VERR_NOT_SUPPORTED; 789 /** @todo someone should check if we really need 2, 2 here */ 790 WORD const wVersionRequested = MAKEWORD(2, 2); 791 WSADATA wsaData; 792 RT_ZERO(wsaData); 793 int rcWsa = g_pfnWSAStartup(wVersionRequested, &wsaData); 794 AssertMsgReturn(wsaData.wVersion >= wVersionRequested && rcWsa == 0, 795 ("Wrong winsock version %#x rcWsa=%#x (%d)\n", wsaData.wVersion, rcWsa, rcWsa), 796 VERR_NOT_SUPPORTED); 835 return VERR_NET_NOT_UNSUPPORTED; 836 837 int rc2 = rtSocketInitWinsock(); 838 if (RT_FAILURE(rc2)) 839 return rc2; 840 797 841 # define getaddrinfo g_pfngetaddrinfo 798 842 # define freeaddrinfo g_pfnfreeaddrinfo … … 882 926 AssertPtr(pvBuffer); 883 927 #ifdef RT_OS_WINDOWS 884 AssertReturn(g_pfnrecv, VERR_N OT_SUPPORTED);928 AssertReturn(g_pfnrecv, VERR_NET_NOT_UNSUPPORTED); 885 929 # define recv g_pfnrecv 886 930 #endif … … 958 1002 AssertPtr(pcbRead); 959 1003 #ifdef RT_OS_WINDOWS 960 AssertReturn(g_pfnrecvfrom, VERR_N OT_SUPPORTED);1004 AssertReturn(g_pfnrecvfrom, VERR_NET_NOT_UNSUPPORTED); 961 1005 # define recvfrom g_pfnrecvfrom 962 1006 #endif … … 1016 1060 AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE); 1017 1061 #ifdef RT_OS_WINDOWS 1018 AssertReturn(g_pfnsend, VERR_N OT_SUPPORTED);1062 AssertReturn(g_pfnsend, VERR_NET_NOT_UNSUPPORTED); 1019 1063 # define send g_pfnsend 1020 1064 #endif … … 1092 1136 AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE); 1093 1137 #ifdef RT_OS_WINDOWS 1094 AssertReturn(g_pfnsendto, VERR_N OT_SUPPORTED);1138 AssertReturn(g_pfnsendto, VERR_NET_NOT_UNSUPPORTED); 1095 1139 # define sendto g_pfnsendto 1096 1140 #endif … … 1153 1197 AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE); 1154 1198 #ifdef RT_OS_WINDOWS 1155 AssertReturn(g_pfnsendto, VERR_N OT_SUPPORTED);1199 AssertReturn(g_pfnsendto, VERR_NET_NOT_UNSUPPORTED); 1156 1200 # define sendto g_pfnsendto 1157 1201 #endif … … 1277 1321 } 1278 1322 else 1279 rc = VERR_N OT_SUPPORTED;1323 rc = VERR_NET_NOT_UNSUPPORTED; 1280 1324 1281 1325 #else /* !RT_OS_WINDOWS */ … … 1356 1400 AssertPtrReturn(pcbRead, VERR_INVALID_PARAMETER); 1357 1401 #ifdef RT_OS_WINDOWS 1358 AssertReturn(g_pfnrecv, VERR_N OT_SUPPORTED);1402 AssertReturn(g_pfnrecv, VERR_NET_NOT_UNSUPPORTED); 1359 1403 #endif 1360 1404 AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS); … … 1422 1466 AssertPtrReturn(pcbWritten, VERR_INVALID_PARAMETER); 1423 1467 #ifdef RT_OS_WINDOWS 1424 AssertReturn(g_pfnsend, VERR_N OT_SUPPORTED);1468 AssertReturn(g_pfnsend, VERR_NET_NOT_UNSUPPORTED); 1425 1469 #endif 1426 1470 AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS); … … 1545 1589 } 1546 1590 else 1547 rc = VERR_N OT_SUPPORTED;1591 rc = VERR_NET_NOT_UNSUPPORTED; 1548 1592 1549 1593 #else /* !RT_OS_WINDOWS */ … … 1618 1662 AssertReturn((RTSOCKETNATIVE)(fdMax - 1) == pThis->hNative, VERR_INTERNAL_ERROR_5); 1619 1663 #ifdef RT_OS_WINDOWS 1620 AssertReturn(g_pfnselect, VERR_N OT_SUPPORTED);1664 AssertReturn(g_pfnselect, VERR_NET_NOT_UNSUPPORTED); 1621 1665 # define select g_pfnselect 1622 1666 #endif … … 1679 1723 AssertReturn((RTSOCKETNATIVE)(fdMax - 1) == hNative, VERR_INTERNAL_ERROR_5); 1680 1724 #ifdef RT_OS_WINDOWS 1681 AssertReturn(g_pfnselect, VERR_N OT_SUPPORTED);1682 AssertReturn(g_pfn__WSAFDIsSet, VERR_N OT_SUPPORTED);1725 AssertReturn(g_pfnselect, VERR_NET_NOT_UNSUPPORTED); 1726 AssertReturn(g_pfn__WSAFDIsSet, VERR_NET_NOT_UNSUPPORTED); 1683 1727 # define select g_pfnselect 1684 1728 # define __WSAFDIsSet g_pfn__WSAFDIsSet … … 1758 1802 AssertReturn(fRead || fWrite, VERR_INVALID_PARAMETER); 1759 1803 #ifdef RT_OS_WINDOWS 1760 AssertReturn(g_pfnshutdown, VERR_N OT_SUPPORTED);1804 AssertReturn(g_pfnshutdown, VERR_NET_NOT_UNSUPPORTED); 1761 1805 # define shutdown g_pfnshutdown 1762 1806 #endif … … 1793 1837 AssertReturn(RTMemPoolRefCount(pThis) >= (pThis->cUsers ? 2U : 1U), VERR_CALLER_NO_REFERENCE); 1794 1838 #ifdef RT_OS_WINDOWS 1795 AssertReturn(g_pfngetsockname, VERR_N OT_SUPPORTED);1839 AssertReturn(g_pfngetsockname, VERR_NET_NOT_UNSUPPORTED); 1796 1840 # define getsockname g_pfngetsockname 1797 1841 #endif … … 1830 1874 AssertReturn(RTMemPoolRefCount(pThis) >= (pThis->cUsers ? 2U : 1U), VERR_CALLER_NO_REFERENCE); 1831 1875 #ifdef RT_OS_WINDOWS 1832 AssertReturn(g_pfngetpeername, VERR_N OT_SUPPORTED);1876 AssertReturn(g_pfngetpeername, VERR_NET_NOT_UNSUPPORTED); 1833 1877 # define getpeername g_pfngetpeername 1834 1878 #endif … … 1895 1939 AssertPtrReturn(pvAddr, VERR_INVALID_POINTER); 1896 1940 #ifdef RT_OS_WINDOWS 1897 AssertReturn(g_pfnbind, VERR_N OT_SUPPORTED);1941 AssertReturn(g_pfnbind, VERR_NET_NOT_UNSUPPORTED); 1898 1942 # define bind g_pfnbind 1899 1943 #endif … … 1931 1975 AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE); 1932 1976 #ifdef RT_OS_WINDOWS 1933 AssertReturn(g_pfnlisten, VERR_N OT_SUPPORTED);1977 AssertReturn(g_pfnlisten, VERR_NET_NOT_UNSUPPORTED); 1934 1978 # define listen g_pfnlisten 1935 1979 #endif … … 1971 2015 AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE); 1972 2016 #ifdef RT_OS_WINDOWS 1973 AssertReturn(g_pfnaccept, VERR_N OT_SUPPORTED);1974 AssertReturn(g_pfnclosesocket, VERR_N OT_SUPPORTED);2017 AssertReturn(g_pfnaccept, VERR_NET_NOT_UNSUPPORTED); 2018 AssertReturn(g_pfnclosesocket, VERR_NET_NOT_UNSUPPORTED); 1975 2019 # define accept g_pfnaccept 1976 2020 #endif … … 2036 2080 AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE); 2037 2081 #ifdef RT_OS_WINDOWS 2038 AssertReturn(g_pfnconnect, VERR_N OT_SUPPORTED);2039 AssertReturn(g_pfnselect, VERR_N OT_SUPPORTED);2040 AssertReturn(g_pfngetsockopt, VERR_N OT_SUPPORTED);2082 AssertReturn(g_pfnconnect, VERR_NET_NOT_UNSUPPORTED); 2083 AssertReturn(g_pfnselect, VERR_NET_NOT_UNSUPPORTED); 2084 AssertReturn(g_pfngetsockopt, VERR_NET_NOT_UNSUPPORTED); 2041 2085 # define connect g_pfnconnect 2042 2086 # define select g_pfnselect … … 2146 2190 AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE); 2147 2191 #ifdef RT_OS_WINDOWS 2148 AssertReturn(g_pfnconnect, VERR_N OT_SUPPORTED);2192 AssertReturn(g_pfnconnect, VERR_NET_NOT_UNSUPPORTED); 2149 2193 # define connect g_pfnconnect 2150 2194 #endif … … 2184 2228 AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE); 2185 2229 #ifdef RT_OS_WINDOWS 2186 AssertReturn(g_pfnsetsockopt, VERR_N OT_SUPPORTED);2230 AssertReturn(g_pfnsetsockopt, VERR_NET_NOT_UNSUPPORTED); 2187 2231 # define setsockopt g_pfnsetsockopt 2188 2232 #endif … … 2230 2274 } 2231 2275 else 2232 rc = VERR_N OT_SUPPORTED;2276 rc = VERR_NET_NOT_UNSUPPORTED; 2233 2277 2234 2278 rtSocketUnlock(pThis); … … 2282 2326 } 2283 2327 else 2284 rc = VERR_N OT_SUPPORTED;2328 rc = VERR_NET_NOT_UNSUPPORTED; 2285 2329 } 2286 2330 return rc; … … 2317 2361 } 2318 2362 else 2319 rc = VERR_N OT_SUPPORTED;2363 rc = VERR_NET_NOT_UNSUPPORTED; 2320 2364 return rc; 2321 2365 } … … 2377 2421 } 2378 2422 else if (RT_SUCCESS(rc)) 2379 rc = VERR_N OT_SUPPORTED;2423 rc = VERR_NET_NOT_UNSUPPORTED; 2380 2424 2381 2425 /* Fall back on select if we hit an error above. */ -
trunk/src/VBox/Runtime/win/RTErrConvertFromWin32.cpp
r69793 r70393 389 389 case WSAEALREADY: return VERR_NET_ALREADY_IN_PROGRESS; 390 390 case WSAEINPROGRESS: return VERR_NET_IN_PROGRESS; 391 case WSAEPROVIDERFAILEDINIT: return VERR_NET_INIT_FAILED; 392 391 393 //case WSAESTALE 116 /* Stale NFS file handle */ 392 394 //case WSAEUCLEAN 117 /* Structure needs cleaning */
Note:
See TracChangeset
for help on using the changeset viewer.