pub struct ServiceResolverBuilder { /* private fields */ }Expand description
Builder for a one-shot DNS-SD resolve of a single, already-known service instance.
Where ServiceBrowserBuilder discovers instances over time, this resolves
one named instance now — mapping the identity fields from a previous
browse BrowseEvent::Found (or BrowseEvent::Removed) event back to a
connectable DiscoveredService. Its main use is as a liveness probe: a
dead instance fails with ServiceBrowseError::ResolveFailed rather than
hanging, so consumers can re-confirm services they haven’t heard from
recently and drop the ones that repeatedly fail.
This matters for the no-goodbye case (a host powered off, crashed, or that
dropped off Wi-Fi without multicasting mDNS goodbye packets): the OS keeps
the browse-driving PTR record until its (long) TTL expires, so no Removed
event is delivered for a long time, yet a fresh resolve of the vanished
instance fails promptly.
§Example
use mdns_sd_discovery::{ServiceBrowseError, ServiceResolverBuilder};
match ServiceResolverBuilder::new("My Web Server", "_http._tcp", "local")
.resolve()
.await
{
Ok(svc) => println!("still alive at {}:{}", svc.host_name, svc.port),
Err(ServiceBrowseError::ResolveFailed(name, _)) => println!("{name} is gone"),
Err(err) => return Err(err.into()),
}Implementations§
Source§impl ServiceResolverBuilder
impl ServiceResolverBuilder
Sourcepub fn new(
name: impl AsRef<str>,
service_type: impl AsRef<str>,
domain: impl AsRef<str>,
) -> Self
pub fn new( name: impl AsRef<str>, service_type: impl AsRef<str>, domain: impl AsRef<str>, ) -> Self
Initializes a builder to resolve the instance identified by name,
service_type (e.g. _http._tcp) and domain (e.g. local).
These are exactly the name,
service_type and
domain fields reported by a browse event.
Sourcepub fn interface_index(&mut self, index: NonZeroU32) -> &mut Self
pub fn interface_index(&mut self, index: NonZeroU32) -> &mut Self
Restricts the resolve to a single interface (the index reported on the
originating browse event, via DiscoveredService::interface_index).
When unset (the default) the instance is resolved on all interfaces.
Sourcepub fn timeout(&mut self, timeout: Duration) -> &mut Self
pub fn timeout(&mut self, timeout: Duration) -> &mut Self
Bounds how long resolve may take before failing with
ServiceBrowseError::ResolveFailed.
This is what makes the resolve usable as a liveness probe: without it, resolving a vanished instance is only bounded by the platform default (on Linux, the D-Bus method timeout of roughly 25 s). Set a shorter timeout to fail faster; the platform default still applies as a ceiling.
Sourcepub async fn resolve(&self) -> Result<DiscoveredService, ServiceBrowseError>
pub async fn resolve(&self) -> Result<DiscoveredService, ServiceBrowseError>
Resolves the instance, returning a connectable DiscoveredService.
Returns ServiceBrowseError::ResolveFailed if the instance no longer
responds (or the configured timeout elapses first).
Trait Implementations§
Source§impl Clone for ServiceResolverBuilder
impl Clone for ServiceResolverBuilder
Source§fn clone(&self) -> ServiceResolverBuilder
fn clone(&self) -> ServiceResolverBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more