This commit is contained in:
azw 2023-11-11 08:29:42 +00:00
parent f90b03aebb
commit bca35ee42c

View File

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