title: Asynchronous event loop design and issues
body: <p>I'm designing event loop for asynchronous socket IO using epoll/devpoll/kqueue/poll/select (including windows-select).</p>
  
  <p>I have two options of performing, IO operation:</p>
  
  <p><strong>Non-blocking mode, poll on EAGAIN</strong></p>
  
  <ol>
  <li>Set socket to non-blocking mode.</li>
  <li>Read/Write to socket.</li>
  <li>If operation succeeds, post completion notification to event loop. </li>
  <li>If I get EAGAIN, add socket to "select list" and poll socket.</li>
  </ol>
  
  <p><strong>Polling mode: poll and then execute</strong></p>
  
  <ol>
  <li>Add socket to select list and poll it.</li>
  <li>Wait for notification that it is readable writable</li>
  <li>read/write </li>
  <li>Post completion notification to event loop of sucseeds</li>
  </ol>
  
  <p>To me it looks like first would require less system calls when using in normal mode,
  especially for writing to socket (buffers are quite big).
  Also it looks like that it would be possible to reduce the overhead over number of "select"
  executions, especially it is nice when you do not have something that scales well
  as epoll/devpoll/kqueue.</p>
  
  <p><strong>Questions:</strong></p>
  
  <ul>
  <li>Are there any advantages of the second approach?</li>
  <li>Are there any portability issues with non-blocking operations on sockets/file descriptors over numerous operating systems: Linux, FreeBSD, Solaris, MacOSX, Windows.</li>
  </ul>
  
  <p><strong>Notes:</strong> Please do not suggest using existing event-loop/socket-api implementations</p>