microasync_util/io/write/
udpsocket.rs1extern crate std;
2
3use core::{
4 future::Future,
5 pin::Pin,
6 task::{Context, Poll},
7};
8use std::{io, net::UdpSocket};
9
10use super::{WriteExactFuture, WriteFuture};
11
12impl<'a> Future for WriteFuture<'a, UdpSocket> {
13 type Output = Result<usize, io::Error>;
14
15 fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
16 let me = self.get_mut();
17 me.0.set_nonblocking(true)
18 .expect("unable to set nonblocking-mode.");
19 let r = me.0.send(me.1);
20 me.0.set_nonblocking(false)
21 .expect("unable to clear nonblocking-mode.");
22
23 Poll::Ready(r)
24 }
25}
26
27impl<'a> Future for WriteExactFuture<'a, UdpSocket> {
28 type Output = Result<(), io::Error>;
29
30 fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
31 let me = self.get_mut();
32 me.0.set_nonblocking(true)
33 .expect("unable to set nonblocking-mode.");
34 let mut n = 0;
35 while n != me.1.len() {
36 n += match me.0.send(&(me.1)[n..]) {
37 Ok(x) => x,
38 Err(e) => return Poll::Ready(Err(e)),
39 }
40 }
41 me.0.set_nonblocking(false)
42 .expect("unable to clear nonblocking-mode.");
43
44 Poll::Ready(Ok(()))
45 }
46}