Module: Async::HTTP::Protocol::HTTP2::Connection

Included in:
Client, Server
Defined in:
lib/async/http/protocol/http2/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



97
98
99
# File 'lib/async/http/protocol/http2/connection.rb', line 97

def count
  @count
end

#promisesObject (readonly)

Returns the value of attribute promises.



91
92
93
# File 'lib/async/http/protocol/http2/connection.rb', line 91

def promises
  @promises
end

#streamObject (readonly)

Returns the value of attribute stream.



50
51
52
# File 'lib/async/http/protocol/http2/connection.rb', line 50

def stream
  @stream
end

Instance Method Details

#connected?Boolean

Can we use this connection to make requests?

Returns:

  • (Boolean)


104
105
106
# File 'lib/async/http/protocol/http2/connection.rb', line 104

def connected?
  @stream.connected?
end

#http1?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/async/http/protocol/http2/connection.rb', line 52

def http1?
  false
end

#http2?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/async/http/protocol/http2/connection.rb', line 56

def http2?
  true
end

#initializeObject



40
41
42
43
44
45
46
47
48
# File 'lib/async/http/protocol/http2/connection.rb', line 40

def initialize(*)
  super
  
  @count = 0
  @reader = nil
  
  # Writing multiple frames at the same time can cause odd problems if frames are only partially written. So we use a semaphore to ensure frames are written in their entirety.
  @write_frame_guard = Async::Semaphore.new(1)
end

#multiplexObject



99
100
101
# File 'lib/async/http/protocol/http2/connection.rb', line 99

def multiplex
  @remote_settings.maximum_concurrent_streams
end

#peerObject



93
94
95
# File 'lib/async/http/protocol/http2/connection.rb', line 93

def peer
  @stream.io
end

#read_in_background(task: Task.current) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/async/http/protocol/http2/connection.rb', line 75

def read_in_background(task: Task.current)
  task.async do |nested_task|
    nested_task.annotate("#{version} reading data for #{self.class}")
    
    begin
      while !self.closed?
        self.read_frame
      end
    rescue EOFError, Async::Wrapper::Cancelled
      # Stream closed.
    ensure
      stop_connection($!)
    end
  end
end

#reusable?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/async/http/protocol/http2/connection.rb', line 108

def reusable?
  !(self.closed? || @stream.closed?)
end

#start_connectionObject



60
61
62
# File 'lib/async/http/protocol/http2/connection.rb', line 60

def start_connection
  @reader ||= read_in_background
end

#stop_connection(error) ⇒ Object



64
65
66
# File 'lib/async/http/protocol/http2/connection.rb', line 64

def stop_connection(error)
  @reader = nil
end

#versionObject



112
113
114
# File 'lib/async/http/protocol/http2/connection.rb', line 112

def version
  VERSION
end

#write_frame(frame) ⇒ Object



68
69
70
71
72
73
# File 'lib/async/http/protocol/http2/connection.rb', line 68

def write_frame(frame)
  # We don't want to write multiple frames at the same time.
  @write_frame_guard.acquire do
    super
  end
end