Class: Protocol::HTTP2::Window

Inherits:
Object
  • Object
show all
Defined in:
lib/protocol/http2/window_update_frame.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(capacity = 0xFFFF) ⇒ Window

Returns a new instance of Window.

Parameters:

  • capacity (Integer) (defaults to: 0xFFFF)

    The initial window size, typically from the settings.



27
28
29
30
31
32
33
34
# File 'lib/protocol/http2/window_update_frame.rb', line 27

def initialize(capacity = 0xFFFF)
  # This is the main field required:
  @available = capacity
  
  # These two fields are primarily used for efficiently sending window updates:
  @used = 0
  @capacity = capacity
end

Instance Attribute Details

#availableObject (readonly)

Returns the value of attribute available.



59
60
61
# File 'lib/protocol/http2/window_update_frame.rb', line 59

def available
  @available
end

#capacityObject

Returns the value of attribute capacity.



46
47
48
# File 'lib/protocol/http2/window_update_frame.rb', line 46

def capacity
  @capacity
end

#usedObject (readonly)

Returns the value of attribute used.



45
46
47
# File 'lib/protocol/http2/window_update_frame.rb', line 45

def used
  @used
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/protocol/http2/window_update_frame.rb', line 61

def available?
  @available > 0
end

#consume(amount) ⇒ Object



54
55
56
57
# File 'lib/protocol/http2/window_update_frame.rb', line 54

def consume(amount)
  @available -= amount
  @used += amount
end

#dupObject



36
37
38
# File 'lib/protocol/http2/window_update_frame.rb', line 36

def dup
  return self.class.new(@capacity)
end

#expand(amount) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/protocol/http2/window_update_frame.rb', line 65

def expand(amount)
  @available += amount
  @used -= amount
  
  if @available > MAXIMUM_ALLOWED_WINDOW_SIZE
    raise FlowControlError, "Expanding window by #{amount} caused overflow: #{@available} > #{MAXIMUM_ALLOWED_WINDOW_SIZE}!"
  end
end

#full?Boolean

The window is completely full?

Returns:

  • (Boolean)


41
42
43
# File 'lib/protocol/http2/window_update_frame.rb', line 41

def full?
  @available <= 0
end

#limited?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/protocol/http2/window_update_frame.rb', line 74

def limited?
  @available < (@capacity / 2)
end

#to_sObject



78
79
80
# File 'lib/protocol/http2/window_update_frame.rb', line 78

def to_s
  "\#<Window used=#{@used} available=#{@available} capacity=#{@capacity}>"
end