pub struct Ports { /* private fields */ }
Expand description
port table.
Implementations§
Source§impl Ports
impl Ports
pub fn new() -> Self
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
get ports capacity.
§Examples
use turn_rs::router::ports::*;
let ports = Ports::new();
assert_eq!(ports.capacity(), 65535 - 49152);
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
get ports allocated size.
§Examples
use turn_rs::router::ports::*;
let ports = Ports::new();
assert_eq!(ports.len(), 0);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
get ports allocated size is empty.
§Examples
use turn_rs::router::ports::*;
let ports = Ports::new();
assert_eq!(ports.is_empty(), true);
Sourcepub fn get(&self, p: u16) -> Option<SocketAddr>
pub fn get(&self, p: u16) -> Option<SocketAddr>
get address from port.
§Examples
use std::net::SocketAddr;
use turn_rs::router::ports::*;
let ports = Ports::new();
let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();
let port = ports.alloc(&addr).unwrap();
assert!(ports.get(port).is_some());
Sourcepub fn get_bound(&self, a: &SocketAddr, p: &SocketAddr) -> Option<u16>
pub fn get_bound(&self, a: &SocketAddr, p: &SocketAddr) -> Option<u16>
get address bound port.
§Examples
use std::net::SocketAddr;
use turn_rs::router::ports::*;
let local = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();
let peer = "127.0.0.1:8081".parse::<SocketAddr>().unwrap();
let pools = Ports::new();
let port = pools.alloc(&local).unwrap();
assert!(pools.bound(&local, port).is_some());
assert!(pools.bound(&peer, port).is_some());
assert_eq!(pools.get_bound(&local, &peer), Some(port));
Sourcepub fn alloc(&self, a: &SocketAddr) -> Option<u16>
pub fn alloc(&self, a: &SocketAddr) -> Option<u16>
allocate port in ports.
§Examples
use std::net::SocketAddr;
use turn_rs::router::ports::*;
let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();
let pools = Ports::new();
assert_eq!(pools.alloc(&addr).is_some(), true);
Sourcepub fn bound(&self, addr: &SocketAddr, port: u16) -> Option<()>
pub fn bound(&self, addr: &SocketAddr, port: u16) -> Option<()>
bound address and peer port.
§Examples
use std::net::SocketAddr;
use turn_rs::router::ports::*;
let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();
let pools = Ports::new();
let port = pools.alloc(&addr).unwrap();
assert!(pools.bound(&addr, port).is_some());
Sourcepub fn remove(&self, a: &SocketAddr, ports: &[u16]) -> Option<()>
pub fn remove(&self, a: &SocketAddr, ports: &[u16]) -> Option<()>
bound address and peer port.
§Examples
use std::net::SocketAddr;
use turn_rs::router::ports::*;
let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();
let pools = Ports::new();
let port = pools.alloc(&addr).unwrap();
assert!(pools.bound(&addr, port).is_some());
assert!(pools.remove(&addr, &vec![port]).is_some());
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Ports
impl RefUnwindSafe for Ports
impl Send for Ports
impl Sync for Ports
impl Unpin for Ports
impl UnwindSafe for Ports
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more