windows - Checking if a Socket has closed in C++ -


I have a small application that redirects stdout to another app (usually command prompt or Bash for Windows) is. The problem is that if the connection is interrupted then my process has no idea and it never stops due to this line:

  WaitForSingleObject (childProcess.hThread, INFINITE) < / Code> 

I was thinking of having a loop with something like this:

  while (true) {if (ProcessIsDead (childProcess.hThread)) / / Off socket and exit if (SocketIsDisocnected (hSocket)) // stop process and exit}  

What will I do to complete this? For the process I know that there is a WinPi to get the exit code, but I do not know how the socket has been called without calling (which I can not do)

Note: I agree that the connected socket is communicating over a network link, because I'm not sure how it will be disconnected if it was a local pipe Except one process or other death.

Use the Selection () function in the Socket API to query the reading state of the socket.

  • If the call has been made and a connection is pending, it will be acceptable.
  • Data available to read (OOB data is included if SOOBiILN is enabled)
  • The connection has been closed / reset / ended.

Therefore, if you select () say that the socket is readable, it is safe to recall it, which will give you WSACONNRESET or return 0 bytes if the connection will reset or close down . Select () takes a 'timeout' parameter, which you can set to the appropriate time interval or zero if you want to select the socket position.

Information on the selection () function


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -