pub async fn receive_or_exit(
    socket: &mut UdpSocket,
    exit_receiver: &mut tokio::sync::oneshot::Receiver<()>,
    in_buf: &mut [u8],
) -> Result<Option<(usize, SocketAddr)>, CaptivePortalError> {
    // The receive future will be wrapped in a try_select. pin it.
    let receive_future = socket.recv_from(in_buf);
    pin_mut!(receive_future);
    pin_mut!(exit_receiver);

    // Create a future that resolves if either of two futures resolve (receive, exit handler)
    let future = try_select(receive_future, exit_receiver);

    match future.await {
        Ok(v) => {
            if let Either::Left(((size, socket_addr), _)) = v {
                Ok(Some((size, socket_addr)))
            } else {
                Ok(None)
            }
        }
        Err(e) => match e {
            Either::Left((e, _)) => Err(CaptivePortalError::IO(e, "Failed to receive")),
            // Server exit handler dropped
            Either::Right((_, _)) => Ok(None),
        },
    }
}
/// Receives the next packet on a udp socket. The future resolves if either a packet got received,
/// an error occurred or the exit handler that belongs to the given exit_receiver has been triggered.
Receives the next packet on a udp socket. The future resolves if either a packet got received,
an error occurred or the exit handler that belongs to the given exit_receiver has been triggered.
Receives the next packet on a udp socket . The future resolves if either a packet got received an error occurred or the exit handler that belongs to the given exit_receiver has been triggered .
pub async fn receive_or_exit(
    socket: &mut UdpSocket,
    exit_receiver: &mut tokio::sync::oneshot::Receiver<()>,
    in_buf: &mut [u8],
) -> Result<Option<(usize, SocketAddr)>, CaptivePortalError> {
    // The receive future will be wrapped in a try_select. pin it.
    let receive_future = socket.recv_from(in_buf);
    pin_mut!(receive_future);
    pin_mut!(exit_receiver);
    // Create a future that resolves if either of two futures resolve (receive, exit handler)
    let future = try_select(receive_future, exit_receiver);
    match future.await {
        Ok(v) => {
            if let Either::Left(((size, socket_addr), _)) = v {
                Ok(Some((size, socket_addr)))
            } else {
                Ok(None)
            }
        }
        Err(e) => match e {
            Either::Left((e, _)) => Err(CaptivePortalError::IO(e, "Failed to receive")),
            // Server exit handler dropped
            Either::Right((_, _)) => Ok(None),
        },
    }
}
pub async fn receive_or_exit ( socket : & mut UdpSocket , exit_receiver : & mut tokio :: sync :: oneshot :: Receiver < ( ) > , in_buf : & mut [ u8 ] , ) -> Result < Option < ( usize , SocketAddr ) > , CaptivePortalError > { // The receive future will be wrapped in a try_select. pin it. let receive_future = socket . recv_from ( in_buf ) ; pin_mut ! ( receive_future ) ; pin_mut ! ( exit_receiver ) ; // Create a future that resolves if either of two futures resolve (receive, exit handler) let future = try_select ( receive_future , exit_receiver ) ; match future . await { Ok ( v ) => { if let Either :: Left ( ( ( size , socket_addr ) , _ ) ) = v { Ok ( Some ( ( size , socket_addr ) ) ) } else { Ok ( None ) } } Err ( e ) => match e { Either :: Left ( ( e , _ ) ) => Err ( CaptivePortalError :: IO ( e , " " ) ) , // Server exit handler dropped Either :: Right ( ( _ , _ ) ) => Ok ( None ) , } , } }
Receives the next packet on a udp socket.
Receives the next packet on a udp socket .
socket
&mut UdpSocket
exit_receiver
&mut tokio::sync::oneshot::Receiver<()>
in_buf
&mut [u8]
socket
&mut UdpSocket
exit_receiver
&mut tokio::sync::oneshot::Receiver<()>
in_buf
&mut [u8]