nimble/hs: remove recursive call
On esp32, tail call optimization does not exist, which can lead to a
stack overflow.
@@ -481,6 +481,7 @@ ble_hs_conn_timer(void)
int32_t time_diff;
uint16_t conn_handle;
+ for (;;) {
conn_handle = BLE_HS_CONN_HANDLE_NONE;
next_exp_in = BLE_HS_FOREVER;
now = ble_npl_time_get();
@@ -545,18 +546,17 @@ ble_hs_conn_timer(void)
ble_hs_unlock();
- /* If a connection has timed out, terminate it. We need to recursively
- * call this function again to determine when the next timeout is. This
- * is a tail-recursive call, so it should be optimized to execute in the
- * same stack frame.
+ /* If a connection has timed out, terminate it. We need to repeatedly
+ * call this function again to determine when the next timeout is.
*/
if (conn_handle != BLE_HS_CONN_HANDLE_NONE) {
ble_gap_terminate(conn_handle, BLE_ERR_REM_USER_CONN_TERM);
- return ble_hs_conn_timer();
+ continue;
}
return next_exp_in;
}
+}
int
ble_hs_conn_init(void)
