Class: DBus::MessageQueue
- Inherits:
-
Object
- Object
- DBus::MessageQueue
- Defined in:
- lib/dbus/message_queue.rb
Overview
Constant Summary collapse
- MSG_BUF_SIZE =
The buffer size for messages.
4096
Instance Attribute Summary collapse
-
#socket ⇒ Object
readonly
The socket that is used to connect with the bus.
Instance Method Summary collapse
-
#buffer_from_socket_nonblock ⇒ void
Fill (append) the buffer from data that might be available on the socket.
-
#initialize(address) ⇒ MessageQueue
constructor
A new instance of MessageQueue.
-
#message_from_buffer_nonblock ⇒ Message?
Get and remove one message from the buffer.
-
#pop(non_block = false) ⇒ Message?
One message or nil if unavailable.
- #push(message) ⇒ Object (also: #<<)
Constructor Details
#initialize(address) ⇒ MessageQueue
Returns a new instance of MessageQueue.
19 20 21 22 23 24 |
# File 'lib/dbus/message_queue.rb', line 19 def initialize(address) @address = address @buffer = "" @is_tcp = false connect end |
Instance Attribute Details
#socket ⇒ Object (readonly)
The socket that is used to connect with the bus.
17 18 19 |
# File 'lib/dbus/message_queue.rb', line 17 def socket @socket end |
Instance Method Details
#buffer_from_socket_nonblock ⇒ void
This method returns an undefined value.
Fill (append) the buffer from data that might be available on the socket.
155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/dbus/message_queue.rb', line 155 def buffer_from_socket_nonblock @buffer += @socket.read_nonblock(MSG_BUF_SIZE) rescue EOFError raise # the caller expects it rescue Errno::EAGAIN # fine, would block rescue Exception => e puts "Oops:", e raise if @is_tcp # why? puts "WARNING: read_nonblock failed, falling back to .recv" @buffer += @socket.recv(MSG_BUF_SIZE) end |
#message_from_buffer_nonblock ⇒ Message?
Get and remove one message from the buffer.
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/dbus/message_queue.rb', line 136 def return nil if @buffer.empty? ret = nil begin ret, size = Message.new.unmarshall_buffer(@buffer) @buffer.slice!(0, size) rescue IncompleteBufferException # fall through, let ret remain nil end ret end |
#pop(non_block = false) ⇒ Message?
TODO:
failure modes
Returns one message or nil if unavailable.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dbus/message_queue.rb', line 30 def pop(non_block = false) buffer_from_socket_nonblock = unless non_block # we can block while .nil? r, _d, _d = IO.select([@socket]) if r && r[0] == @socket buffer_from_socket_nonblock = end end end end |
#push(message) ⇒ Object Also known as: <<
46 47 48 |
# File 'lib/dbus/message_queue.rb', line 46 def push() @socket.write(.marshall) end |