Struct ServiceWatcher
pub struct ServiceWatcher {
socket: AsyncFd<Socket>,
}Expand description
Watches the IPC router for QMI servers that are added or removed.
Services start at different times during boot. Use
ServiceWatcher::wait_for to wait until a service is available before
connecting to it.
§Example
use ql_qmi::{RawClient, ServiceWatcher};
let server = ServiceWatcher::new()?.wait_for(0x401, 1).await?;
let (client, connection) = RawClient::builder(0x401, 1).connect_to(server)?;
tokio::spawn(connection.run());The router queues a message for every change, including every client on
the modem that goes away. Keep reading the watcher with
ServiceWatcher::recv or drop it. Unread messages take up kernel
memory, and on some kernels they keep the device from suspending.
Fields§
§socket: AsyncFd<Socket>Implementations§
§impl ServiceWatcher
impl ServiceWatcher
pub async fn recv(&mut self) -> Result<ServiceEvent, Error>
pub async fn recv(&mut self) -> Result<ServiceEvent, Error>
pub async fn wait_for(
&mut self,
service: u32,
version: u8,
) -> Result<Server, Error>
pub async fn wait_for( &mut self, service: u32, version: u8, ) -> Result<Server, Error>
Waits until a server provides the service and returns it.
Returns immediately if one already does. Drops the changes that were queued before the call, so they can’t report a server that is gone. Repeats the lookup every 30 s, because the router can lose a change when it runs out of memory.
Connecting to the returned server can still fail. The router can list a server for a short time after it has reported its removal.
§Errors
Returns an error if the lookup or receiving fails.
pub async fn wait_for_service<S: Service>(&mut self) -> Result<Server, Error>
pub async fn wait_for_service<S: Service>(&mut self) -> Result<Server, Error>
Waits until a server provides service S and returns it.
Behaves like ServiceWatcher::wait_for otherwise.
§Errors
Returns an error if the lookup or receiving fails.
pub async fn wait_for_instance(
&mut self,
service: u32,
version: u8,
instance_id: u32,
) -> Result<Server, Error>
pub async fn wait_for_instance( &mut self, service: u32, version: u8, instance_id: u32, ) -> Result<Server, Error>
Waits until a server provides this instance of the service and returns it.
Behaves like ServiceWatcher::wait_for otherwise.
§Errors
Returns Error::InstanceNotFound if instance_id doesn’t fit into
24 bits, or an error if the lookup or receiving fails.
pub async fn wait_removed(&mut self, server: Server) -> Result<(), Error>
pub async fn wait_removed(&mut self, server: Server) -> Result<(), Error>
Waits until server goes away.
Returns immediately if it is already gone. Wait for this next to
Connection::run, because the
Connection doesn’t see every server that goes
away. The router reports a hang up to it when the server’s port closes
or the modem restarts, except on EVA for a modem server that was
removed before its port closed. No kernel reports a server that
unregisters but keeps its port. Requests to that server time out.
Repeats the lookup every 30 s, like Self::wait_for.
§Errors
Returns an error if the lookup or receiving fails.