class Net::SSH::Connection::Session

def dispatch_incoming_packets(raise_disconnect_errors: true)

appropriate. Returns as soon as there are no more pending packets.
Read all pending packets from the connection and dispatch them as
def dispatch_incoming_packets(raise_disconnect_errors: true)
  while packet = transport.poll_message
    raise Net::SSH::Exception, "unexpected response #{packet.type} (#{packet.inspect})" unless MAP.key?(packet.type)
    send(MAP[packet.type], packet)
  end
rescue StandardError
  force_channel_cleanup_on_close if closed?
  raise if raise_disconnect_errors || !$!.is_a?(Net::SSH::Disconnect)
end