-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better daemonize + pidfile + rust client
- Loading branch information
1 parent
3c1870c
commit e6a3151
Showing
6 changed files
with
156 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "jsif" | ||
version = "0.1.0" | ||
edition = "2021" | ||
description = "just solve it fast - rust client for the jsi daemon" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::env; | ||
use std::io::{Read, Write}; | ||
use std::os::unix::net::UnixStream; | ||
use std::path::PathBuf; | ||
use std::process; | ||
use std::time::Instant; | ||
|
||
fn get_server_home() -> Option<PathBuf> { | ||
env::var_os("HOME").map(|home| { | ||
let mut path = PathBuf::from(home); | ||
path.push(".jsi"); | ||
path.push("daemon"); | ||
path | ||
}) | ||
} | ||
|
||
fn send_command(command: &str) -> Result<(), Box<dyn std::error::Error>> { | ||
let socket_path = get_server_home().unwrap().join("server.sock"); | ||
let mut stream = UnixStream::connect(socket_path)?; | ||
|
||
// Send the command | ||
stream.write_all(command.as_bytes())?; | ||
stream.flush()?; | ||
|
||
// Read the response | ||
let start = Instant::now(); | ||
let mut response = String::new(); | ||
stream.read_to_string(&mut response)?; | ||
|
||
println!("{}", response); | ||
println!("; response time: {:?}", start.elapsed()); | ||
Ok(()) | ||
} | ||
|
||
fn main() { | ||
let args: Vec<String> = env::args().collect(); | ||
|
||
if args.len() < 2 { | ||
eprintln!("Usage: {} <command>", args[0]); | ||
process::exit(1); | ||
} | ||
|
||
let command = args[1..].join(" "); | ||
|
||
match send_command(&command) { | ||
Ok(_) => (), | ||
Err(e) => eprintln!("Error: {}", e), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters