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.



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

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



69
70
71
72
# File 'lib/h2/server.rb', line 69

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



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

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



63
64
65
# File 'lib/h2/server.rb', line 63

def handle_push_promise push_promise
  push_promise.keep
end

#handle_stream(stream) ⇒ Object

async stream handling



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

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

#shutdownObject



42
43
44
# File 'lib/h2/server.rb', line 42

def shutdown
  @server.close if @server
end