Skip to content

Commit

Permalink
Added multipart string reader
Browse files Browse the repository at this point in the history
Sending and recieving multipart string messages is only supported on XREQ, XREP, Router and Dealer sockets, afaik.
At least i couldn't get it to work with normal REQ, REP sockets.
  • Loading branch information
Asmod4n committed Mar 5, 2014
1 parent 4c2ab1a commit c25bb2f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/celluloid/zmq/sockets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,17 @@ def read(buffer = '')
end
buffer
end

# Read a multipart string message from the socket
def read_multipart(buffer = [])
ZMQ.wait_readable(@socket) if ZMQ.evented?

unless ::ZMQ::Util.resultcode_ok? @socket.recv_strings buffer
raise IOError, "error receiving ZMQ string: #{::ZMQ::Util.error_string}"
end
buffer
end
end
# Multiparts message ?
def_delegator :@socket, :more_parts?
end
Expand All @@ -99,6 +109,8 @@ def read(buffer = '')
module WritableSocket
# Send a message to the socket
def write(*messages)
ZMQ.wait_writable(@socket) if ZMQ.evented?

unless ::ZMQ::Util.resultcode_ok? @socket.send_strings messages.flatten
raise IOError, "error sending 0MQ message: #{::ZMQ::Util.error_string}"
end
Expand Down

0 comments on commit c25bb2f

Please sign in to comment.