OSDN Git Service

rusty-gd: some tidying in acl
authorZach Johnson <zachoverflow@google.com>
Thu, 31 Dec 2020 03:06:18 +0000 (19:06 -0800)
committerZach Johnson <zachoverflow@google.com>
Wed, 20 Jan 2021 00:55:53 +0000 (16:55 -0800)
use short variable names where the usage context is so small it's self
explanatory (a little more go-like)

Bug: 171749953
Tag: #gd-refactor
Test: gd/cert/run --rhost
Change-Id: Iada70c9f33d141e93828c14dcad31057195027bb

gd/rust/acl/src/classic.rs
gd/rust/acl/src/core.rs

index 243d5ff..4c3d739 100644 (file)
@@ -139,8 +139,9 @@ async fn provide_acl_manager(
 ) -> AclManager {
     let (req_tx, mut req_rx) = channel::<Request>(10);
     let (conn_evt_tx, conn_evt_rx) = channel::<Event>(10);
+    let local_rt = rt.clone();
 
-    rt.clone().spawn(async move {
+    local_rt.spawn(async move {
         let connections: Arc<Mutex<HashMap<u16, ConnectionInternal>>> = Arc::new(Mutex::new(HashMap::new()));
         let mut connect_queue: Vec<Address> = Vec::new();
         let mut pending = PendingConnect::None;
index 85bfbc3..d612897 100644 (file)
@@ -127,47 +127,43 @@ async fn provide_acl_dispatch(
                         },
                     }
                 },
-                Some(packet) = consume(&acl.rx) => {
-                    match connections.get_mut(&packet.get_handle()) {
-                        Some(connection) => connection.reassembler.on_packet(packet).await,
-                        None if packet.get_handle() == QCOM_DEBUG_HANDLE => {},
-                        None => info!("no acl for {}", packet.get_handle()),
+                Some(p) = consume(&acl.rx) => {
+                    match connections.get_mut(&p.get_handle()) {
+                        Some(c) => c.reassembler.on_packet(p).await,
+                        None if p.get_handle() == QCOM_DEBUG_HANDLE => {},
+                        None => info!("no acl for {}", p.get_handle()),
                     }
                 },
-                Some(packet) = classic_outbound.next(), if classic_credits > 0 => {
-                    acl.tx.send(packet).await.unwrap();
+                Some(p) = classic_outbound.next(), if classic_credits > 0 => {
+                    acl.tx.send(p).await.unwrap();
                     classic_credits -= 1;
                 },
-                Some(packet) = le_outbound.next(), if le_credits > 0 => {
-                    acl.tx.send(packet).await.unwrap();
+                Some(p) = le_outbound.next(), if le_credits > 0 => {
+                    acl.tx.send(p).await.unwrap();
                     le_credits -= 1;
                 },
                 Some(evt) = evt_rx.recv() => {
                     match evt.specialize() {
                         NumberOfCompletedPackets(evt) => {
-                            for info in evt.get_completed_packets() {
-                                match connections.get(&info.connection_handle) {
-                                    Some(connection) => {
-                                        let credits = info.host_num_of_completed_packets;
-                                        match connection.bt {
-                                            Classic => {
-                                                classic_credits += credits;
-                                                assert!(classic_credits <= controller.acl_buffers);
-                                            },
-                                            Le => {
-                                                le_credits += credits;
-                                                assert!(le_credits <= controller.le_buffers.into());
-                                            },
+                            for entry in evt.get_completed_packets() {
+                                match connections.get(&entry.connection_handle) {
+                                    Some(conn) => {
+                                        let credits = entry.host_num_of_completed_packets;
+                                        match conn.bt {
+                                            Classic => classic_credits += credits,
+                                            Le => le_credits += credits,
                                         }
+                                        assert!(classic_credits <= controller.acl_buffers);
+                                        assert!(le_credits <= controller.le_buffers.into());
                                     },
-                                    None => info!("dropping credits for unknown connection {}", info.connection_handle),
+                                    None => info!("dropping credits for unknown connection {}", entry.connection_handle),
                                 }
                             }
                         },
                         DisconnectionComplete(evt) => {
-                            if let Some(connection) = connections.remove(&evt.get_connection_handle()) {
-                                connection.close_tx.send(()).unwrap();
-                                connection.evt_tx.send(evt.into()).await.unwrap();
+                            if let Some(c) = connections.remove(&evt.get_connection_handle()) {
+                                c.close_tx.send(()).unwrap();
+                                c.evt_tx.send(evt.into()).await.unwrap();
                             }
                         },
                         _ => unimplemented!(),