Changeset 27549 in vbox for trunk/src/VBox/Runtime/r3
- Timestamp:
- Mar 19, 2010 6:26:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/socket.cpp
r27541 r27549 124 124 * handle concurrently. */ 125 125 uint32_t volatile cUsers; 126 #ifdef RT_OS_WINDOWS127 126 /** The native socket handle. */ 128 SOCKET hNative; 127 RTSOCKETNATIVE hNative; 128 #ifdef RT_OS_WINDOWS 129 129 /** The event semaphore we've associated with the socket handle. 130 130 * This is WSA_INVALID_EVENT if not done. */ … … 138 138 * This is ZERO if we're currently not subscribing to anything. */ 139 139 uint32_t fSubscribedEvts; 140 #else 141 /** The native socket handle. */ 142 int hNative; 143 #endif 140 #endif /* RT_OS_WINDOWS */ 144 141 } RTSOCKETINT; 145 142 … … 246 243 * @param hNative The native handle. 247 244 */ 248 int rtSocketCreateForNative(RTSOCKETINT **ppSocket, 249 #ifdef RT_OS_WINDOWS 250 SOCKET hNative 251 #else 252 int hNative 253 #endif 254 ) 245 int rtSocketCreateForNative(RTSOCKETINT **ppSocket, RTSOCKETNATIVE hNative) 255 246 { 256 247 RTSOCKETINT *pThis = (RTSOCKETINT *)RTMemAlloc(sizeof(*pThis)); … … 286 277 * Create the socket. 287 278 */ 288 #ifdef RT_OS_WINDOWS 289 SOCKET hNative = socket(iDomain, iType, iProtocol); 290 if (hNative == INVALID_SOCKET) 279 RTSOCKETNATIVE hNative = socket(iDomain, iType, iProtocol); 280 if (hNative == NIL_RTSOCKETNATIVE) 291 281 return rtSocketError(); 292 #else293 int hNative = socket(iDomain, iType, iProtocol);294 if (hNative == -1)295 return rtSocketError();296 #endif297 282 298 283 /* … … 333 318 pThis->hEvent = WSA_INVALID_EVENT; 334 319 } 335 336 if (pThis->hNative != INVALID_SOCKET) 337 { 338 rc = closesocket(pThis->hNative); 339 if (!rc) 340 rc = VINF_SUCCESS; 341 else 320 #endif 321 322 if (pThis->hNative != NIL_RTSOCKETNATIVE) 323 { 324 #ifdef RT_OS_WINDOWS 325 if (closesocket(pThis->hNative)) 326 #else 327 if (close(pThis->hNative)) 328 #endif 342 329 { 343 330 rc = rtSocketError(); 344 AssertMsgFailed(("\"%s\": closesocket(%p) -> %Rrc\n", pThis->hNative, rc)); 331 #ifdef RT_OS_WINDOWS 332 AssertMsgFailed(("\"%s\": closesocket(%p) -> %Rrc\n", (uintptr_t)pThis->hNative, rc)); 333 #else 334 AssertMsgFailed(("\"%s\": close(%d) -> %Rrc\n", pThis->hNative, rc)); 335 #endif 345 336 } 346 pThis->hNative = INVALID_SOCKET; 347 } 348 349 #else 350 if (pThis->hNative != -1) 351 { 352 if (close(pThis->hNative)) 353 { 354 rc = rtSocketError(); 355 AssertMsgFailed(("\"%s\": close(%d) -> %Rrc\n", pThis->hNative, rc)); 356 } 357 pThis->hNative = -1; 358 } 359 #endif 337 pThis->hNative = NIL_RTSOCKETNATIVE; 338 } 360 339 361 340 return rc; … … 569 548 { 570 549 /* 571 * Validate input. 550 * Validate input, don't lock it because we might want to interrupt a call 551 * active on a different thread. 572 552 */ 573 553 RTSOCKETINT *pThis = hSocket; … … 575 555 AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE); 576 556 AssertReturn(fRead || fWrite, VERR_INVALID_PARAMETER); 577 //AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS);578 557 579 558 /* … … 591 570 rc = rtSocketError(); 592 571 593 rtSocketUnlock(pThis);594 572 return rc; 595 573 } … … 770 748 /* 771 749 * Validate input. 772 */ 773 RTSOCKETINT *pThis = hSocket; 774 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 775 AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE); 750 * Only lock the socket temporarily while we get the native handle, so that 751 * we can safely shutdown and destroy the socket from a different thread. 752 */ 753 RTSOCKETINT *pThis = hSocket; 754 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 755 AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE); 756 776 757 AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS); 758 759 rtSocketUnlock(pThis); 760 777 761 778 762 /* … … 783 767 #ifdef RT_OS_WINDOWS 784 768 int cbAddr = (int)*pcbAddr; 785 SOCKET hNative = accept(pThis->hNative, pAddr, &cbAddr);786 if (hNative != INVALID_SOCKET)787 769 #else 788 770 socklen_t cbAddr = *pcbAddr; 789 int hNative = accept(pThis->hNative, pAddr, &cbAddr); 790 if (hNative != -1)791 #endif 771 #endif 772 RTSOCKETNATIVE hNative = accept(pThis->hNative, pAddr, &cbAddr); 773 if (hNative != NIL_RTSOCKETNATIVE) 792 774 { 793 775 *pcbAddr = cbAddr; … … 808 790 else 809 791 rc = rtSocketError(); 810 811 rtSocketUnlock(pThis);812 792 return rc; 813 793 }
Note:
See TracChangeset
for help on using the changeset viewer.