Remove WebSocketStream::send()

The same functionality is already provided via StreamExt::send() and
unlike the custom implementation it handles WouldBlock correctly and not
as an error.
pull/3/head
Sebastian Dröge 5 years ago
parent 9bf555ed07
commit e86a2f4ae7
  1. 2
      examples/autobahn-client.rs
  2. 2
      examples/autobahn-server.rs
  3. 2
      examples/client.rs
  4. 2
      examples/server.rs
  5. 37
      src/lib.rs

@ -1,5 +1,5 @@
use async_tungstenite::{connect_async, tungstenite::Result};
use futures::StreamExt;
use futures::{SinkExt, StreamExt};
use log::*;
use url::Url;

@ -1,6 +1,6 @@
use async_std::net::{SocketAddr, TcpListener, TcpStream, ToSocketAddrs};
use async_tungstenite::accept_async;
use futures::StreamExt;
use futures::{SinkExt, StreamExt};
use log::*;
async fn accept_connection(peer: SocketAddr, stream: TcpStream) {

@ -12,7 +12,7 @@
use std::env;
use futures::StreamExt;
use futures::{SinkExt, StreamExt};
use log::*;
use tungstenite::protocol::Message;

@ -24,7 +24,7 @@ use async_std::net::{SocketAddr, ToSocketAddrs};
use async_std::net::{TcpListener, TcpStream};
use async_std::task;
use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender};
use futures::StreamExt;
use futures::{SinkExt, StreamExt};
use log::*;
use tungstenite::protocol::Message;

@ -243,18 +243,6 @@ impl<S> WebSocketStream<S> {
self.inner.get_mut().get_mut()
}
/// Send a message to this websocket
pub async fn send(&mut self, msg: Message) -> Result<(), WsError>
where
S: AsyncWrite + AsyncRead + Unpin,
{
let f = SendFuture {
stream: self,
message: Some(msg),
};
f.await
}
/// Close the underlying web socket
pub async fn close(&mut self, msg: Option<CloseFrame<'_>>) -> Result<(), WsError>
where
@ -336,31 +324,6 @@ where
}
}
#[pin_project]
struct SendFuture<'a, T> {
stream: &'a mut WebSocketStream<T>,
message: Option<Message>,
}
impl<'a, T> Future for SendFuture<'a, T>
where
T: AsyncRead + AsyncWrite + Unpin,
AllowStd<T>: Read + Write,
{
type Output = Result<(), WsError>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
let message = this.message.take().expect("Cannot poll twice");
Poll::Ready(
this.stream
.with_context(Some((ContextWaker::Write, cx)), |s| {
s.write_message(message)
}),
)
}
}
#[pin_project]
struct CloseFuture<'a, T> {
stream: &'a mut WebSocketStream<T>,

Loading…
Cancel
Save