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.



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

def count
  @count
end

#promisesObject (readonly)

Returns the value of attribute promises.



102
103
104
# File 'lib/async/http/protocol/http2/connection.rb', line 102

def promises
  @promises
end

#streamObject (readonly)

Returns the value of attribute stream.



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

def stream
  @stream
end

Instance Method Details

#close(error = nil) ⇒ Object



66
67
68
69
70
# File 'lib/async/http/protocol/http2/connection.rb', line 66

def close(error = nil)
	@reader = nil
	
	super
end

#connected?Boolean

Can we use this connection to make requests?

Returns:

  • (Boolean)


115
116
117
# File 'lib/async/http/protocol/http2/connection.rb', line 115

def connected?
	@stream.connected?
end

#http1?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/async/http/protocol/http2/connection.rb', line 54

def http1?
	false
end

#http2?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/async/http/protocol/http2/connection.rb', line 58

def http2?
	true
end

#initializeObject



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

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



110
111
112
# File 'lib/async/http/protocol/http2/connection.rb', line 110

def multiplex
	self.maximum_concurrent_streams
end

#peerObject



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

def peer
	@stream.io
end

#read_in_background(task: Task.current) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/async/http/protocol/http2/connection.rb', line 85

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.consume_window
				self.read_frame
			end
		rescue EOFError, Errno::ECONNRESET, Errno::EPIPE, Async::Wrapper::Cancelled
			# Ignore.
		ensure
			close($!)
		end
	end
end

#reusable?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/async/http/protocol/http2/connection.rb', line 119

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

#start_connectionObject



62
63
64
# File 'lib/async/http/protocol/http2/connection.rb', line 62

def start_connection
	@reader ||= read_in_background
end

#versionObject



123
124
125
# File 'lib/async/http/protocol/http2/connection.rb', line 123

def version
	VERSION
end

#write_frame(frame) ⇒ Object



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

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

#write_frames(&block) ⇒ Object



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

def write_frames(&block)
	@write_frame_guard.acquire do
		super
	end
end