<commit_before>module Cod
  class TcpServer
    def initialize(bind_to)
      @socket = TCPServer.new(*bind_to.split(':'))
      @client_sockets = []
      @round_robin_index = 0
      @messages = Array.new
      @serializer = SimpleSerializer.new
    end
    
    # Receives one object from the channel. 
    #
    # Example: 
    #   channel.get # => object
    #   
    def get(opts={})
      msg, socket = _get(opts)
      return msg
    end
    
    # Receives one object from the channel. Returns a tuple of
    # <message,channel> where channel is a tcp channel that links back to the
    # client that sent message.
    #
    # Using this method, the server can communicate back to its clients
    # individually instead of collectively. 
    #
    # Example: 
    #   msg, chan = server.get_ext
    #   chan.put :answer
    def get_ext(opts={})
      msg, socket = _get(opts)
      return [
        msg, 
        TcpClient.new(socket, @serializer)]
    end
    
    # Closes the channel. 
    #
    def close
      @socket.close
      @client_sockets.each { |io| io.close }
    end

    # Returns an array of IOs that Cod.select should select on. 
    #
    def to_read_fds
      @client_sockets
    end

    # --------------------------------------------------------- service/client
    
    def service
      Service.new(self)
    end
    def client(answers_to)
      Service::Client.new(answers_to, answers_to)
    end

  private
    def _get(opts)
      loop do
        # Check if there are pending connects
        accept_new_connections<commit_msg>. note<commit_after>module Cod
  class TcpServer
    def initialize(bind_to)
      @socket = TCPServer.new(*bind_to.split(':'))
      @client_sockets = []
      @round_robin_index = 0
      @messages = Array.new
      @serializer = SimpleSerializer.new
    end
    
    # Receives one object from the channel. 
    #
    # Example: 
    #   channel.get # => object
    #   
    def get(opts={})
      msg, socket = _get(opts)
      return msg
    end
    
    # Receives one object from the channel. Returns a tuple of
    # <message,channel> where channel is a tcp channel that links back to the
    # client that sent message.
    #
    # Using this method, the server can communicate back to its clients
    # individually instead of collectively. 
    #
    # Example: 
    #   msg, chan = server.get_ext
    #   chan.put :answer
    def get_ext(opts={})
      msg, socket = _get(opts)
      return [
        msg, 
        TcpClient.new(socket, @serializer)]
    end
    
    # Closes the channel. 
    #
    def close
      @socket.close
      @client_sockets.each { |io| io.close }
    end

    # Returns an array of IOs that Cod.select should select on. 
    #
    def to_read_fds
      @client_sockets
    end

    # --------------------------------------------------------- service/client
    
    def service
      Service.new(self)
    end
    # NOTE: It is really more convenient to just construct a Cod.tcp_client 
    # and ask that for a client object. In the case of TCP, this is enough. 
    #
    def client(answers_to)
      Service::Client.new(answers_to, answers_to)
    end

  private
    def _get(opts)
      loop do
        # Check if there are pending connects
        accept_new_connections
{'fraction_non_alphanumeric': 0.11192436718511742, 'fraction_numerical': 0.000609942055504727, 'mean_word_length': 1.8349178910976665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5682123', 'n_tokens_mistral': 1007, 'n_tokens_neox': 965, 'n_words': 298}