chuckremes/ffi-rzmq — Issue #46: ZMQ::Poller#delete incorrectly returns false
Author: halorgium
Created: 2011-11-01 22:25:12+00:00
State: open

When more than one socket is registered on a `ZMQ::Poller` and one socket is deleted from the `Poller`, the return value is incorrectly `false`.
This is used in ZMQMachine [1]

require 'ffi-rzmq'

context = ZMQ::Context.new
socket1 = con.socket ZMQ::REP
socket2 = con.socket ZMQ::REP

poller = ZMQ::Poller.new
poller.register_readable socket1
poller.register_readable socket2

p poller.delete socket2

The reason this occurs is because one of the success conditions is that the socket was deleted from the `@sockets` array. [2]
But in the common case, the `#deregister` method actually calls back into `#delete` which then deletes the socket from the array. [3]

I am not sure of the best way to resolve this, but it would make sense to only attempt to delete the socket once instead of the 3 times it is occurring now.

[1] https://github.com/chuckremes/zmqmachine/blob/e382367c64bc37c7b82df9b0c440d6b1ddf80d11/lib/zm/reactor.rb#L553
[2] https://github.com/chuckremes/ffi-rzmq/blob/f8e851280e518504cd5c3b7e4bcae9ac8f32d038/lib/ffi-rzmq/poll.rb#L147-148
[3] https://github.com/chuckremes/ffi-rzmq/blob/f8e851280e518504cd5c3b7e4bcae9ac8f32d038/lib/ffi-rzmq/poll.rb#L107