This is the mail archive of the
cygwin-developers
mailing list for the Cygwin project.
Re: 1.7.8: write fails with EAGAIN
On Mar 7 15:35, Christopher Faylor wrote:
> On Mon, Mar 07, 2011 at 06:31:42PM +0100, Corinna Vinschen wrote:
> > * Write requests of {PIPE_BUF} bytes or less shall not be interleaved
> > with data from other processes doing writes on the same pipe.
> > Writes of greater than {PIPE_BUF} bytes may have data interleaved,
> > on arbitrary boundaries, with writes by other processes, whether or
> > not the O_NONBLOCK flag of the file status flags is set.
> > * If the O_NONBLOCK flag is clear, a write request may cause the
> > thread to block, but on normal completion it shall return nbyte.
> > * If the O_NONBLOCK flag is set, write() requests shall be handled
> > differently, in the following ways:
> > + The write() function shall not block the thread.
> > + A write request for {PIPE_BUF} or fewer bytes shall have the
> > following effect: if there is sufficient space available in
> > the pipe, write() shall transfer all the data and return the
> > number of bytes requested. Otherwise, write() shall transfer
> > no data and return -1 with errno set to [EAGAIN].
> > + A write request for more than {PIPE_BUF} bytes shall cause one
> > of the following:
> > o When at least one byte can be written, transfer what it
> > can and return the number of bytes written. When all data
> > previously written to the pipe is read, it shall transfer
> > at least {PIPE_BUF} bytes.
> > o When no data can be written, transfer no data, and return
> > -1 with errno set to [EAGAIN].
> >
> >So, a blocking write with many bytes is not expected to be atomic
> >anyway, and if the pipe is non-blocking you may write (and return) any
> >number of bytes which happen to fit.
>
> None of the above is really what I was worried about. I was worried
> about preserving non-blocking behavior if possible.
That was why I quoted that text. You can preserve non-blocking
behaviour by never writing more than PIPE_BUF bytes in a single
non-blocking call. A conforming application must be able to deal
with non-blocking writes to return less bytes than given to the
write call.
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Project Co-Leader cygwin AT cygwin DOT com
Red Hat