Poll PTY and keyboard when there is no data

This commit is contained in:
pjht 2024-09-20 14:42:41 -05:00
parent 598318ecf5
commit 6e9938c5fc
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A
3 changed files with 54 additions and 2 deletions

39
Cargo.lock generated
View File

@ -22,6 +22,9 @@ name = "bitflags"
version = "2.6.0" version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "byteorder" name = "byteorder"
@ -59,6 +62,16 @@ version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d"
[[package]]
name = "file_rpc"
version = "0.1.0"
dependencies = [
"bitflags",
"parking_lot",
"postcard",
"serde",
]
[[package]] [[package]]
name = "hash32" name = "hash32"
version = "0.2.1" version = "0.2.1"
@ -86,6 +99,7 @@ dependencies = [
name = "init_phase2" name = "init_phase2"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"file_rpc",
"syslog_msg_ipc", "syslog_msg_ipc",
"syslog_rpc", "syslog_rpc",
] ]
@ -139,9 +153,21 @@ dependencies = [
"embedded-io 0.4.0", "embedded-io 0.4.0",
"embedded-io 0.6.1", "embedded-io 0.6.1",
"heapless", "heapless",
"postcard-derive",
"serde", "serde",
] ]
[[package]]
name = "postcard-derive"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0239fa9c1d225d4b7eb69925c25c5e082307a141e470573fbbe3a817ce6a7a37"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.86" version = "1.0.86"
@ -207,7 +233,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.77",
] ]
[[package]] [[package]]
@ -231,6 +257,17 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.77" version = "2.0.77"

View File

@ -4,5 +4,6 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
file_rpc = { version = "0.1.0", path = "../file_rpc" }
syslog_msg_ipc = { version = "0.1.0", path = "../syslog/syslog_msg_ipc" } syslog_msg_ipc = { version = "0.1.0", path = "../syslog/syslog_msg_ipc" }
syslog_rpc = { version = "0.1.0", path = "../syslog/syslog_rpc" } syslog_rpc = { version = "0.1.0", path = "../syslog/syslog_rpc" }

View File

@ -1,10 +1,11 @@
use std::{ use std::{
fs::File, fs::File,
io::{Read, Write}, io::{Read, Write},
os::mikros::{ipc, syscalls}, os::mikros::{fs::FileExt, ipc, syscalls},
process::Command, process::Command,
}; };
use file_rpc::{PendingPoll, PollEvents};
use syslog_rpc::Message; use syslog_rpc::Message;
struct SyslogMessageHandler { struct SyslogMessageHandler {
@ -71,9 +72,22 @@ fn main() {
let mut kbd_buf = [0u8; 512]; let mut kbd_buf = [0u8; 512];
let mut pty_buf = [0u8; 512]; let mut pty_buf = [0u8; 512];
let (kbd_pid, kbd_fd) = kbd.get_pid_fd();
let (pty_pid, pty_fd) = pty.get_pid_fd();
let kbd_pid_client = file_rpc::Client::new(kbd_pid);
let pty_pid_client = file_rpc::Client::new(pty_pid);
loop { loop {
let kbd_len = kbd.read(&mut kbd_buf).unwrap(); let kbd_len = kbd.read(&mut kbd_buf).unwrap();
let pty_len = pty.read(&mut pty_buf).unwrap(); let pty_len = pty.read(&mut pty_buf).unwrap();
if kbd_len == 0 && pty_len == 0 {
let kbd_poll = kbd_pid_client.poll(kbd_fd, PollEvents::POLLIN);
let pty_poll = pty_pid_client.poll(pty_fd, PollEvents::POLLIN);
PendingPoll::get_list_result(&[kbd_poll, pty_poll]);
continue;
}
pty.write_all(&kbd_buf[..kbd_len]).unwrap(); pty.write_all(&kbd_buf[..kbd_len]).unwrap();
display.write_all(&pty_buf[..pty_len]).unwrap(); display.write_all(&pty_buf[..pty_len]).unwrap();
} }