<commit_before><html>
  <head>
    <style>
      body {
        max-width: 40em;
        margin: 2em;
      }

      a {
        color: inherit;
      }

      a:hover {
        color: red;
      }

      dt { margin-top: 1em; }
      dd { margin-bottom: 1em; }

      table {
        margin: 1em 0;
        padding: 0;
      }

      table th {
        text-align: left;
        padding: 0.2em;
        white-space: nowrap;
      }

      table td {
        padding: 0.2em;
        text-align: left;
        white-space: nowrap;
      }

    </style>
    <title>Asynchronous I/O in Windows for Unix Programmers</title>
  </head>
  <body>
<h1>Asynchronous I/O in Windows for Unix Programmers</h1>

<p><NAME> <EMAIL>

<p>This document assumes you are familiar with how non-blocking socket I/O
is done in Unix.

<p>Windows presents asynchronous and non-blocking I/O differently than in Unix.
The syscall
<a href="http://msdn.microsoft.com/en-us/library/ms740141(v=VS.85).aspx"><code>select()</code>
  is available in Windows</a>.
<code>select</code> processing is O(n) in the number of file descriptors
unlike the modern constant-time multiplexers like epoll which makes it
unacceptable for high-concurrency servers.

<p>
Windows has another way of polling called
<a href="http://msdn.microsoft.com/en-us/library/aa365198(VS.85).aspx">I/O completion ports</a>
(IOCPs). IOCPs are the objects used to poll
<a href="http://msdn.microsoft.com/en-us/library/ms686358(v=vs.85).aspx">overlapped I/O</a>
for completion. IOCP polling is constant time (REF?).
They are similar to the Unix I/O multiplexers
<ul>
  <li> <a
  href="http://en.wikipedia.org/wiki/Kqueue">kqueue</a> on Macintosh and
BSDs,
  <li> <a href="http://en.wikipedia.org/wiki/Epoll">epoll</a>
  on Linux,
  <li> <a
  href="http://developers.sun.com/solaris/articles/event_completion.html">event
  completion ports</a> on Solaris,
  <li> <a href="">poll</a> on modern Unixes, and
  <li> <a
    href="http://www.kernel.org/doc/man-pages/online/pages/man2/select.2.html"><code>select()</code></a>,
  which is available everywhere.
</ul>
The fundamental variation is that in a Unix you generally ask the kernel to
wait for state change in a file descriptor's readability or writablity. With
overlapped I/O and IOCPs the programmers waits for asynchronous function
calls to complete.
For example, instead of waiting for a socket to become writable and then
using <a
  href="http://www.kernel.org/doc/man-pages/online/pages/man2/send.2.html"><code>send(2)</code></a>
on it, as you commonly would do in a Unix, with overlapped I/O you
would rather <a
  href="http://msdn.microsoft.com/en-us/library/ms742203(v=vs.85).aspx"><code>WSASend()</code></a>
the data and then wait for it to have been sent.

<p> Unix non-blocking I/O is not beautiful. A principle abstraction in Unix<commit_msg>iocp-links: clean up introduction<commit_after><html>
  <head>
    <style>
      body {
        max-width: 40em;
        margin: 2em;
      }

      a {
        color: inherit;
      }

      a:hover {
        color: red;
      }

      dt { margin-top: 1em; }
      dd { margin-bottom: 1em; }

      table {
        margin: 1em 0;
        padding: 0;
      }

      table th {
        text-align: left;
        padding: 0.2em;
        white-space: nowrap;
      }

      table td {
        padding: 0.2em;
        text-align: left;
        white-space: nowrap;
      }

    </style>
    <title>Asynchronous I/O in Windows for Unix Programmers</title>
  </head>
  <body>
<h1>Asynchronous I/O in Windows for Unix Programmers</h1>

<p><NAME> <EMAIL>

<p>This document assumes you are familiar with how non-blocking socket I/O
is done in Unix.

<p>The syscall
<a href="http://msdn.microsoft.com/en-us/library/ms740141(v=VS.85).aspx"><code>select</code>
  is available in Windows</a> 
but <code>select</code> processing is O(n) in the number of file descriptors
unlike the modern constant-time multiplexers like epoll which makes select
unacceptable for high-concurrency servers.
This document will describe how high-concurrency programs are
designed in Windows.

<p>
Instead of <a href="http://en.wikipedia.org/wiki/Epoll">epoll</a>
or
<a href="http://en.wikipedia.org/wiki/Kqueue">kqueue</a>,
Windows has its own I/O multiplexer  called
<a href="http://msdn.microsoft.com/en-us/library/aa365198(VS.85).aspx">I/O completion ports</a>
(IOCPs). IOCPs are the objects used to poll
<a href="http://msdn.microsoft.com/en-us/library/ms686358(v=vs.85).aspx">overlapped I/O</a>
for completion. IOCP polling is constant time (REF?).

<p>
The fundamental variation is that in a Unix you generally ask the kernel to
wait for state change in a file descriptor's readability or writablity. With
overlapped I/O and IOCPs the programmers waits for asynchronous function
calls to complete.
For example, instead of waiting for a socket to become writable and then
using <a
  href="http://www.kernel.org/doc/man-pages/online/pages/man2/send.2.html"><code>send(2)</code></a>
on it, as you commonly would do in a Unix, with overlapped I/O you
would rather <a
  href="http://msdn.microsoft.com/en-us/library/ms742203(v=vs.85).aspx"><code>WSASend()</code></a>
the data and then wait for it to have been sent.

<p> Unix non-blocking I/O is not beautiful. A principle abstraction in Unix
{'fraction_non_alphanumeric': 0.12648669057957335, 'fraction_numerical': 0.018878610534264678, 'mean_word_length': 3.1006191950464395, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6109474', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1740, 'n_words': 545}