Nonblocking UART driver using _write_r - error if no data was written?

MikuslawProxy mikuslawproxy@gmail.com
Wed Feb 26 14:34:00 GMT 2014


On Wed, Feb 26, 2014 at 12:47 PM, Freddie Chopin <freddie_chopin@op.pl> wrote:
> I guess some rationale is here:
>
> http://pubs.opengroup.org/onlinepubs/009695399/functions/write.html
>
>> When attempting to write to a file descriptor (other than a pipe or
>> FIFO) that supports non-blocking writes and cannot accept the data
>> immediately:
>>
>> [...]
>>
>> If the O_NONBLOCK flag is set, write() shall not block the thread. If
>> some data can be written without blocking the thread, write() shall
>> write what it can and return the number of bytes written. Otherwise,
>> it shall return -1 and set errno to [EAGAIN].
>

That makes sense. Thank you for the link.

>
> In your case "no data can be written", so the functions return -1. I've
> recently thought about write()/read() implementations in POSIX and I'm under
> impression that 0 can be returned only if you request a write of 0 bytes. If
> you request to write anything, the only possible return values are -1 if
> nothing was written (errno set to EAGAIN) or a positive value with number of
> bytes written (I'm not considering any actual errors to make it simpler).
>
> Regards,
> FCh
>

By the way, search for EAGAIN in newlib code didn't return anything
interesting in code that would end up with on my target (STM32). Just
define in errno.h and string for that in strerror.c. The rest is in
linux code, but also nothing interesting, I think.

So, is it a bug that we don't check the write for EAGAIN errno, so we
can loop on that in fflush?



More information about the Newlib mailing list