aboutsummaryrefslogtreecommitdiffstats
path: root/src/types/udp.rs
blob: 00e218ffbfddae41f3b1a9448950aa3c4d7b4988 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use super::Endpoint;
use std::error;

/* Often times an a file descriptor in an atomic might suffice.
 */
pub trait Bind: Send + Sync {
    type Error: error::Error;
    type Endpoint: Endpoint;

    fn new() -> Self;

    /// Updates the port of the Bind
    ///
    /// # Arguments
    ///
    /// - port, The new port to bind to. 0 means any available port.
    ///
    /// # Returns
    ///
    /// The unit type or an error, if binding fails
    fn set_port(&self, port: u16) -> Result<(), Self::Error>;

    /// Returns the current port of the bind
    fn get_port(&self) -> u16;
    fn recv(&self, dst: &mut [u8]) -> Self::Endpoint;
    fn send(&self, src: &[u8], dst: &Self::Endpoint);
}