Recovering from a broken TCP socket in Ruby when in gets()

前端 未结 5 785
花落未央
花落未央 2021-01-05 08:40

I\'m reading lines of input on a TCP socket, similar to this:

class Bla  
  def getcmd
    @sock.gets unless @sock.closed?
  end

  def start     
    srv =          


        
5条回答
  •  心在旅途
    2021-01-05 08:59

    If you believe the rdoc for ruby sockets, they don't implement gets. This leads me to believe gets is being provided by a higher level of abstraction (maybe the IO libraries?) and probably isn't aware of socket-specific things like 'connection closed.'

    Try using recvfrom instead of gets

提交回复
热议问题