summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJae-Heon Ji <32578710+jaeheonji@users.noreply.github.com>2022-02-23 23:50:49 +0900
committerGitHub <noreply@github.com>2022-02-23 23:50:49 +0900
commita489194b55817b68213618fa81718b7beae9eba0 (patch)
tree0cf7c6182028583e81b7cdcd69479274c4cbb819
parent39eddd8b1c31eb6932163841bda18a82044e4700 (diff)
fix: invalid assignment of `client_id` (#1052)
* feat: sync socket connection in * chore: apply clippy * chore: change message name
-rw-r--r--src/sessions.rs12
-rw-r--r--zellij-client/src/lib.rs4
-rw-r--r--zellij-server/src/lib.rs6
-rw-r--r--zellij-server/src/route.rs4
-rw-r--r--zellij-utils/src/errors.rs2
-rw-r--r--zellij-utils/src/ipc.rs2
6 files changed, 26 insertions, 4 deletions
diff --git a/src/sessions.rs b/src/sessions.rs
index 0cc870a7e..d05287e47 100644
--- a/src/sessions.rs
+++ b/src/sessions.rs
@@ -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,
}
}
diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs
index 9bc8828aa..0e4f0e207 100644
--- a/zellij-client/src/lib.rs
+++ b/zellij-client/src/lib.rs
@@ -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();
}
+ _ => {}
}
}
diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs
index 9ee0bbfee..82f759db4 100644
--- a/zellij-server/src/lib.rs
+++ b/zellij-server/src/lib.rs
@@ -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);
+ }
}
}
diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs
index fc14175a6..033a571b3 100644
--- a/zellij-server/src/route.rs
+++ b/zellij-server/src/route.rs
@@ -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;
+ }
}
}
}
diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs
index ea8033e50..7ac0df85c 100644
--- a/zellij-utils/src/errors.rs
+++ b/zellij-utils/src/errors.rs
@@ -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,
}
diff --git a/zellij-utils/src/ipc.rs b/zellij-utils/src/ipc.rs
index 2716dd3cc..231c5ecd4 100644
--- a/zellij-utils/src/ipc.rs
+++ b/zellij-utils/src/ipc.rs
@@ -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)]