diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ef5227fc..33d5d1fbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - HID Host: storage for HID Descriptors is now optional - HCI: support newer AIROC Controller that require Download Mode with ENABLE_AIROC_DOWNLOAD_MODE - Zephyr: provide hal_flash_bank implementation for native flash driver - +- POSIX: support error condition for file descriptors in btstack_run_loop + ### Fixed - GAP: store link key for standard/non-SSP pairing - BENP: emit channel opened with ERROR_CODE_REMOTE_USER_TERMINATED_CONNECTION if connection cannot be set up diff --git a/platform/posix/btstack_run_loop_posix.c b/platform/posix/btstack_run_loop_posix.c index 6aae31688..7c39d0bd5 100644 --- a/platform/posix/btstack_run_loop_posix.c +++ b/platform/posix/btstack_run_loop_posix.c @@ -160,7 +160,8 @@ static uint32_t btstack_run_loop_posix_get_time_ms(void){ static void btstack_run_loop_posix_execute(void) { fd_set descriptors_read; fd_set descriptors_write; - + fd_set descriptors_error; + btstack_linked_list_iterator_t it; struct timeval * timeout; struct timeval tv; @@ -179,6 +180,7 @@ static void btstack_run_loop_posix_execute(void) { // collect FDs FD_ZERO(&descriptors_read); FD_ZERO(&descriptors_write); + FD_ZERO(&descriptors_error); int highest_fd = -1; btstack_linked_list_iterator_init(&it, &btstack_run_loop_base_data_sources); while (btstack_linked_list_iterator_has_next(&it)){ @@ -198,6 +200,13 @@ static void btstack_run_loop_posix_execute(void) { } log_debug("btstack_run_loop_execute adding fd %u for write", ds->source.fd); } + if (ds->flags & DATA_SOURCE_CALLBACK_ERROR){ + FD_SET(ds->source.fd, &descriptors_error); + if (ds->source.fd > highest_fd) { + highest_fd = ds->source.fd; + } + log_debug("btstack_run_loop_execute adding fd %u for error", ds->source.fd); + } } // get next timeout @@ -231,6 +240,11 @@ static void btstack_run_loop_posix_execute(void) { log_debug("btstack_run_loop_posix_execute: process write ds %p with fd %u\n", ds, ds->source.fd); ds->process(ds, DATA_SOURCE_CALLBACK_WRITE); } + if (btstack_run_loop_posix_data_sources_modified) break; + if (FD_ISSET(ds->source.fd, &descriptors_error)) { + log_debug("btstack_run_loop_posix_execute: process error ds %p with fd %u\n", ds, ds->source.fd); + ds->process(ds, DATA_SOURCE_CALLBACK_ERROR); + } } } log_debug("btstack_run_loop_posix_execute: after ds check\n"); diff --git a/src/btstack_run_loop.h b/src/btstack_run_loop.h index 4dd8ed903..7c1408fbd 100644 --- a/src/btstack_run_loop.h +++ b/src/btstack_run_loop.h @@ -75,6 +75,7 @@ typedef enum { DATA_SOURCE_CALLBACK_POLL = 1 << 0, DATA_SOURCE_CALLBACK_READ = 1 << 1, DATA_SOURCE_CALLBACK_WRITE = 1 << 2, + DATA_SOURCE_CALLBACK_ERROR = 1 << 3, } btstack_data_source_callback_type_t; typedef struct btstack_data_source {