mirror of https://github.com/chipsenkbeil/distant
Refactor GenericServerRef to ServerRef
parent
569052d0cd
commit
3ac715eadd
@ -1,36 +1,58 @@
|
||||
use std::future::Future;
|
||||
use std::net::IpAddr;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use tokio::task::JoinError;
|
||||
|
||||
use super::ServerRef;
|
||||
|
||||
/// Reference to a TCP server instance
|
||||
/// Reference to a TCP server instance.
|
||||
pub struct TcpServerRef {
|
||||
pub(crate) addr: IpAddr,
|
||||
pub(crate) port: u16,
|
||||
pub(crate) inner: Box<dyn ServerRef>,
|
||||
pub(crate) inner: ServerRef,
|
||||
}
|
||||
|
||||
impl TcpServerRef {
|
||||
pub fn new(addr: IpAddr, port: u16, inner: Box<dyn ServerRef>) -> Self {
|
||||
pub fn new(addr: IpAddr, port: u16, inner: ServerRef) -> Self {
|
||||
Self { addr, port, inner }
|
||||
}
|
||||
|
||||
/// Returns the IP address that the listener is bound to
|
||||
/// Returns the IP address that the listener is bound to.
|
||||
pub fn ip_addr(&self) -> IpAddr {
|
||||
self.addr
|
||||
}
|
||||
|
||||
/// Returns the port that the listener is bound to
|
||||
/// Returns the port that the listener is bound to.
|
||||
pub fn port(&self) -> u16 {
|
||||
self.port
|
||||
}
|
||||
|
||||
/// Consumes ref, returning inner ref.
|
||||
pub fn into_inner(self) -> ServerRef {
|
||||
self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl Future for TcpServerRef {
|
||||
type Output = Result<(), JoinError>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
Pin::new(&mut self.inner.task).poll(cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl ServerRef for TcpServerRef {
|
||||
fn is_finished(&self) -> bool {
|
||||
self.inner.is_finished()
|
||||
impl Deref for TcpServerRef {
|
||||
type Target = ServerRef;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
fn shutdown(&self) {
|
||||
self.inner.shutdown();
|
||||
impl DerefMut for TcpServerRef {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.inner
|
||||
}
|
||||
}
|
||||
|
@ -1,35 +1,52 @@
|
||||
use std::future::Future;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use tokio::task::JoinError;
|
||||
|
||||
use super::ServerRef;
|
||||
|
||||
/// Reference to a unix socket server instance
|
||||
/// Reference to a unix socket server instance.
|
||||
pub struct UnixSocketServerRef {
|
||||
pub(crate) path: PathBuf,
|
||||
pub(crate) inner: Box<dyn ServerRef>,
|
||||
pub(crate) inner: ServerRef,
|
||||
}
|
||||
|
||||
impl UnixSocketServerRef {
|
||||
pub fn new(path: PathBuf, inner: Box<dyn ServerRef>) -> Self {
|
||||
pub fn new(path: PathBuf, inner: ServerRef) -> Self {
|
||||
Self { path, inner }
|
||||
}
|
||||
|
||||
/// Returns the path to the socket
|
||||
/// Returns the path to the socket.
|
||||
pub fn path(&self) -> &Path {
|
||||
&self.path
|
||||
}
|
||||
|
||||
/// Consumes ref, returning inner ref
|
||||
pub fn into_inner(self) -> Box<dyn ServerRef> {
|
||||
/// Consumes ref, returning inner ref.
|
||||
pub fn into_inner(self) -> ServerRef {
|
||||
self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl ServerRef for UnixSocketServerRef {
|
||||
fn is_finished(&self) -> bool {
|
||||
self.inner.is_finished()
|
||||
impl Future for UnixSocketServerRef {
|
||||
type Output = Result<(), JoinError>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
Pin::new(&mut self.inner.task).poll(cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for UnixSocketServerRef {
|
||||
type Target = ServerRef;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
fn shutdown(&self) {
|
||||
self.inner.shutdown();
|
||||
impl DerefMut for UnixSocketServerRef {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.inner
|
||||
}
|
||||
}
|
||||
|
@ -1,35 +1,52 @@
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::future::Future;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use tokio::task::JoinError;
|
||||
|
||||
use super::ServerRef;
|
||||
|
||||
/// Reference to a unix socket server instance
|
||||
/// Reference to a windows pipe server instance.
|
||||
pub struct WindowsPipeServerRef {
|
||||
pub(crate) addr: OsString,
|
||||
pub(crate) inner: Box<dyn ServerRef>,
|
||||
}
|
||||
|
||||
impl WindowsPipeServerRef {
|
||||
pub fn new(addr: OsString, inner: Box<dyn ServerRef>) -> Self {
|
||||
pub fn new(addr: OsString, inner: ServerRef) -> Self {
|
||||
Self { addr, inner }
|
||||
}
|
||||
|
||||
/// Returns the addr that the listener is bound to
|
||||
/// Returns the addr that the listener is bound to.
|
||||
pub fn addr(&self) -> &OsStr {
|
||||
&self.addr
|
||||
}
|
||||
|
||||
/// Consumes ref, returning inner ref
|
||||
pub fn into_inner(self) -> Box<dyn ServerRef> {
|
||||
/// Consumes ref, returning inner ref.
|
||||
pub fn into_inner(self) -> ServerRef {
|
||||
self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl ServerRef for WindowsPipeServerRef {
|
||||
fn is_finished(&self) -> bool {
|
||||
self.inner.is_finished()
|
||||
impl Future for WindowsPipeServerRef {
|
||||
type Output = Result<(), JoinError>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
Pin::new(&mut self.inner.task).poll(cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for WindowsPipeServerRef {
|
||||
type Target = ServerRef;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
fn shutdown(&self) {
|
||||
self.inner.shutdown();
|
||||
impl DerefMut for WindowsPipeServerRef {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.inner
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue