title: How to break out of fgets?
body: <p>I am writing a simple instant messaging client &amp; server to get the handle of socket programming.</p>
  
  <p>My client has two threads:</p>
  
  <ul>
  <li>Thread A has a streaming socket connection with the server and
  performs a readline in a loop, printing out lines of text it receives
  from the server. If the readline returns EOF, the loop exits.</li>
  <li>Thread B listens to keyboard input from the user using fgets in a loop. When the user presses enter, it sends the line to the server (so it can forward it to the other client).</li>
  </ul>
  
  <p>When a user presses Ctrl-D, the client sends a special message to the server saying "the client wants to disconnect" at which point the server closes the connection file descriptor for that user. This causes thread A to exit the loop since the readline function returns EOF. Thread A then closes the connection file descriptor and completes.</p>
  
  <p>Meanwhile, thread B is still listening to keyboard input from the user until they hit enter. Ideally, the fgets would break early and let the user know that the other client disconnected.</p>
  
  <p>Is there anyway to do or do I need to use a different input function or library?</p>