title: Checking if a Socket has closed in C++
body: <p>I have a small application that redirects the stdout/in of an another app (usually command prompt or bash for windows). The problem is that if the connection is interrupted the my process has no idea and it never closes because of this line:</p>
  
  <pre><code>WaitForSingleObject(childProcess.hThread, INFINITE)
  </code></pre>
  
  <p>I was thinking of having a loop with something like this:</p>
  
  <pre><code>while(true)
  {
       if(ProcessIsDead(childProcess.hThread))
        // close socket and exit
      if(SocketIsDisocnnected(hSocket))
      // close process and exit
  
  }
  </code></pre>
  
  <p>What functions would I use to accomplish this? For ProcessIsDead I know there is a winapi for getting the exit code but I don't know how to check if the socket is disconnected without calling recv (which i cant do)</p>