summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKunal Mohan <kunalmohan99@gmail.com>2021-02-13 15:50:56 +0530
committerKunal Mohan <kunalmohan99@gmail.com>2021-04-14 01:41:27 +0530
commitac6af3000e31068cc5023d98b7594404bb444508 (patch)
tree46b7396201e68a742156c3d510d1ad0d0b8080a9
parentb9b08d071df735789a76ff804368daf4069679bc (diff)
Use interprocess crate, BufReader and BufWriter
-rw-r--r--src/common/mod.rs35
-rw-r--r--src/server/mod.rs15
2 files changed, 29 insertions, 21 deletions
diff --git a/src/common/mod.rs b/src/common/mod.rs
index ce5f0214b..bec861680 100644
--- a/src/common/mod.rs
+++ b/src/common/mod.rs
@@ -9,18 +9,21 @@ pub mod screen;
pub mod utils;
pub mod wasm_vm;
-use std::io::Write;
-use std::os::unix::net::UnixStream;
+use std::io::{BufWriter, Write};
use std::path::{Path, PathBuf};
use std::sync::mpsc;
use std::thread;
use std::{collections::HashMap, fs};
-use std::{
- collections::HashSet,
- io::Write,
- str::FromStr,
- sync::{Arc, Mutex},
-};
+
+use crate::panes::PaneId;
+use directories_next::ProjectDirs;
+use input::handler::InputMode;
+use interprocess::local_socket::LocalSocketStream;
+use serde::{Deserialize, Serialize};
+use termion::input::TermRead;
+use wasm_vm::PluginEnv;
+use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value};
+use wasmer_wasi::{Pipe, WasiState};
use crate::cli::CliArgs;
use crate::layout::Layout;
@@ -124,14 +127,14 @@ thread_local!(
);
pub struct IpcSenderWithContext {
err_ctx: ErrorContext,
- sender: UnixStream,
+ sender: BufWriter<LocalSocketStream>,
}
impl IpcSenderWithContext {
pub fn new() -> Self {
Self {
err_ctx: ErrorContext::new(),
- sender: UnixStream::connect(ZELLIJ_IPC_PIPE).unwrap(),
+ sender: BufWriter::new(LocalSocketStream::connect(ZELLIJ_IPC_PIPE).unwrap()),
}
}
@@ -142,7 +145,9 @@ impl IpcSenderWithContext {
pub fn send(&mut self, msg: ApiCommand) -> std::io::Result<()> {
eprintln!("IpcSender sent {:?}", msg);
let command = bincode::serialize(&(self.err_ctx, msg)).unwrap();
- self.sender.write_all(&command)
+ let x = self.sender.write_all(&command);
+ self.sender.flush();
+ x
}
}
@@ -150,7 +155,7 @@ impl std::clone::Clone for IpcSenderWithContext {
fn clone(&self) -> Self {
Self {
err_ctx: self.err_ctx,
- sender: UnixStream::connect(ZELLIJ_IPC_PIPE).unwrap(),
+ sender: BufWriter::new(LocalSocketStream::connect(ZELLIJ_IPC_PIPE).unwrap()),
}
}
}
@@ -544,8 +549,8 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
break;
}
AppInstruction::Error(backtrace) => {
- //let _ = send_server_instructions.send(ApiCommand::Quit);
- //let _ = ipc_thread.join();
+ let _ = send_server_instructions.send(ApiCommand::Quit);
+ let _ = ipc_thread.join();
//IpcSenderWithContext::new().send(ApiCommand::Quit);
let _ = send_screen_instructions.send(ScreenInstruction::Quit);
let _ = screen_thread.join();
@@ -574,7 +579,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
}
let _ = send_server_instructions.send(ApiCommand::Quit);
- //let _ = ipc_thread.join().unwrap();
+ let _ = ipc_thread.join().unwrap();
//IpcSenderWithContext::new().send(ApiCommand::Quit);
let _ = send_screen_instructions.send(ScreenInstruction::Quit);
screen_thread.join().unwrap();
diff --git a/src/server/mod.rs b/src/server/mod.rs
index aa8aad8d4..eb87753c1 100644
--- a/src/server/mod.rs
+++ b/src/server/mod.rs
@@ -12,7 +12,8 @@ use crate::pty_bus::{PtyBus, PtyInstruction};
use crate::screen::ScreenInstruction;
use crate::utils::consts::ZELLIJ_IPC_PIPE;
use crate::wasm_vm::PluginInstruction;
-use std::io::Read;
+use interprocess::local_socket::{LocalSocketListener, LocalSocketStream};
+use std::io::{BufReader, Read};
use std::path::PathBuf;
use std::sync::mpsc::channel;
use std::thread;
@@ -31,8 +32,8 @@ pub fn start_server(
);
std::fs::remove_file(ZELLIJ_IPC_PIPE).ok();
- let listener = std::os::unix::net::UnixListener::bind(ZELLIJ_IPC_PIPE)
- .expect("could not listen on ipc socket");
+ let listener =
+ LocalSocketListener::bind(ZELLIJ_IPC_PIPE).expect("could not listen on ipc socket");
// Don't use default layouts in tests, but do everywhere else
#[cfg(not(test))]
@@ -146,18 +147,20 @@ pub fn start_server(
}
}
- let _ = pty_thread.join();
+ //let _ = pty_thread.join();
}
})
- .unwrap()
+ .unwrap();
+ pty_thread
}
fn handle_stream(
mut send_pty_instructions: SenderWithContext<PtyInstruction>,
mut send_app_instructions: SenderWithContext<AppInstruction>,
- mut stream: std::os::unix::net::UnixStream,
+ mut stream: LocalSocketStream,
km: u32,
) {
+ //let mut reader = BufReader::new(stream);
let mut buffer = [0; 65535]; // TODO: more accurate
loop {
let bytes = stream