main
_ 2020-10-27 01:55:47 +00:00
parent 394345cfe2
commit a8caae68c3
2 changed files with 16 additions and 3 deletions

View File

@ -21,9 +21,7 @@ use tokio::{
time::delay_for, time::delay_for,
}; };
mod watcher; use ptth::watcher::Watchers;
use watcher::Watchers;
#[derive (Clone)] #[derive (Clone)]
enum Message { enum Message {
@ -60,6 +58,17 @@ async fn handle_wake (state: Arc <ServerState>)
status_reply (StatusCode::OK, "ok\n") status_reply (StatusCode::OK, "ok\n")
} }
async fn handle_udp_send () -> Response <Body>
{
use tokio::net::UdpSocket;
let mut sock = UdpSocket::bind (SocketAddr::from (([0,0,0,0], 0))).await.unwrap ();
sock.send_to (b"handle_udp_send\n", SocketAddr::from (([127,0,0,1], 9000u16))).await.unwrap ();
status_reply (StatusCode::OK, "ok\n")
}
async fn handle_all (req: Request <Body>, state: Arc <ServerState>) async fn handle_all (req: Request <Body>, state: Arc <ServerState>)
-> Result <Response <Body>, Infallible> -> Result <Response <Body>, Infallible>
{ {
@ -72,6 +81,9 @@ async fn handle_all (req: Request <Body>, state: Arc <ServerState>)
else if uri == "/wake" { else if uri == "/wake" {
Ok (handle_wake (state).await) Ok (handle_wake (state).await)
} }
else if uri == "/udp_send" {
Ok (handle_udp_send ().await)
}
else { else {
Ok (status_reply (StatusCode::OK, "Hi\n")) Ok (status_reply (StatusCode::OK, "Hi\n"))
} }

1
src/lib.rs Normal file
View File

@ -0,0 +1 @@
pub mod watcher;