add more comments

This commit is contained in:
Will Greenberg
2023-11-15 11:07:08 -08:00
parent 4729525235
commit f319ee8d70

View File

@@ -26,10 +26,11 @@ enum DiagDeviceError {
}
struct DiagDevice {
pub file: File,
file: File,
use_mdm: i32,
}
// Triggers the diag device's debug logging mode
fn enable_frame_readwrite(fd: i32, mode: i32) -> DiagResult<()> {
unsafe {
if libc::ioctl(fd, DIAG_IOCTL_SWITCH_LOGGING, mode, 0, 0, 0) < 0 {
@@ -48,6 +49,8 @@ fn enable_frame_readwrite(fd: i32, mode: i32) -> DiagResult<()> {
Ok(())
}
// Unsure of what MDM actually stands for, but if `use_mdm` is > 0, then
// an additional mask is included in every diag request
fn determine_use_mdm(fd: i32) -> DiagResult<i32> {
let use_mdm: i32 = 0;
unsafe {
@@ -133,14 +136,20 @@ fn main() -> std::io::Result<()> {
println!("Starting server");
let listener = TcpListener::bind("0.0.0.0:43555")?;
// Since we only care about one client at a time, store a copy of that
// client's TcpStream in a mutex. This lets us write to the client from a
// separate thread
let client_mutex: Arc<Mutex<Option<TcpStream>>> = Arc::new(Mutex::new(None));
// initialize the diag device and create a cloned handle to its file. this
// lets us perform reads and writes in separate threads. i *think* this is
// sound
let mut dev_reader = DiagDevice::new().unwrap();
let mut dev_writer = dev_reader.try_clone().unwrap();
// Spawn a thread to continuously read from the diag device, sending any
// messages to the client
let client_mutex_clone = client_mutex.clone();
// Spawn a thread to continuously read from the diag device, sending
// messages to the client (if any)
thread::spawn(move || {
loop {
match dev_reader.read_response() {