Module: DripDrop::ZMQWritableHandler
- Included in:
- ZMQPubHandler, ZMQPushHandler, ZMQXRepHandler, ZMQXReqHandler
- Defined in:
- lib/dripdrop/handlers/zeromq.rb
Instance Method Summary collapse
- #initialize(*args) ⇒ Object
- #on_writable(socket) ⇒ Object
-
#send_message(message) ⇒ Object
Sends a message, accepting either a DripDrop::Message, a hash that looks like a DripDrop::Message (has keys :name, :head, :body), or your own custom messages.
Instance Method Details
#initialize(*args) ⇒ Object
37 38 39 40 |
# File 'lib/dripdrop/handlers/zeromq.rb', line 37 def initialize(*args) super(*args) @send_queue = [] end |
#on_writable(socket) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/dripdrop/handlers/zeromq.rb', line 42 def on_writable(socket) unless @send_queue.empty? = @send_queue.shift num_parts = .length .each_with_index do |part,i| # Set the multi-part flag unless this is the last message multipart_flag = i + 1 < num_parts ? ZMQ::SNDMORE : 0 if part.class == ZMQ::Message socket.send(part, multipart_flag) else if part.class == String socket.send_string(part, multipart_flag) else $stderr.write "Can only send Strings, not #{part.class}: #{part}" if @debug end end end else @connection.deregister_writable end end |
#send_message(message) ⇒ Object
Sends a message, accepting either a DripDrop::Message, a hash that looks like a DripDrop::Message (has keys :name, :head, :body), or your own custom messages. Custom messages should either be a String, or for multipart messages, an Array of String objects.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/dripdrop/handlers/zeromq.rb', line 70 def () = dd_messagify() if .is_a?(DripDrop::Message) @send_queue.push([.encoded]) elsif .class == Array @send_queue.push() else @send_queue.push([]) end @connection.register_writable end |