title: Ruby TCPSocket recv blocking and never returning
body: <p>So, I have the following code:</p>
  
  <pre><code>  def LSCPHandler.send_message(message, hostname, port)
  s = TCPSocket.open(hostname, port)
  s.print message
  ret = s.recv(1024)
  s.close 
  LSCPHandler.parse_error(ret)
  return ret  
  </code></pre>
  
  <p>end</p>
  
  <p>Which works just fine, normally. The server I'm talking to returns the response pretty quickly, usually, and all is well.</p>
  
  <p>Then, today, something went wrong with the server. Not my problem, BUT, this resulted in my entire application hanging, waiting for recv to time out. This isn't exactly optimal. </p>
  
  <p>Is there a way to time out recv if I dont' hear something back immediately? I tried looking at the ruby documentation, but it really confuses me(i.e. TCPSocket only implements three methods, none of them open or recv, and it's parent class of Socket doesn't implemente these methods either. And Socket's parent class appears to be Object? I'm throughly confused)</p>