- Timestamp:
- Oct 23, 2024 4:20:54 AM (5 weeks ago)
- Location:
- trunk/src/VBox/Devices
- Files:
-
- 2 deleted
- 2 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Makefile.kmk
r106345 r106608 780 780 Network/DrvNATlibslirp.cpp 781 781 VBoxDD_SOURCES.win += \ 782 Network/RTWin PollLibslirp.cpp782 Network/RTWinSocketPair.cpp 783 783 Network/DrvNATlibslirp.cpp_INCS += \ 784 784 $(PATH_ROOT)/src/libs/libslirp-4.8.0/src \ -
trunk/src/VBox/Devices/Network/DrvNATlibslirp.cpp
r106273 r106608 37 37 # include <iprt/win/winsock2.h> 38 38 # include <iprt/win/ws2tcpip.h> 39 # include "winutils.h" 40 # define inet_aton(x, y) inet_pton(2, x, y) 41 # define AF_INET6 23 39 42 #endif 40 43 … … 52 55 # include <errno.h> 53 56 #endif 57 54 58 #ifdef RT_OS_FREEBSD 55 59 # include <netinet/in.h> 56 60 #endif 57 61 58 #ifdef RT_OS_WINDOWS 59 # include <iprt/win/winsock2.h> 60 # include "winpoll.h" 61 # define inet_aton(x, y) inet_pton(2, x, y) 62 # define AF_INET6 23 63 #endif 64 62 #include <iprt/asm.h> 65 63 #include <iprt/assert.h> 66 64 #include <iprt/critsect.h> … … 221 219 /** The read end of the control pipe. */ 222 220 RTPIPE hPipeRead; 223 # if HC_ARCH_BITS == 32224 uint32_t u32Padding;225 # endif226 221 #else 227 /* * for external notification*/228 HANDLE hWakeupEvent;222 /* wakeup socket pair for NAT thread */ 223 SOCKET pWakeupSockPair[2]; 229 224 #endif 225 /* count of bytes sent to notify NAT thread */ 226 volatile uint64_t cbWakeupNotifs; 230 227 231 228 #define DRV_PROFILE_COUNTER(name, dsc) STAMPROFILE Stat ## name … … 603 600 size_t cbIgnored; 604 601 rc = RTPipeWrite(pThis->hPipeWrite, "", 1, &cbIgnored); 602 if (RT_SUCCESS(rc)) 603 { 604 /* Count how many bites we send down the socket */ 605 ASMAtomicIncU64(&pThis->cbWakeupNotifs); 606 } 605 607 #else 606 /* kick WSAWaitForMultipleEvents */ 607 rc = WSASetEvent(pThis->hWakeupEvent); 608 int cbWritten = send(pThis->pWakeupSockPair[0], "", 1, NULL); 609 if (cbWritten == SOCKET_ERROR) 610 { 611 int error = WSAGetLastError(); 612 Log4(("Notify NAT Thread Error %d\n", error)); 613 } 614 else 615 { 616 /* Count how many bites we send down the socket */ 617 ASMAtomicIncU64(&pThis->cbWakeupNotifs); 618 } 608 619 #endif 609 620 AssertRC(rc); … … 704 715 { 705 716 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT); 706 #ifdef VBOX_NAT_DELAY_HACK707 unsigned int cBreak = 0;708 #endif 709 # ifndef RT_OS_WINDOWS717 #ifdef RT_OS_WINDOWS 718 drvNAT_AddPollCb(pThis->pWakeupSockPair[1], SLIRP_POLL_IN | SLIRP_POLL_HUP, pThis); 719 pThis->pNATState->polls[0].fd = pThis->pWakeupSockPair[1]; 720 #else 710 721 unsigned int cPollNegRet = 0; 711 722 drvNAT_AddPollCb(RTPipeToNative(pThis->hPipeRead), SLIRP_POLL_IN | SLIRP_POLL_HUP, pThis); … … 764 775 * device's thread sends before we've entered multiplex, 765 776 * so to avoid false alarm drain pipe here to the very end 766 *767 * @todo: Probably we should counter drvNATSend to count how768 * deep pipe has been filed before drain.769 *770 777 */ 771 /** @todo XXX: Make it reading exactly we need to drain the772 * pipe.*/773 778 char ch; 774 779 size_t cbRead; 775 RTPipeRead(pThis->hPipeRead, &ch, 1, &cbRead); 780 uint64_t cbWakeupNotifs = ASMAtomicReadU64(&pThis->cbWakeupNotifs); 781 RTPipeRead(pThis->hPipeRead, &ch, cbWakeupNotifs, &cbRead); 782 ASMAtomicSubU64(&pThis->cbWakeupNotifs, cbRead); 776 783 } 777 784 … … 782 789 #else /* RT_OS_WINDOWS */ 783 790 uint32_t msTimeout = DRVNAT_DEFAULT_TIMEOUT; 784 pThis->pNATState->nsock = 0;791 pThis->pNATState->nsock = 1; 785 792 slirp_pollfds_fill(pThis->pNATState->pSlirp, &msTimeout, drvNAT_AddPollCb /* SlirpAddPollCb */, pThis /* opaque */); 786 793 drvNAT_UpdateTimeout(&msTimeout, pThis); 787 794 788 int cChangedFDs = 0; 789 int vrc = RTWinPoll(pThis->pNATState->polls, pThis->pNATState->nsock, msTimeout, &cChangedFDs, pThis->hWakeupEvent); 790 if (vrc != VINF_SUCCESS) 791 { 792 if (vrc != VERR_TIMEOUT) 793 LogRel(("NAT: RTWinPoll returned vrc=%Rrc (cChangedFDs=%d)\n", vrc, cChangedFDs)); 795 int cChangedFDs = WSAPoll(pThis->pNATState->polls, pThis->pNATState->nsock, msTimeout /* timeout */); 796 int error = WSAGetLastError(); 797 if (cChangedFDs == SOCKET_ERROR) 798 { 799 LogRel(("NAT: RTWinPoll returned error=%Rrc (cChangedFDs=%d)\n", error, cChangedFDs)); 794 800 Log4(("NAT: NSOCK = %d\n", pThis->pNATState->nsock)); 801 } 802 803 if (pThis->pNATState->polls[0].revents & (POLLIN)) 804 { 805 /* drain the pipe 806 * 807 * Note! drvNATSend decoupled so we don't know how many times 808 * device's thread sends before we've entered multiplex, 809 * so to avoid false alarm drain pipe here to the very end 810 */ 811 char ch; 812 size_t cbRead; 813 uint64_t cbWakeupNotifs = ASMAtomicReadU64(&pThis->cbWakeupNotifs); 814 cbRead = recv(pThis->pWakeupSockPair[1], &ch, cbWakeupNotifs, NULL); 815 ASMAtomicSubU64(&pThis->cbWakeupNotifs, cbRead); 795 816 } 796 817 … … 809 830 RTReqQueueProcess(pThis->hSlirpReqQueue, 0); 810 831 drvNAT_CheckTimeout(pThis); 811 # ifdef VBOX_NAT_DELAY_HACK812 if (cBreak++ > 128)813 {814 cBreak = 0;815 RTThreadSleep(2);816 }817 # endif818 832 #endif /* RT_OS_WINDOWS */ 819 833 } … … 1703 1717 AssertRCReturn(rc, rc); 1704 1718 #else 1705 // Create the wakeup event handle. 1706 pThis->hWakeupEvent = NULL; 1707 pThis->hWakeupEvent = CreateEvent(NULL, FALSE, FALSE, NULL); /* auto-reset event */ 1708 Assert(pThis->hWakeupEvent != NULL); 1719 // Create the wakeup socket pair. 1720 pThis->pWakeupSockPair[0] = NULL; 1721 pThis->pWakeupSockPair[1] = NULL; 1722 1723 /* idx=0 is write, idx=1 is read */ 1724 rc = RTWinSocketPair(AF_INET, SOCK_DGRAM, 0, pThis->pWakeupSockPair); 1725 AssertRCReturn(rc, rc); 1709 1726 #endif 1727 /* initalize the notifier counter */ 1728 pThis->cbWakeupNotifs = 0; 1710 1729 1711 1730 rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pSlirpThread, pThis, drvNATAsyncIoThread, -
trunk/src/VBox/Devices/Network/winutils.h
r106585 r106608 26 26 */ 27 27 28 #ifndef VBOX_INCLUDED_SRC_N AT_winutils_h29 #define VBOX_INCLUDED_SRC_N AT_winutils_h28 #ifndef VBOX_INCLUDED_SRC_Network_winutils_h 29 #define VBOX_INCLUDED_SRC_Network_winutils_h 30 30 #ifndef RT_WITHOUT_PRAGMA_ONCE 31 31 # pragma once … … 218 218 } 219 219 220 #endif /* !VBOX_INCLUDED_SRC_N AT_winutils_h */220 #endif /* !VBOX_INCLUDED_SRC_Network_winutils_h */
Note:
See TracChangeset
for help on using the changeset viewer.