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
@@ -0,0 +1,255 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2007-2012 iMatix Corporation
|
3
|
+
Copyright (c) 2009-2011 250bpm s.r.o.
|
4
|
+
Copyright (c) 2011 VMware, Inc.
|
5
|
+
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
|
6
|
+
|
7
|
+
This file is part of 0MQ.
|
8
|
+
|
9
|
+
0MQ is free software; you can redistribute it and/or modify it under
|
10
|
+
the terms of the GNU Lesser General Public License as published by
|
11
|
+
the Free Software Foundation; either version 3 of the License, or
|
12
|
+
(at your option) any later version.
|
13
|
+
|
14
|
+
0MQ is distributed in the hope that it will be useful,
|
15
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
GNU Lesser General Public License for more details.
|
18
|
+
|
19
|
+
You should have received a copy of the GNU Lesser General Public License
|
20
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
*/
|
22
|
+
|
23
|
+
#ifndef __ZMQ_SOCKET_BASE_HPP_INCLUDED__
|
24
|
+
#define __ZMQ_SOCKET_BASE_HPP_INCLUDED__
|
25
|
+
|
26
|
+
#include <string>
|
27
|
+
#include <map>
|
28
|
+
#include <stdarg.h>
|
29
|
+
|
30
|
+
#include "own.hpp"
|
31
|
+
#include "array.hpp"
|
32
|
+
#include "stdint.hpp"
|
33
|
+
#include "poller.hpp"
|
34
|
+
#include "atomic_counter.hpp"
|
35
|
+
#include "i_poll_events.hpp"
|
36
|
+
#include "mailbox.hpp"
|
37
|
+
#include "stdint.hpp"
|
38
|
+
#include "clock.hpp"
|
39
|
+
#include "pipe.hpp"
|
40
|
+
|
41
|
+
extern "C"
|
42
|
+
{
|
43
|
+
void zmq_free_event (void *data, void *hint);
|
44
|
+
}
|
45
|
+
|
46
|
+
namespace zmq
|
47
|
+
{
|
48
|
+
|
49
|
+
class ctx_t;
|
50
|
+
class msg_t;
|
51
|
+
class pipe_t;
|
52
|
+
|
53
|
+
class socket_base_t :
|
54
|
+
public own_t,
|
55
|
+
public array_item_t <>,
|
56
|
+
public i_poll_events,
|
57
|
+
public i_pipe_events
|
58
|
+
{
|
59
|
+
friend class reaper_t;
|
60
|
+
|
61
|
+
public:
|
62
|
+
|
63
|
+
// Returns false if object is not a socket.
|
64
|
+
bool check_tag ();
|
65
|
+
|
66
|
+
// Create a socket of a specified type.
|
67
|
+
static socket_base_t *create (int type_, zmq::ctx_t *parent_,
|
68
|
+
uint32_t tid_, int sid_);
|
69
|
+
|
70
|
+
// Returns the mailbox associated with this socket.
|
71
|
+
mailbox_t *get_mailbox ();
|
72
|
+
|
73
|
+
// Interrupt blocking call if the socket is stuck in one.
|
74
|
+
// This function can be called from a different thread!
|
75
|
+
void stop ();
|
76
|
+
|
77
|
+
// Interface for communication with the API layer.
|
78
|
+
int setsockopt (int option_, const void *optval_, size_t optvallen_);
|
79
|
+
int getsockopt (int option_, void *optval_, size_t *optvallen_);
|
80
|
+
int bind (const char *addr_);
|
81
|
+
int connect (const char *addr_);
|
82
|
+
int term_endpoint (const char *addr_);
|
83
|
+
int send (zmq::msg_t *msg_, int flags_);
|
84
|
+
int recv (zmq::msg_t *msg_, int flags_);
|
85
|
+
int close ();
|
86
|
+
|
87
|
+
// These functions are used by the polling mechanism to determine
|
88
|
+
// which events are to be reported from this socket.
|
89
|
+
bool has_in ();
|
90
|
+
bool has_out ();
|
91
|
+
|
92
|
+
// Using this function reaper thread ask the socket to regiter with
|
93
|
+
// its poller.
|
94
|
+
void start_reaping (poller_t *poller_);
|
95
|
+
|
96
|
+
// i_poll_events implementation. This interface is used when socket
|
97
|
+
// is handled by the poller in the reaper thread.
|
98
|
+
void in_event ();
|
99
|
+
void out_event ();
|
100
|
+
void timer_event (int id_);
|
101
|
+
|
102
|
+
// i_pipe_events interface implementation.
|
103
|
+
void read_activated (pipe_t *pipe_);
|
104
|
+
void write_activated (pipe_t *pipe_);
|
105
|
+
void hiccuped (pipe_t *pipe_);
|
106
|
+
void terminated (pipe_t *pipe_);
|
107
|
+
void lock();
|
108
|
+
void unlock();
|
109
|
+
|
110
|
+
int monitor(const char *endpoint_, int events_);
|
111
|
+
|
112
|
+
void event_connected (std::string &addr_, int fd_);
|
113
|
+
void event_connect_delayed (std::string &addr_, int err_);
|
114
|
+
void event_connect_retried (std::string &addr_, int interval_);
|
115
|
+
void event_listening (std::string &addr_, int fd_);
|
116
|
+
void event_bind_failed (std::string &addr_, int err_);
|
117
|
+
void event_accepted (std::string &addr_, int fd_);
|
118
|
+
void event_accept_failed (std::string &addr_, int err_);
|
119
|
+
void event_closed (std::string &addr_, int fd_);
|
120
|
+
void event_close_failed (std::string &addr_, int fd_);
|
121
|
+
void event_disconnected (std::string &addr_, int fd_);
|
122
|
+
|
123
|
+
protected:
|
124
|
+
|
125
|
+
socket_base_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_);
|
126
|
+
virtual ~socket_base_t ();
|
127
|
+
|
128
|
+
// Concrete algorithms for the x- methods are to be defined by
|
129
|
+
// individual socket types.
|
130
|
+
virtual void xattach_pipe (zmq::pipe_t *pipe_,
|
131
|
+
bool icanhasall_ = false) = 0;
|
132
|
+
|
133
|
+
// The default implementation assumes there are no specific socket
|
134
|
+
// options for the particular socket type. If not so, overload this
|
135
|
+
// method.
|
136
|
+
virtual int xsetsockopt (int option_, const void *optval_,
|
137
|
+
size_t optvallen_);
|
138
|
+
|
139
|
+
// The default implementation assumes that send is not supported.
|
140
|
+
virtual bool xhas_out ();
|
141
|
+
virtual int xsend (zmq::msg_t *msg_, int flags_);
|
142
|
+
|
143
|
+
// The default implementation assumes that recv in not supported.
|
144
|
+
virtual bool xhas_in ();
|
145
|
+
virtual int xrecv (zmq::msg_t *msg_, int flags_);
|
146
|
+
|
147
|
+
// i_pipe_events will be forwarded to these functions.
|
148
|
+
virtual void xread_activated (pipe_t *pipe_);
|
149
|
+
virtual void xwrite_activated (pipe_t *pipe_);
|
150
|
+
virtual void xhiccuped (pipe_t *pipe_);
|
151
|
+
virtual void xterminated (pipe_t *pipe_) = 0;
|
152
|
+
|
153
|
+
// Delay actual destruction of the socket.
|
154
|
+
void process_destroy ();
|
155
|
+
|
156
|
+
// Socket event data dispath
|
157
|
+
void monitor_event (zmq_event_t data_);
|
158
|
+
|
159
|
+
// Copy monitor specific event endpoints to event messages
|
160
|
+
void copy_monitor_address (char *dest_, std::string &src_);
|
161
|
+
|
162
|
+
// Monitor socket cleanup
|
163
|
+
void stop_monitor ();
|
164
|
+
|
165
|
+
private:
|
166
|
+
// Creates new endpoint ID and adds the endpoint to the map.
|
167
|
+
void add_endpoint (const char *addr_, own_t *endpoint_);
|
168
|
+
|
169
|
+
// Map of open endpoints.
|
170
|
+
typedef std::multimap <std::string, own_t *> endpoints_t;
|
171
|
+
endpoints_t endpoints;
|
172
|
+
|
173
|
+
// Map of open inproc endpoints.
|
174
|
+
typedef std::multimap <std::string, pipe_t *> inprocs_t;
|
175
|
+
inprocs_t inprocs;
|
176
|
+
|
177
|
+
// To be called after processing commands or invoking any command
|
178
|
+
// handlers explicitly. If required, it will deallocate the socket.
|
179
|
+
void check_destroy ();
|
180
|
+
|
181
|
+
// Moves the flags from the message to local variables,
|
182
|
+
// to be later retrieved by getsockopt.
|
183
|
+
void extract_flags (msg_t *msg_);
|
184
|
+
|
185
|
+
// Used to check whether the object is a socket.
|
186
|
+
uint32_t tag;
|
187
|
+
|
188
|
+
// If true, associated context was already terminated.
|
189
|
+
bool ctx_terminated;
|
190
|
+
|
191
|
+
// If true, object should have been already destroyed. However,
|
192
|
+
// destruction is delayed while we unwind the stack to the point
|
193
|
+
// where it doesn't intersect the object being destroyed.
|
194
|
+
bool destroyed;
|
195
|
+
|
196
|
+
// Parse URI string.
|
197
|
+
int parse_uri (const char *uri_, std::string &protocol_,
|
198
|
+
std::string &address_);
|
199
|
+
|
200
|
+
// Check whether transport protocol, as specified in connect or
|
201
|
+
// bind, is available and compatible with the socket type.
|
202
|
+
int check_protocol (const std::string &protocol_);
|
203
|
+
|
204
|
+
// Register the pipe with this socket.
|
205
|
+
void attach_pipe (zmq::pipe_t *pipe_, bool icanhasall_ = false);
|
206
|
+
|
207
|
+
// Processes commands sent to this socket (if any). If timeout is -1,
|
208
|
+
// returns only after at least one command was processed.
|
209
|
+
// If throttle argument is true, commands are processed at most once
|
210
|
+
// in a predefined time period.
|
211
|
+
int process_commands (int timeout_, bool throttle_);
|
212
|
+
|
213
|
+
// Handlers for incoming commands.
|
214
|
+
void process_stop ();
|
215
|
+
void process_bind (zmq::pipe_t *pipe_);
|
216
|
+
void process_term (int linger_);
|
217
|
+
|
218
|
+
// Socket's mailbox object.
|
219
|
+
mailbox_t mailbox;
|
220
|
+
|
221
|
+
// List of attached pipes.
|
222
|
+
typedef array_t <pipe_t, 3> pipes_t;
|
223
|
+
pipes_t pipes;
|
224
|
+
|
225
|
+
// Reaper's poller and handle of this socket within it.
|
226
|
+
poller_t *poller;
|
227
|
+
poller_t::handle_t handle;
|
228
|
+
|
229
|
+
// Timestamp of when commands were processed the last time.
|
230
|
+
uint64_t last_tsc;
|
231
|
+
|
232
|
+
// Number of messages received since last command processing.
|
233
|
+
int ticks;
|
234
|
+
|
235
|
+
// True if the last message received had MORE flag set.
|
236
|
+
bool rcvmore;
|
237
|
+
|
238
|
+
// Improves efficiency of time measurement.
|
239
|
+
clock_t clock;
|
240
|
+
|
241
|
+
// Monitor socket;
|
242
|
+
void *monitor_socket;
|
243
|
+
|
244
|
+
// Bitmask of events being monitored
|
245
|
+
int monitor_events;
|
246
|
+
|
247
|
+
socket_base_t (const socket_base_t&);
|
248
|
+
const socket_base_t &operator = (const socket_base_t&);
|
249
|
+
mutex_t sync;
|
250
|
+
};
|
251
|
+
|
252
|
+
}
|
253
|
+
|
254
|
+
#endif
|
255
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2007-2009 iMatix Corporation
|
3
|
+
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
|
4
|
+
|
5
|
+
This file is part of 0MQ.
|
6
|
+
|
7
|
+
0MQ is free software; you can redistribute it and/or modify it under
|
8
|
+
the terms of the GNU Lesser General Public License as published by
|
9
|
+
the Free Software Foundation; either version 3 of the License, or
|
10
|
+
(at your option) any later version.
|
11
|
+
|
12
|
+
0MQ is distributed in the hope that it will be useful,
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
GNU Lesser General Public License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU Lesser General Public License
|
18
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
|
21
|
+
#ifndef __ZMQ_STDINT_HPP_INCLUDED__
|
22
|
+
#define __ZMQ_STDINT_HPP_INCLUDED__
|
23
|
+
|
24
|
+
#include "platform.hpp"
|
25
|
+
|
26
|
+
#if defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_OPENVMS
|
27
|
+
|
28
|
+
#include <inttypes.h>
|
29
|
+
|
30
|
+
#elif defined _MSC_VER && _MSC_VER < 1600
|
31
|
+
|
32
|
+
#ifndef int8_t
|
33
|
+
typedef __int8 int8_t;
|
34
|
+
#endif
|
35
|
+
#ifndef int16_t
|
36
|
+
typedef __int16 int16_t;
|
37
|
+
#endif
|
38
|
+
#ifndef int32_t
|
39
|
+
typedef __int32 int32_t;
|
40
|
+
#endif
|
41
|
+
#ifndef int64_t
|
42
|
+
typedef __int64 int64_t;
|
43
|
+
#endif
|
44
|
+
#ifndef uint8_t
|
45
|
+
typedef unsigned __int8 uint8_t;
|
46
|
+
#endif
|
47
|
+
#ifndef uint16_t
|
48
|
+
typedef unsigned __int16 uint16_t;
|
49
|
+
#endif
|
50
|
+
#ifndef uint32_t
|
51
|
+
typedef unsigned __int32 uint32_t;
|
52
|
+
#endif
|
53
|
+
#ifndef uint64_t
|
54
|
+
typedef unsigned __int64 uint64_t;
|
55
|
+
#endif
|
56
|
+
|
57
|
+
#else
|
58
|
+
|
59
|
+
#include <stdint.h>
|
60
|
+
|
61
|
+
#endif
|
62
|
+
|
63
|
+
#endif
|
@@ -0,0 +1,594 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2009-2011 250bpm s.r.o.
|
3
|
+
Copyright (c) 2007-2009 iMatix Corporation
|
4
|
+
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
|
5
|
+
|
6
|
+
This file is part of 0MQ.
|
7
|
+
|
8
|
+
0MQ is free software; you can redistribute it and/or modify it under
|
9
|
+
the terms of the GNU Lesser General Public License as published by
|
10
|
+
the Free Software Foundation; either version 3 of the License, or
|
11
|
+
(at your option) any later version.
|
12
|
+
|
13
|
+
0MQ is distributed in the hope that it will be useful,
|
14
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
GNU Lesser General Public License for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU Lesser General Public License
|
19
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
*/
|
21
|
+
|
22
|
+
#include "platform.hpp"
|
23
|
+
#if defined ZMQ_HAVE_WINDOWS
|
24
|
+
#include "windows.hpp"
|
25
|
+
#else
|
26
|
+
#include <unistd.h>
|
27
|
+
#include <sys/socket.h>
|
28
|
+
#include <arpa/inet.h>
|
29
|
+
#include <netinet/tcp.h>
|
30
|
+
#include <netinet/in.h>
|
31
|
+
#include <netdb.h>
|
32
|
+
#include <fcntl.h>
|
33
|
+
#endif
|
34
|
+
|
35
|
+
#include <string.h>
|
36
|
+
#include <new>
|
37
|
+
|
38
|
+
#include "stream_engine.hpp"
|
39
|
+
#include "io_thread.hpp"
|
40
|
+
#include "session_base.hpp"
|
41
|
+
#include "encoder.hpp"
|
42
|
+
#include "decoder.hpp"
|
43
|
+
#include "v1_encoder.hpp"
|
44
|
+
#include "v1_decoder.hpp"
|
45
|
+
#include "config.hpp"
|
46
|
+
#include "err.hpp"
|
47
|
+
#include "ip.hpp"
|
48
|
+
#include "likely.hpp"
|
49
|
+
#include "wire.hpp"
|
50
|
+
|
51
|
+
zmq::stream_engine_t::stream_engine_t (fd_t fd_, const options_t &options_, const std::string &endpoint_) :
|
52
|
+
s (fd_),
|
53
|
+
io_enabled (false),
|
54
|
+
inpos (NULL),
|
55
|
+
insize (0),
|
56
|
+
decoder (NULL),
|
57
|
+
outpos (NULL),
|
58
|
+
outsize (0),
|
59
|
+
encoder (NULL),
|
60
|
+
handshaking (true),
|
61
|
+
greeting_bytes_read (0),
|
62
|
+
session (NULL),
|
63
|
+
options (options_),
|
64
|
+
endpoint (endpoint_),
|
65
|
+
plugged (false),
|
66
|
+
terminating (false),
|
67
|
+
socket (NULL)
|
68
|
+
{
|
69
|
+
// Put the socket into non-blocking mode.
|
70
|
+
unblock_socket (s);
|
71
|
+
// Set the socket buffer limits for the underlying socket.
|
72
|
+
if (options.sndbuf) {
|
73
|
+
int rc = setsockopt (s, SOL_SOCKET, SO_SNDBUF,
|
74
|
+
(char*) &options.sndbuf, sizeof (int));
|
75
|
+
#ifdef ZMQ_HAVE_WINDOWS
|
76
|
+
wsa_assert (rc != SOCKET_ERROR);
|
77
|
+
#else
|
78
|
+
errno_assert (rc == 0);
|
79
|
+
#endif
|
80
|
+
}
|
81
|
+
if (options.rcvbuf) {
|
82
|
+
int rc = setsockopt (s, SOL_SOCKET, SO_RCVBUF,
|
83
|
+
(char*) &options.rcvbuf, sizeof (int));
|
84
|
+
#ifdef ZMQ_HAVE_WINDOWS
|
85
|
+
wsa_assert (rc != SOCKET_ERROR);
|
86
|
+
#else
|
87
|
+
errno_assert (rc == 0);
|
88
|
+
#endif
|
89
|
+
}
|
90
|
+
|
91
|
+
#ifdef SO_NOSIGPIPE
|
92
|
+
// Make sure that SIGPIPE signal is not generated when writing to a
|
93
|
+
// connection that was already closed by the peer.
|
94
|
+
int set = 1;
|
95
|
+
int rc = setsockopt (s, SOL_SOCKET, SO_NOSIGPIPE, &set, sizeof (int));
|
96
|
+
errno_assert (rc == 0);
|
97
|
+
#endif
|
98
|
+
}
|
99
|
+
|
100
|
+
zmq::stream_engine_t::~stream_engine_t ()
|
101
|
+
{
|
102
|
+
zmq_assert (!plugged);
|
103
|
+
|
104
|
+
if (s != retired_fd) {
|
105
|
+
#ifdef ZMQ_HAVE_WINDOWS
|
106
|
+
int rc = closesocket (s);
|
107
|
+
wsa_assert (rc != SOCKET_ERROR);
|
108
|
+
#else
|
109
|
+
int rc = close (s);
|
110
|
+
errno_assert (rc == 0);
|
111
|
+
#endif
|
112
|
+
s = retired_fd;
|
113
|
+
}
|
114
|
+
|
115
|
+
if (encoder != NULL)
|
116
|
+
delete encoder;
|
117
|
+
if (decoder != NULL)
|
118
|
+
delete decoder;
|
119
|
+
}
|
120
|
+
|
121
|
+
void zmq::stream_engine_t::plug (io_thread_t *io_thread_,
|
122
|
+
session_base_t *session_)
|
123
|
+
{
|
124
|
+
zmq_assert (!plugged);
|
125
|
+
plugged = true;
|
126
|
+
|
127
|
+
// Connect to session object.
|
128
|
+
zmq_assert (!session);
|
129
|
+
zmq_assert (session_);
|
130
|
+
session = session_;
|
131
|
+
socket = session-> get_socket ();
|
132
|
+
|
133
|
+
// Connect to I/O threads poller object.
|
134
|
+
io_object_t::plug (io_thread_);
|
135
|
+
handle = add_fd (s);
|
136
|
+
io_enabled = true;
|
137
|
+
|
138
|
+
// Send the 'length' and 'flags' fields of the identity message.
|
139
|
+
// The 'length' field is encoded in the long format.
|
140
|
+
outpos = greeting_output_buffer;
|
141
|
+
outpos [outsize++] = 0xff;
|
142
|
+
put_uint64 (&outpos [outsize], options.identity_size + 1);
|
143
|
+
outsize += 8;
|
144
|
+
outpos [outsize++] = 0x7f;
|
145
|
+
|
146
|
+
set_pollin (handle);
|
147
|
+
set_pollout (handle);
|
148
|
+
// Flush all the data that may have been already received downstream.
|
149
|
+
in_event ();
|
150
|
+
}
|
151
|
+
|
152
|
+
void zmq::stream_engine_t::unplug ()
|
153
|
+
{
|
154
|
+
zmq_assert (plugged);
|
155
|
+
plugged = false;
|
156
|
+
|
157
|
+
// Cancel all fd subscriptions.
|
158
|
+
if (io_enabled) {
|
159
|
+
rm_fd (handle);
|
160
|
+
io_enabled = false;
|
161
|
+
}
|
162
|
+
|
163
|
+
// Disconnect from I/O threads poller object.
|
164
|
+
io_object_t::unplug ();
|
165
|
+
|
166
|
+
// Disconnect from session object.
|
167
|
+
if (encoder)
|
168
|
+
encoder->set_msg_source (NULL);
|
169
|
+
if (decoder)
|
170
|
+
decoder->set_msg_sink (NULL);
|
171
|
+
session = NULL;
|
172
|
+
}
|
173
|
+
|
174
|
+
void zmq::stream_engine_t::terminate ()
|
175
|
+
{
|
176
|
+
if (!terminating && encoder && encoder->has_data ()) {
|
177
|
+
// Give io_thread a chance to send in the buffer
|
178
|
+
terminating = true;
|
179
|
+
return;
|
180
|
+
}
|
181
|
+
unplug ();
|
182
|
+
delete this;
|
183
|
+
}
|
184
|
+
|
185
|
+
void zmq::stream_engine_t::in_event ()
|
186
|
+
{
|
187
|
+
// If still handshaking, receive and prcess the greeting message.
|
188
|
+
if (unlikely (handshaking))
|
189
|
+
if (!handshake ())
|
190
|
+
return;
|
191
|
+
|
192
|
+
zmq_assert (decoder);
|
193
|
+
bool disconnection = false;
|
194
|
+
|
195
|
+
// If there's no data to process in the buffer...
|
196
|
+
if (!insize) {
|
197
|
+
|
198
|
+
// Retrieve the buffer and read as much data as possible.
|
199
|
+
// Note that buffer can be arbitrarily large. However, we assume
|
200
|
+
// the underlying TCP layer has fixed buffer size and thus the
|
201
|
+
// number of bytes read will be always limited.
|
202
|
+
decoder->get_buffer (&inpos, &insize);
|
203
|
+
insize = read (inpos, insize);
|
204
|
+
|
205
|
+
// Check whether the peer has closed the connection.
|
206
|
+
if (insize == (size_t) -1) {
|
207
|
+
insize = 0;
|
208
|
+
disconnection = true;
|
209
|
+
}
|
210
|
+
}
|
211
|
+
|
212
|
+
// Push the data to the decoder.
|
213
|
+
size_t processed = decoder->process_buffer (inpos, insize);
|
214
|
+
|
215
|
+
if (unlikely (processed == (size_t) -1)) {
|
216
|
+
disconnection = true;
|
217
|
+
}
|
218
|
+
else {
|
219
|
+
|
220
|
+
// Stop polling for input if we got stuck.
|
221
|
+
if (processed < insize)
|
222
|
+
reset_pollin (handle);
|
223
|
+
|
224
|
+
// Adjust the buffer.
|
225
|
+
inpos += processed;
|
226
|
+
insize -= processed;
|
227
|
+
}
|
228
|
+
|
229
|
+
// Flush all messages the decoder may have produced.
|
230
|
+
session->flush ();
|
231
|
+
|
232
|
+
// Input error has occurred. If the last decoded
|
233
|
+
// message has already been accepted, we terminate
|
234
|
+
// the engine immediately. Otherwise, we stop
|
235
|
+
// waiting for input events and postpone the termination
|
236
|
+
// until after the session has accepted the message.
|
237
|
+
if (disconnection) {
|
238
|
+
if (decoder->stalled ()) {
|
239
|
+
rm_fd (handle);
|
240
|
+
io_enabled = false;
|
241
|
+
}
|
242
|
+
else
|
243
|
+
error ();
|
244
|
+
}
|
245
|
+
}
|
246
|
+
|
247
|
+
void zmq::stream_engine_t::out_event ()
|
248
|
+
{
|
249
|
+
// If write buffer is empty, try to read new data from the encoder.
|
250
|
+
if (!outsize) {
|
251
|
+
|
252
|
+
// Even when we stop polling as soon as there is no
|
253
|
+
// data to send, the poller may invoke out_event one
|
254
|
+
// more time due to 'speculative write' optimisation.
|
255
|
+
if (unlikely (encoder == NULL)) {
|
256
|
+
zmq_assert (handshaking);
|
257
|
+
return;
|
258
|
+
}
|
259
|
+
|
260
|
+
outpos = NULL;
|
261
|
+
encoder->get_data (&outpos, &outsize);
|
262
|
+
|
263
|
+
// If there is no data to send, stop polling for output.
|
264
|
+
if (outsize == 0) {
|
265
|
+
reset_pollout (handle);
|
266
|
+
return;
|
267
|
+
}
|
268
|
+
}
|
269
|
+
|
270
|
+
// If there are any data to write in write buffer, write as much as
|
271
|
+
// possible to the socket. Note that amount of data to write can be
|
272
|
+
// arbitratily large. However, we assume that underlying TCP layer has
|
273
|
+
// limited transmission buffer and thus the actual number of bytes
|
274
|
+
// written should be reasonably modest.
|
275
|
+
int nbytes = write (outpos, outsize);
|
276
|
+
|
277
|
+
// IO error has occurred. We stop waiting for output events.
|
278
|
+
// The engine is not terminated until we detect input error;
|
279
|
+
// this is necessary to prevent losing incomming messages.
|
280
|
+
if (nbytes == -1) {
|
281
|
+
reset_pollout (handle);
|
282
|
+
if (unlikely (terminating))
|
283
|
+
terminate ();
|
284
|
+
return;
|
285
|
+
}
|
286
|
+
|
287
|
+
outpos += nbytes;
|
288
|
+
outsize -= nbytes;
|
289
|
+
|
290
|
+
// If we are still handshaking and there are no data
|
291
|
+
// to send, stop polling for output.
|
292
|
+
if (unlikely (handshaking))
|
293
|
+
if (outsize == 0)
|
294
|
+
reset_pollout (handle);
|
295
|
+
|
296
|
+
if (unlikely (terminating))
|
297
|
+
if (outsize == 0)
|
298
|
+
terminate ();
|
299
|
+
}
|
300
|
+
|
301
|
+
void zmq::stream_engine_t::activate_out ()
|
302
|
+
{
|
303
|
+
set_pollout (handle);
|
304
|
+
|
305
|
+
// Speculative write: The assumption is that at the moment new message
|
306
|
+
// was sent by the user the socket is probably available for writing.
|
307
|
+
// Thus we try to write the data to socket avoiding polling for POLLOUT.
|
308
|
+
// Consequently, the latency should be better in request/reply scenarios.
|
309
|
+
out_event ();
|
310
|
+
}
|
311
|
+
|
312
|
+
void zmq::stream_engine_t::activate_in ()
|
313
|
+
{
|
314
|
+
if (unlikely (!io_enabled)) {
|
315
|
+
// There was an input error but the engine could not
|
316
|
+
// be terminated (due to the stalled decoder).
|
317
|
+
// Flush the pending message and terminate the engine now.
|
318
|
+
zmq_assert (decoder);
|
319
|
+
decoder->process_buffer (inpos, 0);
|
320
|
+
zmq_assert (!decoder->stalled ());
|
321
|
+
session->flush ();
|
322
|
+
error ();
|
323
|
+
return;
|
324
|
+
}
|
325
|
+
|
326
|
+
set_pollin (handle);
|
327
|
+
|
328
|
+
// Speculative read.
|
329
|
+
in_event ();
|
330
|
+
}
|
331
|
+
|
332
|
+
bool zmq::stream_engine_t::handshake ()
|
333
|
+
{
|
334
|
+
zmq_assert (handshaking);
|
335
|
+
zmq_assert (greeting_bytes_read < greeting_size);
|
336
|
+
|
337
|
+
// Receive the greeting.
|
338
|
+
while (greeting_bytes_read < greeting_size) {
|
339
|
+
const int n = read (greeting + greeting_bytes_read,
|
340
|
+
greeting_size - greeting_bytes_read);
|
341
|
+
if (n == -1) {
|
342
|
+
error ();
|
343
|
+
return false;
|
344
|
+
}
|
345
|
+
|
346
|
+
if (n == 0)
|
347
|
+
return false;
|
348
|
+
|
349
|
+
greeting_bytes_read += n;
|
350
|
+
|
351
|
+
// We have received at least one byte from the peer.
|
352
|
+
// If the first byte is not 0xff, we know that the
|
353
|
+
// peer is using unversioned protocol.
|
354
|
+
if (greeting [0] != 0xff)
|
355
|
+
break;
|
356
|
+
|
357
|
+
if (greeting_bytes_read < 10)
|
358
|
+
continue;
|
359
|
+
|
360
|
+
// Inspect the right-most bit of the 10th byte (which coincides
|
361
|
+
// with the 'flags' field if a regular message was sent).
|
362
|
+
// Zero indicates this is a header of identity message
|
363
|
+
// (i.e. the peer is using the unversioned protocol).
|
364
|
+
if (!(greeting [9] & 0x01))
|
365
|
+
break;
|
366
|
+
|
367
|
+
// The peer is using versioned protocol.
|
368
|
+
// Send the rest of the greeting, if necessary.
|
369
|
+
if (outpos + outsize != greeting_output_buffer + greeting_size) {
|
370
|
+
if (outsize == 0)
|
371
|
+
set_pollout (handle);
|
372
|
+
outpos [outsize++] = 1; // Protocol version
|
373
|
+
outpos [outsize++] = options.type; // Socket type
|
374
|
+
}
|
375
|
+
}
|
376
|
+
|
377
|
+
// Position of the version field in the greeting.
|
378
|
+
const size_t version_pos = 10;
|
379
|
+
|
380
|
+
// Is the peer using the unversioned protocol?
|
381
|
+
// If so, we send and receive rests of identity
|
382
|
+
// messages.
|
383
|
+
if (greeting [0] != 0xff || !(greeting [9] & 0x01)) {
|
384
|
+
encoder = new (std::nothrow) encoder_t (out_batch_size);
|
385
|
+
alloc_assert (encoder);
|
386
|
+
encoder->set_msg_source (session);
|
387
|
+
|
388
|
+
decoder = new (std::nothrow) decoder_t (in_batch_size, options.maxmsgsize);
|
389
|
+
alloc_assert (decoder);
|
390
|
+
decoder->set_msg_sink (session);
|
391
|
+
|
392
|
+
// We have already sent the message header.
|
393
|
+
// Since there is no way to tell the encoder to
|
394
|
+
// skip the message header, we simply throw that
|
395
|
+
// header data away.
|
396
|
+
const size_t header_size = options.identity_size + 1 >= 255 ? 10 : 2;
|
397
|
+
unsigned char tmp [10], *bufferp = tmp;
|
398
|
+
size_t buffer_size = header_size;
|
399
|
+
encoder->get_data (&bufferp, &buffer_size);
|
400
|
+
zmq_assert (buffer_size == header_size);
|
401
|
+
|
402
|
+
// Make sure the decoder sees the data we have already received.
|
403
|
+
inpos = greeting;
|
404
|
+
insize = greeting_bytes_read;
|
405
|
+
|
406
|
+
// To allow for interoperability with peers that do not forward
|
407
|
+
// their subscriptions, we inject a phony subsription
|
408
|
+
// message into the incomming message stream. To put this
|
409
|
+
// message right after the identity message, we temporarily
|
410
|
+
// divert the message stream from session to ourselves.
|
411
|
+
if (options.type == ZMQ_PUB || options.type == ZMQ_XPUB)
|
412
|
+
decoder->set_msg_sink (this);
|
413
|
+
}
|
414
|
+
else
|
415
|
+
if (greeting [version_pos] == 0) {
|
416
|
+
// ZMTP/1.0 framing.
|
417
|
+
encoder = new (std::nothrow) encoder_t (out_batch_size);
|
418
|
+
alloc_assert (encoder);
|
419
|
+
encoder->set_msg_source (session);
|
420
|
+
|
421
|
+
decoder = new (std::nothrow) decoder_t (in_batch_size, options.maxmsgsize);
|
422
|
+
alloc_assert (decoder);
|
423
|
+
decoder->set_msg_sink (session);
|
424
|
+
}
|
425
|
+
else {
|
426
|
+
// v1 framing protocol.
|
427
|
+
encoder = new (std::nothrow) v1_encoder_t (out_batch_size, session);
|
428
|
+
alloc_assert (encoder);
|
429
|
+
|
430
|
+
decoder = new (std::nothrow)
|
431
|
+
v1_decoder_t (in_batch_size, options.maxmsgsize, session);
|
432
|
+
alloc_assert (decoder);
|
433
|
+
}
|
434
|
+
|
435
|
+
// Start polling for output if necessary.
|
436
|
+
if (outsize == 0)
|
437
|
+
set_pollout (handle);
|
438
|
+
|
439
|
+
// Handshaking was successful.
|
440
|
+
// Switch into the normal message flow.
|
441
|
+
handshaking = false;
|
442
|
+
|
443
|
+
return true;
|
444
|
+
}
|
445
|
+
|
446
|
+
int zmq::stream_engine_t::push_msg (msg_t *msg_)
|
447
|
+
{
|
448
|
+
zmq_assert (options.type == ZMQ_PUB || options.type == ZMQ_XPUB);
|
449
|
+
|
450
|
+
// The first message is identity.
|
451
|
+
// Let the session process it.
|
452
|
+
int rc = session->push_msg (msg_);
|
453
|
+
errno_assert (rc == 0);
|
454
|
+
|
455
|
+
// Inject the subscription message so that the ZMQ 2.x peer
|
456
|
+
// receives our messages.
|
457
|
+
rc = msg_->init_size (1);
|
458
|
+
errno_assert (rc == 0);
|
459
|
+
*(unsigned char*) msg_->data () = 1;
|
460
|
+
rc = session->push_msg (msg_);
|
461
|
+
session->flush ();
|
462
|
+
|
463
|
+
// Once we have injected the subscription message, we can
|
464
|
+
// Divert the message flow back to the session.
|
465
|
+
zmq_assert (decoder);
|
466
|
+
decoder->set_msg_sink (session);
|
467
|
+
|
468
|
+
return rc;
|
469
|
+
}
|
470
|
+
|
471
|
+
void zmq::stream_engine_t::error ()
|
472
|
+
{
|
473
|
+
zmq_assert (session);
|
474
|
+
socket->event_disconnected (endpoint, s);
|
475
|
+
session->detach ();
|
476
|
+
unplug ();
|
477
|
+
delete this;
|
478
|
+
}
|
479
|
+
|
480
|
+
int zmq::stream_engine_t::write (const void *data_, size_t size_)
|
481
|
+
{
|
482
|
+
#ifdef ZMQ_HAVE_WINDOWS
|
483
|
+
|
484
|
+
int nbytes = send (s, (char*) data_, (int) size_, 0);
|
485
|
+
|
486
|
+
// If not a single byte can be written to the socket in non-blocking mode
|
487
|
+
// we'll get an error (this may happen during the speculative write).
|
488
|
+
if (nbytes == SOCKET_ERROR && WSAGetLastError () == WSAEWOULDBLOCK)
|
489
|
+
return 0;
|
490
|
+
|
491
|
+
// Signalise peer failure.
|
492
|
+
if (nbytes == SOCKET_ERROR && (
|
493
|
+
WSAGetLastError () == WSAENETDOWN ||
|
494
|
+
WSAGetLastError () == WSAENETRESET ||
|
495
|
+
WSAGetLastError () == WSAEHOSTUNREACH ||
|
496
|
+
WSAGetLastError () == WSAECONNABORTED ||
|
497
|
+
WSAGetLastError () == WSAETIMEDOUT ||
|
498
|
+
WSAGetLastError () == WSAECONNRESET))
|
499
|
+
return -1;
|
500
|
+
|
501
|
+
wsa_assert (nbytes != SOCKET_ERROR);
|
502
|
+
return nbytes;
|
503
|
+
|
504
|
+
#else
|
505
|
+
|
506
|
+
ssize_t nbytes = send (s, data_, size_, 0);
|
507
|
+
|
508
|
+
// Several errors are OK. When speculative write is being done we may not
|
509
|
+
// be able to write a single byte from the socket. Also, SIGSTOP issued
|
510
|
+
// by a debugging tool can result in EINTR error.
|
511
|
+
if (nbytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK ||
|
512
|
+
errno == EINTR))
|
513
|
+
return 0;
|
514
|
+
|
515
|
+
// Signalise peer failure.
|
516
|
+
if (nbytes == -1) {
|
517
|
+
errno_assert (errno != EACCES
|
518
|
+
&& errno != EBADF
|
519
|
+
&& errno != EDESTADDRREQ
|
520
|
+
&& errno != EFAULT
|
521
|
+
&& errno != EINVAL
|
522
|
+
&& errno != EISCONN
|
523
|
+
&& errno != EMSGSIZE
|
524
|
+
&& errno != ENOMEM
|
525
|
+
&& errno != ENOTSOCK
|
526
|
+
&& errno != EOPNOTSUPP);
|
527
|
+
return -1;
|
528
|
+
}
|
529
|
+
|
530
|
+
return (size_t) nbytes;
|
531
|
+
|
532
|
+
#endif
|
533
|
+
}
|
534
|
+
|
535
|
+
int zmq::stream_engine_t::read (void *data_, size_t size_)
|
536
|
+
{
|
537
|
+
#ifdef ZMQ_HAVE_WINDOWS
|
538
|
+
|
539
|
+
int nbytes = recv (s, (char*) data_, (int) size_, 0);
|
540
|
+
|
541
|
+
// If not a single byte can be read from the socket in non-blocking mode
|
542
|
+
// we'll get an error (this may happen during the speculative read).
|
543
|
+
if (nbytes == SOCKET_ERROR && WSAGetLastError () == WSAEWOULDBLOCK)
|
544
|
+
return 0;
|
545
|
+
|
546
|
+
// Connection failure.
|
547
|
+
if (nbytes == SOCKET_ERROR && (
|
548
|
+
WSAGetLastError () == WSAENETDOWN ||
|
549
|
+
WSAGetLastError () == WSAENETRESET ||
|
550
|
+
WSAGetLastError () == WSAECONNABORTED ||
|
551
|
+
WSAGetLastError () == WSAETIMEDOUT ||
|
552
|
+
WSAGetLastError () == WSAECONNRESET ||
|
553
|
+
WSAGetLastError () == WSAECONNREFUSED ||
|
554
|
+
WSAGetLastError () == WSAENOTCONN))
|
555
|
+
return -1;
|
556
|
+
|
557
|
+
wsa_assert (nbytes != SOCKET_ERROR);
|
558
|
+
|
559
|
+
// Orderly shutdown by the other peer.
|
560
|
+
if (nbytes == 0)
|
561
|
+
return -1;
|
562
|
+
|
563
|
+
return nbytes;
|
564
|
+
|
565
|
+
#else
|
566
|
+
|
567
|
+
ssize_t nbytes = recv (s, data_, size_, 0);
|
568
|
+
|
569
|
+
// Several errors are OK. When speculative read is being done we may not
|
570
|
+
// be able to read a single byte from the socket. Also, SIGSTOP issued
|
571
|
+
// by a debugging tool can result in EINTR error.
|
572
|
+
if (nbytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK ||
|
573
|
+
errno == EINTR))
|
574
|
+
return 0;
|
575
|
+
|
576
|
+
// Signalise peer failure.
|
577
|
+
if (nbytes == -1) {
|
578
|
+
errno_assert (errno != EBADF
|
579
|
+
&& errno != EFAULT
|
580
|
+
&& errno != EINVAL
|
581
|
+
&& errno != ENOMEM
|
582
|
+
&& errno != ENOTSOCK);
|
583
|
+
return -1;
|
584
|
+
}
|
585
|
+
|
586
|
+
// Orderly shutdown by the peer.
|
587
|
+
if (nbytes == 0)
|
588
|
+
return -1;
|
589
|
+
|
590
|
+
return (size_t) nbytes;
|
591
|
+
|
592
|
+
#endif
|
593
|
+
}
|
594
|
+
|