-
Notifications
You must be signed in to change notification settings - Fork 965
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The current `StreamMuxer` API is based around a poll-based approach where each substream needs to be passed by value to read/write/close it. The muxer itself however is not available in the end-user abstractions like `ConnectionHandler`. To circumvent this, the `StreamMuxerBox` type exists which allows a `StreamMuxer` to be cloned. Together with `SubstreamRef`, this allows each substream to own a reference to the muxer it was created with and pass itself to the muxer within implementations of `AsyncRead` and `AsyncWrite`. These implementations are convenient as they allow an end-user to simply read and write to the substream without holding a reference to anything else. We can achieve the same goal by changing the `StreamMuxer` abstraction to always return a `AsyncReadWriteBox`. Depending on the implementation of the muxer, this may require more code within its implementation of the `StreamMuxer` trait. yamux already provides a `Stream` type that implements `AsyncRead` and `AsyncWrite` and we can thus directly construct a `AsyncReadWriteBox`. For mplex, we wrap the actual muxer in an `Arc` and store it within the `Substream` struct. This allowsus to call the various `poll_` functions from within the `AsyncRead` and `AsyncWrite` implementations.
- Loading branch information
1 parent
9c90331
commit 2b0f2de
Showing
20 changed files
with
463 additions
and
1,340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.