11-11-2022 04:27 AM
Hi all We appreciate the person who provided this service. However, I ran into several issues with it. My issue is that each call to "Raw Socket Ping" consumes 3 Windows Handles and never releases them (viewable in Task Manager by adding the Handles column). I'm not sure how many handles Win has available, but they are few, and once you're out, there's nothing else you can do on the PC till you close the LV software. I determined that the WSASocket() and SendTo DLL functions were the source of the issue (). These procedures each take hold of 2 and 1 handles, and WSACleanup() never releases them. I simply refer to the vi as "Raw Socket Ping."
11-11-2022 06:27 AM
First, the WSAStartup() should definitely not be called ad afinitum over and over again. You should at least remember that you called it already and then skip that.
Second, LabVIEW already calls WSAStartup very early on during its own startup so calling it again should be completely unnecessary.
But it's not sendto() that uses up a handle every time but the Setup For Ping.vi creates a new socket every time (which behind the scene simply is a handle), but that socket is never getting closed after use. There should be a call to closesocket() after (or inside) the Get Reply.vi. This open handle is most likely what also prevents the call to WSACleanup() to close the two handles that were opened in WSAStartup(), as they are in fact referenced by this socket handle.
Also that library has several potential problems when run in 64-bit LabVIEW.
Third, you should probably look into using the Windows API IcmpSendEcho() instead. This supposedly is handled behind the scenes through a Windows service (with the appropriate privileges to open a raw ICMP socket) and communicate with it from this API.
Solves a lot of problems at once:
- The elevated privilege for the user process is not required, since the ICMP message handling is really done in a kernel service that has the appropriate privileges anyway.
- You don't need to make sure that the WinSock library is properly initialized and there should be no spurious handles getting allocated anymore.
- It's pretty much a call to IcmpCreateFile(), IcmpSendEcho() and IcmpCloseHandle() and that's it.