James Lohr
unread,Nov 19, 2020, 5:43:46 AM11/19/20Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to kryonet-users
Hello,
I'd like to submit a bug fix for the following issue:
When calling server.update(int timeout) with a value smaller than 25ms, the method will occasionally return after 25+ ms.
Example, calling server.update(13) will typically return in 13ms, but occasionally takes 25-26ms.
The reason for this is the following code, which looks like a workaround for an issue with nio:
// NIO freaks and returns immediately with 0 sometimes, so try to keep from hogging the CPU.
long elapsedTime = System.currentTimeMillis() - startTime;
try {
if (elapsedTime < 25) Thread.sleep(25 - elapsedTime);
} catch (InterruptedException ex) {
}
I think that a better solution, which would resolve the above issue, is the following:
// NIO freaks and returns immediately with 0 sometimes, so try to keep from hogging the CPU.
long elapsedTime = System.currentTimeMillis() - startTime;
try {
int targetDuration = Math.min(timeout,25);
if (elapsedTime < targetDuration) Thread.sleep(targetDuration - elapsedTime);
} catch (InterruptedException ex) {
}
I'm not often contributed to opensource projects, so will need a bit of help in submitting a fix.
I have tried downloading the full Kryonet source, and while it compiles fine (I'm using Intellij), and I'm able to run unit tests individually, when I try to mvn install , the tests fail with some of them timing out.
Cheers,