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

feat(net): AsyncWrite and AsyncRead for WebSocket #379

Merged
merged 4 commits into from
Oct 6, 2023

Conversation

CBenoit
Copy link
Contributor

@CBenoit CBenoit commented Oct 4, 2023

Implements AsyncWrite and AsyncRead on WebSocket behind the io-util feature flag.

This code was originally living in an ad hoc fashion, in our IronRDP repository, and I thought it was best to upstream it. In addition to the unit tests, I can confirm it works when running long-lived RDP sessions in the browser.

Closes #25

@CBenoit CBenoit force-pushed the websocket-async-read-async-write branch from 120bc58 to 6ae0098 Compare October 4, 2023 23:18
Comment on lines +103 to +104
# As of now, only implements `AsyncRead` and `AsyncWrite` on `WebSocket`
io-util = ["futures-io"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it was best to provide this as an optional feature so that futures-io is not added in the dependency graph of all dependents

Comment on lines +60 to +64
/// Leftover bytes when using `AsyncRead`.
///
/// These bytes are drained and returned in subsequent calls to `poll_read`.
#[cfg(feature = "io-util")]
pub(super) read_pending_bytes: Option<Vec<u8>>, // Same size as `Vec<u8>` alone thanks to niche optimization
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative to Vec::drain would be to maintain an index pointing to the beginning of the "pending" region

Copy link
Collaborator

@ranile ranile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add an integration test for this and also update the CHANGELOG file in the root of the repo?

Update: I just noticed that the tests mod includes the integration tests. Can you just update the changelog? It'll be ready for merge then

@@ -99,3 +100,5 @@ eventsource = [
'web-sys/EventSource',
'web-sys/MessageEvent',
]
# As of now, only implements `AsyncRead` and `AsyncWrite` on `WebSocket`
io-util = ["futures-io"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
io-util = ["futures-io"]
io-util = ["dep:futures-io"]

This ensures futures-io is not a feature (by default, cargo adds features for optional dependencies)

Copy link
Contributor Author

@CBenoit CBenoit Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you. However, the rest of the Cargo.toml is currently not using dep: to denote a dependency. When using this notation at one place, the other places must be updated too because this effectively disables the old "implicit features". This is also technically a breaking change because these implicit features may be enabled by downstream users, though it’s probably not a big deal because there is generally little value in enabling those. I think it’s better to tackle this in a separate PR for all crates in order to keep consistency. However, if you prefer I’m okay with converting this crate as part of this PR. I just want to make sure it’s okay for you.

@CBenoit
Copy link
Contributor Author

CBenoit commented Oct 5, 2023

Can you also add an integration test for this and also update the CHANGELOG file in the root of the repo?

Update: I just noticed that the tests mod includes the integration tests. Can you just update the changelog? It'll be ready for merge then

Maybe it’s better if I move these tests in the tests/ folder instead? I mirrored how it was done in the futures module, but as you said, those are integration tests. Maybe I should move the one in futures as well for consistency. What do you think?

@ranile
Copy link
Collaborator

ranile commented Oct 5, 2023

No, it's fine here as well. I would like to keep them consistent and this PR is not a place to move the tests. Can you merge from master and update the changelog? Merging from master should also fix the CI failures

@CBenoit CBenoit force-pushed the websocket-async-read-async-write branch from f91b372 to 06cedc4 Compare October 5, 2023 17:28
@CBenoit
Copy link
Contributor Author

CBenoit commented Oct 5, 2023

No, it's fine here as well. I would like to keep them consistent and this PR is not a place to move the tests. Can you merge from master and update the changelog? Merging from master should also fix the CI failures

Sounds good. I rebased on master and only updated the changelog (see the last commit).

Copy link
Collaborator

@ranile ranile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How about impl AsyncRead/AsyncWrite for WebSocket?
2 participants