0

First of all, please look this question to understand what I mentioned.

When I try socket close in windows OS for unreachable IP with UDP, I got the three-second delay.

As you can see from the results there is the three-second delay in Windows OS. But there is no delay in Ubuntu namely problem is related Windows Operating System. How to decrease the three-second delay to the zero?

Windows Socket Close Time for Unreachable IP(with UDP): 3 seconds
Ubuntu Socket Close Time for Unreachable IP(with UDP): 0 Second

Thanks in advance...

  • What is different about this question that's not addressed by the one you're referencing? Are you opening a new question on ServerFault to draw attention to the first on StackOverflow? – Matthew Wetmore Jul 10 '17 at 15:47
  • @MatthewWetmore . After lots of tests and results, I have understood this problem is not related to a programming language. It's related to an Operating system so I have wanted to ask that question to the Serverfault. – Salih Karagöz Jul 11 '17 at 05:19

1 Answers1

1

Here's a silly example from .NET docs that takes a connectionless protocol and uses connect() just so it can block like crazy and almost certainly wait a few seconds at the end for the stray ICMP unreachable to maybe arrive:
https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.udpclient?view=netframework-4.7

this is your answer on what to do in windows to get out of that UDP socket fast:
(IMHO if it respected what UDP was trying to accomplish it would use asynchronous send/recv, set Linger to false, and for good measure set the send and recieve timeouts to smallish milliseconds even though they shouldn't matter...and then just terminate without cleaning up after itself...)
Seriously, here's MSDN elaborating on how that works:
https://stackoverflow.com/questions/4160347/close-vs-shutdown-socket?rq=1

This post gets at the importance of setting the handle to non-blocking (SOCK_STREAM blocks by default in windows).
https://stackoverflow.com/questions/17058224/concept-of-non-blocking-socket-functions-using-wsawaitformultipleevents?rq=1

Here's a more portable way of doing it (rather than deal with windows setsocketopt() or similar -- poll() or select() before shutting down)
https://stackoverflow.com/questions/16163260/setting-timeout-for-recv-fcn-of-a-udp-socket?rq=1

Here's python reminding us that if you send it UDP you shouldn't necessarily expect anything back. And also explaining the error:
https://stackoverflow.com/questions/34242622/windows-udp-sockets-recvfrom-fails-with-error-10054?rq=1

You really don't need to close your UDP sockets if you're leaving anyway. Be a slob.
https://stackoverflow.com/questions/19819927/when-to-close-a-udp-socket?rq=1
At least setsocketopt() REUSE in case you want it later (say, in a loop).

Close vs. Shutdown (TCP, mostly) in case you're still not convinced:
https://stackoverflow.com/questions/4160347/close-vs-shutdown-socket?rq=1

And here are some reasons you should clean up after yourself:
https://stackoverflow.com/questions/12776563/what-is-the-drawback-if-i-do-not-invoke-the-udpclient-close-method

quadruplebucky
  • 5,139
  • 20
  • 23