vbox的更動 24204 路徑 trunk/src/VBox/Runtime/r3/tcp.cpp
- 時間撮記:
- 2009-10-30 下午04:00:40 (15 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Runtime/r3/tcp.cpp
r23666 r24204 56 56 #include <iprt/string.h> 57 57 #include <iprt/thread.h> 58 #include <iprt/time.h> 58 59 59 60 #include "internal/magics.h" … … 72 73 # else 73 74 # define SHUT_RDWR 2 75 # endif 76 #endif 77 #ifndef SHUT_WR 78 # ifdef SD_SEND 79 # define SHUT_WR SD_SEND 80 # else 81 # define SHUT_WR 1 74 82 # endif 75 83 #endif … … 140 148 static int rcTcpServerListenCleanup(PRTTCPSERVER pServer); 141 149 static int rtTcpServerDestroySocket(RTSOCKET volatile *pSockClient, const char *pszMsg); 142 static int rtTcpClose(RTSOCKET Sock, const char *pszMsg );150 static int rtTcpClose(RTSOCKET Sock, const char *pszMsg, bool fTryGracefulShutdown); 143 151 144 152 … … 243 251 * @returns IPRT status code. 244 252 */ 245 static int rtTcpServerDestroySocket(RTSOCKET volatile *pSock, const char *pszMsg )253 static int rtTcpServerDestroySocket(RTSOCKET volatile *pSock, const char *pszMsg, bool fTryGracefulShutdown) 246 254 { 247 255 RTSOCKET Sock = rtTcpAtomicXchgSock(pSock, NIL_RTSOCKET); 248 256 if (Sock != NIL_RTSOCKET) 249 257 { 250 shutdown(Sock, SHUT_RDWR); 251 return rtTcpClose(Sock, pszMsg); 258 if (!fTryGracefulShutdown) 259 shutdown(Sock, SHUT_RDWR); 260 return rtTcpClose(Sock, pszMsg, fTryGracefulShutdown); 252 261 } 253 262 return VINF_TCP_SERVER_NO_CLIENT; … … 467 476 AssertMsgFailed(("setsockopt() %Rrc\n", rc)); 468 477 } 469 rtTcpClose(WaitSock, "RTServerCreateEx" );478 rtTcpClose(WaitSock, "RTServerCreateEx", false /*fTryGracefulShutdown*/); 470 479 } 471 480 else … … 575 584 if (!rtTcpServerTrySetState(pServer, RTTCPSERVERSTATE_SERVING, RTTCPSERVERSTATE_ACCEPTING)) 576 585 { 577 rtTcpClose(Socket, "rtTcpServerListen" );586 rtTcpClose(Socket, "rtTcpServerListen", true /*fTryGracefulShutdown*/); 578 587 return rcTcpServerListenCleanup(pServer); 579 588 } 580 589 rtTcpAtomicXchgSock(&pServer->SockClient, Socket); 581 590 int rc = pServer->pfnServe(Socket, pServer->pvUser); 582 rtTcpServerDestroySocket(&pServer->SockClient, "Listener: client" );591 rtTcpServerDestroySocket(&pServer->SockClient, "Listener: client", true /*fTryGracefulShutdown*/); 583 592 584 593 /* … … 595 604 RTSOCKET SockServer = rtTcpAtomicXchgSock(&pServer->SockServer, NIL_RTSOCKET); 596 605 rtTcpServerSetState(pServer, RTTCPSERVERSTATE_STOPPED, RTTCPSERVERSTATE_STOPPING); 597 rtTcpClose(SockServer, "Listener: server stopped" );606 rtTcpClose(SockServer, "Listener: server stopped", false /*fTryGracefulShutdown*/); 598 607 } 599 608 else … … 613 622 * Close the server socket, the client one shouldn't be set. 614 623 */ 615 rtTcpServerDestroySocket(&pServer->SockServer, "ListenCleanup" );624 rtTcpServerDestroySocket(&pServer->SockServer, "ListenCleanup", false /*fTryGracefulShutdown*/); 616 625 Assert(pServer->SockClient == NIL_RTSOCKET); 617 626 … … 656 665 AssertReturn(RTMemPoolRetain(pServer) != UINT32_MAX, VERR_INVALID_HANDLE); 657 666 658 int rc = rtTcpServerDestroySocket(&pServer->SockClient, "DisconnectClient: client" );667 int rc = rtTcpServerDestroySocket(&pServer->SockClient, "DisconnectClient: client", true /*fTryGracefulShutdown*/); 659 668 660 669 RTMemPoolRelease(RTMEMPOOL_DEFAULT, pServer); … … 706 715 if (rtTcpServerTrySetState(pServer, RTTCPSERVERSTATE_STOPPING, enmState)) 707 716 { 708 rtTcpServerDestroySocket(&pServer->SockServer, "RTTcpServerShutdown" );717 rtTcpServerDestroySocket(&pServer->SockServer, "RTTcpServerShutdown", false /*fTryGracefulShutdown*/); 709 718 rtTcpServerSetState(pServer, RTTCPSERVERSTATE_STOPPED, RTTCPSERVERSTATE_STOPPING); 710 719 … … 770 779 */ 771 780 ASMAtomicWriteU32(&pServer->u32Magic, ~RTTCPSERVER_MAGIC); 772 rtTcpServerDestroySocket(&pServer->SockServer, "Destroyer: server" );773 rtTcpServerDestroySocket(&pServer->SockClient, "Destroyer: client" );781 rtTcpServerDestroySocket(&pServer->SockServer, "Destroyer: server", false /*fTryGracefulShutdown*/); 782 rtTcpServerDestroySocket(&pServer->SockClient, "Destroyer: client", true /*fTryGracefulShutdown*/); 774 783 775 784 /* … … 945 954 } 946 955 rc = rtTcpError(); 947 rtTcpClose(Sock, "RTTcpClientConnect" );956 rtTcpClose(Sock, "RTTcpClientConnect", false /*fTryGracefulShutdown*/); 948 957 } 949 958 else … … 955 964 RTR3DECL(int) RTTcpClientClose(RTSOCKET Sock) 956 965 { 957 return rtTcpClose(Sock, "RTTcpClientClose" );966 return rtTcpClose(Sock, "RTTcpClientClose", true /*fTryGracefulShutdown*/); 958 967 } 959 968 … … 962 971 * Internal close function which does all the proper bitching. 963 972 */ 964 static int rtTcpClose(RTSOCKET Sock, const char *pszMsg) 965 { 973 static int rtTcpClose(RTSOCKET Sock, const char *pszMsg, bool fTryGracefulShutdown) 974 { 975 int rc; 976 966 977 /* ignore nil handles. */ 967 978 if (Sock == NIL_RTSOCKET) … … 969 980 970 981 /* 982 * Try to gracefully shut it down. 983 */ 984 if (fTryGracefulShutdown) 985 { 986 rc = shutdown(Sock, SHUT_WR); 987 if (!rc) 988 { 989 uint64_t u64Start = RTTimeMilliTS(); 990 for (;;) 991 { 992 rc = RTTcpSelectOne(Sock, 1000); 993 if (rc == VERR_TIMEOUT) 994 { 995 if (RTTimeMilliTS() - u64Start > 30000) 996 break; 997 } 998 else if (rc != VINF_SUCCESS) 999 break; 1000 { 1001 uint8_t abBitBucket[16*_1KB]; 1002 ssize_t cbBytesRead = recv(Sock, abBitBucket, sizeof(abBitBucket), MSG_NOSIGNAL); 1003 if (cbBytesRead == 0) 1004 break; /* orderly shutdown in progress */ 1005 if (cbBytesRead < 0) 1006 break; /* some kind of error, never mind which... */ 1007 } 1008 } /* forever */ 1009 } 1010 } 1011 1012 /* 971 1013 * Attempt to close it. 972 1014 */ 973 1015 #ifdef RT_OS_WINDOWS 974 intrc = closesocket(Sock);1016 rc = closesocket(Sock); 975 1017 #else 976 intrc = close(Sock);1018 rc = close(Sock); 977 1019 #endif 978 1020 if (!rc)
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器