This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On Feb 26 15:33, MikuslawProxy wrote:
> 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?

fflush is not required to do that.  From POSIX-1.2008(*):

  The fflush() function shall fail if:

  [EAGAIN]

     [CX] The O_NONBLOCK flag is set for the file descriptor
     underlying stream and the thread would be delayed in the
     write operation.


Corinna

(*) http://pubs.opengroup.org/onlinepubs/009695399/functions/fflush.html

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

Attachment: pgpvfeX_IDpWc.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]