aboutsummaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
authorKunal Mohan <kunalmohan99@gmail.com>2021-03-18 22:37:25 +0530
committerKunal Mohan <kunalmohan99@gmail.com>2021-05-04 20:47:51 +0530
commit0d814ebcde98659babeaaa71a3ad5ee720021fc4 (patch)
tree28b136c7ebde8f00375712c3fcec38992e81a60e /src/server
parentwip: remove the commands that are called only on the client (diff)
downloadsl0ppij-0d814ebcde98659babeaaa71a3ad5ee720021fc4.tar.gz
sl0ppij-0d814ebcde98659babeaaa71a3ad5ee720021fc4.tar.xz
sl0ppij-0d814ebcde98659babeaaa71a3ad5ee720021fc4.zip
Divide OsApi into ClientOsApi and ServerOsApi and move calls to os thread
Diffstat (limited to 'src/server')
-rw-r--r--src/server/mod.rs23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/server/mod.rs b/src/server/mod.rs
index c1713918..00368904 100644
--- a/src/server/mod.rs
+++ b/src/server/mod.rs
@@ -4,7 +4,7 @@ use crate::common::{
ServerInstruction,
};
use crate::errors::{ContextType, ErrorContext, OsContext, PtyContext};
-use crate::os_input_output::{OsApi, OsApiInstruction};
+use crate::os_input_output::{get_server_os_input, ServerOsApi, ServerOsApiInstruction};
use crate::panes::PaneId;
use crate::pty_bus::{PtyBus, PtyInstruction};
use crate::screen::ScreenInstruction;
@@ -14,9 +14,10 @@ use std::path::PathBuf;
use std::sync::mpsc::channel;
use std::thread;
-pub fn start_server(os_input: Box<dyn OsApi>, opts: CliArgs) -> (thread::JoinHandle<()>, String) {
+pub fn start_server(opts: CliArgs) -> (thread::JoinHandle<()>, String) {
let (send_pty_instructions, receive_pty_instructions): ChannelWithContext<PtyInstruction> =
channel();
+ let os_input = Box::new(get_server_os_input());
let mut send_pty_instructions = SenderWithContext::new(
ErrorContext::new(),
SenderType::Sender(send_pty_instructions),
@@ -30,8 +31,9 @@ pub fn start_server(os_input: Box<dyn OsApi>, opts: CliArgs) -> (thread::JoinHan
#[cfg(test)]
let (server_name, server_buffer) = SharedRingBuffer::create_temp(8192).unwrap();
- let (send_os_instructions, receive_os_instructions): ChannelWithContext<OsApiInstruction> =
- channel();
+ let (send_os_instructions, receive_os_instructions): ChannelWithContext<
+ ServerOsApiInstruction,
+ > = channel();
let mut send_os_instructions = SenderWithContext::new(
ErrorContext::new(),
SenderType::Sender(send_os_instructions),
@@ -131,22 +133,23 @@ pub fn start_server(os_input: Box<dyn OsApi>, opts: CliArgs) -> (thread::JoinHan
.expect("failed to receive an event on the channel");
err_ctx.add_call(ContextType::Os(OsContext::from(&event)));
match event {
- OsApiInstruction::SetTerminalSizeUsingFd(fd, cols, rows) => {
+ ServerOsApiInstruction::SetTerminalSizeUsingFd(fd, cols, rows) => {
os_input.set_terminal_size_using_fd(fd, cols, rows);
}
- OsApiInstruction::WriteToTtyStdin(fd, mut buf) => {
+ ServerOsApiInstruction::WriteToTtyStdin(fd, mut buf) => {
let slice = buf.as_mut_slice();
os_input.write_to_tty_stdin(fd, slice).unwrap();
}
- OsApiInstruction::TcDrain(fd) => {
+ ServerOsApiInstruction::TcDrain(fd) => {
os_input.tcdrain(fd).unwrap();
}
+ ServerOsApiInstruction::Exit => break,
}
}
})
.unwrap();
- let join_handle = thread::Builder::new()
+ let server_handle = thread::Builder::new()
.name("ipc_server".to_string())
.spawn({
let recv_server_instructions = IpcReceiver::new(server_buffer);
@@ -158,6 +161,7 @@ pub fn start_server(os_input: Box<dyn OsApi>, opts: CliArgs) -> (thread::JoinHan
recv_server_instructions.recv().unwrap();
err_ctx.add_call(ContextType::IPCServer);
send_pty_instructions.update(err_ctx);
+ send_os_instructions.update(err_ctx);
if send_client_instructions.len() == 1 {
send_client_instructions[0].update(err_ctx);
}
@@ -213,6 +217,7 @@ pub fn start_server(os_input: Box<dyn OsApi>, opts: CliArgs) -> (thread::JoinHan
}
ServerInstruction::Exit => {
let _ = send_pty_instructions.send(PtyInstruction::Exit);
+ let _ = send_os_instructions.send(ServerOsApiInstruction::Exit);
let _ = pty_thread.join();
let _ = os_thread.join();
let _ = send_client_instructions[0].send(ClientInstruction::Exit);
@@ -222,5 +227,5 @@ pub fn start_server(os_input: Box<dyn OsApi>, opts: CliArgs) -> (thread::JoinHan
}
})
.unwrap();
- (join_handle, server_name)
+ (server_handle, server_name)
}