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.



75
76
77
# File 'lib/async/http/protocol/http2/connection.rb', line 75

def count
  @count
end

#streamObject (readonly)

Returns the value of attribute stream.



44
45
46
# File 'lib/async/http/protocol/http2/connection.rb', line 44

def stream
  @stream
end

Instance Method Details

#closeObject



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

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

#good?Boolean

Can we use this connection to make requests?

Returns:

  • (Boolean)


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

def good?
	@stream.connected?
end

#initializeObject



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

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

#multiplexObject



77
78
79
# File 'lib/async/http/protocol/http2/connection.rb', line 77

def multiplex
	@remote_settings.maximum_concurrent_streams
end

#peerObject



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

def peer
	@stream.io
end

#read_in_background(task: Task.current) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/async/http/protocol/http2/connection.rb', line 54

def read_in_background(task: Task.current)
	task.async do |nested_task|
		nested_task.annotate("#{version} reading data")
		
		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
		rescue
			Async.logger.debug(self) {$!}
		ensure
			stop_connection
		end
	end
end

#reusable?Boolean

Returns:

  • (Boolean)


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

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

#start_connectionObject



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

def start_connection
	@reader ||= read_in_background
end

#stop_connectionObject



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

def stop_connection
	@reader = nil
end

#versionObject



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

def version
	VERSION
end