GNOME Bugzilla – Bug 655282
Add ZeroMQ bindings
Last modified: 2014-06-12 22:04:06 UTC
Created attachment 192630 [details] [review] ZeroMQ bindings patch I have attached a patch for ZeroMQ (libzmq) bindings. I also have 13 examples showing its use, which follow along with ZeroMQ's guide, to go into the wiki. I am looking forward to comments, and if everything is OK for this to be merged into master. I would also propose myself as the maintainer for these bindings if they are accepted.
Review of attachment 192630 [details] [review]: Instead of MSG and MSG.Msg, why not just put everything in a Message struct? It looks great so far. There are a few issues I would like to address before pushing it into the Vala repository, though: Why is the move method outside of the Msg struct? Msg.data should probably be a uint8[] (and a wrapper in the vapi to call size as well). Perhaps a property instead of a method, for consistency with string.data? In Socket, you could deal with a errno return code with a static method instead of a constructor. Perhaps POLL* should be in a namespace? You could even put the PollItem struct and poll function in there Perhaps device should be in the Device enum?
I am having some troubles with the Msg struct and copying. Looks like I may be blocked by https://bugzilla.gnome.org/show_bug.cgi?id=645852. Socket.send owns the message, and then makes a copy before the method call to zmq_send. Vala puts the copy parameters in the wrong order (ZMQ has their copy method paramters reversed from normal), and also copies without initializing the temporary variable first. If a temporary Msg variable is used in the copy, it must be initialized first; otherwise, a segmentation fault is produced.
Created attachment 195900 [details] [review] ZeroMQ bindings patch
Comment on attachment 195900 [details] [review] ZeroMQ bindings patch This new patch should address the issues noted. However, there is still problem with Vala not initializing the temporary variables it creates before use.
(In reply to comment #4) > However, there is still problem with Vala not initializing the temporary > variables it creates before use. Can you please be more specific?
In Socket.send the Msg is owned, so Vala makes a copy of the message before the method call. If I set the Msg struct copy_function="zmq_msg_copy" it will use the copy function backwards (src, dst) instead of (dst, src), and also does not initialize the copy before use with zmq_msg_init() (this will cause a seg fault). If I disable it with has_copy_function = false, it will create one called "zmq_msg_copy" which conflicts with ZMQ's version. If I set copy_function = "", it will compile, but it will still use a temporary zmq_msg_t variable that is not initialized. Currently, its set to copy_function="". You can see this with the hwserver and hwclient examples: https://github.com/lgunsch/zmq-vala/blob/master/examples/hwserver.vala https://github.com/lgunsch/zmq-vala/blob/master/examples/hwclient.vala
It probably makes sense to turn Msg into a compact class then. At all, I wouldn't mind implicitly copying a message, rather explicitly doing it with .copy() as it might be an heavy operation.
Have you considered binding czmq (http://czmq.zeromq.org/manual:czmq) instead of libzmq? It seems like it would be a bit more friendly towards Vala...
Created attachment 196961 [details] [review] Add ZeroMQ Bindings. CZMQ does look quite a bit more friendly towards Vala. It adds quite a bit more functionality as well. I will create bindings for it as well. Also, since I changed the send msg from owned, to ref, all my issues have disappeared and ZMQ works as expected now. I also have a good set of examples of use.
Added to vala-extra-vapis commit b4b13bfff9b7ab069313ae344eab3a7cc2376641 Author: Lewis Gunsch <lewis@gunsch.ca> Date: Thu Jun 12 14:46:31 2014 -0700 Add libzmq bindings. https://bugzilla.gnome.org/show_bug.cgi?id=655282