From 49982575d9e51c919b2751e068547d0718ff28e6 Mon Sep 17 00:00:00 2001 From: Chris Manton Date: Mon, 5 Oct 2020 13:19:24 -0700 Subject: [PATCH] Streamline stack/l2cap/l2c_link::l2c_link_process_num_completed_pkts Towards readable code Bug: 163134718 Tag: #refactor Test: act.py -tc BleCocTest Test: ble paired 2 phones Test: classic paired Bose SoundLink Change-Id: I1d6072e5f526c7f2ac1b3229c2e4bdbcdbf3d083 --- stack/l2cap/l2c_link.cc | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/stack/l2cap/l2c_link.cc b/stack/l2cap/l2c_link.cc index 9a4718c15..034681720 100644 --- a/stack/l2cap/l2c_link.cc +++ b/stack/l2cap/l2c_link.cc @@ -1231,32 +1231,35 @@ void l2c_link_process_num_completed_pkts(uint8_t* p, uint8_t evt_len) { ******************************************************************************/ void l2c_link_segments_xmitted(BT_HDR* p_msg) { uint8_t* p = (uint8_t*)(p_msg + 1) + p_msg->offset; - uint16_t handle; - tL2C_LCB* p_lcb; /* Extract the handle */ + uint16_t handle{HCI_INVALID_HANDLE}; STREAM_TO_UINT16(handle, p); handle = HCID_GET_HANDLE(handle); /* Find the LCB based on the handle */ - p_lcb = l2cu_find_lcb_by_handle(handle); - if (p_lcb == NULL) { - L2CAP_TRACE_WARNING("L2CAP - rcvd segment complete, unknown handle: %d", - handle); + tL2C_LCB* p_lcb = l2cu_find_lcb_by_handle(handle); + if (p_lcb == nullptr) { + LOG_WARN("Received segment complete for unknown connection handle:%d", + handle); osi_free(p_msg); return; } - if (p_lcb->link_state == LST_CONNECTED) { - /* Enqueue the buffer to the head of the transmit queue, and see */ - /* if we can transmit anything more. */ - list_prepend(p_lcb->link_xmit_data_q, p_msg); + if (p_lcb->link_state != LST_CONNECTED) { + LOG_INFO("Received segment complete for unconnected connection handle:%d:", + handle); + osi_free(p_msg); + return; + } - p_lcb->partial_segment_being_sent = false; + /* Enqueue the buffer to the head of the transmit queue, and see */ + /* if we can transmit anything more. */ + list_prepend(p_lcb->link_xmit_data_q, p_msg); - l2c_link_check_send_pkts(p_lcb, 0, NULL); - } else - osi_free(p_msg); + p_lcb->partial_segment_being_sent = false; + + l2c_link_check_send_pkts(p_lcb, 0, NULL); } tBTM_STATUS l2cu_ConnectAclForSecurity(const RawAddress& bd_addr) { -- 2.11.0