Skip to content

Commit

Permalink
Always check available() in InputPumper to avoid burning CPU (#4095)
Browse files Browse the repository at this point in the history
Attempts to fix #4092

Instead of checking `src.available() == 0`, we check for
`src.read(buffer) == 0`, which should provide a more accurate measure
  • Loading branch information
lihaoyi authored Dec 10, 2024
1 parent 8c2de86 commit 1eb4a04
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions main/client/src/mill/main/client/InputPumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,17 @@ public void run() {
byte[] buffer = new byte[1024];
try {
while (running) {
if (!runningCheck.getAsBoolean()) {
running = false;
} else if (checkAvailable && src.available() == 0) Thread.sleep(1);
if (!runningCheck.getAsBoolean()) running = false;
else {
int n;
try {
n = src.read(buffer);
} catch (Exception e) {
n = -1;
}
if (n == -1) {
running = false;
} else {
if (n == -1) running = false;
else if (n == 0) Thread.sleep(1);
else {
try {
dest.write(buffer, 0, n);
dest.flush();
Expand Down

0 comments on commit 1eb4a04

Please sign in to comment.