Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Jan 15, 2024
1 parent b3de617 commit 11e9cc0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 7 additions & 0 deletions quinn-proto/src/connection/datagrams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ pub struct Datagrams<'a> {
impl<'a> Datagrams<'a> {
/// Queue an unreliable, unordered datagram for immediate transmission
///
/// If `drop` is true, previously queued datagrams which are still unsent will be discarded to
/// make space for this datagram. If `drop` is false, and there isn't enough space due to
/// previously queued datagrams, this function will return `SendDatagramError::Blocked`
///
/// Returns `Err` iff a `len`-byte datagram cannot currently be sent
pub fn send(&mut self, data: Bytes, drop: bool) -> Result<(), SendDatagramError> {
if self.conn.config.datagram_receive_buffer_size.is_none() {
Expand All @@ -44,6 +48,7 @@ impl<'a> Datagrams<'a> {
} else if self.conn.datagrams.outgoing_total + data.len()
> self.conn.config.datagram_send_buffer_size
{
self.conn.datagrams.send_blocked = true;
return Err(SendDatagramError::Blocked(data));
}
self.conn.datagrams.outgoing_total += data.len();
Expand Down Expand Up @@ -101,6 +106,7 @@ pub(super) struct DatagramState {
pub(super) incoming: VecDeque<Datagram>,
pub(super) outgoing: VecDeque<Datagram>,
pub(super) outgoing_total: usize,
pub(super) send_blocked: bool,
}

impl DatagramState {
Expand Down Expand Up @@ -147,6 +153,7 @@ impl DatagramState {
}

self.outgoing_total -= datagram.data.len();
self.send_blocked = false;
datagram.encode(true, buf);
true
}
Expand Down
3 changes: 2 additions & 1 deletion quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3095,6 +3095,7 @@ impl Connection {
}

// DATAGRAM
let datagram_send_was_blocked = self.datagrams.send_blocked;
let mut sent_datagrams = false;
while buf.len() + Datagram::SIZE_BOUND < max_size && space_id == SpaceId::Data {
match self.datagrams.write(buf, max_size) {
Expand All @@ -3106,7 +3107,7 @@ impl Connection {
false => break,
}
}
if sent_datagrams {
if datagram_send_was_blocked && sent_datagrams {
self.events.push_back(Event::DatagramSent);
}

Expand Down
6 changes: 2 additions & 4 deletions quinn/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,11 @@ impl Connection {

/// Transmit `data` as an unreliable, unordered application datagram
///
/// Application datagrams are a low-level primitive. They may be lost or delivered out of order,
/// and `data` must both fit inside a single QUIC packet and be smaller than the maximum
/// dictated by the peer.
///
/// Unlike [`send_datagram()`], this method will wait for buffer space during congestion
/// conditions, which effectively prioritizes old datagrams over new datagrams.
///
/// See [`send_datagram()`] for details.
///
/// [`send_datagram()`]: Connection::send_datagram
pub fn send_datagram_wait(&self, data: Bytes) -> SendDatagram<'_> {
SendDatagram {
Expand Down

0 comments on commit 11e9cc0

Please sign in to comment.