fix: invalid assignment of client_id (#1052)
* feat: sync socket connection in * chore: apply clippy * chore: change message name
This commit is contained in:
parent
39eddd8b1c
commit
a489194b55
6 changed files with 26 additions and 4 deletions
|
|
@ -6,7 +6,7 @@ use zellij_utils::{
|
|||
consts::ZELLIJ_SOCK_DIR,
|
||||
envs,
|
||||
interprocess::local_socket::LocalSocketStream,
|
||||
ipc::{ClientToServerMsg, IpcSenderWithContext},
|
||||
ipc::{ClientToServerMsg, IpcReceiverWithContext, IpcSenderWithContext, ServerToClientMsg},
|
||||
};
|
||||
|
||||
pub(crate) fn get_sessions() -> Result<Vec<String>, io::ErrorKind> {
|
||||
|
|
@ -56,14 +56,18 @@ fn assert_socket(name: &str) -> bool {
|
|||
let path = &*ZELLIJ_SOCK_DIR.join(name);
|
||||
match LocalSocketStream::connect(path) {
|
||||
Ok(stream) => {
|
||||
IpcSenderWithContext::new(stream).send(ClientToServerMsg::ClientExited);
|
||||
true
|
||||
let mut sender = IpcSenderWithContext::new(stream);
|
||||
sender.send(ClientToServerMsg::ConnStatus);
|
||||
|
||||
let mut receiver: IpcReceiverWithContext<ServerToClientMsg> = sender.get_receiver();
|
||||
let (instruction, _) = receiver.recv();
|
||||
matches!(instruction, ServerToClientMsg::Connected)
|
||||
}
|
||||
Err(e) if e.kind() == io::ErrorKind::ConnectionRefused => {
|
||||
drop(fs::remove_file(path));
|
||||
false
|
||||
}
|
||||
Err(_) => true,
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ pub(crate) enum ClientInstruction {
|
|||
UnblockInputThread,
|
||||
Exit(ExitReason),
|
||||
SwitchToMode(InputMode),
|
||||
Connected,
|
||||
}
|
||||
|
||||
impl From<ServerToClientMsg> for ClientInstruction {
|
||||
|
|
@ -46,6 +47,7 @@ impl From<ServerToClientMsg> for ClientInstruction {
|
|||
ServerToClientMsg::SwitchToMode(input_mode) => {
|
||||
ClientInstruction::SwitchToMode(input_mode)
|
||||
}
|
||||
ServerToClientMsg::Connected => ClientInstruction::Connected,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -58,6 +60,7 @@ impl From<&ClientInstruction> for ClientContext {
|
|||
ClientInstruction::Render(_) => ClientContext::Render,
|
||||
ClientInstruction::UnblockInputThread => ClientContext::UnblockInputThread,
|
||||
ClientInstruction::SwitchToMode(_) => ClientContext::SwitchToMode,
|
||||
ClientInstruction::Connected => ClientContext::Connected,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -323,6 +326,7 @@ pub fn start_client(
|
|||
.send(InputInstruction::SwitchToMode(input_mode))
|
||||
.unwrap();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ pub enum ServerInstruction {
|
|||
KillSession,
|
||||
DetachSession(ClientId),
|
||||
AttachClient(ClientAttributes, Options, ClientId),
|
||||
ConnStatus(ClientId),
|
||||
}
|
||||
|
||||
impl From<&ServerInstruction> for ServerContext {
|
||||
|
|
@ -85,6 +86,7 @@ impl From<&ServerInstruction> for ServerContext {
|
|||
ServerInstruction::KillSession => ServerContext::KillSession,
|
||||
ServerInstruction::DetachSession(..) => ServerContext::DetachSession,
|
||||
ServerInstruction::AttachClient(..) => ServerContext::AttachClient,
|
||||
ServerInstruction::ConnStatus(..) => ServerContext::ConnStatus,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -523,6 +525,10 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
|
|||
}
|
||||
break;
|
||||
}
|
||||
ServerInstruction::ConnStatus(client_id) => {
|
||||
os_input.send_to_client(client_id, ServerToClientMsg::Connected);
|
||||
remove_client!(client_id, os_input, session_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -461,6 +461,10 @@ pub(crate) fn route_thread_main(
|
|||
ClientToServerMsg::KillSession => {
|
||||
to_server.send(ServerInstruction::KillSession).unwrap();
|
||||
}
|
||||
ClientToServerMsg::ConnStatus => {
|
||||
let _ = to_server.send(ServerInstruction::ConnStatus(client_id));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -311,6 +311,7 @@ pub enum ClientContext {
|
|||
Render,
|
||||
ServerError,
|
||||
SwitchToMode,
|
||||
Connected,
|
||||
}
|
||||
|
||||
/// Stack call representations corresponding to the different types of [`ServerInstruction`]s.
|
||||
|
|
@ -325,4 +326,5 @@ pub enum ServerContext {
|
|||
KillSession,
|
||||
DetachSession,
|
||||
AttachClient,
|
||||
ConnStatus,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ pub enum ClientToServerMsg {
|
|||
Action(Action),
|
||||
ClientExited,
|
||||
KillSession,
|
||||
ConnStatus,
|
||||
}
|
||||
|
||||
// Types of messages sent from the server to the client
|
||||
|
|
@ -82,6 +83,7 @@ pub enum ServerToClientMsg {
|
|||
UnblockInputThread,
|
||||
Exit(ExitReason),
|
||||
SwitchToMode(InputMode),
|
||||
Connected,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue