Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poll_* methods to support custom futures implementations #78

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5f1d0e5
frame: Use abstract trait to write the header to
dgrr May 27, 2024
9ea19e6
Implement poll* methods to support future-based systems
dgrr May 27, 2024
3c779ff
Merge branch 'main' of github.com:dgrr/fastwebsockets
dgrr May 27, 2024
7fc1617
poll methods for WebSocketStream
dgrr May 28, 2024
f1696f1
WebSocket: start_send_frame function
dgrr May 29, 2024
30c1586
Cargo.toml: futures version
dgrr May 29, 2024
909cd67
Cargo.toml: tokio_util version
dgrr May 29, 2024
78f81dd
Set the waker before flushing
dgrr May 29, 2024
23a7101
Implement poll_read_frame & poll_write_frame for WebSocketRead and We…
dgrr May 29, 2024
59904ad
Bring back unstable-split feature
dgrr Jun 23, 2024
8285b55
write_frame: Check readiness of the underlying connection by flushing…
dgrr Jun 24, 2024
3f050bf
Function docs
dgrr Jun 24, 2024
b7b7696
Fix return type when not using SIMD for utf8 processing
dgrr Jun 24, 2024
b1b087c
Generate state machine for reading
dgrr Jun 30, 2024
3636e5b
WriteHalf: Advance buffer on poll_ready
dgrr Jun 30, 2024
3a537e3
Simplify loop by conradludgate
dgrr Jun 30, 2024
da4f6d7
use vec
conradludgate Jul 1, 2024
9abbf6c
better buffer manipulation
conradludgate Jul 1, 2024
e91e922
re-introduce vectored writes
conradludgate Jul 1, 2024
5d45077
refactor
conradludgate Jul 1, 2024
1d579a1
Use a Vec<u8> instead of BytesMut for the write buffer
dgrr Jul 1, 2024
988cbd5
Merge branch 'main' into dgrr/main
dgrr Jul 1, 2024
53b2b96
Merge pull request #1 from conradludgate/dgrr/main
dgrr Jul 6, 2024
28c331a
Remove underscore from used variable names
dgrr Jul 6, 2024
7656018
Added test to check that simple and vectored serialization do not con…
dgrr Jul 6, 2024
b960f15
WebSocket: Handle obligated send flushing with states to ensure delivery
dgrr Jul 7, 2024
9eebea5
Merge branch 'denoland:main' into main
dgrr Sep 28, 2024
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
33 changes: 30 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ bytes = "1.5.0"
axum-core = { version = "0.4.3", optional = true }
http = { version = "1", optional = true }
async-trait = { version = "0.1", optional = true }
tokio-util = { version = "0.7", features = ["codec", "io"] }
futures = { version = "0.3", default-features = false, features = ["std"] }

[features]
default = ["simd"]
Expand Down
4 changes: 2 additions & 2 deletions src/fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'f, S> FragmentCollector<S> {
{
loop {
let (res, obligated_send) =
self.read_half.read_frame_inner(&mut self.stream).await;
self.read_half.read_frame(&mut self.stream).await;
let is_closed = self.write_half.closed;
if let Some(obligated_send) = obligated_send {
if !is_closed {
Expand Down Expand Up @@ -179,7 +179,7 @@ impl<'f, S> FragmentCollectorRead<S> {
{
loop {
let (res, obligated_send) =
self.read_half.read_frame_inner(&mut self.stream).await;
self.read_half.read_frame(&mut self.stream).await;
if let Some(frame) = obligated_send {
let res = send_fn(frame).await;
res.map_err(|e| WebSocketError::SendError(e.into()))?;
Expand Down
7 changes: 5 additions & 2 deletions src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub struct Frame<'f> {
pub payload: Payload<'f>,
}

const MAX_HEAD_SIZE: usize = 16;
pub(crate) const MAX_HEAD_SIZE: usize = 16;

impl<'f> Frame<'f> {
/// Creates a new WebSocket `Frame`.
Expand Down Expand Up @@ -321,6 +321,9 @@ impl<'f> Frame<'f> {
}

/// Writes the frame to the buffer and returns a slice of the buffer containing the frame.
///
/// This function will NOT append the frame to the Vec, but rather replace the current bytes
/// with the frame's serialized bytes.
pub fn write<'a>(&mut self, buf: &'a mut Vec<u8>) -> &'a [u8] {
fn reserve_enough(buf: &mut Vec<u8>, len: usize) {
if buf.len() < len {
Expand All @@ -330,7 +333,7 @@ impl<'f> Frame<'f> {
let len = self.payload.len();
reserve_enough(buf, len + MAX_HEAD_SIZE);

let size = self.fmt_head(buf);
let size = self.fmt_head(&mut *buf);
buf[size..size + len].copy_from_slice(&self.payload);
&buf[..size + len]
}
Expand Down
Loading
Loading