pub struct BandwidthManager { /* private fields */ }Expand description
Bandwidth manager for controlling incoming/outgoing data rates.
Implementations§
Source§impl BandwidthManager
impl BandwidthManager
Sourcepub fn new(
outgoing_bw: u32,
incoming_bw: u32,
window_duration: Duration,
) -> Self
pub fn new( outgoing_bw: u32, incoming_bw: u32, window_duration: Duration, ) -> Self
Creates a new bandwidth manager with specified limits (bytes/sec).
Sourcepub fn set_outgoing_bandwidth(&mut self, bytes_per_sec: u32)
pub fn set_outgoing_bandwidth(&mut self, bytes_per_sec: u32)
Sets the outgoing bandwidth limit in bytes per second.
Sourcepub fn set_incoming_bandwidth(&mut self, bytes_per_sec: u32)
pub fn set_incoming_bandwidth(&mut self, bytes_per_sec: u32)
Sets the incoming bandwidth limit in bytes per second.
Sourcepub fn update_window(&mut self, now: Instant)
pub fn update_window(&mut self, now: Instant)
Updates the bandwidth window if needed.
Sourcepub fn can_send_outgoing(&self, byte_count: usize) -> bool
pub fn can_send_outgoing(&self, byte_count: usize) -> bool
Checks if sending the given number of bytes is allowed. Returns true if allowed, false if would exceed bandwidth limit.
Sourcepub fn record_sent(&mut self, byte_count: usize)
pub fn record_sent(&mut self, byte_count: usize)
Records that the given number of bytes were sent.
Sourcepub fn can_receive_incoming(&self, byte_count: usize) -> bool
pub fn can_receive_incoming(&self, byte_count: usize) -> bool
Checks if receiving the given number of bytes is allowed.
Sourcepub fn record_received(&mut self, byte_count: usize)
pub fn record_received(&mut self, byte_count: usize)
Records that the given number of bytes were received.
Sourcepub fn outgoing_utilization(&self) -> f32
pub fn outgoing_utilization(&self) -> f32
Returns the current outgoing bandwidth utilization (0.0 to 1.0+).
Sourcepub fn incoming_utilization(&self) -> f32
pub fn incoming_utilization(&self) -> f32
Returns the current incoming bandwidth utilization (0.0 to 1.0+).
Trait Implementations§
Source§impl Clone for BandwidthManager
impl Clone for BandwidthManager
Source§fn clone(&self) -> BandwidthManager
fn clone(&self) -> BandwidthManager
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for BandwidthManager
impl RefUnwindSafe for BandwidthManager
impl Send for BandwidthManager
impl Sync for BandwidthManager
impl Unpin for BandwidthManager
impl UnwindSafe for BandwidthManager
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