I am wondering if there is a Windows equivalent for Linux mkfifo. By equivalent, I mean way of creating files, with st_mode S_IFIFO. Thanks for answers.
A FIFO special file sends data from one process to another so that the receiving process reads the data first-in-first-out (FIFO). A FIFO special file is also called a named pipe, or a FIFO . A FIFO special file can also be shared by a number of processes that were not created by forks.
FIFOs are created using mknod(2), mkfifo(3C), or the mknod(1M) command. They are removed using unlink(2) or the rm(1) command.
When a user process attempts to read from an empty pipe (or FIFO), the following happens: If one end of the pipe is closed, 0 is returned, indicating the end of the file. If the write side of the FIFO has closed, read(2) returns 0 to indicate the end of the file.
A FIFO, also known as a named pipe, is a special file similar to a pipe but with a name on the filesystem. Multiple processes can access this special file for reading and writing like any ordinary file. Thus, the name works only as a reference point for processes that need to use a name in the filesystem.
It should be possible to emulate the mkfifo
behavior to some degree. I have implemented something like that many years ago for OS/2 which is quite similar to WinXX with respect to the file system.
The main restriction is that Windows uses reserved file names for pipes: \\.\pipe\pipename or \\servername\pipe\pipename over the network (which can be very useful). But you will not be able to use arbitrary fifo names directly. The pipe names need the \\.\pipe\ prefix.
However, an application could create a pipe with CreateNamedPipe
with PIPE_ACCESS_DUPLEX
and e.g. a GUID name and create a symbolic link to this pipe in the target directory with DeviceIoControl
/ FSCTL_SET_REPARSE_POINT
. This should be quite close to mkfifo
.
The drawback is that the application that services the pipe must run as long as the pipe instance exists. And, of course, it should clean up the symbolic link on termination. Furthermore it needs to read all data from the pipe and write it back again. Not sure whether this can be implemented with zero copy.
There are some further aspects. E.g. if you want to be able to delete your emulated FIFO you need to track the deletion of the symbolic link and terminate the worker process in this case.
I am sorry, I have no Windows development environment so I can't test this approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With