You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2017/04/10 11:46:54 UTC
[02/50] incubator-mynewt-core git commit: nimble/att: Use new helpers
for sending error response
nimble/att: Use new helpers for sending error response
This constructs response directly on mbuf reducing number of memcopies.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/b50707b6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b50707b6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b50707b6
Branch: refs/heads/master
Commit: b50707b6a67dd8b4d6b168904b0a4d6b8a79bcf7
Parents: 71a8a47
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 12:52:57 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:16 2017 +0200
----------------------------------------------------------------------
net/nimble/host/src/ble_att_svr.c | 71 +++++++++++++---------------------
1 file changed, 27 insertions(+), 44 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b50707b6/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index 5ca2c87..ac6fa55 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -568,43 +568,26 @@ ble_att_svr_write_handle(uint16_t conn_handle, uint16_t attr_handle,
}
static int
-ble_att_svr_tx_error_rsp(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
- struct os_mbuf *txom, uint8_t req_op,
- uint16_t handle, uint8_t error_code)
+ble_att_svr_tx_error_rsp(uint16_t conn_handle, struct os_mbuf *txom,
+ uint8_t req_op, uint16_t handle, uint8_t error_code)
{
- struct ble_att_error_rsp rsp;
- void *dst;
- int rc;
+ struct ble_att_error_rsp *rsp;
BLE_HS_DBG_ASSERT(error_code != 0);
BLE_HS_DBG_ASSERT(OS_MBUF_PKTLEN(txom) == 0);
- dst = os_mbuf_extend(txom, BLE_ATT_ERROR_RSP_SZ);
- if (dst == NULL) {
- rc = BLE_HS_ENOMEM;
- goto err;
- }
-
- rsp.baep_req_op = req_op;
- rsp.baep_handle = handle;
- rsp.baep_error_code = error_code;
-
- ble_att_error_rsp_write(dst, BLE_ATT_ERROR_RSP_SZ, &rsp);
-
- rc = ble_l2cap_tx(conn, chan, txom);
- txom = NULL;
- if (rc != 0) {
- goto err;
+ rsp = ble_att_cmd_prepare(BLE_ATT_OP_ERROR_RSP, sizeof(*rsp), txom);
+ if (rsp == NULL) {
+ return BLE_HS_ENOMEM;
}
- BLE_ATT_LOG_CMD(1, "error rsp", conn->bhc_handle,
- ble_att_error_rsp_log, &rsp);
+ rsp->baep_req_op = req_op;
+ rsp->baep_handle = htole16(handle);
+ rsp->baep_error_code = error_code;
- return 0;
+ BLE_ATT_LOG_CMD(1, "error rsp", conn_handle, ble_att_error_rsp_log, rsp);
-err:
- os_mbuf_free_chain(txom);
- return rc;
+ return ble_att_tx(conn_handle, txom);
}
/**
@@ -664,26 +647,26 @@ ble_att_svr_tx_rsp(uint16_t conn_handle, int hs_status, struct os_mbuf *om,
if (hs_status != 0) {
err_status = BLE_ATT_ERR_UNLIKELY;
}
- }
+ }
+ }
- if (hs_status != 0) {
- STATS_INC(ble_att_stats, error_rsp_tx);
+ ble_hs_unlock();
- /* Reuse om for error response. */
- if (om == NULL) {
- om = ble_hs_mbuf_l2cap_pkt();
- } else {
- os_mbuf_adj(om, OS_MBUF_PKTLEN(om));
- }
- if (om != NULL) {
- ble_att_svr_tx_error_rsp(conn, chan, om, att_op,
- err_handle, err_status);
- om = NULL;
- }
+ if (hs_status != 0) {
+ STATS_INC(ble_att_stats, error_rsp_tx);
+
+ /* Reuse om for error response. */
+ if (om == NULL) {
+ om = ble_hs_mbuf_l2cap_pkt();
+ } else {
+ os_mbuf_adj(om, OS_MBUF_PKTLEN(om));
+ }
+ if (om != NULL) {
+ ble_att_svr_tx_error_rsp(conn_handle, om, att_op,
+ err_handle, err_status);
+ om = NULL;
}
}
-
- ble_hs_unlock();
}
/* Free mbuf if it was not consumed (i.e., if the send failed). */