title: Does QAbstractSocket::waitForDisconnected impose a race condition?
body: <p>Here is the outline of my QThread subclass which is created per-connection by my QTcpServer subclass</p>
  
  <pre><code>void
  Socket :: run ()
  {
      QTcpSocket socket;
  
      if (false == socket .setSocketDescriptor (m_sd))
      {
           error ();
           return;
      }
  
      do_stuff ();
  
      socket .disconnectFromHost ();
      socket .waitForDisconnected ();
  }
  </code></pre>
  
  <p>I am getting this error:</p>
  
  <pre><code>QAbstractSocket::waitForDisconnected() is not allowed in UnconnectedState
  </code></pre>
  
  <p>Huh? This code is lifted from <a href="http://doc.qt.io/qt-5/qtnetwork-threadedfortuneserver-example.html" rel="nofollow">the documentation</a>. Elsewhere I have seen this:</p>
  
  <pre><code>socket .disconnectFromHost ();
  
  if (QAbstractSocket :: ConnectedState == socket .state ())
      socket .waitForDisconnected (); 
  </code></pre>
  
  <p>Isn't this a race condition? If it's not a race condition then it's not an asynchronous process, in that universe <code>disconnectFromHost</code> would always succeed and <code>waitForDisconnected</code> would be redundant. Right?</p>
  
  <p>What is the correct usage of these functions?</p>