Skip to content

Commit

Permalink
PER_DATAFRAME_OVERHEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
vi committed Jul 24, 2022
1 parent 604d010 commit 3bde0f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::ws::receiver::{DataFrameIterator, MessageIterator};
const DEFAULT_MAX_DATAFRAME_SIZE : usize = 1024*1024*100;
const DEFAULT_MAX_MESSAGE_SIZE : usize = 1024*1024*200;
const MAX_DATAFRAMES_IN_ONE_MESSAGE: usize = 1024*1024;
const PER_DATAFRAME_OVERHEAD : usize = 64; // not actually measured, just to prevent filling memory with empty buffers

/// This reader bundles an existing stream with a parsing algorithm.
/// It is used by the client in its `.split()` function as the reading component.
Expand Down Expand Up @@ -138,7 +139,7 @@ impl ws::Receiver for Receiver {
}

let finished = first.finished;
current_message_length += first.data.len();
current_message_length += first.data.len() + PER_DATAFRAME_OVERHEAD;
self.buffer.push(first);
finished
} else {
Expand All @@ -152,7 +153,7 @@ impl ws::Receiver for Receiver {
match next.opcode as u8 {
// Continuation opcode
0 => {
current_message_length += next.data.len();
current_message_length += next.data.len() + PER_DATAFRAME_OVERHEAD;
self.buffer.push(next)
}
// Control frame
Expand Down
3 changes: 2 additions & 1 deletion websocket-base/src/codec/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::ws::util::header::read_header;
const DEFAULT_MAX_DATAFRAME_SIZE : usize = 1024*1024*100;
const DEFAULT_MAX_MESSAGE_SIZE : usize = 1024*1024*200;
const MAX_DATAFRAMES_IN_ONE_MESSAGE: usize = 1024*1024;
const PER_DATAFRAME_OVERHEAD : usize = 64;

/// Even though a websocket connection may look perfectly symmetrical
/// in reality there are small differences between clients and servers.
Expand Down Expand Up @@ -299,7 +300,7 @@ where
}
// its good
_ => {
current_message_length += frame.data.len();
current_message_length += frame.data.len() + PER_DATAFRAME_OVERHEAD;
self.buffer.push(frame);
}
};
Expand Down

0 comments on commit 3bde0f4

Please sign in to comment.