Struct mdns_sd::ServiceDaemon

source ·
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

source

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.

source

pub fn browse(&self, service_type: &str) -> Result<Receiver<ServiceEvent>>

Starts browsing for a specific service type.

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.

source

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.

source

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.

source

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.

source

pub fn monitor(&self) -> Result<Receiver<DaemonEvent>>

Starts to monitor events from the daemon.

Returns a channel Receiver of DaemonEvent.

source

pub fn shutdown(&self) -> Result<()>

Shuts down the daemon thread.

When an error is returned, the caller should retry only when the error is Error::Again, otherwise should log and move on.

source

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.

source

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.

Trait Implementations§

source§

impl Clone for ServiceDaemon

source§

fn clone(&self) -> ServiceDaemon

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.