'Server' program side:
#define RESP_FIFO_NAME "response" /* Global Variables */ char *cmdfifo = CMD_FIFO_NAME; /* Name of command FIFO. */ char *respfifo = RESP_FIFO_NAME; /* Name of response FIFO. */ int main(int argc, char* argv[]) { int infd, outfd; /* FIFO file descriptors. */ ... // blah blah other code here /* Create command FIFO. */ if (mkfifo(cmdfifo, FIFO_MODE) == -1) { if (errno != EEXIST) { fprintf(stderr, "Server: Couldn’t create %s FIFO.\n", CMD_FIFO_NAME); exit(1); } } /* Create response FIFO. */ if (mkfifo(respfifo, FIFO_MODE) == -1) { if (errno != EEXIST) { fprintf(stderr, "Server: Couldn’t create %s FIFO.\n", RESP_FIFO_NAME); exit(1); } } /* Open the command FIFO for non-blocking reading. */ if ((infd = open(cmdfifo, O_RDONLY | O_NONBLOCK)) == -1) { fprintf(stderr, "Server: Failed to open %s FIFO.\n", CMD_FIFO_NAME); exit(1); } /* Open the response FIFO for non-blocking writes. */ if ((outfd = open(respfifo, O_WRONLY | O_NONBLOCK)) == -1) { fprintf(stderr, "Server: Failed to open %s FIFO.\n", RESP_FIFO_NAME); perror(RESP_FIFO_NAME); exit(1); } The program prints an output of:
Server: Couldn’t create response FIFO. I understand very little on FIFOs as my professor didn't teach it. This was all I was able to manage from reading his examples and lecture notes. I tried without O_NONBLOCK flag but that just causes the program to hang, so it is required. I don't understand why the read FIFO is fine but the write FIFO fails to open.
mkfifo()call in the error message — sorespfiforather thanRESP_FIFO_NAME. What FIFOs exist in the current directory (of the program when it is run)? Are you sure you want angle brackets included in the FIFO name (or is the error message from a different version of the code)? You could includeerrnoandstrerror(errno)in the output; this would help diagnose what the problem is (EEXIST vs EPERM vs ...).perrororstrerrorto know what is the exact error.RESP_FIFO_NAMEis a preprocessor#define'd macro constant. I will add that now. I assumed it did not matter as it was simply a string literal with direct text replacement. Yeah, I'll use perror right now and see what the actual problem is.perror(RESP_FIFO_NAME)outputs<RESP_FIFO_NAME>: No such device or addresswhich is apparentlyENXIOmkfifo(2)on Mac OS X. Have you done anychdir()operations? I see that dropping the angle brackets doesn't change the result. What isFIFO_MODE? Does the command FIFO already exist?