diff --git a/f9/src/app.rs b/f9/src/app.rs index 7cffc8c..09d94d1 100644 --- a/f9/src/app.rs +++ b/f9/src/app.rs @@ -29,6 +29,15 @@ pub trait UserApp { fn get_http_listen_port(&self) -> i32; } +struct HttpContext { + id: u64, + query_str: String, + add_tick: i64, + handled: bool, + //not_found: bool, + rsp: String +} + #[derive(SharedFromSelf)] pub struct App { _self_wp: Weak::>, @@ -40,16 +49,11 @@ pub struct App { im_msgs: Rc::>>, im_work_msgs: Rc::>>, im_mutex: Mutex, - http_handlers: HashMap>>)>>, + http_handlers: HashMap>, + //http_handlers: HashMap>, webapp_state: Arc::, } -#[derive(Deserialize)] -struct Ca { - c: String, - a: String -} - struct AppState { request: Arc>>>>, } @@ -62,15 +66,6 @@ struct IMMsgNode { entry: Rc::>>, } -struct HttpContext { - id: u64, - query_str: String, - add_tick: i64, - handled: bool, - //not_found: bool, - rsp: String -} - async fn index(data: Data>, req: HttpRequest) -> impl Responder { println!("http.thread.id {:?}", std::thread::current().id()); let context = Arc::new( @@ -242,17 +237,28 @@ impl App { } fn dispatch_httprequest(&mut self) { + #[derive(Deserialize)] + struct Ca { + c: String, + a: String + } { - let v = &mut self.webapp_state.request.lock().unwrap(); - if v.len() > 0 { - let c = v.pop(); - match c { + let pending_list = &mut self.webapp_state.request.lock().unwrap(); + while pending_list.len() > 0 { + match pending_list.pop() { Some(v) => { - let query = web::Query::::from_query(&v.lock().unwrap().query_str).unwrap(); - - println!("c={}&a={}", query.c, query.a); - v.lock().unwrap().rsp = "dsafsf".to_string(); - v.lock().unwrap().handled = true; + let ctx = &mut v.lock().unwrap(); + let req = web::Query::::from_query(&ctx.query_str).unwrap(); + let key = format!("{}${}", &req.c, &req.a); + match self.http_handlers.get_mut(&key) { + Some(v1) => { + (v1)(&ctx); + ctx.handled = true; + } + None => { + //ctx.handled = true; + } + } } None => {