Sends all commands at once and reads responses
 @return [Array] of responses
423634
def sync
      serialized_commands = @commands.map { |c| Protocol.build_command(*c) }
      connection.socket.write(serialized_commands.join)
      Array.new(@commands.size) { connection.read_response }
    ensure
      @commands.clear
    end
768074
def _read_packet(self):
        
        # Grab command, send it and decode response
        cmd = self._commands_to_read.popleft()
        try:
            raw_data = self._interface.read()
            raw_data = bytearray(raw_data)
            decoded_data = cmd.decode_data(raw_data)
        except Exception as exception:
            self._abort_all_transfers(exception)
            raise

        decoded_data = bytearray(decoded_data)
        self._command_response_buf.extend(decoded_data)

        # Attach data to transfers
        pos = 0
        while True:
            size_left = len(self._command_response_buf) - pos
            if size_left == 0:
                # If size left is 0 then the transfer list might
                # be empty, so don't try to access element 0
                break
            transfer = self._transfer_list[0]
            size = transfer.get_data_size()
            if size > size_left:
                break

            self._transfer_list.popleft()
            data = self._command_response_buf[pos:pos + size]
            pos += size
            transfer.add_response(data)

        # Remove used data from _command_response_buf
        if pos > 0:
            self._command_response_buf = self._command_response_buf[pos:]
18431
def get_responses(msg, text)
      message = Slackbotsy::Message.new(self, msg)
      @listeners.map do |listener|
        text.match(listener.regex) do |mdata|
         begin
            message.instance_exec(mdata, *mdata[1..-1], &listener.proc)
          rescue => err # keep running even with a broken script, but report the error
            err
          end
        end
      end
    end
767162
function receive(msg) {
  var requests = [];
  var responses = [];

  if (!this.active) {
    return this;
  }

  // If we got JSON, parse it
  if (typeof msg === 'string') {
    try {
      msg = JSON.parse(msg);
    } catch (e) {
      // The specification doesn't force us to respond in error, ignoring
      return this;
    }
  }

  // If we get a standard single-type batch, dispatch it
  if (msg.constructor === Array) {
    if (msg.length === 0) {
      return this;
    }
    // Hint of request batch
    if (typeof msg[0].method === 'string') {
      requests = msg;
    } else {
      responses = msg;
    }
  } else if (typeof msg === 'object') {
    // Could we be a 'dual-batch' extended message?
    if (
      typeof msg.requests !== 'undefined'
      && typeof msg.responses !== 'undefined'
    ) {
      requests = msg.requests;
      responses = msg.responses;
    } else if (typeof msg.method === 'string') {
      // We're a single request
      requests.push(msg);
    } else {
      // We must be a single response
      responses.push(msg);
    }
  }

  responses.forEach(deliverResponse.bind(this));
  requests.forEach(serveRequest.bind(this));
  return this;
}
683596
def read(self):
        ''''''
        responses = self._read()
        # Determine the number of messages in here and decrement our ready
        # count appropriately
        self.ready -= sum(
            map(int, (r.frame_type == Message.FRAME_TYPE for r in responses)))
        return responses
1304103
def get_all_commands_hash
      without_categories = {}
      category_command_map.each do |category, commands|
        without_categories.merge!(commands)
      end
      command_map.merge(without_categories)
    end
100518
function send_commands(cmds, cb) {
        function callback(value) {
            if (cb) cb(value)
            this.locked = false
        }
        function run() { 
            if (this.locked = cmds.length > 0) send_command(cmds.shift(), (success) => {
                if (success) setTimeout(run, 200);
                else callback(false);
            });
            else callback(true); 
        };
        if(!this.locked) run();
    }
988160
def send_headers
			raise "sent headers already" if @sent_headers
			@sent_headers = true

			fixup_headers

			ary = []
			ary << "HTTP/1.1 #{@status || 200} #{@status_string || '...'}\r\n"
			ary += generate_header_lines(@headers)
			ary << "\r\n"

			send_data ary.join
		end
600283
def command(command_name, *args)
      response_key = "#{command_name}_response".to_sym
      result_key = "#{command_name}_result".to_sym

      message = args.last.is_a?(Hash) ? args.pop : {}
      result = @client.call command_name,
                            cookies: @auth_cookie,
                            message: { :token => @login_token }.merge(message)

      result.hash[:envelope][:body][response_key][result_key]
    end
1069809
def send_sessions
      sessions = []
      counts = @session_counts
      @session_counts = Concurrent::Hash.new(0)
      counts.each do |min, count|
        sessions << {
          :startedAt => min,
          :sessionsStarted => count
        }
      end
      deliver(sessions)
    end
1034587
def respond_to?(m, *args)
      super(m, *args) || @targets.all? { |t| t.respond_to?(m, *args) }
    end
881603
def perform
      http = Net::HTTP.new(uri.host, uri.port)
      http.use_ssl = true
      http.ssl_timeout = @options[:ssl_timeout] unless @options[:ssl_timeout].nil?
      http.open_timeout = @options[:open_timeout] unless @options[:open_timeout].nil?
      http.read_timeout = @options[:read_timeout] unless @options[:read_timeout].nil?

      req = Net::HTTP::Post.new(uri.request_uri, headers)
      req.body = body
      resp = http.request(req)
      verify_response(resp)

      resp
    end
120543
def update_state
      Thread.new do
        Dictionary.commands.each do |zone, commands|
          Dictionary.commands[zone].each do |command, info|
            info[:values].each do |value, _|
              if value == 'QSTN'
                send(Parser.parse(command + "QSTN"))
                # If we send any faster we risk making the stereo drop replies. 
                # A dropped reply is not necessarily indicative of the
                # receiver's failure to receive the command and change state
                # accordingly. In this case, we're only making queries, so we do
                # want to capture every reply.
                sleep DEFAULT_TIMEOUT
              end
            end
          end
        end
      end
    end
207606
def handle_response stdout, stderr, thread
      unless thread.value.success?
        dump = "#{thread.value} \n Stderr: #{stderr.read} \n Stdout: #{stdout.read} \n"
        raise dump
      end
    end
551272
def call(command, params)
      @command = command
      request = Net::HTTP::Get.new(uri.request_uri + "?" + params)
      response = http.request(request)
      Response.new(response.body, response)
    end
974707
def sendall(self, data, flags=0):
        ''''''
        count = len(data)
        while count:
            sent = self.send(data, flags)
            # This could probably be a buffer object
            data = data[sent:]
            count -= sent
736693
def with_output
      super do |out|
        out.puts header
        @queued_write = []
        yield out
        @queued_write.sort.each do |line|
          out.puts(line)
        end
      end
    end