mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-19 00:00:09 +02:00
net: Pass SocketAddr by value (#3125)
This commit is contained in:
@@ -130,7 +130,7 @@ impl<I, C: Encoder<I> + Unpin> Sink<(I, SocketAddr)> for UdpFramed<C> {
|
||||
..
|
||||
} = *self;
|
||||
|
||||
let n = ready!(socket.poll_send_to(cx, &wr, &out_addr))?;
|
||||
let n = ready!(socket.poll_send_to(cx, &wr, *out_addr))?;
|
||||
|
||||
let wrote_all = n == self.wr.len();
|
||||
self.wr.clear();
|
||||
|
||||
@@ -745,11 +745,11 @@ impl UdpSocket {
|
||||
&self,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &[u8],
|
||||
target: &SocketAddr,
|
||||
target: SocketAddr,
|
||||
) -> Poll<io::Result<usize>> {
|
||||
self.io
|
||||
.registration()
|
||||
.poll_write_io(cx, || self.io.send_to(buf, *target))
|
||||
.poll_write_io(cx, || self.io.send_to(buf, target))
|
||||
}
|
||||
|
||||
/// Try to send data on the socket to the given address, but if the send is
|
||||
|
||||
+5
-5
@@ -66,7 +66,7 @@ async fn send_to_recv_from_poll() -> std::io::Result<()> {
|
||||
let receiver = UdpSocket::bind("127.0.0.1:0").await?;
|
||||
|
||||
let receiver_addr = receiver.local_addr()?;
|
||||
poll_fn(|cx| sender.poll_send_to(cx, MSG, &receiver_addr)).await?;
|
||||
poll_fn(|cx| sender.poll_send_to(cx, MSG, receiver_addr)).await?;
|
||||
|
||||
let mut recv_buf = [0u8; 32];
|
||||
let mut read = ReadBuf::new(&mut recv_buf);
|
||||
@@ -83,7 +83,7 @@ async fn send_to_peek_from() -> std::io::Result<()> {
|
||||
let receiver = UdpSocket::bind("127.0.0.1:0").await?;
|
||||
|
||||
let receiver_addr = receiver.local_addr()?;
|
||||
poll_fn(|cx| sender.poll_send_to(cx, MSG, &receiver_addr)).await?;
|
||||
poll_fn(|cx| sender.poll_send_to(cx, MSG, receiver_addr)).await?;
|
||||
|
||||
// peek
|
||||
let mut recv_buf = [0u8; 32];
|
||||
@@ -111,7 +111,7 @@ async fn send_to_peek_from_poll() -> std::io::Result<()> {
|
||||
let receiver = UdpSocket::bind("127.0.0.1:0").await?;
|
||||
|
||||
let receiver_addr = receiver.local_addr()?;
|
||||
poll_fn(|cx| sender.poll_send_to(cx, MSG, &receiver_addr)).await?;
|
||||
poll_fn(|cx| sender.poll_send_to(cx, MSG, receiver_addr)).await?;
|
||||
|
||||
let mut recv_buf = [0u8; 32];
|
||||
let mut read = ReadBuf::new(&mut recv_buf);
|
||||
@@ -192,7 +192,7 @@ async fn split_chan_poll() -> std::io::Result<()> {
|
||||
let (tx, mut rx) = tokio::sync::mpsc::channel::<(Vec<u8>, std::net::SocketAddr)>(1_000);
|
||||
tokio::spawn(async move {
|
||||
while let Some((bytes, addr)) = rx.recv().await {
|
||||
poll_fn(|cx| s.poll_send_to(cx, &bytes, &addr))
|
||||
poll_fn(|cx| s.poll_send_to(cx, &bytes, addr))
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
@@ -209,7 +209,7 @@ async fn split_chan_poll() -> std::io::Result<()> {
|
||||
|
||||
// test that we can send a value and get back some response
|
||||
let sender = UdpSocket::bind("127.0.0.1:0").await?;
|
||||
poll_fn(|cx| sender.poll_send_to(cx, MSG, &addr)).await?;
|
||||
poll_fn(|cx| sender.poll_send_to(cx, MSG, addr)).await?;
|
||||
|
||||
let mut recv_buf = [0u8; 32];
|
||||
let mut read = ReadBuf::new(&mut recv_buf);
|
||||
|
||||
Reference in New Issue
Block a user