rbczmq 1.7.1 → 1.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitmodules +1 -1
- data/CHANGELOG.rdoc +4 -0
- data/Gemfile.lock +1 -1
- data/README.rdoc +5 -4
- data/ext/czmq/.gitignore +5 -0
- data/ext/czmq/.travis.yml +10 -1
- data/ext/czmq/AUTHORS +2 -0
- data/ext/czmq/COPYING.LESSER +3 -0
- data/ext/czmq/Makefile.am +13 -3
- data/ext/czmq/NEWS +132 -0
- data/ext/czmq/README.md +1553 -615
- data/ext/czmq/README.txt +188 -72
- data/ext/czmq/addons/Makefile.am +9 -0
- data/ext/czmq/addons/makecert.c +72 -0
- data/ext/czmq/builds/mingw32/Makefile.mingw32 +11 -3
- data/ext/czmq/builds/msvc/.gitignore +4 -1
- data/ext/czmq/builds/msvc/czmq.vcproj +4 -0
- data/ext/czmq/builds/msvc/czmq.vcxproj +6 -1
- data/ext/czmq/builds/msvc/czmq.vcxproj.filters +4 -1
- data/ext/{zeromq/cmake/Modules/zmq_version.cpp → czmq/builds/msvc/platform.h} +10 -9
- data/ext/czmq/configure.ac +64 -5
- data/ext/czmq/doc/Makefile.am +8 -1
- data/ext/czmq/doc/mkmans +17 -0
- data/ext/czmq/doc/zauth.txt +191 -0
- data/ext/czmq/doc/zbeacon.txt +13 -22
- data/ext/czmq/doc/zcert.txt +122 -0
- data/ext/czmq/doc/zcertstore.txt +107 -0
- data/ext/czmq/doc/zchunk.txt +77 -0
- data/ext/czmq/doc/zclock.txt +8 -0
- data/ext/czmq/doc/zconfig.txt +9 -63
- data/ext/czmq/doc/zctx.txt +26 -7
- data/ext/czmq/doc/zdir.txt +83 -0
- data/ext/czmq/doc/zfile.txt +130 -35
- data/ext/czmq/doc/zframe.txt +6 -39
- data/ext/czmq/doc/zhash.txt +55 -10
- data/ext/czmq/doc/zlist.txt +2 -4
- data/ext/czmq/doc/zloop.txt +7 -1
- data/ext/czmq/doc/zmsg.txt +75 -32
- data/ext/czmq/doc/zpoller.txt +88 -0
- data/ext/czmq/doc/zsocket.txt +50 -1
- data/ext/czmq/doc/zsockopt.txt +185 -251
- data/ext/czmq/doc/zstr.txt +14 -3
- data/ext/czmq/doc/zsys.txt +89 -1
- data/ext/czmq/doc/ztree.txt +21 -11
- data/ext/czmq/examples/security/LICENSE +18 -0
- data/ext/czmq/examples/security/README.txt +9 -0
- data/ext/czmq/examples/security/grasslands.c +29 -0
- data/ext/czmq/examples/security/hello.c +10 -0
- data/ext/czmq/examples/security/ironhouse.c +55 -0
- data/ext/czmq/examples/security/ironhouse2.c +103 -0
- data/ext/czmq/examples/security/stonehouse.c +51 -0
- data/ext/czmq/examples/security/strawhouse.c +44 -0
- data/ext/czmq/examples/security/woodhouse.c +40 -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 +10 -4
- data/ext/czmq/include/czmq_prelude.h +42 -42
- data/ext/czmq/include/zauth.h +97 -0
- data/ext/czmq/include/zbeacon.h +0 -5
- data/ext/czmq/include/zcert.h +118 -0
- data/ext/czmq/include/zcertstore.h +78 -0
- data/ext/czmq/include/zchunk.h +87 -0
- data/ext/czmq/include/zclock.h +4 -0
- data/ext/czmq/include/zconfig.h +21 -12
- data/ext/czmq/include/zctx.h +34 -11
- data/ext/czmq/include/zdir.h +90 -0
- data/ext/czmq/include/zfile.h +104 -25
- data/ext/czmq/include/zframe.h +7 -20
- data/ext/czmq/include/zhash.h +13 -0
- data/ext/czmq/include/zlist.h +0 -4
- data/ext/czmq/include/zloop.h +5 -5
- data/ext/czmq/include/zmsg.h +59 -29
- data/ext/czmq/include/zmutex.h +5 -0
- data/ext/czmq/include/zpoller.h +72 -0
- data/ext/czmq/include/zsocket.h +12 -15
- data/ext/czmq/include/zsockopt.h +124 -121
- data/ext/czmq/include/zstr.h +12 -9
- data/ext/czmq/include/zsys.h +50 -2
- data/ext/czmq/mkdoc +1 -1
- data/ext/czmq/model/sockopts.xml +101 -21
- data/ext/czmq/scripts/sockopts.gsl +95 -41
- data/ext/czmq/src/Makefile.am +13 -0
- data/ext/czmq/src/czmq_selftest.c +16 -10
- data/ext/czmq/src/selftest +2 -2
- data/ext/czmq/src/zauth.c +714 -0
- data/ext/czmq/src/zbeacon.c +27 -35
- data/ext/czmq/src/zcert.c +463 -0
- data/ext/czmq/src/zcertstore.c +265 -0
- data/ext/czmq/src/zchunk.c +207 -0
- data/ext/czmq/src/zclock.c +18 -0
- data/ext/czmq/src/zconfig.c +116 -99
- data/ext/czmq/src/zctx.c +103 -18
- data/ext/czmq/src/zdir.c +409 -0
- data/ext/czmq/src/zfile.c +421 -130
- data/ext/czmq/src/zframe.c +28 -127
- data/ext/czmq/src/zhash.c +255 -139
- data/ext/czmq/src/zlist.c +2 -8
- data/ext/czmq/src/zloop.c +40 -13
- data/ext/czmq/src/zmsg.c +109 -141
- data/ext/czmq/src/zmutex.c +27 -1
- data/ext/czmq/src/zpoller.c +218 -0
- data/ext/czmq/src/zsocket.c +53 -66
- data/ext/czmq/src/zsockopt.c +2337 -682
- data/ext/czmq/src/zstr.c +48 -118
- data/ext/czmq/src/zsys.c +270 -3
- data/ext/czmq/src/zthread.c +2 -2
- data/ext/czmq/src/ztree.c +179 -180
- data/ext/rbczmq/beacon.c +1 -1
- data/ext/rbczmq/context.c +12 -3
- data/ext/rbczmq/context.h +7 -0
- data/ext/rbczmq/extconf.rb +13 -4
- data/ext/rbczmq/pollitem.c +1 -1
- data/ext/rbczmq/socket.c +34 -24
- data/ext/rbczmq/socket.h +3 -2
- data/ext/zeromq/AUTHORS +17 -3
- data/ext/zeromq/CMakeLists.txt +742 -339
- data/ext/zeromq/COPYING.LESSER +2 -0
- data/ext/zeromq/Makefile.am +3 -3
- data/ext/zeromq/NEWS +130 -1
- data/ext/zeromq/{README → README.md} +8 -9
- data/ext/zeromq/builds/cmake/Modules/FindAsciiDoc.cmake +24 -0
- data/ext/zeromq/builds/cmake/Modules/TestZMQVersion.cmake +18 -0
- data/ext/zeromq/builds/cmake/Modules/ZMQSourceRunChecks.cmake +129 -0
- data/ext/zeromq/{cmake → builds/cmake}/NSIS.template32.in +1 -1
- data/ext/zeromq/{cmake → builds/cmake}/NSIS.template64.in +1 -1
- data/ext/zeromq/builds/cmake/platform.hpp.in +88 -0
- data/ext/zeromq/builds/mingw32/Makefile.mingw32 +47 -0
- data/ext/zeromq/{src/i_msg_sink.hpp → builds/mingw32/platform.hpp} +10 -21
- data/ext/zeromq/builds/msvc/Makefile.am +5 -2
- data/ext/zeromq/builds/msvc/c_local_lat/c_local_lat.vcxproj +1 -1
- data/ext/zeromq/builds/msvc/c_local_lat/c_local_lat11.vcxproj +91 -0
- data/ext/zeromq/builds/msvc/c_local_thr/c_local_thr.vcproj +2 -0
- data/ext/zeromq/builds/msvc/c_local_thr/c_local_thr.vcxproj +21 -1
- data/ext/zeromq/builds/msvc/c_local_thr/c_local_thr11.vcxproj +111 -0
- data/ext/zeromq/builds/msvc/c_remote_lat/c_remote_lat.vcxproj +1 -1
- data/ext/zeromq/builds/msvc/c_remote_lat/c_remote_lat11.vcxproj +91 -0
- data/ext/zeromq/builds/msvc/c_remote_thr/c_remote_thr.vcproj +2 -0
- data/ext/zeromq/builds/msvc/c_remote_thr/c_remote_thr.vcxproj +21 -1
- data/ext/zeromq/builds/msvc/c_remote_thr/c_remote_thr11.vcxproj +111 -0
- data/ext/zeromq/builds/msvc/errno.cpp +1 -1
- data/ext/zeromq/builds/msvc/errno.hpp +1 -1
- data/ext/zeromq/builds/msvc/inproc_lat/inproc_lat.vcproj +176 -174
- data/ext/zeromq/builds/msvc/inproc_lat/inproc_lat.vcxproj +21 -1
- data/ext/zeromq/builds/msvc/inproc_lat/inproc_lat11.vcxproj +110 -0
- data/ext/zeromq/builds/msvc/inproc_thr/inproc_thr.vcproj +176 -174
- data/ext/zeromq/builds/msvc/inproc_thr/inproc_thr.vcxproj +21 -1
- data/ext/zeromq/builds/msvc/inproc_thr/inproc_thr11.vcxproj +110 -0
- data/ext/zeromq/builds/msvc/libzmq/libzmq.vcproj +997 -804
- data/ext/zeromq/builds/msvc/libzmq/libzmq.vcxproj +78 -2
- data/ext/zeromq/builds/msvc/libzmq/libzmq.vcxproj.filters +42 -6
- data/ext/zeromq/builds/msvc/libzmq/libzmq11.vcxproj +362 -0
- data/ext/zeromq/builds/msvc/msvc.sln +6 -0
- data/ext/zeromq/builds/msvc/msvc10.sln +36 -2
- data/ext/zeromq/builds/msvc/msvc11.sln +150 -0
- data/ext/zeromq/builds/msvc/properties/Static.props +15 -0
- data/ext/zeromq/builds/msvc/properties/ZeroMQ.props +0 -1
- data/ext/zeromq/builds/msvc/properties/ZeroMQ_Static.props +23 -0
- data/ext/zeromq/builds/redhat/zeromq.spec.in +2 -1
- data/ext/zeromq/{configure.in → configure.ac} +74 -15
- data/ext/zeromq/doc/Makefile.am +6 -4
- data/ext/zeromq/doc/zmq.txt +30 -3
- data/ext/zeromq/doc/zmq_bind.txt +2 -2
- data/ext/zeromq/doc/zmq_close.txt +2 -2
- data/ext/zeromq/doc/zmq_connect.txt +9 -7
- data/ext/zeromq/doc/zmq_ctx_destroy.txt +4 -3
- data/ext/zeromq/doc/zmq_ctx_get.txt +8 -3
- data/ext/zeromq/doc/zmq_ctx_new.txt +3 -2
- data/ext/zeromq/doc/zmq_ctx_set.txt +13 -1
- data/ext/zeromq/doc/zmq_ctx_shutdown.txt +52 -0
- data/ext/zeromq/doc/zmq_ctx_term.txt +67 -0
- data/ext/zeromq/doc/zmq_curve.txt +92 -0
- data/ext/zeromq/doc/zmq_curve_keypair.txt +56 -0
- data/ext/zeromq/doc/zmq_disconnect.txt +2 -2
- data/ext/zeromq/doc/zmq_epgm.txt +5 -4
- data/ext/zeromq/doc/zmq_errno.txt +2 -2
- data/ext/zeromq/doc/zmq_getsockopt.txt +149 -24
- data/ext/zeromq/doc/zmq_init.txt +2 -2
- data/ext/zeromq/doc/zmq_inproc.txt +2 -2
- data/ext/zeromq/doc/zmq_ipc.txt +10 -5
- data/ext/zeromq/doc/zmq_msg_close.txt +4 -3
- data/ext/zeromq/doc/zmq_msg_copy.txt +2 -2
- data/ext/zeromq/doc/zmq_msg_data.txt +2 -2
- data/ext/zeromq/doc/zmq_msg_get.txt +3 -3
- data/ext/zeromq/doc/zmq_msg_init.txt +2 -2
- data/ext/zeromq/doc/zmq_msg_init_data.txt +2 -2
- data/ext/zeromq/doc/zmq_msg_init_size.txt +2 -2
- data/ext/zeromq/doc/zmq_msg_more.txt +6 -4
- data/ext/zeromq/doc/zmq_msg_move.txt +2 -2
- data/ext/zeromq/doc/zmq_msg_recv.txt +3 -4
- data/ext/zeromq/doc/zmq_msg_send.txt +10 -7
- data/ext/zeromq/doc/zmq_msg_set.txt +2 -1
- data/ext/zeromq/doc/zmq_msg_size.txt +2 -2
- data/ext/zeromq/doc/zmq_null.txt +27 -0
- data/ext/zeromq/doc/zmq_pgm.txt +5 -4
- data/ext/zeromq/doc/zmq_plain.txt +37 -0
- data/ext/zeromq/doc/zmq_poll.txt +2 -6
- data/ext/zeromq/doc/zmq_proxy.txt +2 -1
- data/ext/zeromq/doc/zmq_recv.txt +2 -5
- data/ext/zeromq/doc/zmq_recvmsg.txt +3 -5
- data/ext/zeromq/doc/zmq_send.txt +9 -7
- data/ext/zeromq/doc/zmq_send_const.txt +103 -0
- data/ext/zeromq/doc/zmq_sendmsg.txt +8 -8
- data/ext/zeromq/doc/zmq_setsockopt.txt +291 -37
- data/ext/zeromq/doc/zmq_socket.txt +92 -21
- data/ext/zeromq/doc/zmq_socket_monitor.txt +102 -131
- data/ext/zeromq/doc/zmq_strerror.txt +3 -2
- data/ext/zeromq/doc/zmq_tcp.txt +4 -2
- data/ext/zeromq/doc/zmq_term.txt +3 -3
- data/ext/zeromq/doc/zmq_unbind.txt +2 -2
- data/ext/zeromq/doc/zmq_version.txt +3 -2
- data/ext/zeromq/doc/zmq_z85_decode.txt +50 -0
- data/ext/zeromq/doc/zmq_z85_encode.txt +57 -0
- data/ext/zeromq/foreign/openpgm/libpgm-5.2.122~dfsg.tar.gz +0 -0
- data/ext/zeromq/include/zmq.h +179 -136
- data/ext/zeromq/include/zmq_utils.h +44 -3
- data/ext/zeromq/perf/inproc_lat.cpp +2 -4
- data/ext/zeromq/perf/inproc_thr.cpp +1 -1
- data/ext/zeromq/perf/local_lat.cpp +1 -3
- data/ext/zeromq/perf/local_thr.cpp +1 -3
- data/ext/zeromq/perf/remote_lat.cpp +1 -3
- data/ext/zeromq/perf/remote_thr.cpp +1 -8
- data/ext/zeromq/src/Makefile.am +26 -7
- data/ext/zeromq/src/address.cpp +7 -8
- data/ext/zeromq/src/address.hpp +1 -2
- data/ext/zeromq/src/array.hpp +1 -3
- data/ext/zeromq/src/atomic_counter.hpp +11 -3
- data/ext/zeromq/src/atomic_ptr.hpp +9 -3
- data/ext/zeromq/src/blob.hpp +2 -2
- data/ext/zeromq/src/clock.cpp +3 -4
- data/ext/zeromq/src/clock.hpp +1 -2
- data/ext/zeromq/src/command.hpp +2 -3
- data/ext/zeromq/src/config.hpp +1 -3
- data/ext/zeromq/src/ctx.cpp +154 -15
- data/ext/zeromq/src/ctx.hpp +34 -3
- data/ext/zeromq/src/curve_client.cpp +410 -0
- data/ext/zeromq/src/curve_client.hpp +109 -0
- data/ext/zeromq/src/curve_server.cpp +629 -0
- data/ext/zeromq/src/curve_server.hpp +120 -0
- data/ext/zeromq/src/dbuffer.hpp +134 -0
- data/ext/zeromq/src/dealer.cpp +52 -60
- data/ext/zeromq/src/dealer.hpp +12 -26
- data/ext/zeromq/src/decoder.hpp +27 -102
- data/ext/zeromq/src/devpoll.cpp +1 -3
- data/ext/zeromq/src/devpoll.hpp +1 -3
- data/ext/zeromq/src/dist.cpp +17 -15
- data/ext/zeromq/src/dist.hpp +5 -6
- data/ext/zeromq/src/encoder.hpp +32 -52
- data/ext/zeromq/src/epoll.cpp +1 -3
- data/ext/zeromq/src/epoll.hpp +1 -3
- data/ext/zeromq/src/err.cpp +2 -4
- data/ext/zeromq/src/err.hpp +7 -4
- data/ext/zeromq/src/fd.hpp +1 -2
- data/ext/zeromq/src/fq.cpp +2 -5
- data/ext/zeromq/src/fq.hpp +2 -4
- data/ext/zeromq/src/i_decoder.hpp +11 -9
- data/ext/zeromq/src/i_encoder.hpp +7 -11
- data/ext/zeromq/src/i_engine.hpp +3 -3
- data/ext/zeromq/src/i_poll_events.hpp +1 -3
- data/ext/zeromq/src/io_object.cpp +1 -3
- data/ext/zeromq/src/io_object.hpp +1 -3
- data/ext/zeromq/src/io_thread.cpp +1 -3
- data/ext/zeromq/src/io_thread.hpp +1 -3
- data/ext/zeromq/src/ip.cpp +46 -5
- data/ext/zeromq/src/ip.hpp +7 -4
- data/ext/zeromq/src/ipc_address.cpp +13 -2
- data/ext/zeromq/src/ipc_address.hpp +1 -2
- data/ext/zeromq/src/ipc_connecter.cpp +3 -3
- data/ext/zeromq/src/ipc_connecter.hpp +1 -2
- data/ext/zeromq/src/ipc_listener.cpp +15 -10
- data/ext/zeromq/src/ipc_listener.hpp +1 -2
- data/ext/zeromq/src/kqueue.cpp +11 -3
- data/ext/zeromq/src/kqueue.hpp +7 -3
- data/ext/zeromq/src/lb.cpp +13 -11
- data/ext/zeromq/src/lb.hpp +10 -5
- data/ext/zeromq/src/libzmq.pc.cmake.in +10 -0
- data/ext/zeromq/src/likely.hpp +1 -2
- data/ext/zeromq/src/mailbox.cpp +1 -4
- data/ext/zeromq/src/mailbox.hpp +8 -3
- data/ext/zeromq/src/mechanism.cpp +163 -0
- data/ext/zeromq/src/mechanism.hpp +101 -0
- data/ext/zeromq/src/msg.cpp +38 -18
- data/ext/zeromq/src/msg.hpp +19 -7
- data/ext/zeromq/src/mtrie.cpp +16 -14
- data/ext/zeromq/src/mtrie.hpp +1 -3
- data/ext/zeromq/src/mutex.hpp +42 -3
- data/ext/zeromq/src/null_mechanism.cpp +282 -0
- data/ext/zeromq/src/null_mechanism.hpp +65 -0
- data/ext/zeromq/src/object.cpp +29 -3
- data/ext/zeromq/src/object.hpp +8 -5
- data/ext/zeromq/src/options.cpp +557 -485
- data/ext/zeromq/src/options.hpp +38 -24
- data/ext/zeromq/src/own.cpp +1 -2
- data/ext/zeromq/src/own.hpp +1 -2
- data/ext/zeromq/src/pair.cpp +8 -25
- data/ext/zeromq/src/pair.hpp +5 -22
- data/ext/zeromq/src/pgm_receiver.cpp +80 -67
- data/ext/zeromq/src/pgm_receiver.hpp +11 -10
- data/ext/zeromq/src/pgm_sender.cpp +37 -16
- data/ext/zeromq/src/pgm_sender.hpp +12 -6
- data/ext/zeromq/src/pgm_socket.cpp +8 -8
- data/ext/zeromq/src/pgm_socket.hpp +1 -4
- data/ext/zeromq/src/pipe.cpp +110 -72
- data/ext/zeromq/src/pipe.hpp +36 -27
- data/ext/zeromq/src/plain_mechanism.cpp +482 -0
- data/ext/zeromq/src/plain_mechanism.hpp +88 -0
- data/ext/zeromq/src/poll.cpp +1 -3
- data/ext/zeromq/src/poll.hpp +1 -3
- data/ext/zeromq/src/poller.hpp +1 -3
- data/ext/zeromq/src/poller_base.cpp +3 -3
- data/ext/zeromq/src/poller_base.hpp +1 -2
- data/ext/zeromq/src/precompiled.cpp +1 -2
- data/ext/zeromq/src/precompiled.hpp +1 -2
- data/ext/zeromq/src/proxy.cpp +1 -2
- data/ext/zeromq/src/proxy.hpp +1 -2
- data/ext/zeromq/src/pub.cpp +2 -16
- data/ext/zeromq/src/pub.hpp +2 -19
- data/ext/zeromq/src/pull.cpp +7 -24
- data/ext/zeromq/src/pull.hpp +4 -21
- data/ext/zeromq/src/push.cpp +8 -22
- data/ext/zeromq/src/push.hpp +4 -21
- data/ext/zeromq/src/random.cpp +1 -2
- data/ext/zeromq/src/random.hpp +1 -2
- data/ext/zeromq/src/raw_decoder.cpp +63 -0
- data/ext/zeromq/src/raw_decoder.hpp +66 -0
- data/ext/zeromq/src/raw_encoder.cpp +40 -0
- data/ext/zeromq/src/raw_encoder.hpp +60 -0
- data/ext/zeromq/src/reaper.cpp +12 -2
- data/ext/zeromq/src/reaper.hpp +6 -2
- data/ext/zeromq/src/rep.cpp +7 -21
- data/ext/zeromq/src/rep.hpp +3 -20
- data/ext/zeromq/src/req.cpp +132 -38
- data/ext/zeromq/src/req.hpp +27 -8
- data/ext/zeromq/src/router.cpp +109 -65
- data/ext/zeromq/src/router.hpp +9 -23
- data/ext/zeromq/src/select.cpp +1 -3
- data/ext/zeromq/src/select.hpp +1 -3
- data/ext/zeromq/src/session_base.cpp +164 -118
- data/ext/zeromq/src/session_base.hpp +29 -22
- data/ext/zeromq/src/signaler.cpp +127 -19
- data/ext/zeromq/src/signaler.hpp +20 -3
- data/ext/zeromq/src/socket_base.cpp +167 -134
- data/ext/zeromq/src/socket_base.hpp +18 -20
- data/ext/zeromq/src/stdint.hpp +1 -2
- data/ext/zeromq/src/stream.cpp +257 -0
- data/ext/zeromq/src/stream.hpp +97 -0
- data/ext/zeromq/src/stream_engine.cpp +405 -157
- data/ext/zeromq/src/stream_engine.hpp +72 -23
- data/ext/zeromq/src/sub.cpp +5 -18
- data/ext/zeromq/src/sub.hpp +2 -19
- data/ext/zeromq/src/tcp.cpp +23 -3
- data/ext/zeromq/src/tcp.hpp +7 -3
- data/ext/zeromq/src/tcp_address.cpp +35 -46
- data/ext/zeromq/src/tcp_address.hpp +7 -12
- data/ext/zeromq/src/tcp_connecter.cpp +10 -5
- data/ext/zeromq/src/tcp_connecter.hpp +1 -3
- data/ext/zeromq/src/tcp_listener.cpp +19 -8
- data/ext/zeromq/src/tcp_listener.hpp +1 -3
- data/ext/zeromq/src/thread.cpp +2 -4
- data/ext/zeromq/src/thread.hpp +1 -3
- data/ext/zeromq/src/trie.cpp +122 -125
- data/ext/zeromq/src/trie.hpp +1 -4
- data/ext/zeromq/src/v1_decoder.cpp +77 -91
- data/ext/zeromq/src/v1_decoder.hpp +10 -21
- data/ext/zeromq/src/v1_encoder.cpp +24 -62
- data/ext/zeromq/src/v1_encoder.hpp +7 -18
- data/ext/zeromq/src/v2_decoder.cpp +142 -0
- data/ext/zeromq/src/v2_decoder.hpp +57 -0
- data/ext/zeromq/src/v2_encoder.cpp +67 -0
- data/ext/zeromq/src/{i_msg_source.hpp → v2_encoder.hpp} +20 -15
- data/ext/zeromq/src/{v1_protocol.hpp → v2_protocol.hpp} +7 -11
- data/ext/zeromq/src/windows.hpp +2 -4
- data/ext/zeromq/src/wire.hpp +5 -6
- data/ext/zeromq/src/xpub.cpp +37 -46
- data/ext/zeromq/src/xpub.hpp +7 -23
- data/ext/zeromq/src/xsub.cpp +26 -40
- data/ext/zeromq/src/xsub.hpp +5 -21
- data/ext/zeromq/src/ypipe.hpp +3 -4
- data/ext/zeromq/src/ypipe_base.hpp +44 -0
- data/ext/zeromq/src/ypipe_conflate.hpp +127 -0
- data/ext/zeromq/src/yqueue.hpp +3 -7
- data/ext/zeromq/src/zmq.cpp +76 -96
- data/ext/zeromq/src/zmq_utils.cpp +146 -8
- data/ext/zeromq/tests/Makefile.am +56 -8
- data/ext/zeromq/tests/test_abstract_ipc.cpp +57 -0
- data/ext/zeromq/tests/test_conflate.cpp +75 -0
- data/ext/zeromq/tests/test_connect_resolve.cpp +14 -15
- data/ext/zeromq/tests/test_ctx_destroy.cpp +90 -0
- data/ext/zeromq/tests/test_ctx_options.cpp +52 -0
- data/ext/zeromq/tests/test_disconnect_inproc.cpp +35 -30
- data/ext/zeromq/tests/test_fork.cpp +81 -0
- data/ext/zeromq/tests/test_hwm.cpp +251 -35
- data/ext/zeromq/tests/test_immediate.cpp +229 -0
- data/ext/zeromq/tests/test_inproc_connect.cpp +339 -0
- data/ext/zeromq/tests/test_invalid_rep.cpp +9 -13
- data/ext/zeromq/tests/test_iov.cpp +106 -0
- data/ext/zeromq/tests/test_issue_566.cpp +85 -0
- data/ext/zeromq/tests/test_last_endpoint.cpp +14 -18
- data/ext/zeromq/tests/test_linger.cpp +93 -0
- data/ext/zeromq/tests/test_monitor.cpp +112 -129
- data/ext/zeromq/tests/test_msg_flags.cpp +17 -16
- data/ext/zeromq/tests/test_pair_inproc.cpp +25 -7
- data/ext/zeromq/tests/test_pair_ipc.cpp +4 -7
- data/ext/zeromq/tests/test_pair_tcp.cpp +4 -8
- data/ext/zeromq/tests/test_probe_router.cpp +72 -0
- data/ext/zeromq/tests/test_req_correlate.cpp +177 -0
- data/ext/zeromq/tests/test_req_relaxed.cpp +116 -0
- data/ext/zeromq/tests/test_reqrep_device.cpp +9 -17
- data/ext/zeromq/tests/test_reqrep_inproc.cpp +4 -7
- data/ext/zeromq/tests/test_reqrep_ipc.cpp +4 -7
- data/ext/zeromq/tests/test_reqrep_tcp.cpp +4 -8
- data/ext/zeromq/tests/test_router_mandatory.cpp +41 -22
- data/ext/zeromq/tests/test_security_curve.cpp +212 -0
- data/ext/zeromq/tests/test_security_null.cpp +148 -0
- data/ext/zeromq/tests/test_security_plain.cpp +150 -0
- data/ext/zeromq/tests/test_shutdown_stress.cpp +10 -23
- data/ext/zeromq/tests/test_spec_dealer.cpp +254 -0
- data/ext/zeromq/tests/test_spec_pushpull.cpp +293 -0
- data/ext/zeromq/tests/test_spec_rep.cpp +155 -0
- data/ext/zeromq/tests/test_spec_req.cpp +253 -0
- data/ext/zeromq/tests/test_spec_router.cpp +204 -0
- data/ext/zeromq/tests/test_stream.cpp +228 -0
- data/ext/zeromq/tests/test_sub_forward.cpp +14 -22
- data/ext/zeromq/tests/test_system.cpp +82 -0
- data/ext/zeromq/tests/test_term_endpoint.cpp +17 -31
- data/ext/zeromq/tests/test_timeo.cpp +34 -78
- data/ext/zeromq/tests/testutil.hpp +211 -26
- data/ext/zeromq/tools/Makefile.am +9 -0
- data/ext/zeromq/tools/curve_keygen.c +58 -0
- data/lib/zmq/version.rb +1 -1
- data/test/test_socket.rb +4 -3
- metadata +114 -15
- data/ext/zeromq/cmake/Modules/TestZMQVersion.cmake +0 -35
- data/ext/zeromq/foreign/openpgm/libpgm-5.1.118~dfsg.tar.gz +0 -0
- data/ext/zeromq/src/decoder.cpp +0 -166
- data/ext/zeromq/src/encoder.cpp +0 -102
- data/ext/zeromq/tests/test_connect_delay.cpp +0 -260
@@ -0,0 +1,265 @@
|
|
1
|
+
/* =========================================================================
|
2
|
+
zcertstore - work with CURVE security certificate stores
|
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
|
+
To authenticate new clients using the ZeroMQ CURVE security mechanism,
|
29
|
+
we have to check that the client's public key matches a key we know and
|
30
|
+
accept. There are numerous ways to store accepted client public keys.
|
31
|
+
The mechanism CZMQ implements is "certificates" (plain text files) held
|
32
|
+
in a "certificate store" (a disk directory). This class works with such
|
33
|
+
certificate stores, and lets you easily load them from disk, and check
|
34
|
+
if a given client public key is known or not. The zcert class does the
|
35
|
+
work of managing a single certificate.
|
36
|
+
@discuss
|
37
|
+
The certificate store can be memory-only, in which case you can load it
|
38
|
+
yourself by inserting certificate objects one by one, or it can be loaded
|
39
|
+
from disk, in which case you can add, modify, or remove certificates on
|
40
|
+
disk at any time, and the store will detect such changes and refresh
|
41
|
+
itself automatically. In most applications you won't use this class
|
42
|
+
directly but through the zauth class, which provides a high-level API for
|
43
|
+
authentication (and manages certificate stores for you). To actually
|
44
|
+
create certificates on disk, use the zcert class in code, or the
|
45
|
+
tools/makecert.c command line tool, or any text editor. The format of a
|
46
|
+
certificate file is defined in the zcert man page.
|
47
|
+
@end
|
48
|
+
*/
|
49
|
+
|
50
|
+
#include "../include/czmq.h"
|
51
|
+
|
52
|
+
// Structure of our class
|
53
|
+
|
54
|
+
struct _zcertstore_t {
|
55
|
+
char *location; // Directory location
|
56
|
+
// This isn't sufficient; we should check the hash of all files
|
57
|
+
// or else use a trigger like inotify on Linux.
|
58
|
+
time_t modified; // Modified time of directory
|
59
|
+
size_t count; // Number of certificates
|
60
|
+
size_t cursize; // Total size of certificates
|
61
|
+
zlist_t *cert_list; // List of loaded certificates
|
62
|
+
zhash_t *cert_hash; // Hash of loaded certificates
|
63
|
+
};
|
64
|
+
|
65
|
+
|
66
|
+
// --------------------------------------------------------------------------
|
67
|
+
// Constructor
|
68
|
+
//
|
69
|
+
// Create a new certificate store from a disk directory, loading and
|
70
|
+
// indexing all certificates in that location. The directory itself may be
|
71
|
+
// absent, and created later, or modified at any time. The certificate store
|
72
|
+
// is automatically refreshed on any zcertstore_lookup() call. If the
|
73
|
+
// location is specified as NULL, creates a pure-memory store, which you
|
74
|
+
// can work with by inserting certificates at runtime. The location is
|
75
|
+
// treated as a printf format.
|
76
|
+
|
77
|
+
static void s_load_certs_from_disk (zcertstore_t *self);
|
78
|
+
|
79
|
+
zcertstore_t *
|
80
|
+
zcertstore_new (char *location, ...)
|
81
|
+
{
|
82
|
+
zcertstore_t *self = (zcertstore_t *) zmalloc (sizeof (zcertstore_t));
|
83
|
+
assert (self);
|
84
|
+
|
85
|
+
self->cert_list = zlist_new ();
|
86
|
+
self->cert_hash = zhash_new ();
|
87
|
+
if (location) {
|
88
|
+
va_list argptr;
|
89
|
+
va_start (argptr, location);
|
90
|
+
self->location = zsys_vprintf (location, argptr);
|
91
|
+
va_end (argptr);
|
92
|
+
s_load_certs_from_disk (self);
|
93
|
+
}
|
94
|
+
return self;
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
// Get rid of any existing certificates in the store, but leave the
|
99
|
+
// store list and hash in place.
|
100
|
+
|
101
|
+
static void
|
102
|
+
s_empty_store (zcertstore_t *self)
|
103
|
+
{
|
104
|
+
zcert_t *cert = (zcert_t *) zlist_pop (self->cert_list);
|
105
|
+
while (cert) {
|
106
|
+
zhash_delete (self->cert_hash, zcert_public_txt (cert));
|
107
|
+
zcert_destroy (&cert);
|
108
|
+
cert = (zcert_t *) zlist_pop (self->cert_list);
|
109
|
+
}
|
110
|
+
assert (zlist_size (self->cert_list) == 0);
|
111
|
+
assert (zhash_size (self->cert_hash) == 0);
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
// Load certificates from directory location, if it exists
|
116
|
+
|
117
|
+
static void
|
118
|
+
s_load_certs_from_disk (zcertstore_t *self)
|
119
|
+
{
|
120
|
+
s_empty_store (self);
|
121
|
+
zdir_t *dir = zdir_new (self->location, NULL);
|
122
|
+
if (dir) {
|
123
|
+
// Load all certificates including those in subdirectories
|
124
|
+
zfile_t **filelist = zdir_flatten (dir);
|
125
|
+
uint index;
|
126
|
+
for (index = 0;; index++) {
|
127
|
+
zfile_t *file = filelist [index];
|
128
|
+
if (!file)
|
129
|
+
break; // End of list
|
130
|
+
if (zfile_is_regular (file)) {
|
131
|
+
zcert_t *cert = zcert_load (zfile_filename (file, NULL));
|
132
|
+
if (cert)
|
133
|
+
zcertstore_insert (self, &cert);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
free (filelist);
|
137
|
+
self->modified = zdir_modified (dir);
|
138
|
+
self->count = zdir_count (dir);
|
139
|
+
self->cursize = zdir_cursize (dir);
|
140
|
+
|
141
|
+
zdir_destroy (&dir);
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
// --------------------------------------------------------------------------
|
147
|
+
// Destructor
|
148
|
+
//
|
149
|
+
// Destroy a certificate store object in memory. Does not affect anything
|
150
|
+
// stored on disk.
|
151
|
+
|
152
|
+
void
|
153
|
+
zcertstore_destroy (zcertstore_t **self_p)
|
154
|
+
{
|
155
|
+
assert (self_p);
|
156
|
+
if (*self_p) {
|
157
|
+
zcertstore_t *self = *self_p;
|
158
|
+
s_empty_store (self);
|
159
|
+
zlist_destroy (&self->cert_list);
|
160
|
+
zhash_destroy (&self->cert_hash);
|
161
|
+
free (self->location);
|
162
|
+
free (self);
|
163
|
+
*self_p = NULL;
|
164
|
+
}
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
// --------------------------------------------------------------------------
|
169
|
+
// Look up certificate by public key, returns zcert_t object if found,
|
170
|
+
// else returns NULL. The public key is provided in Z85 text format.
|
171
|
+
|
172
|
+
zcert_t *
|
173
|
+
zcertstore_lookup (zcertstore_t *self, char *public_key)
|
174
|
+
{
|
175
|
+
// If directory has changed, reload all certificates
|
176
|
+
if (self->location) {
|
177
|
+
zdir_t *dir = zdir_new (self->location, NULL);
|
178
|
+
if (dir
|
179
|
+
&& (self->modified != zdir_modified (dir)
|
180
|
+
|| self->count != zdir_count (dir)
|
181
|
+
|| self->cursize != zdir_cursize (dir))) {
|
182
|
+
s_load_certs_from_disk (self);
|
183
|
+
}
|
184
|
+
zdir_destroy (&dir);
|
185
|
+
}
|
186
|
+
return (zcert_t *) zhash_lookup (self->cert_hash, public_key);
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
// --------------------------------------------------------------------------
|
191
|
+
// Insert certificate into certificate store in memory. Note that this
|
192
|
+
// does not save the certificate to disk. To do that, use zcert_save()
|
193
|
+
// directly on the certificate.
|
194
|
+
|
195
|
+
void
|
196
|
+
zcertstore_insert (zcertstore_t *self, zcert_t **cert_p)
|
197
|
+
{
|
198
|
+
zlist_append (self->cert_list, *cert_p);
|
199
|
+
zhash_insert (self->cert_hash, zcert_public_txt (*cert_p), *cert_p);
|
200
|
+
*cert_p = NULL; // We own this now
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
// --------------------------------------------------------------------------
|
205
|
+
// Print out list of certificates in store to stdout, for debugging
|
206
|
+
// purposes.
|
207
|
+
|
208
|
+
void
|
209
|
+
zcertstore_dump (zcertstore_t *self)
|
210
|
+
{
|
211
|
+
if (self->location)
|
212
|
+
printf ("Certificate store at %s:\n", self->location);
|
213
|
+
else
|
214
|
+
printf ("Certificate store\n");
|
215
|
+
|
216
|
+
zcert_t *cert = (zcert_t *) zlist_first (self->cert_list);
|
217
|
+
while (cert) {
|
218
|
+
zcert_dump (cert);
|
219
|
+
cert = (zcert_t *) (zcert_t *) zlist_next (self->cert_list);
|
220
|
+
}
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
// --------------------------------------------------------------------------
|
225
|
+
// Selftest
|
226
|
+
|
227
|
+
int
|
228
|
+
zcertstore_test (bool verbose)
|
229
|
+
{
|
230
|
+
printf (" * zcertstore: ");
|
231
|
+
#if (ZMQ_VERSION_MAJOR == 4)
|
232
|
+
// @selftest
|
233
|
+
// Create temporary directory for test files
|
234
|
+
# define TESTDIR ".test_zcertstore"
|
235
|
+
zsys_dir_create (TESTDIR);
|
236
|
+
|
237
|
+
// Load certificate store from disk; it will be empty
|
238
|
+
zcertstore_t *certstore = zcertstore_new ("%s", TESTDIR);
|
239
|
+
|
240
|
+
// Create a single new certificate and save to disk
|
241
|
+
zcert_t *cert = zcert_new ();
|
242
|
+
char *client_key = strdup (zcert_public_txt (cert));
|
243
|
+
zcert_set_meta (cert, "name", "John Doe");
|
244
|
+
zcert_save (cert, TESTDIR "/mycert.txt");
|
245
|
+
zcert_destroy (&cert);
|
246
|
+
|
247
|
+
// Check that certificate store refreshes as expected
|
248
|
+
cert = zcertstore_lookup (certstore, client_key);
|
249
|
+
assert (cert);
|
250
|
+
assert (streq (zcert_meta (cert, "name"), "John Doe"));
|
251
|
+
free (client_key);
|
252
|
+
if (verbose)
|
253
|
+
zcertstore_dump (certstore);
|
254
|
+
|
255
|
+
zcertstore_destroy (&certstore);
|
256
|
+
|
257
|
+
// Delete all test files
|
258
|
+
zdir_t *dir = zdir_new (TESTDIR, NULL);
|
259
|
+
zdir_remove (dir, true);
|
260
|
+
zdir_destroy (&dir);
|
261
|
+
// @end
|
262
|
+
#endif
|
263
|
+
printf ("OK\n");
|
264
|
+
return 0;
|
265
|
+
}
|
@@ -0,0 +1,207 @@
|
|
1
|
+
/* =========================================================================
|
2
|
+
zchunk - work with memory chunks
|
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 MERCHANTA-
|
18
|
+
BILITY 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
|
+
@header
|
27
|
+
The zchunk class works with variable sized blobs. Not as efficient as
|
28
|
+
ØMQ's messages but they do less weirdness and so are easier to understand.
|
29
|
+
The chunk class has methods to read and write chunks from disk.
|
30
|
+
@discuss
|
31
|
+
@end
|
32
|
+
*/
|
33
|
+
|
34
|
+
#include "../include/czmq.h"
|
35
|
+
|
36
|
+
// Structure of our class
|
37
|
+
|
38
|
+
struct _zchunk_t {
|
39
|
+
size_t size; // Current size of data part
|
40
|
+
size_t max_size; // Maximum allocated size
|
41
|
+
byte *data; // Data part follows here
|
42
|
+
};
|
43
|
+
|
44
|
+
|
45
|
+
// --------------------------------------------------------------------------
|
46
|
+
// Constructor
|
47
|
+
|
48
|
+
zchunk_t *
|
49
|
+
zchunk_new (const void *data, size_t size)
|
50
|
+
{
|
51
|
+
zchunk_t *self = (zchunk_t *) zmalloc (sizeof (zchunk_t) + size);
|
52
|
+
if (self) {
|
53
|
+
self->max_size = size;
|
54
|
+
self->data = (byte *) self + sizeof (zchunk_t);
|
55
|
+
if (data) {
|
56
|
+
self->size = size;
|
57
|
+
memcpy (self->data, data, size);
|
58
|
+
}
|
59
|
+
else
|
60
|
+
self->size = 0;
|
61
|
+
}
|
62
|
+
return self;
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
// --------------------------------------------------------------------------
|
67
|
+
// Destroy a chunk
|
68
|
+
|
69
|
+
void
|
70
|
+
zchunk_destroy (zchunk_t **self_p)
|
71
|
+
{
|
72
|
+
assert (self_p);
|
73
|
+
if (*self_p) {
|
74
|
+
zchunk_t *self = *self_p;
|
75
|
+
// If data was reallocated independently, free it independently
|
76
|
+
if (self->data != (byte *) self + sizeof (zchunk_t))
|
77
|
+
free (self->data);
|
78
|
+
|
79
|
+
free (self);
|
80
|
+
*self_p = NULL;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
|
85
|
+
// --------------------------------------------------------------------------
|
86
|
+
// Resizes chunk max_size as requested; chunk_cur size is set to zero
|
87
|
+
|
88
|
+
void
|
89
|
+
zchunk_resize (zchunk_t *self, size_t size)
|
90
|
+
{
|
91
|
+
// If data was reallocated independently, free it independently
|
92
|
+
if (self->data != (byte *) self + sizeof (zchunk_t))
|
93
|
+
free (self->data);
|
94
|
+
|
95
|
+
self->data = (byte *) zmalloc (size);
|
96
|
+
self->max_size = size;
|
97
|
+
self->size = 0;
|
98
|
+
}
|
99
|
+
|
100
|
+
|
101
|
+
// --------------------------------------------------------------------------
|
102
|
+
// Set chunk data from user-supplied data; truncate if too large
|
103
|
+
// Returns actual size of chunk
|
104
|
+
|
105
|
+
size_t
|
106
|
+
zchunk_set (zchunk_t *self, const void *data, size_t size)
|
107
|
+
{
|
108
|
+
assert (self);
|
109
|
+
if (size > self->max_size)
|
110
|
+
size = self->max_size;
|
111
|
+
memcpy (self->data, data, size);
|
112
|
+
self->size = size;
|
113
|
+
return size;
|
114
|
+
}
|
115
|
+
|
116
|
+
|
117
|
+
// --------------------------------------------------------------------------
|
118
|
+
// Fill chunk data from user-supplied octet
|
119
|
+
// Returns actual size of chunk
|
120
|
+
|
121
|
+
size_t
|
122
|
+
zchunk_fill (zchunk_t *self, byte filler, size_t size)
|
123
|
+
{
|
124
|
+
assert (self);
|
125
|
+
if (size > self->max_size)
|
126
|
+
size = self->max_size;
|
127
|
+
memset (self->data, filler, size);
|
128
|
+
self->size = size;
|
129
|
+
return size;
|
130
|
+
}
|
131
|
+
|
132
|
+
|
133
|
+
// --------------------------------------------------------------------------
|
134
|
+
// Return chunk cur size
|
135
|
+
|
136
|
+
size_t
|
137
|
+
zchunk_size (zchunk_t *self)
|
138
|
+
{
|
139
|
+
assert (self);
|
140
|
+
return self->size;
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
// --------------------------------------------------------------------------
|
145
|
+
// Return chunk max size
|
146
|
+
|
147
|
+
size_t
|
148
|
+
zchunk_max_size (zchunk_t *self)
|
149
|
+
{
|
150
|
+
assert (self);
|
151
|
+
return self->max_size;
|
152
|
+
}
|
153
|
+
|
154
|
+
|
155
|
+
// --------------------------------------------------------------------------
|
156
|
+
// Return chunk data
|
157
|
+
|
158
|
+
byte *
|
159
|
+
zchunk_data (zchunk_t *self)
|
160
|
+
{
|
161
|
+
assert (self);
|
162
|
+
return self->data;
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
// --------------------------------------------------------------------------
|
167
|
+
// Read chunk from an open file descriptor
|
168
|
+
|
169
|
+
zchunk_t *
|
170
|
+
zchunk_read (FILE *handle, size_t bytes)
|
171
|
+
{
|
172
|
+
zchunk_t *self = zchunk_new (NULL, bytes);
|
173
|
+
self->size = fread (self->data, 1, bytes, handle);
|
174
|
+
return self;
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
// --------------------------------------------------------------------------
|
179
|
+
// Write chunk to an open file descriptor
|
180
|
+
|
181
|
+
int
|
182
|
+
zchunk_write (zchunk_t *self, FILE *handle)
|
183
|
+
{
|
184
|
+
size_t items = fwrite (self->data, 1, self->size, handle);
|
185
|
+
int rc = (items < self->size)? -1: 0;
|
186
|
+
return rc;
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
// --------------------------------------------------------------------------
|
191
|
+
// Self test of this class
|
192
|
+
int
|
193
|
+
zchunk_test (bool verbose)
|
194
|
+
{
|
195
|
+
printf (" * zchunk: ");
|
196
|
+
|
197
|
+
// @selftest
|
198
|
+
zchunk_t *chunk = zchunk_new ("1234567890", 10);
|
199
|
+
assert (chunk);
|
200
|
+
assert (zchunk_size (chunk) == 10);
|
201
|
+
assert (memcmp (zchunk_data (chunk), "1234567890", 10) == 0);
|
202
|
+
zchunk_destroy (&chunk);
|
203
|
+
// @end
|
204
|
+
|
205
|
+
printf ("OK\n");
|
206
|
+
return 0;
|
207
|
+
}
|