use crate::*;
impl Default for ServerControlHook {
#[inline(always)]
fn default() -> Self {
Self {
wait_hook: Arc::new(|| Box::pin(async {})),
shutdown_hook: Arc::new(|| Box::pin(async {})),
}
}
}
impl ServerControlHook {
pub(crate) fn set_wait_hook(
&mut self,
hook: Arc<dyn Fn() -> SendableAsyncTask<()> + Send + Sync>,
) {
self.wait_hook = hook;
}
pub(crate) fn set_shutdown_hook(
&mut self,
hook: Arc<dyn Fn() -> SendableAsyncTask<()> + Send + Sync>,
) {
self.shutdown_hook = hook;
}
pub fn get_wait_hook(&self) -> Arc<dyn Fn() -> SendableAsyncTask<()> + Send + Sync> {
self.wait_hook.clone()
}
pub fn get_shutdown_hook(&self) -> Arc<dyn Fn() -> SendableAsyncTask<()> + Send + Sync> {
self.shutdown_hook.clone()
}
pub async fn wait(&self) {
(self.get_wait_hook())().await;
}
pub async fn shutdown(&self) {
(self.get_shutdown_hook())().await;
}
}
impl HandlerState {
#[inline(always)]
pub(crate) fn new(socket: ArcRwLockUdpSocket) -> Self {
Self { socket }
}
pub(crate) fn get_socket(&self) -> ArcRwLockUdpSocket {
self.socket.clone()
}
}
impl ServerHook for DefaultServerHook {
async fn new(_ctx: &Context) -> Self {
Self
}
async fn handle(self, _ctx: &Context) {}
}