Skip to content

Commit 0b47e50

Browse files
committed
std: sys: stdio: uefi: Do not retry on NOT_READY
Since NOT_READY is now used to signal read 0. Remove the loop which would always retry on NOT_READY status. Instead, use the following algorithm: 1. Try reading any pending characters. Return if present. 2. If no pending character, NOT_READY is returned. 3. Wait for key. 4. Return the key or error. Signed-off-by: Ayush Singh <[email protected]>
1 parent 188cfec commit 0b47e50

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

library/std/src/sys/stdio/uefi.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,17 @@ unsafe fn simple_text_output(
184184
fn simple_text_input_read(
185185
stdin: *mut r_efi::protocols::simple_text_input::Protocol,
186186
) -> io::Result<u16> {
187-
loop {
188-
match read_key_stroke(stdin) {
189-
Ok(x) => return Ok(x.unicode_char),
190-
Err(e) if e == r_efi::efi::Status::NOT_READY => wait_stdin(stdin)?,
191-
Err(e) => return Err(io::Error::from_raw_os_error(e.as_usize())),
192-
}
187+
// Try reading any pending keys. Else wait for a new character
188+
match read_key_stroke(stdin) {
189+
Ok(x) => return Ok(x.unicode_char),
190+
Err(e) if e == r_efi::efi::Status::NOT_READY => wait_stdin(stdin)?,
191+
Err(e) => return Err(io::Error::from_raw_os_error(e.as_usize())),
193192
}
193+
194+
// Try reading a key after the wait.
195+
read_key_stroke(stdin)
196+
.map(|x| x.unicode_char)
197+
.map_err(|e| io::Error::from_raw_os_error(e.as_usize()))
194198
}
195199

196200
fn wait_stdin(stdin: *mut r_efi::protocols::simple_text_input::Protocol) -> io::Result<()> {

0 commit comments

Comments
 (0)