title: why non-blocking write to disk doesn't return EAGAIN or EWOULDBLOCK?
body: <p>I modified a program from APUE, the program first open a file, then mark the fd as non-blocking, then continue write to the fd until write return -1. </p>
  
  <p>I think since disk I/O is slow, when write buffers in OS is nearly full, the write system call will return -1, and the errno should be EAGAIN or EWOULDBLOCK.</p>
  
  <p>But I ran the program for about several minutes and I repeated running the program serveral times, the write system call didn't returned -1 even once! Why? 
  Here's the code:</p>
  
  <pre><code>#include "apue.h"
  #include &lt;errno.h&gt;
  #include &lt;fcntl.h&gt;
  
  char    buf[4096];
  
  int
  main(void)
  {
          int nwrite;
  
          int fd = open("a.txt", O_RDWR);
          if(fd&lt;0){
              printf("fd&lt;0\n");
              return 0;
          }
          int  i;
          for(i = 0; i&lt;sizeof(buf); i++)
              buf[i] = i*2;
  
          set_fl(fd, O_NONBLOCK); /* set nonblocking */
  
          while (1) {
                  nwrite = write(fd, buf, sizeof(buf));
                  if (nwrite &lt; 0) {
                      printf("write returned:%d, errno=%d\n", nwrite, errno);
                      return 0;
                  }
          }
  
          clr_fl(STDOUT_FILENO, O_NONBLOCK);      /* clear nonblocking */
  
          exit(0);
  }
  </code></pre>