def pop_frames_for_protocol(id)
      pws = protocol_window_size
      queues = @queues[id]

      frames = []
      size = 0

      while size < pws
        frames_added = 0

        %i(priority normal chunked).each do |qn|
          q = queues[qn]

          if !q.empty?
            fs = q.peek.frame_size
            if size + fs <= pws
              frames.push q.deq
              size += fs
              frames_added += 1
            end
          end

          # add no more than two in order to send normal and priority first
          # i.e. next is 'priority' again
          #
          # FIXME: too weird
          #
          break if frames_added == 2
        end

        break if frames_added == 0 # empty queues
      end

      # the following can not be guaranteed, as pws might have been different
      # at the time where packets were framed and added to the queues
      #
      #   frames.map(&:frame_size).sum <= pws
      return frames
    end
def pop_frames_for_protocol(id)
      pws = protocol_window_size
      queues = @queues[id]

      frames = []
      size = 0

      while size < pws
        frames_added = 0

        %i(priority normal chunked).each do |qn|
          q = queues[qn]

          if !q.empty?
            fs = q.peek.frame_size
            if size + fs <= pws
              frames.push q.deq
              size += fs
              frames_added += 1
            end
          end

          # add no more than two in order to send normal and priority first
          # i.e. next is 'priority' again
          #
          # FIXME: too weird
          #
          break if frames_added == 2
        end

        break if frames_added == 0 # empty queues
      end

      # the following can not be guaranteed, as pws might have been different
      # at the time where packets were framed and added to the queues
      #
      #   frames.map(&:frame_size).sum <= pws
      return frames
    end
If priority packet and normal packet exist:
   send up to pws/2 bytes from each (priority first)
 else if priority packet and chunked-frame exist:
   send up to pws/2 bytes from each
 else if normal packet and chunked-frame exist:
   send up to pws/2 bytes from each
 else
   read pws bytes from active buffer

 If there are bytes leftover -- for example, if the bytes sent is < pws,
 then repeat the cycle.