distant_net/server/
ref.rs

1use std::future::Future;
2use std::pin::Pin;
3use std::task::{Context, Poll};
4
5use tokio::sync::broadcast;
6use tokio::task::{JoinError, JoinHandle};
7
8/// Represents a reference to a server
9pub struct ServerRef {
10    pub(crate) shutdown: broadcast::Sender<()>,
11    pub(crate) task: JoinHandle<()>,
12}
13
14impl ServerRef {
15    pub fn is_finished(&self) -> bool {
16        self.task.is_finished()
17    }
18
19    pub fn shutdown(&self) {
20        let _ = self.shutdown.send(());
21    }
22}
23
24impl Future for ServerRef {
25    type Output = Result<(), JoinError>;
26
27    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
28        Pin::new(&mut self.task).poll(cx)
29    }
30}
31
32mod tcp;
33pub use tcp::*;
34
35#[cfg(unix)]
36mod unix;
37
38#[cfg(unix)]
39pub use unix::*;
40
41#[cfg(windows)]
42mod windows;
43
44#[cfg(windows)]
45pub use windows::*;