1
This commit is contained in:
parent
9121591702
commit
e6a625ba4e
@ -1,7 +1,51 @@
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
use tokio::runtime::Runtime;
|
||||||
|
use tokio::net::TcpStream;
|
||||||
use r9;
|
use r9;
|
||||||
use crate::common::{DownStreamPack, UpStreamPack};
|
use crate::common::{DownStreamPack, UpStreamPack};
|
||||||
pub struct UpStream {
|
pub struct UpStream {
|
||||||
|
pub instance_id: i32,
|
||||||
|
remote_ip: String,
|
||||||
|
remote_port: i32,
|
||||||
|
last_pong_tick: i64,
|
||||||
|
|
||||||
down_pack_queue: Arc<Mutex::<r9::QueueLock<DownStreamPack>>>,
|
down_pack_queue: Arc<Mutex::<r9::QueueLock<DownStreamPack>>>,
|
||||||
up_pack_queue: Arc<Mutex::<r9::QueueLock<UpStreamPack>>>,
|
up_pack_queue: Arc<Mutex::<r9::QueueLock<UpStreamPack>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl UpStream {
|
||||||
|
|
||||||
|
pub fn new(instance_id: i32, remote_ip: String, remote_port: i32) -> Self {
|
||||||
|
let p = Self{
|
||||||
|
instance_id: instance_id,
|
||||||
|
remote_ip: remote_ip,
|
||||||
|
remote_port: remote_port,
|
||||||
|
last_pong_tick: 0,
|
||||||
|
|
||||||
|
down_pack_queue: r9::QueueLock::<DownStreamPack>::new_ex(),
|
||||||
|
up_pack_queue: r9::QueueLock::<UpStreamPack>::new_ex(),
|
||||||
|
};
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(&self, rt: &tokio::runtime::Runtime) {
|
||||||
|
{
|
||||||
|
//let down_pack_queue = self.down_pack_queue.clone();
|
||||||
|
//let up_pack_queue = self.up_pack_queue.clone();
|
||||||
|
rt.spawn(async move {
|
||||||
|
let mut result = TcpStream::connect("192.168.100.39:7616").await;
|
||||||
|
match result {
|
||||||
|
Ok(v) => {
|
||||||
|
let a = Arc::new(Mutex::new(v));
|
||||||
|
println!("connect ok");
|
||||||
|
//upstream_enter(a, down_pack_queue, up_pack_queue).await;
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
println!("connect err")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,13 +1,16 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
|
use tokio::net::TcpStream;
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
use crate::upstream::UpStream;
|
use crate::upstream::UpStream;
|
||||||
use crate::app::UserApp;
|
use crate::app::UserApp;
|
||||||
|
|
||||||
pub struct UpStreamMgr {
|
pub struct UpStreamMgr {
|
||||||
curr_id: i16,
|
curr_id: i16,
|
||||||
key_hash: HashMap<String, Rc::<UpStream>>,
|
key_hash: Rc::<RefCell::<HashMap<String, Rc::<UpStream>>>>,
|
||||||
id_hash: HashMap<i32, Rc::<UpStream>>,
|
id_hash: Rc::<RefCell::<HashMap<i32, Rc::<UpStream>>>>,
|
||||||
tokio_rt: Runtime,
|
tokio_rt: Runtime,
|
||||||
}
|
}
|
||||||
unsafe impl Send for UpStreamMgr{}
|
unsafe impl Send for UpStreamMgr{}
|
||||||
@ -32,8 +35,10 @@ impl UpStreamMgr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(&self) {
|
pub fn init(&self) {
|
||||||
|
let upstream = Rc::new(UpStream::new(1, "192.168.100.39".to_string(), 7616));
|
||||||
|
self.key_hash.borrow_mut().insert("".to_string(), upstream.clone());
|
||||||
|
self.id_hash.borrow_mut().insert(upstream.instance_id, upstream.clone());
|
||||||
|
upstream.init(&self.tokio_rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uninit(&self) {
|
pub fn uninit(&self) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user