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,
|
consts::ZELLIJ_SOCK_DIR,
|
||||||
envs,
|
envs,
|
||||||
interprocess::local_socket::LocalSocketStream,
|
interprocess::local_socket::LocalSocketStream,
|
||||||
ipc::{ClientToServerMsg, IpcSenderWithContext},
|
ipc::{ClientToServerMsg, IpcReceiverWithContext, IpcSenderWithContext, ServerToClientMsg},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) fn get_sessions() -> Result<Vec<String>, io::ErrorKind> {
|
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);
|
let path = &*ZELLIJ_SOCK_DIR.join(name);
|
||||||
match LocalSocketStream::connect(path) {
|
match LocalSocketStream::connect(path) {
|
||||||
Ok(stream) => {
|
Ok(stream) => {
|
||||||
IpcSenderWithContext::new(stream).send(ClientToServerMsg::ClientExited);
|
let mut sender = IpcSenderWithContext::new(stream);
|
||||||
true
|
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 => {
|
Err(e) if e.kind() == io::ErrorKind::ConnectionRefused => {
|
||||||
drop(fs::remove_file(path));
|
drop(fs::remove_file(path));
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
Err(_) => true,
|
Err(_) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ pub(crate) enum ClientInstruction {
|
||||||
UnblockInputThread,
|
UnblockInputThread,
|
||||||
Exit(ExitReason),
|
Exit(ExitReason),
|
||||||
SwitchToMode(InputMode),
|
SwitchToMode(InputMode),
|
||||||
|
Connected,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ServerToClientMsg> for ClientInstruction {
|
impl From<ServerToClientMsg> for ClientInstruction {
|
||||||
|
|
@ -46,6 +47,7 @@ impl From<ServerToClientMsg> for ClientInstruction {
|
||||||
ServerToClientMsg::SwitchToMode(input_mode) => {
|
ServerToClientMsg::SwitchToMode(input_mode) => {
|
||||||
ClientInstruction::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::Render(_) => ClientContext::Render,
|
||||||
ClientInstruction::UnblockInputThread => ClientContext::UnblockInputThread,
|
ClientInstruction::UnblockInputThread => ClientContext::UnblockInputThread,
|
||||||
ClientInstruction::SwitchToMode(_) => ClientContext::SwitchToMode,
|
ClientInstruction::SwitchToMode(_) => ClientContext::SwitchToMode,
|
||||||
|
ClientInstruction::Connected => ClientContext::Connected,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -323,6 +326,7 @@ pub fn start_client(
|
||||||
.send(InputInstruction::SwitchToMode(input_mode))
|
.send(InputInstruction::SwitchToMode(input_mode))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ pub enum ServerInstruction {
|
||||||
KillSession,
|
KillSession,
|
||||||
DetachSession(ClientId),
|
DetachSession(ClientId),
|
||||||
AttachClient(ClientAttributes, Options, ClientId),
|
AttachClient(ClientAttributes, Options, ClientId),
|
||||||
|
ConnStatus(ClientId),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&ServerInstruction> for ServerContext {
|
impl From<&ServerInstruction> for ServerContext {
|
||||||
|
|
@ -85,6 +86,7 @@ impl From<&ServerInstruction> for ServerContext {
|
||||||
ServerInstruction::KillSession => ServerContext::KillSession,
|
ServerInstruction::KillSession => ServerContext::KillSession,
|
||||||
ServerInstruction::DetachSession(..) => ServerContext::DetachSession,
|
ServerInstruction::DetachSession(..) => ServerContext::DetachSession,
|
||||||
ServerInstruction::AttachClient(..) => ServerContext::AttachClient,
|
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;
|
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 => {
|
ClientToServerMsg::KillSession => {
|
||||||
to_server.send(ServerInstruction::KillSession).unwrap();
|
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,
|
Render,
|
||||||
ServerError,
|
ServerError,
|
||||||
SwitchToMode,
|
SwitchToMode,
|
||||||
|
Connected,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stack call representations corresponding to the different types of [`ServerInstruction`]s.
|
/// Stack call representations corresponding to the different types of [`ServerInstruction`]s.
|
||||||
|
|
@ -325,4 +326,5 @@ pub enum ServerContext {
|
||||||
KillSession,
|
KillSession,
|
||||||
DetachSession,
|
DetachSession,
|
||||||
AttachClient,
|
AttachClient,
|
||||||
|
ConnStatus,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ pub enum ClientToServerMsg {
|
||||||
Action(Action),
|
Action(Action),
|
||||||
ClientExited,
|
ClientExited,
|
||||||
KillSession,
|
KillSession,
|
||||||
|
ConnStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Types of messages sent from the server to the client
|
// Types of messages sent from the server to the client
|
||||||
|
|
@ -82,6 +83,7 @@ pub enum ServerToClientMsg {
|
||||||
UnblockInputThread,
|
UnblockInputThread,
|
||||||
Exit(ExitReason),
|
Exit(ExitReason),
|
||||||
SwitchToMode(InputMode),
|
SwitchToMode(InputMode),
|
||||||
|
Connected,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue