Module: DripDrop::ZMQReadableHandler

Included in:
Mongrel2Handler, ZMQPullHandler, ZMQSubHandler, ZMQXRepHandler, ZMQXReqHandler
Defined in:
lib/dripdrop/handlers/zeromq.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#message_classObject

Returns the value of attribute message_class.



94
95
96
# File 'lib/dripdrop/handlers/zeromq.rb', line 94

def message_class
  @message_class
end

Instance Method Details

#decode_message(msg) ⇒ Object



96
97
98
# File 'lib/dripdrop/handlers/zeromq.rb', line 96

def decode_message(msg)
  @message_class.decode(msg)
end

#on_readable(socket, messages) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/dripdrop/handlers/zeromq.rb', line 100

def on_readable(socket, messages)
  begin
    case @msg_format
    when :raw
      @recv_cbak.call(messages)
    when :dripdrop
      if messages.length > 1
        raise "Expected message in one part for #{self.inspect}, got #{messages.map(&:copy_out_string)}"
      end
      
      body  = messages.shift.copy_out_string
      @recv_cbak.call(decode_message(body))
    else
      raise "Unknown message format '#{@msg_format}'"
    end
  rescue StandardError => e
    handle_error(e)
  end
end