Skip to content

Commit 3afaf6b

Browse files
author
Jason M. Miller
committed
Reduce CPU usage when stdin is null
There are some use-cases in which stdin will not be attached to the shpool client. Right now when that happens, one thread is busy-waiting on stdin. This fix adds a 200ms delay to the polling.
1 parent 0e45a86 commit 3afaf6b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

libshpool/src/protocol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use super::{consts, tty};
3131

3232
const JOIN_POLL_DUR: time::Duration = time::Duration::from_millis(100);
3333
const JOIN_HANGUP_DUR: time::Duration = time::Duration::from_millis(300);
34+
const STDIN_POLL_DUR: time::Duration = time::Duration::from_millis(200);
3435

3536
/// The centralized encoding function that should be used for all protocol
3637
/// serialization.
@@ -257,6 +258,7 @@ impl Client {
257258
loop {
258259
let nread = stdin.read(&mut buf).context("reading stdin from user")?;
259260
if nread == 0 {
261+
thread::sleep(STDIN_POLL_DUR);
260262
continue;
261263
}
262264
debug!("read {} bytes", nread);

0 commit comments

Comments
 (0)