rbczmq 1.6.2 → 1.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -3
- data/.gitmodules +6 -0
- data/.travis.yml +5 -1
- data/CHANGELOG.rdoc +15 -0
- data/Gemfile.lock +2 -2
- data/README.rdoc +5 -2
- data/Rakefile +8 -3
- data/ext/czmq/.gitignore +52 -0
- data/ext/czmq/.travis.yml +18 -0
- data/ext/czmq/AUTHORS +9 -0
- data/ext/czmq/COPYING +674 -0
- data/ext/czmq/COPYING.LESSER +178 -0
- data/ext/czmq/ChangeLog +0 -0
- data/ext/czmq/Makefile.am +22 -0
- data/ext/czmq/NEWS +263 -0
- data/ext/czmq/README +0 -0
- data/ext/czmq/README.md +1122 -0
- data/ext/czmq/README.txt +327 -0
- data/ext/czmq/autogen.sh +46 -0
- data/ext/czmq/builds/android/Android.mk +35 -0
- data/ext/czmq/builds/android/Application.mk +1 -0
- data/ext/czmq/builds/android/build.sh +59 -0
- data/ext/czmq/builds/android/clean.sh +26 -0
- data/ext/czmq/builds/mingw32/Makefile.mingw32 +38 -0
- data/ext/czmq/builds/mingw32/platform.h +0 -0
- data/ext/czmq/builds/msvc/.gitignore +18 -0
- data/ext/czmq/builds/msvc/README.txt +17 -0
- data/ext/czmq/builds/msvc/czmq.sln +69 -0
- data/ext/czmq/builds/msvc/czmq.vcproj +2246 -0
- data/ext/czmq/builds/msvc/czmq.vcxproj +329 -0
- data/ext/czmq/builds/msvc/czmq.vcxproj.filters +117 -0
- data/ext/czmq/builds/msvc/czmq11.sln +36 -0
- data/ext/czmq/builds/msvc/czmq_selftest.vcproj +840 -0
- data/ext/czmq/builds/msvc/czmq_selftest.vcxproj +189 -0
- data/ext/czmq/builds/msvc/czmq_selftest.vcxproj.filters +14 -0
- data/ext/czmq/c +520 -0
- data/ext/czmq/configure.ac +229 -0
- data/ext/czmq/doc/Makefile.am +49 -0
- data/ext/czmq/doc/asciidoc.conf +57 -0
- data/ext/czmq/doc/czmq.txt +334 -0
- data/ext/czmq/doc/mkman +100 -0
- data/ext/czmq/doc/mksite +65 -0
- data/ext/czmq/doc/wdput +43 -0
- data/ext/czmq/doc/xml2wd.pl +242 -0
- data/ext/czmq/doc/zbeacon.txt +173 -0
- data/ext/czmq/doc/zclock.txt +51 -0
- data/ext/czmq/doc/zconfig.txt +92 -0
- data/ext/czmq/doc/zctx.txt +111 -0
- data/ext/czmq/doc/zfile.txt +77 -0
- data/ext/czmq/doc/zframe.txt +222 -0
- data/ext/czmq/doc/zhash.txt +225 -0
- data/ext/czmq/doc/zlist.txt +176 -0
- data/ext/czmq/doc/zloop.txt +106 -0
- data/ext/czmq/doc/zmsg.txt +315 -0
- data/ext/czmq/doc/zmutex.txt +54 -0
- data/ext/czmq/doc/zsocket.txt +110 -0
- data/ext/czmq/doc/zsockopt.txt +528 -0
- data/ext/czmq/doc/zstr.txt +80 -0
- data/ext/czmq/doc/zsys.txt +44 -0
- data/ext/czmq/doc/zthread.txt +126 -0
- data/ext/czmq/doc/ztree.txt +236 -0
- data/ext/czmq/images/README_1.png +0 -0
- data/ext/czmq/images/README_2.png +0 -0
- data/ext/czmq/include/czmq.h +64 -0
- data/ext/czmq/include/czmq_prelude.h +504 -0
- data/ext/czmq/include/zbeacon.h +91 -0
- data/ext/czmq/include/zclock.h +56 -0
- data/ext/czmq/include/zconfig.h +117 -0
- data/ext/czmq/include/zctx.h +96 -0
- data/ext/czmq/include/zfile.h +82 -0
- data/ext/czmq/include/zframe.h +145 -0
- data/ext/czmq/include/zhash.h +127 -0
- data/ext/czmq/include/zlist.h +113 -0
- data/ext/czmq/include/zloop.h +98 -0
- data/ext/czmq/include/zmsg.h +165 -0
- data/ext/czmq/include/zmutex.h +62 -0
- data/ext/czmq/include/zsocket.h +104 -0
- data/ext/czmq/include/zsockopt.h +249 -0
- data/ext/czmq/include/zstr.h +69 -0
- data/ext/czmq/include/zsys.h +66 -0
- data/ext/czmq/include/zthread.h +62 -0
- data/ext/czmq/include/ztree.h +133 -0
- data/ext/czmq/mkdoc +14 -0
- data/ext/czmq/model/generate +2 -0
- data/ext/czmq/model/sockopts.xml +101 -0
- data/ext/czmq/notes.txt +21 -0
- data/ext/czmq/scripts/sockopts.gsl +325 -0
- data/ext/czmq/src/Makefile.am +61 -0
- data/ext/czmq/src/czmq_selftest.c +60 -0
- data/ext/czmq/src/libczmq.pc.in +11 -0
- data/ext/czmq/src/selftest +7 -0
- data/ext/czmq/src/selftest.cfg +5 -0
- data/ext/czmq/src/valgrind.supp +14 -0
- data/ext/czmq/src/vg +2 -0
- data/ext/czmq/src/zbeacon.c +787 -0
- data/ext/czmq/src/zclock.c +143 -0
- data/ext/czmq/src/zconfig.c +691 -0
- data/ext/czmq/src/zctx.c +287 -0
- data/ext/czmq/src/zfile.c +237 -0
- data/ext/czmq/src/zframe.c +551 -0
- data/ext/czmq/src/zhash.c +664 -0
- data/ext/czmq/src/zlist.c +459 -0
- data/ext/czmq/src/zloop.c +496 -0
- data/ext/czmq/src/zmsg.c +854 -0
- data/ext/czmq/src/zmutex.c +134 -0
- data/ext/czmq/src/zsocket.c +313 -0
- data/ext/czmq/src/zsockopt.c +1756 -0
- data/ext/czmq/src/zstr.c +297 -0
- data/ext/czmq/src/zsys.c +136 -0
- data/ext/czmq/src/zthread.c +269 -0
- data/ext/czmq/src/ztree.c +888 -0
- data/ext/czmq/version.sh +21 -0
- data/ext/rbczmq/extconf.rb +1 -18
- data/ext/rbczmq/poller.c +4 -1
- data/ext/rbczmq/socket.c +28 -5
- data/ext/rbczmq/socket.h +1 -0
- data/ext/zeromq/AUTHORS +110 -0
- data/ext/zeromq/CMakeLists.txt +392 -0
- data/ext/zeromq/COPYING +674 -0
- data/ext/zeromq/COPYING.LESSER +179 -0
- data/ext/zeromq/INSTALL +246 -0
- data/ext/zeromq/MAINTAINERS +56 -0
- data/ext/zeromq/Makefile.am +40 -0
- data/ext/zeromq/NEWS +333 -0
- data/ext/zeromq/README +39 -0
- data/ext/zeromq/acinclude.m4 +930 -0
- data/ext/zeromq/autogen.sh +45 -0
- data/ext/zeromq/branding.bmp +0 -0
- data/ext/zeromq/builds/msvc/Makefile.am +33 -0
- data/ext/zeromq/builds/msvc/c_local_lat/c_local_lat.vcproj +176 -0
- data/ext/zeromq/builds/msvc/c_local_lat/c_local_lat.vcxproj +87 -0
- data/ext/zeromq/builds/msvc/c_local_thr/c_local_thr.vcproj +176 -0
- data/ext/zeromq/builds/msvc/c_local_thr/c_local_thr.vcxproj +87 -0
- data/ext/zeromq/builds/msvc/c_remote_lat/c_remote_lat.vcproj +176 -0
- data/ext/zeromq/builds/msvc/c_remote_lat/c_remote_lat.vcxproj +87 -0
- data/ext/zeromq/builds/msvc/c_remote_thr/c_remote_thr.vcproj +176 -0
- data/ext/zeromq/builds/msvc/c_remote_thr/c_remote_thr.vcxproj +87 -0
- data/ext/zeromq/builds/msvc/errno.cpp +32 -0
- data/ext/zeromq/builds/msvc/errno.hpp +56 -0
- data/ext/zeromq/builds/msvc/inproc_lat/inproc_lat.vcproj +174 -0
- data/ext/zeromq/builds/msvc/inproc_lat/inproc_lat.vcxproj +86 -0
- data/ext/zeromq/builds/msvc/inproc_thr/inproc_thr.vcproj +174 -0
- data/ext/zeromq/builds/msvc/inproc_thr/inproc_thr.vcxproj +86 -0
- data/ext/zeromq/builds/msvc/libzmq/libzmq.vcproj +804 -0
- data/ext/zeromq/builds/msvc/libzmq/libzmq.vcxproj +252 -0
- data/ext/zeromq/builds/msvc/libzmq/libzmq.vcxproj.filters +431 -0
- data/ext/zeromq/builds/msvc/msvc.sln +89 -0
- data/ext/zeromq/builds/msvc/msvc10.sln +116 -0
- data/ext/zeromq/builds/msvc/platform.hpp +32 -0
- data/ext/zeromq/builds/msvc/properties/Common.props +21 -0
- data/ext/zeromq/builds/msvc/properties/Debug.props +19 -0
- data/ext/zeromq/builds/msvc/properties/Dynamic.props +20 -0
- data/ext/zeromq/builds/msvc/properties/Executable.props +19 -0
- data/ext/zeromq/builds/msvc/properties/Precompiled.props +14 -0
- data/ext/zeromq/builds/msvc/properties/Release.props +22 -0
- data/ext/zeromq/builds/msvc/properties/Win32.props +12 -0
- data/ext/zeromq/builds/msvc/properties/Win32_Release.props +17 -0
- data/ext/zeromq/builds/msvc/properties/WithOpenPGM.props +12 -0
- data/ext/zeromq/builds/msvc/properties/ZeroMQ.props +23 -0
- data/ext/zeromq/builds/msvc/properties/x64.props +12 -0
- data/ext/zeromq/builds/redhat/zeromq.spec.in +160 -0
- data/ext/zeromq/builds/valgrind/valgrind.supp +14 -0
- data/ext/zeromq/builds/valgrind/vg +1 -0
- data/ext/zeromq/cmake/Modules/TestZMQVersion.cmake +35 -0
- data/ext/zeromq/cmake/Modules/zmq_version.cpp +31 -0
- data/ext/zeromq/cmake/NSIS.template32.in +952 -0
- data/ext/zeromq/cmake/NSIS.template64.in +960 -0
- data/ext/zeromq/configure.in +428 -0
- data/ext/zeromq/doc/Makefile.am +51 -0
- data/ext/zeromq/doc/asciidoc.conf +56 -0
- data/ext/zeromq/doc/zmq.txt +233 -0
- data/ext/zeromq/doc/zmq_bind.txt +102 -0
- data/ext/zeromq/doc/zmq_close.txt +52 -0
- data/ext/zeromq/doc/zmq_connect.txt +98 -0
- data/ext/zeromq/doc/zmq_ctx_destroy.txt +66 -0
- data/ext/zeromq/doc/zmq_ctx_get.txt +67 -0
- data/ext/zeromq/doc/zmq_ctx_new.txt +49 -0
- data/ext/zeromq/doc/zmq_ctx_set.txt +75 -0
- data/ext/zeromq/doc/zmq_disconnect.txt +67 -0
- data/ext/zeromq/doc/zmq_epgm.txt +162 -0
- data/ext/zeromq/doc/zmq_errno.txt +50 -0
- data/ext/zeromq/doc/zmq_getsockopt.txt +516 -0
- data/ext/zeromq/doc/zmq_init.txt +52 -0
- data/ext/zeromq/doc/zmq_inproc.txt +85 -0
- data/ext/zeromq/doc/zmq_ipc.txt +85 -0
- data/ext/zeromq/doc/zmq_msg_close.txt +55 -0
- data/ext/zeromq/doc/zmq_msg_copy.txt +57 -0
- data/ext/zeromq/doc/zmq_msg_data.txt +48 -0
- data/ext/zeromq/doc/zmq_msg_get.txt +72 -0
- data/ext/zeromq/doc/zmq_msg_init.txt +65 -0
- data/ext/zeromq/doc/zmq_msg_init_data.txt +85 -0
- data/ext/zeromq/doc/zmq_msg_init_size.txt +58 -0
- data/ext/zeromq/doc/zmq_msg_more.txt +63 -0
- data/ext/zeromq/doc/zmq_msg_move.txt +52 -0
- data/ext/zeromq/doc/zmq_msg_recv.txt +125 -0
- data/ext/zeromq/doc/zmq_msg_send.txt +122 -0
- data/ext/zeromq/doc/zmq_msg_set.txt +45 -0
- data/ext/zeromq/doc/zmq_msg_size.txt +48 -0
- data/ext/zeromq/doc/zmq_pgm.txt +162 -0
- data/ext/zeromq/doc/zmq_poll.txt +132 -0
- data/ext/zeromq/doc/zmq_proxy.txt +97 -0
- data/ext/zeromq/doc/zmq_recv.txt +93 -0
- data/ext/zeromq/doc/zmq_recvmsg.txt +123 -0
- data/ext/zeromq/doc/zmq_send.txt +100 -0
- data/ext/zeromq/doc/zmq_sendmsg.txt +119 -0
- data/ext/zeromq/doc/zmq_setsockopt.txt +523 -0
- data/ext/zeromq/doc/zmq_socket.txt +369 -0
- data/ext/zeromq/doc/zmq_socket_monitor.txt +288 -0
- data/ext/zeromq/doc/zmq_strerror.txt +55 -0
- data/ext/zeromq/doc/zmq_tcp.txt +101 -0
- data/ext/zeromq/doc/zmq_term.txt +66 -0
- data/ext/zeromq/doc/zmq_unbind.txt +65 -0
- data/ext/zeromq/doc/zmq_version.txt +53 -0
- data/ext/zeromq/foreign/openpgm/Makefile.am +8 -0
- data/ext/zeromq/foreign/openpgm/libpgm-5.1.118~dfsg.tar.gz +0 -0
- data/ext/zeromq/include/zmq.h +402 -0
- data/ext/zeromq/include/zmq_utils.h +64 -0
- data/ext/zeromq/installer.ico +0 -0
- data/ext/zeromq/perf/Makefile.am +22 -0
- data/ext/zeromq/perf/inproc_lat.cpp +233 -0
- data/ext/zeromq/perf/inproc_thr.cpp +241 -0
- data/ext/zeromq/perf/local_lat.cpp +109 -0
- data/ext/zeromq/perf/local_thr.cpp +133 -0
- data/ext/zeromq/perf/remote_lat.cpp +122 -0
- data/ext/zeromq/perf/remote_thr.cpp +105 -0
- data/ext/zeromq/src/Makefile.am +171 -0
- data/ext/zeromq/src/address.cpp +78 -0
- data/ext/zeromq/src/address.hpp +52 -0
- data/ext/zeromq/src/array.hpp +155 -0
- data/ext/zeromq/src/atomic_counter.hpp +197 -0
- data/ext/zeromq/src/atomic_ptr.hpp +196 -0
- data/ext/zeromq/src/blob.hpp +129 -0
- data/ext/zeromq/src/clock.cpp +147 -0
- data/ext/zeromq/src/clock.hpp +60 -0
- data/ext/zeromq/src/command.hpp +154 -0
- data/ext/zeromq/src/config.hpp +89 -0
- data/ext/zeromq/src/ctx.cpp +352 -0
- data/ext/zeromq/src/ctx.hpp +173 -0
- data/ext/zeromq/src/dealer.cpp +133 -0
- data/ext/zeromq/src/dealer.hpp +92 -0
- data/ext/zeromq/src/decoder.cpp +166 -0
- data/ext/zeromq/src/decoder.hpp +248 -0
- data/ext/zeromq/src/devpoll.cpp +190 -0
- data/ext/zeromq/src/devpoll.hpp +105 -0
- data/ext/zeromq/src/dist.cpp +194 -0
- data/ext/zeromq/src/dist.hpp +105 -0
- data/ext/zeromq/src/encoder.cpp +102 -0
- data/ext/zeromq/src/encoder.hpp +200 -0
- data/ext/zeromq/src/epoll.cpp +178 -0
- data/ext/zeromq/src/epoll.hpp +101 -0
- data/ext/zeromq/src/err.cpp +291 -0
- data/ext/zeromq/src/err.hpp +155 -0
- data/ext/zeromq/src/fd.hpp +45 -0
- data/ext/zeromq/src/fq.cpp +141 -0
- data/ext/zeromq/src/fq.hpp +74 -0
- data/ext/zeromq/src/i_decoder.hpp +49 -0
- data/ext/zeromq/src/i_encoder.hpp +55 -0
- data/ext/zeromq/src/i_engine.hpp +55 -0
- data/ext/zeromq/src/i_msg_sink.hpp +43 -0
- data/ext/zeromq/src/i_msg_source.hpp +44 -0
- data/ext/zeromq/src/i_poll_events.hpp +47 -0
- data/ext/zeromq/src/io_object.cpp +108 -0
- data/ext/zeromq/src/io_object.hpp +81 -0
- data/ext/zeromq/src/io_thread.cpp +104 -0
- data/ext/zeromq/src/io_thread.hpp +91 -0
- data/ext/zeromq/src/ip.cpp +109 -0
- data/ext/zeromq/src/ip.hpp +41 -0
- data/ext/zeromq/src/ipc_address.cpp +84 -0
- data/ext/zeromq/src/ipc_address.hpp +67 -0
- data/ext/zeromq/src/ipc_connecter.cpp +265 -0
- data/ext/zeromq/src/ipc_connecter.hpp +128 -0
- data/ext/zeromq/src/ipc_listener.cpp +206 -0
- data/ext/zeromq/src/ipc_listener.hpp +99 -0
- data/ext/zeromq/src/kqueue.cpp +201 -0
- data/ext/zeromq/src/kqueue.hpp +107 -0
- data/ext/zeromq/src/lb.cpp +148 -0
- data/ext/zeromq/src/lb.hpp +73 -0
- data/ext/zeromq/src/libzmq.pc.in +10 -0
- data/ext/zeromq/src/likely.hpp +33 -0
- data/ext/zeromq/src/mailbox.cpp +87 -0
- data/ext/zeromq/src/mailbox.hpp +75 -0
- data/ext/zeromq/src/msg.cpp +299 -0
- data/ext/zeromq/src/msg.hpp +148 -0
- data/ext/zeromq/src/mtrie.cpp +428 -0
- data/ext/zeromq/src/mtrie.hpp +93 -0
- data/ext/zeromq/src/mutex.hpp +118 -0
- data/ext/zeromq/src/object.cpp +393 -0
- data/ext/zeromq/src/object.hpp +134 -0
- data/ext/zeromq/src/options.cpp +562 -0
- data/ext/zeromq/src/options.hpp +135 -0
- data/ext/zeromq/src/own.cpp +206 -0
- data/ext/zeromq/src/own.hpp +145 -0
- data/ext/zeromq/src/pair.cpp +136 -0
- data/ext/zeromq/src/pair.hpp +79 -0
- data/ext/zeromq/src/pgm_receiver.cpp +283 -0
- data/ext/zeromq/src/pgm_receiver.hpp +141 -0
- data/ext/zeromq/src/pgm_sender.cpp +218 -0
- data/ext/zeromq/src/pgm_sender.hpp +113 -0
- data/ext/zeromq/src/pgm_socket.cpp +706 -0
- data/ext/zeromq/src/pgm_socket.hpp +124 -0
- data/ext/zeromq/src/pipe.cpp +447 -0
- data/ext/zeromq/src/pipe.hpp +207 -0
- data/ext/zeromq/src/poll.cpp +176 -0
- data/ext/zeromq/src/poll.hpp +105 -0
- data/ext/zeromq/src/poller.hpp +82 -0
- data/ext/zeromq/src/poller_base.cpp +99 -0
- data/ext/zeromq/src/poller_base.hpp +86 -0
- data/ext/zeromq/src/precompiled.cpp +21 -0
- data/ext/zeromq/src/precompiled.hpp +47 -0
- data/ext/zeromq/src/proxy.cpp +150 -0
- data/ext/zeromq/src/proxy.hpp +32 -0
- data/ext/zeromq/src/pub.cpp +57 -0
- data/ext/zeromq/src/pub.hpp +69 -0
- data/ext/zeromq/src/pull.cpp +79 -0
- data/ext/zeromq/src/pull.hpp +81 -0
- data/ext/zeromq/src/push.cpp +76 -0
- data/ext/zeromq/src/push.hpp +80 -0
- data/ext/zeromq/src/random.cpp +52 -0
- data/ext/zeromq/src/random.hpp +37 -0
- data/ext/zeromq/src/reaper.cpp +117 -0
- data/ext/zeromq/src/reaper.hpp +80 -0
- data/ext/zeromq/src/rep.cpp +137 -0
- data/ext/zeromq/src/rep.hpp +80 -0
- data/ext/zeromq/src/req.cpp +185 -0
- data/ext/zeromq/src/req.hpp +91 -0
- data/ext/zeromq/src/router.cpp +364 -0
- data/ext/zeromq/src/router.hpp +138 -0
- data/ext/zeromq/src/select.cpp +216 -0
- data/ext/zeromq/src/select.hpp +126 -0
- data/ext/zeromq/src/session_base.cpp +503 -0
- data/ext/zeromq/src/session_base.hpp +156 -0
- data/ext/zeromq/src/signaler.cpp +406 -0
- data/ext/zeromq/src/signaler.hpp +63 -0
- data/ext/zeromq/src/socket_base.cpp +1236 -0
- data/ext/zeromq/src/socket_base.hpp +255 -0
- data/ext/zeromq/src/stdint.hpp +63 -0
- data/ext/zeromq/src/stream_engine.cpp +594 -0
- data/ext/zeromq/src/stream_engine.hpp +149 -0
- data/ext/zeromq/src/sub.cpp +93 -0
- data/ext/zeromq/src/sub.hpp +71 -0
- data/ext/zeromq/src/tcp.cpp +131 -0
- data/ext/zeromq/src/tcp.hpp +38 -0
- data/ext/zeromq/src/tcp_address.cpp +613 -0
- data/ext/zeromq/src/tcp_address.hpp +100 -0
- data/ext/zeromq/src/tcp_connecter.cpp +319 -0
- data/ext/zeromq/src/tcp_connecter.hpp +123 -0
- data/ext/zeromq/src/tcp_listener.cpp +293 -0
- data/ext/zeromq/src/tcp_listener.hpp +91 -0
- data/ext/zeromq/src/thread.cpp +107 -0
- data/ext/zeromq/src/thread.hpp +79 -0
- data/ext/zeromq/src/trie.cpp +337 -0
- data/ext/zeromq/src/trie.hpp +79 -0
- data/ext/zeromq/src/v1_decoder.cpp +162 -0
- data/ext/zeromq/src/v1_decoder.hpp +68 -0
- data/ext/zeromq/src/v1_encoder.cpp +103 -0
- data/ext/zeromq/src/v1_encoder.hpp +60 -0
- data/ext/zeromq/src/v1_protocol.hpp +43 -0
- data/ext/zeromq/src/version.rc.in +93 -0
- data/ext/zeromq/src/windows.hpp +181 -0
- data/ext/zeromq/src/wire.hpp +99 -0
- data/ext/zeromq/src/xpub.cpp +200 -0
- data/ext/zeromq/src/xpub.hpp +110 -0
- data/ext/zeromq/src/xsub.cpp +242 -0
- data/ext/zeromq/src/xsub.hpp +108 -0
- data/ext/zeromq/src/ypipe.hpp +210 -0
- data/ext/zeromq/src/yqueue.hpp +199 -0
- data/ext/zeromq/src/zmq.cpp +1058 -0
- data/ext/zeromq/src/zmq_utils.cpp +61 -0
- data/ext/zeromq/tests/Makefile.am +55 -0
- data/ext/zeromq/tests/test_connect_delay.cpp +260 -0
- data/ext/zeromq/tests/test_connect_resolve.cpp +54 -0
- data/ext/zeromq/tests/test_disconnect_inproc.cpp +120 -0
- data/ext/zeromq/tests/test_hwm.cpp +83 -0
- data/ext/zeromq/tests/test_invalid_rep.cpp +92 -0
- data/ext/zeromq/tests/test_last_endpoint.cpp +60 -0
- data/ext/zeromq/tests/test_monitor.cpp +289 -0
- data/ext/zeromq/tests/test_msg_flags.cpp +78 -0
- data/ext/zeromq/tests/test_pair_inproc.cpp +53 -0
- data/ext/zeromq/tests/test_pair_ipc.cpp +53 -0
- data/ext/zeromq/tests/test_pair_tcp.cpp +54 -0
- data/ext/zeromq/tests/test_reqrep_device.cpp +143 -0
- data/ext/zeromq/tests/test_reqrep_inproc.cpp +53 -0
- data/ext/zeromq/tests/test_reqrep_ipc.cpp +53 -0
- data/ext/zeromq/tests/test_reqrep_tcp.cpp +54 -0
- data/ext/zeromq/tests/test_router_mandatory.cpp +62 -0
- data/ext/zeromq/tests/test_shutdown_stress.cpp +93 -0
- data/ext/zeromq/tests/test_sub_forward.cpp +99 -0
- data/ext/zeromq/tests/test_term_endpoint.cpp +118 -0
- data/ext/zeromq/tests/test_timeo.cpp +119 -0
- data/ext/zeromq/tests/testutil.hpp +77 -0
- data/ext/zeromq/version.sh +21 -0
- data/lib/zmq/version.rb +1 -1
- data/rbczmq.gemspec +16 -3
- data/test/test_socket.rb +13 -1
- metadata +398 -9
- checksums.yaml +0 -15
- data/ext/czmq-1.4.1.tar.gz +0 -0
- data/ext/zeromq-3.2.3.tar.gz +0 -0
data/ext/czmq/src/zmsg.c
ADDED
@@ -0,0 +1,854 @@
|
|
1
|
+
/* =========================================================================
|
2
|
+
zmsg - working with multipart messages
|
3
|
+
|
4
|
+
-------------------------------------------------------------------------
|
5
|
+
Copyright (c) 1991-2013 iMatix Corporation <www.imatix.com>
|
6
|
+
Copyright other contributors as noted in the AUTHORS file.
|
7
|
+
|
8
|
+
This file is part of CZMQ, the high-level C binding for 0MQ:
|
9
|
+
http://czmq.zeromq.org.
|
10
|
+
|
11
|
+
This is free software; you can redistribute it and/or modify it under
|
12
|
+
the terms of the GNU Lesser General Public License as published by the
|
13
|
+
Free Software Foundation; either version 3 of the License, or (at your
|
14
|
+
option) any later version.
|
15
|
+
|
16
|
+
This software is distributed in the hope that it will be useful, but
|
17
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABIL-
|
18
|
+
ITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
19
|
+
Public License for more details.
|
20
|
+
|
21
|
+
You should have received a copy of the GNU Lesser General Public License
|
22
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
=========================================================================
|
24
|
+
*/
|
25
|
+
|
26
|
+
/*
|
27
|
+
@header
|
28
|
+
The zmsg class provides methods to send and receive multipart messages
|
29
|
+
across 0MQ sockets. This class provides a list-like container interface,
|
30
|
+
with methods to work with the overall container. zmsg_t messages are
|
31
|
+
composed of zero or more zframe_t frames.
|
32
|
+
@discuss
|
33
|
+
@end
|
34
|
+
*/
|
35
|
+
|
36
|
+
#include "../include/czmq.h"
|
37
|
+
|
38
|
+
// Structure of our class
|
39
|
+
|
40
|
+
struct _zmsg_t {
|
41
|
+
zlist_t *frames; // List of frames
|
42
|
+
size_t content_size; // Total content size
|
43
|
+
};
|
44
|
+
|
45
|
+
|
46
|
+
// --------------------------------------------------------------------------
|
47
|
+
// Constructor
|
48
|
+
|
49
|
+
zmsg_t *
|
50
|
+
zmsg_new (void)
|
51
|
+
{
|
52
|
+
zmsg_t
|
53
|
+
*self;
|
54
|
+
|
55
|
+
self = (zmsg_t *) zmalloc (sizeof (zmsg_t));
|
56
|
+
if (self) {
|
57
|
+
self->frames = zlist_new ();
|
58
|
+
if (!self->frames) {
|
59
|
+
free (self);
|
60
|
+
return NULL;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
return self;
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
// --------------------------------------------------------------------------
|
68
|
+
// Destructor
|
69
|
+
|
70
|
+
void
|
71
|
+
zmsg_destroy (zmsg_t **self_p)
|
72
|
+
{
|
73
|
+
assert (self_p);
|
74
|
+
if (*self_p) {
|
75
|
+
zmsg_t *self = *self_p;
|
76
|
+
while (zlist_size (self->frames) > 0) {
|
77
|
+
zframe_t *frame = (zframe_t *) zlist_pop (self->frames);
|
78
|
+
zframe_destroy (&frame);
|
79
|
+
}
|
80
|
+
zlist_destroy (&self->frames);
|
81
|
+
free (self);
|
82
|
+
*self_p = NULL;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
|
87
|
+
// --------------------------------------------------------------------------
|
88
|
+
// Receive message from socket, returns zmsg_t object or NULL if the recv
|
89
|
+
// was interrupted. Does a blocking recv, if you want to not block then use
|
90
|
+
// the zloop class or zmq_poll to check for socket input before receiving.
|
91
|
+
|
92
|
+
zmsg_t *
|
93
|
+
zmsg_recv (void *zocket)
|
94
|
+
{
|
95
|
+
assert (zocket);
|
96
|
+
zmsg_t *self = zmsg_new ();
|
97
|
+
if (!self)
|
98
|
+
return NULL;
|
99
|
+
|
100
|
+
while (1) {
|
101
|
+
zframe_t *frame = zframe_recv (zocket);
|
102
|
+
if (!frame) {
|
103
|
+
zmsg_destroy (&self);
|
104
|
+
break; // Interrupted or terminated
|
105
|
+
}
|
106
|
+
if (zmsg_add (self, frame)) {
|
107
|
+
zmsg_destroy (&self);
|
108
|
+
break;
|
109
|
+
}
|
110
|
+
if (!zframe_more (frame))
|
111
|
+
break; // Last message frame
|
112
|
+
}
|
113
|
+
return self;
|
114
|
+
}
|
115
|
+
|
116
|
+
|
117
|
+
// --------------------------------------------------------------------------
|
118
|
+
// Send message to socket, destroy after sending. If the message has no
|
119
|
+
// frames, sends nothing but destroys the message anyhow. Safe to call
|
120
|
+
// if zmsg is null.
|
121
|
+
|
122
|
+
int
|
123
|
+
zmsg_send (zmsg_t **self_p, void *zocket)
|
124
|
+
{
|
125
|
+
assert (self_p);
|
126
|
+
assert (zocket);
|
127
|
+
zmsg_t *self = *self_p;
|
128
|
+
|
129
|
+
int rc = 0;
|
130
|
+
if (self) {
|
131
|
+
zframe_t *frame = (zframe_t *) zlist_pop (self->frames);
|
132
|
+
while (frame) {
|
133
|
+
rc = zframe_send (&frame, zocket,
|
134
|
+
zlist_size (self->frames)? ZFRAME_MORE: 0);
|
135
|
+
if (rc != 0)
|
136
|
+
break;
|
137
|
+
frame = (zframe_t *) zlist_pop (self->frames);
|
138
|
+
}
|
139
|
+
zmsg_destroy (self_p);
|
140
|
+
}
|
141
|
+
return rc;
|
142
|
+
}
|
143
|
+
|
144
|
+
|
145
|
+
// --------------------------------------------------------------------------
|
146
|
+
// Return size of message, i.e. number of frames (0 or more).
|
147
|
+
|
148
|
+
size_t
|
149
|
+
zmsg_size (zmsg_t *self)
|
150
|
+
{
|
151
|
+
assert (self);
|
152
|
+
return zlist_size (self->frames);
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
// --------------------------------------------------------------------------
|
157
|
+
// Return size of message, i.e. number of frames (0 or more).
|
158
|
+
|
159
|
+
size_t
|
160
|
+
zmsg_content_size (zmsg_t *self)
|
161
|
+
{
|
162
|
+
assert (self);
|
163
|
+
return self->content_size;
|
164
|
+
}
|
165
|
+
|
166
|
+
|
167
|
+
// --------------------------------------------------------------------------
|
168
|
+
// Push frame to the front of the message, i.e. before all other frames.
|
169
|
+
// Message takes ownership of frame, will destroy it when message is sent.
|
170
|
+
// Returns 0 on success, -1 on error.
|
171
|
+
|
172
|
+
int
|
173
|
+
zmsg_push (zmsg_t *self, zframe_t *frame)
|
174
|
+
{
|
175
|
+
assert (self);
|
176
|
+
assert (frame);
|
177
|
+
self->content_size += zframe_size (frame);
|
178
|
+
return zlist_push (self->frames, (void *) frame);
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
// --------------------------------------------------------------------------
|
183
|
+
// Remove first frame from message, if any. Returns frame, or NULL. Caller
|
184
|
+
// now owns frame and must destroy it when finished with it.
|
185
|
+
|
186
|
+
zframe_t *
|
187
|
+
zmsg_pop (zmsg_t *self)
|
188
|
+
{
|
189
|
+
assert (self);
|
190
|
+
zframe_t *frame = (zframe_t *) zlist_pop (self->frames);
|
191
|
+
if (frame)
|
192
|
+
self->content_size -= zframe_size (frame);
|
193
|
+
return frame;
|
194
|
+
}
|
195
|
+
|
196
|
+
|
197
|
+
// --------------------------------------------------------------------------
|
198
|
+
// Add frame to the end of the message, i.e. after all other frames.
|
199
|
+
// Message takes ownership of frame, will destroy it when message is sent.
|
200
|
+
// Returns 0 on success
|
201
|
+
|
202
|
+
int
|
203
|
+
zmsg_add (zmsg_t *self, zframe_t *frame)
|
204
|
+
{
|
205
|
+
assert (self);
|
206
|
+
assert (frame);
|
207
|
+
self->content_size += zframe_size (frame);
|
208
|
+
return zlist_append (self->frames, frame);
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
// --------------------------------------------------------------------------
|
213
|
+
// Push block of memory to front of message, as a new frame.
|
214
|
+
// Returns 0 on success, -1 on error.
|
215
|
+
|
216
|
+
int
|
217
|
+
zmsg_pushmem (zmsg_t *self, const void *src, size_t size)
|
218
|
+
{
|
219
|
+
assert (self);
|
220
|
+
zframe_t *frame = zframe_new (src, size);
|
221
|
+
if (frame) {
|
222
|
+
self->content_size += size;
|
223
|
+
return zlist_push (self->frames, frame);
|
224
|
+
}
|
225
|
+
else
|
226
|
+
return -1;
|
227
|
+
}
|
228
|
+
|
229
|
+
// --------------------------------------------------------------------------
|
230
|
+
// Add block of memory to the end of the message, as a new frame.
|
231
|
+
|
232
|
+
int
|
233
|
+
zmsg_addmem (zmsg_t *self, const void *src, size_t size)
|
234
|
+
{
|
235
|
+
assert (self);
|
236
|
+
zframe_t *frame = zframe_new (src, size);
|
237
|
+
if (frame) {
|
238
|
+
self->content_size += size;
|
239
|
+
return zlist_append (self->frames, frame);
|
240
|
+
}
|
241
|
+
else
|
242
|
+
return -1;
|
243
|
+
}
|
244
|
+
|
245
|
+
// --------------------------------------------------------------------------
|
246
|
+
// Add block of memory to the end of the message, as a new frame.
|
247
|
+
// The new frame is zero-copy-constructed (see zframe_new_zero_copy(...)
|
248
|
+
// for detailed description)
|
249
|
+
// NOTE: this method is DEPRECATED and is slated for removal. These are the
|
250
|
+
// problems with the method:
|
251
|
+
// - premature optimization: do we really need this? It makes the API more
|
252
|
+
// complex; high-performance applications would not use zmsg in any case,
|
253
|
+
// they would work directly with zmq_msg objects.
|
254
|
+
// (PH, 2013/05/18)
|
255
|
+
|
256
|
+
int
|
257
|
+
zmsg_addmem_zero_copy (zmsg_t *self, void *src, size_t size, zframe_free_fn *free_fn, void *arg)
|
258
|
+
{
|
259
|
+
assert (self);
|
260
|
+
zframe_t *frame = zframe_new_zero_copy (src, size, free_fn, arg);
|
261
|
+
if (frame) {
|
262
|
+
self->content_size += size;
|
263
|
+
return zlist_append (self->frames, frame);
|
264
|
+
}
|
265
|
+
else
|
266
|
+
return -1;
|
267
|
+
}
|
268
|
+
|
269
|
+
// --------------------------------------------------------------------------
|
270
|
+
// Push string as new frame to front of message
|
271
|
+
|
272
|
+
int
|
273
|
+
zmsg_pushstr (zmsg_t *self, const char *format, ...)
|
274
|
+
{
|
275
|
+
assert (self);
|
276
|
+
assert (format);
|
277
|
+
|
278
|
+
// Format string into buffer
|
279
|
+
int size = 255 + 1;
|
280
|
+
char stackbuffer[255+1];
|
281
|
+
char *string = stackbuffer;
|
282
|
+
va_list argptr;
|
283
|
+
va_start (argptr, format);
|
284
|
+
int required = vsnprintf (string, size, format, argptr);
|
285
|
+
va_end (argptr);
|
286
|
+
#ifdef _MSC_VER
|
287
|
+
if (required < 0 || required >= size) {
|
288
|
+
va_start (argptr, format);
|
289
|
+
required = _vscprintf (format, argptr);
|
290
|
+
va_end (argptr);
|
291
|
+
}
|
292
|
+
#endif
|
293
|
+
if (required >= size) {
|
294
|
+
size = required + 1;
|
295
|
+
string = (char *) malloc (size);
|
296
|
+
if (!string) {
|
297
|
+
return -1;
|
298
|
+
}
|
299
|
+
va_start (argptr, format);
|
300
|
+
size = vsnprintf (string, size, format, argptr);
|
301
|
+
va_end (argptr);
|
302
|
+
}
|
303
|
+
else
|
304
|
+
size = required;
|
305
|
+
|
306
|
+
self->content_size += size;
|
307
|
+
zlist_push (self->frames, zframe_new (string, size));
|
308
|
+
if (string!=stackbuffer)
|
309
|
+
free (string);
|
310
|
+
return 0;
|
311
|
+
}
|
312
|
+
|
313
|
+
|
314
|
+
// --------------------------------------------------------------------------
|
315
|
+
// Push string as new frame to end of message
|
316
|
+
|
317
|
+
int
|
318
|
+
zmsg_addstr (zmsg_t *self, const char *format, ...)
|
319
|
+
{
|
320
|
+
assert (self);
|
321
|
+
assert (format);
|
322
|
+
// Format string into buffer
|
323
|
+
int size = 255 + 1;
|
324
|
+
char stackbuffer[255+1];
|
325
|
+
char *string = stackbuffer;
|
326
|
+
va_list argptr;
|
327
|
+
va_start (argptr, format);
|
328
|
+
int required = vsnprintf (string, size, format, argptr);
|
329
|
+
va_end (argptr);
|
330
|
+
#ifdef _MSC_VER
|
331
|
+
if (required < 0 || required >= size) {
|
332
|
+
va_start (argptr, format);
|
333
|
+
required = _vscprintf (format, argptr);
|
334
|
+
va_end (argptr);
|
335
|
+
}
|
336
|
+
#endif
|
337
|
+
if (required >= size) {
|
338
|
+
size = required + 1;
|
339
|
+
string = (char *) malloc (size);
|
340
|
+
if (!string) {
|
341
|
+
return -1;
|
342
|
+
}
|
343
|
+
va_start (argptr, format);
|
344
|
+
size = vsnprintf (string, size, format, argptr);
|
345
|
+
va_end (argptr);
|
346
|
+
}
|
347
|
+
else
|
348
|
+
size = required;
|
349
|
+
|
350
|
+
self->content_size += size;
|
351
|
+
zlist_append (self->frames, zframe_new (string, size));
|
352
|
+
if (string!=stackbuffer)
|
353
|
+
free (string);
|
354
|
+
return 0;
|
355
|
+
}
|
356
|
+
|
357
|
+
|
358
|
+
// --------------------------------------------------------------------------
|
359
|
+
// Pop frame off front of message, return as fresh string
|
360
|
+
|
361
|
+
char *
|
362
|
+
zmsg_popstr (zmsg_t *self)
|
363
|
+
{
|
364
|
+
assert (self);
|
365
|
+
zframe_t *frame = (zframe_t *) zlist_pop (self->frames);
|
366
|
+
char *string = NULL;
|
367
|
+
if (frame) {
|
368
|
+
self->content_size -= zframe_size (frame);
|
369
|
+
string = zframe_strdup (frame);
|
370
|
+
zframe_destroy (&frame);
|
371
|
+
}
|
372
|
+
return string;
|
373
|
+
}
|
374
|
+
|
375
|
+
|
376
|
+
// --------------------------------------------------------------------------
|
377
|
+
// Push frame plus empty frame to front of message, before first frame.
|
378
|
+
// Message takes ownership of frame, will destroy it when message is sent.
|
379
|
+
|
380
|
+
void
|
381
|
+
zmsg_wrap (zmsg_t *self, zframe_t *frame)
|
382
|
+
{
|
383
|
+
assert (self);
|
384
|
+
assert (frame);
|
385
|
+
if (zmsg_pushmem (self, "", 0) == 0)
|
386
|
+
zmsg_push (self, frame);
|
387
|
+
}
|
388
|
+
|
389
|
+
|
390
|
+
// --------------------------------------------------------------------------
|
391
|
+
// Pop frame off front of message, caller now owns frame
|
392
|
+
// If next frame is empty, pops and destroys that empty frame.
|
393
|
+
|
394
|
+
zframe_t *
|
395
|
+
zmsg_unwrap (zmsg_t *self)
|
396
|
+
{
|
397
|
+
assert (self);
|
398
|
+
zframe_t *frame = zmsg_pop (self);
|
399
|
+
zframe_t *empty = zmsg_first (self);
|
400
|
+
if (zframe_size (empty) == 0) {
|
401
|
+
empty = zmsg_pop (self);
|
402
|
+
zframe_destroy (&empty);
|
403
|
+
}
|
404
|
+
return frame;
|
405
|
+
}
|
406
|
+
|
407
|
+
|
408
|
+
// --------------------------------------------------------------------------
|
409
|
+
// Remove specified frame from list, if present. Does not destroy frame.
|
410
|
+
|
411
|
+
void
|
412
|
+
zmsg_remove (zmsg_t *self, zframe_t *frame)
|
413
|
+
{
|
414
|
+
assert (self);
|
415
|
+
self->content_size -= zframe_size (frame);
|
416
|
+
zlist_remove (self->frames, frame);
|
417
|
+
}
|
418
|
+
|
419
|
+
|
420
|
+
// --------------------------------------------------------------------------
|
421
|
+
// Set cursor to first frame in message. Returns frame, or NULL.
|
422
|
+
|
423
|
+
zframe_t *
|
424
|
+
zmsg_first (zmsg_t *self)
|
425
|
+
{
|
426
|
+
assert (self);
|
427
|
+
return (zframe_t *) zlist_first (self->frames);
|
428
|
+
}
|
429
|
+
|
430
|
+
|
431
|
+
// --------------------------------------------------------------------------
|
432
|
+
// Return the next frame. If there are no more frames, returns NULL. To move
|
433
|
+
// to the first frame call zmsg_first(). Advances the cursor.
|
434
|
+
|
435
|
+
zframe_t *
|
436
|
+
zmsg_next (zmsg_t *self)
|
437
|
+
{
|
438
|
+
assert (self);
|
439
|
+
return (zframe_t *) zlist_next (self->frames);
|
440
|
+
}
|
441
|
+
|
442
|
+
|
443
|
+
// --------------------------------------------------------------------------
|
444
|
+
// Return the last frame. If there are no frames, returns NULL.
|
445
|
+
|
446
|
+
zframe_t *
|
447
|
+
zmsg_last (zmsg_t *self)
|
448
|
+
{
|
449
|
+
assert (self);
|
450
|
+
return (zframe_t *) zlist_last (self->frames);
|
451
|
+
}
|
452
|
+
|
453
|
+
|
454
|
+
// --------------------------------------------------------------------------
|
455
|
+
// Save message to an open file, return 0 if OK, else -1.
|
456
|
+
int
|
457
|
+
zmsg_save (zmsg_t *self, FILE *file)
|
458
|
+
{
|
459
|
+
assert (self);
|
460
|
+
assert (file);
|
461
|
+
|
462
|
+
zframe_t *frame = zmsg_first (self);
|
463
|
+
while (frame) {
|
464
|
+
size_t frame_size = zframe_size (frame);
|
465
|
+
if (fwrite (&frame_size, sizeof (frame_size), 1, file) != 1)
|
466
|
+
return -1;
|
467
|
+
if (fwrite (zframe_data (frame), frame_size, 1, file) != 1)
|
468
|
+
return -1;
|
469
|
+
frame = zmsg_next (self);
|
470
|
+
}
|
471
|
+
return 0;
|
472
|
+
}
|
473
|
+
|
474
|
+
|
475
|
+
// --------------------------------------------------------------------------
|
476
|
+
// Load/append an open file into message, create new message if
|
477
|
+
// null message provided. Returns NULL if the message could not be
|
478
|
+
// loaded.
|
479
|
+
|
480
|
+
zmsg_t *
|
481
|
+
zmsg_load (zmsg_t *self, FILE *file)
|
482
|
+
{
|
483
|
+
assert (file);
|
484
|
+
if (!self)
|
485
|
+
self = zmsg_new ();
|
486
|
+
if (!self)
|
487
|
+
return NULL;
|
488
|
+
|
489
|
+
while (true) {
|
490
|
+
size_t frame_size;
|
491
|
+
size_t rc = fread (&frame_size, sizeof (frame_size), 1, file);
|
492
|
+
if (rc == 1) {
|
493
|
+
zframe_t *frame = zframe_new (NULL, frame_size);
|
494
|
+
rc = fread (zframe_data (frame), frame_size, 1, file);
|
495
|
+
if (frame_size > 0 && rc != 1)
|
496
|
+
break; // Unable to read properly, quit
|
497
|
+
zmsg_add (self, frame);
|
498
|
+
}
|
499
|
+
else
|
500
|
+
break; // Unable to read properly, quit
|
501
|
+
}
|
502
|
+
return self;
|
503
|
+
}
|
504
|
+
|
505
|
+
|
506
|
+
// --------------------------------------------------------------------------
|
507
|
+
// Encode message to a new buffer, return buffer size
|
508
|
+
|
509
|
+
// Frame lengths are encoded as 1, 1+2, or 1+4 bytes
|
510
|
+
// 0..253 bytes octet + data
|
511
|
+
// 254..64k-1 bytes 0xFE + 2octet + data
|
512
|
+
// 64k..4Gb-1 bytes 0xFF + 4octet + data
|
513
|
+
|
514
|
+
#define ZMSG_SHORT_LEN 0xFE
|
515
|
+
#define ZMSG_LONG_LEN 0xFF
|
516
|
+
|
517
|
+
size_t
|
518
|
+
zmsg_encode (zmsg_t *self, byte **buffer)
|
519
|
+
{
|
520
|
+
assert (self);
|
521
|
+
|
522
|
+
// Calculate real size of buffer
|
523
|
+
size_t buffer_size = 0;
|
524
|
+
zframe_t *frame = zmsg_first (self);
|
525
|
+
while (frame) {
|
526
|
+
size_t frame_size = zframe_size (frame);
|
527
|
+
if (frame_size < ZMSG_SHORT_LEN)
|
528
|
+
buffer_size += frame_size + 1;
|
529
|
+
else
|
530
|
+
if (frame_size < 0x10000)
|
531
|
+
buffer_size += frame_size + 3;
|
532
|
+
else
|
533
|
+
buffer_size += frame_size + 5;
|
534
|
+
frame = zmsg_next (self);
|
535
|
+
}
|
536
|
+
*buffer = (byte *) malloc (buffer_size);
|
537
|
+
|
538
|
+
// Encode message now
|
539
|
+
byte *dest = *buffer;
|
540
|
+
frame = zmsg_first (self);
|
541
|
+
while (frame) {
|
542
|
+
size_t frame_size = zframe_size (frame);
|
543
|
+
if (frame_size < ZMSG_SHORT_LEN) {
|
544
|
+
*dest++ = (byte) frame_size;
|
545
|
+
memcpy (dest, zframe_data (frame), frame_size);
|
546
|
+
dest += frame_size;
|
547
|
+
}
|
548
|
+
else
|
549
|
+
if (frame_size < 0x10000) {
|
550
|
+
*dest++ = ZMSG_SHORT_LEN;
|
551
|
+
*dest++ = (frame_size >> 8) & 255;
|
552
|
+
*dest++ = frame_size & 255;
|
553
|
+
memcpy (dest, zframe_data (frame), frame_size);
|
554
|
+
dest += frame_size;
|
555
|
+
}
|
556
|
+
else {
|
557
|
+
*dest++ = ZMSG_LONG_LEN;
|
558
|
+
*dest++ = (frame_size >> 24) & 255;
|
559
|
+
*dest++ = (frame_size >> 16) & 255;
|
560
|
+
*dest++ = (frame_size >> 8) & 255;
|
561
|
+
*dest++ = frame_size & 255;
|
562
|
+
memcpy (dest, zframe_data (frame), frame_size);
|
563
|
+
dest += frame_size;
|
564
|
+
}
|
565
|
+
frame = zmsg_next (self);
|
566
|
+
}
|
567
|
+
assert ((dest - *buffer) == buffer_size);
|
568
|
+
return buffer_size;
|
569
|
+
}
|
570
|
+
|
571
|
+
|
572
|
+
// --------------------------------------------------------------------------
|
573
|
+
// Decode a buffer into a new message, returns NULL if buffer is not
|
574
|
+
// properly formatted or there is insufficient free memory.
|
575
|
+
|
576
|
+
zmsg_t *
|
577
|
+
zmsg_decode (byte *buffer, size_t buffer_size)
|
578
|
+
{
|
579
|
+
zmsg_t *self = zmsg_new ();
|
580
|
+
if (!self)
|
581
|
+
return NULL;
|
582
|
+
|
583
|
+
byte *source = buffer;
|
584
|
+
byte *limit = buffer + buffer_size;
|
585
|
+
while (source < limit) {
|
586
|
+
size_t frame_size = *source++;
|
587
|
+
if (frame_size == ZMSG_SHORT_LEN) {
|
588
|
+
if (source > limit - 2) {
|
589
|
+
zmsg_destroy (&self);
|
590
|
+
break;
|
591
|
+
}
|
592
|
+
frame_size = (source [0] << 8) + source [1];
|
593
|
+
source += 2;
|
594
|
+
}
|
595
|
+
else
|
596
|
+
if (frame_size == ZMSG_LONG_LEN) {
|
597
|
+
if (source > limit - 4) {
|
598
|
+
zmsg_destroy (&self);
|
599
|
+
break;
|
600
|
+
}
|
601
|
+
frame_size = (source [0] << 24)
|
602
|
+
+ (source [1] << 16)
|
603
|
+
+ (source [2] << 8)
|
604
|
+
+ source [3];
|
605
|
+
source += 4;
|
606
|
+
}
|
607
|
+
if (source > limit - frame_size) {
|
608
|
+
zmsg_destroy (&self);
|
609
|
+
break;
|
610
|
+
}
|
611
|
+
zframe_t *frame = zframe_new (source, frame_size);
|
612
|
+
if (frame) {
|
613
|
+
if (zmsg_add (self, frame)) {
|
614
|
+
zmsg_destroy (&self);
|
615
|
+
break;
|
616
|
+
}
|
617
|
+
source += frame_size;
|
618
|
+
}
|
619
|
+
else {
|
620
|
+
zmsg_destroy (&self);
|
621
|
+
break;
|
622
|
+
}
|
623
|
+
}
|
624
|
+
return self;
|
625
|
+
}
|
626
|
+
|
627
|
+
|
628
|
+
// --------------------------------------------------------------------------
|
629
|
+
// Create copy of message, as new message object
|
630
|
+
|
631
|
+
zmsg_t *
|
632
|
+
zmsg_dup (zmsg_t *self)
|
633
|
+
{
|
634
|
+
assert (self);
|
635
|
+
zframe_t *frame = zmsg_first (self);
|
636
|
+
if (!frame)
|
637
|
+
return NULL;
|
638
|
+
|
639
|
+
zmsg_t *copy = zmsg_new ();
|
640
|
+
if (!copy)
|
641
|
+
return NULL;
|
642
|
+
|
643
|
+
while (frame) {
|
644
|
+
if (zmsg_addmem (copy, zframe_data (frame), zframe_size (frame))) {
|
645
|
+
zmsg_destroy (©);
|
646
|
+
return NULL;
|
647
|
+
}
|
648
|
+
frame = zmsg_next (self);
|
649
|
+
}
|
650
|
+
return copy;
|
651
|
+
}
|
652
|
+
|
653
|
+
|
654
|
+
// --------------------------------------------------------------------------
|
655
|
+
// Dump message to stderr, for debugging and tracing
|
656
|
+
// Truncates to first 10 frames, for readability; this may be unfortunate
|
657
|
+
// when debugging larger and more complex messages. Perhaps a way to hide
|
658
|
+
// repeated lines instead?
|
659
|
+
|
660
|
+
void
|
661
|
+
zmsg_dump (zmsg_t *self)
|
662
|
+
{
|
663
|
+
fprintf (stderr, "--------------------------------------\n");
|
664
|
+
if (!self) {
|
665
|
+
fprintf (stderr, "NULL");
|
666
|
+
return;
|
667
|
+
}
|
668
|
+
zframe_t *frame = zmsg_first (self);
|
669
|
+
int frame_nbr = 0;
|
670
|
+
while (frame && frame_nbr++ < 10) {
|
671
|
+
zframe_print (frame, "");
|
672
|
+
frame = zmsg_next (self);
|
673
|
+
}
|
674
|
+
}
|
675
|
+
|
676
|
+
|
677
|
+
// --------------------------------------------------------------------------
|
678
|
+
// Selftest
|
679
|
+
|
680
|
+
int
|
681
|
+
zmsg_test (bool verbose)
|
682
|
+
{
|
683
|
+
printf (" * zmsg: ");
|
684
|
+
|
685
|
+
int rc = 0;
|
686
|
+
// @selftest
|
687
|
+
zctx_t *ctx = zctx_new ();
|
688
|
+
assert (ctx);
|
689
|
+
|
690
|
+
void *output = zsocket_new (ctx, ZMQ_PAIR);
|
691
|
+
assert (output);
|
692
|
+
zsocket_bind (output, "inproc://zmsg.test");
|
693
|
+
void *input = zsocket_new (ctx, ZMQ_PAIR);
|
694
|
+
assert (input);
|
695
|
+
zsocket_connect (input, "inproc://zmsg.test");
|
696
|
+
|
697
|
+
// Test send and receive of single-frame message
|
698
|
+
zmsg_t *msg = zmsg_new ();
|
699
|
+
assert (msg);
|
700
|
+
zframe_t *frame = zframe_new ("Hello", 5);
|
701
|
+
assert (frame);
|
702
|
+
zmsg_push (msg, frame);
|
703
|
+
assert (zmsg_size (msg) == 1);
|
704
|
+
assert (zmsg_content_size (msg) == 5);
|
705
|
+
rc = zmsg_send (&msg, output);
|
706
|
+
assert (msg == NULL);
|
707
|
+
assert (rc == 0);
|
708
|
+
|
709
|
+
msg = zmsg_recv (input);
|
710
|
+
assert (msg);
|
711
|
+
assert (zmsg_size (msg) == 1);
|
712
|
+
assert (zmsg_content_size (msg) == 5);
|
713
|
+
zmsg_destroy (&msg);
|
714
|
+
|
715
|
+
// Test send and receive of multi-frame message
|
716
|
+
msg = zmsg_new ();
|
717
|
+
assert (msg);
|
718
|
+
rc = zmsg_addmem (msg, "Frame0", 6);
|
719
|
+
assert (rc == 0);
|
720
|
+
rc = zmsg_addmem (msg, "Frame1", 6);
|
721
|
+
assert (rc == 0);
|
722
|
+
rc = zmsg_addmem (msg, "Frame2", 6);
|
723
|
+
assert (rc == 0);
|
724
|
+
rc = zmsg_addmem (msg, "Frame3", 6);
|
725
|
+
assert (rc == 0);
|
726
|
+
rc = zmsg_addmem (msg, "Frame4", 6);
|
727
|
+
assert (rc == 0);
|
728
|
+
rc = zmsg_addmem (msg, "Frame5", 6);
|
729
|
+
assert (rc == 0);
|
730
|
+
rc = zmsg_addmem (msg, "Frame6", 6);
|
731
|
+
assert (rc == 0);
|
732
|
+
rc = zmsg_addmem (msg, "Frame7", 6);
|
733
|
+
assert (rc == 0);
|
734
|
+
rc = zmsg_addmem (msg, "Frame8", 6);
|
735
|
+
assert (rc == 0);
|
736
|
+
rc = zmsg_addmem (msg, "Frame9", 6);
|
737
|
+
assert (rc == 0);
|
738
|
+
zmsg_t *copy = zmsg_dup (msg);
|
739
|
+
assert (copy);
|
740
|
+
rc = zmsg_send (©, output);
|
741
|
+
assert (rc == 0);
|
742
|
+
rc = zmsg_send (&msg, output);
|
743
|
+
assert (rc == 0);
|
744
|
+
|
745
|
+
copy = zmsg_recv (input);
|
746
|
+
assert (copy);
|
747
|
+
assert (zmsg_size (copy) == 10);
|
748
|
+
assert (zmsg_content_size (copy) == 60);
|
749
|
+
zmsg_destroy (©);
|
750
|
+
|
751
|
+
msg = zmsg_recv (input);
|
752
|
+
assert (msg);
|
753
|
+
assert (zmsg_size (msg) == 10);
|
754
|
+
assert (zmsg_content_size (msg) == 60);
|
755
|
+
if (verbose)
|
756
|
+
zmsg_dump (msg);
|
757
|
+
|
758
|
+
// Save to a file, read back
|
759
|
+
FILE *file = fopen ("zmsg.test", "w");
|
760
|
+
assert (file);
|
761
|
+
rc = zmsg_save (msg, file);
|
762
|
+
assert (rc == 0);
|
763
|
+
fclose (file);
|
764
|
+
|
765
|
+
file = fopen ("zmsg.test", "r");
|
766
|
+
rc = zmsg_save (msg, file);
|
767
|
+
assert (rc == -1);
|
768
|
+
fclose (file);
|
769
|
+
zmsg_destroy (&msg);
|
770
|
+
|
771
|
+
file = fopen ("zmsg.test", "r");
|
772
|
+
msg = zmsg_load (NULL, file);
|
773
|
+
assert (msg);
|
774
|
+
fclose (file);
|
775
|
+
remove ("zmsg.test");
|
776
|
+
assert (zmsg_size (msg) == 10);
|
777
|
+
assert (zmsg_content_size (msg) == 60);
|
778
|
+
|
779
|
+
// Remove all frames except first and last
|
780
|
+
int frame_nbr;
|
781
|
+
for (frame_nbr = 0; frame_nbr < 8; frame_nbr++) {
|
782
|
+
zmsg_first (msg);
|
783
|
+
frame = zmsg_next (msg);
|
784
|
+
zmsg_remove (msg, frame);
|
785
|
+
zframe_destroy (&frame);
|
786
|
+
}
|
787
|
+
// Test message frame manipulation
|
788
|
+
assert (zmsg_size (msg) == 2);
|
789
|
+
frame = zmsg_last (msg);
|
790
|
+
assert (zframe_streq (frame, "Frame9"));
|
791
|
+
assert (zmsg_content_size (msg) == 12);
|
792
|
+
frame = zframe_new ("Address", 7);
|
793
|
+
assert (frame);
|
794
|
+
zmsg_wrap (msg, frame);
|
795
|
+
assert (zmsg_size (msg) == 4);
|
796
|
+
rc = zmsg_addstr (msg, "Body");
|
797
|
+
assert (rc == 0);
|
798
|
+
assert (zmsg_size (msg) == 5);
|
799
|
+
frame = zmsg_unwrap (msg);
|
800
|
+
zframe_destroy (&frame);
|
801
|
+
assert (zmsg_size (msg) == 3);
|
802
|
+
char *body = zmsg_popstr (msg);
|
803
|
+
assert (streq (body, "Frame0"));
|
804
|
+
free (body);
|
805
|
+
zmsg_destroy (&msg);
|
806
|
+
|
807
|
+
// Test encoding/decoding
|
808
|
+
msg = zmsg_new ();
|
809
|
+
assert (msg);
|
810
|
+
byte *blank = (byte *) zmalloc (100000);
|
811
|
+
assert (blank);
|
812
|
+
rc = zmsg_addmem (msg, blank, 0);
|
813
|
+
assert (rc == 0);
|
814
|
+
rc = zmsg_addmem (msg, blank, 1);
|
815
|
+
assert (rc == 0);
|
816
|
+
rc = zmsg_addmem (msg, blank, 253);
|
817
|
+
assert (rc == 0);
|
818
|
+
rc = zmsg_addmem (msg, blank, 254);
|
819
|
+
assert (rc == 0);
|
820
|
+
rc = zmsg_addmem (msg, blank, 255);
|
821
|
+
assert (rc == 0);
|
822
|
+
rc = zmsg_addmem (msg, blank, 256);
|
823
|
+
assert (rc == 0);
|
824
|
+
rc = zmsg_addmem (msg, blank, 65535);
|
825
|
+
assert (rc == 0);
|
826
|
+
rc = zmsg_addmem (msg, blank, 65536);
|
827
|
+
assert (rc == 0);
|
828
|
+
rc = zmsg_addmem (msg, blank, 65537);
|
829
|
+
assert (rc == 0);
|
830
|
+
free (blank);
|
831
|
+
assert (zmsg_size (msg) == 9);
|
832
|
+
byte *buffer;
|
833
|
+
size_t buffer_size = zmsg_encode (msg, &buffer);
|
834
|
+
zmsg_destroy (&msg);
|
835
|
+
msg = zmsg_decode (buffer, buffer_size);
|
836
|
+
assert (msg);
|
837
|
+
free (buffer);
|
838
|
+
zmsg_destroy (&msg);
|
839
|
+
|
840
|
+
// Now try methods on an empty message
|
841
|
+
msg = zmsg_new ();
|
842
|
+
assert (msg);
|
843
|
+
assert (zmsg_size (msg) == 0);
|
844
|
+
assert (zmsg_first (msg) == NULL);
|
845
|
+
assert (zmsg_last (msg) == NULL);
|
846
|
+
assert (zmsg_next (msg) == NULL);
|
847
|
+
assert (zmsg_pop (msg) == NULL);
|
848
|
+
zmsg_destroy (&msg);
|
849
|
+
|
850
|
+
zctx_destroy (&ctx);
|
851
|
+
// @end
|
852
|
+
printf ("OK\n");
|
853
|
+
return 0;
|
854
|
+
}
|