Skip to content

Commit

Permalink
refactor(udp): pass SocketAddr instead of &SocketAddr
Browse files Browse the repository at this point in the history
`SocketAddr` implements `Copy`.

https://doc.rust-lang.org/std/net/enum.SocketAddr.html#impl-Copy-for-SocketAddr

Thus there is no need to pass by reference instead of by value.
  • Loading branch information
mxinden committed Oct 11, 2024
1 parent 944c817 commit b88836b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion neqo-bin/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ impl<'a, H: Handler> Runner<'a, H> {

async fn process_multiple_input(&mut self) -> Res<()> {
loop {
let dgrams = self.socket.recv(&self.local_addr)?;
let dgrams = self.socket.recv(self.local_addr)?;
if dgrams.is_empty() {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion neqo-bin/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl ServerRunner {
match self.ready().await? {
Ready::Socket(inx) => loop {
let (host, socket) = self.sockets.get_mut(inx).unwrap();
let dgrams = socket.recv(host)?;
let dgrams = socket.recv(*host)?;
if dgrams.is_empty() {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion neqo-bin/src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Socket {

/// Receive a batch of [`Datagram`]s on the given [`Socket`], each set with
/// the provided local address.
pub fn recv(&self, local_address: &SocketAddr) -> Result<Vec<Datagram>, io::Error> {
pub fn recv(&self, local_address: SocketAddr) -> Result<Vec<Datagram>, io::Error> {
self.inner
.try_io(tokio::io::Interest::READABLE, || {
neqo_udp::recv_inner(local_address, &self.state, &self.inner)
Expand Down
12 changes: 6 additions & 6 deletions neqo-udp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use std::os::fd::AsFd as SocketRef;
use std::os::windows::io::AsSocket as SocketRef;

pub fn recv_inner(
local_address: &SocketAddr,
local_address: SocketAddr,
state: &UdpSocketState,
socket: impl SocketRef,
) -> Result<Vec<Datagram>, io::Error> {
Expand Down Expand Up @@ -99,7 +99,7 @@ pub fn recv_inner(
);
Datagram::new(
meta.addr,
*local_address,
local_address,
meta.ecn.map(|n| IpTos::from(n as u8)).unwrap_or_default(),
d,
)
Expand Down Expand Up @@ -138,7 +138,7 @@ impl<S: SocketRef> Socket<S> {

/// Receive a batch of [`Datagram`]s on the given [`Socket`], each
/// set with the provided local address.
pub fn recv(&self, local_address: &SocketAddr) -> Result<Vec<Datagram>, io::Error> {
pub fn recv(&self, local_address: SocketAddr) -> Result<Vec<Datagram>, io::Error> {
recv_inner(local_address, &self.state, &self.inner)
}
}
Expand Down Expand Up @@ -170,7 +170,7 @@ mod tests {
);

sender.send(&datagram)?;
let res = receiver.recv(&receiver_addr);
let res = receiver.recv(receiver_addr);
assert_eq!(res.unwrap_err().kind(), std::io::ErrorKind::WouldBlock);

Ok(())
Expand All @@ -192,7 +192,7 @@ mod tests {
sender.send(&datagram)?;

let received_datagram = receiver
.recv(&receiver_addr)
.recv(receiver_addr)
.expect("receive to succeed")
.into_iter()
.next()
Expand Down Expand Up @@ -238,7 +238,7 @@ mod tests {
let mut num_received = 0;
while num_received < max_gso_segments {
receiver
.recv(&receiver_addr)
.recv(receiver_addr)
.expect("receive to succeed")
.into_iter()
.for_each(|d| {
Expand Down

0 comments on commit b88836b

Please sign in to comment.