truvorskameikin / udp-discovery-cpp

A small library to add local network discovery feature to your C++ programs with no dependencies
MIT License
60 stars 28 forks source link

to_sleep_ms can be negative, causing SleepFor to wait for (almost) ever #34

Open teub opened 2 years ago

teub commented 2 years ago

Hello,

IsRightTime can set a negative value to to_sleep_until_next_delete_idle, causing the subsequent call to SleepFor to wait for a very long time on windows, and the process getting stuck when calling Stop(true) on the peer. Indeed, Sleep((DWORD)time_ms) casts the negative value to a very large positive value.

I don't know if IsRightTime is buggy; a possible fix would be replacing "SleepFor(to_sleep_ms);" with "SleepFor(std::max((long)0, to_sleep_ms));", or maybe do the check in the function itself.