Skip to content

Commit

Permalink
optim: Create frames_receiver on the receiving end
Browse files Browse the repository at this point in the history
Workaround for a panic on Windows:
servo/ipc-channel#277
  • Loading branch information
YaLTeR committed May 31, 2022
1 parent 530b3b9 commit 8a74753
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/modules/tas_editor/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,30 @@ fn server_thread(listener: TcpListener) {
}
drop(stream);

let (_, (sender, receiver)) = match server.accept() {
let (_, (hltas_sender, workaround_sender)): (_, (_, IpcSender<_>)) = match server.accept() {
Ok(x) => x,
Err(err) => {
error!("Error accepting remote client IPC connection: {err:?}");
continue;
}
};

let (frames_sender, frames_receiver) = match ipc_channel::ipc::channel() {
Ok(x) => x,
Err(err) => {
error!("Error creating a frames IPC channel: {err:?}");
return;
}
};

if let Err(err) = workaround_sender.send(frames_sender) {
error!("Error sending the frames sender to the remote client: {err:?}");
return;
};

REMOTE_GAMES.lock().push(RemoteGame {
sender,
receiver,
sender: hltas_sender,
receiver: frames_receiver,
state: RemoteGameState::Free,
});
}
Expand Down Expand Up @@ -237,19 +250,31 @@ pub fn try_connecting_to_server(marker: MainThreadMarker) {
}
};

let (frames_sender, frames_receiver) = match ipc_channel::ipc::channel() {
// Workaround for a Windows ipc-channel panic: the receiver for large payloads should be created
// in the process that will be using it.
//
// https://github.com/servo/ipc-channel/issues/277
let (workaround_sender, workaround_receiver) = match ipc_channel::ipc::channel() {
Ok(x) => x,
Err(err) => {
error!("Error creating a frames IPC channel: {err:?}");
error!("Error creating a workaround IPC channel: {err:?}");
return;
}
};

if let Err(err) = tx.send((hltas_sender, frames_receiver)) {
if let Err(err) = tx.send((hltas_sender, workaround_sender)) {
error!("Error sending the IPC channels to the remote server: {err:?}");
return;
}

let frames_sender = match workaround_receiver.recv() {
Ok(x) => x,
Err(err) => {
error!("Error receiving the frames sender from the remote server: {err:?}");
return;
}
};

info!("Connected to a remote server.");

*REMOTE_SERVER.borrow_mut(marker) = Some(RemoteServer {
Expand Down

0 comments on commit 8a74753

Please sign in to comment.