This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: Nonblocking UART driver using _write_r - error if no data was written?
- From: MikuslawProxy <mikuslawproxy at gmail dot com>
- To: Freddie Chopin <freddie_chopin at op dot pl>
- Cc: newlib at sourceware dot org
- Date: Wed, 26 Feb 2014 15:33:47 +0100
- Subject: Re: Nonblocking UART driver using _write_r - error if no data was written?
- Authentication-results: sourceware.org; auth=none
- References: <CAMym-+z-1ABKQnJaR_eKDTxqk_+0ZgeGdnq_++efJGTBy6o2yA at mail dot gmail dot com> <CAMym-+wVa4HiMNj_LbriWV1WnroxNuNYPnkAe_K24g7EFiMk0Q at mail dot gmail dot com> <530DD434 dot 1 at op dot pl>
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?