seperating task CONNECT
and ASSOCIATE
count
This commit is contained in:
parent
2c2fc7924b
commit
6cfb00dd81
@ -1,7 +1,4 @@
|
|||||||
use super::{
|
use super::side::{self, Side, SideMarker};
|
||||||
side::{self, Side, SideMarker},
|
|
||||||
TaskRegister,
|
|
||||||
};
|
|
||||||
use crate::protocol::{Authenticate as AuthenticateHeader, Header};
|
use crate::protocol::{Authenticate as AuthenticateHeader, Header};
|
||||||
|
|
||||||
pub struct Authenticate<M>
|
pub struct Authenticate<M>
|
||||||
@ -14,17 +11,15 @@ where
|
|||||||
|
|
||||||
pub struct Tx {
|
pub struct Tx {
|
||||||
header: Header,
|
header: Header,
|
||||||
_task_reg: TaskRegister,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Rx;
|
pub struct Rx;
|
||||||
|
|
||||||
impl Authenticate<side::Tx> {
|
impl Authenticate<side::Tx> {
|
||||||
pub(super) fn new(task_reg: TaskRegister, token: [u8; 8]) -> Self {
|
pub(super) fn new(token: [u8; 8]) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: Side::Tx(Tx {
|
inner: Side::Tx(Tx {
|
||||||
header: Header::Authenticate(AuthenticateHeader::new(token)),
|
header: Header::Authenticate(AuthenticateHeader::new(token)),
|
||||||
_task_reg: task_reg,
|
|
||||||
}),
|
}),
|
||||||
_marker: side::Tx,
|
_marker: side::Tx,
|
||||||
}
|
}
|
||||||
|
@ -36,13 +36,17 @@ impl Connect<side::Tx> {
|
|||||||
|
|
||||||
struct Rx {
|
struct Rx {
|
||||||
addr: Address,
|
addr: Address,
|
||||||
|
_task_reg: TaskRegister,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Connect<side::Rx> {
|
impl Connect<side::Rx> {
|
||||||
pub(super) fn new(header: ConnectHeader) -> Self {
|
pub(super) fn new(task_reg: TaskRegister, header: ConnectHeader) -> Self {
|
||||||
let (addr,) = header.into();
|
let (addr,) = header.into();
|
||||||
Self {
|
Self {
|
||||||
inner: Side::Rx(Rx { addr }),
|
inner: Side::Rx(Rx {
|
||||||
|
addr,
|
||||||
|
_task_reg: task_reg,
|
||||||
|
}),
|
||||||
_marker: side::Rx,
|
_marker: side::Rx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,29 +24,31 @@ pub use self::{
|
|||||||
|
|
||||||
pub struct Connection {
|
pub struct Connection {
|
||||||
udp_sessions: Mutex<UdpSessions>,
|
udp_sessions: Mutex<UdpSessions>,
|
||||||
local_active_task_count: ActiveTaskCount,
|
task_connect_count: TaskCount,
|
||||||
|
task_associate_count: TaskCount,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let local_active_task_count = ActiveTaskCount::new();
|
let task_associate_count = TaskCount::new();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
udp_sessions: Mutex::new(UdpSessions::new(local_active_task_count.clone())),
|
udp_sessions: Mutex::new(UdpSessions::new(task_associate_count.clone())),
|
||||||
local_active_task_count,
|
task_connect_count: TaskCount::new(),
|
||||||
|
task_associate_count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_authenticate(&self, token: [u8; 8]) -> Authenticate<side::Tx> {
|
pub fn send_authenticate(&self, token: [u8; 8]) -> Authenticate<side::Tx> {
|
||||||
Authenticate::new(self.local_active_task_count.reg(), token)
|
Authenticate::new(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_connect(&self, addr: Address) -> Connect<side::Tx> {
|
pub fn send_connect(&self, addr: Address) -> Connect<side::Tx> {
|
||||||
Connect::<side::Tx>::new(self.local_active_task_count.reg(), addr)
|
Connect::<side::Tx>::new(self.task_connect_count.reg(), addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn recv_connect(&self, header: ConnectHeader) -> Connect<side::Rx> {
|
pub fn recv_connect(&self, header: ConnectHeader) -> Connect<side::Rx> {
|
||||||
Connect::<side::Rx>::new(header)
|
Connect::<side::Rx>::new(self.task_connect_count.reg(), header)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_packet(
|
pub fn send_packet(
|
||||||
@ -66,16 +68,20 @@ impl Connection {
|
|||||||
Heartbeat::new()
|
Heartbeat::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn local_active_task_count(&self) -> usize {
|
pub fn task_connect_count(&self) -> usize {
|
||||||
self.local_active_task_count.get()
|
self.task_connect_count.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn task_associate_count(&self) -> usize {
|
||||||
|
self.task_associate_count.get()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct ActiveTaskCount(Arc<()>);
|
struct TaskCount(Arc<()>);
|
||||||
struct TaskRegister(Weak<()>);
|
struct TaskRegister(Weak<()>);
|
||||||
|
|
||||||
impl ActiveTaskCount {
|
impl TaskCount {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self(Arc::new(()))
|
Self(Arc::new(()))
|
||||||
}
|
}
|
||||||
@ -91,21 +97,21 @@ impl ActiveTaskCount {
|
|||||||
|
|
||||||
struct UdpSessions {
|
struct UdpSessions {
|
||||||
sessions: HashMap<u16, UdpSession>,
|
sessions: HashMap<u16, UdpSession>,
|
||||||
local_active_task_count: ActiveTaskCount,
|
task_associate_count: TaskCount,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UdpSessions {
|
impl UdpSessions {
|
||||||
fn new(local_active_task_count: ActiveTaskCount) -> Self {
|
fn new(task_associate_count: TaskCount) -> Self {
|
||||||
Self {
|
Self {
|
||||||
sessions: HashMap::new(),
|
sessions: HashMap::new(),
|
||||||
local_active_task_count,
|
task_associate_count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send<'a>(&mut self, assoc_id: u16, addr: Address, max_pkt_size: usize) -> Packet<side::Tx> {
|
fn send<'a>(&mut self, assoc_id: u16, addr: Address, max_pkt_size: usize) -> Packet<side::Tx> {
|
||||||
self.sessions
|
self.sessions
|
||||||
.entry(assoc_id)
|
.entry(assoc_id)
|
||||||
.or_insert_with(|| UdpSession::new(self.local_active_task_count.reg()))
|
.or_insert_with(|| UdpSession::new(self.task_associate_count.reg()))
|
||||||
.send(assoc_id, addr, max_pkt_size)
|
.send(assoc_id, addr, max_pkt_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user