This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

NCS: Bluetooth connection context library

Hello everyone,

currently I'm working with NCS V1.9.1 and I was wondering if it is intentionally that the bt_conn_ctx_count() function always returns the CONFIG_BT_MAX_CONN count?

In my application the "_max_clients" count is not equal the CONFIG_BT_MAX_CONN count and therefore the bt_conn_ctx_count() function is not very useful. My expectation would have been that the function returns the "_max_clients" count after creating the contexts with the BT_CONN_CTX_DEF() macro.

Thanks in advance.

  • It looks like it is intentional and is supposed to give you the array size to be able search the whole index to get the context by id , like below.

    	const size_t contexts = bt_conn_ctx_count(hids_obj->conn_ctx);
    
    	for (size_t i = 0; i < contexts; i++) {
    		const struct bt_conn_ctx *ctx =
    		    bt_conn_ctx_get_by_id(hids_obj->conn_ctx, i);
    
    		if (ctx) {

    Yes, it looks inefficient, memory wise to have fewer max clients and more array space but  do not think this will cause any functional problems in the search for context by Id as the id match will happen before the search hits the tail of the array elements. But yes, this looks like an item for optimization.

  • Hello Susheel,

    thank you for the reply.

    Ok, good to know.

    Best regards,
    David

Related