Class: ZMQMachine::Socket::Req
- Inherits:
-
Object
- Object
- ZMQMachine::Socket::Req
- Includes:
- Base
- Defined in:
- lib/zm/sockets/req.rb
Instance Attribute Summary
Attributes included from Base
#kind, #poll_options, #raw_socket
Instance Method Summary collapse
-
#initialize(context, handler) ⇒ Req
constructor
A new instance of Req.
-
#on_attach(handler) ⇒ Object
Attach a handler to the REQ socket.
-
#send_message(message) ⇒ Object
timeout
is measured in milliseconds; default is 0 (never timeout).
Methods included from Base
#attach, #bind, #connect, #identity, #identity=, #inspect, #resume_read, #resume_write, #send_message_string, #send_messages
Constructor Details
#initialize(context, handler) ⇒ Req
Returns a new instance of Req.
44 45 46 47 48 49 50 |
# File 'lib/zm/sockets/req.rb', line 44 def initialize context, handler @poll_options = ZMQ::POLLOUT @kind = :request super @state = :ready end |
Instance Method Details
#on_attach(handler) ⇒ Object
Attach a handler to the REQ socket.
A REQ socket must alternate between send/recv (i.e. it cannot send twice in a row without an intervening receive). This socket expects its handler
to implement at least the #on_readable method. This method will be called whenever a reply arrives.
For error handling purposes, the handler must also implement #on_readable_error.
63 64 65 66 67 |
# File 'lib/zm/sockets/req.rb', line 63 def on_attach handler raise ArgumentError, "Handler must implement an #on_readable method" unless handler.respond_to? :on_readable raise ArgumentError, "Handler must implement an #on_readable_error method" unless handler.respond_to? :on_readable_error super end |
#send_message(message) ⇒ Object
timeout
is measured in milliseconds; default is 0 (never timeout)
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/zm/sockets/req.rb', line 70 def unless waiting_for_reply? rc = super @state = :waiting_for_reply else rc = -1 end rc end |