chore: disable unix_socket example on windows (#146)
This commit is contained in:
parent
18346b94e4
commit
6c2c02454d
1 changed files with 62 additions and 57 deletions
|
|
@ -1,35 +1,15 @@
|
||||||
|
mod common;
|
||||||
|
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> anyhow::Result<()> {
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
use common::calculator::Calculator;
|
use common::calculator::Calculator;
|
||||||
use rmcp::{serve_client, serve_server};
|
use rmcp::{serve_client, serve_server};
|
||||||
use tokio::net::{UnixListener, UnixStream};
|
use tokio::net::{UnixListener, UnixStream};
|
||||||
|
|
||||||
mod common;
|
|
||||||
|
|
||||||
const SOCKET_PATH: &str = "/tmp/rmcp_example.sock";
|
const SOCKET_PATH: &str = "/tmp/rmcp_example.sock";
|
||||||
|
|
||||||
#[tokio::main]
|
|
||||||
async fn main() -> anyhow::Result<()> {
|
|
||||||
// Remove any existing socket file
|
|
||||||
let _ = fs::remove_file(SOCKET_PATH);
|
|
||||||
match UnixListener::bind(SOCKET_PATH) {
|
|
||||||
Ok(unix_listener) => {
|
|
||||||
println!("Server successfully listening on {}", SOCKET_PATH);
|
|
||||||
tokio::spawn(server(unix_listener));
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
println!("Unable to bind to {}: {}", SOCKET_PATH, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
client().await?;
|
|
||||||
|
|
||||||
// Clean up socket file
|
|
||||||
let _ = fs::remove_file(SOCKET_PATH);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn server(unix_listener: UnixListener) -> anyhow::Result<()> {
|
async fn server(unix_listener: UnixListener) -> anyhow::Result<()> {
|
||||||
while let Ok((stream, addr)) = unix_listener.accept().await {
|
while let Ok((stream, addr)) = unix_listener.accept().await {
|
||||||
println!("Client connected: {:?}", addr);
|
println!("Client connected: {:?}", addr);
|
||||||
|
|
@ -80,3 +60,28 @@ async fn client() -> anyhow::Result<()> {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove any existing socket file
|
||||||
|
let _ = fs::remove_file(SOCKET_PATH);
|
||||||
|
match UnixListener::bind(SOCKET_PATH) {
|
||||||
|
Ok(unix_listener) => {
|
||||||
|
println!("Server successfully listening on {}", SOCKET_PATH);
|
||||||
|
tokio::spawn(server(unix_listener));
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("Unable to bind to {}: {}", SOCKET_PATH, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
client().await?;
|
||||||
|
|
||||||
|
// Clean up socket file
|
||||||
|
let _ = fs::remove_file(SOCKET_PATH);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "unix"))]
|
||||||
|
fn main() {
|
||||||
|
println!("Unix socket example is not supported on this platform.");
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue