Class: Libevent::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/libevent/builder.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Builder) initialize(options = {}, &block)

A new instance of Builder



3
4
5
6
# File 'lib/libevent/builder.rb', line 3

def initialize(options = {}, &block)
  @base = Base.new
  instance_eval(&block) if block_given?
end

Instance Attribute Details

- (Object) base (readonly)

Returns the value of attribute base



8
9
10
# File 'lib/libevent/builder.rb', line 8

def base
  @base
end

Instance Method Details

- (Object) dispatch

Start event base loop



28
29
30
# File 'lib/libevent/builder.rb', line 28

def dispatch
  base.dispatch
end

- (Http) server(host, port) {|http| ... }

Create new Http instance, bind socket and options yield http object

Parameters:

  • host (String)
  • port (Fixnum)

Yields:

  • (http)

Returns:

  • (Http)

    instance



14
15
16
17
18
19
# File 'lib/libevent/builder.rb', line 14

def server(host, port, &block)
  http = Http.new(@base)
  http.bind_socket(host, port) or raise RuntimeError, "can't bind socket #{host}:#{port}"
  yield(http) if block_given?
  http
end

- (Object) signal(name, &block)

Trap signal using event base

Parameters:

  • name (String)

    a signal name



23
24
25
# File 'lib/libevent/builder.rb', line 23

def signal(name, &block)
  base.trap_signal(name, &block)
end