class Puma::MiniSSL::Socket

def read_nonblock(size, *_)

def read_nonblock(size, *_)
  # *_ is to deal with keyword args that were added
  # at some point (and being used in the wild)
  while true
    output = engine_read_all
    return output if output
    data = @socket.read_nonblock(size, exception: false)
    if data == :wait_readable || data == :wait_writable
      # It would make more sense to let @socket.read_nonblock raise
      # EAGAIN if necessary but it seems like it'll misbehave on Windows.
      # I don't have a Windows machine to debug this so I can't explain
      # exactly whats happening in that OS. Please let me know if you
      # find out!
      #
      # In the meantime, we can emulate the correct behavior by
      # capturing :wait_readable & :wait_writable and raising EAGAIN
      # ourselves.
      raise IO::EAGAINWaitReadable
    elsif data.nil?
      raise SSLError.exception "HTTP connection?" if bad_tlsv1_3?
      return nil
    end
    @engine.inject(data)
    output = engine_read_all
    return output if output
    while neg_data = @engine.extract
      @socket.write neg_data
    end
  end
end