1
This commit is contained in:
parent
89c2cb73ff
commit
40b6747ae8
@ -6,6 +6,7 @@ use r9_macro_derive::Singleton;
|
|||||||
use f9::app::App;
|
use f9::app::App;
|
||||||
use f9::app::HttpContext;
|
use f9::app::HttpContext;
|
||||||
use crate::listener::WsListener;
|
use crate::listener::WsListener;
|
||||||
|
use crate::upstream::UpStreamMgr;
|
||||||
|
|
||||||
#[derive(SharedFromSelf)]
|
#[derive(SharedFromSelf)]
|
||||||
#[derive(Singleton)]
|
#[derive(Singleton)]
|
||||||
@ -38,6 +39,7 @@ impl f9::app::UserApp for UserApp {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
WsListener::instance().borrow_mut().init();
|
WsListener::instance().borrow_mut().init();
|
||||||
|
UpStreamMgr::instance().borrow_mut().init();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self) {
|
fn update(&mut self) {
|
||||||
|
@ -1,3 +1,56 @@
|
|||||||
|
use std::rc::{Rc, Weak};
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::error::Error;
|
||||||
|
use tokio::net::{TcpStream, ToSocketAddrs};
|
||||||
|
use tokio::io::AsyncWriteExt;
|
||||||
|
use tokio::runtime::Runtime;
|
||||||
|
|
||||||
|
use r9_macro::SharedFromSelf;
|
||||||
|
use r9_macro_derive::SharedFromSelf;
|
||||||
|
use r9_macro_derive::Singleton;
|
||||||
|
|
||||||
|
#[derive(SharedFromSelf)]
|
||||||
|
#[derive(Singleton)]
|
||||||
pub struct UpStreamMgr {
|
pub struct UpStreamMgr {
|
||||||
|
_self_wp: Weak::<RefCell::<Self>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn run_app() -> Result<(), Box<dyn Error>> {
|
||||||
|
// Connect to a peer
|
||||||
|
let mut stream = TcpStream::connect("127.0.0.1:8080").await?;
|
||||||
|
|
||||||
|
// Write some data.
|
||||||
|
stream.write_all(b"hello world!").await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UpStreamMgr {
|
||||||
|
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let p = UpStreamMgr{
|
||||||
|
_self_wp: Default::default(),
|
||||||
|
};
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(&mut self) {
|
||||||
|
//let (tx, _) = std::sync::mpsc::channel();
|
||||||
|
|
||||||
|
|
||||||
|
std::thread::spawn(move || {
|
||||||
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||||
|
.worker_threads(4)
|
||||||
|
.thread_name("my-custom-name")
|
||||||
|
.thread_stack_size(3 * 1024 * 1024)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
rt.block_on(async {
|
||||||
|
run_app().await;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user