This commit is contained in:
parent
bef5307f7d
commit
818b13da58
@ -12,6 +12,7 @@ fn main() {
|
||||
mod winserv {
|
||||
use std::ffi::OsString;
|
||||
use std::time::Duration;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use windows_service::{
|
||||
define_windows_service,
|
||||
service::{
|
||||
@ -37,11 +38,13 @@ mod winserv {
|
||||
.unwrap();
|
||||
|
||||
let _ = runtime.block_on(async move {
|
||||
let client = irc_rpc::create_client().await?;
|
||||
let mut client = irc_rpc::create_client().await?;
|
||||
|
||||
let sender = client.sender();
|
||||
|
||||
let mut run = true;
|
||||
let run = Arc::new(Mutex::new(true));
|
||||
|
||||
let r2 = run.clone();
|
||||
|
||||
// The entry point where execution will start on a background thread after a call to
|
||||
// `service_dispatcher::start` from `main`.
|
||||
@ -54,13 +57,13 @@ mod winserv {
|
||||
// Handle stop
|
||||
ServiceControl::Stop => {
|
||||
sender.send_quit("ouch or die").unwrap();
|
||||
run = false;
|
||||
*r2.lock().unwrap() = false;
|
||||
ServiceControlHandlerResult::NoError
|
||||
}
|
||||
|
||||
ServiceControl::Preshutdown => {
|
||||
sender.send_quit("ouch or die").unwrap();
|
||||
run = false;
|
||||
*r2.lock().unwrap() = false;
|
||||
ServiceControlHandlerResult::NoError
|
||||
}
|
||||
|
||||
@ -83,8 +86,8 @@ mod winserv {
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
while run {
|
||||
if let Err(_) = irc_rpc::event_loop(client).await {
|
||||
while *run.lock().unwrap() {
|
||||
if let Err(_) = irc_rpc::event_loop(&mut client).await {
|
||||
//log error
|
||||
}
|
||||
}
|
||||
@ -94,7 +97,7 @@ mod winserv {
|
||||
service_type: SERVICE_TYPE,
|
||||
current_state: ServiceState::Stopped,
|
||||
controls_accepted: ServiceControlAccept::empty(),
|
||||
exit_code: ServiceExitCode::Win32(420),
|
||||
exit_code: ServiceExitCode::Win32(0),
|
||||
checkpoint: 0,
|
||||
wait_hint: Duration::default(),
|
||||
process_id: None,
|
||||
|
@ -11,8 +11,8 @@ pub fn start_loop() -> Result<(), failure::Error> {
|
||||
.unwrap();
|
||||
|
||||
runtime.block_on(async move {
|
||||
let client = create_client().await?;
|
||||
event_loop(client).await
|
||||
let mut client = create_client().await?;
|
||||
event_loop(&mut client).await
|
||||
})
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ pub async fn create_client() -> Result<Client, failure::Error> {
|
||||
.map_err(|x| failure::Error::from(x))
|
||||
}
|
||||
|
||||
pub async fn event_loop(mut client: Client) -> Result<(), failure::Error> {
|
||||
pub async fn event_loop(client: &mut Client) -> Result<(), failure::Error> {
|
||||
// We can also load the Config at runtime via Config::load("path/to/config.toml")
|
||||
|
||||
client.identify()?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user