ack_udp/
sock_send.rs

1use std::sync::Arc;
2use std::{net::SocketAddr, io};
3use tokio::net::UdpSocket;
4use tokio::task;
5
6pub trait SockSend {
7  fn sock_send(&self, buf: Vec<u8>, address: SocketAddr);
8}
9
10async fn send(socket: Arc<UdpSocket>, buf: Vec<u8>, address: SocketAddr) -> io::Result<usize> {
11  let a = socket.send_to(&buf, address).await?;
12
13  Ok(a)
14}
15
16impl SockSend for Arc<UdpSocket> {
17  fn sock_send(&self, buf: Vec<u8>, address: SocketAddr) {
18    let socket = self.clone();
19
20    task::spawn(send(socket, buf, address));
21  }
22}