Got things working! But we are loosing data in transmission :( PS: There are debug logs in there

This commit is contained in:
Kunal Mohan 2021-02-13 13:33:32 +05:30
parent d1a17ef356
commit 2943dc7b3b
3 changed files with 31 additions and 11 deletions

View file

@ -141,6 +141,7 @@ impl IpcSenderWithContext {
}
pub fn send(&mut self, msg: ApiCommand) -> std::io::Result<()> {
eprintln!("IpcSender sent {:?}", msg);
let command = bincode::serialize(&(self.err_ctx, msg)).unwrap();
self.sender.write_all(&command)
}
@ -200,7 +201,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) {
SenderWithContext::new(SenderType::Sender(send_plugin_instructions));
let (send_app_instructions, receive_app_instructions): SyncChannelWithContext<AppInstruction> =
mpsc::sync_channel(0);
mpsc::sync_channel(500);
let send_app_instructions =
SenderWithContext::new(SenderType::SyncSender(send_app_instructions));
@ -560,7 +561,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) {
break;
}
AppInstruction::Error(backtrace) => {
let _ = send_server_instructions.send(ApiCommand::Quit);
//let _ = send_server_instructions.send(ApiCommand::Quit);
//let _ = ipc_thread.join();
//IpcSenderWithContext::new().send(ApiCommand::Quit);
let _ = send_screen_instructions.send(ScreenInstruction::Quit);
@ -570,10 +571,11 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) {
os_input.unset_raw_mode(0);
let goto_start_of_last_line = format!("\u{1b}[{};{}H", full_screen_ws.rows, 1);
let error = format!("{}\n{}", goto_start_of_last_line, backtrace);
let _ = os_input
.get_stdout_writer()
.write(error.as_bytes())
.unwrap();
//let _ = os_input
// .get_stdout_writer()
// .write(error.as_bytes())
// .unwrap();
eprintln!("{}", error);
std::process::exit(1);
}
AppInstruction::ToScreen(instruction) => {

View file

@ -197,6 +197,7 @@ fn stream_terminal_bytes(pid: RawFd, os_input: Box<dyn OsApi>, debug: bool) -> J
let mut err_ctx = OPENCALLS.with(|ctx| *ctx.borrow());
task::spawn({
async move {
eprintln!("New task spawned");
err_ctx.add_call(ContextType::AsyncTask);
let mut send_server_instructions = IpcSenderWithContext::new();
send_server_instructions.update(err_ctx);

View file

@ -109,7 +109,7 @@ pub fn start_server(
command_is_executing.done_closing_pane();
}
PtyInstruction::Quit => {
break;
//break;
}
}
}
@ -120,14 +120,25 @@ pub fn start_server(
.name("ipc_server".to_string())
.spawn({
move || {
let mut km = 0;
for stream in listener.incoming() {
match stream {
Ok(stream) => {
let send_app_instructions = send_app_instructions.clone();
let send_pty_instructions = send_pty_instructions.clone();
thread::spawn(move || {
handle_stream(send_pty_instructions, send_app_instructions, stream);
});
let nm = format!("{}", km);
thread::Builder::new()
.name(nm)
.spawn(move || {
handle_stream(
send_pty_instructions,
send_app_instructions,
stream,
km,
);
})
.unwrap();
km += 1;
}
Err(err) => {
panic!("err {:?}", err);
@ -145,6 +156,7 @@ fn handle_stream(
mut send_pty_instructions: SenderWithContext<PtyInstruction>,
mut send_app_instructions: SenderWithContext<AppInstruction>,
mut stream: std::os::unix::net::UnixStream,
km: u32,
) {
let mut buffer = [0; 65535]; // TODO: more accurate
loop {
@ -152,11 +164,16 @@ fn handle_stream(
.read(&mut buffer)
.expect("failed to parse ipc message");
let (mut err_ctx, decoded): (ErrorContext, ApiCommand) =
bincode::deserialize(&buffer[..bytes]).expect("failed to deserialize ipc message");
match bincode::deserialize(&buffer[..bytes]) {
Ok(d) => d,
Err(e) => break,
};
err_ctx.add_call(ContextType::IPCServer);
send_pty_instructions.update(err_ctx);
send_app_instructions.update(err_ctx);
eprintln!("Server {} Received {:?}", km, decoded);
match decoded {
ApiCommand::OpenFile(file_name) => {
let path = PathBuf::from(file_name);