Skip to content

Commit

Permalink
switch to Bytes to allow cheap cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire authored and djc committed May 9, 2023
1 parent d08ad01 commit 7d006c0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ impl Connection {
self.stats.udp_tx.bytes += buf.len() as u64;
return Some(Transmit {
destination,
contents: buf,
contents: buf.freeze(),
ecn: None,
segment_size: None,
src_ip: self.local_ip,
Expand Down Expand Up @@ -836,7 +836,7 @@ impl Connection {

Some(Transmit {
destination: self.path.remote,
contents: buf,
contents: buf.freeze(),
ecn: if self.path.sending_ecn {
Some(EcnCodepoint::Ect0)
} else {
Expand Down
8 changes: 4 additions & 4 deletions quinn-proto/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl Endpoint {
self.transmits.push_back(Transmit {
destination: remote,
ecn: None,
contents: buf,
contents: buf.freeze(),
segment_size: None,
src_ip: local_ip,
});
Expand Down Expand Up @@ -359,7 +359,7 @@ impl Endpoint {
self.transmits.push_back(Transmit {
destination: addresses.remote,
ecn: None,
contents: buf,
contents: buf.freeze(),
segment_size: None,
src_ip: addresses.local_ip,
});
Expand Down Expand Up @@ -547,7 +547,7 @@ impl Endpoint {
self.transmits.push_back(Transmit {
destination: addresses.remote,
ecn: None,
contents: buf,
contents: buf.freeze(),
segment_size: None,
src_ip: addresses.local_ip,
});
Expand Down Expand Up @@ -703,7 +703,7 @@ impl Endpoint {
self.transmits.push_back(Transmit {
destination: addresses.remote,
ecn: None,
contents: buf,
contents: buf.freeze(),
segment_size: None,
src_ip: addresses.local_ip,
})
Expand Down
4 changes: 2 additions & 2 deletions quinn-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod tests;
pub mod transport_parameters;
mod varint;

use bytes::BytesMut;
use bytes::Bytes;
pub use varint::{VarInt, VarIntBoundsExceeded};

mod connection;
Expand Down Expand Up @@ -278,7 +278,7 @@ pub struct Transmit {
/// Explicit congestion notification bits to set on the packet
pub ecn: Option<EcnCodepoint>,
/// Contents of the datagram
pub contents: BytesMut,
pub contents: Bytes,
/// The segment size if this transmission contains multiple datagrams.
/// This is `None` if the transmit only contains a single datagram
pub segment_size: Option<usize>,
Expand Down
17 changes: 11 additions & 6 deletions quinn-proto/src/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::{
};

use assert_matches::assert_matches;
use bytes::BytesMut;
use lazy_static::lazy_static;
use rustls::{Certificate, KeyLogFile, PrivateKey};
use tracing::{info_span, trace};
Expand Down Expand Up @@ -131,9 +132,11 @@ impl Pair {
socket.send_to(&x.contents, x.destination).unwrap();
}
if self.server.addr == x.destination {
self.server
.inbound
.push_back((self.time + self.latency, x.ecn, x.contents));
self.server.inbound.push_back((
self.time + self.latency,
x.ecn,
x.contents.as_ref().into(),
));
}
}
}
Expand All @@ -154,9 +157,11 @@ impl Pair {
socket.send_to(&x.contents, x.destination).unwrap();
}
if self.client.addr == x.destination {
self.client
.inbound
.push_back((self.time + self.latency, x.ecn, x.contents));
self.client.inbound.push_back((
self.time + self.latency,
x.ecn,
x.contents.as_ref().into(),
));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions quinn-udp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::{
time::{Duration, Instant},
};

use bytes::BytesMut;
use bytes::Bytes;
use tracing::warn;

#[cfg(unix)]
Expand Down Expand Up @@ -132,14 +132,14 @@ impl Default for RecvMeta {
}

/// An outgoing packet
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Transmit {
/// The socket this datagram should be sent to
pub destination: SocketAddr,
/// Explicit congestion notification bits to set on the packet
pub ecn: Option<EcnCodepoint>,
/// Contents of the datagram
pub contents: BytesMut,
pub contents: Bytes,
/// The segment size if this transmission contains multiple datagrams.
/// This is `None` if the transmit only contains a single datagram
pub segment_size: Option<usize>,
Expand Down

0 comments on commit 7d006c0

Please sign in to comment.