pub struct DnsClient { /* private fields */ }Expand description
Implementations§
Source§impl DnsClient
impl DnsClient
Sourcepub fn new(
stack: &mut Stack<'_>,
servers: &[IpAddress],
) -> Result<DnsClient, Full>
pub fn new( stack: &mut Stack<'_>, servers: &[IpAddress], ) -> Result<DnsClient, Full>
Create a DNS client.
Creates and binds a UDP socket in stack.
Truncates the server list if servers.len() > DNS_MAX_SERVER_COUNT.
Errors:
Fullif the stack has no room for another UDP socket.
Sourcepub fn remove(self, stack: &mut Stack<'_>)
pub fn remove(self, stack: &mut Stack<'_>)
Destroy the client, removing its UDP socket from stack.
Pending queries are cancelled.
Sourcepub fn socket(&self) -> UdpHandle
pub fn socket(&self) -> UdpHandle
The UDP socket the client sends and receives on.
Use it to set the hop limit. Don’t bind, close or read from it.
Sourcepub fn update_servers(&mut self, servers: &[IpAddress])
pub fn update_servers(&mut self, servers: &[IpAddress])
Update the list of DNS servers, will replace all existing servers
Truncates the server list if servers.len() > DNS_MAX_SERVER_COUNT.
Sourcepub fn start_query(
&mut self,
stack: &mut Stack<'_>,
name: &str,
query_type: Type,
) -> Result<DnsQueryHandle, StartQueryError>
pub fn start_query( &mut self, stack: &mut Stack<'_>, name: &str, query_type: Type, ) -> Result<DnsQueryHandle, StartQueryError>
Start a query.
name is specified in human-friendly format, such as "rust-lang.org".
It accepts names both with and without trailing dot, and they’re treated
the same (there’s no support for DNS search path).
With the mdns feature, names ending in .local are sent with multicast DNS.
Sourcepub fn start_query_raw(
&mut self,
stack: &mut Stack<'_>,
raw_name: &[u8],
query_type: Type,
mdns: MulticastDns,
) -> Result<DnsQueryHandle, StartQueryError>
pub fn start_query_raw( &mut self, stack: &mut Stack<'_>, raw_name: &[u8], query_type: Type, mdns: MulticastDns, ) -> Result<DnsQueryHandle, StartQueryError>
Start a query with a raw (wire-format) DNS name, such as
b"\x09rust-lang\x03org\x00".
You probably want to use start_query instead.
Sourcepub fn get_query_result(
&mut self,
handle: DnsQueryHandle,
) -> Result<Vec<IpAddress, DNS_MAX_RESULT_COUNT>, GetQueryResultError>
pub fn get_query_result( &mut self, handle: DnsQueryHandle, ) -> Result<Vec<IpAddress, DNS_MAX_RESULT_COUNT>, GetQueryResultError>
Get the result of a query.
If the query is completed, the query slot is automatically freed.
§Panics
Panics if the handle corresponds to a free slot.
Sourcepub fn cancel_query(&mut self, handle: DnsQueryHandle)
pub fn cancel_query(&mut self, handle: DnsQueryHandle)
Cancels a query, freeing the slot.
§Panics
Panics if the handle corresponds to an already free slot.
Sourcepub fn register_query_waker(&mut self, handle: DnsQueryHandle, waker: &Waker)
pub fn register_query_waker(&mut self, handle: DnsQueryHandle, waker: &Waker)
Assign a waker to a query slot.
The waker will be woken when the query completes, either successfully or failed.
§Panics
Panics if the handle corresponds to an already free slot.
Sourcepub fn poll(&mut self, stack: &mut Stack<'_>) -> Instant
pub fn poll(&mut self, stack: &mut Stack<'_>) -> Instant
Advance the client: process received responses and send due queries.
Uses the time of the last Stack::poll.
Returns the next time poll should be called to retransmit a query, or
Instant::MAX if no query is pending. Call it after every Stack::poll,
and again when that deadline arrives.