serial: break from read after closing

This commit is contained in:
Alexander Vasiljev 2020-10-19 12:24:39 +03:00 committed by David Sidrane
parent 0e431e6bf0
commit d523757d4a

View File

@ -686,6 +686,10 @@ static int uart_close(FAR struct file *filep)
leave_critical_section(flags);
/* Wake up read and poll functions */
uart_datareceived(dev);
/* We need to re-initialize the semaphores if this is the last close
* of the device, as the close might be caused by pthread_cancel() of
* a thread currently blocking on any of them.
@ -854,6 +858,16 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen
break;
}
else if (filep->f_inode == 0)
{
/* File has been closed.
* Descriptor is not valid.
*/
recvd = -EBADFD;
break;
}
/* No... then we would have to wait to get receive some data.
* If the user has specified the O_NONBLOCK option, then do not
* wait.