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<()> { pub fn send(&mut self, msg: ApiCommand) -> std::io::Result<()> {
eprintln!("IpcSender sent {:?}", msg);
let command = bincode::serialize(&(self.err_ctx, msg)).unwrap(); let command = bincode::serialize(&(self.err_ctx, msg)).unwrap();
self.sender.write_all(&command) 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)); SenderWithContext::new(SenderType::Sender(send_plugin_instructions));
let (send_app_instructions, receive_app_instructions): SyncChannelWithContext<AppInstruction> = let (send_app_instructions, receive_app_instructions): SyncChannelWithContext<AppInstruction> =
mpsc::sync_channel(0); mpsc::sync_channel(500);
let send_app_instructions = let send_app_instructions =
SenderWithContext::new(SenderType::SyncSender(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; break;
} }
AppInstruction::Error(backtrace) => { AppInstruction::Error(backtrace) => {
let _ = send_server_instructions.send(ApiCommand::Quit); //let _ = send_server_instructions.send(ApiCommand::Quit);
//let _ = ipc_thread.join(); //let _ = ipc_thread.join();
//IpcSenderWithContext::new().send(ApiCommand::Quit); //IpcSenderWithContext::new().send(ApiCommand::Quit);
let _ = send_screen_instructions.send(ScreenInstruction::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); os_input.unset_raw_mode(0);
let goto_start_of_last_line = format!("\u{1b}[{};{}H", full_screen_ws.rows, 1); 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 error = format!("{}\n{}", goto_start_of_last_line, backtrace);
let _ = os_input //let _ = os_input
.get_stdout_writer() // .get_stdout_writer()
.write(error.as_bytes()) // .write(error.as_bytes())
.unwrap(); // .unwrap();
eprintln!("{}", error);
std::process::exit(1); std::process::exit(1);
} }
AppInstruction::ToScreen(instruction) => { 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()); let mut err_ctx = OPENCALLS.with(|ctx| *ctx.borrow());
task::spawn({ task::spawn({
async move { async move {
eprintln!("New task spawned");
err_ctx.add_call(ContextType::AsyncTask); err_ctx.add_call(ContextType::AsyncTask);
let mut send_server_instructions = IpcSenderWithContext::new(); let mut send_server_instructions = IpcSenderWithContext::new();
send_server_instructions.update(err_ctx); send_server_instructions.update(err_ctx);

View file

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