Wait for a service to reach the desired status, with a timeout.
(
service_handle: SC_HANDLE,
desired: &ServiceStatus,
)
| 862 | |
| 863 | /// Wait for a service to reach the desired status, with a timeout. |
| 864 | unsafe fn wait_for_status( |
| 865 | service_handle: SC_HANDLE, |
| 866 | desired: &ServiceStatus, |
| 867 | ) -> Result<(), ServiceError> { |
| 868 | let start = std::time::Instant::now(); |
| 869 | let timeout = std::time::Duration::from_secs(STATUS_WAIT_TIMEOUT_SECS); |
| 870 | loop { |
| 871 | let current = unsafe { query_status(service_handle)? }; |
| 872 | if current == *desired { |
| 873 | return Ok(()); |
| 874 | } |
| 875 | if start.elapsed() > timeout { |
| 876 | return Err(t!("set.statusTimeout", |
| 877 | expected = desired.to_string(), |
| 878 | actual = current.to_string() |
| 879 | ).to_string().into()); |
| 880 | } |
| 881 | std::thread::sleep(std::time::Duration::from_millis(STATUS_POLL_INTERVAL_MS)); |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | /// Check whether `service` matches all non-`None` fields in `filter`. |
| 886 | fn matches_filter(service: &WindowsService, filter: &WindowsService) -> bool { |
no test coverage detected