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;
}
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::<RefCell::<Self>>,
@ -40,16 +49,11 @@ pub struct App {
im_msgs: Rc::<RefCell::<r9::ListHead::<IMMsgNode>>>,
im_work_msgs: Rc::<RefCell::<r9::ListHead::<IMMsgNode>>>,
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>,
}
#[derive(Deserialize)]
struct Ca {
c: String,
a: String
}
struct AppState {
request: Arc<Mutex<Vec<Arc<Mutex<HttpContext>>>>>,
}
@ -62,15 +66,6 @@ struct 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 {
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::<Ca>::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::<Ca>::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 => {