mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-01 18:51:35 +00:00
Add StreamMuxer::flush
. (#534)
Update the `StreamMuxer` trait. - `read_substream`, `write_substream` and `flush_substream` now return `Poll` instead of `Result`. - A new `Shutdown` enum allows for half-closing of substreams and is used in `shutdown_substream`. - `close_inbound` and `close_outbound` have been merged into `shutdown` which takes a `Shutdown` parameter to allow closing only one direction. - Add a new `flush_all` method to allow flushing after a series of actions (e.g. multiple `shutdown_substream`). W.r.t. flushing the general idea is that normal use drains buffers over time. Shutting down a substream does not imply flushing, so can be followed by `flush_substream` or (if multiple substreams are to be shut down) a single `flush_all`. Shutting down the muxer itself proceeds likewise, i.e. `shutdown` followed by `flush_all`.
This commit is contained in:
@ -310,11 +310,18 @@ where
|
||||
for (_, outbound) in self.outbound_substreams.drain() {
|
||||
self.muxer.destroy_outbound(outbound);
|
||||
}
|
||||
if !self.inbound_finished {
|
||||
self.muxer.close_inbound();
|
||||
}
|
||||
if !self.outbound_finished {
|
||||
self.muxer.close_outbound();
|
||||
// TODO: Maybe the shutdown logic should not be part of the destructor?
|
||||
match (self.inbound_finished, self.outbound_finished) {
|
||||
(true, true) => {}
|
||||
(true, false) => {
|
||||
let _ = self.muxer.shutdown(muxing::Shutdown::Outbound);
|
||||
}
|
||||
(false, true) => {
|
||||
let _ = self.muxer.shutdown(muxing::Shutdown::Inbound);
|
||||
}
|
||||
(false, false) => {
|
||||
let _ = self.muxer.shutdown(muxing::Shutdown::All);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user