Skip to content

Commit 95e4fd4

Browse files
committed
Add eventmachine support
This code was pinched from mvidner#52. The original repo for that PR seems to have been deleted.
1 parent bab904d commit 95e4fd4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/dbus/bus.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ def glibize
235235
end
236236
end
237237

238+
def eventmachinize
239+
require File.join(File.dirname(File.expand_path(__FILE__)), "loop-em")
240+
241+
conn = ::EventMachine.watch(@message_queue.socket, Loop::EventMachine::Reader, self)
242+
conn.notify_readable = true
243+
end
244+
238245
# FIXME: describe the following names, flags and constants.
239246
# See DBus spec for definition
240247
NAME_FLAG_ALLOW_REPLACEMENT = 0x1

lib/dbus/loop-em.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require 'eventmachine'
2+
3+
module DBus
4+
module Loop
5+
module EventMachine
6+
class Reader < ::EventMachine::Connection
7+
def initialize(parent)
8+
@parent = parent
9+
end
10+
11+
def notify_readable
12+
@parent.dispatch_message_queue
13+
rescue EOFError
14+
detach
15+
end
16+
end
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)