Skip to content

Commit d50269a

Browse files
authored
PollStream/PollDataChannel: flush before shutting down (#340)
* PollStream/PollDataChannel: flush before shutting down "Invocation of a shutdown implies an invocation of flush. Once this method returns Ready it implies that a flush successfully happened before the shutdown happened. That is, callers don’t need to call flush before calling shutdown. They can rely that by calling shutdown any pending buffered data will be written out." https://docs.rs/tokio/1.21.2/tokio/io/trait.AsyncWrite.html#tymethod.poll_shutdown * format code * fix clippy warning * fix another clippy warning * add changelog entries
1 parent c0579c3 commit d50269a

File tree

6 files changed

+29
-19
lines changed

6 files changed

+29
-19
lines changed

data/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
* Increased minimum support rust version to `1.60.0`.
6+
* `PollDataChannel::poll_shutdown`: make sure to flush any writes before shutting down [#340](https://github.com/webrtc-rs/webrtc/pull/340)
67

78
## 0.5.0
89

data/src/data_channel/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,11 @@ impl AsyncWrite for PollDataChannel {
626626
}
627627

628628
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
629+
match self.as_mut().poll_flush(cx) {
630+
Poll::Pending => return Poll::Pending,
631+
Poll::Ready(_) => {}
632+
}
633+
629634
let fut = match self.shutdown_fut.as_mut() {
630635
Some(fut) => fut,
631636
None => {

sctp/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
* Increased minimum support rust version to `1.60.0`.
6+
* `PollStream::poll_shutdown`: make sure to flush any writes before shutting down [#340](https://github.com/webrtc-rs/webrtc/pull/340)
67

78
## v0.6.1
89

@@ -12,4 +13,3 @@
1213
## Prior to 0.6.1
1314

1415
Before 0.6.1 there was no changelog, previous changes are sometimes, but not always, available in the [GitHub Releases](https://github.com/webrtc-rs/sctp/releases).
15-

sctp/src/stream/mod.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@ mod stream_test;
44
use crate::association::AssociationState;
55
use crate::chunk::chunk_payload_data::{ChunkPayloadData, PayloadProtocolIdentifier};
66
use crate::error::{Error, Result};
7-
use crate::queue::reassembly_queue::ReassemblyQueue;
8-
97
use crate::queue::pending_queue::PendingQueue;
8+
use crate::queue::reassembly_queue::ReassemblyQueue;
109

1110
use bytes::Bytes;
12-
use std::fmt;
13-
use std::future::Future;
14-
use std::io;
15-
use std::net::Shutdown;
16-
use std::pin::Pin;
17-
use std::sync::atomic::{AtomicBool, AtomicU16, AtomicU32, AtomicU8, AtomicUsize, Ordering};
18-
use std::sync::Arc;
19-
use std::task::{Context, Poll};
20-
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
21-
use tokio::sync::{mpsc, Mutex, Notify};
11+
use std::{
12+
fmt,
13+
future::Future,
14+
io,
15+
net::Shutdown,
16+
pin::Pin,
17+
sync::atomic::{AtomicBool, AtomicU16, AtomicU32, AtomicU8, AtomicUsize, Ordering},
18+
sync::Arc,
19+
task::{Context, Poll},
20+
};
21+
use tokio::{
22+
io::{AsyncRead, AsyncWrite, ReadBuf},
23+
sync::{mpsc, Mutex, Notify},
24+
};
2225

2326
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
2427
#[repr(C)]
@@ -760,6 +763,11 @@ impl AsyncWrite for PollStream {
760763
}
761764

762765
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
766+
match self.as_mut().poll_flush(cx) {
767+
Poll::Pending => return Poll::Pending,
768+
Poll::Ready(_) => {}
769+
}
770+
763771
let fut = match self.shutdown_fut.as_mut() {
764772
Some(fut) => fut,
765773
None => {

stun/src/message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub struct Message {
6464

6565
impl fmt::Display for Message {
6666
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67-
let t_id = base64::encode(&self.transaction_id.0);
67+
let t_id = base64::encode(self.transaction_id.0);
6868
write!(
6969
f,
7070
"{} l={} attrs={} id={}",

util/src/fixed_big_int/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ impl FixedBigInt {
8181
}
8282
let chunk = i / 64;
8383
let pos = i % 64;
84-
if self.bits[chunk] & (1 << pos) != 0 {
85-
1
86-
} else {
87-
0
88-
}
84+
usize::from(self.bits[chunk] & (1 << pos) != 0)
8985
}
9086

9187
// set_bit sets i-th bit to 1.

0 commit comments

Comments
 (0)