diff options
author | hozan23 <hozan23@karyontech.net> | 2024-05-19 23:41:31 +0200 |
---|---|---|
committer | hozan23 <hozan23@karyontech.net> | 2024-05-19 23:41:31 +0200 |
commit | f6f44784fff5488bb59d563ee7ff7b94c08a48c1 (patch) | |
tree | 63fa6fa0d620748a92d819f4773773ea9d53afc5 /net/src/stream/websocket.rs | |
parent | a6016c7eeb11fc8aeaa1a3b160b970b15362695d (diff) |
use cargo features to enable/disable protocols for net crate
Diffstat (limited to 'net/src/stream/websocket.rs')
-rw-r--r-- | net/src/stream/websocket.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/net/src/stream/websocket.rs b/net/src/stream/websocket.rs index 2552eaf..9d41626 100644 --- a/net/src/stream/websocket.rs +++ b/net/src/stream/websocket.rs @@ -6,9 +6,9 @@ use std::{ use async_tungstenite::tungstenite::Message; use futures_util::{Sink, SinkExt, Stream, StreamExt}; -#[cfg(feature = "smol")] +#[cfg(all(feature = "smol", feature = "tls"))] use futures_rustls::TlsStream; -#[cfg(feature = "tokio")] +#[cfg(all(feature = "tokio", feature = "tls"))] use tokio_rustls::TlsStream; use karyon_core::async_runtime::net::TcpStream; @@ -37,6 +37,7 @@ where } } + #[cfg(feature = "tls")] pub fn new_wss(conn: WebSocketStream<TlsStream<TcpStream>>, codec: C) -> Self { Self { inner: InnerWSConn::Tls(conn), @@ -59,6 +60,7 @@ where enum InnerWSConn { Plain(WebSocketStream<TcpStream>), + #[cfg(feature = "tls")] Tls(WebSocketStream<TlsStream<TcpStream>>), } @@ -68,6 +70,7 @@ impl Sink<Message> for InnerWSConn { fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> { match &mut *self { InnerWSConn::Plain(s) => Pin::new(s).poll_ready(cx).map_err(Error::from), + #[cfg(feature = "tls")] InnerWSConn::Tls(s) => Pin::new(s).poll_ready(cx).map_err(Error::from), } } @@ -75,6 +78,7 @@ impl Sink<Message> for InnerWSConn { fn start_send(mut self: Pin<&mut Self>, item: Message) -> Result<()> { match &mut *self { InnerWSConn::Plain(s) => Pin::new(s).start_send(item).map_err(Error::from), + #[cfg(feature = "tls")] InnerWSConn::Tls(s) => Pin::new(s).start_send(item).map_err(Error::from), } } @@ -82,6 +86,7 @@ impl Sink<Message> for InnerWSConn { fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> { match &mut *self { InnerWSConn::Plain(s) => Pin::new(s).poll_flush(cx).map_err(Error::from), + #[cfg(feature = "tls")] InnerWSConn::Tls(s) => Pin::new(s).poll_flush(cx).map_err(Error::from), } } @@ -89,6 +94,7 @@ impl Sink<Message> for InnerWSConn { fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> { match &mut *self { InnerWSConn::Plain(s) => Pin::new(s).poll_close(cx).map_err(Error::from), + #[cfg(feature = "tls")] InnerWSConn::Tls(s) => Pin::new(s).poll_close(cx).map_err(Error::from), } .map_err(Error::from) @@ -101,6 +107,7 @@ impl Stream for InnerWSConn { fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { match &mut *self { InnerWSConn::Plain(s) => Pin::new(s).poll_next(cx).map_err(Error::from), + #[cfg(feature = "tls")] InnerWSConn::Tls(s) => Pin::new(s).poll_next(cx).map_err(Error::from), } } |