native refactor done
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
use crate::intf::*;
|
||||
use crate::network_connection::*;
|
||||
use crate::xx::*;
|
||||
use crate::*;
|
||||
@@ -17,38 +16,23 @@ impl ConnectionTable {
|
||||
|
||||
pub fn add_connection(&mut self, conn: NetworkConnection) -> Result<(), String> {
|
||||
let descriptor = conn.connection_descriptor();
|
||||
|
||||
assert_ne!(
|
||||
descriptor.protocol_type(),
|
||||
ProtocolType::UDP,
|
||||
"Only connection oriented protocols go in the table!"
|
||||
);
|
||||
|
||||
if self.conn_by_addr.contains_key(&descriptor) {
|
||||
return Err(format!(
|
||||
"Connection already added to table: {:?}",
|
||||
descriptor
|
||||
));
|
||||
}
|
||||
|
||||
let timestamp = get_timestamp();
|
||||
|
||||
let entry = ConnectionTableEntry {
|
||||
conn,
|
||||
established_time: timestamp,
|
||||
last_message_sent_time: None,
|
||||
last_message_recv_time: None,
|
||||
stopper: Eventual::new(),
|
||||
};
|
||||
let res = self.conn_by_addr.insert(descriptor, entry.clone());
|
||||
let res = self.conn_by_addr.insert(descriptor, conn);
|
||||
assert!(res.is_none());
|
||||
Ok(entry)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_connection(
|
||||
&self,
|
||||
descriptor: &ConnectionDescriptor,
|
||||
) -> Option<ConnectionTableEntry> {
|
||||
pub fn get_connection(&self, descriptor: &ConnectionDescriptor) -> Option<NetworkConnection> {
|
||||
self.conn_by_addr.get(descriptor).cloned()
|
||||
}
|
||||
|
||||
@@ -59,7 +43,7 @@ impl ConnectionTable {
|
||||
pub fn remove_connection(
|
||||
&mut self,
|
||||
descriptor: &ConnectionDescriptor,
|
||||
) -> Result<ConnectionTableEntry, String> {
|
||||
) -> Result<NetworkConnection, String> {
|
||||
self.conn_by_addr
|
||||
.remove(descriptor)
|
||||
.ok_or_else(|| format!("Connection not in table: {:?}", descriptor))
|
||||
|
||||
Reference in New Issue
Block a user