lib/0mq/poll.rb in 0mq-0.2.1 vs lib/0mq/poll.rb in 0mq-0.3.0

- old
+ new

@@ -13,11 +13,12 @@ # Construct a Poll object and start polling. # See #initialize for parameters. # See #run for block and return value. def self.poll(*sockets, &block) - new(*sockets).tap { |poll| poll.run(&block) } + poller = new *sockets + poller.run &block end # Non-blocking version of poll. def self.poll_nonblock(*sockets, &block) self.poll *sockets, timeout: 0, &block @@ -56,11 +57,11 @@ # Build table to reference ZMQ::Socket to its pointer's address. # This is an easy way to reconnect PollItem to ZMQ::Socket without # having to store multiple dimensions in the socks hash. @socket_lookup = {} - @socks.each { |socket, event| @socket_lookup[socket.ptr.address] = socket } + @socks.each { |socket, event| @socket_lookup[socket.to_ptr.address] = socket } # Allocate space for C PollItem (zmq_pollitem_t) structs. @poll_structs = FFI::MemoryPointer.new LibZMQ::PollItem, @socks.count, true # Create the PollItem objects. @@ -88,11 +89,11 @@ # Convert seconds to miliseconds. timeout = @timeout > 0 ? (@timeout * 1000).to_i : @timeout # Poll rc = LibZMQ::zmq_poll @poll_structs, @poll_items.count, timeout - ZMQ.error_check true if rc==-1 + ZMQ.error_check true if rc == -1 # Create a hash of the items with triggered events. # (ZMQ::Socket => revents) triggered_items = @poll_items.select { |pi| pi.revents > 0 } .map { |pi| [@socket_lookup[pi.socket.address], pi.revents] } @@ -113,11 +114,14 @@ end end +# :nodoc: module LibZMQ + + # :nodoc: class PollItem # Get the event flags: # ZMQ::POLLIN, ZMQ::POLLOUT, ZMQ::POLLERR. # Event flags are bitmasked. @@ -140,10 +144,10 @@ end # Set the socket to poll for events on. # Accepts a ZMQ::Socket or a pointer. def socket=(sock) - self[:socket] = sock.is_a?(FFI::Pointer) ? sock : sock.ptr + self[:socket] = sock.is_a?(FFI::Pointer) ? sock : sock.to_ptr end end end