title: What happens when connection drops in sockets (C)
body: <p>Okay, so this seems like a fairly straight forward issue but I feel that I've read every article on socket programming I can find and have not found a satisfactory answer.  Let me first describe the system I am programming.  I apologize, but I have to be very vague for NDA purposes, but it'll be enough to get my question across.</p>
  
  <p>I'm writing a central multi threaded C server with a thread pool.  There are two types of clients, type A and type B.  There are thousands of each.  Type A are workers which do things for Type B.  Type A is constantly updating information about itself to the server (say, every 15 seconds).  Type B only talks to the server when it needs something done, at which point the server picks out an A client and assigns it the job.  This goes on roughly 24/7, and is very time sensitive.</p>
  
  <p>I've decided to go with a persistent TCP model - this means as soon as B asks for work to be done, the server can immediately send the info over to A, without waiting for the A in question to connect to the server.  Furthermore, if every A is talking to the server every 15 seconds, it would be a lot of overhead to keep establishing connections.</p>
  
  <p>If the A chosen by the server is unavailable, it needs to select a new A as soon as possible because B is very impatient. </p>
  
  <p>My question is, how do I tell if the connection has dropped?  I'm not talking about a socket being closed, but just no longer connected.  For example, B1 wants work done, server selects A1 and sends it the request.  However, someone decides to snip the Ethernet cable.  I can't afford to have the server happily sending data along to A1 until the connection times out minutes later.  Can I ping the client before trying to send it messages or something?  Will that introduce way too much latency?  What can be done?</p>