Class: H2::Server

Inherits:
Object
  • Object
show all
Includes:
Celluloid::IO
Defined in:
lib/h2/server.rb,
lib/h2/server/https.rb,
lib/h2/server/stream.rb,
lib/h2/server/connection.rb,
lib/h2/server/push_promise.rb,
lib/h2/server/stream/request.rb,
lib/h2/server/stream/response.rb,
lib/h2/server/stream/event_source.rb

Overview

base H2 server, a Celluoid::IO production

Direct Known Subclasses

HTTP, HTTPS

Defined Under Namespace

Classes: Connection, HTTP, HTTPS, PushPromise, Stream, StreamError

Constant Summary collapse

TCP_DEFAULT_BACKLOG =
100

Instance Method Summary collapse

Constructor Details

#initialize(server, **options, &on_connection) ⇒ Server

Returns a new instance of Server.



19
20
21
22
23
24
25
26
27
# File 'lib/h2/server.rb', line 19

def initialize server, **options, &on_connection
  @server        = server
  @options       = options
  @on_connection = on_connection

  backlog = options.fetch :backlog, TCP_DEFAULT_BACKLOG
  @server.listen backlog
  async.run
end

Instance Method Details

#goaway(connection) ⇒ Object

async goaway



56
57
58
59
# File 'lib/h2/server.rb', line 56

def goaway connection
  sleep 0.25
  connection.parser.goaway unless connection.closed?
end

#handle_connection(socket) ⇒ Object

build a new connection object, run it through the given block, and start reading from the socket if still attached



36
37
38
39
40
# File 'lib/h2/server.rb', line 36

def handle_connection socket
  connection = H2::Server::Connection.new socket: socket, server: self
  @on_connection[connection]
  connection.read if connection.attached?
end

#handle_push_promise(push_promise) ⇒ Object

async push promise



50
51
52
# File 'lib/h2/server.rb', line 50

def handle_push_promise push_promise
  push_promise.keep
end

#handle_stream(stream) ⇒ Object

async stream handling



44
45
46
# File 'lib/h2/server.rb', line 44

def handle_stream stream
  stream.connection.each_stream[stream]
end

#shutdownObject



29
30
31
# File 'lib/h2/server.rb', line 29

def shutdown
  @server.close if @server
end