title: What would be a buffered version of a fifo?
body: <p><strong>Background</strong><BR>I'm playing around with a FIFO and every time I try to write on my fifo it blocks until someone is reading the other side of the fd:</p>
  
  <pre><code>int fd;
  char buffer[100] = {0};
  char * myfifo = "/tmp/myfifo";    
  
  mkfifo(myfifo, 0666);
  printf("What would you like to send?\n");
  fgets(buffer, 100, stdin);
  
  if((fd = open(myfifo, O_WRONLY)) &lt; 0)
      printf("Couldn't open the FIFO for writing!\n");
  else {
      write(fd, buffer, strlen(buffer));
      close(fd);
  </code></pre>
  
  <p>This code works, but it blocks until I read the <code>/tmp/myfifo</code> side and get the data. When I change the code as such:</p>
  
  <pre><code>if((fd = open(myfifo, O_WRONLY | O_NONBLOCK)) &lt; 0)
  </code></pre>
  
  <p>Then the open fails with error <code>No such device or address</code>, unless I have someone sitting blocked on the "read" side.</p>
  
  <p><strong>Analysis</strong>
  As per the <a href="http://linux.die.net/man/7/fifo" rel="nofollow">man page</a> for <code>fifo()</code>:<br>
  <code>The kernel maintains exactly one pipe object for each FIFO special file that is opened by at least one process. The FIFO must be opened on both ends (reading and writing) before data can be passed. Normally, opening the FIFO blocks until the other end is opened also.</code></p>
  
  <p>So this is expected operation.</p>
  
  <p><strong>Question</strong></p>
  
  <p>Based on my experiments, and what I'm reading... I have to <strong>assume</strong> a FIFO is a non-queued, non-buffered mechanism and only works when there is a process sitting and waiting for data.</p>
  
  <p>Is there a different communication mechanism that works in a non-blocked buffered manor, basically a buffered FIFO, or would I have to make my own message storage/notification system for that?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I say I'm "playing around" which is actually pretty descriptive here. I'm trying to learn the ins and outs of the various IPC mechanisms (FIFOs, sockets, and pipes). I'm working towards learning to use <code>select()</code> and understand what can be used to wake up sleeping processes which call select. Reason being it's part of a communications driver I'm analyzing for port to a new platform. <br>
  I excluded this from the original post as it is sort of irrelevant. I'm just trying to make sure I can understand (at the moment) FIFO's, how to use them, the limitations on them, and other IPC mechanism. Hence my original assumption/questions about "better" versions of FIFO that will store data and can be written to without blocking.</p>