Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: invalid assignment of client_id #1052

Merged
merged 3 commits into from
Feb 23, 2022
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: 8 additions & 4 deletions src/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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,
}
}

Expand Down
4 changes: 4 additions & 0 deletions zellij-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub(crate) enum ClientInstruction {
UnblockInputThread,
Exit(ExitReason),
SwitchToMode(InputMode),
Connected,
}

impl From<ServerToClientMsg> for ClientInstruction {
Expand All @@ -46,6 +47,7 @@ impl From<ServerToClientMsg> for ClientInstruction {
ServerToClientMsg::SwitchToMode(input_mode) => {
ClientInstruction::SwitchToMode(input_mode)
}
ServerToClientMsg::Connected => ClientInstruction::Connected,
}
}
}
Expand All @@ -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,
}
}
}
Expand Down Expand Up @@ -323,6 +326,7 @@ pub fn start_client(
.send(InputInstruction::SwitchToMode(input_mode))
.unwrap();
}
_ => {}
}
}

Expand Down
6 changes: 6 additions & 0 deletions zellij-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub enum ServerInstruction {
KillSession,
DetachSession(ClientId),
AttachClient(ClientAttributes, Options, ClientId),
ConnStatus(ClientId),
}

impl From<&ServerInstruction> for ServerContext {
Expand All @@ -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,
}
}
}
Expand Down Expand Up @@ -525,6 +527,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);
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions zellij-server/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,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;
}
}
}
}
2 changes: 2 additions & 0 deletions zellij-utils/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ pub enum ClientContext {
Render,
ServerError,
SwitchToMode,
Connected,
}

/// Stack call representations corresponding to the different types of [`ServerInstruction`]s.
Expand All @@ -323,4 +324,5 @@ pub enum ServerContext {
KillSession,
DetachSession,
AttachClient,
ConnStatus,
}
2 changes: 2 additions & 0 deletions zellij-utils/src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub enum ClientToServerMsg {
Action(Action),
ClientExited,
KillSession,
ConnStatus,
}

// Types of messages sent from the server to the client
Expand All @@ -82,6 +83,7 @@ pub enum ServerToClientMsg {
UnblockInputThread,
Exit(ExitReason),
SwitchToMode(InputMode),
Connected,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down