Class: Raptor::Http2::Writer
- Inherits:
-
Object
- Object
- Raptor::Http2::Writer
- Defined in:
- lib/raptor/http2.rb,
sig/generated/raptor/http2.rbs
Overview
Lock-free per-connection frame writer.
Serializes concurrent socket writes from multiple stream workers without blocking any of them.
Constant Summary collapse
- IDLE =
:idle
Instance Method Summary collapse
-
#initialize ⇒ 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.
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 74 |
# File 'lib/raptor/http2.rb', line 45 def write_frames(socket, frames) return if frames.nil? || 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| socket.write(frame) rescue nil end end end |