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