aboutsummaryrefslogtreecommitdiff
path: root/net/src/stream/websocket.rs
diff options
context:
space:
mode:
Diffstat (limited to 'net/src/stream/websocket.rs')
-rw-r--r--net/src/stream/websocket.rs11
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),
}
}