VFS: select() on UART should return immediately when data is buffered

This commit is contained in:
Roland Dobai 2018-11-27 12:53:19 +01:00
parent 81231fcc4b
commit 957cf0ab84
2 changed files with 15 additions and 1 deletions

View File

@ -393,6 +393,17 @@ static esp_err_t uart_start_select(int nfds, fd_set *readfds, fd_set *writefds,
FD_ZERO(writefds); FD_ZERO(writefds);
FD_ZERO(exceptfds); FD_ZERO(exceptfds);
for (int i = 0; i < max_fds; ++i) {
if (FD_ISSET(i, _readfds_orig)) {
size_t buffered_size;
if (uart_get_buffered_data_len(i, &buffered_size) == ESP_OK && buffered_size > 0) {
// signalize immediately when data is buffered
FD_SET(i, _readfds);
esp_vfs_select_triggered(_signal_sem);
}
}
}
portEXIT_CRITICAL(uart_get_selectlock()); portEXIT_CRITICAL(uart_get_selectlock());
// s_one_select_lock is not released on successfull exit - will be // s_one_select_lock is not released on successfull exit - will be
// released in uart_end_select() // released in uart_end_select()

View File

@ -66,7 +66,10 @@ static void uart_select_task()
if (FD_ISSET(fd, &rfds)) { if (FD_ISSET(fd, &rfds)) {
char buf; char buf;
if (read(fd, &buf, 1) > 0) { if (read(fd, &buf, 1) > 0) {
ESP_LOGI(TAG, "Received: %c", buf); ESP_LOGI(TAG, "Received: %c", buf);
// Note: Only one character was read even the buffer contains more. The other characters will
// be read one-by-one by subsequent calls to select() which will then return immediately
// without timeout.
} else { } else {
ESP_LOGE(TAG, "UART read error"); ESP_LOGE(TAG, "UART read error");
break; break;