-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update tokio-udp to use std-future (#1199)
- Loading branch information
1 parent
0784dc2
commit 6316aa1
Showing
16 changed files
with
342 additions
and
600 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use super::UdpSocket; | ||
use std::future::Future; | ||
use std::io; | ||
use std::pin::Pin; | ||
use std::task::{Context, Poll}; | ||
|
||
/// A future that receives a datagram from the connected address. | ||
/// | ||
/// This `struct` is created by [`recv`](super::UdpSocket::recv). | ||
#[must_use = "futures do nothing unless polled"] | ||
#[derive(Debug)] | ||
pub struct Recv<'a, 'b> { | ||
socket: &'a mut UdpSocket, | ||
buf: &'b mut [u8], | ||
} | ||
|
||
impl<'a, 'b> Recv<'a, 'b> { | ||
pub(super) fn new(socket: &'a mut UdpSocket, buf: &'b mut [u8]) -> Self { | ||
Self { socket, buf } | ||
} | ||
} | ||
|
||
impl<'a, 'b> Future for Recv<'a, 'b> { | ||
type Output = io::Result<usize>; | ||
|
||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
let Recv { socket, buf } = self.get_mut(); | ||
Pin::new(&mut **socket).poll_recv(cx, buf) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use super::UdpSocket; | ||
use std::future::Future; | ||
use std::io; | ||
use std::net::SocketAddr; | ||
use std::pin::Pin; | ||
use std::task::{Context, Poll}; | ||
|
||
/// A future that receives a datagram. | ||
/// | ||
/// This `struct` is created by [`recv_from`](super::UdpSocket::recv_from). | ||
#[must_use = "futures do nothing unless polled"] | ||
#[derive(Debug)] | ||
pub struct RecvFrom<'a, 'b> { | ||
socket: &'a mut UdpSocket, | ||
buf: &'b mut [u8], | ||
} | ||
|
||
impl<'a, 'b> RecvFrom<'a, 'b> { | ||
pub(super) fn new(socket: &'a mut UdpSocket, buf: &'b mut [u8]) -> Self { | ||
Self { socket, buf } | ||
} | ||
} | ||
|
||
impl<'a, 'b> Future for RecvFrom<'a, 'b> { | ||
type Output = io::Result<(usize, SocketAddr)>; | ||
|
||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
let RecvFrom { socket, buf } = self.get_mut(); | ||
Pin::new(&mut **socket).poll_recv_from(cx, buf) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use super::UdpSocket; | ||
use std::future::Future; | ||
use std::io; | ||
use std::pin::Pin; | ||
use std::task::{Context, Poll}; | ||
|
||
/// A future that sends a datagram to the connected address. | ||
/// | ||
/// This `struct` is created by [`send`](super::UdpSocket::send). | ||
#[must_use = "futures do nothing unless polled"] | ||
#[derive(Debug)] | ||
pub struct Send<'a, 'b> { | ||
socket: &'a mut UdpSocket, | ||
buf: &'b [u8], | ||
} | ||
|
||
impl<'a, 'b> Send<'a, 'b> { | ||
pub(super) fn new(socket: &'a mut UdpSocket, buf: &'b [u8]) -> Self { | ||
Self { socket, buf } | ||
} | ||
} | ||
|
||
impl<'a, 'b> Future for Send<'a, 'b> { | ||
type Output = io::Result<usize>; | ||
|
||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
let Send { socket, buf } = self.get_mut(); | ||
Pin::new(&mut **socket).poll_send(cx, buf) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use super::UdpSocket; | ||
use std::future::Future; | ||
use std::io; | ||
use std::net::SocketAddr; | ||
use std::pin::Pin; | ||
use std::task::{Context, Poll}; | ||
|
||
/// A future that sends a datagram to a given address. | ||
/// | ||
/// This `struct` is created by [`send_to`](super::UdpSocket::send_to). | ||
#[must_use = "futures do nothing unless polled"] | ||
#[derive(Debug)] | ||
pub struct SendTo<'a, 'b> { | ||
socket: &'a mut UdpSocket, | ||
buf: &'b [u8], | ||
target: &'b SocketAddr, | ||
} | ||
|
||
impl<'a, 'b> SendTo<'a, 'b> { | ||
pub(super) fn new(socket: &'a mut UdpSocket, buf: &'b [u8], target: &'b SocketAddr) -> Self { | ||
Self { | ||
socket, | ||
buf, | ||
target, | ||
} | ||
} | ||
} | ||
|
||
impl<'a, 'b> Future for SendTo<'a, 'b> { | ||
type Output = io::Result<usize>; | ||
|
||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
let SendTo { | ||
socket, | ||
buf, | ||
target, | ||
} = self.get_mut(); | ||
Pin::new(&mut **socket).poll_send_to(cx, buf, target) | ||
} | ||
} |
Oops, something went wrong.