-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
io: bring back split
utility
#1521
Conversation
Bring back `split` utility as a free fn instead of a method on `AsyncRead`. This utility wraps the `stream` in an `Arc` and uses mutual exclusion to ensure correct access. Additionally, the specialized `split_mut` fn on TcpStream and UdsStream is promoted to `split`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM
|
||
struct Inner<T> { | ||
locked: AtomicBool, | ||
stream: UnsafeCell<T>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a quick check, is UnsafeCell necessary here?
I'm generally happy for this change, but the loss of an owned split for |
@jonhoo +1, also not sure why the owning version was removed/replaced. I can't use the referencing |
An owning version exists as a free fn: The idea is to place emphasis on the async/await friendly zero-cost options. |
Hm, ok, but the read and write halves being references reduces the usefulness of this split quite a lot. The |
You are correct, except that introducing an Could you describe more what you are trying to do? |
Our code is here (using tokio 0.1 with async/await preview, beware, there are some ugly hacks, especially my attemp at I'm in the process of attempting to port that code to tokio 0.2. So, would it be considered non-zero-cost even if the |
Bring back
split
utility as a free fn instead of a method onAsyncRead
. This utility wraps thestream
in anArc
and uses mutualexclusion to ensure correct access.
Additionally, the specialized
split_mut
fn on TcpStream and UdsStreamis promoted to
split
.