Changeset 27288 in vbox
- Timestamp:
- Mar 11, 2010 4:37:17 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/tcp.cpp
r26915 r27288 48 48 # include <netdb.h> 49 49 # include <unistd.h> 50 # include <fcntl.h> 50 51 #endif /* !RT_OS_WINDOWS */ 51 52 #include <limits.h> … … 158 159 static DECLCALLBACK(int) rtTcpServerThread(RTTHREAD ThreadSelf, void *pvServer); 159 160 static int rtTcpServerListen(PRTTCPSERVER pServer); 160 static int r cTcpServerListenCleanup(PRTTCPSERVER pServer);161 static int rtTcpServerListenCleanup(PRTTCPSERVER pServer); 161 162 static int rtTcpServerDestroySocket(RTSOCKET volatile *pSockClient, const char *pszMsg); 162 163 static int rtTcpClose(RTSOCKET Sock, const char *pszMsg, bool fTryGracefulShutdown); … … 217 218 return VERR_UNRESOLVED_ERROR; 218 219 } 220 #endif 221 } 222 223 224 /** 225 * Helper that ensures the correct inheritability of a socket. 226 * 227 * We're currently ignoring failures. 228 * 229 * @param Socket The socket handle. 230 * @param fInheritable The desired inheritability state. 231 */ 232 static void rtTcpSetInheritance(RTSOCKET Socket, bool fInheritable) 233 { 234 #ifdef RT_OS_WINDOWS 235 /** @todo Find some magic way to change this... Worst case we have to use 236 * DuplicateHandle w/bInheritable=FALSE and replace the original 237 * handles... */ 238 #else 239 fcntl(Socket, F_SETFD, fInheritable ? 0 : FD_CLOEXEC); 219 240 #endif 220 241 } … … 357 378 rc = rtTcpServerListen(pServer); 358 379 else 359 rc = r cTcpServerListenCleanup(pServer);380 rc = rtTcpServerListenCleanup(pServer); 360 381 RTMemPoolRelease(RTMEMPOOL_DEFAULT, pServer); 361 382 NOREF(ThreadSelf); … … 425 446 if (WaitSock != -1) 426 447 { 448 rtTcpSetInheritance(WaitSock, false /*fInheritable*/); 449 427 450 /* 428 451 * Set socket options. … … 573 596 if ( enmState != RTTCPSERVERSTATE_ACCEPTING 574 597 && enmState != RTTCPSERVERSTATE_SERVING) 575 return r cTcpServerListenCleanup(pServer);598 return rtTcpServerListenCleanup(pServer); 576 599 if (!rtTcpServerTrySetState(pServer, RTTCPSERVERSTATE_ACCEPTING, enmState)) 577 600 continue; … … 589 612 /* These are typical for what can happen during destruction. */ 590 613 if (errno == EBADF || errno == EINVAL || errno == ENOTSOCK) 591 return r cTcpServerListenCleanup(pServer);614 return rtTcpServerListenCleanup(pServer); 592 615 #endif 593 616 continue; 594 617 } 618 rtTcpSetInheritance(Socket, false /*fInheritable*/); 595 619 596 620 /* … … 600 624 { 601 625 rtTcpClose(Socket, "rtTcpServerListen", true /*fTryGracefulShutdown*/); 602 return r cTcpServerListenCleanup(pServer);626 return rtTcpServerListenCleanup(pServer); 603 627 } 604 628 rtTcpAtomicXchgSock(&pServer->SockClient, Socket); … … 622 646 } 623 647 else 624 r cTcpServerListenCleanup(pServer); /* ignore rc */648 rtTcpServerListenCleanup(pServer); /* ignore rc */ 625 649 return rc; 626 650 } … … 632 656 * Clean up after listener. 633 657 */ 634 static int r cTcpServerListenCleanup(PRTTCPSERVER pServer)658 static int rtTcpServerListenCleanup(PRTTCPSERVER pServer) 635 659 { 636 660 /* … … 706 730 && enmState != RTTCPSERVERSTATE_CREATED) 707 731 { 708 rc = r cTcpServerListenCleanup(pServer);732 rc = rtTcpServerListenCleanup(pServer); 709 733 break; 710 734 } … … 729 753 rc = rtTcpError(); 730 754 if (!rtTcpServerTrySetState(pServer, RTTCPSERVERSTATE_CREATED, RTTCPSERVERSTATE_ACCEPTING)) 731 rc = r cTcpServerListenCleanup(pServer);755 rc = rtTcpServerListenCleanup(pServer); 732 756 if (RT_FAILURE(rc)) 733 757 break; 734 758 continue; 735 759 } 760 rtTcpSetInheritance(Socket, false /*fInheritable*/); 736 761 737 762 /* … … 740 765 if (rtTcpServerTrySetState(pServer, RTTCPSERVERSTATE_SERVING, RTTCPSERVERSTATE_ACCEPTING)) 741 766 { 767 RTSOCKET OldSocket = rtTcpAtomicXchgSock(&pServer->SockClient, Socket); 768 Assert(OldSocket == NIL_RTSOCKET); NOREF(OldSocket); 742 769 *pSockClient = Socket; 743 770 rc = VINF_SUCCESS; … … 746 773 { 747 774 rtTcpClose(Socket, "RTTcpServerListen2", true /*fTryGracefulShutdown*/); 748 rc = r cTcpServerListenCleanup(pServer);775 rc = rtTcpServerListenCleanup(pServer); 749 776 } 750 777 break; … … 1151 1178 if (Sock != -1) 1152 1179 { 1180 rtTcpSetInheritance(Sock, false /*fInheritable*/); 1181 1153 1182 struct sockaddr_in InAddr; 1154 1183 RT_ZERO(InAddr);
Note:
See TracChangeset
for help on using the changeset viewer.