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.



85
86
87
# File 'lib/async/http/protocol/http2/connection.rb', line 85

def count
  @count
end

#promisesObject (readonly)

Returns the value of attribute promises.



79
80
81
# File 'lib/async/http/protocol/http2/connection.rb', line 79

def promises
  @promises
end

#streamObject (readonly)

Returns the value of attribute stream.



46
47
48
# File 'lib/async/http/protocol/http2/connection.rb', line 46

def stream
  @stream
end

Instance Method Details

#closeObject



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

def close
	Async.logger.debug(self) {"Closing connection"}
	
	@reader.stop if @reader
	
	super
end

#connected?Boolean

Can we use this connection to make requests?

Returns:

  • (Boolean)


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

def connected?
	@stream.connected?
end

#http1?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/async/http/protocol/http2/connection.rb', line 48

def http1?
	false
end

#http2?Boolean

Returns:

  • (Boolean)


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

def http2?
	true
end

#initializeObject



39
40
41
42
43
44
# File 'lib/async/http/protocol/http2/connection.rb', line 39

def initialize(*)
	super
	
	@count = 0
	@reader = nil
end

#multiplexObject



87
88
89
# File 'lib/async/http/protocol/http2/connection.rb', line 87

def multiplex
	@remote_settings.maximum_concurrent_streams
end

#peerObject



81
82
83
# File 'lib/async/http/protocol/http2/connection.rb', line 81

def peer
	@stream.io
end

#read_in_background(task: Task.current) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/async/http/protocol/http2/connection.rb', line 64

def read_in_background(task: Task.current)
	task.async do |nested_task|
		nested_task.annotate("#{version} reading data for #{self.class}")
		
		begin
			# Even thought the connection might be logically closed, we are not done until all HTTP/2 streams are closed or the underlying I/O is closed.
			while !@stream.closed?
				self.read_frame
			end
		ensure
			stop_connection($!)
		end
	end
end

#reusable?Boolean

Returns:

  • (Boolean)


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

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

#start_connectionObject



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

def start_connection
	@reader ||= read_in_background
end

#stop_connection(error) ⇒ Object



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

def stop_connection(error)
	@reader = nil
end

#versionObject



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

def version
	VERSION
end