Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Convert DCell::Server to the new celluloid-zmq API

  • Loading branch information...
commit e62d0ec8a1d92f4f967fc191e8ec59456aba8ff4 1 parent 958c474
@tarcieri tarcieri authored
Showing with 28 additions and 26 deletions.
  1. +28 −26 lib/celluloid/zmq/sockets.rb
View
54 lib/celluloid/zmq/sockets.rb
@@ -1,34 +1,9 @@
module Celluloid
module ZMQ
- module ReadableSocket
- # Read a message from the socket
- def read(buffer = '')
- Celluloid.current_actor.wait_readable(@socket) if evented?
-
- unless ::ZMQ::Util.resultcode_ok? @socket.recv_string buffer
- raise IOError, "error receiving ZMQ string: #{::ZMQ::Util.error_string}"
- end
- buffer
- end
- end
-
- module WritableSocket
- # Send a message to the socket
- def send(message)
- Celluloid.current_actor.wait_writable(@socket) if evented?
-
- if ::ZMQ::Util.resultcode_ok? socket.send_string message
- raise IOError, "error sending 0MQ message: #{::ZMQ::Util.error_string}"
- end
- message
- end
- alias_method :<<, :send
- end
-
class Socket
# Create a new socket
def initialize(type)
- @socket = Celluloid::ZMQ.context.socket ::ZMQ.const_get(type.to_s.upscase)
+ @socket = Celluloid::ZMQ.context.socket ::ZMQ.const_get(type.to_s.upcase)
unless ::ZMQ::Util.resultcode_ok? @socket.setsockopt(::ZMQ::LINGER, 0)
@socket.close
@@ -67,6 +42,33 @@ def evented?
alias_method :inspect, :to_s
end
+ # Readable 0MQ sockets have a read method
+ module ReadableSocket
+ # Read a message from the socket
+ def read(buffer = '')
+ Celluloid.current_actor.wait_readable(@socket) if evented?
+
+ unless ::ZMQ::Util.resultcode_ok? @socket.recv_string buffer
+ raise IOError, "error receiving ZMQ string: #{::ZMQ::Util.error_string}"
+ end
+ buffer
+ end
+ end
+
+ # Writable 0MQ sockets have a send method
+ module WritableSocket
+ # Send a message to the socket
+ def send(message)
+ Celluloid.current_actor.wait_writable(@socket) if evented?
+
+ if ::ZMQ::Util.resultcode_ok? socket.send_string message
+ raise IOError, "error sending 0MQ message: #{::ZMQ::Util.error_string}"
+ end
+ message
+ end
+ alias_method :<<, :send
+ end
+
# ReqSockets are the counterpart of RepSockets (REQ/REP)
class ReqSocket < Socket
include ReadableSocket
Please sign in to comment.
Something went wrong with that request. Please try again.