Skip to content

Commit 4200246

Browse files
timwu20haikoschol
authored andcommitted
set and listen on ChannelBufferedAmountLow after stream closure
1 parent 925caa9 commit 4200246

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/multistream_select/protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl Message {
220220

221221
// Skip ahead to the next protocol.
222222
remaining = &tail[len..];
223-
if remaining.is_empty(){
223+
if remaining.is_empty() {
224224
// During negotiation the remote may not append a trailing newline.
225225
break;
226226
}

src/transport/webrtc/connection.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,8 @@ impl WebRtcConnection {
631631
protocol: protocol.to_string(),
632632
});
633633

634+
self.rtc.channel(channel_id).unwrap().set_buffered_amount_low_threshold(1024);
635+
634636
tracing::trace!(
635637
target: LOG_TARGET,
636638
peer = ?self.peer,
@@ -742,6 +744,20 @@ impl WebRtcConnection {
742744

743745
continue;
744746
}
747+
Event::ChannelBufferedAmountLow(channel_id) => {
748+
if let Some(ChannelState::Closing) = self.channels.get(&channel_id) {
749+
tracing::trace!(
750+
target: LOG_TARGET,
751+
peer = ?self.peer,
752+
?channel_id,
753+
"buffer drained, closing channel",
754+
);
755+
self.rtc.direct_api().close_data_channel(channel_id);
756+
self.handles.remove(&channel_id);
757+
}
758+
759+
continue;
760+
}
745761
event => {
746762
tracing::debug!(
747763
target: LOG_TARGET,
@@ -794,10 +810,7 @@ impl WebRtcConnection {
794810
?channel_id,
795811
"channel closed",
796812
);
797-
798-
self.rtc.direct_api().close_data_channel(channel_id);
799813
self.channels.insert(channel_id, ChannelState::Closing);
800-
self.handles.remove(&channel_id);
801814
}
802815
Some((channel_id, Some(SubstreamEvent::Message(data)))) => {
803816
if let Err(error) = self.on_outbound_data(channel_id, data) {

0 commit comments

Comments
 (0)