title: How to simulate a blocking send() using WSASend() and IOCP?
body: <p><strong><em>Edit:</strong>
  This question is not necessary, as the <code>WSASend()</code> function can inherently be used in a blocking mode, even if the socket has the overlapped attribute and is associated with a completion port. To use it in a blocking mode: <strong>just don't supply an overlapped structure or a completion routine when calling <code>WSASend()</code></strong>.</em></p>
  
  <hr>
  
  <p>I want to make sure that when I send data, the function will only return when this data has been placed in the send buffer. So this is what I come up with (pseudo code):</p>
  
  <pre><code>void WSASend_Block(char *arr, int length)
  {
      OVERLAPPED overlapped;
      overlapped.hEvent = someEvent;
      int result = WSASend(arr, length, &amp;overlapped);
  
      while(true)
      {
          if (result == 0) // IO operation has been scheduled
          {
              wait(overlapped.hEvent, INFINITE); // block until data is placed into send buffer
              break;
          }
          else
          {
              result = WSASend(arr, length, &amp;overlapped);
          }
      }
  }
  </code></pre>