diff --git a/src/common/mod.rs b/src/common/mod.rs index ec1f0959..9a7e40e4 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -164,7 +164,7 @@ impl IpcSenderWithContext { } pub fn send(&mut self, msg: T) -> ipmpsc::Result<()> { - self.sender.send(&(self.err_ctx, msg)) + self.sender.send(&(msg, self.err_ctx)) } } @@ -573,7 +573,7 @@ pub fn start( .spawn({ let recv_client_instructions = IpcReceiver::new(client_buffer); move || loop { - let (err_ctx, instruction): (ErrorContext, ClientInstruction) = + let (instruction, err_ctx): (ClientInstruction, ErrorContext) = recv_client_instructions.recv().unwrap(); send_app_instructions.update(err_ctx); match instruction { diff --git a/src/common/os_input_output.rs b/src/common/os_input_output.rs index 90bd0e49..b97834b5 100644 --- a/src/common/os_input_output.rs +++ b/src/common/os_input_output.rs @@ -180,7 +180,10 @@ pub trait ServerOsApi: Send + Sync { fn kill(&mut self, pid: RawFd) -> Result<(), nix::Error>; /// Returns a [`Box`] pointer to this [`OsApi`] struct. fn box_clone(&self) -> Box; + /// Returns the receiver of ServerInstructions. + // Should be called by server once only. fn get_server_receiver(&self) -> IpcReceiver; + /// Returns a sender to the Server. fn get_server_sender(&self) -> IpcSenderWithContext; } @@ -264,6 +267,7 @@ pub trait ClientOsApi: Send + Sync { fn read_from_stdin(&self) -> Vec; /// Returns a [`Box`] pointer to this [`OsApi`] struct. fn box_clone(&self) -> Box; + /// Returns a sender to the Server. fn get_server_sender(&self) -> IpcResult; } diff --git a/src/server/mod.rs b/src/server/mod.rs index 3c6918ea..b902ea27 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -147,7 +147,7 @@ pub fn start_server(os_input: Box, opts: CliArgs) -> thread::Jo // For now, We make sure that the first message is `NewClient` so there are no out of bound panics. let mut send_client_instructions: Vec = Vec::with_capacity(1); move || loop { - let (mut err_ctx, instruction): (ErrorContext, ServerInstruction) = + let (instruction, mut err_ctx): (ServerInstruction, ErrorContext) = recv_server_instructions.recv().unwrap(); err_ctx.add_call(ContextType::IPCServer(ServerContext::from(&instruction))); send_pty_instructions.update(err_ctx);