<commit_before>module BERTRPC
  class Action
    include Encodes

    def initialize(svc, req, mod, fun, args)
      @svc = svc
      @req = req
      @mod = mod
      @fun = fun
      @args = args
    end

    def execute
      bert_request = encode_ruby_request(t[@req.kind, @mod, @fun, @args])
      bert_response = transaction(bert_request)
      decode_bert_response(bert_response)
    end

    #private

    def write(sock, bert)
      sock.write([bert.length].pack("N"))
      sock.write(bert)
    end

    def read(sock, len, timeout)
      data, size = [], 0
      while size < len
        r, w, e = select([sock], [], [], timeout)
        raise Errno::EAGAIN if r.nil?
        data << sock.recvfrom(len - size)
        size += data.last.size
      end
      data.join ''
    end

    def transaction(bert_request)
      timeout = @svc.timeout
      sock = connect_to(@svc.host, @svc.port, timeout)

      if @req.options
        if @req.options[:cache] && @req.options[:cache][0] == :validation<commit_msg>oops recvfrom returns a [msg, addr] tuple, not a string<commit_after>module BERTRPC
  class Action
    include Encodes

    def initialize(svc, req, mod, fun, args)
      @svc = svc
      @req = req
      @mod = mod
      @fun = fun
      @args = args
    end

    def execute
      bert_request = encode_ruby_request(t[@req.kind, @mod, @fun, @args])
      bert_response = transaction(bert_request)
      decode_bert_response(bert_response)
    end

    #private

    def write(sock, bert)
      sock.write([bert.length].pack("N"))
      sock.write(bert)
    end

    def read(sock, len, timeout)
      data, size = [], 0
      while size < len
        r, w, e = select([sock], [], [], timeout)
        raise Errno::EAGAIN if r.nil?
        msg, sender = sock.recvfrom(len - size)
        size += msg.size
        data << msg
      end
      data.join ''
    end

    def transaction(bert_request)
      timeout = @svc.timeout
      sock = connect_to(@svc.host, @svc.port, timeout)

      if @req.options
        if @req.options[:cache] && @req.options[:cache][0] == :validation
{'fraction_non_alphanumeric': 0.1255969436485196, 'fraction_numerical': 0.0019102196752626551, 'mean_word_length': 2.2280431432973806, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2810021', 'n_tokens_mistral': 700, 'n_tokens_neox': 677, 'n_words': 175}