1
This commit is contained in:
parent
09f31f0964
commit
e7c666c803
@ -5,12 +5,11 @@ use r9_macro_derive::SharedFromSelf;
|
|||||||
use r9_macro_derive::Singleton;
|
use r9_macro_derive::Singleton;
|
||||||
use r9::Queue;
|
use r9::Queue;
|
||||||
use f9::app::App;
|
use f9::app::App;
|
||||||
use f9::app::HttpContext;
|
|
||||||
use crate::listener::WsListener;
|
use crate::listener::WsListener;
|
||||||
use crate::upstream::UpStreamMgr;
|
use crate::upstream::UpStreamMgr;
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
use r9::xtimer::TimerList;
|
use r9::xtimer::TimerList;
|
||||||
//use crate::ss;
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
pub struct DownStreamPack {
|
pub struct DownStreamPack {
|
||||||
pub holder: Option<Rc::<RefCell::<DownStreamPack>>>,
|
pub holder: Option<Rc::<RefCell::<DownStreamPack>>>,
|
||||||
@ -22,12 +21,11 @@ pub struct DownStreamPack {
|
|||||||
unsafe impl Send for DownStreamPack {}
|
unsafe impl Send for DownStreamPack {}
|
||||||
unsafe impl Sync for DownStreamPack {}
|
unsafe impl Sync for DownStreamPack {}
|
||||||
|
|
||||||
#[derive(SharedFromSelf)]
|
|
||||||
#[derive(Singleton)]
|
|
||||||
pub struct UserApp {
|
pub struct UserApp {
|
||||||
_self_wp: Weak::<RefCell::<Self>>,
|
|
||||||
net_msg_queue: Rc::<RefCell::<r9::Queue<DownStreamPack>>>,
|
net_msg_queue: Rc::<RefCell::<r9::Queue<DownStreamPack>>>,
|
||||||
}
|
}
|
||||||
|
unsafe impl Send for UserApp {}
|
||||||
|
unsafe impl Sync for UserApp {}
|
||||||
|
|
||||||
impl f9::app::UserApp for UserApp {
|
impl f9::app::UserApp for UserApp {
|
||||||
|
|
||||||
@ -35,29 +33,12 @@ impl f9::app::UserApp for UserApp {
|
|||||||
return "statserver".to_string();
|
return "statserver".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init(&mut self) {
|
fn init(&self) {
|
||||||
App::instance().borrow_mut().add_http_handler(
|
|
||||||
"Ops$selfChecking".to_string(),
|
|
||||||
Rc::new(RefCell::new(
|
|
||||||
move |ctx: &mut HttpContext| {
|
|
||||||
ctx.rsp = "Ops$selfChecking".to_string();
|
|
||||||
App::instance().borrow_mut().add_http_handler(
|
|
||||||
"Ops$selfChecking3".to_string(),
|
|
||||||
Rc::new(RefCell::new(
|
|
||||||
move |ctx: &mut HttpContext| {
|
|
||||||
ctx.rsp = "Ops$selfChecking3".to_string();
|
|
||||||
}
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
),
|
|
||||||
);
|
|
||||||
WsListener::instance().borrow_mut().init();
|
WsListener::instance().borrow_mut().init();
|
||||||
UpStreamMgr::instance().borrow_mut().init();
|
UpStreamMgr::instance().borrow_mut().init();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self) {
|
fn update(&self) {
|
||||||
self.net_msg_queue.borrow_mut().fetch();
|
self.net_msg_queue.borrow_mut().fetch();
|
||||||
let work_list = self.net_msg_queue.borrow().work_list.lock().unwrap().clone();
|
let work_list = self.net_msg_queue.borrow().work_list.lock().unwrap().clone();
|
||||||
while !work_list.borrow().empty() {
|
while !work_list.borrow().empty() {
|
||||||
@ -68,7 +49,7 @@ impl f9::app::UserApp for UserApp {
|
|||||||
WsListener::instance().borrow().update();
|
WsListener::instance().borrow().update();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uninit(&mut self) {
|
fn uninit(&self) {
|
||||||
WsListener::instance().borrow_mut().uninit();
|
WsListener::instance().borrow_mut().uninit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,8 +59,14 @@ impl f9::app::UserApp for UserApp {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static UserAppInstance: OnceLock<UserApp> = OnceLock::new();
|
||||||
|
|
||||||
impl UserApp {
|
impl UserApp {
|
||||||
|
|
||||||
|
pub fn instance() -> &'static UserApp {
|
||||||
|
return UserAppInstance.get_or_init(|| UserApp::new());
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_down_stream_pack(&self, socket_handle: u16, data: bytes::BytesMut) {
|
pub fn add_down_stream_pack(&self, socket_handle: u16, data: bytes::BytesMut) {
|
||||||
println!("add_down_stream_pack1 len:{0}", data.len());
|
println!("add_down_stream_pack1 len:{0}", data.len());
|
||||||
let node = Rc::new(RefCell::new(DownStreamPack{
|
let node = Rc::new(RefCell::new(DownStreamPack{
|
||||||
@ -95,7 +82,6 @@ impl UserApp {
|
|||||||
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let p = UserApp{
|
let p = UserApp{
|
||||||
_self_wp: Default::default(),
|
|
||||||
net_msg_queue: r9::Queue::<DownStreamPack>::new(),
|
net_msg_queue: r9::Queue::<DownStreamPack>::new(),
|
||||||
};
|
};
|
||||||
return p;
|
return p;
|
||||||
|
@ -114,7 +114,7 @@ impl WsConn {
|
|||||||
println!("recv buf_len:{0}", tmp_bytes.len());
|
println!("recv buf_len:{0}", tmp_bytes.len());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
UserApp::instance().borrow().add_down_stream_pack(self.socket_handle, tmp_bytes);
|
UserApp::instance().add_down_stream_pack(self.socket_handle, tmp_bytes);
|
||||||
}
|
}
|
||||||
offset += (pack_len as usize) + 12;
|
offset += (pack_len as usize) + 12;
|
||||||
}
|
}
|
||||||
|
2
third_party/librust
vendored
2
third_party/librust
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 902db5e1bf1789c5055b0e9015f513a409cac4c6
|
Subproject commit 1e0615b6e7a0b7321a58f508ae745c9fdf3987b1
|
Loading…
x
Reference in New Issue
Block a user