title: QTcpSocket - An invalid handle was specified when exting QRunnable
body: <p>This error occurred in this snippet:</p>
  
  <pre><code>void TCPConnectThread::run()
  {
      m_socket = new QTcpSocket();
      m_socket-&gt;setSocketDescriptor(m_fd);
  
      m_socket-&gt;waitForReadyRead(10000);
  
      QString data = m_socket-&gt;readAll();
  
      m_socket-&gt;waitForDisconnected();
  }
  </code></pre>
  
  <p>A little deep in:</p>
  
  <pre><code>if (::WSAIoctl(socketDescriptor, FIONREAD, &amp;dummy, sizeof(dummy), &amp;nbytes,  
  sizeof(nbytes), &amp;sizeWritten, 0,0) == SOCKET_ERROR) &lt;-Exception here
  {
      WS_ERROR_DEBUG(WSAGetLastError());
      return -1;
  }
  </code></pre>
  
  <p>Deeper in:  </p>
  
  <pre><code>if (::getsockopt(d-&gt;socketDescriptor, SOL_SOCKET, 
  SO_ERROR, (char *) &amp;value, &amp;valueSize) == 0) &lt;-Here
  </code></pre>
  
  <p><code>invalid handle</code> exception occurred when exiting the <code>run</code> method.</p>
  
  <p>Here's how I get m_socket:  </p>
  
  <pre><code>m_socket = new QTcpSocket();
  m_socket-&gt;setSocketDescriptor(m_fd);//m_fd is the socket descriptor of another socket
                                      //from another thread
  </code></pre>
  
  <p>Here's the the thread from which <code>m_fd</code> is collected:  </p>
  
  <pre><code>void TCPListenerThread::onNewConnection()
  {
      QTcpSocket *clientSocket = m_tcpServer-&gt;nextPendingConnection();
      int sockfd = clientSocket-&gt;socketDescriptor();
      m_connectThread = new TCPConnectThread(sockfd);
      m_threadPool-&gt;start(m_connectThread);
  }
  </code></pre>
  
  <p>Exception:</p>
  
  <pre><code>Most possible exception at 0x76edf9ea in manager_host.exe:   
  0xC0000008: An invalid handle was specified  
  </code></pre>
  
  <p>How and where may I find this invalid handle ?</p>