[zeromq-dev] missing events ZMQ_FD / ZMQ_EVENTS
Gerhard Lipp
gelipp at googlemail.com
Wed May 2 09:11:11 CEST 2012
hello paul!
i dont understand the background of your approach. why should the src
fd's io handler check the dst's events (and vice versa)?
even if this worked in this scenario, wouldn't it be a coincidence?
well, at least it is better than busy waiting / polling ...
regards
On Fri, Apr 27, 2012 at 9:10 PM, Paul Colomiets <paul at colomiets.name> wrote:
> Hi Gerhard,
>
> On Fri, Apr 27, 2012 at 2:10 PM, Gerhard Lipp <gelipp at googlemail.com> wrote:
>> Ok, so i must always check if there are more events to process before
>> returning from the io handler (frankly I don't understand the
>> explanation). A short test still shows the lock explained earlier:
>
> Try the following:
>
> local zmq = require'zmq'
> local ev = require'ev'
> local c = zmq.init(1)
> local xreq = c:socket(zmq.XREQ)
> xreq:bind('tcp://127.0.0.1:13333')
> local xrep = c:socket(zmq.XREP)
> xrep:bind('tcp://127.0.0.1:13334')
>
> local is_readable =
> function(sock)
> local events = sock:getopt(zmq.EVENTS)
> return events == zmq.POLLIN or events == (zmq.POLLIN + zmq.POLLOUT)
> end
>
> local forward_io =
> function(src,dst)
> return ev.IO.new(
> function(loop,io) -- called whenever src:getopt(zmq.FD) becomes readable
> while is_readable(src) or is_readable(dst) do
> if is_readable(src) do
> repeat
> local data = assert(src:recv(zmq.NOBLOCK))
> local more = src:getopt(zmq.RCVMORE) > 0
> dst:send(data,more and zmq.SNDMORE or 0)
> until not more
> end
> if is_readable(dst) do
> repeat
> local data = assert(dst:recv(zmq.NOBLOCK))
> local more = dst:getopt(zmq.RCVMORE) > 0
> src:send(data,more and zmq.SNDMORE or 0)
> until not more
> end
> end
> end,
> src:getopt(zmq.FD),
> ev.READ
> )
> end
> local xrep_io = forward_io(xrep,xreq)
> local xreq_io = forward_io(xreq,xrep)
> xreq_io:start(ev.Loop.default)
> xrep_io:start(ev.Loop.default)
> ev.Loop.default:loop()
>
> If this works. You can optimize (and clarify) it more.
>
> --
> Paul
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
More information about the zeromq-dev
mailing list