Class: Libevent::Builder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ 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

#baseObject (readonly)

Returns the value of attribute base



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

def base
  @base
end

Instance Method Details

#dispatchObject

Start event base loop



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

def dispatch
  base.dispatch
end

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

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

Yields:

  • (http)


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

#signal(name, &block) ⇒ Object

Trap signal using event base



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

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