Module: EventMachine
- Defined in:
- lib/revem.rb
Defined Under Namespace
Classes: CallsBackToEM, Connection, OneShotEMTimer
Class Method Summary collapse
-
.add_timer(interval, proc = nil, &block) ⇒ Object
ltodo: use Rev’s PeriodicTimer to wrap EM’s two similar to it todo: close all connections on ‘stop’, I believe.
- .cancel_timer(t) ⇒ Object
-
.connect(addr, port, handler = Connection, *args) {|conn| ... } ⇒ Object
Make an outgoing connection.
-
.epoll ⇒ Object
Compatibility noop.
-
.kqueue ⇒ Object
Compatibility noop.
-
.run ⇒ Object
Start the Reactor loop.
-
.set_comm_inactivity_timeout(*args) ⇒ Object
TODO.
-
.set_descriptor_table_size(nfds) ⇒ Object
Set the maximum number of descriptors available to this process.
-
.start_server(addr, port, handler = Connection, *args, &block) ⇒ Object
Start a TCP server on the given address and port.
-
.stop_event_loop ⇒ Object
Stop the Reactor loop.
- .stop_server(server) ⇒ Object
Class Method Details
.add_timer(interval, proc = nil, &block) ⇒ Object
ltodo: use Rev’s PeriodicTimer to wrap EM’s two similar to it todo: close all connections on ‘stop’, I believe
51 52 53 54 55 56 57 |
# File 'lib/revem.rb', line 51 def add_timer interval, proc = nil, &block block ||= proc t = OneShotEMTimer.new(interval, false) # non repeating t.setup(block) t.attach(Rev::Loop.default) # fire 'er off ltodo: do we keep track of these timers in memory? t end |
.cancel_timer(t) ⇒ Object
59 60 61 |
# File 'lib/revem.rb', line 59 def cancel_timer t t.detach if t.attached? # guess there's a case where EM you can say 'cancel' but it's already fired? kind of odd but it happens end |
.connect(addr, port, handler = Connection, *args) {|conn| ... } ⇒ Object
Make an outgoing connection
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/revem.rb', line 66 def connect(addr, port, handler = Connection, *args, &block) block = args.pop if Proc === args[-1] # make sure we're a 'real' class here klass = if (handler and handler.is_a?(Class)) handler else Class.new( Connection ) {handler and include handler} end wrapped_child = CallsBackToEM.connect(addr, port, *args) # ltodo: args? what? they're used? also TODOC TODO FIX conn = klass.new(wrapped_child) # ltodo [?] addr, port, *args) wrapped_child.attach(Rev::Loop.default) # necessary conn.heres_your_socket(wrapped_child) wrapped_child.call_back_to_this(conn) # calls post_init for us yield conn if block_given? end |
.epoll ⇒ Object
Compatibility noop. Handled automatically by libev
113 |
# File 'lib/revem.rb', line 113 def epoll; end |
.kqueue ⇒ Object
Compatibility noop. Handled automatically by libev
116 |
# File 'lib/revem.rb', line 116 def kqueue; end |
.run ⇒ Object
Start the Reactor loop
28 29 30 31 |
# File 'lib/revem.rb', line 28 def run yield if block_given? Rev::Loop.default.run end |
.set_comm_inactivity_timeout(*args) ⇒ Object
TODO
63 |
# File 'lib/revem.rb', line 63 def set_comm_inactivity_timeout *args; end |
.set_descriptor_table_size(nfds) ⇒ Object
Set the maximum number of descriptors available to this process
108 109 110 |
# File 'lib/revem.rb', line 108 def set_descriptor_table_size(nfds) Rev::Utils.maxfds = nfds end |
.start_server(addr, port, handler = Connection, *args, &block) ⇒ Object
Start a TCP server on the given address and port
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/revem.rb', line 85 def start_server(addr, port, handler = Connection, *args, &block) # make sure we're a 'real' class here klass = if (handler and handler.is_a?(Class)) handler else Class.new( Connection ) {handler and include handler} end server = Rev::TCPServer.new(addr, port, CallsBackToEM, *args) { |wrapped_child| conn = klass.new(wrapped_child) conn.heres_your_socket(wrapped_child) # ideally NOT have this :) wrapped_child.call_back_to_this(conn) block.call(conn) if block } server.attach(Rev::Loop.default) end |
.stop_event_loop ⇒ Object
Stop the Reactor loop
34 35 36 |
# File 'lib/revem.rb', line 34 def stop_event_loop Rev::Loop.default.stop end |
.stop_server(server) ⇒ Object
103 104 105 |
# File 'lib/revem.rb', line 103 def stop_server server server.close end |