Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/transport/websocket/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ use std::{

// TODO: add tests

const DEFAULT_BUF_SIZE: usize = 8 * 1024;

/// Send state.
enum State {
/// State is poisoned.
Expand Down Expand Up @@ -70,7 +72,7 @@ impl<S: AsyncRead + AsyncWrite + Unpin> BufferedStream<S> {
/// Create new [`BufferedStream`].
pub(super) fn new(stream: WebSocketStream<S>) -> Self {
Self {
write_buffer: Vec::with_capacity(2000),
write_buffer: Vec::with_capacity(DEFAULT_BUF_SIZE),
read_buffer: None,
write_ptr: 0usize,
stream,
Expand Down Expand Up @@ -124,10 +126,9 @@ impl<S: AsyncRead + AsyncWrite + Unpin> futures::AsyncWrite for BufferedStream<S
}
State::FlushPending => match futures::ready!(self.stream.poll_flush_unpin(cx)) {
Ok(_res) => {
// TODO: optimize
self.state = State::ReadyToSend;
self.write_ptr = 0;
self.write_buffer = Vec::with_capacity(2000);
self.write_buffer.clear();
return Poll::Ready(Ok(()));
}
Err(_) => return Poll::Ready(Err(std::io::ErrorKind::UnexpectedEof.into())),
Expand Down
Loading