pub struct ServiceDaemon { /* private fields */ }Expand description
A daemon thread for mDNS
This struct provides a handle and an API to the daemon. It is cloneable.
Implementations§
source§impl ServiceDaemon
impl ServiceDaemon
sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Creates a new daemon and spawns a thread to run the daemon.
The daemon (re)uses the default mDNS port 5353. To keep it simple, we don’t ask callers to set the port.
sourcepub fn browse(&self, service_type: &str) -> Result<Receiver<ServiceEvent>>
pub fn browse(&self, service_type: &str) -> Result<Receiver<ServiceEvent>>
Starts browsing for a specific service type.
service_type must end with a valid mDNS domain: ‘._tcp.local.’ or ‘._udp.local.’
Returns a channel Receiver to receive events about the service. The caller
can call .recv_async().await on this receiver to handle events in an
async environment or call .recv() in a sync environment.
When a new instance is found, the daemon automatically tries to resolve, i.e. finding more details, i.e. SRV records and TXT records.
sourcepub fn stop_browse(&self, ty_domain: &str) -> Result<()>
pub fn stop_browse(&self, ty_domain: &str) -> Result<()>
Stops searching for a specific service type.
When an error is returned, the caller should retry only when
the error is Error::Again, otherwise should log and move on.
sourcepub fn resolve_hostname(
&self,
hostname: &str,
timeout: Option<u64>,
) -> Result<Receiver<HostnameResolutionEvent>>
pub fn resolve_hostname( &self, hostname: &str, timeout: Option<u64>, ) -> Result<Receiver<HostnameResolutionEvent>>
Starts querying for the ip addresses of a hostname.
Returns a channel Receiver to receive events about the hostname.
The caller can call .recv_async().await on this receiver to handle events in an
async environment or call .recv() in a sync environment.
The timeout is specified in milliseconds.
sourcepub fn stop_resolve_hostname(&self, hostname: &str) -> Result<()>
pub fn stop_resolve_hostname(&self, hostname: &str) -> Result<()>
Stops querying for the ip addresses of a hostname.
When an error is returned, the caller should retry only when
the error is Error::Again, otherwise should log and move on.
sourcepub fn register(&self, service_info: ServiceInfo) -> Result<()>
pub fn register(&self, service_info: ServiceInfo) -> Result<()>
Registers a service provided by this host.
If service_info has no addresses yet and its addr_auto is enabled,
this method will automatically fill in addresses from the host.
To re-announce a service with an updated service_info, just call
this register function again. No need to call unregister first.
sourcepub fn unregister(&self, fullname: &str) -> Result<Receiver<UnregisterStatus>>
pub fn unregister(&self, fullname: &str) -> Result<Receiver<UnregisterStatus>>
Unregisters a service. This is a graceful shutdown of a service.
Returns a channel receiver that is used to receive the status code of the unregister.
When an error is returned, the caller should retry only when
the error is Error::Again, otherwise should log and move on.
sourcepub fn monitor(&self) -> Result<Receiver<DaemonEvent>>
pub fn monitor(&self) -> Result<Receiver<DaemonEvent>>
Starts to monitor events from the daemon.
Returns a channel Receiver of DaemonEvent.
sourcepub fn shutdown(&self) -> Result<Receiver<DaemonStatus>>
pub fn shutdown(&self) -> Result<Receiver<DaemonStatus>>
Shuts down the daemon thread and returns a channel to receive the status.
When an error is returned, the caller should retry only when
the error is Error::Again, otherwise should log and move on.
sourcepub fn status(&self) -> Result<Receiver<DaemonStatus>>
pub fn status(&self) -> Result<Receiver<DaemonStatus>>
Returns the status of the daemon.
When an error is returned, the caller should retry only when
the error is Error::Again, otherwise should consider the daemon
stopped working and move on.
sourcepub fn get_metrics(&self) -> Result<Receiver<Metrics>>
pub fn get_metrics(&self) -> Result<Receiver<Metrics>>
Returns a channel receiver for the metrics, e.g. input/output counters.
The metrics returned is a snapshot. Hence the caller should call this method repeatedly if they want to monitor the metrics continuously.
sourcepub fn set_service_name_len_max(&self, len_max: u8) -> Result<()>
pub fn set_service_name_len_max(&self, len_max: u8) -> Result<()>
Change the max length allowed for a service name.
As RFC 6763 defines a length max for a service name, a user should not call
this method unless they have to. See SERVICE_NAME_LEN_MAX_DEFAULT.
len_max is capped at an internal limit, which is currently 30.
sourcepub fn enable_interface(&self, if_kind: impl IntoIfKindVec) -> Result<()>
pub fn enable_interface(&self, if_kind: impl IntoIfKindVec) -> Result<()>
Include interfaces that match if_kind for this service daemon.
For example:
daemon.enable_interface("en0")?;sourcepub fn disable_interface(&self, if_kind: impl IntoIfKindVec) -> Result<()>
pub fn disable_interface(&self, if_kind: impl IntoIfKindVec) -> Result<()>
Ignore/exclude interfaces that match if_kind for this daemon.
For example:
daemon.disable_interface(IfKind::IPv6)?;Trait Implementations§
source§impl Clone for ServiceDaemon
impl Clone for ServiceDaemon
source§fn clone(&self) -> ServiceDaemon
fn clone(&self) -> ServiceDaemon
1.6.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ServiceDaemon
impl RefUnwindSafe for ServiceDaemon
impl Send for ServiceDaemon
impl Sync for ServiceDaemon
impl Unpin for ServiceDaemon
impl UnwindSafe for ServiceDaemon
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)