[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: zmq poller used as main select
- From: Gaspard Bucher <gaspard@...>
- Date: Mon, 12 Sep 2011 11:30:27 +0200
Thanks to the talks at the Lua Workshop, I finally understood how I
could reimplement my scheduling algorithms without using a global
mutex. The gist is to use a central scheduler that does a single
"select" on all sockets and then to use coroutines to resume where the
calls would have blocked with blocking sockets.
Anyway, I want to use the dynamic nature of Lua to have a transparent
api that can be used with two different "polling" libraries (zmq/qt):
1. when used with zmq by using zmq.poll()
2. when used with Qt with app:exec()
>From my understanding, a zmq poll can work with non-zmq file
descriptors (zmq_pollitem->fd) and Qt can handle traditional sockets
with QSocketNotifier.
My plan now is to use zmq_poll when Qt is not running. When Qt dylib
is loaded, I would (in Lua):
1. move all zmq/traditional file descriptors to QSocketNotifier
2. use QTimer::singleShot for timed events
3. hand control to Qt with app:exec()
When events trigger QSocketNotifier, this calls the original
scheduling loop to resume the coroutine related to this socket/zmq
socket.
By reading Qt source code, QSocketNotifier just end up in a "select",
but I am not sure what happens with zmq (ZMQ_FD?)...
Is this totally insane ? Can it be done with Robert's zmq bindings
(which look really great) ?
Thanks for any comment,
Gaspard
[1] zmq --> Qt https://github.com/jonnydee/nzmqt/blob/master/include/nzmqt/nzmqt.hpp#L325
[2] socket --> zmq http://api.zeromq.org/2-1-1:zmq-poll
[3] ZMQ_FD http://api.zeromq.org/2-1-0:zmq-getsockopt
Gaspard