pub struct Client { /* private fields */ }
Expand description
Manages a single outbound uflow
connection.
Implementations§
source§impl Client
impl Client
sourcepub fn connect<A: ToSocketAddrs>(
dst_addr: A,
config: Config
) -> Result<Self, Error>
pub fn connect<A: ToSocketAddrs>(
dst_addr: A,
config: Config
) -> Result<Self, Error>
Opens a non-blocking UDP socket bound to an ephemeral address, and returns a corresponding
Client
object. A connection to the server at the provided destination address is
initiated immediately.
An IPv4/IPv6 socket will be opened according to the type of the destination address.
Error Handling
Any errors resulting from socket initialization are forwarded to the caller. This function will panic if the provided client configuration is not valid.
sourcepub fn step(&mut self) -> impl Iterator<Item = Event>
pub fn step(&mut self) -> impl Iterator<Item = Event>
Flushes outbound frames, then processes as many inbound frames as possible from the
internal socket. Returns an iterator of Event
objects to signal connection events and
deliver packets received from the server.
Note 1: All events are considered delivered, even if the iterator is not consumed until the end.
Note 2: Internally, uflow
uses the leaky bucket
algorithm to control the rate at which UDP
frames are sent. To ensure that data is transferred smoothly, this function should be
called regularly and relatively frequently.
sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Returns true
if the connection is active, that is, a connection handshake has been
completed and the remote host has not yet timed out or disconnected. Returns false
otherwise.
sourcepub fn send(&mut self, data: Box<[u8]>, channel_id: usize, mode: SendMode)
pub fn send(&mut self, data: Box<[u8]>, channel_id: usize, mode: SendMode)
Enqueues a packet for delivery to the server. The packet will be sent on the given channel according to the specified mode.
If a connection has not yet been established, the packet will remain enqueued until the connection succeeds. Otherwise, if the connection is not active, the packet will be silently discarded.
Error Handling
This function will panic if channel_id
does not refer to a valid channel (channel_id >= CHANNEL_COUNT
), or if data.len()
exceeds the maximum packet
size.
sourcepub fn disconnect(&mut self)
pub fn disconnect(&mut self)
Gracefully terminates this connection once all packets have been sent.
If any outbound packets are pending, they will be sent prior to disconnecting. Reliable
packets can be assumed to have been delievered, so long as the server does not also
disconnect in the meantime. The connection will remain active until the next call to
Client::step()
with no pending outbound packets.
sourcepub fn disconnect_now(&mut self)
pub fn disconnect_now(&mut self)
Gracefully terminates this connection as soon as possible.
If any outbound packets are pending, they may be flushed prior to disconnecting, but no
packets are guaranteed to be received by the server. The connection will remain active
until the next call to Client::step()
.
sourcepub fn local_address(&self) -> SocketAddr
pub fn local_address(&self) -> SocketAddr
Returns the local address of the internal UDP socket.
sourcepub fn remote_address(&self) -> SocketAddr
pub fn remote_address(&self) -> SocketAddr
Returns the address of the server.
sourcepub fn rtt_s(&self) -> Option<f64>
pub fn rtt_s(&self) -> Option<f64>
Returns the current estimate of the round-trip time (RTT), in seconds.
If the RTT has not yet been computed, None
is returned instead.
sourcepub fn send_buffer_size(&self) -> usize
pub fn send_buffer_size(&self) -> usize
Returns the combined size of all outstanding packets (i.e. those which have not yet been acknowledged), in bytes.
This figure represents the amount of memory allocated for outgoing packets. Packets which
are marked TimeSensitive
are included in this total, even if
they would not be sent.