Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions console_backend/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,7 @@ mod tests {
backup_file(bfilename.clone());
let shared_state = SharedState::new();
let (client_send_, client_receive) = mpsc::channel::<Vec<u8>>();
let client_send = ClientSender {
inner: client_send_,
};
let client_send = ClientSender::new(client_send_);
let connection_state = ConnectionState::new(client_send, shared_state.clone());
let filename = TEST_SHORT_FILEPATH.to_string();
receive_thread(client_receive);
Expand All @@ -417,9 +415,7 @@ mod tests {
backup_file(bfilename.clone());
let shared_state = SharedState::new();
let (client_send_, client_receive) = mpsc::channel::<Vec<u8>>();
let client_send = ClientSender {
inner: client_send_,
};
let client_send = ClientSender::new(client_send_);
let connection_state = ConnectionState::new(client_send, shared_state.clone());
let filename = TEST_SHORT_FILEPATH.to_string();
receive_thread(client_receive);
Expand Down Expand Up @@ -449,9 +445,7 @@ mod tests {
backup_file(bfilename.clone());
let shared_state = SharedState::new();
let (client_send_, client_receive) = mpsc::channel::<Vec<u8>>();
let client_send = ClientSender {
inner: client_send_,
};
let client_send = ClientSender::new(client_send_);
let connection_state = ConnectionState::new(client_send.clone(), shared_state.clone());
let filename = TEST_FILEPATH.to_string();
let expected_duration = Duration::from_secs_f64(SERVER_STATE_CONNECTION_LOOP_TIMEOUT_SEC)
Expand Down
20 changes: 10 additions & 10 deletions console_backend/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use std::{
path::PathBuf,
str::FromStr,
sync::mpsc,
thread,
time,
thread, time,
};

use crate::cli_options::*;
Expand Down Expand Up @@ -119,35 +118,36 @@ fn handle_cli(opt: CliOptions, connection_state: &ConnectionState, shared_state:
impl Server {
#[new]
pub fn __new__() -> Self {
Server { client_recv: None, client_sender: None }
Server {
client_recv: None,
client_sender: None,
}
}

#[text_signature = "($self, /)"]
pub fn fetch_message(&mut self, py: Python) -> Option<PyObject> {
let result = py.allow_threads(move || loop {
if let Some(client_recv) = &self.client_recv {
match client_recv.recv_timeout(time::Duration::from_millis(1)) {
Ok(buf) => {
break Some(buf)
}
Ok(buf) => break Some(buf),
Err(err) => {
use std::sync::mpsc::RecvTimeoutError;
if matches!(err, RecvTimeoutError::Timeout) {
if self.client_sender.as_ref().unwrap().connected.get() {
continue
continue;
} else {
eprintln!("shutting down");
break None
break None;
}
} else {
eprintln!("client recv disconnected");
break None
break None;
}
}
}
} else {
eprintln!("no client receive endpoint");
break None
break None;
}
});
result.map(|result| PyBytes::new(py, &result).into())
Expand Down
5 changes: 4 additions & 1 deletion console_backend/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ pub struct ClientSender {
}
impl ClientSender {
pub fn new(inner: sync::mpsc::Sender<Vec<u8>>) -> Self {
Self { inner, connected: ArcBool::new_with(true) }
Self {
inner,
connected: ArcBool::new_with(true),
}
}
}
impl CapnProtoSender for ClientSender {
Expand Down
4 changes: 1 addition & 3 deletions console_backend/tests/mem_benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ mod mem_bench_impl {
.send(client_recv)
.expect("sending client recv handle should succeed");

let client_send = ClientSender {
inner: client_send_,
};
let client_send = ClientSender::new(client_send_);
let shared_state = SharedState::new();
shared_state.set_running(true, client_send.clone());
let conn = Connection::file(
Expand Down
2 changes: 1 addition & 1 deletion src/main/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,4 +604,4 @@ def handle_cli_arguments(args: argparse.Namespace, globals_: QObject):
endpoint_main.shutdown()
server_thread.join()

sys.exit()
sys.exit()