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:
Ivan Grokhotkov
2022-05-17 18:52:49 +02:00
parent 3254f8deae
commit bf10146a15
4 changed files with 18 additions and 26 deletions

View File

@@ -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);