title: How to detect TCP connection lost?
body: <p>I have crossplatform code I've written at the socket level on Linux and iPhone. It opens nonblocking sockets and connects to a server. Everything works great except sometimes when one of the client/server disconnects it halts exec via SIGPIPE on the other during a recv or send call. </p>
  
  <p>That makes sense. On Linux I can use a flag to indicate to the OS lib not to raise SIGPIPE - then I can sense the error myself and handle it cleanly. That works fine  </p>
  
  <p>However on iPhone OS (and presumably osx which I later care about) there's no flag to indicate not to throw SIGPIPE. I can do signal(SIGPIPE, IGN); which seems to USUALLY stop it, but still sometimes I get it??? (This could be due to where I set that signal handling up - I may only do it on app start and I instead may have to do it every time the app becomes active??)</p>
  
  <p>This all makes me feel like I'm catching the disconnect the wrong way - should I be using select() or friends to sense if a disconnect has occurred?? Specifically how can I do that?</p>