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.



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

def count
  @count
end

#promisesObject (readonly)

Returns the value of attribute promises.



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

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



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

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

#connected?Boolean

Can we use this connection to make requests?

Returns:

  • (Boolean)


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

def connected?
	@stream.connected?
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



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

def multiplex
	@remote_settings.maximum_concurrent_streams
end

#peerObject



73
74
75
# File 'lib/async/http/protocol/http2/connection.rb', line 73

def peer
	@stream.io
end

#read_in_background(task: Task.current) ⇒ Object



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

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)


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

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

#start_connectionObject



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

def start_connection
	@reader ||= read_in_background
end

#stop_connection(error) ⇒ Object



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

def stop_connection(error)
	@reader = nil
end

#versionObject



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

def version
	VERSION
end