The implementation of the code at the beginning is as follows:
Void createfifo ()
{
If (mkfifo (primary opath, o_creat | o_excl | o_rdwr) <0) & (errno! = Eexist ))
{
Printf (strerror (errno ));
}
}
Int openfifo ()
{
FD = open (opath, o_rdwr | o_nonblock );
Return FD;
}
I think it is not elegant. After all, two functions need to be called, and another write function is called.
2. Use the correct instructions:
// The mkfifo function has implicitly specified o_creat | o_excl, that is, it either creates a new FIFO or
// An eexist error is returned (if the specified name's FIFO already exists ). If you do not want to create a new FIFO
// Call open instead of mkfifo. To open an existing FIFO or create a new FIFO, you must
// Call mkfifo first and check whether eexist is returned. If this error is returned, call open
// The mkfifo command can also be used to create a FIFO, which can be used in shell scripts or command lines.
Int openfifo (const char * pszw.opath)
{
Int FD =-1;
If (mkfifo (psz1_opath, o_creat | o_excl | o_rdwr) <0) & (errno! = Eexist ))
{
Printf (strerror (errno ));
}
FD = open (pszfifopath, o_rdwr | o_nonblock );
Return FD;
}
Exploring the FIFO Pipeline