mirror of
https://github.com/espressif/esp-idf.git
synced 2025-12-16 04:22:22 +00:00
esp_system, vfs: fix incomplete blocking reads in vfs_cdcacm
Blocking read from cdcacm VFS could return less bytes than requested. This didn’t match the behaviour of other VFS drivers, and higher level code could misbehave.
This commit is contained in:
@@ -125,15 +125,16 @@ static int cdcacm_read_char(void)
|
||||
}
|
||||
}
|
||||
|
||||
static bool cdcacm_data_in_buffer(void)
|
||||
static ssize_t cdcacm_data_length_in_buffer(void)
|
||||
{
|
||||
ssize_t len = esp_usb_console_available_for_read();
|
||||
if (len < 0) {
|
||||
len = 0;
|
||||
}
|
||||
if (s_peek_char != NONE) {
|
||||
return true;
|
||||
len += 1;
|
||||
}
|
||||
if (esp_usb_console_read_available()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return len;
|
||||
}
|
||||
|
||||
/* Push back a character; it will be returned by next call to cdcacm_read_char */
|
||||
@@ -150,7 +151,7 @@ static ssize_t cdcacm_read(int fd, void *data, size_t size)
|
||||
ssize_t received = 0;
|
||||
_lock_acquire_recursive(&s_read_lock);
|
||||
|
||||
while (!cdcacm_data_in_buffer()) {
|
||||
while (cdcacm_data_length_in_buffer() < size) {
|
||||
if (!s_blocking) {
|
||||
errno = EWOULDBLOCK;
|
||||
_lock_release_recursive(&s_read_lock);
|
||||
|
||||
Reference in New Issue
Block a user