Rewriting the FIFO code

Corinna Vinschen
Thu Feb 28 22:23:00 GMT 2019

On Feb 28 21:25, Ken Brown wrote:
> On 1/23/2019 8:05 AM, Corinna Vinschen wrote:
> > On Jan 22 20:44, Ken Brown wrote:
> >> On 12/26/2018 2:03 PM, Corinna Vinschen wrote:
> >>> On Dec 26 14:00, Ken Brown wrote:
> >>>> Thanks for the encouragement, and Happy Holidays to you too.  One question: In
> >>>> the new AF_UNIX socket code you mostly used NT functions, but the existing FIFO
> >>>> code uses Win32 functions.  Do you prefer NT functions for new code?
> >>>
> >>> The NT functions have some advantages over the Win32 functions.
> >>> For instance, WaitNamedPipe is not interruptible, while
> >>> NtFsControlFile(FSCTL_PIPE_WAIT) can be called asynchronously
> >>> and then you can just wait for an event object via cygwait
> >>> (see fhandler_socket_unix::wait_pipe_thread).
> >>>
> >>> So, in theory I'd prefer NT functions, but if you feel uncomfortable
> >>> and just want to implement away, feel free to go ahead with Win32
> >>> functions.
> >>
> >> I've decided to use Win32 functions for now, not because of discomfort but
> >> because it allowed me to use more of the existing code.  I can always change
> >> that later.
> > 
> > Sounds good to me.  Just... can we make the fifo pipes PIPE_NOWAIT, by
> > any chance and make fhandler_fifo a derived class of fhandler_base?
> I'm working on this now and have two questions.
> First, if I make fhandler_fifo derived from fhandler_base, don't I
> have to use NT functions for creating pipes, etc.?  (This isn't a
> problem, but I just want to make sure I understand).  For one thing,
> my understanding is that asynchronous I/O can only be done using
> overlapped I/O or NT functions.  For another thing, fhandler_base uses
> NT functions for I/O, so I think I have to be consistent with that.

For consistency it would be nice, but no, you don't have to use
NT function.  PIPE_NOWAIT is also available via Win32 API.

> Second, fhandler_base_overlapped uses an atomic write buffer.  Is
> there a problem giving that up?  Do I need to find some other way of
> making sure that writes of PIPE_BUF bytes or fewer are atomic?

You can use NOWAIT pipes atomically.  MSDN has a failry nice
description (see under "Wait Mode":


Corinna Vinschen
Cygwin Maintainer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <>

More information about the Cygwin-developers mailing list