Class: Raptor::Http2::Writer
- Inherits:
-
Object
- Object
- Raptor::Http2::Writer
- Defined in:
- lib/raptor/http2.rb,
sig/generated/raptor/http2.rbs
Overview
Serialises concurrent frame writes on a single HTTP/2 connection so exactly one thread is writing at any moment.
Constant Summary collapse
- IDLE =
:idle
Instance Method Summary collapse
-
#initialize(write_timeout:) ⇒ Writer
constructor
Creates a new Writer.
-
#write_frames(socket, frames) ⇒ void
Writes frames to the socket, coordinating with concurrent writers so that exactly one thread is actively writing at any time.
Constructor Details
Instance Method Details
#write_frames(socket, frames) ⇒ void
This method returns an undefined value.
Writes frames to the socket, coordinating with concurrent writers so that exactly one thread is actively writing at any time.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/raptor/http2.rb', line 44 def write_frames(socket, frames) return if !frames || frames.empty? claimed = false @state.swap do |current| if current.equal?(IDLE) claimed = true frames else claimed = false current + frames end end return unless claimed loop do pending = nil @state.swap do |current| pending = current current.empty? ? IDLE : [] end break if pending.empty? pending.each do |frame| Http.socket_write(socket, frame, timeout: @write_timeout) rescue nil end end end |