title: UNIX nonblocking I/O: O_NONBLOCK vs. FIONBIO
body: <p>In every example and discussion I run across in the context of BSD socket programming, it seems that the recommended way to set a file descriptor to nonblocking I/O mode is using the <code>O_NONBLOCK</code> flag to <code>fcntl()</code>, e.g.</p>
  
  <pre><code>int flags = fcntl(fd, F_GETFL, 0);
  fcntl(fd, F_SETFL, flags | O_NONBLOCK);
  </code></pre>
  
  <p>I've been doing network programming in UNIX for over ten years, and have always used the <code>FIONBIO ioctl()</code> call to do this:</p>
  
  <pre><code>int opt = 1;
  ioctl(fd, FIONBIO, &amp;opt);
  </code></pre>
  
  <p>Never really gave much thought to why.  Just learned it that way.  </p>
  
  <p>Does anyone have any commentary on the possible respective merits of one or the other?  I imagine the portability locus differs somewhat, but do not know to what extent as <code>ioctl_list(2)</code> doesn't speak to that aspect of individual <code>ioctl</code> methods.  </p>