Class: Raptor::Http2::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/raptor/http2.rb,
sig/generated/raptor/http2.rbs

Overview

Queues concurrent frame writes while the reactor remains the sole owner of the connection socket.

Instance Method Summary collapse

Constructor Details

#initialize(write_timeout:) ⇒ Writer

Creates a new Writer.

Parameters:



36
37
38
39
40
# File 'lib/raptor/http2.rb', line 36

def initialize(write_timeout:)
  @reactor = nil
  @connection_id = nil
  @write_timeout = write_timeout
end

Instance Method Details

#attach(reactor, connection_id) ⇒ void

This method returns an undefined value.

Routes subsequent frame writes through the connection's reactor.

Parameters:

  • reactor (Reactor) —

    the reactor that owns the connection

  • connection_id (Integer) —

    unique connection identifier



49
50
51
52
# File 'lib/raptor/http2.rb', line 49

def attach(reactor, connection_id)
  @reactor = reactor
  @connection_id = connection_id
end

#attach_body(stream_id, body, finished) ⇒ Boolean

Attaches a response body that outlives its application thread.

Parameters:

  • stream_id (Integer) —

    the HTTP/2 stream identifier

  • body (DetachedBody) —

    the response body

  • finished (Proc) —

    called with the close reason

Returns:

  • (Boolean) —

    whether the reactor accepted the body



80
81
82
# File 'lib/raptor/http2.rb', line 80

def attach_body(stream_id, body, finished)
  @reactor.attach_http2_body(@connection_id, stream_id, body, finished)
end

#write_frames(socket, frames) ⇒ void

This method returns an undefined value.

Queues frames for the reactor to write. Before attachment, writes directly so the writer remains usable during connection setup.

Parameters:

  • socket (OpenSSL::SSL::SSLSocket) —

    the connection socket

  • frames (Array<String>, nil) —

    frame bytes to write in order



62
63
64
65
66
67
68
69
70
# File 'lib/raptor/http2.rb', line 62

def write_frames(socket, frames)
  return if !frames || frames.empty?

  if @reactor
    @reactor.write_http2_frames(@connection_id, frames)
  else
    Http.socket_write(socket, frames.join, timeout: @write_timeout) rescue nil
  end
end