pax_global_header00006660000000000000000000000064125403663270014522gustar00rootroot0000000000000052 comment=4784589eff234e673724662c9247037e4c804e5d zmqpp-4.1.2/000077500000000000000000000000001254036632700126755ustar00rootroot00000000000000zmqpp-4.1.2/.gitignore000066400000000000000000000000501254036632700146600ustar00rootroot00000000000000build docs .cproject .project .settings zmqpp-4.1.2/.travis.yml000066400000000000000000000014771254036632700150170ustar00rootroot00000000000000# Zmqpp language: cpp env: - ZMQ_REPO=zeromq3-x BUILD_TYPE=default - ZMQ_REPO=zeromq4-x BUILD_TYPE=default WITH_LIBSODIUM=1 - ZMQ_REPO=zeromq4-1 BUILD_TYPE=default WITH_LIBSODIUM=1 - ZMQ_REPO=libzmq BUILD_TYPE=default WITH_LIBSODIUM=1 - ZMQ_REPO=zeromq3-x BUILD_TYPE=cmake - ZMQ_REPO=zeromq4-x BUILD_TYPE=cmake WITH_LIBSODIUM=1 - ZMQ_REPO=zeromq4-1 BUILD_TYPE=cmake WITH_LIBSODIUM=1 - ZMQ_REPO=libzmq BUILD_TYPE=cmake WITH_LIBSODIUM=1 before_install: - if [ "$CXX" == "g++" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; fi - sudo apt-get update install: # g++4.8.1 - if [ "$CXX" = "g++" ]; then sudo apt-get install -qq g++-4.8; fi - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8"; fi # Requirements - sudo apt-get install -qq libboost-all-dev script: - ./travis.sh zmqpp-4.1.2/AUTHORS000066400000000000000000000010461254036632700137460ustar00rootroot00000000000000Individual Contributors ======================= Author: Ben Gray Author: Dmitry Odzerikho Author: Michi Henning Author: Pieter Hintjens Author: Rob Hubbard Author: Dinka Ranns Author: Olaf Lenz Author: Krzysztof Rapacki Author: Prem Shankar Kumar Author: Arnaud Kapp Author: Lionel Orry zmqpp-4.1.2/CHANGES.md000066400000000000000000000121761254036632700142760ustar00rootroot00000000000000Development =========== Version 4.1.2 ============= * Fix a compilation bug (#119) * Improve documentation Version 4.1.1 ============= Breaking -------- * Removed message::add(pointer, size_t) as there were situations it conflicts with the new easier to use templated add. This has been replaced with a message::add_raw(pointer, size_t) method. Other changes ------------- * Added options to pop from/push to front of a message, this adds a new frame before the current ones. * Added matching but redundant pop from/push to the end of the message. * Support for remaining 0mq 3.2 and 4.0 socket options. * socket_option::conflate keep only one message in queues, ignores high water mark options. Only supports single part messages. * socket_option::curve_public_key set curve long term public key. This must be set on CURVE client sockets. You can provide the key as 32 binary bytes, or as a 40-character string encoded in the Z85 encoding format. * socket_option::curve_secret_key set curve long term secret key. This must be set on both CURVE client and server sockets. You can provide the key as 32 binary bytes, or as a 40-character string encoded in the Z85 encoding format. * socket_option::curve_server_key set the long term server key. This must be set on CURVE client sockets. You can provide the key as 32 binary bytes, or as a 40-character string encoded in the Z85 encoding format. * socket_option::curve_server defines if the socket will at as a server for CURVE security. * socket_option::ipv6 replacing the now deprecated ipv4only option, enables support for ipv6. * socket_option::mechanism query the socket to find the current security mechanism, if any. * socket_option::plain_password Sets the password for outgoing connections over TCP or IPC. * socket_option::plain_server defines whether the socket will act as server for PLAIN security. * socket_option::plain_username Sets the username for outgoing connections over TCP or IPC. * socket_option::probe_router Tell a router to automatically end an empty message when a new connection is made or accepted. You may set this on REQ, DEALER, or ROUTER sockets connected to a ROUTER socket. * socket_option::request_correlate Tell a REQ socket to prefix outgoing messages with an extra frame containing a request id. * socket_option::request_relaxed trigger reconnect on send instead of forcing a wait for previous reply. * socket_option::router_raw Don't apply 0mq framing to message, allowing talk to non-0mq sockets. * socket_option::zap_domain Domain value for ZAP (ZMQ RFC 27) authentication. * Support for 4.0 context option. * context_option::ipv6 replacing the now deprecated ipv4only option, enables support for ipv6. * Basic wrapper of socket monitor, socket class now has a monitor function that setups the inproc monitor socket against it. * Basic curve support. Allowing generation of keys via more c++ style interfaces as well as decoding and encoding z85 formatted data. Version 3.2.0 ============= * Reworked client application, this is technically breaking but its only the the client so noone should care. Multipart support that works with linux pipes is now the default. * Added a new -d detailed verbose option, the only reason it is not -vv is lack of boost option support. This provides diagnostic information. * Added -s to support single part messages, incase anyone actually used that. Version 3.1.0 ============= * Support for 3.2 socket disconnect and unbind. Version 3.0.0 ============= Breaking -------- * All constants are now lower_case rather the FULL_CAPITAL, this was due to defintiations conflicting with some of the values * Message class methods that read data are now marked as const. This is only potentially breaking and probably will not harm most people. Other changes ------------- * Support for 3.2 style contexts and context options * context_option::io_threads to set the number of threads required. This must be set before sockets are created to have any effect. Default 1. * context_option::max_sockets to set the maximum number of sockets allowed by this context. Default 1024. * Support for new 3.2 socket options * socket_option::delay_attach_on_connect to force connections to delay creating internal buffers until the connection to the remote endpoint. * socket_option::last_endpoint to get the last endpoint this socket was bound to. * socket_option::router_mandatory to enable routablity error checking on router sockets. * socket_option::xpub_verbose to force all subscriptions to bubble up the system rather than just new subscriptions. * socket_option::tcp_keepalive to enable tcp level keepalives, a special value of -1 is used for os default. * socket_option::tcp_keepalive_idle to force an overide of the keepalive count, often this is the retry count. * socket_option::tcp_keepalive_count to force an overide of the retry count. * socket_option::tcp_keepalive_interval to alter time between keepalives. * socket_option::tcp_accept_filter to add address based whitelist for incomming connections. zmqpp-4.1.2/CMakeLists.txt000066400000000000000000000150661254036632700154450ustar00rootroot00000000000000# ZMQPP Cmake build description. # ============================== # # CMake should find the zmq libraries / headers automatically if they are # installed system-wide. If CMake cannot find them not, or you would like to # use custom built ones, set these variables: # # - ZEROMQ_LIB_DIR to the directory where libzmq / libzmq-shared is located # # - ZEROMQ_INCLUDE_DIR to the directory where zmq.h is located # cmake_minimum_required(VERSION 2.8) enable_testing() # prepare C++11 set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") # show all warnings set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra") # Set a consistent MACOSX_RPATH default across all CMake versions. When CMake # 2.8.12 is required, change this default to 1. When CMake 3.0.0 is required, # remove this block (see CMP0042). # # TODO: verify correctness of this flag if(NOT DEFINED CMAKE_MACOSX_RPATH) set(CMAKE_MACOSX_RPATH 0) endif() # If libzmq is build in the same cmake global project and we want to # depends on it instead of searching for libzmq in the system, we set this to true set( ZMQPP_LIBZMQ_CMAKE false CACHE BOOL "libzmq is build through cmake too" ) set( ZMQPP_BUILD_STATIC true CACHE BOOL "Build the ZMQPP static library" ) set( ZMQPP_BUILD_SHARED true CACHE BOOL "Build the ZMQPP dynamic library" ) set( ZMQPP_BUILD_EXAMPLES false CACHE BOOL "Build the ZMQPP examples" ) set( ZMQPP_BUILD_CLIENT false CACHE BOOL "Build the ZMQPP client" ) set( ZMQPP_BUILD_TESTS false CACHE BOOL "Build the ZMQPP tests" ) # Since the current CMake build of ZMQ does not work for generating a dynamic libzmq, # give a chance for users to update which ZMQ library to link to # zmq-static is the name of the static target in libzmq's CMakeLists.txt set( ZMQPP_LIBZMQ_NAME_STATIC "zmq-static" CACHE STRING "The ZMQ library to link the static ZMQPP. (if built)" ) set( ZMQPP_LIBZMQ_NAME_SHARED "zmq" CACHE STRING "The ZMQ library to link the dynamic ZMQPP. (if built)" ) # Paths to set to look for zmq set( ZEROMQ_LIB_DIR "" CACHE PATH "The library directory for libzmq" ) set( ZEROMQ_INCLUDE_DIR "" CACHE PATH "The include directory for ZMQ" ) # Build flags set( IS_TRAVIS_CI_BUILD true CACHE bool "Defines TRAVIS_CI_BUILD - Should the tests avoid running cases where memory is scarce." ) # Find zmq.h and add its dir to the includes find_path(ZEROMQ_INCLUDE zmq.h PATHS ${ZEROMQ_INCLUDE_DIR}) include_directories(${ZEROMQ_INCLUDE_DIR} ${ZEROMQ_INCLUDE} ${CMAKE_CURRENT_SOURCE_DIR}/src ) # Do not run some tests when building on travis-ci (this cause oom error and kill the test # process) # These tests seem to be: # - sending_large_messages_string if (IS_TRAVIS_CI_BUILD) add_definitions( -DTRAVIS_CI_BUILD) endif() set( INSTALL_TARGET_LIST ) # The library to link with the examples and the tests. # Because we may or may not build shared/static libs, this needs to # be dynamic set( LIB_TO_LINK_TO_EXAMPLES ) # libzmqpp # -------- set( LIBZMQPP_SOURCES src/zmqpp/actor.cpp src/zmqpp/context.cpp src/zmqpp/curve.cpp src/zmqpp/frame.cpp src/zmqpp/message.cpp src/zmqpp/poller.cpp src/zmqpp/reactor.cpp src/zmqpp/signal.cpp src/zmqpp/socket.cpp src/zmqpp/z85.cpp src/zmqpp/zap_request.cpp src/zmqpp/auth.cpp src/zmqpp/zmqpp.cpp ) # Staticlib if (ZMQPP_BUILD_STATIC) add_library( zmqpp-static STATIC ${LIBZMQPP_SOURCES}) if (NOT ZMQPP_LIBZMQ_CMAKE) find_library(ZEROMQ_LIBRARY_STATIC ${ZMQPP_LIBZMQ_NAME_STATIC} PATHS ${ZEROMQ_LIB_DIR}) if (NOT ZEROMQ_LIBRARY_STATIC) # If libzmq was not installed through CMake, the static binary is libzmq.a not libzmq-static.a find_library(ZEROMQ_LIBRARY_STATIC libzmq.a PATHS ${ZEROMQ_LIB_DIR}) endif() target_link_libraries( zmqpp-static ${ZEROMQ_LIBRARY_STATIC}) else() # libzmq-static is the name of the target from # libzmq's CMake target_link_libraries(zmqpp-static libzmq-static) endif() list( APPEND INSTALL_TARGET_LIST zmqpp-static) set( LIB_TO_LINK_TO_EXAMPLES zmqpp-static ) endif() # ZMQPP_BUILD_STATIC # Shared lib if (ZMQPP_BUILD_SHARED) add_library( zmqpp SHARED ${LIBZMQPP_SOURCES}) if (NOT ZMQPP_LIBZMQ_CMAKE) find_library(ZEROMQ_LIBRARY_SHARED ${ZMQPP_LIBZMQ_NAME_SHARED} PATHS ${ZEROMQ_LIB_DIR}) target_link_libraries( zmqpp ${ZEROMQ_LIBRARY_SHARED} ) else() # libzmq is the name of the target from # libzmq's CMake target_link_libraries(zmqpp libzmq) endif() list( APPEND INSTALL_TARGET_LIST zmqpp) set( LIB_TO_LINK_TO_EXAMPLES zmqpp ) endif() # ZMQPP_BUILD_SHARED # Examples # -------- if(ZMQPP_BUILD_EXAMPLES) add_executable( zmqpp-simple-server examples/simple_server ) add_executable( zmqpp-simple-client examples/simple_client ) target_link_libraries( zmqpp-simple-client ${LIB_TO_LINK_TO_EXAMPLES} ) target_link_libraries( zmqpp-simple-server ${LIB_TO_LINK_TO_EXAMPLES} ) list( APPEND INSTALL_TARGET_LIST zmqpp-simple-server zmqpp-simple-client ) endif() # Client # ------ if( ZMQPP_BUILD_CLIENT ) # Boost # ----- set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) find_package(Boost REQUIRED COMPONENTS program_options ) include_directories( ${Boost_INCLUDE_DIRS} ) add_executable( zmqpp-client src/client/main.cpp src/client/options.cpp ) target_link_libraries( zmqpp-client ${LIB_TO_LINK_TO_EXAMPLES} ${Boost_LIBRARIES} ) list( APPEND INSTALL_TARGET_LIST zmqpp-client ) endif() # Tests # ----- if( ZMQPP_BUILD_TESTS ) # # Boost # ----- set(Boost_USE_STATIC_LIBS OFF) # only find static libs set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) find_package(Boost REQUIRED COMPONENTS thread system unit_test_framework) include_directories( ${Boost_INCLUDE_DIRS} ) add_executable( zmqpp-test-runner src/tests/test_actor.cpp src/tests/test_context.cpp src/tests/test_inet.cpp src/tests/test_load.cpp src/tests/test_message.cpp src/tests/test_message_stream.cpp src/tests/test_poller.cpp src/tests/test_reactor.cpp src/tests/test_sanity.cpp src/tests/test_socket.cpp src/tests/test_socket_options.cpp src/tests/test_z85.cpp src/tests/test_auth.cpp ) target_link_libraries( zmqpp-test-runner ${LIB_TO_LINK_TO_EXAMPLES} ${Boost_LIBRARIES}) add_test( zmqpp-test zmqpp-test-runner --log-level=test-suite ) endif() # Install # ------- install(TARGETS ${INSTALL_TARGET_LIST} RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(DIRECTORY src/zmqpp DESTINATION include/ FILES_MATCHING PATTERN "*.hpp") zmqpp-4.1.2/Doxyfile000066400000000000000000002276401254036632700144160ustar00rootroot00000000000000# Doxyfile 1.8.2 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project. # # All text after a hash (#) is considered a comment and will be ignored. # The format is: # TAG = value [value, ...] # For lists items can also be appended using: # TAG += value [value, ...] # Values that contain spaces should be placed between quotes (" "). #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- # This tag specifies the encoding used for all characters in the config file # that follow. The default is UTF-8 which is also the encoding used for all # text before the first occurrence of this tag. Doxygen uses libiconv (or the # iconv built into libc) for the transcoding. See # http://www.gnu.org/software/libiconv for the list of possible encodings. DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or sequence of words) that should # identify the project. Note that if you do not use Doxywizard you need # to put quotes around the project name if it contains spaces. PROJECT_NAME = zmqpp # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or # if some version control system is used. PROJECT_NUMBER = 4.1.2 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer # a quick idea about the purpose of the project. Keep the description short. PROJECT_BRIEF = "C++ bindings for 0mq (libzmq)" # With the PROJECT_LOGO tag one can specify an logo or icon that is # included in the documentation. The maximum height of the logo should not # exceed 55 pixels and the maximum width should not exceed 200 pixels. # Doxygen will copy the logo to the output directory. PROJECT_LOGO = # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. # If a relative path is entered, it will be relative to the location # where doxygen was started. If left blank the current directory will be used. OUTPUT_DIRECTORY = ./docs # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create # 4096 sub-directories (in 2 levels) under the output directory of each output # format and will distribute the generated files over these directories. # Enabling this option can be useful when feeding doxygen a huge amount of # source files, where putting all generated files in the same directory would # otherwise cause performance problems for the file system. CREATE_SUBDIRS = NO # The OUTPUT_LANGUAGE tag is used to specify the language in which all # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. # The default language is English, other supported languages are: # Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, # Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, # Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English # messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, # Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, # Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. OUTPUT_LANGUAGE = English # If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will # include brief member descriptions after the members that are listed in # the file and class documentation (similar to JavaDoc). # Set to NO to disable this. BRIEF_MEMBER_DESC = YES # If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend # the brief description of a member or function before the detailed description. # Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the # brief descriptions will be completely suppressed. REPEAT_BRIEF = YES # This tag implements a quasi-intelligent brief description abbreviator # that is used to form the text in various listings. Each string # in this list, if found as the leading text of the brief description, will be # stripped from the text and the result after processing the whole list, is # used as the annotated text. Otherwise, the brief description is used as-is. # If left blank, the following values are used ("$name" is automatically # replaced with the name of the entity): "The $name class" "The $name widget" # "The $name file" "is" "provides" "specifies" "contains" # "represents" "a" "an" "the" ABBREVIATE_BRIEF = # If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then # Doxygen will generate a detailed section even if there is only a brief # description. ALWAYS_DETAILED_SEC = NO # If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all # inherited members of a class in the documentation of that class as if those # members were ordinary class members. Constructors, destructors and assignment # operators of the base classes will not be shown. INLINE_INHERITED_MEMB = NO # If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full # path before files name in the file list and in the header files. If set # to NO the shortest path that makes the file name unique will be used. FULL_PATH_NAMES = YES # If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag # can be used to strip a user-defined part of the path. Stripping is # only done if one of the specified strings matches the left-hand part of # the path. The tag can be used to show relative paths in the file list. # If left blank the directory from which doxygen is run is used as the # path to strip. Note that you specify absolute paths here, but also # relative paths, which will be relative from the directory where doxygen is # started. STRIP_FROM_PATH = # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of # the path mentioned in the documentation of a class, which tells # the reader which header file to include in order to use a class. # If left blank only the name of the header file containing the class # definition is used. Otherwise one should specify the include paths that # are normally passed to the compiler using the -I flag. STRIP_FROM_INC_PATH = # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter # (but less readable) file names. This can be useful if your file system # doesn't support long names like on DOS, Mac, or CD-ROM. SHORT_NAMES = NO # If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen # will interpret the first line (until the first dot) of a JavaDoc-style # comment as the brief description. If set to NO, the JavaDoc # comments will behave just like regular Qt-style comments # (thus requiring an explicit @brief command for a brief description.) JAVADOC_AUTOBRIEF = YES # If the QT_AUTOBRIEF tag is set to YES then Doxygen will # interpret the first line (until the first dot) of a Qt-style # comment as the brief description. If set to NO, the comments # will behave just like regular Qt-style comments (thus requiring # an explicit \brief command for a brief description.) QT_AUTOBRIEF = NO # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen # treat a multi-line C++ special comment block (i.e. a block of //! or /// # comments) as a brief description. This used to be the default behaviour. # The new default is to treat a multi-line C++ comment block as a detailed # description. Set this tag to YES if you prefer the old behaviour instead. MULTILINE_CPP_IS_BRIEF = NO # If the INHERIT_DOCS tag is set to YES (the default) then an undocumented # member inherits the documentation from any documented member that it # re-implements. INHERIT_DOCS = YES # If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce # a new page for each member. If set to NO, the documentation of a member will # be part of the file/class/namespace that contains it. SEPARATE_MEMBER_PAGES = NO # The TAB_SIZE tag can be used to set the number of spaces in a tab. # Doxygen uses this value to replace tabs by spaces in code fragments. TAB_SIZE = 4 # This tag can be used to specify a number of aliases that acts # as commands in the documentation. An alias has the form "name=value". # For example adding "sideeffect=\par Side Effects:\n" will allow you to # put the command \sideeffect (or @sideeffect) in the documentation, which # will result in a user-defined paragraph with heading "Side Effects:". # You can put \n's in the value part of an alias to insert newlines. ALIASES = # This tag can be used to specify a number of word-keyword mappings (TCL only). # A mapping has the form "name=value". For example adding # "class=itcl::class" will allow you to use the command class in the # itcl::class meaning. TCL_SUBST = # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C # sources only. Doxygen will then generate output that is more tailored for C. # For instance, some of the names that are used will be different. The list # of all members will be omitted, etc. OPTIMIZE_OUTPUT_FOR_C = NO # Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java # sources only. Doxygen will then generate output that is more tailored for # Java. For instance, namespaces will be presented as packages, qualified # scopes will look different, etc. OPTIMIZE_OUTPUT_JAVA = NO # Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran # sources only. Doxygen will then generate output that is more tailored for # Fortran. OPTIMIZE_FOR_FORTRAN = NO # Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL # sources. Doxygen will then generate output that is tailored for # VHDL. OPTIMIZE_OUTPUT_VHDL = NO # Doxygen selects the parser to use depending on the extension of the files it # parses. With this tag you can assign which parser to use for a given # extension. Doxygen has a built-in mapping, but you can override or extend it # using this tag. The format is ext=language, where ext is a file extension, # and language is one of the parsers supported by doxygen: IDL, Java, # Javascript, CSharp, C, C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, # C++. For instance to make doxygen treat .inc files as Fortran files (default # is PHP), and .f files as C (default is Fortran), use: inc=Fortran f=C. Note # that for custom extensions you also need to set FILE_PATTERNS otherwise the # files are not read by doxygen. EXTENSION_MAPPING = # If MARKDOWN_SUPPORT is enabled (the default) then doxygen pre-processes all # comments according to the Markdown format, which allows for more readable # documentation. See http://daringfireball.net/projects/markdown/ for details. # The output of markdown processing is further processed by doxygen, so you # can mix doxygen, HTML, and XML commands with Markdown formatting. # Disable only in case of backward compatibilities issues. MARKDOWN_SUPPORT = YES # When enabled doxygen tries to link words that correspond to documented classes, # or namespaces to their corresponding documentation. Such a link can be # prevented in individual cases by by putting a % sign in front of the word or # globally by setting AUTOLINK_SUPPORT to NO. AUTOLINK_SUPPORT = YES # If you use STL classes (i.e. std::string, std::vector, etc.) but do not want # to include (a tag file for) the STL sources as input, then you should # set this tag to YES in order to let doxygen match functions declarations and # definitions whose arguments contain STL classes (e.g. func(std::string); v.s. # func(std::string) {}). This also makes the inheritance and collaboration # diagrams that involve STL classes more complete and accurate. BUILTIN_STL_SUPPORT = YES # If you use Microsoft's C++/CLI language, you should set this option to YES to # enable parsing support. CPP_CLI_SUPPORT = NO # Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. # Doxygen will parse them like normal C++ but will assume all classes use public # instead of private inheritance when no explicit protection keyword is present. SIP_SUPPORT = NO # For Microsoft's IDL there are propget and propput attributes to indicate getter and setter methods for a property. Setting this option to YES (the default) will make doxygen replace the get and set methods by a property in the documentation. This will only work if the methods are indeed getting or setting a simple type. If this is not the case, or you want to show the methods anyway, you should set this option to NO. IDL_PROPERTY_SUPPORT = YES # If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC # tag is set to YES, then doxygen will reuse the documentation of the first # member in the group (if any) for the other members of the group. By default # all members of a group must be documented explicitly. DISTRIBUTE_GROUP_DOC = NO # Set the SUBGROUPING tag to YES (the default) to allow class member groups of # the same type (for instance a group of public functions) to be put as a # subgroup of that type (e.g. under the Public Functions section). Set it to # NO to prevent subgrouping. Alternatively, this can be done per class using # the \nosubgrouping command. SUBGROUPING = YES # When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and # unions are shown inside the group in which they are included (e.g. using # @ingroup) instead of on a separate page (for HTML and Man pages) or # section (for LaTeX and RTF). INLINE_GROUPED_CLASSES = NO # When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and # unions with only public data fields will be shown inline in the documentation # of the scope in which they are defined (i.e. file, namespace, or group # documentation), provided this scope is documented. If set to NO (the default), # structs, classes, and unions are shown on a separate page (for HTML and Man # pages) or section (for LaTeX and RTF). INLINE_SIMPLE_STRUCTS = NO # When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum # is documented as struct, union, or enum with the name of the typedef. So # typedef struct TypeS {} TypeT, will appear in the documentation as a struct # with name TypeT. When disabled the typedef will appear as a member of a file, # namespace, or class. And the struct will be named TypeS. This can typically # be useful for C code in case the coding convention dictates that all compound # types are typedef'ed and only the typedef is referenced, never the tag name. TYPEDEF_HIDES_STRUCT = NO # The SYMBOL_CACHE_SIZE determines the size of the internal cache use to # determine which symbols to keep in memory and which to flush to disk. # When the cache is full, less often used symbols will be written to disk. # For small to medium size projects (<1000 input files) the default value is # probably good enough. For larger projects a too small cache size can cause # doxygen to be busy swapping symbols to and from disk most of the time # causing a significant performance penalty. # If the system has enough physical memory increasing the cache will improve the # performance by keeping more symbols in memory. Note that the value works on # a logarithmic scale so increasing the size by one will roughly double the # memory usage. The cache size is given by this formula: # 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, # corresponding to a cache size of 2^16 = 65536 symbols. SYMBOL_CACHE_SIZE = 0 # Similar to the SYMBOL_CACHE_SIZE the size of the symbol lookup cache can be # set using LOOKUP_CACHE_SIZE. This cache is used to resolve symbols given # their name and scope. Since this can be an expensive process and often the # same symbol appear multiple times in the code, doxygen keeps a cache of # pre-resolved symbols. If the cache is too small doxygen will become slower. # If the cache is too large, memory is wasted. The cache size is given by this # formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range is 0..9, the default is 0, # corresponding to a cache size of 2^16 = 65536 symbols. LOOKUP_CACHE_SIZE = 0 #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- # If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in # documentation are documented, even if no documentation was available. # Private class members and static file members will be hidden unless # the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES EXTRACT_ALL = YES # If the EXTRACT_PRIVATE tag is set to YES all private members of a class # will be included in the documentation. EXTRACT_PRIVATE = YES # If the EXTRACT_PACKAGE tag is set to YES all members with package or internal # scope will be included in the documentation. EXTRACT_PACKAGE = NO # If the EXTRACT_STATIC tag is set to YES all static members of a file # will be included in the documentation. EXTRACT_STATIC = NO # If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) # defined locally in source files will be included in the documentation. # If set to NO only classes defined in header files are included. EXTRACT_LOCAL_CLASSES = YES # This flag is only useful for Objective-C code. When set to YES local # methods, which are defined in the implementation section but not in # the interface are included in the documentation. # If set to NO (the default) only methods in the interface are included. EXTRACT_LOCAL_METHODS = NO # If this flag is set to YES, the members of anonymous namespaces will be # extracted and appear in the documentation as a namespace called # 'anonymous_namespace{file}', where file will be replaced with the base # name of the file that contains the anonymous namespace. By default # anonymous namespaces are hidden. EXTRACT_ANON_NSPACES = NO # If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all # undocumented members of documented classes, files or namespaces. # If set to NO (the default) these members will be included in the # various overviews, but no documentation section is generated. # This option has no effect if EXTRACT_ALL is enabled. HIDE_UNDOC_MEMBERS = NO # If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all # undocumented classes that are normally visible in the class hierarchy. # If set to NO (the default) these classes will be included in the various # overviews. This option has no effect if EXTRACT_ALL is enabled. HIDE_UNDOC_CLASSES = NO # If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all # friend (class|struct|union) declarations. # If set to NO (the default) these declarations will be included in the # documentation. HIDE_FRIEND_COMPOUNDS = NO # If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any # documentation blocks found inside the body of a function. # If set to NO (the default) these blocks will be appended to the # function's detailed documentation block. HIDE_IN_BODY_DOCS = NO # The INTERNAL_DOCS tag determines if documentation # that is typed after a \internal command is included. If the tag is set # to NO (the default) then the documentation will be excluded. # Set it to YES to include the internal documentation. INTERNAL_DOCS = NO # If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate # file names in lower-case letters. If set to YES upper-case letters are also # allowed. This is useful if you have classes or files whose names only differ # in case and if your file system supports case sensitive file names. Windows # and Mac users are advised to set this option to NO. CASE_SENSE_NAMES = YES # If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen # will show members with their full class and namespace scopes in the # documentation. If set to YES the scope will be hidden. HIDE_SCOPE_NAMES = NO # If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen # will put a list of the files that are included by a file in the documentation # of that file. SHOW_INCLUDE_FILES = YES # If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen # will list include files with double quotes in the documentation # rather than with sharp brackets. FORCE_LOCAL_INCLUDES = NO # If the INLINE_INFO tag is set to YES (the default) then a tag [inline] # is inserted in the documentation for inline members. INLINE_INFO = YES # If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen # will sort the (detailed) documentation of file and class members # alphabetically by member name. If set to NO the members will appear in # declaration order. SORT_MEMBER_DOCS = YES # If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the # brief documentation of file, namespace and class members alphabetically # by member name. If set to NO (the default) the members will appear in # declaration order. SORT_BRIEF_DOCS = NO # If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen # will sort the (brief and detailed) documentation of class members so that # constructors and destructors are listed first. If set to NO (the default) # the constructors will appear in the respective orders defined by # SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. # This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO # and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. SORT_MEMBERS_CTORS_1ST = NO # If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the # hierarchy of group names into alphabetical order. If set to NO (the default) # the group names will appear in their defined order. SORT_GROUP_NAMES = NO # If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be # sorted by fully-qualified names, including namespaces. If set to # NO (the default), the class list will be sorted only by class name, # not including the namespace part. # Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. # Note: This option applies only to the class list, not to the # alphabetical list. SORT_BY_SCOPE_NAME = NO # If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to # do proper type resolution of all parameters of a function it will reject a # match between the prototype and the implementation of a member function even # if there is only one candidate or it is obvious which candidate to choose # by doing a simple string match. By disabling STRICT_PROTO_MATCHING doxygen # will still accept a match between prototype and implementation in such cases. STRICT_PROTO_MATCHING = NO # The GENERATE_TODOLIST tag can be used to enable (YES) or # disable (NO) the todo list. This list is created by putting \todo # commands in the documentation. GENERATE_TODOLIST = YES # The GENERATE_TESTLIST tag can be used to enable (YES) or # disable (NO) the test list. This list is created by putting \test # commands in the documentation. GENERATE_TESTLIST = YES # The GENERATE_BUGLIST tag can be used to enable (YES) or # disable (NO) the bug list. This list is created by putting \bug # commands in the documentation. GENERATE_BUGLIST = YES # The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or # disable (NO) the deprecated list. This list is created by putting # \deprecated commands in the documentation. GENERATE_DEPRECATEDLIST= YES # The ENABLED_SECTIONS tag can be used to enable conditional # documentation sections, marked by \if sectionname ... \endif. ENABLED_SECTIONS = # The MAX_INITIALIZER_LINES tag determines the maximum number of lines # the initial value of a variable or macro consists of for it to appear in # the documentation. If the initializer consists of more lines than specified # here it will be hidden. Use a value of 0 to hide initializers completely. # The appearance of the initializer of individual variables and macros in the # documentation can be controlled using \showinitializer or \hideinitializer # command in the documentation regardless of this setting. MAX_INITIALIZER_LINES = 30 # Set the SHOW_USED_FILES tag to NO to disable the list of files generated # at the bottom of the documentation of classes and structs. If set to YES the # list will mention the files that were used to generate the documentation. SHOW_USED_FILES = YES # Set the SHOW_FILES tag to NO to disable the generation of the Files page. # This will remove the Files entry from the Quick Index and from the # Folder Tree View (if specified). The default is YES. SHOW_FILES = YES # Set the SHOW_NAMESPACES tag to NO to disable the generation of the # Namespaces page. # This will remove the Namespaces entry from the Quick Index # and from the Folder Tree View (if specified). The default is YES. SHOW_NAMESPACES = YES # The FILE_VERSION_FILTER tag can be used to specify a program or script that # doxygen should invoke to get the current version for each file (typically from # the version control system). Doxygen will invoke the program by executing (via # popen()) the command , where is the value of # the FILE_VERSION_FILTER tag, and is the name of an input file # provided by doxygen. Whatever the program writes to standard output # is used as the file version. See the manual for examples. FILE_VERSION_FILTER = # The LAYOUT_FILE tag can be used to specify a layout file which will be parsed # by doxygen. The layout file controls the global structure of the generated # output files in an output format independent way. To create the layout file # that represents doxygen's defaults, run doxygen with the -l option. # You can optionally specify a file name after the option, if omitted # DoxygenLayout.xml will be used as the name of the layout file. LAYOUT_FILE = # The CITE_BIB_FILES tag can be used to specify one or more bib files # containing the references data. This must be a list of .bib files. The # .bib extension is automatically appended if omitted. Using this command # requires the bibtex tool to be installed. See also # http://en.wikipedia.org/wiki/BibTeX for more info. For LaTeX the style # of the bibliography can be controlled using LATEX_BIB_STYLE. To use this # feature you need bibtex and perl available in the search path. CITE_BIB_FILES = #--------------------------------------------------------------------------- # configuration options related to warning and progress messages #--------------------------------------------------------------------------- # The QUIET tag can be used to turn on/off the messages that are generated # by doxygen. Possible values are YES and NO. If left blank NO is used. QUIET = NO # The WARNINGS tag can be used to turn on/off the warning messages that are # generated by doxygen. Possible values are YES and NO. If left blank # NO is used. WARNINGS = YES # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings # for undocumented members. If EXTRACT_ALL is set to YES then this flag will # automatically be disabled. WARN_IF_UNDOCUMENTED = YES # If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for # potential errors in the documentation, such as not documenting some # parameters in a documented function, or documenting parameters that # don't exist or using markup commands wrongly. WARN_IF_DOC_ERROR = YES # The WARN_NO_PARAMDOC option can be enabled to get warnings for # functions that are documented, but have no documentation for their parameters # or return value. If set to NO (the default) doxygen will only warn about # wrong or incomplete parameter documentation, but not about the absence of # documentation. WARN_NO_PARAMDOC = NO # The WARN_FORMAT tag determines the format of the warning messages that # doxygen can produce. The string should contain the $file, $line, and $text # tags, which will be replaced by the file and line number from which the # warning originated and the warning text. Optionally the format may contain # $version, which will be replaced by the version of the file (if it could # be obtained via FILE_VERSION_FILTER) WARN_FORMAT = "$file:$line: $text" # The WARN_LOGFILE tag can be used to specify a file to which warning # and error messages should be written. If left blank the output is written # to stderr. WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- # The INPUT tag can be used to specify the files and/or directories that contain # documented source files. You may enter file names like "myfile.cpp" or # directories like "/usr/src/myproject". Separate the files or directories # with spaces. INPUT = ./src # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is # also the default input encoding. Doxygen uses libiconv (or the iconv built # into libc) for the transcoding. See http://www.gnu.org/software/libiconv for # the list of possible encodings. INPUT_ENCODING = UTF-8 # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp # and *.h) to filter out the source-files in the directories. If left # blank the following patterns are tested: # *.c *.cc *.cxx *.cpp *.c++ *.d *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh # *.hxx *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.dox *.py # *.f90 *.f *.for *.vhd *.vhdl FILE_PATTERNS = # The RECURSIVE tag can be used to turn specify whether or not subdirectories # should be searched for input files as well. Possible values are YES and NO. # If left blank NO is used. RECURSIVE = YES # The EXCLUDE tag can be used to specify files and/or directories that should be # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. # Note that relative paths are relative to the directory from which doxygen is # run. EXCLUDE = # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded # from the input. EXCLUDE_SYMLINKS = NO # If the value of the INPUT tag contains directories, you can use the # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude # certain files from those directories. Note that the wildcards are matched # against the file with absolute path, so to exclude all test directories # for example use the pattern */test/* EXCLUDE_PATTERNS = # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the # output. The symbol name can be a fully qualified name, a word, or if the # wildcard * is used, a substring. Examples: ANamespace, AClass, # AClass::ANamespace, ANamespace::*Test EXCLUDE_SYMBOLS = ZMQPP_COMPARABLE_ENUM \ ZMQPP_REQUIRED_ZMQ_MAJOR \ ZMQPP_REQUIRED_ZMQ_MINOR \ zmqpp::zmq_msg_wrapper \ zmqpp::callback_releaser \ zmq_msg_wrapper \ callback_releaser \ max_socket_option_buffer_size \ max_stream_buffer_size # The EXAMPLE_PATH tag can be used to specify one or more files or # directories that contain example code fragments that are included (see # the \include command). EXAMPLE_PATH = ../examples # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp # and *.h) to filter out the source-files in the directories. If left # blank all files are included. EXAMPLE_PATTERNS = *.cpp # If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be # searched for input files to be used with the \include or \dontinclude # commands irrespective of the value of the RECURSIVE tag. # Possible values are YES and NO. If left blank NO is used. EXAMPLE_RECURSIVE = NO # The IMAGE_PATH tag can be used to specify one or more files or # directories that contain image that are included in the documentation (see # the \image command). IMAGE_PATH = # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program # by executing (via popen()) the command , where # is the value of the INPUT_FILTER tag, and is the name of an # input file. Doxygen will then use the output that the filter program writes # to standard output. # If FILTER_PATTERNS is specified, this tag will be # ignored. INPUT_FILTER = # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern # basis. # Doxygen will compare the file name with each pattern and apply the # filter if there is a match. # The filters are a list of the form: # pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further # info on how filters are used. If FILTER_PATTERNS is empty or if # non of the patterns match the file name, INPUT_FILTER is applied. FILTER_PATTERNS = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using # INPUT_FILTER) will be used to filter the input files when producing source # files to browse (i.e. when SOURCE_BROWSER is set to YES). FILTER_SOURCE_FILES = NO # The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file # pattern. A pattern will override the setting for FILTER_PATTERN (if any) # and it is also possible to disable source filtering for a specific pattern # using *.ext= (so without naming a filter). This option only has effect when # FILTER_SOURCE_FILES is enabled. FILTER_SOURCE_PATTERNS = #--------------------------------------------------------------------------- # configuration options related to source browsing #--------------------------------------------------------------------------- # If the SOURCE_BROWSER tag is set to YES then a list of source files will # be generated. Documented entities will be cross-referenced with these sources. # Note: To get rid of all source code in the generated output, make sure also # VERBATIM_HEADERS is set to NO. SOURCE_BROWSER = NO # Setting the INLINE_SOURCES tag to YES will include the body # of functions and classes directly in the documentation. INLINE_SOURCES = NO # Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct # doxygen to hide any special comment blocks from generated source code # fragments. Normal C, C++ and Fortran comments will always remain visible. STRIP_CODE_COMMENTS = YES # If the REFERENCED_BY_RELATION tag is set to YES # then for each documented function all documented # functions referencing it will be listed. REFERENCED_BY_RELATION = NO # If the REFERENCES_RELATION tag is set to YES # then for each documented function all documented entities # called/used by that function will be listed. REFERENCES_RELATION = NO # If the REFERENCES_LINK_SOURCE tag is set to YES (the default) # and SOURCE_BROWSER tag is set to YES, then the hyperlinks from # functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will # link to the source code. # Otherwise they will link to the documentation. REFERENCES_LINK_SOURCE = YES # If the USE_HTAGS tag is set to YES then the references to source code # will point to the HTML generated by the htags(1) tool instead of doxygen # built-in source browser. The htags tool is part of GNU's global source # tagging system (see http://www.gnu.org/software/global/global.html). You # will need version 4.8.6 or higher. USE_HTAGS = NO # If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen # will generate a verbatim copy of the header file for each class for # which an include is specified. Set to NO to disable this. VERBATIM_HEADERS = YES #--------------------------------------------------------------------------- # configuration options related to the alphabetical class index #--------------------------------------------------------------------------- # If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index # of all compounds will be generated. Enable this if the project # contains a lot of classes, structs, unions or interfaces. ALPHABETICAL_INDEX = YES # If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then # the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns # in which this list will be split (can be a number in the range [1..20]) COLS_IN_ALPHA_INDEX = 5 # In case all classes in a project start with a common prefix, all # classes will be put under the same header in the alphabetical index. # The IGNORE_PREFIX tag can be used to specify one or more prefixes that # should be ignored while generating the index headers. IGNORE_PREFIX = #--------------------------------------------------------------------------- # configuration options related to the HTML output #--------------------------------------------------------------------------- # If the GENERATE_HTML tag is set to YES (the default) Doxygen will # generate HTML output. GENERATE_HTML = YES # The HTML_OUTPUT tag is used to specify where the HTML docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `html' will be used as the default path. HTML_OUTPUT = html # The HTML_FILE_EXTENSION tag can be used to specify the file extension for # each generated HTML page (for example: .htm,.php,.asp). If it is left blank # doxygen will generate files with .html extension. HTML_FILE_EXTENSION = .html # The HTML_HEADER tag can be used to specify a personal HTML header for # each generated HTML page. If it is left blank doxygen will generate a # standard header. Note that when using a custom header you are responsible # for the proper inclusion of any scripts and style sheets that doxygen # needs, which is dependent on the configuration options used. # It is advised to generate a default header using "doxygen -w html # header.html footer.html stylesheet.css YourConfigFile" and then modify # that header. Note that the header is subject to change so you typically # have to redo this when upgrading to a newer version of doxygen or when # changing the value of configuration settings such as GENERATE_TREEVIEW! HTML_HEADER = # The HTML_FOOTER tag can be used to specify a personal HTML footer for # each generated HTML page. If it is left blank doxygen will generate a # standard footer. HTML_FOOTER = # The HTML_STYLESHEET tag can be used to specify a user-defined cascading # style sheet that is used by each HTML page. It can be used to # fine-tune the look of the HTML output. If left blank doxygen will # generate a default style sheet. Note that it is recommended to use # HTML_EXTRA_STYLESHEET instead of this one, as it is more robust and this # tag will in the future become obsolete. HTML_STYLESHEET = # The HTML_EXTRA_STYLESHEET tag can be used to specify an additional # user-defined cascading style sheet that is included after the standard # style sheets created by doxygen. Using this option one can overrule # certain style aspects. This is preferred over using HTML_STYLESHEET # since it does not replace the standard style sheet and is therefor more # robust against future updates. Doxygen will copy the style sheet file to # the output directory. HTML_EXTRA_STYLESHEET = # The HTML_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the HTML output directory. Note # that these files will be copied to the base HTML output directory. Use the # $relpath$ marker in the HTML_HEADER and/or HTML_FOOTER files to load these # files. In the HTML_STYLESHEET file, use the file name only. Also note that # the files will be copied as-is; there are no commands or markers available. HTML_EXTRA_FILES = # The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. # Doxygen will adjust the colors in the style sheet and background images # according to this color. Hue is specified as an angle on a colorwheel, # see http://en.wikipedia.org/wiki/Hue for more information. # For instance the value 0 represents red, 60 is yellow, 120 is green, # 180 is cyan, 240 is blue, 300 purple, and 360 is red again. # The allowed range is 0 to 359. HTML_COLORSTYLE_HUE = 220 # The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of # the colors in the HTML output. For a value of 0 the output will use # grayscales only. A value of 255 will produce the most vivid colors. HTML_COLORSTYLE_SAT = 100 # The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to # the luminance component of the colors in the HTML output. Values below # 100 gradually make the output lighter, whereas values above 100 make # the output darker. The value divided by 100 is the actual gamma applied, # so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2, # and 100 does not change the gamma. HTML_COLORSTYLE_GAMMA = 80 # If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML # page will contain the date and time when the page was generated. Setting # this to NO can help when comparing the output of multiple runs. HTML_TIMESTAMP = YES # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML # documentation will contain sections that can be hidden and shown after the # page has loaded. HTML_DYNAMIC_SECTIONS = NO # With HTML_INDEX_NUM_ENTRIES one can control the preferred number of # entries shown in the various tree structured indices initially; the user # can expand and collapse entries dynamically later on. Doxygen will expand # the tree to such a level that at most the specified number of entries are # visible (unless a fully collapsed tree already exceeds this amount). # So setting the number of entries 1 will produce a full collapsed tree by # default. 0 is a special value representing an infinite number of entries # and will result in a full expanded tree by default. HTML_INDEX_NUM_ENTRIES = 100 # If the GENERATE_DOCSET tag is set to YES, additional index files # will be generated that can be used as input for Apple's Xcode 3 # integrated development environment, introduced with OSX 10.5 (Leopard). # To create a documentation set, doxygen will generate a Makefile in the # HTML output directory. Running make will produce the docset in that # directory and running "make install" will install the docset in # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find # it at startup. # See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html # for more information. GENERATE_DOCSET = NO # When GENERATE_DOCSET tag is set to YES, this tag determines the name of the # feed. A documentation feed provides an umbrella under which multiple # documentation sets from a single provider (such as a company or product suite) # can be grouped. DOCSET_FEEDNAME = "Doxygen generated docs" # When GENERATE_DOCSET tag is set to YES, this tag specifies a string that # should uniquely identify the documentation set bundle. This should be a # reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen # will append .docset to the name. DOCSET_BUNDLE_ID = org.doxygen.Project # When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely # identify the documentation publisher. This should be a reverse domain-name # style string, e.g. com.mycompany.MyDocSet.documentation. DOCSET_PUBLISHER_ID = org.doxygen.Publisher # The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher. DOCSET_PUBLISHER_NAME = Publisher # If the GENERATE_HTMLHELP tag is set to YES, additional index files # will be generated that can be used as input for tools like the # Microsoft HTML help workshop to generate a compiled HTML help file (.chm) # of the generated HTML documentation. GENERATE_HTMLHELP = NO # If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can # be used to specify the file name of the resulting .chm file. You # can add a path in front of the file if the result should not be # written to the html output directory. CHM_FILE = # If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can # be used to specify the location (absolute path including file name) of # the HTML help compiler (hhc.exe). If non-empty doxygen will try to run # the HTML help compiler on the generated index.hhp. HHC_LOCATION = # If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag # controls if a separate .chi index file is generated (YES) or that # it should be included in the master .chm file (NO). GENERATE_CHI = NO # If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING # is used to encode HtmlHelp index (hhk), content (hhc) and project file # content. CHM_INDEX_ENCODING = # If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag # controls whether a binary table of contents is generated (YES) or a # normal table of contents (NO) in the .chm file. BINARY_TOC = NO # The TOC_EXPAND flag can be set to YES to add extra items for group members # to the contents of the HTML help documentation and to the tree view. TOC_EXPAND = NO # If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and # QHP_VIRTUAL_FOLDER are set, an additional index file will be generated # that can be used as input for Qt's qhelpgenerator to generate a # Qt Compressed Help (.qch) of the generated HTML documentation. GENERATE_QHP = NO # If the QHG_LOCATION tag is specified, the QCH_FILE tag can # be used to specify the file name of the resulting .qch file. # The path specified is relative to the HTML output folder. QCH_FILE = # The QHP_NAMESPACE tag specifies the namespace to use when generating # Qt Help Project output. For more information please see # http://doc.trolltech.com/qthelpproject.html#namespace QHP_NAMESPACE = org.doxygen.Project # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating # Qt Help Project output. For more information please see # http://doc.trolltech.com/qthelpproject.html#virtual-folders QHP_VIRTUAL_FOLDER = doc # If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to # add. For more information please see # http://doc.trolltech.com/qthelpproject.html#custom-filters QHP_CUST_FILTER_NAME = # The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the # custom filter to add. For more information please see # # Qt Help Project / Custom Filters. QHP_CUST_FILTER_ATTRS = # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this # project's # filter section matches. # # Qt Help Project / Filter Attributes. QHP_SECT_FILTER_ATTRS = # If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can # be used to specify the location of Qt's qhelpgenerator. # If non-empty doxygen will try to run qhelpgenerator on the generated # .qhp file. QHG_LOCATION = # If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files # will be generated, which together with the HTML files, form an Eclipse help # plugin. To install this plugin and make it available under the help contents # menu in Eclipse, the contents of the directory containing the HTML and XML # files needs to be copied into the plugins directory of eclipse. The name of # the directory within the plugins directory should be the same as # the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before # the help appears. GENERATE_ECLIPSEHELP = NO # A unique identifier for the eclipse help plugin. When installing the plugin # the directory name containing the HTML and XML files should also have # this name. ECLIPSE_DOC_ID = org.doxygen.Project # The DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) # at top of each HTML page. The value NO (the default) enables the index and # the value YES disables it. Since the tabs have the same information as the # navigation tree you can set this option to NO if you already set # GENERATE_TREEVIEW to YES. DISABLE_INDEX = NO # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index # structure should be generated to display hierarchical information. # If the tag value is set to YES, a side panel will be generated # containing a tree-like index structure (just like the one that # is generated for HTML Help). For this to work a browser that supports # JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). # Windows users are probably better off using the HTML help feature. # Since the tree basically has the same information as the tab index you # could consider to set DISABLE_INDEX to NO when enabling this option. GENERATE_TREEVIEW = NO # The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values # (range [0,1..20]) that doxygen will group on one line in the generated HTML # documentation. Note that a value of 0 will completely suppress the enum # values from appearing in the overview section. ENUM_VALUES_PER_LINE = 4 # If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be # used to set the initial width (in pixels) of the frame in which the tree # is shown. TREEVIEW_WIDTH = 250 # When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open # links to external symbols imported via tag files in a separate window. EXT_LINKS_IN_WINDOW = NO # Use this tag to change the font size of Latex formulas included # as images in the HTML documentation. The default is 10. Note that # when you change the font size after a successful doxygen run you need # to manually remove any form_*.png images from the HTML output directory # to force them to be regenerated. FORMULA_FONTSIZE = 10 # Use the FORMULA_TRANPARENT tag to determine whether or not the images # generated for formulas are transparent PNGs. Transparent PNGs are # not supported properly for IE 6.0, but are supported on all modern browsers. # Note that when changing this option you need to delete any form_*.png files # in the HTML output before the changes have effect. FORMULA_TRANSPARENT = YES # Enable the USE_MATHJAX option to render LaTeX formulas using MathJax # (see http://www.mathjax.org) which uses client side Javascript for the # rendering instead of using prerendered bitmaps. Use this if you do not # have LaTeX installed or if you want to formulas look prettier in the HTML # output. When enabled you may also need to install MathJax separately and # configure the path to it using the MATHJAX_RELPATH option. USE_MATHJAX = NO # When MathJax is enabled you need to specify the location relative to the # HTML output directory using the MATHJAX_RELPATH option. The destination # directory should contain the MathJax.js script. For instance, if the mathjax # directory is located at the same level as the HTML output directory, then # MATHJAX_RELPATH should be ../mathjax. The default value points to # the MathJax Content Delivery Network so you can quickly see the result without # installing MathJax. # However, it is strongly recommended to install a local # copy of MathJax from http://www.mathjax.org before deployment. MATHJAX_RELPATH = http://www.mathjax.org/mathjax # The MATHJAX_EXTENSIONS tag can be used to specify one or MathJax extension # names that should be enabled during MathJax rendering. MATHJAX_EXTENSIONS = # When the SEARCHENGINE tag is enabled doxygen will generate a search box # for the HTML output. The underlying search engine uses javascript # and DHTML and should work on any modern browser. Note that when using # HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets # (GENERATE_DOCSET) there is already a search function so this one should # typically be disabled. For large projects the javascript based search engine # can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. SEARCHENGINE = YES # When the SERVER_BASED_SEARCH tag is enabled the search engine will be # implemented using a PHP enabled web server instead of at the web client # using Javascript. Doxygen will generate the search PHP script and index # file to put on the web server. The advantage of the server # based approach is that it scales better to large projects and allows # full text search. The disadvantages are that it is more difficult to setup # and does not have live searching capabilities. SERVER_BASED_SEARCH = NO #--------------------------------------------------------------------------- # configuration options related to the LaTeX output #--------------------------------------------------------------------------- # If the GENERATE_LATEX tag is set to YES (the default) Doxygen will # generate Latex output. GENERATE_LATEX = YES # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `latex' will be used as the default path. LATEX_OUTPUT = latex # The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be # invoked. If left blank `latex' will be used as the default command name. # Note that when enabling USE_PDFLATEX this option is only used for # generating bitmaps for formulas in the HTML output, but not in the # Makefile that is written to the output directory. LATEX_CMD_NAME = latex # The MAKEINDEX_CMD_NAME tag can be used to specify the command name to # generate index for LaTeX. If left blank `makeindex' will be used as the # default command name. MAKEINDEX_CMD_NAME = makeindex # If the COMPACT_LATEX tag is set to YES Doxygen generates more compact # LaTeX documents. This may be useful for small projects and may help to # save some trees in general. COMPACT_LATEX = NO # The PAPER_TYPE tag can be used to set the paper type that is used # by the printer. Possible values are: a4, letter, legal and # executive. If left blank a4wide will be used. PAPER_TYPE = a4 # The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX # packages that should be included in the LaTeX output. EXTRA_PACKAGES = # The LATEX_HEADER tag can be used to specify a personal LaTeX header for # the generated latex document. The header should contain everything until # the first chapter. If it is left blank doxygen will generate a # standard header. Notice: only use this tag if you know what you are doing! LATEX_HEADER = # The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for # the generated latex document. The footer should contain everything after # the last chapter. If it is left blank doxygen will generate a # standard footer. Notice: only use this tag if you know what you are doing! LATEX_FOOTER = # If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated # is prepared for conversion to pdf (using ps2pdf). The pdf file will # contain links (just like the HTML output) instead of page references # This makes the output suitable for online browsing using a pdf viewer. PDF_HYPERLINKS = YES # If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of # plain latex in the generated Makefile. Set this option to YES to get a # higher quality PDF documentation. USE_PDFLATEX = YES # If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. # command to the generated LaTeX files. This will instruct LaTeX to keep # running if errors occur, instead of asking the user for help. # This option is also used when generating formulas in HTML. LATEX_BATCHMODE = NO # If LATEX_HIDE_INDICES is set to YES then doxygen will not # include the index chapters (such as File Index, Compound Index, etc.) # in the output. LATEX_HIDE_INDICES = NO # If LATEX_SOURCE_CODE is set to YES then doxygen will include # source code with syntax highlighting in the LaTeX output. # Note that which sources are shown also depends on other settings # such as SOURCE_BROWSER. LATEX_SOURCE_CODE = NO # The LATEX_BIB_STYLE tag can be used to specify the style to use for the # bibliography, e.g. plainnat, or ieeetr. The default style is "plain". See # http://en.wikipedia.org/wiki/BibTeX for more info. LATEX_BIB_STYLE = plain #--------------------------------------------------------------------------- # configuration options related to the RTF output #--------------------------------------------------------------------------- # If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output # The RTF output is optimized for Word 97 and may not look very pretty with # other RTF readers or editors. GENERATE_RTF = NO # The RTF_OUTPUT tag is used to specify where the RTF docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `rtf' will be used as the default path. RTF_OUTPUT = rtf # If the COMPACT_RTF tag is set to YES Doxygen generates more compact # RTF documents. This may be useful for small projects and may help to # save some trees in general. COMPACT_RTF = NO # If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated # will contain hyperlink fields. The RTF file will # contain links (just like the HTML output) instead of page references. # This makes the output suitable for online browsing using WORD or other # programs which support those fields. # Note: wordpad (write) and others do not support links. RTF_HYPERLINKS = NO # Load style sheet definitions from file. Syntax is similar to doxygen's # config file, i.e. a series of assignments. You only have to provide # replacements, missing definitions are set to their default value. RTF_STYLESHEET_FILE = # Set optional variables used in the generation of an rtf document. # Syntax is similar to doxygen's config file. RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # configuration options related to the man page output #--------------------------------------------------------------------------- # If the GENERATE_MAN tag is set to YES (the default) Doxygen will # generate man pages GENERATE_MAN = NO # The MAN_OUTPUT tag is used to specify where the man pages will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `man' will be used as the default path. MAN_OUTPUT = man # The MAN_EXTENSION tag determines the extension that is added to # the generated man pages (default is the subroutine's section .3) MAN_EXTENSION = .3 # If the MAN_LINKS tag is set to YES and Doxygen generates man output, # then it will generate one additional man file for each entity # documented in the real man page(s). These additional files # only source the real man page, but without them the man command # would be unable to find the correct page. The default is NO. MAN_LINKS = NO #--------------------------------------------------------------------------- # configuration options related to the XML output #--------------------------------------------------------------------------- # If the GENERATE_XML tag is set to YES Doxygen will # generate an XML file that captures the structure of # the code including all documentation. GENERATE_XML = NO # The XML_OUTPUT tag is used to specify where the XML pages will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `xml' will be used as the default path. XML_OUTPUT = xml # The XML_SCHEMA tag can be used to specify an XML schema, # which can be used by a validating XML parser to check the # syntax of the XML files. XML_SCHEMA = # The XML_DTD tag can be used to specify an XML DTD, # which can be used by a validating XML parser to check the # syntax of the XML files. XML_DTD = # If the XML_PROGRAMLISTING tag is set to YES Doxygen will # dump the program listings (including syntax highlighting # and cross-referencing information) to the XML output. Note that # enabling this will significantly increase the size of the XML output. XML_PROGRAMLISTING = YES #--------------------------------------------------------------------------- # configuration options for the AutoGen Definitions output #--------------------------------------------------------------------------- # If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will # generate an AutoGen Definitions (see autogen.sf.net) file # that captures the structure of the code including all # documentation. Note that this feature is still experimental # and incomplete at the moment. GENERATE_AUTOGEN_DEF = NO #--------------------------------------------------------------------------- # configuration options related to the Perl module output #--------------------------------------------------------------------------- # If the GENERATE_PERLMOD tag is set to YES Doxygen will # generate a Perl module file that captures the structure of # the code including all documentation. Note that this # feature is still experimental and incomplete at the # moment. GENERATE_PERLMOD = NO # If the PERLMOD_LATEX tag is set to YES Doxygen will generate # the necessary Makefile rules, Perl scripts and LaTeX code to be able # to generate PDF and DVI output from the Perl module output. PERLMOD_LATEX = NO # If the PERLMOD_PRETTY tag is set to YES the Perl module output will be # nicely formatted so it can be parsed by a human reader. # This is useful # if you want to understand what is going on. # On the other hand, if this # tag is set to NO the size of the Perl module output will be much smaller # and Perl will parse it just the same. PERLMOD_PRETTY = YES # The names of the make variables in the generated doxyrules.make file # are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. # This is useful so different doxyrules.make files included by the same # Makefile don't overwrite each other's variables. PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the preprocessor #--------------------------------------------------------------------------- # If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will # evaluate all C-preprocessor directives found in the sources and include # files. ENABLE_PREPROCESSING = YES # If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro # names in the source code. If set to NO (the default) only conditional # compilation will be performed. Macro expansion can be done in a controlled # way by setting EXPAND_ONLY_PREDEF to YES. MACRO_EXPANSION = YES # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES # then the macro expansion is limited to the macros specified with the # PREDEFINED and EXPAND_AS_DEFINED tags. EXPAND_ONLY_PREDEF = YES # If the SEARCH_INCLUDES tag is set to YES (the default) the includes files # pointed to by INCLUDE_PATH will be searched when a #include is found. SEARCH_INCLUDES = YES # The INCLUDE_PATH tag can be used to specify one or more directories that # contain include files that are not input files but should be processed by # the preprocessor. INCLUDE_PATH = # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard # patterns (like *.h and *.hpp) to filter out the header-files in the # directories. If left blank, the patterns specified with FILE_PATTERNS will # be used. INCLUDE_FILE_PATTERNS = # The PREDEFINED tag can be used to specify one or more macro names that # are defined before the preprocessor is started (similar to the -D option of # gcc). The argument of the tag is a list of macros of the form: name # or name=definition (no spaces). If the definition and the = are # omitted =1 is assumed. To prevent a macro definition from being # undefined via #undef or recursively expanded use the := operator # instead of the = operator. PREDEFINED = ZMQ_VERSION_MAJOR=1000 # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. # The macro definition that is found in the sources will be used. # Use the PREDEFINED tag if you want to use a different macro definition that # overrules the definition found in the source code. EXPAND_AS_DEFINED = ZMQPP_COMPARABLE_ENUM # If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then # doxygen's preprocessor will remove all references to function-like macros # that are alone on a line, have an all uppercase name, and do not end with a # semicolon, because these will confuse the parser if not removed. SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- # Configuration::additions related to external references #--------------------------------------------------------------------------- # The TAGFILES option can be used to specify one or more tagfiles. For each # tag file the location of the external documentation should be added. The # format of a tag file without this location is as follows: # # TAGFILES = file1 file2 ... # Adding location for the tag files is done as follows: # # TAGFILES = file1=loc1 "file2 = loc2" ... # where "loc1" and "loc2" can be relative or absolute paths # or URLs. Note that each tag file must have a unique name (where the name does # NOT include the path). If a tag file is not located in the directory in which # doxygen is run, you must also specify the path to the tagfile here. TAGFILES = # When a file name is specified after GENERATE_TAGFILE, doxygen will create # a tag file that is based on the input files it reads. GENERATE_TAGFILE = # If the ALLEXTERNALS tag is set to YES all external classes will be listed # in the class index. If set to NO only the inherited external classes # will be listed. ALLEXTERNALS = NO # If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed # in the modules index. If set to NO, only the current project's groups will # be listed. EXTERNAL_GROUPS = YES # The PERL_PATH should be the absolute path and name of the perl script # interpreter (i.e. the result of `which perl'). PERL_PATH = /usr/bin/perl #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- # If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will # generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base # or super classes. Setting the tag to NO turns the diagrams off. Note that # this option also works with HAVE_DOT disabled, but it is recommended to # install and use dot, since it yields more powerful graphs. CLASS_DIAGRAMS = YES # You can define message sequence charts within doxygen comments using the \msc # command. Doxygen will then run the mscgen tool (see # http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the # documentation. The MSCGEN_PATH tag allows you to specify the directory where # the mscgen tool resides. If left empty the tool is assumed to be found in the # default search path. MSCGEN_PATH = # If set to YES, the inheritance and collaboration graphs will hide # inheritance and usage relations if the target is undocumented # or is not a class. HIDE_UNDOC_RELATIONS = YES # If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is # available from the path. This tool is part of Graphviz, a graph visualization # toolkit from AT&T and Lucent Bell Labs. The other options in this section # have no effect if this option is set to NO (the default) HAVE_DOT = YES # The DOT_NUM_THREADS specifies the number of dot invocations doxygen is # allowed to run in parallel. When set to 0 (the default) doxygen will # base this on the number of processors available in the system. You can set it # explicitly to a value larger than 0 to get control over the balance # between CPU load and processing speed. DOT_NUM_THREADS = 0 # By default doxygen will use the Helvetica font for all dot files that # doxygen generates. When you want a differently looking font you can specify # the font name using DOT_FONTNAME. You need to make sure dot is able to find # the font, which can be done by putting it in a standard location or by setting # the DOTFONTPATH environment variable or by setting DOT_FONTPATH to the # directory containing the font. DOT_FONTNAME = Helvetica # The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. # The default size is 10pt. DOT_FONTSIZE = 10 # By default doxygen will tell dot to use the Helvetica font. # If you specify a different font using DOT_FONTNAME you can use DOT_FONTPATH to # set the path where dot can find it. DOT_FONTPATH = # If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen # will generate a graph for each documented class showing the direct and # indirect inheritance relations. Setting this tag to YES will force the # CLASS_DIAGRAMS tag to NO. CLASS_GRAPH = YES # If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen # will generate a graph for each documented class showing the direct and # indirect implementation dependencies (inheritance, containment, and # class references variables) of the class with other documented classes. COLLABORATION_GRAPH = YES # If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen # will generate a graph for groups, showing the direct groups dependencies GROUP_GRAPHS = YES # If the UML_LOOK tag is set to YES doxygen will generate inheritance and # collaboration diagrams in a style similar to the OMG's Unified Modeling # Language. UML_LOOK = NO # If the UML_LOOK tag is enabled, the fields and methods are shown inside # the class node. If there are many fields or methods and many nodes the # graph may become too big to be useful. The UML_LIMIT_NUM_FIELDS # threshold limits the number of items for each type to make the size more # managable. Set this to 0 for no limit. Note that the threshold may be # exceeded by 50% before the limit is enforced. UML_LIMIT_NUM_FIELDS = 10 # If set to YES, the inheritance and collaboration graphs will show the # relations between templates and their instances. TEMPLATE_RELATIONS = NO # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT # tags are set to YES then doxygen will generate a graph for each documented # file showing the direct and indirect include dependencies of the file with # other documented files. INCLUDE_GRAPH = YES # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and # HAVE_DOT tags are set to YES then doxygen will generate a graph for each # documented header file showing the documented files that directly or # indirectly include this file. INCLUDED_BY_GRAPH = YES # If the CALL_GRAPH and HAVE_DOT options are set to YES then # doxygen will generate a call dependency graph for every global function # or class method. Note that enabling this option will significantly increase # the time of a run. So in most cases it will be better to enable call graphs # for selected functions only using the \callgraph command. CALL_GRAPH = NO # If the CALLER_GRAPH and HAVE_DOT tags are set to YES then # doxygen will generate a caller dependency graph for every global function # or class method. Note that enabling this option will significantly increase # the time of a run. So in most cases it will be better to enable caller # graphs for selected functions only using the \callergraph command. CALLER_GRAPH = NO # If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen # will generate a graphical hierarchy of all classes instead of a textual one. GRAPHICAL_HIERARCHY = YES # If the DIRECTORY_GRAPH and HAVE_DOT tags are set to YES # then doxygen will show the dependencies a directory has on other directories # in a graphical way. The dependency relations are determined by the #include # relations between the files in the directories. DIRECTORY_GRAPH = YES # The DOT_IMAGE_FORMAT tag can be used to set the image format of the images # generated by dot. Possible values are svg, png, jpg, or gif. # If left blank png will be used. If you choose svg you need to set # HTML_FILE_EXTENSION to xhtml in order to make the SVG files # visible in IE 9+ (other browsers do not have this requirement). DOT_IMAGE_FORMAT = png # If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to # enable generation of interactive SVG images that allow zooming and panning. # Note that this requires a modern browser other than Internet Explorer. # Tested and working are Firefox, Chrome, Safari, and Opera. For IE 9+ you # need to set HTML_FILE_EXTENSION to xhtml in order to make the SVG files # visible. Older versions of IE do not have SVG support. INTERACTIVE_SVG = NO # The tag DOT_PATH can be used to specify the path where the dot tool can be # found. If left blank, it is assumed the dot tool can be found in the path. DOT_PATH = # The DOTFILE_DIRS tag can be used to specify one or more directories that # contain dot files that are included in the documentation (see the # \dotfile command). DOTFILE_DIRS = # The MSCFILE_DIRS tag can be used to specify one or more directories that # contain msc files that are included in the documentation (see the # \mscfile command). MSCFILE_DIRS = # The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of # nodes that will be shown in the graph. If the number of nodes in a graph # becomes larger than this value, doxygen will truncate the graph, which is # visualized by representing a node as a red box. Note that doxygen if the # number of direct children of the root node in a graph is already larger than # DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note # that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. DOT_GRAPH_MAX_NODES = 50 # The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the # graphs generated by dot. A depth value of 3 means that only nodes reachable # from the root by following a path via at most 3 edges will be shown. Nodes # that lay further from the root node will be omitted. Note that setting this # option to 1 or 2 may greatly reduce the computation time needed for large # code bases. Also note that the size of a graph can be further restricted by # DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. MAX_DOT_GRAPH_DEPTH = 0 # Set the DOT_TRANSPARENT tag to YES to generate images with a transparent # background. This is disabled by default, because dot on Windows does not # seem to support this out of the box. Warning: Depending on the platform used, # enabling this option may lead to badly anti-aliased labels on the edges of # a graph (i.e. they become hard to read). DOT_TRANSPARENT = NO # Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output # files in one run (i.e. multiple -o and -T options on the command line). This # makes dot run faster, but since only newer versions of dot (>1.8.10) # support this, this feature is disabled by default. DOT_MULTI_TARGETS = YES # If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will # generate a legend page explaining the meaning of the various boxes and # arrows in the dot generated graphs. GENERATE_LEGEND = YES # If the DOT_CLEANUP tag is set to YES (the default) Doxygen will # remove the intermediate dot files that are used to generate # the various graphs. DOT_CLEANUP = YES zmqpp-4.1.2/LICENSE000066400000000000000000000405261254036632700137110ustar00rootroot00000000000000Mozilla Public License Version 2.0 ================================== 1. Definitions -------------- 1.1. "Contributor" means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software. 1.2. "Contributor Version" means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributor's Contribution. 1.3. "Contribution" means Covered Software of a particular Contributor. 1.4. "Covered Software" means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof. 1.5. "Incompatible With Secondary Licenses" means (a) that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or (b) that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License. 1.6. "Executable Form" means any form of the work other than Source Code Form. 1.7. "Larger Work" means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software. 1.8. "License" means this document. 1.9. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently, any and all of the rights conveyed by this License. 1.10. "Modifications" means any of the following: (a) any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or (b) any new file in Source Code Form that contains any Covered Software. 1.11. "Patent Claims" of a Contributor means any patent claim(s), including without limitation, method, process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of the License, by the making, using, selling, offering for sale, having made, import, or transfer of either its Contributions or its Contributor Version. 1.12. "Secondary License" means either the GNU General Public License, Version 2.0, the GNU Lesser General Public License, Version 2.1, the GNU Affero General Public License, Version 3.0, or any later versions of those licenses. 1.13. "Source Code Form" means the form of the work preferred for making modifications. 1.14. "You" (or "Your") means an individual or a legal entity exercising rights under this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. 2. License Grants and Conditions -------------------------------- 2.1. Grants Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license: (a) under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and (b) under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version. 2.2. Effective Date The licenses granted in Section 2.1 with respect to any Contribution become effective for each Contribution on the date the Contributor first distributes such Contribution. 2.3. Limitations on Grant Scope The licenses granted in this Section 2 are the only rights granted under this License. No additional rights or licenses will be implied from the distribution or licensing of Covered Software under this License. Notwithstanding Section 2.1(b) above, no patent license is granted by a Contributor: (a) for any code that a Contributor has removed from Covered Software; or (b) for infringements caused by: (i) Your and any other third party's modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or (c) under Patent Claims infringed by Covered Software in the absence of its Contributions. This License does not grant any rights in the trademarks, service marks, or logos of any Contributor (except as may be necessary to comply with the notice requirements in Section 3.4). 2.4. Subsequent Licenses No Contributor makes additional grants as a result of Your choice to distribute the Covered Software under a subsequent version of this License (see Section 10.2) or under the terms of a Secondary License (if permitted under the terms of Section 3.3). 2.5. Representation Each Contributor represents that the Contributor believes its Contributions are its original creation(s) or it has sufficient rights to grant the rights to its Contributions conveyed by this License. 2.6. Fair Use This License is not intended to limit any rights You have under applicable copyright doctrines of fair use, fair dealing, or other equivalents. 2.7. Conditions Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1. 3. Responsibilities ------------------- 3.1. Distribution of Source Form All distribution of Covered Software in Source Code Form, including any Modifications that You create or to which You contribute, must be under the terms of this License. You must inform recipients that the Source Code Form of the Covered Software is governed by the terms of this License, and how they can obtain a copy of this License. You may not attempt to alter or restrict the recipients' rights in the Source Code Form. 3.2. Distribution of Executable Form If You distribute Covered Software in Executable Form then: (a) such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and (b) You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients' rights in the Source Code Form under this License. 3.3. Distribution of a Larger Work You may create and distribute a Larger Work under terms of Your choice, provided that You also comply with the requirements of this License for the Covered Software. If the Larger Work is a combination of Covered Software with a work governed by one or more Secondary Licenses, and the Covered Software is not Incompatible With Secondary Licenses, this License permits You to additionally distribute such Covered Software under the terms of such Secondary License(s), so that the recipient of the Larger Work may, at their option, further distribute the Covered Software under the terms of either this License or such Secondary License(s). 3.4. Notices You may not remove or alter the substance of any license notices (including copyright notices, patent notices, disclaimers of warranty, or limitations of liability) contained within the Source Code Form of the Covered Software, except that You may alter any license notices to the extent required to remedy known factual inaccuracies. 3.5. Application of Additional Terms You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, You may do so only on Your own behalf, and not on behalf of any Contributor. You must make it absolutely clear that any such warranty, support, indemnity, or liability obligation is offered by You alone, and You hereby agree to indemnify every Contributor for any liability incurred by such Contributor as a result of warranty, support, indemnity or liability terms You offer. You may include additional disclaimers of warranty and limitations of liability specific to any jurisdiction. 4. Inability to Comply Due to Statute or Regulation --------------------------------------------------- If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Software due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be placed in a text file included with all distributions of the Covered Software under this License. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it. 5. Termination -------------- 5.1. The rights granted under this License will terminate automatically if You fail to comply with any of its terms. However, if You become compliant, then the rights granted under this License from a particular Contributor are reinstated (a) provisionally, unless and until such Contributor explicitly and finally terminates Your grants, and (b) on an ongoing basis, if such Contributor fails to notify You of the non-compliance by some reasonable means prior to 60 days after You have come back into compliance. Moreover, Your grants from a particular Contributor are reinstated on an ongoing basis if such Contributor notifies You of the non-compliance by some reasonable means, this is the first time You have received notice of non-compliance with this License from such Contributor, and You become compliant prior to 30 days after Your receipt of the notice. 5.2. If You initiate litigation against any entity by asserting a patent infringement claim (excluding declaratory judgment actions, counter-claims, and cross-claims) alleging that a Contributor Version directly or indirectly infringes any patent, then the rights granted to You by any and all Contributors for the Covered Software under Section 2.1 of this License shall terminate. 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or Your distributors under this License prior to termination shall survive termination. ************************************************************************ * * * 6. Disclaimer of Warranty * * ------------------------- * * * * Covered Software is provided under this License on an "as is" * * basis, without warranty of any kind, either expressed, implied, or * * statutory, including, without limitation, warranties that the * * Covered Software is free of defects, merchantable, fit for a * * particular purpose or non-infringing. The entire risk as to the * * quality and performance of the Covered Software is with You. * * Should any Covered Software prove defective in any respect, You * * (not any Contributor) assume the cost of any necessary servicing, * * repair, or correction. This disclaimer of warranty constitutes an * * essential part of this License. No use of any Covered Software is * * authorized under this License except under this disclaimer. * * * ************************************************************************ ************************************************************************ * * * 7. Limitation of Liability * * -------------------------- * * * * Under no circumstances and under no legal theory, whether tort * * (including negligence), contract, or otherwise, shall any * * Contributor, or anyone who distributes Covered Software as * * permitted above, be liable to You for any direct, indirect, * * special, incidental, or consequential damages of any character * * including, without limitation, damages for lost profits, loss of * * goodwill, work stoppage, computer failure or malfunction, or any * * and all other commercial damages or losses, even if such party * * shall have been informed of the possibility of such damages. This * * limitation of liability shall not apply to liability for death or * * personal injury resulting from such party's negligence to the * * extent applicable law prohibits such limitation. Some * * jurisdictions do not allow the exclusion or limitation of * * incidental or consequential damages, so this exclusion and * * limitation may not apply to You. * * * ************************************************************************ 8. Litigation ------------- Any litigation relating to this License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business and such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. Nothing in this Section shall prevent a party's ability to bring cross-claims or counter-claims. 9. Miscellaneous ---------------- This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not be used to construe this License against a Contributor. 10. Versions of the License --------------------------- 10.1. New Versions Mozilla Foundation is the license steward. Except as provided in Section 10.3, no one other than the license steward has the right to modify or publish new versions of this License. Each version will be given a distinguishing version number. 10.2. Effect of New Versions You may distribute the Covered Software under the terms of the version of the License under which You originally received the Covered Software, or under the terms of any subsequent version published by the license steward. 10.3. Modified Versions If you create software not governed by this License, and you want to create a new license for such software, you may create and use a modified version of this License if you rename the license and remove any references to the name of the license steward (except to note that such modified license differs from this License). 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses If You choose to distribute Source Code Form that is Incompatible With Secondary Licenses under the terms of this version of the License, the notice described in Exhibit B of this License must be attached. Exhibit A - Source Code Form License Notice ------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice. You may add additional accurate notices of copyright ownership. Exhibit B - "Incompatible With Secondary Licenses" Notice --------------------------------------------------------- This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. zmqpp-4.1.2/Makefile000066400000000000000000000133361254036632700143430ustar00rootroot00000000000000# # Instance values, command line user specifiable # CONFIG = max CPPFLAGS = CXXFLAGS = LDFLAGS = PREFIX = /usr/local BINDIR = $(DESTDIR)$(PREFIX)/bin LIBDIR = $(DESTDIR)$(PREFIX)/lib INCLUDEDIR = $(DESTDIR)$(PREFIX)/include # # Tools # #CXX = g++ LD = $(CXX) AR = ar # # Build values # LIBRARY_NAME = zmqpp VERSION_MAJOR = 4 VERSION_MINOR = 1 VERSION_REVISION = 2 # # Paths # LIBRARY_DIR = $(LIBRARY_NAME) CLIENT_DIR = client TESTS_DIR = tests SRC_PATH = ./src LIBRARY_PATH = $(SRC_PATH)/$(LIBRARY_DIR) CLIENT_PATH = $(SRC_PATH)/$(CLIENT_DIR) TESTS_PATH = $(SRC_PATH)/$(TESTS_DIR) BUILD_PATH = ./build/$(CONFIG)-$(CXX) OBJECT_PATH = $(BUILD_PATH)/obj CUSTOM_INCLUDE_PATH = # # Core values # APP_VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_REVISION) APP_DATESTAMP = $(shell date '+"%Y-%m-%d %H:%M"') LIBRARY_SHARED = lib$(LIBRARY_NAME).so LIBRARY_VERSION_SHARED = $(LIBRARY_SHARED).$(VERSION_MAJOR) LIBRARY_FULL_VERSION_SHARED = $(LIBRARY_SHARED).$(APP_VERSION) LIBRARY_ARCHIVE = lib$(LIBRARY_NAME).a CLIENT_TARGET = $(LIBRARY_NAME) TESTS_TARGET = $(LIBRARY_NAME)-tests # OS Specific values UNAME_S := $(shell uname -s) LD_EXTRA = AR_EXTRA = ifeq ($(UNAME_S),Linux) LD_EXTRA += -Wl,-soname -Wl,$(LIBRARY_VERSION_SHARED) AR_EXTRA = crf endif ifeq ($(UNAME_S),Darwin) LIBRARY_SHARED = lib$(LIBRARY_NAME).dylib LIBRARY_VERSION_SHARED = lib$(LIBRARY_NAME).$(VERSION_MAJOR).dylib LIBRARY_FULL_VERSION_SHARED = lib$(LIBRARY_NAME).$(APP_VERSION).dylib AR_EXTRA = cr endif CONFIG_FLAGS = ifeq ($(CONFIG),debug) CONFIG_FLAGS = -g -fno-inline -ftemplate-depth-1000 endif ifeq ($(CONFIG),valgrind) CONFIG_FLAGS = -g -O1 -DNO_DEBUG_LOG -DNO_TRACE_LOG endif ifeq ($(CONFIG),max) CONFIG_FLAGS = -O3 -funroll-loops -ffast-math -finline-functions -fomit-frame-pointer -DNDEBUG endif ifneq (,$(findstring $(CONFIG),release loadtest)) CONFIG_FLAGS = -O3 -funroll-loops -ffast-math -finline-functions -fomit-frame-pointer -DNO_DEBUG_LOG -DNO_TRACE_LOG -DNDEBUG endif COMMON_FLAGS = -MMD -std=c++11 -pipe -Wall -fPIC \ -DBUILD_ENV=$(CONFIG) \ -DBUILD_DATESTAMP='$(APP_DATESTAMP)' \ -DBUILD_LIBRARY_NAME='"$(LIBRARY_NAME)"' \ -DBUILD_CLIENT_NAME='"$(CLIENT_TARGET)"' \ -I$(SRC_PATH) $(CUSTOM_INCLUDE_PATH) COMMON_LIBS = -lzmq LIBRARY_LIBS = CLIENT_LIBS = -L$(BUILD_PATH) \ -l$(LIBRARY_NAME) \ -lboost_program_options TEST_LIBS = -L$(BUILD_PATH) \ -l$(LIBRARY_NAME) \ -lsodium \ -lboost_unit_test_framework \ -lpthread ifeq ($(CONFIG),loadtest) CONFIG_FLAGS := $(CONFIG_FLAGS) -DLOADTEST TEST_LIBS := $(TEST_LIBS) -lboost_thread -lboost_system endif ALL_LIBRARY_OBJECTS := $(patsubst $(SRC_PATH)/%.cpp, $(OBJECT_PATH)/%.o, $(shell find $(LIBRARY_PATH) -iname '*.cpp')) ALL_LIBRARY_INCLUDES := $(shell find $(LIBRARY_PATH) -iname '*.hpp') ALL_CLIENT_OBJECTS := $(patsubst $(SRC_PATH)/%.cpp, $(OBJECT_PATH)/%.o, $(shell find $(CLIENT_PATH) -iname '*.cpp')) ALL_TEST_OBJECTS := $(patsubst $(SRC_PATH)/%.cpp, $(OBJECT_PATH)/%.o, $(shell find $(TESTS_PATH) -iname '*.cpp')) TEST_SUITES := ${addprefix test-,${sort ${shell find ${TESTS_PATH} -iname *.cpp | xargs grep BOOST_AUTO_TEST_SUITE\( | sed 's/.*BOOST_AUTO_TEST_SUITE( \(.*\) )/\1/' }}} # # BUILD Targets - Standardised # .PHONY: clean uninstall test $(TEST_SUITES) main: $(LIBRARY_SHARED) $(LIBRARY_ARCHIVE) @echo "use make check to test the build" all: $(LIBRARY_SHARED) $(LIBRARY_ARCHIVE) $(CLIENT_TARGET) @echo "use make check to test the build" check: $(LIBRARY_SHARED) $(LIBRARY_ARCHIVE) test install: mkdir -p $(INCLUDEDIR)/$(LIBRARY_DIR) mkdir -p $(LIBDIR) install -m 644 $(ALL_LIBRARY_INCLUDES) $(INCLUDEDIR)/$(LIBRARY_DIR) install -m 755 $(BUILD_PATH)/$(LIBRARY_VERSION_SHARED) $(LIBDIR)/$(LIBRARY_FULL_VERSION_SHARED) install -m 755 $(BUILD_PATH)/$(LIBRARY_ARCHIVE) $(LIBDIR)/$(LIBRARY_ARCHIVE) ln -sf $(LIBRARY_FULL_VERSION_SHARED) $(LIBDIR)/$(LIBRARY_VERSION_SHARED) ln -sf $(LIBRARY_FULL_VERSION_SHARED) $(LIBDIR)/$(LIBRARY_SHARED) if [ -f $(BUILD_PATH)/$(CLIENT_TARGET) ]; then install -m 755 $(BUILD_PATH)/$(CLIENT_TARGET) $(BINDIR); fi $(LDCONFIG) @echo "use make installcheck to test the install" installcheck: $(TESTS_TARGET) $(BUILD_PATH)/$(TESTS_TARGET) uninstall: rm -rf $(INCLUDEDIR)/$(LIBRARY_DIR) rm -f $(LIBDIR)/$(LIBRARY_FULL_VERSION_SHARED) rm -f $(LIBDIR)/$(LIBRARY_VERSION_SHARED) rm -f $(LIBDIR)/$(LIBRARY_SHARED) rm -f $(LIBDIR)/$(LIBRARY_ARCHIVE) rm -f $(BINDIR)/$(CLIENT_TARGET) clean: rm -rf build/* rm -rf docs client: $(CLIENT_TARGET) library: $(LIBRARY_SHARED) $(LIBRARY_ARCHIVE) # # BUILD Targets # $(LIBRARY_SHARED): $(ALL_LIBRARY_OBJECTS) $(LD) $(LDFLAGS) -shared -rdynamic $(LD_EXTRA) -o $(BUILD_PATH)/$(LIBRARY_VERSION_SHARED) $^ $(LIBRARY_LIBS) $(COMMON_LIBS) $(LIBRARY_ARCHIVE): $(ALL_LIBRARY_OBJECTS) $(AR) $(AR_EXTRA) $(BUILD_PATH)/$@ $^ $(CLIENT_TARGET): $(LIBRARY_SHARED) $(LIBRARY_ARCHIVE) $(ALL_CLIENT_OBJECTS) $(LD) $(LDFLAGS) -o $(BUILD_PATH)/$@ $(ALL_CLIENT_OBJECTS) $(CLIENT_LIBS) $(COMMON_LIBS) $(TESTS_TARGET): $(LIBRARY_SHARED) $(LIBRARY_ARCHIVE) $(ALL_TEST_OBJECTS) $(LD) $(LDFLAGS) -o $(BUILD_PATH)/$@ $(ALL_TEST_OBJECTS) $(TEST_LIBS) $(COMMON_LIBS) $(TEST_SUITES): $(TESTS_TARGET) LD_LIBRARY_PATH=$(BUILD_PATH):$(LD_LIBRARY_PATH) $(BUILD_PATH)/$(TESTS_TARGET) --log_level=message --run_test=$(patsubst test-%,%,$@) test: $(TESTS_TARGET) @echo "running all test targets ($(TEST_SUITES))" LD_LIBRARY_PATH=$(BUILD_PATH):$(LD_LIBRARY_PATH) $(BUILD_PATH)/$(TESTS_TARGET) # # Dependencies # We don't care if they don't exist as the object won't have been built # -include $(patsubst %.o,%.d,$(ALL_LIBRARY_OBJECTS) $(ALL_TEST_OBJECTS)) # # Object file generation # $(OBJECT_PATH)/%.o: $(SRC_PATH)/%.cpp -mkdir -p $(dir $@) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COMMON_FLAGS) $(CONFIG_FLAGS) -c -o $@ $< zmqpp-4.1.2/README.md000066400000000000000000000136211254036632700141570ustar00rootroot00000000000000Introduction ============ Library / Bindings ------------------ This C++ binding for 0mq/zmq is a 'high-level' library that hides most of the c-style interface core 0mq provides. It consists of a number of header and source files all residing in the zmq directory, these files are provided under the MPLv2 license (see LICENSE for details). They can either be included directly into any 0mq using project or used as a library. A really basic Makefile is provided for this purpose and will generate both shared and static libraries. There are a number of unit tests covering the code but in no way should the tests be considered complete. Command-Line Client ------------------- There is also a command line client that can be used to test or even bridge zmq connections. The client is built on top of the libzmqpp bindings. Feature Requests ================ If there is any missing features from the current versions of ZeroMQ that you wish to use please raise an issue against this project, or even a pull request. Generally I've only added things as I need them but I'm always happy to improve the feature set as people require. Contributing ============ Contribution to this binding is welcome and it is suggested using pull requests in github that will then be reviewed and merged or commented on. The full contribution is outlined on the zmq site (http://zeromq.org/docs:contributing) Please feel free to add yourself to the AUTHORS file in an alphanumerically sorted way before you raise the pull request. Documentation ============= Most of the code is now commented with doxygen style tags, and a basic configuration file to generate them is in the root directory. To build the documentation with doxygen use doxygen And the resulting html or latex docs will be in the docs/html or docs/latex directories. libzmqpp ======== There is a Makefile provided which will build, test and install the binding on a GNU Linux system. I have not tested it on anything other than Ubuntu since 11.04 and Centos 5 and 6. The install process will only install headers and the shared object to the system. The archive will remain in the build directory. The tests for the binding (make check) require the boost unittest framework to have been installed however these do not need to be built or run to install the library itself. Requirements ------------ ZeroMQ 2.2.x or later. We recommend to use ZeroMQ >= 3. C++11 compliant compiler. (g++ >= 4.7) The command line client and the tests also require libboost. Installation ------------ Installation can be done by the standard make && make install. If the boost unittest framework is install check and installcheck can be run for sanity checking.To use ZMQ4 security feature install libsodium and libzmq --with-libsodium as shown below before ZMQPP. # Build, check, and install libsodium git clone git://github.com/jedisct1/libsodium.git cd libsodium ./autogen.sh ./configure && make check sudo make install sudo ldconfig cd ../ # Build, check, and install the latest version of ZeroMQ git clone git://github.com/zeromq/libzmq.git cd libzmq ./autogen.sh ./configure --with-libsodium && make sudo make install sudo ldconfig cd ../ # Now install ZMQPP make make check sudo make install make installcheck The most commonly useful overrides are setting CXX, to change the compiler used, and PREFIX to change install location. The CXX prefix should be used on all targets as the compiler version is used in the build path. PREFIX is only relevant for the install target. Debugging --------- The makefile defaults to a production ready build, however a debug version can be build by passing CONFIG=debug to the make command. In debug mode there is less optimisations and a number of sanity check assert statements. If you are not using the installed library the sanity check effect is governed by the defining of NDEBUG. zmqpp ===== The make file can also build and install a client tool called zmqpp. To build this tool add the step; make client Before the install stage. The install target will install the client to the binaries directory if it has been built. Usage ----- The client is a command line tool that can be used to listen or send to 0mq sockets. Its very basic so don't expect anything clever. zmqpp --help will list details about the possible flags it can take; Usage: zmqpp [options] SOCKETTYPE ENDPOINT 0mq command line client tool. SOCKETTYPE is one of the supported 0mq socket types. pub, pull, push, rep, req, sub ENDPOINT is any valid 0mq endpoint. Connection Options: -a [ --annotate ] annotate output with direction -b [ --bind ] arg bind to specified endpoint -c [ --connect ] arg connect to specified endpoint -d [ --detailed ] increased level of information displayed -x [ --exit-when-no-input ] don't wait for (streamed) input; exit on zero message -s [ --singlepart ] treat each line as a new message -v [ --verbose ] display output sent over socket to stderr Miscellaneous Options: --version display version --help show this help page Multiple uses of -c or -b are allowed to connect or bind to multiple endpoints, if neither is specified the connect is assumed for endpoint ENDPOINT. For send capable sockets entering text on standard in and pressing return will create a message part, with an empty part (double newline) marking the end of a message. If singlepart is enabled then the message is sent after each newline on the input stream. The default flags will allow you to pipe data from one instance of zmqpp to another and so bridge between zmq sockets. Licensing ========= Both the library and the associated command line client are released under the MPLv2 license. Please see LICENSE for full details. zmqpp-4.1.2/examples/000077500000000000000000000000001254036632700145135ustar00rootroot00000000000000zmqpp-4.1.2/examples/Makefile000066400000000000000000000004731254036632700161570ustar00rootroot00000000000000CPP = g++ RM = rm -f CPPFLAGS = -Wall -I. -O2 -std=c++11 -g LDFLAGS = -lpthread -lzmqpp -lzmq -lsodium -Wl,--no-as-needed SOURCES = $(wildcard *.cpp) TARGETS = $(SOURCES:%.cpp=%) all: ${TARGETS} clean: ${RM} *.obj *~* ${TARGETS} ${TARGETS}: ${CPP} ${CPPFLAGS} -o $@ ${@:%=%.cpp} ${LDFLAGS} zmqpp-4.1.2/examples/grasslands.cpp000066400000000000000000000025211254036632700173600ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * The Grasslands Pattern * * The Classic ZeroMQ model, plain text with no protection at all. * * \date 25 Nov 2014 * \author Prem Shankar Kumar (\@meprem) */ #include #include #include using namespace std; int main(int argc, char *argv[]) { // initialize the 0MQ context zmqpp::context context; // create and bind a server socket zmqpp::socket server (context, zmqpp::socket_type::push); server.bind("tcp://*:9000"); // create and connect a client socket zmqpp::socket client (context, zmqpp::socket_type::pull); client.connect("tcp://127.0.0.1:9000"); // Send a single message from server to client zmqpp::message request; request << "Hello"; server.send(request); zmqpp::message response; client.receive(response); assert("Hello" == response.get(0)); std::cout << "Grasslands test OK" << std::endl; return 0; } /* prem@prem-Vostro-2420:~/zmqpp-develop/examples$./grasslands Grasslands test OK prem@prem-Vostro-2420:~/zmqpp-develop/examples$ */ zmqpp-4.1.2/examples/ironhouse.cpp000066400000000000000000000076511254036632700172430ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * The Ironhouse Pattern * * Security doesn't get any stronger than this. An attacker is going to * have to break into your systems to see data before/after encryption. * * \date 25 Nov 2014 * \author Prem Shankar Kumar (\@meprem) */ #include #include #include #include using namespace std; int main(int argc, char *argv[]) { // initialize the 0MQ context zmqpp::context context; // Start an authentication engine for this context. This engine // allows or denies incoming connections (talking to the libzmq // core over a protocol called ZAP). zmqpp::auth authenticator(context); // Get some indication of what the authenticator is deciding authenticator.set_verbose (true); authenticator.configure_domain ("*"); // Whitelist our address; any other address will be rejected authenticator.allow ("127.0.0.1"); // We need two certificates, one for the client and one for // the server. The client must know the server's public key // to make a CURVE connection. zmqpp::curve::keypair client_keypair = zmqpp::curve::generate_keypair(); zmqpp::curve::keypair server_keypair = zmqpp::curve::generate_keypair(); std::cout << "Client Public Key :" << client_keypair.public_key << std::endl; std::cout << "Client Secret Key :" << client_keypair.secret_key << std::endl; std::cout << "Server Public Key :" << server_keypair.public_key << std::endl; std::cout << "Server Secret Key :" << server_keypair.secret_key << std::endl; // Tell authenticator to use the client public key authenticator.configure_curve(client_keypair.public_key); // create and bind a server socket zmqpp::socket server (context, zmqpp::socket_type::push); server.set(zmqpp::socket_option::identity, "IDENT"); int as_server = 1; server.set(zmqpp::socket_option::curve_server, as_server); server.set(zmqpp::socket_option::curve_secret_key, server_keypair.secret_key); server.bind("tcp://*:9000"); // create and connect a client socket zmqpp::socket client (context, zmqpp::socket_type::pull); client.set(zmqpp::socket_option::curve_server_key, server_keypair.public_key); client.set(zmqpp::socket_option::curve_public_key, client_keypair.public_key); client.set(zmqpp::socket_option::curve_secret_key, client_keypair.secret_key); client.connect("tcp://127.0.0.1:9000"); // Send a single message from server to client zmqpp::message request; request << "Hello"; server.send(request); zmqpp::message response; client.receive(response); assert("Hello" == response.get(0)); std::cout << "Ironhouse test OK" << std::endl; return 0; } /* prem@prem-Vostro-2420:~/zmqpp-develop/examples$./ironhouse auth: Starting ZAP Authentication Server auth: verbose:true auth: API command=DOMAIN auth: domain=* auth: API command=ALLOW auth: whitelisting ipaddress=127.0.0.1 Client Public Key :-XgJ}*n)lN>PwAPxA3eZ!w2c@w@.9:xU}fr[+9+] Client Secret Key :ePdC3.>Lq%oHoi!@u>8OU)]BUF+8lTCh&@A.7vlw Server Public Key :5hucezYEV)Yyr14gFugs0x8uU!fwB%voGwyp>:#G Server Secret Key :5X5bMl)3RKpti8Z5o7hCTnOfxix](tJHJToo.-pb auth: configure CURVE - client public key:-XgJ}*n)lN>PwAPxA3eZ!w2c@w@.9:xU}fr[+9+] auth: API command=CURVE auth: configured CURVE - allow client with public key:-XgJ}*n)lN>PwAPxA3eZ!w2c@w@.9:xU}fr[+9+] auth: ZAP request mechanism=CURVE ipaddress=127.0.0.1 auth: passed (whitelist) address=127.0.0.1 auth: allowed (CURVE) client_key=-XgJ}*n)lN>PwAPxA3eZ!w2c@w@.9:xU}fr[+9+] auth: ZAP reply status_code=200 status_text=OK Ironhouse test OK auth: API command=TERMINATE auth: Shutdown ZAP Authentication Server prem@prem-Vostro-2420:~/zmqpp-develop/examples$ */ zmqpp-4.1.2/examples/ironhouse2.cpp000066400000000000000000000124501254036632700173160ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * The Ironhouse2 Pattern * * Security doesn't get any stronger than this. An attacker is going to * have to break into your systems to see data before/after encryption. * * This is exactly the same example but broken into two threads * so you can better see what client and server do, separately. * * \date 25 Nov 2014 * \author Prem Shankar Kumar (\@meprem) */ #include #include #include #include #include #include #include using namespace std; /* * The client task runs in its own context, and receives the * client keypair and server public key as an argument. */ void client_task (zmqpp::curve::keypair& client_keypair, std::string server_public_key) { // initialize the 0MQ context zmqpp::context context; // create client socket and configure it to use full encryption zmqpp::socket client (context, zmqpp::socket_type::pull); client.set(zmqpp::socket_option::curve_server_key, server_public_key); client.set(zmqpp::socket_option::curve_public_key, client_keypair.public_key); client.set(zmqpp::socket_option::curve_secret_key, client_keypair.secret_key); client.connect("tcp://127.0.0.1:9000"); // Wait for our message, that signals the test was successful zmqpp::message response; client.receive(response); assert("Hello" == response.get(0)); std::cout << "Ironhouse2 test OK" << std::endl; } /* * The server task runs in its own context, and receives the * server key pair and a set of allowed/valid client public keys as an argument. */ void server_task (zmqpp::curve::keypair& server_keypair, std::vector& client_public_keys) { // initialize the 0MQ context zmqpp::context context; // Start an authentication engine for this context. This engine // allows or denies incoming connections (talking to the libzmq // core over a protocol called ZAP). zmqpp::auth authenticator(context); // Get some indication of what the authenticator is deciding authenticator.set_verbose (true); authenticator.configure_domain ("*"); // Whitelist our address; any other address will be rejected authenticator.allow ("127.0.0.1"); // Tell authenticator to do authenticate clients against all allowed client public keys for(auto cpk : client_public_keys) authenticator.configure_curve(cpk); // create and bind a server socket zmqpp::socket server (context, zmqpp::socket_type::push); server.set(zmqpp::socket_option::identity, "IDENT"); int as_server = 1; server.set(zmqpp::socket_option::curve_server, as_server); server.set(zmqpp::socket_option::curve_secret_key, server_keypair.secret_key); server.bind("tcp://*:9000"); // Send a single message from server to client zmqpp::message request; request << "Hello"; server.send(request); std::this_thread::sleep_for(std::chrono::seconds(1)); } int main(int argc, char *argv[]) { // We need two certificates, one for the client and one for // the server. The client must know the server's public key // to make a CURVE connection. zmqpp::curve::keypair client_keypair = zmqpp::curve::generate_keypair(); zmqpp::curve::keypair server_keypair = zmqpp::curve::generate_keypair(); std::cout << "Client Public Key :" << client_keypair.public_key << std::endl; std::cout << "Client Secret Key :" << client_keypair.secret_key << std::endl; // Allowed clients public keys std::vector client_public_keys; client_public_keys.push_back(client_keypair.public_key); std::cout << "Server Public Key :" << server_keypair.public_key << std::endl; std::cout << "Server Secret Key :" << server_keypair.secret_key << std::endl; // Now start two threads; each of these has their own ZeroMQ context. std::thread client_thread(client_task, std::ref(client_keypair), std::ref(server_keypair.public_key)); std::thread server_thread(server_task, std::ref(server_keypair), std::ref(client_public_keys)); // wait to finish client_thread.join(); server_thread.join(); return 0; } /* prem@prem-Vostro-2420:~/zmqpp-develop/examples$./ironhouse2 Client Public Key :/@=c(x1t7Rwe Server Secret Key :np?uPAh)tx[ExgYI(m!Dg!xyK?ViaP9+[r-ok4Q4 auth: Starting ZAP Authentication Server auth: verbose:true auth: API command=DOMAIN auth: domain=* auth: API command=ALLOW auth: whitelisting ipaddress=127.0.0.1 auth: configure CURVE - client public key:/@ #include #include using namespace std; int main(int argc, char *argv[]) { const string endpoint = "tcp://localhost:4242"; // initialize the 0MQ context zmqpp::context context; // generate a push socket zmqpp::socket_type type = zmqpp::socket_type::push; zmqpp::socket socket (context, type); // open the connection cout << "Opening connection to " << endpoint << "..." << endl; socket.connect(endpoint); // send a message cout << "Sending text and a number..." << endl; zmqpp::message message; // compose a message from a string and a number message << "Hello World!" << 42; socket.send(message); cout << "Sent message." << endl; cout << "Finished." << endl; } zmqpp-4.1.2/examples/simple_server.cpp000066400000000000000000000020751254036632700201020ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ #include #include #include using namespace std; int main(int argc, char *argv[]) { const string endpoint = "tcp://*:4242"; // initialize the 0MQ context zmqpp::context context; // generate a pull socket zmqpp::socket_type type = zmqpp::socket_type::pull; zmqpp::socket socket (context, type); // bind to the socket cout << "Binding to " << endpoint << "..." << endl; socket.bind(endpoint); // receive the message cout << "Receiving message..." << endl; zmqpp::message message; // decompose the message socket.receive(message); string text; int number; message >> text >> number; cout << "Received text:\"" << text << "\" and a number: " << number << endl; cout << "Finished." << endl; } zmqpp-4.1.2/examples/stonehouse.cpp000066400000000000000000000075311254036632700174210ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * The Stonehouse Pattern * * Where we allow any clients to connect, but we promise clients * that we are who we claim to be, and our conversations won't be * tampered with or modified, or spied on. * * \date 25 Nov 2014 * \author Prem Shankar Kumar (\@meprem) */ #include #include #include #include using namespace std; int main(int argc, char *argv[]) { // initialize the 0MQ context zmqpp::context context; // Start an authentication engine for this context. This engine // allows or denies incoming connections (talking to the libzmq // core over a protocol called ZAP). zmqpp::auth authenticator(context); // Get some indication of what the authenticator is deciding authenticator.set_verbose (true); authenticator.configure_domain ("*"); // Whitelist our address; any other address will be rejected authenticator.allow ("127.0.0.1"); // Tell the authenticator how to handle CURVE requests authenticator.configure_curve ("CURVE_ALLOW_ANY"); // We need two certificates, one for the client and one for // the server. The client must know the server's public key // to make a CURVE connection. zmqpp::curve::keypair client_keypair = zmqpp::curve::generate_keypair(); zmqpp::curve::keypair server_keypair = zmqpp::curve::generate_keypair(); std::cout << "Client Public Key :" << client_keypair.public_key << std::endl; std::cout << "Client Secret Key :" << client_keypair.secret_key << std::endl; std::cout << "Server Public Key :" << server_keypair.public_key << std::endl; std::cout << "Server Secret Key :" << server_keypair.secret_key << std::endl; // create and bind a server socket zmqpp::socket server (context, zmqpp::socket_type::push); server.set(zmqpp::socket_option::identity, "IDENT"); int as_server = 1; server.set(zmqpp::socket_option::curve_server, as_server); server.set(zmqpp::socket_option::curve_secret_key, server_keypair.secret_key); server.bind("tcp://*:9000"); // create and connect a client socket zmqpp::socket client (context, zmqpp::socket_type::pull); client.set(zmqpp::socket_option::curve_server_key, server_keypair.public_key); client.set(zmqpp::socket_option::curve_public_key, client_keypair.public_key); client.set(zmqpp::socket_option::curve_secret_key, client_keypair.secret_key); client.connect("tcp://127.0.0.1:9000"); // Send a single message from server to client zmqpp::message request; request << "Hello"; server.send(request); zmqpp::message response; client.receive(response); assert("Hello" == response.get(0)); std::cout << "Stonehouse test OK" << std::endl; return 0; } /* prem@prem-Vostro-2420:~/zmqpp-develop/examples$./stonehouse auth: Starting ZAP Authentication Server auth: verbose:true auth: API command=DOMAIN auth: domain=* auth: API command=ALLOW auth: whitelisting ipaddress=127.0.0.1 auth: configure CURVE - client public key:CURVE_ALLOW_ANY auth: API command=CURVE auth: configured CURVE - allow ALL clients Client Public Key :RKsg#n}EYFY[&byc-s6kIv1ri9Pe:Sjxp8LK8ES[ Client Secret Key :D/p?iaw=utRNVB^8pfX944(0pz/ADAAwx.k&h#xd Server Public Key :bP4=Ej(W^ecT:](PmXa{U3O6Y*HwLsrQ%Yb)H5joFpAA=EB?UrDaj]wQZh*}x4dsr@D:++ auth: ZAP request mechanism=CURVE ipaddress=127.0.0.1 auth: passed (whitelist) address=127.0.0.1 auth: allowed (CURVE allow any client) auth: ZAP reply status_code=200 status_text=OK Stonehouse test OK auth: API command=TERMINATE auth: Shutdown ZAP Authentication Server prem@prem-Vostro-2420:~/zmqpp-develop/examples$ */ zmqpp-4.1.2/examples/strawhouse.cpp000066400000000000000000000043721254036632700174310ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * The Strawhouse Pattern. * * We allow or deny clients according to their IP address. It may keep * spammers and idiots away, but won't stop a real attacker for more * than a heartbeat. * * \date 25 Nov 2014 * \author Prem Shankar Kumar (\@meprem) */ #include #include #include using namespace std; int main(int argc, char *argv[]) { // initialize the 0MQ context zmqpp::context context; // Start an authentication engine for this context. This engine // allows or denies incoming connections (talking to the libzmq // core over a protocol called ZAP). zmqpp::auth authenticator(context); // Get some indication of what the authenticator is deciding authenticator.set_verbose (true); // Configure ZAP domain authenticator.configure_domain ("global"); // Whitelist our address; any other address will be rejected authenticator.allow ("127.0.0.1"); // create and bind a server socket zmqpp::socket server (context, zmqpp::socket_type::push); //server.set(zmqpp::socket_option::zap_domain, "global"); server.bind("tcp://*:9000"); // create and connect a client socket zmqpp::socket client (context, zmqpp::socket_type::pull); client.connect("tcp://127.0.0.1:9000"); // Send a single message from server to client zmqpp::message request; request << "Hello"; server.send(request); zmqpp::message response; client.receive(response); assert("Hello" == response.get(0)); std::cout << "Strawhouse test OK" << std::endl; return 0; } /* prem@prem-Vostro-2420:~/zmqpp-develop/examples$./strawhouse auth: Starting ZAP Authentication Server auth: verbose:true auth: API command=DOMAIN auth: domain=global auth: API command=ALLOW auth: whitelisting ipaddress=127.0.0.1 Strawhouse test OK auth: API command=TERMINATE auth: Shutdown ZAP Authentication Server prem@prem-Vostro-2420:~/zmqpp-develop/examples$ */ zmqpp-4.1.2/examples/woodhouse.cpp000066400000000000000000000052331254036632700172360ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * The Woodhouse Pattern * * It may keep some malicious people out but all it takes is a bit * of network sniffing, and they'll be able to fake their way in. * * \date 25 Nov 2014 * \author Prem Shankar Kumar (\@meprem) */ #include #include #include using namespace std; int main(int argc, char *argv[]) { // initialize the 0MQ context zmqpp::context context; // Start an authentication engine for this context. This engine // allows or denies incoming connections (talking to the libzmq // core over a protocol called ZAP). zmqpp::auth authenticator(context); // Get some indication of what the authenticator is deciding authenticator.set_verbose (true); authenticator.configure_domain ("*"); // Tell the authenticator how to handle PLAIN requests authenticator.configure_plain ("admin", "password"); // Whitelist our address; any other address will be rejected authenticator.allow ("127.0.0.1"); // create and bind a server socket zmqpp::socket server (context, zmqpp::socket_type::push); server.set(zmqpp::socket_option::plain_server, 1); server.bind("tcp://*:9000"); // create and connect a client socket zmqpp::socket client (context, zmqpp::socket_type::pull); client.set(zmqpp::socket_option::plain_username, "admin"); client.set(zmqpp::socket_option::plain_password, "password"); client.connect("tcp://127.0.0.1:9000"); // Send a single message from server to client zmqpp::message request; request << "Hello"; server.send(request); zmqpp::message response; client.receive(response); assert("Hello" == response.get(0)); std::cout << "Woodhouse test OK" << std::endl; return 0; } /* prem@prem-Vostro-2420:~/zmqpp-develop/examples$./woodhouse auth: Starting ZAP Authentication Server auth: verbose:true auth: API command=DOMAIN auth: domain=* auth: configure PLAIN - username:admin password:password auth: API command=PLAIN auth: configured PLAIN - user:admin auth: API command=ALLOW auth: whitelisting ipaddress=127.0.0.1 auth: ZAP request mechanism=PLAIN ipaddress=127.0.0.1 auth: passed (whitelist) address=127.0.0.1 auth: allowed (PLAIN) username=admin password=password auth: ZAP reply status_code=200 status_text=OK Woodhouse test OK auth: API command=TERMINATE auth: Shutdown ZAP Authentication Server prem@prem-Vostro-2420:~/zmqpp-develop/examples$ */ zmqpp-4.1.2/packaging/000077500000000000000000000000001254036632700146215ustar00rootroot00000000000000zmqpp-4.1.2/packaging/build-srpm000077500000000000000000000026701254036632700166320ustar00rootroot00000000000000#!/bin/bash PKG_NAME=zmqpp t=`dirname ${BASH_SOURCE}` PKG_VERSION=`cat ${t}/../CHANGES.md | grep ^Version | head -n 1 | awk -F" " '{print $2}'` PKG_RELEASE=`git log --pretty="%ai" -n 1 | tr -d ':' | tr ' \-+:' '....' | cut -c1-17` PKG_RELEASE=${PKG_RELEASE}.git`git log --pretty="%h" -n 1` OUTPUT_DIRECTORY= syntax() { echo "build-srpm -o [output directory]" } while getopts "o:" o; do case "${o}" in o) OUTPUT_DIRECTORY=${OPTARG} ;; *) syntax exit 1 ;; esac done if [ -z "$OUTPUT_DIRECTORY" ] ; then echo error: no output directory specified echo syntax exit 1 fi if [ ! -d ${OUTPUT_DIRECTORY} ] ; then echo "error: output directory doesn't exist" exit 1 fi TARGET_DIR=`mktemp --tmpdir -d XXXXXXrpm-packaging` _prepare_srpm() { mkdir -p ${TARGET_DIR}/SPECS || return 1 mkdir -p ${TARGET_DIR}/SOURCES || return 1 git archive --format tar.gz --prefix=${PKG_NAME}-${PKG_VERSION}/ HEAD > \ ${TARGET_DIR}/SOURCES/${PKG_NAME}-${PKG_VERSION}.tar.gz || return 1 cat ${t}/${PKG_NAME}.spec | sed s/PKG_VERSION/${PKG_VERSION}/g \ | sed s/PKG_RELEASE/${PKG_RELEASE}/g > ${TARGET_DIR}/SPECS/${PKG_NAME}.spec || return 1 rpmbuild -bs --define "_topdir ${TARGET_DIR}" ${TARGET_DIR}/SPECS/${PKG_NAME}.spec || return 1 return 0 } if _prepare_srpm; then cp -a ${TARGET_DIR}/SRPMS/* ${OUTPUT_DIRECTORY} fi rm -rf ${TARGET_DIR} zmqpp-4.1.2/packaging/zmqpp.spec000066400000000000000000000030311254036632700166410ustar00rootroot00000000000000Name: zmqpp Version: PKG_VERSION Release: PKG_RELEASE%{?dist} Summary: 0mq 'highlevel' C++ bindings Group: System Environment/Libraries License: LGPLv3 URL: https://github.com/zeromq/zmqpp Source0: %{name}-%{version}.tar.gz BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) BuildRequires: gcc-c++ BuildRequires: zeromq3-devel BuildRequires: boost-devel %description This C++ binding for 0mq/zmq is a 'high-level' library that hides most of the c-style interface core 0mq provides. It consists of a number of header and source files all residing in the zmq directory, these files are provided under the MIT license (see LICENCE for details). %package devel Summary: Development files for %{name} Group: Development/Libraries Requires: %{name} = %{version}-%{release} %description devel The %{name}-devel package contains libraries and header files for developing applications that use %{name}. %prep %setup -q %build make %{?_smp_mflags} %check make check %install rm -rf ${RPM_BUILD_ROOT} mkdir -p ${RPM_BUILD_ROOT}%{_libdir} mkdir -p ${RPM_BUILD_ROOT}%{_includedir}/zmqpp make install \ PREFIX=/usr \ DESTDIR=${RPM_BUILD_ROOT} \ LIBDIR=${RPM_BUILD_ROOT}%{_libdir} \ INCLUDEDIR=${RPM_BUILD_ROOT}%{_includedir} %clean rm -rf $RPM_BUILD_ROOT %post -p /sbin/ldconfig %postun -p /sbin/ldconfig %files %defattr(-,root,root,-) %{_libdir}/libzmqpp.* %files devel %defattr(-,root,root,-) %{_includedir}/zmqpp/* zmqpp-4.1.2/src/000077500000000000000000000000001254036632700134645ustar00rootroot00000000000000zmqpp-4.1.2/src/client/000077500000000000000000000000001254036632700147425ustar00rootroot00000000000000zmqpp-4.1.2/src/client/main.cpp000066400000000000000000000207151254036632700163770ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * Created on: 16 Aug 2011 * Author: @benjamg */ #include #include #include #include #include #include "options.hpp" #ifndef BUILD_CLIENT_NAME #define BUILD_CLIENT_NAME "zmqpp" #endif int main(int argc, char const* argv[]) { client_options const options = process_command_line( argc, argv ); if( options.show_version ) { uint8_t major, minor, patch; zmqpp::zmq_version(major, minor, patch); std::cout << BUILD_CLIENT_NAME << " version " << zmqpp::version() << std::endl; std::cout << " built against 0mq version " << static_cast(major) << "." << static_cast(minor) << "." << static_cast(patch) << std::endl; return EXIT_FAILURE; } if( options.show_usage || options.show_help ) { show_usage( std::cout, BUILD_CLIENT_NAME ); if( options.show_help ) { std::cout << std::endl; show_help( std::cout ); } return EXIT_FAILURE; } bool can_send = false, can_recv = false, toggles = false; switch( options.type ) { case zmqpp::socket_type::push: can_send = true; break; case zmqpp::socket_type::pull: can_recv = true; break; case zmqpp::socket_type::publish: can_send = true; break; case zmqpp::socket_type::subscribe: can_recv = true; break; case zmqpp::socket_type::request: can_send = true; toggles = true; break; case zmqpp::socket_type::reply: can_recv = true, toggles = true; break; default: std::cerr << "Unsupported socket type" << std::endl; return EXIT_FAILURE; } int standardin = -1; // If we can send / toggle then we need stdin if( can_send || toggles ) { if( options.verbose ) { std::cerr << "Connecting to stdin" << std::endl; } standardin = fileno(stdin); if ( standardin < 0 ) // really? { std::cerr << "Unable to get standard input, this might be an OS thing, sorry." << std::endl; return EXIT_FAILURE; } } zmqpp::context context; zmqpp::socket socket( context, options.type ); // TODO: allow subscriptions on command line if( zmqpp::socket_type::subscribe == options.type ) { socket.subscribe( "" ); } if( !options.binds.empty() ) { for(size_t i = 0; i < options.binds.size(); ++i) { if( options.verbose ) { std::cerr << "binding to " << options.binds[i] << std::endl; } try { socket.bind( options.binds[i] ); } catch(zmqpp::zmq_internal_exception& e) { std::cerr << "failed to bind to endpoint " << options.binds[i] << ": " << e.what() << std::endl; return EXIT_FAILURE; } } } if( !options.connects.empty() ) { for(size_t i = 0; i < options.connects.size(); ++i) { if( options.verbose ) { std::cerr << "connecting to " << options.connects[i] << std::endl; } try { socket.connect( options.connects[i] ); } catch(zmqpp::zmq_internal_exception& e) { std::cerr << "failed to bind to endpoint " << options.connects[i] << ": " << e.what() << std::endl; return EXIT_FAILURE; } } } zmqpp::poller poller; poller.add(socket); if( standardin >= 0 ) { poller.add( standardin ); } if( options.verbose && ( can_send || toggles ) ) { std::cerr << "While sending packets is allowed data entered on standard in will be sent to the 0mq socket." << std::endl; if( options.singlepart ) { std::cerr << "messages will be considered terminated by newline." << std::endl; } else { std::cerr << "Message parts will be considered terminated by newline." << std::endl; std::cerr << "Messages will be considered terminated by an empty part." << std::endl; std::cerr << "The empty part itself will not be included." << std::endl; } std::cerr << std::endl; if ( toggles && !can_send ) { std::cerr << "Sending starts as disabled for this socket type." << std::endl; std::cerr << std::endl; } } if( options.detailed ) { if( standardin >= 0 ) { if( options.annotate ) { std::cerr << "**: "; } std::cerr << "reading from stdin is enabled." << std::endl; } if( can_send ) { if( options.annotate ) { std::cerr << "**: "; } std::cerr << "sending via socket is enabled." << std::endl; } if( can_recv ) { if( options.annotate ) { std::cerr << "**: "; } std::cerr << "receiving via socket is enabled." << std::endl; } if( toggles ) { if( options.annotate ) { std::cerr << "**: "; } std::cerr << "socket will flip between send/recv." << std::endl; } if( options.annotate ) { std::cerr << "**: "; } std::cerr << "Warning - Detailed logging is enabled." << std::endl; } zmqpp::message message; while(true) { poller.check_for(socket, (can_recv) ? zmqpp::poller::poll_in : zmqpp::poller::poll_none); if( standardin >= 0 ) { poller.check_for(standardin, (can_send) ? zmqpp::poller::poll_in : zmqpp::poller::poll_none); } if( options.detailed ) { if( options.annotate ) { std::cerr << "**: "; } std::cerr << "Polling for incomming message data." << std::endl; } if( poller.poll() ) { if (poller.has_input(socket)) { assert(can_recv); if( options.detailed ) { if( options.annotate ) { std::cerr << "**: "; } std::cerr << "Message on socket." << std::endl; } do { std::string message; socket.receive(message); if( options.annotate ) { std::cout << "<<: "; } std::cout << message << std::endl; } while(socket.has_more_parts()); if( options.annotate ) { std::cout << " --- " << std::endl; } else { std::cout << std::endl; } if (toggles) { can_recv = false; can_send = true; if( options.detailed ) { if( options.annotate ) { std::cerr << "**: " << std::endl; } std::cerr << "Toggling to sending enabled" << std::endl; } } } if( (standardin >= 0) && poller.has_input( standardin ) ) { assert(can_send); if( options.detailed ) { if( options.annotate ) { std::cerr << "**: "; } std::cerr << "Data on stdin." << std::endl; } // TODO: handle cases where we actually read a mb of data from standard in and still don't have the terminator std::array buffer; size_t length = 0; char* result = fgets( buffer.data(), buffer.size(), stdin ); if( !result ) { if( options.annotate ) { std::cerr << "!!: "; } std::cerr << "Error in standard input" << std::endl; return EXIT_FAILURE; } assert(message.parts() == 0); while( result && (length = strlen( buffer.data() ) - 1) > 0 ) // trim newline from gets { buffer[length] = 0; message.add_raw( buffer.data(), static_cast(length) ); if( options.singlepart ) { break; } result = fgets(buffer.data(), buffer.size(), stdin); } if( message.parts() > 0 ) { if( options.verbose ) { for( size_t i = 0; i < message.parts(); ++i ) { if( options.annotate ) { std::cout << ">>: "; } std::cout << message.get(i) << std::endl; } if( options.annotate ) { std::cout << " --- " << std::endl; } else { std::cout << std::endl; } } if( !socket.send( message, true ) ) { if( options.detailed ) { if( options.annotate ) { std::cerr << "**: "; } std::cerr << "Output blocking, waiting to send" << std::endl; } if( !socket.send( message ) ) { if( options.annotate ) { std::cerr << "!!: "; } std::cerr << "Send failed, socket would have blocked" << std::endl; zmqpp::message tmp; std::swap( tmp, message ); } } if (toggles) { can_recv = true; can_send = false; if( options.detailed ) { if( options.annotate ) { std::cerr << "**: " << std::endl; } std::cerr << "Toggling to receive enabled" << std::endl; } } } } else if( (standardin >= 0) && can_send && !can_recv ) { if( options.detailed ) { if( options.annotate ) { std::cerr << "**: "; } std::cerr << "No data on stdin, exiting reader." << std::endl; } break; } } else if( options.detailed ) { if( options.annotate ) { std::cerr << "**: "; } std::cerr << "Poller returned with no data, possibly an interrupt." << std::endl; } } if( options.detailed ) { if( options.annotate ) { std::cerr << "**: "; } std::cerr << "Exited reader, shutting down." << std::endl; } return EXIT_SUCCESS; } zmqpp-4.1.2/src/client/options.cpp000066400000000000000000000123241254036632700171430ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * options.cpp * * Created on: 6 Nov 2013 * Author: bgray */ #include #include #include #include #include #include #include "options.hpp" #ifndef BUILD_CLIENT_NAME #define BUILD_CLIENT_NAME "zmqpp" #endif boost::program_options::options_description connection_options() { boost::program_options::options_description options("Connection Options"); options.add_options() ( "annotate,a", "annotate output with direction" ) ( "bind,b", boost::program_options::value>(), "bind to specified endpoint" ) ( "connect,c", boost::program_options::value>(), "connect to specified endpoint" ) ( "detailed,d", "increased level of information displayed" ) ( "exit-when-no-input,x", "don't wait for (streamed) input; exit on zero message" ) ( "ignore-zeroes,z", "deprecated option, now the default state" ) ( "multipart,m", "deprecated option, now the default state" ) ( "singlepart,s", "treat each line as a new message" ) ( "verbose,v", "display output sent over socket to stderr" ) ; return options; } boost::program_options::options_description miscellaneous_options() { boost::program_options::options_description options("Miscellaneous Options"); options.add_options() ( "version", "display version" ) ( "help", "show this help page" ) ; return options; } typedef std::map socket_type_index; socket_type_index socket_type_options() { socket_type_index socket_types = { { "push", zmqpp::socket_type::push }, { "pull", zmqpp::socket_type::pull }, { "pub", zmqpp::socket_type::publish }, { "publish", zmqpp::socket_type::publish }, { "sub", zmqpp::socket_type::subscribe }, { "subscribe", zmqpp::socket_type::subscribe }, { "req", zmqpp::socket_type::request }, { "request", zmqpp::socket_type::request }, { "rep", zmqpp::socket_type::reply }, { "reply", zmqpp::socket_type::reply } }; return socket_types; } client_options process_command_line(int argc, char const* argv[]) { boost::program_options::positional_options_description arguments; arguments.add("type", 1); arguments.add("connect", 1); boost::program_options::options_description all; all.add_options() ( "type", "0mq socket type" ) ; all.add(miscellaneous_options()); all.add(connection_options()); boost::program_options::variables_map vm; client_options options; try { boost::program_options::store( boost::program_options::command_line_parser( argc, argv ).options( all ).positional( arguments ).run(), vm ); } catch(boost::program_options::too_many_positional_options_error& e) { std::cerr << "Too many arguments provided." << std::endl; options.show_usage = true; } catch(boost::program_options::unknown_option& e) { std::cerr << "Unknown option '" << e.get_option_name() << "'." << std::endl; options.show_usage = true; } catch(boost::program_options::error& e) { std::cerr << "command line parse error: " << e.what() << "'." << std::endl; options.show_usage = true; } socket_type_index socket_types = socket_type_options(); if ( vm.count( "type" ) && ( socket_types.end() == socket_types.find( vm["type"].as() ) ) ) { std::cerr << "Unknown value '" << vm["type"].as() << "' provided for 0mq socket type." << std::endl; options.show_usage = true; } if ( (0 == vm.count( "type" )) || vm.count( "help" ) || ( (0 == vm.count( "connect" )) && (0 == vm.count( "bind" )) ) ) { options.show_usage = true; } options.show_version = ( vm.count( "version" ) > 0 ); options.show_help = ( vm.count( "help" ) > 0 ); if ( vm.count( "type" ) ) { options.type = socket_types[ vm["type"].as() ]; } if ( vm.count( "bind" ) ) { options.binds = vm["bind"].as>(); } if ( vm.count( "connect" ) ) { options.connects = vm["connect"].as>(); } options.singlepart = ( vm.count( "singlepart" ) > 0 ); options.annotate = ( vm.count( "annotate" ) > 0 ); options.verbose = ( vm.count( "verbose" ) > 0 || vm.count( "detailed" ) > 0 ); options.detailed = ( vm.count( "detailed" ) > 0 ); options.exit_on_empty = ( vm.count( "exit-when-no-input" ) > 0 ); return options; } std::ostream& show_usage(std::ostream& stream, std::string const& application_name) { stream << "Usage: " BUILD_CLIENT_NAME " [options] SOCKETTYPE ENDPOINT" << std::endl; stream << "0mq command line client tool." << std::endl; stream << "SOCKETTYPE is one of the supported 0mq socket types." << std::endl; stream << " pull, push, pub, sub, req, rep" << std::endl; stream << "ENDPOINT is any valid 0mq endpoint." << std::endl; return stream; } std::ostream& show_help(std::ostream& stream) { stream << connection_options() << std::endl; stream << miscellaneous_options() << std::endl; return stream; } zmqpp-4.1.2/src/client/options.hpp000066400000000000000000000023311254036632700171450ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * options.hpp * * Created on: 6 Nov 2013 * Author: bgray */ #ifndef OPTIONS_HPP_ #define OPTIONS_HPP_ #include #include struct client_options { bool show_usage; bool show_help; bool show_version; bool verbose; bool detailed; bool annotate; zmqpp::socket_type type; std::vector binds; std::vector connects; bool singlepart; bool exit_on_empty; client_options() : show_usage( false ), show_help( false ), show_version( false ) , verbose( false ), detailed( false ), annotate( false ) , type( zmqpp::socket_type::pair ), binds(), connects() , singlepart( false ), exit_on_empty( false ) { } }; client_options process_command_line(int argc, char const* argv[]); std::ostream& show_usage(std::ostream& stream, std::string const& application_name); std::ostream& show_help(std::ostream& stream); #endif /* OPTIONS_HPP_ */ zmqpp-4.1.2/src/mainpage.md000066400000000000000000000024771254036632700156010ustar00rootroot00000000000000@mainpage Introduction ------------ zmqpp is a "high-level" C++ binding for 0mq/zmq. The "high-level" term is used in comparison to [cppzmq](https://github.com/zeromq/cppzmq) which is somewhat a raw wrapper around the [libzmq](https://github.com/zeromq/libzmq) C interface. The library is documented and has a nice test suite. This doesn't mean that the library is bug free or that the test suite is 100% complete. The development takes places in this [GitHub repository](http://github.com/zeromq/zmqpp). Features --------- Basic features: + zmqpp provides most feature from libzmq in a C++ style API. + It supports multiple version of [libzmq](https://github.com/zeromq/libzmq). Being built on top of libzmq, and being a higher-level binding, zmqpp provides some additional features: + [Reactor](@ref zmqpp::reactor) pattern. + [Actor](@ref zmqpp::actor) pattern. + Support for ZAP. Examples -------- zmqpp comes a few examples. These can be found [here](https://github.com/zeromq/zmqpp/tree/develop/examples). Reading the documentation is a good way to start learning about zmqpp. The most important classes that you will likely use are thoses: + [Context](@ref zmqpp::context). + [Socket](@ref zmqpp::socket). + [Message](@ref zmqpp::message). + And either a [Poller](@ref zmqpp::poller) or a [Reactor](@ref zmqpp::reactor). zmqpp-4.1.2/src/tests/000077500000000000000000000000001254036632700146265ustar00rootroot00000000000000zmqpp-4.1.2/src/tests/test_actor.cpp000066400000000000000000000163531254036632700175110ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ #include #include #include "zmqpp/context.hpp" #include "zmqpp/message.hpp" #include "zmqpp/actor.hpp" #include "zmqpp/poller.hpp" #include BOOST_AUTO_TEST_SUITE( actor ) BOOST_AUTO_TEST_CASE(simple_test) { auto lambda = [](zmqpp::socket * pipe) { zmqpp::message msg("boap"); msg.add(42); msg.add(13); pipe->send(zmqpp::signal::ok); // signal we successfully started pipe->send(msg); return true; // will send signal::ok to signal successful shutdown }; zmqpp::actor actor(lambda); zmqpp::message msg; actor.pipe()->receive(msg); int a, b; std::string str; msg >> str >> a >> b; BOOST_CHECK_EQUAL("boap", str); BOOST_CHECK_EQUAL(42, a); BOOST_CHECK_EQUAL(13, b); } BOOST_AUTO_TEST_CASE(test_actor_movable) { auto lambda = [](zmqpp::socket * pipe) { pipe->send(zmqpp::signal::ok); // signal we successfully started pipe->send("boap1"); pipe->send("boap2"); pipe->send("boap3"); return true; }; zmqpp::actor actor1(lambda); std::string str; actor1.pipe()->receive(str); BOOST_CHECK_EQUAL("boap1", str); zmqpp::actor actor2(std::move(actor1)); actor2.pipe()->receive(str); BOOST_CHECK_EQUAL("boap2", str); // move from an "empty" actor and make sure it doesnt have a pointer to the pipe anymore zmqpp::actor actor_empty(std::move(actor1)); BOOST_CHECK(actor_empty.pipe() == nullptr); zmqpp::actor actor3(std::move(actor2)); actor3.pipe()->receive(str); BOOST_CHECK_EQUAL("boap3", str); BOOST_CHECK_EQUAL(actor3.stop(true), true); zmqpp::actor actor4(std::move(actor3)); BOOST_CHECK_EQUAL(actor4.stop(true), true); } BOOST_AUTO_TEST_CASE(child_thread_wait_for_stop) { auto lambda = [](zmqpp::socket * pipe) { int count = 0; zmqpp::message msg; zmqpp::signal sig; pipe->send(zmqpp::signal::ok); while (pipe->receive(msg)) { if (msg.is_signal()) { msg.get(sig, 0); if (sig == zmqpp::signal::stop) break; } zmqpp::message rep("hello"); pipe->send(rep); count++; } zmqpp::message final_res; final_res << count; // send the total count to the parent thread pipe->send(final_res); return true; }; zmqpp::actor *actor = new zmqpp::actor(lambda); zmqpp::message msg; for (int i = 0; i < 12; i++) { actor->pipe()->send("hey"); actor->pipe()->receive(msg); } actor->stop(); // sends the stop signal, but doesn't wait for a response: the destructor will wait instead actor->pipe()->receive(msg); int count; msg >> count; delete actor; BOOST_CHECK_EQUAL(12, count); } /** * Helper function that runs a echo server (router socket) bound to endpoint. * It will send signal::ko if the bind fails (invalid endpoint) and signal::ok if initialization worked. * * It exits when receiving signal::stop from the pipe, and send the number of messages the router sent * when receiving the GET_COUNT command. */ static bool count_echo_server(zmqpp::socket * pipe, zmqpp::context *context, std::string endpoint) { zmqpp::socket router(*context, zmqpp::socket_type::router); zmqpp::poller p; zmqpp::signal sig; int count = 0; // how many message sent (by the router)) try { router.bind(endpoint); pipe->send(zmqpp::signal::ok); } catch (zmqpp::zmq_internal_exception &e) { // by returning false here, the actor will send signal::ko // this will make the actor constructor throw. // we could also to the ourselves: pipe->send(signal::ko);) return false; } p.add(*pipe); p.add(router); while (p.poll()) { zmqpp::message msg; if (p.has_input(router)) { router.receive(msg); router.send(msg); count++; } if (p.has_input(*pipe)) { pipe->receive(msg); if (msg.is_signal()) { msg.get(sig, 0); if (sig == zmqpp::signal::stop) break; } if (msg.get(0) == "GET_COUNT") { zmqpp::message msg_count(count); pipe->send(msg_count); } } } return true; } BOOST_AUTO_TEST_CASE(test_actor_init_failed) { zmqpp::context application_context; // what would be the default context we use generally. // the actor thread will fail and send signal::ko, so actor constructor should throw. // the placeholder is for the pipe socket. BOOST_CHECK_THROW(zmqpp::actor actor(std::bind(&count_echo_server, std::placeholders::_1, &application_context, "InvalidEndpointForRouter")), zmqpp::actor_initialization_exception); } BOOST_AUTO_TEST_CASE(test_actor_stop_failed) { // a task that simulates failure to stop auto lambda_fail = [] (zmqpp::socket * pipe) -> bool { pipe->send(zmqpp::signal::ok); // signal start ok //wait for stop signal while (true) { if (pipe->wait() == zmqpp::signal::stop) break; } // for some reason let's say we failed to properly stopped the task. return false; }; // a task that successfully stops auto lambda_success = [] (zmqpp::socket * pipe) -> bool { pipe->send(zmqpp::signal::ok); // signal start ok //wait for stop signal while (true) { if (pipe->wait() == zmqpp::signal::stop) break; } return true; }; zmqpp::actor actor1(lambda_success); zmqpp::actor actor2(lambda_fail); BOOST_CHECK_EQUAL(true, actor1.stop(true)); BOOST_CHECK_EQUAL(false, actor2.stop(true)); } BOOST_AUTO_TEST_CASE(test_sending_command) { zmqpp::context application_context; // what would be the default context we use generally. zmqpp::actor actor(std::bind(&count_echo_server, std::placeholders::_1, &application_context, "inproc://router-endpoint")); zmqpp::socket client(application_context, zmqpp::socket_type::dealer); client.connect("inproc://router-endpoint"); // simulate a random client of the router int c; for (int i = 0; i < 10; i++) { if (i % 3 == 0) { zmqpp::message msg; actor.pipe()->send("GET_COUNT"); actor.pipe()->receive(msg); msg >> c; BOOST_CHECK_EQUAL(i, c); } client.send("Hello"); std::string bla; client.receive(bla); // we need to receive otherwise the count may be wrong } // assert total count zmqpp::message msg; actor.pipe()->send("GET_COUNT"); actor.pipe()->receive(msg); msg >> c; BOOST_CHECK_EQUAL(10, c); } BOOST_AUTO_TEST_SUITE_END() zmqpp-4.1.2/src/tests/test_auth.cpp000066400000000000000000000314171254036632700173400ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ #include #include #include "zmqpp/context.hpp" #include "zmqpp/message.hpp" #include "zmqpp/actor.hpp" #include "zmqpp/poller.hpp" #include "zmqpp/curve.hpp" #include "zmqpp/zap_request.hpp" #include "zmqpp/auth.hpp" #include #include BOOST_AUTO_TEST_SUITE( auth ) // The whole test suite should be ran only against libzmq > 3 // Also, for some reason those tests fail against zmq4.0.x #if ((ZMQ_VERSION_MAJOR > 3) && !(ZMQ_VERSION_MAJOR == 4 && ZMQ_VERSION_MINOR == 0)) BOOST_AUTO_TEST_CASE(grasslands) { // initialize the 0MQ context zmqpp::context context; // create and bind a server socket zmqpp::socket server(context, zmqpp::socket_type::push); server.bind("tcp://*:9000"); // create and connect a client socket zmqpp::socket client(context, zmqpp::socket_type::pull); client.connect("tcp://127.0.0.1:9000"); // Send a single message from server to client zmqpp::message request; request << "Hello"; server.send(request); zmqpp::message response; client.receive(response); BOOST_CHECK_EQUAL("Hello", response.get(0)); } BOOST_AUTO_TEST_CASE(strawhouse) { // initialize the 0MQ context zmqpp::context context; // Start an authentication engine for this context. This engine // allows or denies incoming connections (talking to the libzmq // core over a protocol called ZAP). zmqpp::auth authenticator(context); // Get some indication of what the authenticator is deciding authenticator.set_verbose(true); // Configure ZAP domain authenticator.configure_domain("global"); // Whitelist our address; any other address will be rejected authenticator.allow("127.0.0.1"); // create and bind a server socket zmqpp::socket server(context, zmqpp::socket_type::push); //server.set(zmqpp::socket_option::zap_domain, "global"); server.bind("tcp://*:9000"); // create and connect a client socket zmqpp::socket client(context, zmqpp::socket_type::pull); client.connect("tcp://127.0.0.1:9000"); // Send a single message from server to client zmqpp::message request; request << "Hello"; server.send(request); zmqpp::message response; client.receive(response); BOOST_CHECK_EQUAL("Hello", response.get(0)); } BOOST_AUTO_TEST_CASE(woodhouse) { // initialize the 0MQ context zmqpp::context context; // Start an authentication engine for this context. This engine // allows or denies incoming connections (talking to the libzmq // core over a protocol called ZAP). zmqpp::auth authenticator(context); // Get some indication of what the authenticator is deciding authenticator.set_verbose(true); authenticator.configure_domain("*"); // Tell the authenticator how to handle PLAIN requests authenticator.configure_plain("admin", "password"); // Whitelist our address; any other address will be rejected authenticator.allow("127.0.0.1"); // create and bind a server socket zmqpp::socket server(context, zmqpp::socket_type::pull); server.set(zmqpp::socket_option::plain_server, 1); server.bind("tcp://*:9000"); // create and connect a client socket zmqpp::socket client(context, zmqpp::socket_type::push); client.set(zmqpp::socket_option::plain_username, "admin"); client.set(zmqpp::socket_option::plain_password, "password"); client.connect("tcp://127.0.0.1:9000"); // Send a single message from client to server zmqpp::message request; request << "Hello"; client.send(request); zmqpp::message response; server.receive(response); std::string user_id; BOOST_CHECK_EQUAL(true, response.get_property("User-Id", user_id)); BOOST_CHECK_EQUAL("admin", user_id); BOOST_CHECK_EQUAL("Hello", response.get(0)); } BOOST_AUTO_TEST_CASE(stonehouse) { if (!zmq_has("curve")) { std::cout << "Skipping stonehouse test since zmq wasn't build with libsodium" << std::endl; return; } // initialize the 0MQ context zmqpp::context context; // Start an authentication engine for this context. This engine // allows or denies incoming connections (talking to the libzmq // core over a protocol called ZAP). zmqpp::auth authenticator(context); // Get some indication of what the authenticator is deciding authenticator.set_verbose(true); authenticator.configure_domain("*"); // Whitelist our address; any other address will be rejected authenticator.allow("127.0.0.1"); // Tell the authenticator how to handle CURVE requests authenticator.configure_curve("CURVE_ALLOW_ANY"); // We need two certificates, one for the client and one for // the server. The client must know the server's public key // to make a CURVE connection. zmqpp::curve::keypair client_keypair = zmqpp::curve::generate_keypair(); zmqpp::curve::keypair server_keypair = zmqpp::curve::generate_keypair(); std::cout << "Client Public Key :" << client_keypair.public_key << std::endl; std::cout << "Client Secret Key :" << client_keypair.secret_key << std::endl; std::cout << "Server Public Key :" << server_keypair.public_key << std::endl; std::cout << "Server Secret Key :" << server_keypair.secret_key << std::endl; // create and bind a server socket zmqpp::socket server(context, zmqpp::socket_type::pull); server.set(zmqpp::socket_option::identity, "IDENT"); int as_server = 1; server.set(zmqpp::socket_option::curve_server, as_server); server.set(zmqpp::socket_option::curve_secret_key, server_keypair.secret_key); server.bind("tcp://*:9000"); // create and connect a client socket zmqpp::socket client(context, zmqpp::socket_type::push); client.set(zmqpp::socket_option::curve_server_key, server_keypair.public_key); client.set(zmqpp::socket_option::curve_public_key, client_keypair.public_key); client.set(zmqpp::socket_option::curve_secret_key, client_keypair.secret_key); client.connect("tcp://127.0.0.1:9000"); // Send a single message from client to server zmqpp::message request; request << "Hello"; client.send(request); zmqpp::message response; server.receive(response); std::string user_id; BOOST_CHECK_EQUAL(true, response.get_property("User-Id", user_id)); BOOST_CHECK_EQUAL(client_keypair.public_key, user_id); BOOST_CHECK_EQUAL("Hello", response.get(0)); } BOOST_AUTO_TEST_CASE(ironhouse) { if (!zmq_has("curve")) { std::cout << "Skipping ironhouse test since zmq wasn't build with libsodium" << std::endl; return; } // initialize the 0MQ context zmqpp::context context; // Start an authentication engine for this context. This engine // allows or denies incoming connections (talking to the libzmq // core over a protocol called ZAP). zmqpp::auth authenticator(context); // Get some indication of what the authenticator is deciding authenticator.set_verbose(true); authenticator.configure_domain("*"); // Whitelist our address; any other address will be rejected authenticator.allow("127.0.0.1"); // We need two certificates, one for the client and one for // the server. The client must know the server's public key // to make a CURVE connection. zmqpp::curve::keypair client_keypair = zmqpp::curve::generate_keypair(); zmqpp::curve::keypair server_keypair = zmqpp::curve::generate_keypair(); std::cout << "Client Public Key :" << client_keypair.public_key << std::endl; std::cout << "Client Secret Key :" << client_keypair.secret_key << std::endl; std::cout << "Server Public Key :" << server_keypair.public_key << std::endl; std::cout << "Server Secret Key :" << server_keypair.secret_key << std::endl; // Tell authenticator to use the client public key authenticator.configure_curve(client_keypair.public_key); // create and bind a server socket zmqpp::socket server(context, zmqpp::socket_type::push); server.set(zmqpp::socket_option::identity, "IDENT"); int as_server = 1; server.set(zmqpp::socket_option::curve_server, as_server); server.set(zmqpp::socket_option::curve_secret_key, server_keypair.secret_key); server.bind("tcp://*:9000"); // create and connect a client socket zmqpp::socket client(context, zmqpp::socket_type::pull); client.set(zmqpp::socket_option::curve_server_key, server_keypair.public_key); client.set(zmqpp::socket_option::curve_public_key, client_keypair.public_key); client.set(zmqpp::socket_option::curve_secret_key, client_keypair.secret_key); client.connect("tcp://127.0.0.1:9000"); // Send a single message from server to client zmqpp::message request; request << "Hello"; server.send(request); zmqpp::message response; client.receive(response); BOOST_CHECK_EQUAL("Hello", response.get(0)); } /* * The client task runs in its own context, and receives the * client keypair and server public key as an argument. */ static void client_task(zmqpp::curve::keypair& client_keypair, std::string server_public_key) { // initialize the 0MQ context zmqpp::context context; // create client socket and configure it to use full encryption zmqpp::socket client(context, zmqpp::socket_type::pull); client.set(zmqpp::socket_option::curve_server_key, server_public_key); client.set(zmqpp::socket_option::curve_public_key, client_keypair.public_key); client.set(zmqpp::socket_option::curve_secret_key, client_keypair.secret_key); client.connect("tcp://127.0.0.1:9000"); // Wait for our message, that signals the test was successful zmqpp::message response; client.receive(response); BOOST_CHECK_EQUAL("Hello", response.get(0)); } /* * The server task runs in its own context, and receives the * server key pair and a set of allowed/valid client public keys as an argument. */ static void server_task(zmqpp::curve::keypair& server_keypair, std::vector& client_public_keys) { // initialize the 0MQ context zmqpp::context context; // Start an authentication engine for this context. This engine // allows or denies incoming connections (talking to the libzmq // core over a protocol called ZAP). zmqpp::auth authenticator(context); // Get some indication of what the authenticator is deciding authenticator.set_verbose(true); authenticator.configure_domain("*"); // Whitelist our address; any other address will be rejected authenticator.allow("127.0.0.1"); // Tell authenticator to do authenticate clients against all allowed client public keys for(auto cpk : client_public_keys) authenticator.configure_curve(cpk); // create and bind a server socket zmqpp::socket server(context, zmqpp::socket_type::push); server.set(zmqpp::socket_option::identity, "IDENT"); int as_server = 1; server.set(zmqpp::socket_option::curve_server, as_server); server.set(zmqpp::socket_option::curve_secret_key, server_keypair.secret_key); server.bind("tcp://*:9000"); // Send a single message from server to client zmqpp::message request; request << "Hello"; server.send(request); std::this_thread::sleep_for(std::chrono::seconds(1)); } BOOST_AUTO_TEST_CASE(ironhouse2) { if (!zmq_has("curve")) { std::cout << "Skipping ironhouse2 test since zmq wasn't build with libsodium" << std::endl; return; } // We need two certificates, one for the client and one for // the server. The client must know the server's public key // to make a CURVE connection. zmqpp::curve::keypair client_keypair = zmqpp::curve::generate_keypair(); zmqpp::curve::keypair server_keypair = zmqpp::curve::generate_keypair(); std::cout << "Client Public Key :" << client_keypair.public_key << std::endl; std::cout << "Client Secret Key :" << client_keypair.secret_key << std::endl; // Allowed clients public keys std::vector client_public_keys; client_public_keys.push_back(client_keypair.public_key); std::cout << "Server Public Key :" << server_keypair.public_key << std::endl; std::cout << "Server Secret Key :" << server_keypair.secret_key << std::endl; // Now start two threads; each of these has their own ZeroMQ context. std::thread client_thread(client_task, std::ref(client_keypair), std::ref(server_keypair.public_key)); std::thread server_thread(server_task, std::ref(server_keypair), std::ref(client_public_keys)); // wait to finish client_thread.join(); server_thread.join(); } #endif BOOST_AUTO_TEST_SUITE_END() zmqpp-4.1.2/src/tests/test_context.cpp000066400000000000000000000030561254036632700200610ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * Created on: 9 Aug 2011 * Author: @benjamg */ #include #include "zmqpp/context.hpp" BOOST_AUTO_TEST_SUITE( context ) BOOST_AUTO_TEST_CASE( initialises ) { zmqpp::context context; BOOST_CHECK(context); } BOOST_AUTO_TEST_CASE( move_supporting ) { zmqpp::context first; BOOST_CHECK(first); zmqpp::context second( std::move(first) ); BOOST_CHECK(second); BOOST_CHECK(!first); } BOOST_AUTO_TEST_CASE( defaults ) { zmqpp::context context; BOOST_CHECK_GE(context.get(zmqpp::context_option::io_threads), ZMQ_IO_THREADS_DFLT); BOOST_CHECK_GE(context.get(zmqpp::context_option::max_sockets), ZMQ_MAX_SOCKETS_DFLT); } BOOST_AUTO_TEST_CASE( validaty ) { zmqpp::context context; BOOST_CHECK(context); context.terminate(); BOOST_CHECK(!context); BOOST_CHECK_THROW(context.get(zmqpp::context_option::io_threads), zmqpp::invalid_instance); } BOOST_AUTO_TEST_CASE( throws_exception ) { #if (ZMQ_VERSION_MAJOR < 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR < 2)) BOOST_CHECK_THROW(new zmqpp::context(-1), zmqpp::zmq_internal_exception); #else zmqpp::context context; BOOST_CHECK_THROW(context.set(zmqpp::context_option::io_threads, -1), zmqpp::zmq_internal_exception); #endif } BOOST_AUTO_TEST_SUITE_END() zmqpp-4.1.2/src/tests/test_inet.cpp000066400000000000000000000022371254036632700173340ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * Created on: 8 Aug 2011 * Author: @benjamg */ #include #include "zmqpp/inet.hpp" BOOST_AUTO_TEST_SUITE( inet ) BOOST_AUTO_TEST_CASE( swaping_64bit_byteorder ) { uint64_t host = 0x1122334455667788; uint64_t network = zmqpp::swap_if_needed(host); uint8_t* bytes = reinterpret_cast(&network); BOOST_CHECK_EQUAL(0x11, bytes[0]); BOOST_CHECK_EQUAL(0x22, bytes[1]); BOOST_CHECK_EQUAL(0x33, bytes[2]); BOOST_CHECK_EQUAL(0x44, bytes[3]); BOOST_CHECK_EQUAL(0x55, bytes[4]); BOOST_CHECK_EQUAL(0x66, bytes[5]); BOOST_CHECK_EQUAL(0x77, bytes[6]); BOOST_CHECK_EQUAL(0x88, bytes[7]); } BOOST_AUTO_TEST_CASE( swaping_64bit_reversable ) { uint64_t host = 0x1122334455667788; uint64_t network = zmqpp::swap_if_needed(host); BOOST_CHECK_EQUAL(host, zmqpp::swap_if_needed(network)); } BOOST_AUTO_TEST_SUITE_END() zmqpp-4.1.2/src/tests/test_load.cpp000066400000000000000000000077461254036632700173260ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * Created on: 12 Aug 2011 * Author: @benjamg */ #ifdef LOADTEST #include #include #include #include "zmqpp/zmqpp.hpp" BOOST_AUTO_TEST_SUITE( load ) // Number of messages to push const uint64_t messages = 1e7; // Short message to send const std::string short_message = "hello world!"; // Timeout for polling in milliseconds const long max_poll_timeout = 500; BOOST_AUTO_TEST_CASE( push_messages_baseline ) { boost::timer t; void* context = zmq_init(1); void* pusher = zmq_socket(context, ZMQ_PUSH); BOOST_REQUIRE_MESSAGE(0 == zmq_connect(pusher, "tcp://localhost:5555"), "connect: " << zmq_strerror(zmq_errno())); void* puller = zmq_socket(context, ZMQ_PULL); BOOST_REQUIRE_MESSAGE(0 == zmq_bind(puller, "tcp://*:5555"), "bind: " << zmq_strerror(zmq_errno())); auto pusher_func = [&pusher](void) { auto remaining = messages; do { #if (ZMQ_VERSION_MAJOR == 2) zmq_msg_t msg; zmq_msg_init_size(&msg, short_message.size()); memcpy(zmq_msg_data(&msg), short_message.data(), short_message.size()); zmq_send(pusher, &msg, 0); #else zmq_send(pusher, short_message.data(), short_message.size(), 0); #endif } while(--remaining > 0); }; zmq_pollitem_t item = { puller, 0, ZMQ_POLLIN, 0 }; boost::thread thread(pusher_func); uint64_t processed = 0; zmq_msg_t message; zmq_msg_init(&message); while(zmq_poll(&item, 1, max_poll_timeout) > 0) { BOOST_REQUIRE(item.revents & ZMQ_POLLIN); #if (ZMQ_VERSION_MAJOR == 2) zmq_recv(puller, &message, 0); #elif (ZMQ_VERSION_MAJOR < 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR < 2)) zmq_recvmsg(puller, &message, 0); #else zmq_msg_recv(&message, puller, 0); #endif BOOST_CHECK_EQUAL(0, strncmp(short_message.data(), static_cast(zmq_msg_data(&message)), short_message.size())); ++processed; } zmq_msg_close(&message); double elapsed_run = t.elapsed(); BOOST_CHECK_MESSAGE(thread.timed_join(boost::posix_time::milliseconds(max_poll_timeout)), "hung while joining pusher thread"); BOOST_CHECK_EQUAL(processed, messages); BOOST_TEST_MESSAGE("Baseline"); BOOST_TEST_MESSAGE("Messages pushed : " << processed); BOOST_TEST_MESSAGE("Run time : " << elapsed_run << " seconds"); BOOST_TEST_MESSAGE("Messages per second: " << processed / elapsed_run); BOOST_TEST_MESSAGE("\n"); zmq_close(pusher); zmq_close(puller); zmq_term(context); } BOOST_AUTO_TEST_CASE( push_messages ) { boost::timer t; zmqpp::context context; zmqpp::socket pusher(context, zmqpp::socket_type::push); pusher.connect("tcp://localhost:55555"); zmqpp::socket puller(context, zmqpp::socket_type::pull); puller.bind("tcp://*:55555"); auto pusher_func = [&pusher](void) { auto remaining = messages; zmqpp::message message; do { message.add(short_message); pusher.send(message); } while(--remaining > 0); }; zmqpp::poller poller; poller.add(puller); boost::thread thread(pusher_func); uint64_t processed = 0; std::string message; while(poller.poll(max_poll_timeout)) { BOOST_REQUIRE(poller.has_input(puller)); puller.receive(message); BOOST_CHECK_EQUAL(short_message, message); ++processed; } double elapsed_run = t.elapsed(); BOOST_CHECK_MESSAGE(thread.timed_join(boost::posix_time::milliseconds(max_poll_timeout)), "hung while joining pusher thread"); BOOST_CHECK_EQUAL(processed, messages); BOOST_TEST_MESSAGE("ZMQPP: Copy String"); BOOST_TEST_MESSAGE("Messages pushed : " << processed); BOOST_TEST_MESSAGE("Run time : " << elapsed_run << " seconds"); BOOST_TEST_MESSAGE("Messages per second: " << processed / elapsed_run); BOOST_TEST_MESSAGE("\n"); } BOOST_AUTO_TEST_SUITE_END() #endif // LOADTEST zmqpp-4.1.2/src/tests/test_message.cpp000066400000000000000000000300531254036632700200160ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * Created on: 9 Aug 2011 * Author: @benjamg */ #include #include #include #include #include #include "zmqpp/exception.hpp" #include "zmqpp/message.hpp" BOOST_AUTO_TEST_SUITE( message ) BOOST_AUTO_TEST_CASE( initialising ) { zmqpp::message message; BOOST_CHECK_EQUAL(0, message.parts()); } BOOST_AUTO_TEST_CASE( throws_exception_reading_invalid_part ) { zmqpp::message message; BOOST_CHECK_THROW(message.get(0), zmqpp::exception); } BOOST_AUTO_TEST_CASE( move_construction_supporting ) { std::string test; zmqpp::message first; first.add("string"); BOOST_CHECK_EQUAL(1, first.parts()); zmqpp::message second( std::move(first) ); BOOST_CHECK_EQUAL(1, second.parts()); BOOST_CHECK_EQUAL(0, first.parts()); // read cursor zmqpp::message boap; boap.add("string"); boap.add("string2"); boap >> test; BOOST_CHECK_EQUAL("string", test); zmqpp::message boap2( std::move(boap)); boap2 >> test; BOOST_CHECK_EQUAL("string2", test); } BOOST_AUTO_TEST_CASE( move_construction_supporting2 ) { std::string test; zmqpp::message first; first.add("string"); first.add("string2"); BOOST_CHECK_EQUAL(2, first.parts()); first >> test; zmqpp::message second( std::move(first) ); first.add("str"); first >> test; } BOOST_AUTO_TEST_CASE( move_assignment_supporting ) { zmqpp::message first; first.add("string"); zmqpp::message second; second.add("blah"); second = std::move(first); BOOST_CHECK_EQUAL(1, second.parts()); BOOST_CHECK_EQUAL(0, first.parts()); zmqpp::message boap; boap.add("string"); boap.add("string2"); std::string test; boap >> test; BOOST_CHECK_EQUAL("string", test); zmqpp::message boap2; boap2 = std::move(boap); boap2 >> test; BOOST_CHECK_EQUAL("string2", test); } BOOST_AUTO_TEST_CASE( move_assignment_supporting2 ) { std::string test; zmqpp::message first; first.add("string"); first.add("string2"); BOOST_CHECK_EQUAL(2, first.parts()); first >> test; BOOST_CHECK_EQUAL("string", test); zmqpp::message second; second = std::move(first); first.add("str"); first >> test; BOOST_CHECK_EQUAL("str", test); } BOOST_AUTO_TEST_CASE( copyable ) { zmqpp::message second; { zmqpp::message first; first.add("string"); BOOST_CHECK_EQUAL(1, first.parts()); second = first.copy(); } BOOST_REQUIRE_EQUAL(1, second.parts()); BOOST_CHECK_EQUAL(strlen("string"), second.size(0)); BOOST_CHECK_EQUAL("string", second.get(0)); } #ifndef ZMQPP_IGNORE_LAMBDA_FUNCTION_TESTS BOOST_AUTO_TEST_CASE( move_part ) { bool called = false; size_t data_size = 5; void* data = malloc(data_size); memset(data, 0, data_size); memcpy(data, "tests", strlen("tests")); auto release_func = [data, &called](void* val) { BOOST_CHECK_EQUAL(val, data); free(val); called = true; }; zmqpp::message* msg = new zmqpp::message(); msg->move(data, data_size, release_func); BOOST_REQUIRE_EQUAL(1, msg->parts()); BOOST_CHECK_EQUAL(strlen("tests"), msg->size(0)); BOOST_CHECK_EQUAL("tests", msg->get(0)); delete msg; BOOST_CHECK(called); } #endif BOOST_AUTO_TEST_CASE( copy_part ) { size_t data_size = strlen("tests"); void* data = malloc(data_size); memset(data, 0, data_size); memcpy(data, "tests", data_size); zmqpp::message* msg = new zmqpp::message(); msg->add_raw(data, data_size); BOOST_REQUIRE_EQUAL(1, msg->parts()); BOOST_CHECK_EQUAL(strlen("tests"), msg->size(0)); BOOST_CHECK_EQUAL("tests", msg->get(0)); delete msg; BOOST_CHECK_EQUAL("tests", std::string(static_cast(data), data_size)); free(data); } BOOST_AUTO_TEST_CASE( add_const_void ) { size_t data_size = strlen("tests"); void* data = malloc(data_size); memset(data, 0, data_size); memcpy(data, "tests", data_size); zmqpp::message* msg = new zmqpp::message(); msg->add_raw((void const*)data, data_size); BOOST_REQUIRE_EQUAL(1, msg->parts()); BOOST_CHECK_EQUAL(strlen("tests"), msg->size(0)); BOOST_CHECK_EQUAL("tests", msg->get(0)); delete msg; BOOST_CHECK_EQUAL("tests", std::string(static_cast(data), data_size)); free(data); } BOOST_AUTO_TEST_CASE( add_char_star ) { char data[] = "tests"; zmqpp::message* msg = new zmqpp::message(); msg->add_raw((char *)data, strlen(data)); BOOST_REQUIRE_EQUAL(1, msg->parts()); BOOST_CHECK_EQUAL(strlen("tests"), msg->size(0)); BOOST_CHECK_EQUAL("tests", msg->get(0)); delete msg; BOOST_CHECK_EQUAL("tests", std::string(static_cast(data), strlen(data))); } BOOST_AUTO_TEST_CASE( add_const_char_star ) { char data[] = "tests"; zmqpp::message* msg = new zmqpp::message(); msg->add_raw((char const *)data, strlen(data)); BOOST_REQUIRE_EQUAL(1, msg->parts()); BOOST_CHECK_EQUAL(strlen("tests"), msg->size(0)); BOOST_CHECK_EQUAL("tests", msg->get(0)); delete msg; BOOST_CHECK_EQUAL("tests", std::string(static_cast(data), strlen(data))); } BOOST_AUTO_TEST_CASE( add_char_literal_and_size_t ) { zmqpp::message* msg = new zmqpp::message(); msg->add_raw("tests", strlen("tests")); BOOST_REQUIRE_EQUAL(1, msg->parts()); BOOST_CHECK_EQUAL(strlen("tests"), msg->size(0)); BOOST_CHECK_EQUAL("tests", msg->get(0)); delete msg; } BOOST_AUTO_TEST_CASE( add_char_literal_and_number ) { zmqpp::message* msg = new zmqpp::message(); msg->add("tests", 45); BOOST_REQUIRE_EQUAL(2, msg->parts()); BOOST_CHECK_EQUAL(strlen("tests"), msg->size(0)); BOOST_CHECK_EQUAL("tests", msg->get(0)); BOOST_REQUIRE_EQUAL(sizeof(int), msg->size(1)); BOOST_CHECK_EQUAL(45, msg->get(1)); delete msg; } BOOST_AUTO_TEST_CASE( add_number ) { zmqpp::message* msg = new zmqpp::message(); msg->add(66); BOOST_REQUIRE_EQUAL(1, msg->parts()); BOOST_REQUIRE_EQUAL(sizeof(int), msg->size(0)); BOOST_CHECK_EQUAL(66, msg->get(0)); delete msg; } BOOST_AUTO_TEST_CASE( copy_part_string ) { zmqpp::message* msg = new zmqpp::message(); std::string part("tests"); msg->add(part); BOOST_REQUIRE_EQUAL(1, msg->parts()); BOOST_CHECK_EQUAL(strlen("tests"), msg->size(0)); BOOST_CHECK_EQUAL("tests", msg->get(0)); delete msg; BOOST_CHECK_EQUAL("tests", part); } BOOST_AUTO_TEST_CASE( multi_part_message ) { zmqpp::message message; message.add("this is the first part"); message.add("some other content here"); message.add("and finally"); BOOST_REQUIRE_EQUAL(3, message.parts()); BOOST_CHECK_EQUAL(strlen("this is the first part"), message.size(0)); BOOST_CHECK_EQUAL("this is the first part", message.get(0)); BOOST_CHECK_EQUAL(strlen("some other content here"), message.size(1)); BOOST_CHECK_EQUAL("some other content here", message.get(1)); BOOST_CHECK_EQUAL(strlen("and finally"), message.size(2)); BOOST_CHECK_EQUAL("and finally", message.get(2)); } BOOST_AUTO_TEST_CASE( stream_throws_exception ) { zmqpp::message message; std::string part; BOOST_CHECK_THROW(message >> part, zmqpp::exception); } BOOST_AUTO_TEST_CASE( stream_output_string ) { zmqpp::message message; message.add("part"); std::string part; message >> part; BOOST_CHECK_EQUAL("part", part); } BOOST_AUTO_TEST_CASE( stream_copy_input_c_string ) { zmqpp::message message; message << "test part"; BOOST_REQUIRE_EQUAL(1, message.parts()); BOOST_CHECK_EQUAL(strlen("test part"), message.size(0)); BOOST_CHECK_EQUAL("test part", message.get(0)); } BOOST_AUTO_TEST_CASE( stream_copy_input_string ) { const std::string part("test part"); zmqpp::message message; message << part; BOOST_CHECK_EQUAL("test part", part); BOOST_REQUIRE_EQUAL(1, message.parts()); BOOST_CHECK_EQUAL(strlen("test part"), message.size(0)); BOOST_CHECK_EQUAL("test part", message.get(0)); } BOOST_AUTO_TEST_CASE( stream_multiple_parts ) { zmqpp::message message; message << "test part"; message << 42; BOOST_REQUIRE_EQUAL(2, message.parts()); std::string part1; uint32_t part2; message >> part1; message >> part2; BOOST_CHECK_EQUAL("test part", part1); BOOST_CHECK_EQUAL(42, part2); } BOOST_AUTO_TEST_CASE( output_stream_resetable ) { zmqpp::message message; message << "test part"; std::string first; message >> first; BOOST_CHECK_EQUAL("test part", first); message.reset_read_cursor(); std::string second; message >> second; BOOST_CHECK_EQUAL("test part", second); } BOOST_AUTO_TEST_CASE( many_part_queue_check ) { std::array parts; for( size_t i = 0; i < parts.size(); i += 2 ) { parts[i] = "message frame " + boost::lexical_cast( i + 1 ); parts[i + 1] = "this part is a much longer test frame, message frame " + boost::lexical_cast( i + 2 ); } zmqpp::message message; for( size_t loop = 0; loop < parts.size(); ++loop ) { message << parts[loop]; for( size_t i = 0; i <= loop; ++i ) { BOOST_REQUIRE_MESSAGE( parts[i].compare( message.get(i) ) == 0, "invalid frame " << i << " on loop " << loop << ": '" << message.get(i) << "' != '" << parts[i] << "'" ); } } } BOOST_AUTO_TEST_CASE( reserve_zmq_frame ) { zmqpp::message message; zmq_msg_t& raw = message.raw_new_msg( strlen("hello world") ); void* data = zmq_msg_data( &raw ); memcpy( data, "hello world", strlen("hello world") ); BOOST_REQUIRE_EQUAL( 1, message.parts() ); BOOST_CHECK_EQUAL( "hello world", message.get(0) ); } BOOST_AUTO_TEST_CASE( push_end_of_frame_queue ) { std::array parts = {{ "test frame 1", "a much much longer test frame 2 to go over the small message size limitation" }}; zmqpp::message message; message.push_back( parts[0] ); message.push_back( parts[1] ); BOOST_REQUIRE_EQUAL( parts.size(), message.parts() ); for( size_t i = 0; i < parts.size(); ++i ) { BOOST_CHECK_EQUAL( parts[i].size(), message.size(i) ); BOOST_CHECK_EQUAL( parts[i], message.get(i) ); } } BOOST_AUTO_TEST_CASE( pop_end_of_frame_queue ) { std::array parts = {{ "a long test frame 1 to go over the small message size limitation", "another frame 2", "some final frame 3" }}; zmqpp::message message; message << parts[0] << parts[1] << parts[2]; BOOST_REQUIRE_EQUAL( parts.size(), message.parts() ); message.pop_back(); BOOST_REQUIRE_EQUAL( parts.size() - 1, message.parts() ); for( size_t i = 0; i < parts.size() - 1; ++i ) { BOOST_CHECK_EQUAL( parts[i].size(), message.size(i) ); BOOST_CHECK_EQUAL( parts[i], message.get(i) ); } } BOOST_AUTO_TEST_CASE( push_front_of_frame_queue ) { std::array parts = {{ "a long test frame 1 to go over the small message size limitation", "another frame 2", "some final frame 3" }}; zmqpp::message message; message << parts[1] << parts[2]; BOOST_REQUIRE_EQUAL( parts.size() - 1, message.parts() ); message.push_front( parts[0] ); BOOST_REQUIRE_EQUAL( parts.size(), message.parts() ); for( size_t i = 0; i < parts.size(); ++i ) { BOOST_CHECK_EQUAL( parts[i].size(), message.size(i) ); BOOST_CHECK_EQUAL( parts[i], message.get(i) ); } } BOOST_AUTO_TEST_CASE( pop_front_of_frame_queue ) { std::array parts = {{ "a long test frame 1 to go over the small message size limitation", "another frame 2", "some final frame 3" }}; zmqpp::message message; message << parts[0] << parts[1] << parts[2]; BOOST_REQUIRE_EQUAL( parts.size(), message.parts() ); message.pop_front(); BOOST_REQUIRE_EQUAL( parts.size() - 1, message.parts() ); for( size_t i = 0; i < parts.size() - 1; ++i ) { BOOST_CHECK_EQUAL( parts[i + 1].size(), message.size(i) ); BOOST_CHECK_EQUAL( parts[i + 1], message.get(i) ); } } BOOST_AUTO_TEST_CASE( add_const_part ) { size_t data_size = strlen("tests"); void* data = malloc(data_size); memset(data, 0, data_size); memcpy(data, "tests", data_size); zmqpp::message* msg = new zmqpp::message(); msg->add_const(data, data_size); BOOST_REQUIRE_EQUAL(1, msg->parts()); BOOST_CHECK_EQUAL(strlen("tests"), msg->size(0)); BOOST_CHECK_EQUAL("tests", msg->get(0)); delete msg; BOOST_CHECK_EQUAL("tests", std::string(static_cast(data), data_size)); free(data); } BOOST_AUTO_TEST_SUITE_END() zmqpp-4.1.2/src/tests/test_message_stream.cpp000066400000000000000000000114621254036632700213740ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * Created on: 10 Aug 2011 * Author: @benjmag */ #include #include "zmqpp/message.hpp" BOOST_AUTO_TEST_SUITE( message_stream ) BOOST_AUTO_TEST_CASE( stream_bool ) { bool input_value = true; bool output_value = false; zmqpp::message message; message << input_value; BOOST_REQUIRE_EQUAL(1, message.parts()); BOOST_CHECK_EQUAL(1, message.size(0)); unsigned char const* data = static_cast(message.raw_data(0)); BOOST_CHECK_EQUAL(1, data[0]); message >> output_value; BOOST_CHECK_EQUAL(input_value, output_value); } BOOST_AUTO_TEST_CASE( stream_float ) { float input_value = 3.14f; float output_value = 0.0f; zmqpp::message message; message << input_value; BOOST_REQUIRE_EQUAL(1, message.parts()); BOOST_CHECK_EQUAL(sizeof(input_value), message.size(0)); message >> output_value; BOOST_CHECK_EQUAL(input_value, output_value); } BOOST_AUTO_TEST_CASE( stream_double ) { double input_value = 3.14; double output_value = 0.0; zmqpp::message message; message << input_value; BOOST_REQUIRE_EQUAL(1, message.parts()); BOOST_CHECK_EQUAL(sizeof(input_value), message.size(0)); message >> output_value; BOOST_CHECK_EQUAL(input_value, output_value); } BOOST_AUTO_TEST_CASE( stream_int8 ) { int8_t input_value = -42; int8_t output_value = 0; zmqpp::message message; message << input_value; BOOST_REQUIRE_EQUAL(1, message.parts()); BOOST_CHECK_EQUAL(1, message.size(0)); unsigned char const* data = static_cast(message.raw_data(0)); BOOST_CHECK_EQUAL(0xD6, data[0]); message >> output_value; BOOST_CHECK_EQUAL(input_value, output_value); } BOOST_AUTO_TEST_CASE( stream_int16 ) { int16_t input_value = 512; int16_t output_value = 0; zmqpp::message message; message << input_value; BOOST_REQUIRE_EQUAL(1, message.parts()); BOOST_CHECK_EQUAL(2, message.size(0)); unsigned char const* data = static_cast(message.raw_data(0)); BOOST_CHECK_EQUAL(0x02, data[0]); BOOST_CHECK_EQUAL(0x00, data[1]); message >> output_value; BOOST_CHECK_EQUAL(input_value, output_value); } BOOST_AUTO_TEST_CASE( stream_int32 ) { int32_t input_value = -19088744; //0xfedcba98 int32_t output_value = 0; zmqpp::message message; message << input_value; BOOST_REQUIRE_EQUAL(1, message.parts()); BOOST_CHECK_EQUAL(4, message.size(0)); unsigned char const* data = static_cast(message.raw_data(0)); BOOST_CHECK_EQUAL(0xFE, data[0]); BOOST_CHECK_EQUAL(0xDC, data[1]); BOOST_CHECK_EQUAL(0xBA, data[2]); BOOST_CHECK_EQUAL(0x98, data[3]); message >> output_value; BOOST_CHECK_EQUAL(input_value, output_value); } BOOST_AUTO_TEST_CASE( stream_int64 ) { int64_t input_value = 1234; int64_t output_value = 0; zmqpp::message message; message << input_value; BOOST_REQUIRE_EQUAL(1, message.parts()); BOOST_CHECK_EQUAL(8, message.size(0)); unsigned char const* data = static_cast(message.raw_data(0)); BOOST_CHECK_EQUAL(0x00, data[0]); BOOST_CHECK_EQUAL(0x00, data[1]); BOOST_CHECK_EQUAL(0x00, data[2]); BOOST_CHECK_EQUAL(0x00, data[3]); BOOST_CHECK_EQUAL(0x00, data[4]); BOOST_CHECK_EQUAL(0x00, data[5]); BOOST_CHECK_EQUAL(0x04, data[6]); BOOST_CHECK_EQUAL(0xD2, data[7]); message >> output_value; BOOST_CHECK_EQUAL(input_value, output_value); } BOOST_AUTO_TEST_CASE( stream_uint8 ) { uint8_t input_value = 1; uint8_t output_value = 0; zmqpp::message message; message << input_value; BOOST_REQUIRE_EQUAL(1, message.parts()); BOOST_CHECK_EQUAL(1, message.size(0)); message >> output_value; BOOST_CHECK_EQUAL(input_value, output_value); } BOOST_AUTO_TEST_CASE( stream_uint16 ) { uint16_t input_value = 12; uint16_t output_value = 0; zmqpp::message message; message << input_value; BOOST_REQUIRE_EQUAL(1, message.parts()); BOOST_CHECK_EQUAL(2, message.size(0)); message >> output_value; BOOST_CHECK_EQUAL(input_value, output_value); } BOOST_AUTO_TEST_CASE( stream_uint32 ) { uint32_t input_value = 123; uint32_t output_value = 0; zmqpp::message message; message << input_value; BOOST_REQUIRE_EQUAL(1, message.parts()); BOOST_CHECK_EQUAL(4, message.size(0)); message >> output_value; BOOST_CHECK_EQUAL(input_value, output_value); } BOOST_AUTO_TEST_CASE( stream_uint64 ) { uint64_t input_value = 1234; uint64_t output_value = 0; zmqpp::message message; message << input_value; BOOST_REQUIRE_EQUAL(1, message.parts()); BOOST_CHECK_EQUAL(8, message.size(0)); message >> output_value; BOOST_CHECK_EQUAL(input_value, output_value); } BOOST_AUTO_TEST_SUITE_END() zmqpp-4.1.2/src/tests/test_poller.cpp000066400000000000000000000133061254036632700176710ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * Created on: 12 Aug 2011 * Author: @benjamg */ #include #include "zmqpp/context.hpp" #include "zmqpp/message.hpp" #include "zmqpp/poller.hpp" #include "zmqpp/socket.hpp" BOOST_AUTO_TEST_SUITE( poll ) const int max_poll_timeout = 100; BOOST_AUTO_TEST_CASE( initialise ) { zmqpp::context context; zmqpp::socket socket(context, zmqpp::socket_type::pull); socket.bind("inproc://test"); zmqpp::poller poller; poller.add(socket); BOOST_CHECK_EQUAL(zmqpp::poller::poll_none, poller.events(socket)); BOOST_CHECK(!poller.has_input(socket)); BOOST_CHECK(!poller.has_output(socket)); BOOST_CHECK(!poller.has_error(socket)); } BOOST_AUTO_TEST_CASE( simple_pull_push ) { zmqpp::context context; zmqpp::socket puller(context, zmqpp::socket_type::pull); puller.bind("inproc://test"); zmqpp::socket pusher(context, zmqpp::socket_type::push); pusher.connect("inproc://test"); BOOST_CHECK(pusher.send_raw("hello world!", sizeof("hello world!"))); zmqpp::poller poller; poller.add(puller); BOOST_CHECK(poller.poll(max_poll_timeout)); BOOST_CHECK_EQUAL(zmqpp::poller::poll_in, poller.events(puller)); BOOST_CHECK(poller.has_input(puller)); std::string message; BOOST_CHECK(puller.receive(message)); BOOST_CHECK_EQUAL("hello world!", message.c_str()); BOOST_CHECK(!puller.has_more_parts()); } BOOST_AUTO_TEST_CASE( multi_socket_poll ) { zmqpp::context context; zmqpp::socket puller1(context, zmqpp::socket_type::pull); puller1.bind("inproc://test1"); zmqpp::socket puller2(context, zmqpp::socket_type::pull); puller2.bind("inproc://test2"); zmqpp::socket puller3(context, zmqpp::socket_type::pull); puller3.bind("inproc://test3"); zmqpp::socket pusher(context, zmqpp::socket_type::push); pusher.connect("inproc://test1"); BOOST_CHECK(pusher.send("hello world!")); zmqpp::poller poller; poller.add(puller1); poller.add(puller2); poller.add(puller3); BOOST_CHECK(poller.poll(max_poll_timeout)); BOOST_CHECK_EQUAL(zmqpp::poller::poll_in, poller.events(puller1)); BOOST_CHECK(poller.has_input(puller1)); BOOST_CHECK(!poller.has_output(puller1)); BOOST_CHECK(!poller.has_error(puller1)); BOOST_CHECK_EQUAL(zmqpp::poller::poll_none, poller.events(puller2)); BOOST_CHECK(!poller.has_input(puller2)); BOOST_CHECK(!poller.has_output(puller2)); BOOST_CHECK(!poller.has_error(puller2)); BOOST_CHECK_EQUAL(zmqpp::poller::poll_none, poller.events(puller3)); BOOST_CHECK(!poller.has_input(puller3)); BOOST_CHECK(!poller.has_output(puller3)); BOOST_CHECK(!poller.has_error(puller3)); std::string message; BOOST_CHECK(puller1.receive(message)); BOOST_CHECK_EQUAL("hello world!", message); BOOST_CHECK(!puller1.has_more_parts()); } BOOST_AUTO_TEST_CASE( throws_exception_unknown_socket ) { zmqpp::context context; zmqpp::socket puller(context, zmqpp::socket_type::pull); puller.bind("inproc://test"); zmqpp::socket pusher(context, zmqpp::socket_type::push); pusher.connect("inproc://test"); zmqpp::poller poller; poller.add(puller); BOOST_CHECK_THROW(poller.events(pusher), zmqpp::exception); } BOOST_AUTO_TEST_CASE( ignores_removed_sockets ) { zmqpp::context context; zmqpp::socket puller1(context, zmqpp::socket_type::pull); puller1.bind("inproc://test1"); zmqpp::socket puller2(context, zmqpp::socket_type::pull); puller2.bind("inproc://test2"); zmqpp::socket pusher(context, zmqpp::socket_type::push); pusher.connect("inproc://test1"); BOOST_CHECK(pusher.send("hello world!")); zmqpp::poller poller; poller.add(puller1); poller.add(puller2); poller.remove(puller1); BOOST_CHECK(!poller.poll(max_poll_timeout)); BOOST_CHECK_EQUAL(zmqpp::poller::poll_none, poller.events(puller2)); BOOST_CHECK(!poller.has_input(puller2)); BOOST_CHECK(!poller.has_output(puller2)); BOOST_CHECK(!poller.has_error(puller2)); std::string message; BOOST_CHECK(puller1.receive(message)); BOOST_CHECK_EQUAL("hello world!", message); BOOST_CHECK(!puller1.has_more_parts()); } BOOST_AUTO_TEST_CASE( remove_maintains_index ) { zmqpp::context context; zmqpp::socket puller1(context, zmqpp::socket_type::pull); puller1.bind("inproc://test1"); zmqpp::socket puller2(context, zmqpp::socket_type::pull); puller2.bind("inproc://test2"); zmqpp::socket puller3(context, zmqpp::socket_type::pull); puller3.bind("inproc://test3"); zmqpp::socket pusher(context, zmqpp::socket_type::push); pusher.connect("inproc://test1"); BOOST_CHECK(pusher.send("hello world!")); zmqpp::poller poller; poller.add(puller1); poller.add(puller2); poller.add(puller3); poller.remove(puller1); // removing last puller will die if index has not been updated poller.remove(puller3); BOOST_CHECK(!poller.poll(max_poll_timeout)); BOOST_CHECK_EQUAL(zmqpp::poller::poll_none, poller.events(puller2)); BOOST_CHECK(!poller.has_input(puller2)); BOOST_CHECK(!poller.has_output(puller2)); BOOST_CHECK(!poller.has_error(puller2)); std::string message; BOOST_CHECK(puller1.receive(message)); BOOST_CHECK_EQUAL("hello world!", message); BOOST_CHECK(!puller1.has_more_parts()); } BOOST_AUTO_TEST_CASE( exceptions_testing_removed_sockets ) { zmqpp::context context; zmqpp::socket pusher(context, zmqpp::socket_type::push); pusher.bind("inproc://test1"); zmqpp::poller poller; // Has no events when added poller.add(pusher); BOOST_CHECK(!poller.events(pusher)); // Exception after removed poller.remove(pusher); BOOST_CHECK_THROW(poller.events(pusher), zmqpp::exception); } BOOST_AUTO_TEST_SUITE_END() zmqpp-4.1.2/src/tests/test_reactor.cpp000066400000000000000000000103211254036632700200250ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ #include #include #include "zmqpp/context.hpp" #include "zmqpp/message.hpp" #include "zmqpp/reactor.hpp" #include "zmqpp/socket.hpp" BOOST_AUTO_TEST_SUITE( reactor ) const int max_poll_timeout = 100; BOOST_AUTO_TEST_CASE(initialise) { zmqpp::context context; zmqpp::socket socket(context, zmqpp::socket_type::pull); socket.bind("inproc://test"); zmqpp::reactor reactor; reactor.add(socket, []()->void { }); BOOST_CHECK_EQUAL(zmqpp::poller::poll_none, reactor.events(socket)); } BOOST_AUTO_TEST_CASE(simple_pull_push) { zmqpp::context context; zmqpp::socket puller(context, zmqpp::socket_type::pull); puller.bind("inproc://test"); zmqpp::socket pusher(context, zmqpp::socket_type::push); pusher.connect("inproc://test"); BOOST_CHECK(pusher.send_raw("hello world!", sizeof ("hello world!"))); zmqpp::reactor reactor; int test = 0; auto callable = [&test]() -> void { test = 1; }; reactor.add(puller, callable); BOOST_CHECK(reactor.poll(max_poll_timeout)); BOOST_CHECK_EQUAL(1, test); BOOST_CHECK_EQUAL(zmqpp::poller::poll_in, reactor.events(puller)); std::string message; BOOST_CHECK(puller.receive(message)); BOOST_CHECK_EQUAL("hello world!", message.c_str()); BOOST_CHECK(!puller.has_more_parts()); } BOOST_AUTO_TEST_CASE(multiple_socket) { zmqpp::context context; zmqpp::socket pub(context, zmqpp::socket_type::pub); pub.bind("inproc://test"); zmqpp::socket sub(context, zmqpp::socket_type::sub); sub.connect("inproc://test"); sub.subscribe("hello"); zmqpp::socket sub2(context, zmqpp::socket_type::sub); sub2.connect("inproc://test"); sub2.subscribe("hello"); BOOST_CHECK(pub.send("hello", zmqpp::socket::send_more)); BOOST_CHECK(pub.send("hello world!")); zmqpp::reactor reactor; int test1 = 0; int test2 = 0; int test3 = 0; auto callable = [](int *value_to_update, int val) -> void { *value_to_update = val; }; reactor.add(sub, std::bind(callable, &test1, 1)); reactor.add(sub2, std::bind(callable, &test2, 2)); reactor.add(pub, std::bind(callable, &test3, 3), zmqpp::poller::poll_out); BOOST_CHECK(reactor.poll(max_poll_timeout)); BOOST_CHECK_EQUAL(1, test1); BOOST_CHECK_EQUAL(2, test2); BOOST_CHECK_EQUAL(3, test3); test1 = 0; test2 = 0; test3 = 0; reactor.remove(sub); BOOST_CHECK(pub.send("hello", zmqpp::socket::send_more)); BOOST_CHECK(pub.send("hello world!")); BOOST_CHECK(reactor.poll(max_poll_timeout)); BOOST_CHECK_EQUAL(0, test1); BOOST_CHECK_EQUAL(2, test2); BOOST_CHECK_EQUAL(3, test3); } BOOST_AUTO_TEST_CASE(remove_socket_in_handler) { zmqpp::context context; zmqpp::socket pub(context, zmqpp::socket_type::pub); pub.bind("inproc://test"); zmqpp::socket sub(context, zmqpp::socket_type::sub); sub.connect("inproc://test"); sub.subscribe("hello"); zmqpp::socket sub2(context, zmqpp::socket_type::sub); sub2.connect("inproc://test"); sub2.subscribe("hello"); BOOST_CHECK(pub.send("hello", zmqpp::socket::send_more)); BOOST_CHECK(pub.send("hello world!")); zmqpp::reactor reactor; int test1 = 0; int test2 = 0; auto callable = [&](int *value_to_update, int val) -> void { if (val == 1) { reactor.remove(sub); } *value_to_update = val; }; reactor.add(sub, std::bind(callable, &test1, 1)); reactor.add(sub2, std::bind(callable, &test2, 2)); BOOST_CHECK(reactor.poll(max_poll_timeout)); BOOST_CHECK_EQUAL(1, test1); BOOST_CHECK_EQUAL(2, test2); test1 = test2 = 0; BOOST_CHECK(pub.send("hello", zmqpp::socket::send_more)); BOOST_CHECK(pub.send("hello world!")); BOOST_CHECK(reactor.poll(max_poll_timeout)); BOOST_CHECK_EQUAL(0, test1); BOOST_CHECK_EQUAL(2, test2); } BOOST_AUTO_TEST_SUITE_END() zmqpp-4.1.2/src/tests/test_sanity.cpp000066400000000000000000000061131254036632700177010ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * Created on: 8 Aug 2011 * Author: @benjamg */ // Module definition should only be in one of the tests #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE zmqpp #include #include #include #include #include const int max_poll_timeout = 1000; BOOST_AUTO_TEST_SUITE( sanity ) BOOST_AUTO_TEST_CASE( correct_zmq_version ) { int major, minor, patch; zmq_version(&major, &minor, &patch); BOOST_CHECK_LE( ZMQPP_REQUIRED_ZMQ_MAJOR, major ); if(ZMQPP_REQUIRED_ZMQ_MAJOR == major) { BOOST_CHECK_LE( ZMQPP_REQUIRED_ZMQ_MINOR, minor ); } } BOOST_AUTO_TEST_CASE( correct_zmqpp_version ) { uint8_t major, minor, patch; zmqpp::version(major, minor, patch); BOOST_CHECK_EQUAL( ZMQPP_VERSION_MAJOR, major ); BOOST_CHECK_EQUAL( ZMQPP_VERSION_MINOR, minor ); BOOST_CHECK_EQUAL( ZMQPP_VERSION_REVISION, patch ); } BOOST_AUTO_TEST_CASE( same_zmq_version_as_built_against ) { uint8_t major, minor, patch; zmqpp::zmq_version(major, minor, patch); BOOST_CHECK_EQUAL( ZMQ_VERSION_MAJOR, major ); BOOST_CHECK_EQUAL( ZMQ_VERSION_MINOR, minor ); BOOST_CHECK_EQUAL( ZMQ_VERSION_PATCH, patch ); } BOOST_AUTO_TEST_CASE( zmq_basic_push_pull ) { std::string data = "hello world!"; void* context = zmq_init(1); void* puller = zmq_socket(context, ZMQ_PULL); zmq_bind(puller, "inproc://test"); void* pusher = zmq_socket(context, ZMQ_PUSH); zmq_connect(pusher, "inproc://test"); #if (ZMQ_VERSION_MAJOR == 2) zmq_msg_t sent_message; zmq_msg_init_size(&sent_message, data.size()); memcpy(zmq_msg_data(&sent_message), data.data(), data.size()); BOOST_CHECK_EQUAL(0, zmq_send(pusher, &sent_message, 0)); #else BOOST_CHECK_EQUAL(data.size(), zmq_send(pusher, data.data(), data.size(), 0)); #endif zmq_pollitem_t items[] = { { puller, 0, ZMQ_POLLIN, 0 } }; BOOST_CHECK_EQUAL(1, zmq_poll(items, 1, max_poll_timeout)); zmq_msg_t received_message; zmq_msg_init(&received_message); #if (ZMQ_VERSION_MAJOR == 2) zmq_recv(puller, &received_message, 0); BOOST_CHECK_EQUAL(static_cast(zmq_msg_data(&received_message)), data.c_str()); zmq_msg_close(&sent_message); zmq_msg_close(&received_message); #else std::array buffer; memset(buffer.data(), 0, buffer.size()); zmq_recv(puller, buffer.data(), buffer.size(), 0); BOOST_CHECK_EQUAL(buffer.data(), data.c_str()); #endif zmq_close(pusher); zmq_close(puller); zmq_term(context); } BOOST_AUTO_TEST_CASE( zmq_basic_options ) { std::string data = "hello world!"; void* context = zmq_init(1); void* socket = zmq_socket(context, ZMQ_SUB); zmq_bind(socket, "inproc://test"); int value; size_t value_size = sizeof(value); BOOST_CHECK_EQUAL(0, zmq_getsockopt(socket, ZMQ_TYPE, &value, &value_size)); BOOST_CHECK_EQUAL(ZMQ_SUB, value); } BOOST_AUTO_TEST_SUITE_END() zmqpp-4.1.2/src/tests/test_socket.cpp000066400000000000000000000371011254036632700176630ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * Created on: 8 Aug 2011 * Author: @benjamg */ #include #include #include #include #include #include "zmqpp/context.hpp" #include "zmqpp/socket.hpp" #include "zmqpp/message.hpp" #include "zmqpp/signal.hpp" BOOST_AUTO_TEST_SUITE( socket ) const int bubble_poll_timeout = 1; const int max_poll_timeout = 100; void bubble_subscriptions(zmqpp::socket& socket) { zmq_pollitem_t item = { socket, 0, ZMQ_POLLIN, 0 }; int result = zmq_poll(&item, 1, bubble_poll_timeout); BOOST_REQUIRE_MESSAGE(0 == result, "polling command failed to timeout during subscription bubble"); } void wait_for_socket(zmqpp::socket& socket) { zmq_pollitem_t item = { socket, 0, ZMQ_POLLIN, 0 }; int result = zmq_poll(&item, 1, max_poll_timeout); BOOST_REQUIRE_MESSAGE(result >= 0, "polling command returned without expected value: " << zmq_strerror(zmq_errno())); BOOST_REQUIRE_MESSAGE(0 != result, "polling command returned with timeout after " << max_poll_timeout << " milliseconds"); BOOST_REQUIRE_MESSAGE(1 == result, "polling command claims " << result << " sockets have events but we only gave it one"); BOOST_REQUIRE_MESSAGE(item.revents & ZMQ_POLLIN, "events do not match expected POLLIN event: " << item.revents); } BOOST_AUTO_TEST_CASE( socket_creation ) { zmqpp::context context; zmqpp::socket socket(context, zmqpp::socket_type::pull); } BOOST_AUTO_TEST_CASE( socket_creation_bad_type ) { zmqpp::context context; BOOST_CHECK_THROW(zmqpp::socket socket(context, static_cast(-1)), zmqpp::zmq_internal_exception) } BOOST_AUTO_TEST_CASE( valid_socket ) { zmqpp::context context; zmqpp::socket socket(context, zmqpp::socket_type::pull); socket.bind("inproc://test"); zmqpp::message message; BOOST_CHECK(!socket.receive(message, true)); } BOOST_AUTO_TEST_CASE( valid_move_supporting ) { zmqpp::context context; std::unique_ptr original(new zmqpp::socket(context, zmqpp::socket_type::pull)); original->bind("inproc://test"); zmqpp::socket clone(std::move(*original)); //original.reset(); zmqpp::message message; BOOST_CHECK(!clone.receive(message, true)); } BOOST_AUTO_TEST_CASE( simple_pull_push ) { zmqpp::context context; zmqpp::socket puller(context, zmqpp::socket_type::pull); puller.bind("inproc://test"); zmqpp::socket pusher(context, zmqpp::socket_type::push); pusher.connect("inproc://test"); BOOST_CHECK(pusher.send("hello world!")); wait_for_socket(puller); std::string message; BOOST_CHECK(puller.receive(message)); BOOST_CHECK_EQUAL("hello world!", message); BOOST_CHECK(!puller.has_more_parts()); } BOOST_AUTO_TEST_CASE( multipart_pair ) { zmqpp::context context; zmqpp::socket alpha(context, zmqpp::socket_type::pair); alpha.bind("inproc://test"); zmqpp::socket omega(context, zmqpp::socket_type::pair); omega.connect("inproc://test"); BOOST_CHECK(alpha.send("hello", zmqpp::socket::send_more)); BOOST_CHECK(alpha.send("world", zmqpp::socket::send_more)); BOOST_CHECK(alpha.send("!")); wait_for_socket(omega); std::string message; BOOST_CHECK(omega.receive(message)); BOOST_CHECK_EQUAL("hello", message); BOOST_REQUIRE(omega.has_more_parts()); BOOST_CHECK(omega.receive(message)); BOOST_CHECK_EQUAL("world", message); BOOST_REQUIRE(omega.has_more_parts()); BOOST_CHECK(omega.receive(message)); BOOST_CHECK_EQUAL("!", message); BOOST_CHECK(!omega.has_more_parts()); } BOOST_AUTO_TEST_CASE( subscribe_via_option ) { zmqpp::context context; zmqpp::socket publisher(context, zmqpp::socket_type::publish); publisher.bind("inproc://test"); zmqpp::socket subscriber(context, zmqpp::socket_type::subscribe); subscriber.connect("inproc://test"); subscriber.set(zmqpp::socket_option::subscribe, "watch1"); BOOST_CHECK(publisher.send("watch0", zmqpp::socket::send_more)); BOOST_CHECK(publisher.send("contents0")); BOOST_CHECK(publisher.send("watch1", zmqpp::socket::send_more)); BOOST_CHECK(publisher.send("contents1")); wait_for_socket(subscriber); std::string message; BOOST_CHECK(subscriber.receive(message)); BOOST_CHECK_EQUAL("watch1", message); BOOST_REQUIRE(subscriber.has_more_parts()); BOOST_CHECK(subscriber.receive(message)); BOOST_CHECK_EQUAL("contents1", message); BOOST_CHECK(!subscriber.has_more_parts()); } BOOST_AUTO_TEST_CASE( subscribe_helpers ) { zmqpp::context context; zmqpp::socket publisher(context, zmqpp::socket_type::publish); publisher.bind("inproc://test"); zmqpp::socket subscriber(context, zmqpp::socket_type::subscribe); subscriber.connect("inproc://test"); subscriber.subscribe("watch1"); subscriber.subscribe("watch2"); BOOST_CHECK(publisher.send("watch0", zmqpp::socket::send_more)); BOOST_CHECK(publisher.send("contents0")); BOOST_CHECK(publisher.send("watch1", zmqpp::socket::send_more)); BOOST_CHECK(publisher.send("contents1")); BOOST_CHECK(publisher.send("watch2", zmqpp::socket::send_more)); BOOST_CHECK(publisher.send("contents2")); BOOST_CHECK(publisher.send("watch3", zmqpp::socket::send_more)); BOOST_CHECK(publisher.send("contents3")); wait_for_socket(subscriber); std::string message; BOOST_CHECK(subscriber.receive(message)); BOOST_CHECK_EQUAL("watch1", message); BOOST_REQUIRE(subscriber.has_more_parts()); BOOST_CHECK(subscriber.receive(message)); BOOST_CHECK_EQUAL("contents1", message); BOOST_CHECK(!subscriber.has_more_parts()); wait_for_socket(subscriber); BOOST_CHECK(subscriber.receive(message)); BOOST_CHECK_EQUAL("watch2", message); BOOST_REQUIRE(subscriber.has_more_parts()); BOOST_CHECK(subscriber.receive(message)); BOOST_CHECK_EQUAL("contents2", message); BOOST_CHECK(!subscriber.has_more_parts()); subscriber.unsubscribe("watch1"); bubble_subscriptions(subscriber); BOOST_CHECK(publisher.send("watch0", zmqpp::socket::send_more)); BOOST_CHECK(publisher.send("contents0")); BOOST_CHECK(publisher.send("watch1", zmqpp::socket::send_more)); BOOST_CHECK(publisher.send("contents1")); BOOST_CHECK(publisher.send("watch2", zmqpp::socket::send_more)); BOOST_CHECK(publisher.send("contents2")); wait_for_socket(subscriber); BOOST_CHECK(subscriber.receive(message)); BOOST_CHECK_EQUAL("watch2", message); BOOST_REQUIRE(subscriber.has_more_parts()); BOOST_CHECK(subscriber.receive(message)); BOOST_CHECK_EQUAL("contents2", message); BOOST_CHECK(!subscriber.has_more_parts()); } BOOST_AUTO_TEST_CASE( subscribe_helpers_multitopic_method ) { std::list topics = { "watch1", "watch2" }; zmqpp::context context; zmqpp::socket publisher(context, zmqpp::socket_type::publish); publisher.bind("inproc://test"); zmqpp::socket subscriber(context, zmqpp::socket_type::subscribe); subscriber.connect("inproc://test"); subscriber.subscribe(topics.begin(), topics.end()); BOOST_CHECK(publisher.send("watch0", zmqpp::socket::send_more)); BOOST_CHECK(publisher.send("contents0")); BOOST_CHECK(publisher.send("watch1", zmqpp::socket::send_more)); BOOST_CHECK(publisher.send("contents1")); BOOST_CHECK(publisher.send("watch2", zmqpp::socket::send_more)); BOOST_CHECK(publisher.send("contents2")); BOOST_CHECK(publisher.send("watch3", zmqpp::socket::send_more)); BOOST_CHECK(publisher.send("contents3")); wait_for_socket(subscriber); std::string message; BOOST_CHECK(subscriber.receive(message)); BOOST_CHECK_EQUAL("watch1", message); BOOST_REQUIRE(subscriber.has_more_parts()); BOOST_CHECK(subscriber.receive(message)); BOOST_CHECK_EQUAL("contents1", message); BOOST_CHECK(!subscriber.has_more_parts()); wait_for_socket(subscriber); BOOST_CHECK(subscriber.receive(message)); BOOST_CHECK_EQUAL("watch2", message); BOOST_REQUIRE(subscriber.has_more_parts()); BOOST_CHECK(subscriber.receive(message)); BOOST_CHECK_EQUAL("contents2", message); BOOST_CHECK(!subscriber.has_more_parts()); } BOOST_AUTO_TEST_CASE( sending_messages ) { zmqpp::context context; zmqpp::socket pusher(context, zmqpp::socket_type::push); pusher.bind("inproc://test"); zmqpp::socket puller(context, zmqpp::socket_type::pull); puller.connect("inproc://test"); zmqpp::message message; std::string part("another world"); message.add("hello world!"); message.add(part); pusher.send(message); BOOST_CHECK_EQUAL(0, message.parts()); wait_for_socket(puller); BOOST_CHECK(puller.receive(part)); BOOST_CHECK_EQUAL("hello world!", part); BOOST_REQUIRE(puller.has_more_parts()); BOOST_CHECK(puller.receive(part)); BOOST_CHECK_EQUAL("another world", part); BOOST_CHECK(!puller.has_more_parts()); } BOOST_AUTO_TEST_CASE( receiving_messages ) { zmqpp::context context; zmqpp::socket pusher(context, zmqpp::socket_type::push); pusher.bind("inproc://test"); zmqpp::socket puller(context, zmqpp::socket_type::pull); puller.connect("inproc://test"); zmqpp::message message; std::string part("another world"); message.add("hello world!"); message.add(part); pusher.send(message); BOOST_CHECK_EQUAL(0, message.parts()); wait_for_socket(puller); BOOST_CHECK(puller.receive(message)); BOOST_REQUIRE_EQUAL(2, message.parts()); BOOST_CHECK_EQUAL("hello world!", message.get(0)); BOOST_CHECK_EQUAL("another world", message.get(1)); BOOST_CHECK(!puller.has_more_parts()); } BOOST_AUTO_TEST_CASE( receive_over_old_messages ) { zmqpp::context context; zmqpp::socket pusher( context, zmqpp::socket_type::push ); pusher.bind( "inproc://test" ); zmqpp::socket puller( context, zmqpp::socket_type::pull ); puller.connect( "inproc://test"); pusher.send( "first message" ); pusher.send( "second message" ); wait_for_socket( puller ); zmqpp::message message; BOOST_CHECK( puller.receive( message ) ); BOOST_REQUIRE_EQUAL( 1, message.parts() ); BOOST_CHECK_EQUAL( "first message", message.get(0) ); BOOST_CHECK( puller.receive( message ) ); BOOST_REQUIRE_EQUAL( 1, message.parts() ); BOOST_CHECK_EQUAL( "second message", message.get(0) ); } BOOST_AUTO_TEST_CASE( cleanup_safe_with_pending_data ) { zmqpp::context context; zmqpp::socket pusher(context, zmqpp::socket_type::push); pusher.bind("inproc://test"); zmqpp::socket puller(context, zmqpp::socket_type::pull); puller.connect("inproc://test"); zmqpp::message message; std::string part("another world"); message.add("hello world!"); message.add(part); pusher.send(message); BOOST_CHECK_EQUAL(0, message.parts()); } BOOST_AUTO_TEST_CASE( multitarget_puller ) { std::vector endpoints = { "inproc://test1", "inproc://test2" }; zmqpp::context context; zmqpp::socket pusher1(context, zmqpp::socket_type::push); pusher1.bind(endpoints[0]); zmqpp::socket pusher2(context, zmqpp::socket_type::push); pusher2.bind(endpoints[1]); zmqpp::socket puller(context, zmqpp::socket_type::pull); puller.connect(endpoints.begin(), endpoints.end()); BOOST_CHECK(pusher1.send("hello world!")); BOOST_CHECK(pusher2.send("a test message")); wait_for_socket(puller); std::string message; BOOST_CHECK(puller.receive(message)); BOOST_CHECK_EQUAL("hello world!", message); BOOST_CHECK(puller.receive(message)); BOOST_CHECK_EQUAL("a test message", message); } BOOST_AUTO_TEST_CASE( test_receive_send_signals ) { zmqpp::context ctx; zmqpp::socket p1(ctx, zmqpp::socket_type::pair); zmqpp::socket p2(ctx, zmqpp::socket_type::pair); p1.bind("inproc://test"); p2.connect("inproc://test"); p1.send(zmqpp::signal::test); p1.send("...."); p1.send(zmqpp::signal::stop); zmqpp::signal s; std::string str; p2.receive(s); BOOST_CHECK_EQUAL(zmqpp::signal::test, s); p2.receive(str); p2.send(zmqpp::signal::test); p2.receive(s); BOOST_CHECK_EQUAL(zmqpp::signal::stop, s); p1.receive(s); BOOST_CHECK_EQUAL(zmqpp::signal::test, s); } BOOST_AUTO_TEST_CASE( test_wait ) { zmqpp::context ctx; zmqpp::socket p1(ctx, zmqpp::socket_type::pair); zmqpp::socket p2(ctx, zmqpp::socket_type::pair); p1.bind("inproc://test"); p2.connect("inproc://test"); p1.send(zmqpp::signal::test); p1.send("...."); p1.send("___"); p1.send(zmqpp::signal::stop); // test wait(): the non signal message must be discarded. BOOST_CHECK_EQUAL(zmqpp::signal::test, p2.wait()); BOOST_CHECK_EQUAL(zmqpp::signal::stop, p2.wait()); } BOOST_AUTO_TEST_CASE( test_signal_block_noblock ) { zmqpp::context ctx; zmqpp::socket p1(ctx, zmqpp::socket_type::pair); zmqpp::socket p2(ctx, zmqpp::socket_type::pair); p1.bind("inproc://test"); BOOST_CHECK_EQUAL(false, p1.send(zmqpp::signal::test, true)); //noblock //p1.send(zmqpp::signal::test); // would block indefinitely p2.connect("inproc://test"); zmqpp::signal sig; BOOST_CHECK_EQUAL(false, p1.receive(sig, true)); //noblock p1.send(zmqpp::signal::test); BOOST_CHECK_EQUAL(true, p2.receive(sig, true)); //noblock } #ifndef TRAVIS_CI_BUILD //do not run when building on travis-ci (this cause oom error and kill the test process) BOOST_AUTO_TEST_CASE( sending_large_messages_string ) { zmqpp::context context; zmqpp::socket pusher(context, zmqpp::socket_type::push); pusher.bind("inproc://test"); zmqpp::socket puller(context, zmqpp::socket_type::pull); puller.connect("inproc://test"); std::string message; const size_t bytes_to_send = static_cast(1024 * 1024 * 1024); message.reserve(bytes_to_send); for (size_t i = 0; i < bytes_to_send; i++) { message.push_back('A' + (i % 26)); } BOOST_CHECK(pusher.send(message)); zmq_pollitem_t item = { puller, 0, ZMQ_POLLIN, 0 }; const int poll_timeout = 1000000; int result = zmq_poll(&item, 1, poll_timeout); BOOST_REQUIRE_MESSAGE(result >= 0, "polling command returned without expected value: " << zmq_strerror(zmq_errno())); BOOST_REQUIRE_MESSAGE(0 != result, "polling command returned with timeout after " << poll_timeout << " milliseconds"); BOOST_REQUIRE_MESSAGE(1 == result, "polling command claims " << result << " sockets have events but we only gave it one"); BOOST_REQUIRE_MESSAGE(item.revents & ZMQ_POLLIN, "events do not match expected POLLIN event: " << item.revents); std::string received_message; BOOST_CHECK(puller.receive(received_message)); BOOST_CHECK_EQUAL(0, message.compare(received_message)); BOOST_CHECK(!puller.has_more_parts()); } #endif #if (ZMQ_VERSION_MAJOR >= 4) BOOST_AUTO_TEST_CASE( test_simple_monitor ) { zmqpp::context ctx; zmqpp::socket server(ctx, zmqpp::socket_type::push); server.bind("tcp://*:55443"); server.monitor("inproc://test_monitor", zmqpp::event::all); zmqpp::socket monitor(ctx, zmqpp::socket_type::pair); monitor.connect("inproc://test_monitor"); zmqpp::socket client(ctx, zmqpp::socket_type::pull); client.connect("tcp://localhost:55443"); zmqpp::message_t message; BOOST_CHECK( monitor.receive( message ) ); BOOST_REQUIRE_EQUAL(2, message.parts()); #if (ZMQ_VERSION_MINOR >= 1) const uint8_t *ptr = reinterpret_cast(message.raw_data(0)); uint16_t ev = *(reinterpret_cast(ptr)); // uint32_t value = *(reinterpret_cast(ptr + 2)); BOOST_CHECK_EQUAL( zmqpp::event::accepted, ev ); BOOST_CHECK_EQUAL("tcp://0.0.0.0:55443", message.get(1)); // value is the underlying file descriptor. we cannot check its value against anything meaningful #else zmq_event_t const* event = static_cast( message.raw_data(0) ); BOOST_CHECK_EQUAL( zmqpp::event::accepted, event->event ); BOOST_CHECK_EQUAL( 0, event->value ); BOOST_CHECK_EQUAL("tcp://0.0.0.0:55443", message.get(1)); #endif } #endif BOOST_AUTO_TEST_SUITE_END() zmqpp-4.1.2/src/tests/test_socket_options.cpp000066400000000000000000000326721254036632700214460ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * Created on: 8 Aug 2011 * Author: @benjamg */ #include #include #include "zmqpp/context.hpp" #include "zmqpp/socket.hpp" BOOST_AUTO_TEST_SUITE( socket_options ) #define STRINGIFY(x) #x #define CHECK_SET(socket, type, option) check_set(socket, zmqpp::socket_option::option, STRINGIFY(option), false) #define CHECK_SET_POSITIVE(socket, type, option) check_set(socket, zmqpp::socket_option::option, STRINGIFY(option), true) #define CHECK_GET(socket, type, option) check_get(socket, zmqpp::socket_option::option, STRINGIFY(option)) // Note the hacky abuse of the fact we don't have float options #define CHECK_NOSET(socket, option) check_set(socket, zmqpp::socket_option::option, STRINGIFY(option), false) #define CHECK_NOGET(socket, option) check_get(socket, zmqpp::socket_option::option, STRINGIFY(option)) template void try_set(zmqpp::socket& socket, zmqpp::socket_option const& option, CheckType const& value, std::string const& option_name, std::string const& value_type) { BOOST_CHECKPOINT("setting option " << option_name << " against set type '" << value_type << "'"); try { socket.set(option, value); BOOST_CHECK_MESSAGE(typeid(CheckType) == typeid(WantedType), "expected exception setting option '" << option_name << "' against type '" << value_type << "'"); } catch(zmqpp::zmq_internal_exception const& e) { BOOST_CHECK_MESSAGE(false, "threw internal exception " << e.zmq_error() << " '" << e.what() << "' setting option '" << option_name << "' against type '" << value_type << "'"); } catch(zmqpp::exception const& e) { BOOST_CHECK_MESSAGE(typeid(CheckType) != typeid(WantedType), "threw unexpected exception '" << e.what() << "' setting option '" << option_name << "' against type '" << value_type << "'"); } } template void try_get(zmqpp::socket const& socket, zmqpp::socket_option const& option, std::string const& option_name, std::string const& value_type) { BOOST_CHECKPOINT("getting option " << option_name << " against set type '" << value_type << "'"); try { CheckType value; socket.get(option, value); BOOST_CHECK_MESSAGE(typeid(CheckType) == typeid(WantedType), "expected exception getting option " << option_name << " against type '" << value_type << "'"); } catch(zmqpp::zmq_internal_exception const& e) { BOOST_CHECK_MESSAGE(false, "threw internal exception " << e.zmq_error() << " '" << e.what() << "' getting option " << option_name << " against type '" << value_type << "'"); } catch(zmqpp::exception const& e) { BOOST_CHECK_MESSAGE(typeid(CheckType) != typeid(WantedType), "threw unexpected exception '" << e.what() << "' getting option " << option_name << " against type '" << value_type << "'"); } } template void check_set(zmqpp::socket& socket, zmqpp::socket_option const& option, std::string const& option_name, bool positive_only) { // Boolean try_set(socket, option, true, option_name, "boolean (true)"); try_set(socket, option, false, option_name, "boolean (false)"); // Integer - Masquerade of unsigned 64bit integer if (typeid(uint64_t) == typeid(Type)) { // Positive integers are valid as unsigned 64bit try_set(socket, option, -1, option_name, "signed integer (negative)"); try_set(socket, option, 42, option_name, "signed_integer (positive / masquerade)"); } else if (typeid(int64_t) == typeid(Type)) { if (positive_only) { try_set(socket, option, -1, option_name, "signed integer (negative)"); } else { try_set(socket, option, -1, option_name, "signed integer (negative / masquerade)"); } try_set(socket, option, 42, option_name, "signed integer (positive / masquerade)"); } // Integer - Masquerade of boolean else if (typeid(bool) == typeid(Type)) { // 1 and 0 Integers are valid as boolean try_set(socket, option, -1, option_name, "signed integer (negative)"); try_set(socket, option, 0, option_name, "signed integer (false / masquerade)"); try_set(socket, option, 1, option_name, "signed integer (true / masquerade)"); try_set(socket, option, 42, option_name, "signed integer (positive)"); } // Integer - Others else { if (positive_only) { try_set(socket, option, -1, option_name, "signed integer (negative / masquerade)"); } else { try_set(socket, option, -1, option_name, "signed integer (negative)"); } try_set(socket, option, 42, option_name, "signed integer (positive)"); } // Unsigned 64bit integer try_set(socket, option, 1, option_name, "unsigned 64bit integer"); #if (ZMQ_VERSION_MAJOR == 2) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR < 2)) // 64bit integer try_set(socket, option, 1, option_name, "signed 64bit integer"); #endif // Strings try_set(socket, option, "test", option_name, "string"); } template void check_get(zmqpp::socket& socket, zmqpp::socket_option const& option, std::string const& option_name) { // Boolean try_get(socket, option, option_name, "boolean"); // Integer - Masquerade of boolean if (typeid(bool) == typeid(Type)) { try_get(socket, option, option_name, "signed integer (masquerade)"); } // Integer - Others else { try_get(socket, option, option_name, "signed integer"); } // Unsigned 64bit integer try_get(socket, option, option_name, "unsigned 64bit integer"); #if (ZMQ_VERSION_MAJOR == 2) // 64bit integer - Masquerade of boolean if (typeid(bool) == typeid(Type)) { try_get(socket, option, option_name, "signed 64bit integer (masquerade)"); } // 64bit integer - Others else { try_get(socket, option, option_name, "signed 64bit integer"); } #else // 64bit integer try_get(socket, option, option_name, "signed 64bit integer"); #endif // Strings try_get(socket, option, option_name, "string"); } BOOST_AUTO_TEST_CASE( set_socket_options ) { zmqpp::context context; zmqpp::socket socket(context, zmqpp::socket_type::subscribe); socket.bind("inproc://test"); CHECK_NOSET(socket, receive_more); CHECK_NOSET(socket, file_descriptor); CHECK_NOSET(socket, events); CHECK_NOSET(socket, type); #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) CHECK_NOSET(socket, last_endpoint); #endif CHECK_SET(socket, int, linger); CHECK_SET_POSITIVE(socket, int, backlog); CHECK_SET(socket, int, receive_timeout); CHECK_SET(socket, int, send_timeout); CHECK_SET(socket, uint64_t, affinity); CHECK_SET(socket, std::string, identity); CHECK_SET(socket, std::string, subscribe); CHECK_SET(socket, std::string, unsubscribe); // For some reason -1 not working here //CHECK_SET(socket, int, reconnect_interval); CHECK_SET_POSITIVE(socket, int, reconnect_interval_max); CHECK_SET_POSITIVE(socket, int, backlog); #if (ZMQ_VERSION_MAJOR > 2) CHECK_SET_POSITIVE(socket, int, send_buffer_size); CHECK_SET_POSITIVE(socket, int, receive_buffer_size); CHECK_SET_POSITIVE(socket, int, rate); CHECK_SET_POSITIVE(socket, int, recovery_interval); CHECK_SET_POSITIVE(socket, int, send_high_water_mark); CHECK_SET_POSITIVE(socket, int, receive_high_water_mark); CHECK_SET_POSITIVE(socket, int, multicast_hops); CHECK_SET_POSITIVE(socket, int64_t, max_messsage_size); #else CHECK_SET(socket, bool, multicast_loopback); CHECK_SET_POSITIVE(socket, int64_t, rate); CHECK_SET_POSITIVE(socket, int64_t, recovery_interval); CHECK_SET_POSITIVE(socket, int64_t, recovery_interval_seconds); CHECK_SET_POSITIVE(socket, int64_t, swap_size); CHECK_SET(socket, uint64_t, send_buffer_size); CHECK_SET(socket, uint64_t, receive_buffer_size); CHECK_SET(socket, uint64_t, high_water_mark); #endif #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 1)) CHECK_SET(socket, bool, ipv4_only); #endif #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) #if (ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 2) CHECK_SET(socket, bool, delay_attach_on_connect); #else CHECK_SET(socket, bool, immediate); #endif // CHECK_SET(socket, int, tcp_keepalive); --- special case of boolean but with -1? CHECK_SET(socket, int, tcp_keepalive_idle); CHECK_SET(socket, int, tcp_keepalive_count); CHECK_SET(socket, int, tcp_keepalive_interval); // CHECK_SET(socket, std::string, tcp_accept_filter); --- special case required to be an address #endif #if (ZMQ_VERSION_MAJOR >= 4) CHECK_SET(socket, bool, ipv6); CHECK_NOSET(socket, mechanism); CHECK_SET(socket, std::string, plain_password); CHECK_SET(socket, bool, plain_server); CHECK_SET(socket, std::string, plain_username); CHECK_SET(socket, std::string, zap_domain); CHECK_SET(socket, bool, conflate); #endif #ifdef ZMQ_EXPERIMENTAL_LABELS CHECK_NOSET(socket, receive_label); #endif } #if (ZMQ_VERSION_MAJOR >= 4) BOOST_AUTO_TEST_CASE( set_socket_options_tcp_only ) { zmqpp::context context; zmqpp::socket socket(context, zmqpp::socket_type::subscribe); socket.bind("tcp://*:54321"); // TODO: reenable once I have curve key generation working to test against // CHECK_SET(socket, std::string, curve_public_key); // CHECK_SET(socket, std::string, curve_secret_key); // CHECK_SET(socket, std::string, curve_server_key); // CHECK_SET(socket, bool, curve_server); } BOOST_AUTO_TEST_CASE( set_socket_options_router_types ) { zmqpp::context context; zmqpp::socket socket(context, zmqpp::socket_type::router); socket.bind("inproc://test"); CHECK_SET(socket, bool, router_raw); CHECK_SET(socket, bool, probe_router); } BOOST_AUTO_TEST_CASE( set_socket_options_request_types ) { zmqpp::context context; zmqpp::socket socket(context, zmqpp::socket_type::request); socket.bind("inproc://test"); CHECK_SET(socket, bool, request_correlate); CHECK_SET(socket, bool, request_relaxed); } #endif BOOST_AUTO_TEST_CASE( get_socket_options ) { zmqpp::context context; zmqpp::socket socket(context, zmqpp::socket_type::subscribe); socket.bind("inproc://test"); CHECK_NOGET(socket, subscribe); CHECK_NOGET(socket, unsubscribe); #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) CHECK_NOGET(socket, router_mandatory); CHECK_NOGET(socket, xpub_verbose); CHECK_NOGET(socket, tcp_accept_filter); #endif CHECK_GET(socket, bool, receive_more); CHECK_GET(socket, int, file_descriptor); CHECK_GET(socket, int, events); CHECK_GET(socket, int, type); CHECK_GET(socket, int, linger); CHECK_GET(socket, int, backlog); CHECK_GET(socket, int, reconnect_interval); CHECK_GET(socket, int, reconnect_interval_max); CHECK_GET(socket, int, receive_timeout); CHECK_GET(socket, int, send_timeout); CHECK_GET(socket, uint64_t, affinity); CHECK_GET(socket, std::string, identity); #if (ZMQ_VERSION_MAJOR > 2) CHECK_GET(socket, int, send_buffer_size); CHECK_GET(socket, int, receive_buffer_size); CHECK_GET(socket, int, rate); CHECK_GET(socket, int, recovery_interval); CHECK_GET(socket, int, send_high_water_mark); CHECK_GET(socket, int, receive_high_water_mark); CHECK_GET(socket, int, multicast_hops); CHECK_GET(socket, int64_t, max_messsage_size); #else CHECK_GET(socket, bool, multicast_loopback); CHECK_GET(socket, int64_t, rate); CHECK_GET(socket, int64_t, recovery_interval); CHECK_GET(socket, int64_t, recovery_interval_seconds); CHECK_GET(socket, int64_t, swap_size); CHECK_GET(socket, uint64_t, send_buffer_size); CHECK_GET(socket, uint64_t, receive_buffer_size); CHECK_GET(socket, uint64_t, high_water_mark); #endif #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 1)) CHECK_GET(socket, bool, ipv4_only); #endif #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) #if (ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 2) CHECK_GET(socket, bool, delay_attach_on_connect); #else CHECK_GET(socket, bool, immediate); #endif CHECK_GET(socket, std::string, last_endpoint); CHECK_GET(socket, int, tcp_keepalive); CHECK_GET(socket, int, tcp_keepalive_idle); CHECK_GET(socket, int, tcp_keepalive_count); CHECK_GET(socket, int, tcp_keepalive_interval); #endif #if (ZMQ_VERSION_MAJOR >= 4) CHECK_GET(socket, bool, ipv6); CHECK_GET(socket, int, mechanism); CHECK_GET(socket, std::string, plain_password); CHECK_GET(socket, bool, plain_server); CHECK_GET(socket, std::string, plain_username); CHECK_GET(socket, std::string, zap_domain); CHECK_NOGET(socket, conflate); CHECK_NOGET(socket, probe_router); CHECK_NOGET(socket, request_correlate); CHECK_NOGET(socket, request_relaxed); CHECK_NOGET(socket, router_raw); #endif #ifdef ZMQ_EXPERIMENTAL_LABELS CHECK_GET(socket, bool, receive_label); #endif } #if (ZMQ_VERSION_MAJOR >= 4) BOOST_AUTO_TEST_CASE( get_socket_options_tcp_only ) { zmqpp::context context; zmqpp::socket socket(context, zmqpp::socket_type::subscribe); socket.bind("tcp://*:54321"); // TODO: reenable once I have curve key generation working to test against // CHECK_GET(socket, std::string, curve_public_key); // CHECK_GET(socket, std::string, curve_secret_key); // CHECK_GET(socket, std::string, curve_server_key); // CHECK_NOGET(socket, curve_server); } #endif BOOST_AUTO_TEST_SUITE_END() zmqpp-4.1.2/src/tests/test_z85.cpp000066400000000000000000000031021254036632700170130ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ #include #include "zmqpp/z85.hpp" #include "zmqpp/exception.hpp" #if (ZMQ_VERSION_MAJOR >= 4) BOOST_AUTO_TEST_SUITE( z85 ) BOOST_AUTO_TEST_CASE(test_encode) { uint8_t data_source[] = {0x86, 0x4F, 0xD2, 0x6F, 0xB5, 0x59, 0xF7, 0x5B}; std::string res; res = zmqpp::z85::encode(data_source, sizeof(data_source)); BOOST_CHECK_EQUAL(res, "HelloWorld"); std::string src(reinterpret_cast(data_source), sizeof(data_source)); res = zmqpp::z85::encode(src); BOOST_CHECK_EQUAL(res, "HelloWorld"); } BOOST_AUTO_TEST_CASE(test_decode) { std::string data_source = "HelloWorld"; std::vector ret; ret = zmqpp::z85::decode(data_source); std::vector expected = {0x86, 0x4F, 0xD2, 0x6F, 0xB5, 0x59, 0xF7, 0x5B}; BOOST_CHECK_EQUAL(ret.size(), expected.size()); for (unsigned int i = 0; i < expected.size(); ++i) BOOST_CHECK_EQUAL(ret[i], expected[i]); } BOOST_AUTO_TEST_CASE(test_wrong_size) { std::string encode_source = "123"; // not divisible by 4 std::string decode_source = "123456"; // not divisible by 5 BOOST_CHECK_THROW(zmqpp::z85::encode(encode_source), zmqpp::z85_exception); BOOST_CHECK_THROW(zmqpp::z85::decode(decode_source), zmqpp::z85_exception); } BOOST_AUTO_TEST_SUITE_END() #endif zmqpp-4.1.2/src/zmqpp/000077500000000000000000000000001254036632700146335ustar00rootroot00000000000000zmqpp-4.1.2/src/zmqpp/actor.cpp000066400000000000000000000062271254036632700164560ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * File: actor.cpp * Author: xaqq * * Created on May 20, 2014, 10:51 PM */ #include #include #include #include "actor.hpp" #include "socket.hpp" #include "message.hpp" #include "exception.hpp" #include "context.hpp" zmqpp::context zmqpp::actor::actor_pipe_ctx_; namespace zmqpp { actor::actor(ActorStartRoutine routine) : parent_pipe_(nullptr), child_pipe_(nullptr), stopped_(false) { std::string pipe_endpoint; parent_pipe_ = new socket(actor_pipe_ctx_, socket_type::pair); pipe_endpoint = bind_parent(); child_pipe_ = new socket(actor_pipe_ctx_, socket_type::pair); child_pipe_->connect(pipe_endpoint); std::thread t(&actor::start_routine, this, child_pipe_, routine); t.detach(); signal sig; sig = parent_pipe_->wait(); assert(sig == signal::ok || sig == signal::ko); if (sig == signal::ko) { delete parent_pipe_; throw actor_initialization_exception(); } } actor::actor(actor &&o) { *this = std::move(o); } actor &actor::operator=(actor &&o) { parent_pipe_ = o.parent_pipe_; stopped_ = o.stopped_; retval_ = o.retval_; o.parent_pipe_ = nullptr; return *this; } actor::~actor() { stop(true); delete parent_pipe_; } bool actor::stop(bool block /* = false */) { if (!parent_pipe_) return false; parent_pipe_->send(signal::stop, true); if (!block) { return true; } else { if (stopped_) return retval_; // wait for a response from the child. Either it successfully shutdown, or not. signal sig = parent_pipe_->wait(); stopped_ = true; assert(sig == signal::ok || sig == signal::ko); return (retval_ = (sig == signal::ok)); } } void actor::start_routine(socket *child_pipe, ActorStartRoutine routine) { if (routine(child_pipe)) child_pipe->send(signal::ok); else child_pipe->send(signal::ko); delete child_pipe; } socket* actor::pipe() { return parent_pipe_; } const socket* actor::pipe() const { return parent_pipe_; } std::string actor::bind_parent() { std::string base_endpoint = "inproc://zmqpp::actor::" + std::to_string(reinterpret_cast (this)); for (;;) { try { std::string endpoint = base_endpoint + std::to_string(std::rand()); parent_pipe_->bind(endpoint); return endpoint; } catch (zmq_internal_exception const&) { // endpoint already taken. } } } } zmqpp-4.1.2/src/zmqpp/actor.hpp000066400000000000000000000113131254036632700164530ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ #pragma once #include #include #include "socket.hpp" namespace zmqpp { /** * An actor is a thread with a pair socket connected to its parent. * It aims to be similar to CMZQ's zactor. * * From the parent thread, instancing an actor will spawn a new thread, and install * a pipe between those two threads. * 1. The parent's end of the pipe can be retrieved by calling pipe() on the actor. * 2. The child's end is passed as a parameter to the routine executed in the child's thread. * * You don't have to manage the 2 PAIR sockets. The parent's one will be destroyed * when the actor dies, and the child's end is taken care of when the user routine ends. * * @note * About user-supplied routine return value: * 1. If the supplied routine returns true, signal::ok will be send to the parent. * 2. If it returns false, signal::ko is send instead. * * @note * There is a simple protocol between actor and parent to avoid synchronization problem: * 1. The actor constructor expect to receive either signal::ok or signal::ko before it returns. * 2. When sending signal::stop (actor destruction or by calling stop()), we expect a response: * (either signal::ko or signal::ok). This response is used to determine if stop() will return * true or false when in blocking mode. */ class actor { public: /** * The user defined function type. */ typedef std::function ActorStartRoutine; /** * Create a new actor. This will effectively create a new thread and runs the user supplied routine. * The constructor expect a signal from the routine before returning. * * Expect to receive either signal::ko or signal::ok before returning. * If it receives signal::ko, it will throw. * @param routine to be executed. */ actor(ActorStartRoutine routine); actor(const actor&) = delete; /** * Move constructor. The other actor will not be usable anymore. * Its pipe() method shall return null, and stop() will do nothing. */ actor(actor &&o); /** * Move-assignment operator. * @see move constructor. */ actor &operator=(actor &&o); virtual ~actor(); /** * @return pointer to the parent's end of the pipe */ socket *pipe(); /** * @return const pointer to the parent's end of the pipe */ const socket *pipe() const; /** * Sends signal::stop to the actor thread. * The actor thread shall stop as soon as possible. * The return value is only relevant when block is true. If block is false (the default), this method * will return true. * * It is safe to call stop() multiple time (to ask the actor to shutdown, and then a bit * later call stop(true) to make sure it is really stopped) * * @note calling this method on an "empty" actor (after it was moved) will return * false and nothing will happen. * @param block whether or not we wait until the actor thread stops. * @return a boolean indicating whether or not the actor successfully shutdown. */ bool stop(bool block = false); private: /** * Call a user defined function and performs cleanup once it returns. * We use a copy of child_pipe_ here; this is to avoid a race condition where the * destructor would be called before start_routine finishes but after it sent signal::ok / signal::ko. * The actor object would be invalid (because already destroyed). * * @param child a copy of child_pipe_. * @param routine user routine that will be called */ void start_routine(socket *child, ActorStartRoutine routine); /** * Bind the parent socket and return the endpoint used. * Since endpoint are generated and have to be tested for availability * this method is reponsible for finding a valid endpoint to bind to. */ std::string bind_parent(); /** * The parent thread socket. * This socket will be closed and freed by the actor destructor. */ socket *parent_pipe_; /** * The child end of the pipe. * It is closed and freed when the routine ran by the actor ends. */ socket *child_pipe_; /** * This static, per process zmqpp::context, is used to connect PAIR socket * between Actor and their parent thread. */ static context actor_pipe_ctx_; /** * Keeps track of the status of the actor thread. */ bool stopped_; bool retval_; }; } zmqpp-4.1.2/src/zmqpp/auth.cpp000066400000000000000000000254401254036632700163050ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 25 Nov 2014 * \author Prem Shankar Kumar (\@meprem) */ #include #include #include "auth.hpp" #include "message.hpp" #include "exception.hpp" #include "socket_types.hpp" #include "signal.hpp" #include "z85.hpp" #if (ZMQ_VERSION_MAJOR > 3) #if defined(ZMQPP_NO_CONSTEXPR) const char * const zmqpp::auth::zap_endpoint_ = "inproc://zeromq.zap.01"; #endif namespace zmqpp { auth::auth(context& ctx) : curve_allow_any(false), terminated(false), verbose(false) { auto zap_auth_server = [this] (socket * pipe, context& auth_ctx) -> bool { // spawn ZAP handler socket zap_handler(auth_ctx, socket_type::reply); try { zap_handler.bind(zap_endpoint_); pipe->send(signal::ok); } catch (zmq_internal_exception const&) { // by returning false here, the actor will send signal::ko // this will make the actor constructor throw. // we could also to the ourselves: pipe->send(signal::ko);) return false; } auth_poller.add(*pipe); auth_poller.add(zap_handler); while (!terminated && auth_poller.poll()) { if (auth_poller.has_input(zap_handler)) { authenticate(zap_handler); } if (auth_poller.has_input(*pipe)) { handle_command(*pipe); } } zap_handler.unbind(zap_endpoint_); return true; }; // Start ZAP Authentication Server std::cout << "auth: Starting ZAP Authentication Server" << std::endl; authenticator = std::make_shared(std::bind(zap_auth_server, std::placeholders::_1, std::ref(ctx))); } auth::~auth() { message msg; msg << "TERMINATE"; authenticator->pipe()->send(msg); authenticator->pipe()->wait(); } void auth::allow(const std::string &address) { message msg; msg << "ALLOW" << address; authenticator->pipe()->send(msg); authenticator->pipe()->wait(); } void auth::deny(const std::string &address) { message msg; msg << "DENY" << address; authenticator->pipe()->send(msg); authenticator->pipe()->wait(); } void auth::configure_domain(const std::string &domain) { message msg; assert(!domain.empty()); msg << "DOMAIN" << domain; authenticator->pipe()->send(msg); authenticator->pipe()->wait(); } void auth::configure_plain(const std::string &username, const std::string &password) { message msg; assert(!username.empty()); assert(!password.empty()); msg << "PLAIN" << username << password; if (verbose) { std::cout << "auth: configure PLAIN - username:" << username << " password:" << password << std::endl; } authenticator->pipe()->send(msg); authenticator->pipe()->wait(); } void auth::configure_curve(const std::string &client_public_key) { message msg; assert(!client_public_key.empty()); msg << "CURVE" << client_public_key; if (verbose) { std::cout << "auth: configure CURVE - client public key:" << client_public_key << std::endl; } authenticator->pipe()->send(msg); authenticator->pipe()->wait(); } void auth::configure_gssapi() { message msg; msg << "GSSAPI"; if (verbose) { std::cout << "auth: configure GSSAPI - Not implemented yet!!!" << std::endl; } authenticator->pipe()->send(msg); authenticator->pipe()->wait(); } void auth::set_verbose(bool verbose) { std::string verbose_string = (true == verbose) ? "true" : "false"; message msg; msg << "VERBOSE" << verbose_string; if(verbose) { std::cout << "auth: verbose:" << verbose_string << std::endl; } authenticator->pipe()->send(msg); authenticator->pipe()->wait(); } void auth::handle_command(socket& pipe) { // Get the whole message off the pipe in one go message msg; pipe.receive(msg); if(0 == msg.parts()) return; // Interrupted // authentication command std::string command = msg.get(0); if (verbose) { std::cout <<"auth: API command=" << command << std::endl; } if("ALLOW" == command) { std::string address = msg.get(1); if(verbose) { std::cout << "auth: whitelisting ipaddress=" << address << std::endl; } whitelist.insert(address); pipe.send(signal::ok); } else if("DENY" == command) { std::string address = msg.get(1); if(verbose) { std::cout << "auth: blacklisting ipaddress=" << address << std::endl; } blacklist.insert(address); pipe.send(signal::ok); } else if("DOMAIN" == command) { std::string domain = msg.get(1); if(verbose) { std::cout << "auth: domain=" << domain << std::endl; } this->domain = domain; pipe.send(signal::ok); } else if("PLAIN" == command) { std::string user = msg.get(1); std::string pass = msg.get(2); if (verbose) { std::cout << "auth: configured PLAIN - user:" << user << std::endl; } passwords.insert(std::make_pair(user, pass)); pipe.send(signal::ok); } else if("CURVE" == command) { // If client_public_key is CURVE_ALLOW_ANY, allow all clients. Otherwise // treat client_public_key as client public key certificate. std::string client_public_key = msg.get(1); if("CURVE_ALLOW_ANY" == client_public_key) { curve_allow_any = true; if(verbose) { std::cout << "auth: configured CURVE - allow ALL clients" << std::endl; } } else { curve_allow_any = false; client_keys.insert(client_public_key); if(verbose) { std::cout << "auth: configured CURVE - allow client with public key:" << client_public_key << std::endl; } } pipe.send(signal::ok); } else if("GSSAPI" == command) { // GSSAPI authentication is not yet implemented here if(verbose) { std::cout << "auth: configure GSSAPI authentication is not yet implemented here" << std::endl; } pipe.send(signal::ok); } else if("VERBOSE" == command) { std::string verbose_string = msg.get(1); verbose = ("true" == verbose_string)? true : false; pipe.send(signal::ok); } else if("TERMINATE" == command) { std::cout << "auth: Shutdown ZAP Authentication Server" << std::endl; terminated = true; pipe.send(signal::ok); } else { if(verbose) { std::cout << "auth: Invalid command=" << command << std::endl; } assert(false); } } bool auth::authenticate_plain(zap_request& request, std::string &user_id) { auto search = passwords.find(request.get_username()); if((search != passwords.end()) && (search->second == request.get_password())) { if (verbose) { std::cout << "auth: allowed (PLAIN) username=" << request.get_username() << " password=" << request.get_password() << std::endl; } user_id = request.get_username(); return true; } else { if (verbose) { std::cout << "auth: denied (PLAIN) username=" << request.get_username() << " password=" << request.get_password() << std::endl; } return false; } } bool auth::authenticate_curve(zap_request& request, std::string &user_id) { if (curve_allow_any) { if (verbose) { std::cout << "auth: allowed (CURVE allow any client)" << std::endl; } user_id = request.get_client_key(); return true; } else { auto search = client_keys.find(request.get_client_key()); if(search != client_keys.end()) { if (verbose) { std::cout << "auth: allowed (CURVE) client_key=" << request.get_client_key() << std::endl; } user_id = request.get_client_key(); return true; } else { if (verbose) { std::cout << "auth: denied (CURVE) client_key=" << request.get_client_key() << std::endl; } return false; } } } bool auth::authenticate_gssapi(zap_request& request) { if (verbose) { std::cout << "auth: allowed (GSSAPI) principal=" << request.get_principal() << " identity=" << request.get_identity() << std::endl; } return true; } void auth::authenticate(socket& sock) { // Receive a ZAP request. zap_request request(sock, verbose); // will be set by mechanism-dependent code std::string user_id; if(request.get_version().empty()) { // Interrupted request.reply("500", "Internal error", ""); return; } // Is address explicitly whitelisted or blacklisted? bool allowed = false; bool denied = false; if(whitelist.size()) { auto search = whitelist.find(request.get_address()); if (search != whitelist.end()) { allowed = true; if (verbose) { std::cout << "auth: passed (whitelist) address=" << request.get_address() << std::endl; } } else { denied = true; if (verbose) { std::cout << "auth: denied (not in whitelist) address=" << request.get_address() << std::endl; } } } else if(blacklist.size()) { auto search = blacklist.find(request.get_address()); if (search != blacklist.end()) { denied = true; if (verbose) { std::cout << "auth: denied (blacklist) address=" << request.get_address() << std::endl; } } else { allowed = true; if (verbose) { std::cout << "auth: passed (not in blacklist) address=" << request.get_address() << std::endl; } } } // Mechanism-specific checks if(!denied) { if (("NULL" == request.get_mechanism()) && !allowed) { // For NULL, we allow if the address wasn't blacklisted if (verbose) { std::cout << "auth: allowed (NULL)" << std::endl; } allowed = true; } else if ("PLAIN" == request.get_mechanism()) { // For PLAIN, even a whitelisted address must authenticate allowed = authenticate_plain(request, user_id); } else if ("CURVE" == request.get_mechanism()) { // For CURVE, even a whitelisted address must authenticate allowed = authenticate_curve(request, user_id); } else if ("GSSAPI" == request.get_mechanism()) { // For GSSAPI, even a whitelisted address must authenticate allowed = authenticate_gssapi(request); } } if (allowed) request.reply("200", "OK", user_id); else request.reply("400", "No access", ""); } } #endif zmqpp-4.1.2/src/zmqpp/auth.hpp000066400000000000000000000117171254036632700163140ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 25 Nov 2014 * \author Prem Shankar Kumar (\@meprem) */ #ifndef ZMQPP_AUTH_HPP_ #define ZMQPP_AUTH_HPP_ #include #include #include #include #include "actor.hpp" #include "poller.hpp" #include "socket.hpp" #include "context.hpp" #include "zap_request.hpp" // Authentication is something from zmq 4 #if (ZMQ_VERSION_MAJOR > 3) namespace zmqpp { /** * auth - authentication for ZeroMQ security mechanisms * * An auth actor takes over authentication for all incoming connections in * its context. You can whitelist or blacklist peers based on IP address, * and define policies for securing PLAIN, CURVE, and GSSAPI connections. * */ class auth { public: /** * Constructor. A auth actor takes over authentication for all incoming connections in * its context. You can whitelist or blacklist peers based on IP address, * and define policies for securing PLAIN, CURVE, and GSSAPI connections. * */ auth(context& ctx); /** * Destructor. * */ ~auth(); /** * Allow (whitelist) a single IP address. For NULL, all clients from this * address will be accepted. For PLAIN and CURVE, they will be allowed to * continue with authentication. You can call this method multiple times * to whitelist multiple IP addresses. If you whitelist a single address, * any non-whitelisted addresses are treated as blacklisted. * */ void allow(const std::string &address); /** * Deny (blacklist) a single IP address. For all security mechanisms, this * rejects the connection without any further authentication. Use either a * whitelist, or a blacklist, not not both. If you define both a whitelist * and a blacklist, only the whitelist takes effect. * */ void deny(const std::string &address); /** * Configure a ZAP domain. To cover all domains, use "*". */ void configure_domain(const std::string &domain); /** * Configure PLAIN authentication. PLAIN authentication uses a plain-text * username and password. * */ void configure_plain(const std::string &username, const std::string &password); /** * Configure CURVE authentication. CURVE authentication uses client public keys. * This method can be called multiple times. To cover all domains, use "*". * To allow all client keys without checking, specify CURVE_ALLOW_ANY for the client_public_key. * */ void configure_curve(const std::string &client_public_key); /** * Configure GSSAPI authentication. GSSAPI authentication uses an underlying * mechanism (usually Kerberos) to establish a secure context and perform mutual * authentication. * */ void configure_gssapi(); /** * Enable verbose tracing of commands and activity. * */ void set_verbose(bool verbose); private: /** * Handle an authentication command from calling application. * */ void handle_command(socket& pipe); /** * Handle a PLAIN authentication request from libzmq core * * @param user_id store the user as the User-Id. */ bool authenticate_plain(zap_request& request, std::string &user_id); /** * Handle a CURVE authentication request from libzmq core * * @param user_id store the public key (z85 encoded) as the User-Id. */ bool authenticate_curve(zap_request& request, std::string &user_id); /** * Handle a GSSAPI authentication request from libzmq core * */ bool authenticate_gssapi(zap_request& request); /** * Authentication. * */ void authenticate(socket& sock); std::shared_ptr authenticator; // ZAP authentication actor poller auth_poller; // Socket poller std::unordered_set whitelist; // Whitelisted addresses std::unordered_set blacklist; // Blacklisted addresses std::unordered_map passwords; // PLAIN passwords, if loaded std::unordered_set client_keys; // Client public keys std::string domain; // ZAP domain bool curve_allow_any; // CURVE allows arbitrary clients bool terminated; // Did caller ask us to quit? bool verbose; // Verbose logging enabled? # if defined(ZMQPP_NO_CONSTEXPR) static const char * const zap_endpoint_; # else constexpr static const char * const zap_endpoint_ = "inproc://zeromq.zap.01"; # endif // No copy - private and not implemented auth(auth const&) ZMQPP_EXPLICITLY_DELETED; auth& operator=(auth const&) NOEXCEPT ZMQPP_EXPLICITLY_DELETED; }; } #endif #endif /* ZMQPP_AUTH_HPP_ */ zmqpp-4.1.2/src/zmqpp/compatibility.hpp000066400000000000000000000067251254036632700202270ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 10 Sep 2011 * \author ron * \author Ben Gray (\@benjamg) * * A fair number of C++0x (or more accurately C++11) features are used in this * library and as this project is used where I work on older compilers this * file was created to help. * * C++ features and their workaround where not supported: * \li lambda functions - disabled, these are only used in the test anyway. * \li typesafe enums - replaced with enum where comparisons needed. * \li nullptr - defined to null. * * As of the port to version 3.1 (libzmqpp version 1.1.0) this file will also * be used to maintain compatablity with multiple versions of 0mq */ #ifndef ZMQPP_COMPATIBILITY_HPP_ #define ZMQPP_COMPATIBILITY_HPP_ #include // Currently we require at least 0mq version 2.2.x #define ZMQPP_REQUIRED_ZMQ_MAJOR 2 #define ZMQPP_REQUIRED_ZMQ_MINOR 2 #if (ZMQ_VERSION_MAJOR < ZMQPP_REQUIRED_ZMQ_MAJOR) || ((ZMQ_VERSION_MAJOR == ZMQPP_REQUIRED_ZMQ_MAJOR) && (ZMQ_VERSION_MINOR < ZMQPP_REQUIRED_ZMQ_MINOR)) #error zmqpp requires a later version of 0mq #endif // Experimental feature support #if (ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR == 0) #define ZMQ_EXPERIMENTAL_LABELS #endif // Deal with older versions of gcc #if defined(__GNUC__) && !defined(__clang__) #if __GNUC__ == 4 // Deal with older gcc not supporting C++0x typesafe enum class name {} comparison #if __GNUC_MINOR__ < 4 #define ZMQPP_COMPARABLE_ENUM enum #endif #if __GNUC_MINOR__ == 4 #if __GNUC_PATCHLEVEL__ < 1 #undef ZMQPP_COMPARABLE_ENUM #define ZMQPP_COMPARABLE_ENUM enum #endif // if __GNUC_PATCHLEVEL__ < 1 #endif // if __GNUC_MINOR__ == 4 // Deal with older gcc not supporting C++0x lambda function #if __GNUC_MINOR__ < 5 #define ZMQPP_IGNORE_LAMBDA_FUNCTION_TESTS #define ZMQPP_EXPLICITLY_DELETED #endif // if __GNUC_MINOR__ < 5 // Deal with older gcc not supporting C++0x nullptr #if __GNUC_MINOR__ < 6 #define nullptr NULL #define NOEXCEPT #endif // if __GNUC_MINOR__ < 6 #endif // if __GNUC_ == 4 #endif // if defined(__GNUC__) && !defined(__clang__) #if defined(_MSC_VER) #define NOEXCEPT throw() #if _MSC_VER < 1900 # define ZMQPP_NO_CONSTEXPR #endif #if _MSC_VER < 1800 #define ZMQPP_EXPLICITLY_DELETED #endif // if _MSC_VER < 1800 #if _MSC_VER < 1600 #define nullptr NULL #define ZMQPP_IGNORE_LAMBDA_FUNCTION_TESTS #define ZMQPP_COMPARABLE_ENUM enum #endif // if _MSC_VER < 1600 #endif // if defined(_MSC_VER) // Generic state, assume a modern compiler #ifndef ZMQPP_COMPARABLE_ENUM #define ZMQPP_COMPARABLE_ENUM enum class #endif #ifndef ZMQPP_EXPLICITLY_DELETED #define ZMQPP_EXPLICITLY_DELETED = delete #endif #ifndef NOEXCEPT #define NOEXCEPT noexcept #endif // There are a couple of methods that take a raw socket in form of a 'file descriptor'. Under POSIX // this is simply an int. But under Windows this type must be a SOCKET. In order to hide this // platform detail we create a raw_socket_t which is a SOCKET under Windows and an int on all the // other platforms. This is practically the same as libzmq does with its zmq_pollitem_t struct. namespace zmqpp { #ifdef _WIN32 typedef SOCKET raw_socket_t; #else typedef int raw_socket_t; #endif } #endif /* ZMQPP_COMPATIBILITY_HPP_ */ zmqpp-4.1.2/src/zmqpp/context.cpp000066400000000000000000000025521254036632700170270ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 9 Aug 2011 * \author Ben Gray (\@benjamg) */ #include "context.hpp" namespace zmqpp { void context::terminate() { int result; do { #if (ZMQ_VERSION_MAJOR < 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR < 2)) result = zmq_term(_context); #else result = zmq_ctx_destroy(_context); #endif } while (result != 0 && zmq_errno() == EINTR); if (result != 0) { throw zmq_internal_exception(); } _context = nullptr; } #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) void context::set(context_option const option, int const value) { if (nullptr == _context) { throw invalid_instance("context is invalid"); } if (0 != zmq_ctx_set(_context, static_cast(option), value)) { throw zmq_internal_exception(); } } int context::get(context_option const option) { if (nullptr == _context) { throw invalid_instance("context is invalid"); } int result = zmq_ctx_get(_context, static_cast(option)); if (result < 0) { throw zmq_internal_exception(); } return result; } #endif } zmqpp-4.1.2/src/zmqpp/context.hpp000066400000000000000000000111331254036632700170270ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 9 Aug 2011 * \author Ben Gray (\@benjamg) */ #ifndef ZMQPP_CONTEXT_HPP_ #define ZMQPP_CONTEXT_HPP_ #include #include #include "compatibility.hpp" #include "exception.hpp" #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) #include "context_options.hpp" #endif namespace zmqpp { /** * The context class represents internal zmq context and io threads. * * By default the context class will create one thread, however this can be * overridden in the constructor. * * The context class is the only object that can be considered thread safe. * * All sockets using endpoints other than inproc require the context to have * at least one thread. * * This class is c++0x move supporting and cannot be copied. */ class context { public: #if (ZMQ_VERSION_MAJOR < 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR < 2)) /** * Initialise the 0mq context. * * If only inproc is used then the context may be created with zero threads. * Any inproc endpoint using sockets must be created using the same context. * * The context is thread safe an may be used anywhere in your application, * however there is no requirement (other than inproc restrictions) for you * to do this. * * \param threads an integer argument for the number of required threads. Defaults to 1. */ context(int const& threads = 1) #else /** * Initialise the 0mq context. * * The context is thread safe an may be used anywhere in your application, * however there is no requirement (other than inproc restrictions) for you * to do this. */ context() #endif : _context(nullptr) { #if (ZMQ_VERSION_MAJOR < 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR < 2)) _context = zmq_init(threads); #else _context = zmq_ctx_new(); #endif if (nullptr == _context) { throw zmq_internal_exception(); } } /** * Closes the 0mq context. * * Any blocking calls other than a socket close will return with an error. * * If there are open sockets will block while zmq internal buffers are * processed up to a limit specified by that sockets linger option. */ ~context() NOEXCEPT { if (nullptr != _context) { terminate(); } } /** * Move supporting constructor. * * Allows zero-copy move semantics to be used with this class. * * \param source a rvalue instance of the object who's internals we wish to steal. */ context(context&& source) NOEXCEPT : _context(source._context) { source._context = nullptr; } /** * Move supporting operator. * * Allows zero-copy move semantics to be used with this class. * * \param source an rvalue instance of the context who's internals we wish to steal. */ context& operator=(context&& source) NOEXCEPT { std::swap( _context, source._context ); return *this; } /** * Terminate the current context. * * Any blocking calls other than a socket close will return with an error. * * If there are open sockets will block while zmq internal buffers are * processed up to a limit specified by that sockets linger option. */ void terminate(); #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) /** * Set the value of an option in the underlaying zmq context. * * \param option a valid ::context_option * \param value to set the option to */ void set(context_option const option, int const value); /** * Get a context option from the underlaying zmq context. * * \param option a valid ::context_option * \return context option value */ int get(context_option const option); #endif /** * Validity checking of the context * * Checks if the underlying 0mq context for this instance is valid. * * Contexts should always be valid unless people are doing 'fun' things with * std::move. * * \return boolean true if the object is valid. */ operator bool() const NOEXCEPT { return nullptr != _context; } /** * Access to the raw 0mq context * * \return void pointer to the underlying 0mq context. */ operator void*() const NOEXCEPT { return _context; } private: void* _context; // No copy - private and not implemented context(context const&) ZMQPP_EXPLICITLY_DELETED; context& operator=(context const&) NOEXCEPT ZMQPP_EXPLICITLY_DELETED; }; } #endif /* ZMQPP_CONTEXT_HPP_ */ zmqpp-4.1.2/src/zmqpp/context_options.hpp000066400000000000000000000016661254036632700206140ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 3 Jul 2013 * \author Ben Gray (\@benjamg) */ #ifndef ZMQPP_CONTEXT_OPTIONS_HPP_ #define ZMQPP_CONTEXT_OPTIONS_HPP_ namespace zmqpp { /** \todo Expand the information on the options to make it actually useful. */ /*! * \brief possible Context options in zmq */ ZMQPP_COMPARABLE_ENUM context_option { io_threads = ZMQ_IO_THREADS, /*!< I/O thread count */ max_sockets = ZMQ_MAX_SOCKETS, /*!< Maximum supported sockets */ #if (ZMQ_VERSION_MAJOR >= 4) ipv6 = ZMQ_IPV6 /*!< Enable ipv6 for all new sockets */ #endif }; } #endif /* ZMQPP_CONTEXT_OPTIONS_HPP_ */ zmqpp-4.1.2/src/zmqpp/curve.cpp000066400000000000000000000015051254036632700164640ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * Created on: 13 Aug 2014 * Author: Ben Gray (@benjamg) */ #include #include #include "compatibility.hpp" #include "curve.hpp" #include "exception.hpp" namespace zmqpp { namespace curve { #if (ZMQ_VERSION_MAJOR >= 4) keypair generate_keypair() { char public_key [41]; char secret_key [41]; int result = zmq_curve_keypair( public_key, secret_key ); if (0 != result) { throw zmq_internal_exception(); } return keypair{ public_key, secret_key }; } #endif } // end curve } zmqpp-4.1.2/src/zmqpp/curve.hpp000066400000000000000000000013671254036632700164770ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 13 Aug 2014 * \author Ben Gray (\@benjamg) */ #ifndef ZMQPP_CURVE_HPP_ #define ZMQPP_CURVE_HPP_ #include #include namespace zmqpp { /** * ZMQ curve facilities. */ namespace curve { /** * A pair of public and private key. */ struct keypair { std::string public_key; std::string secret_key; }; #if (ZMQ_VERSION_MAJOR >= 4) keypair generate_keypair(); #endif } } #endif /* ZMQPP_CURVE_HPP_ */ zmqpp-4.1.2/src/zmqpp/exception.hpp000066400000000000000000000047221254036632700173470ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 9 Aug 2011 * \author Ben Gray (\@benjamg) */ #ifndef ZMQPP_EXCEPTION_HPP_ #define ZMQPP_EXCEPTION_HPP_ #include #include #include namespace zmqpp { /** \todo Have a larger variety of exceptions with better state debug information */ /** * Represents the base zmqpp exception. * * All zmqpp runtime exceptions are children of this class. * The class itself does not provide any special access fields but it only * for convince when catching exceptions. * * The class extends std::runtime_error. * */ class exception : public std::runtime_error { public: /** * Standard exception constructor. * * \param message a string representing the error message. */ exception(std::string const& message) : std::runtime_error(message) { } }; /** * Represents an attempt to use an invalid object. * * Objects may be invalid initially or after a shutdown or close. */ class invalid_instance : public exception { public: invalid_instance(std::string const& message) : exception(message) { } }; /** * Represents a failed zmqpp::actor initialization. */ class actor_initialization_exception : public exception { public: actor_initialization_exception() : exception("Actor Initialization Exception") { } }; /** * Thrown when an error occurs while encoding or decoding to/from z85. * See ZMQ RFC 32 */ class z85_exception : public exception { public: z85_exception(const std::string &msg): exception(msg) { } }; /** * Represents internal zmq errors. * * Any error response from the zmq bindings will be wrapped in this error. * * The class provides access to the zmq error number via zmq_error(). */ class zmq_internal_exception : public exception { public: /** * Uses the zmq functions to pull out error messages and numbers. */ zmq_internal_exception() : exception(zmq_strerror(zmq_errno())) , _error(zmq_errno()) { } /** * Retrieve the zmq error number associated with this exception. * \return zmq error number */ int zmq_error() const { return _error; } private: int _error; }; } #endif /* ZMQPP_EXCEPTION_HPP_ */ zmqpp-4.1.2/src/zmqpp/frame.cpp000066400000000000000000000035301254036632700164320ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 8 Jan 2014 * \author Ben Gray (\@benjamg) */ #include #include #include "exception.hpp" #include "frame.hpp" namespace zmqpp { frame::frame() : _sent( false ) { if( 0 != zmq_msg_init( &_msg ) ) { throw zmq_internal_exception(); } } frame::frame(size_t const size) : _sent( false ) { if( 0 != zmq_msg_init_size( &_msg, size ) ) { throw zmq_internal_exception(); } } frame::frame(void const* part, size_t const size) : _sent( false ) { if( 0 != zmq_msg_init_size( &_msg, size ) ) { throw zmq_internal_exception(); } void* msg_data = zmq_msg_data( &_msg ); memcpy( msg_data, part, size ); } frame::frame(void* part, size_t const size, zmq_free_fn *ffn, void *hint) : _sent( false ) { if( 0 != zmq_msg_init_data( &_msg, part, size, ffn, hint ) ) { throw zmq_internal_exception(); } } frame::~frame() { #ifndef NDEBUG // unused assert variable in release int result = zmq_msg_close( &_msg ); assert(0 == result); #else zmq_msg_close( &_msg ); #endif // NDEBUG } frame::frame(frame&& other) : _sent( other._sent ) { zmq_msg_init( &_msg ); zmq_msg_move( &_msg, &other._msg ); other._sent = false; } frame& frame::operator=(frame&& other) { zmq_msg_init( &_msg ); zmq_msg_move( &_msg, &other._msg ); std::swap( _sent, other._sent ); return *this; } frame frame::copy() const { frame other( size() ); other._sent = _sent; if( 0 != zmq_msg_copy( &other._msg, const_cast(&_msg) ) ) { throw zmq_internal_exception(); } return other; } } // namespace zmqpp zmqpp-4.1.2/src/zmqpp/frame.hpp000066400000000000000000000031571254036632700164440ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 8 Jan 2014 * \author Ben Gray (\@benjamg) */ #ifndef ZMQPP_MESSAGE_FRAME_HPP_ #define ZMQPP_MESSAGE_FRAME_HPP_ #include #include "compatibility.hpp" namespace zmqpp { /*! * \brief an internal frame wrapper for a single zmq message * * This frame wrapper consists of a zmq message and meta data it is used * by the zmqpp message class to keep track of parts in the internal * queue. It is unlikely you need to use this class. */ class frame { public: frame(); frame(size_t const size); frame(void const* part, size_t const size); frame(void* part, size_t const size, zmq_free_fn *ffn, void *hint); ~frame(); bool is_sent() const { return _sent; } void const* data() const { return zmq_msg_data( const_cast(&_msg) ); } size_t size() const { return zmq_msg_size( const_cast(&_msg) ); } void mark_sent() { _sent = true; } zmq_msg_t& msg() { return _msg; } // Move operators frame(frame&& other); frame& operator=(frame&& other); frame copy() const; private: bool _sent; zmq_msg_t _msg; // Disable implicit copy support, code must request a copy to clone frame(frame const&) NOEXCEPT ZMQPP_EXPLICITLY_DELETED; frame& operator=(frame const&) NOEXCEPT ZMQPP_EXPLICITLY_DELETED; }; } // namespace zmqpp #endif /* ZMQPP_MESSAGE_FRAME_HPP_ */ zmqpp-4.1.2/src/zmqpp/inet.hpp000066400000000000000000000106041254036632700163040ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 10 Aug 2011 * \author Ben Gray (\@benjamg) */ #ifndef ZMQPP_INET_HPP_ #define ZMQPP_INET_HPP_ #include /** \todo cross-platform version of including headers. */ // We get htons and htonl from here #ifdef _WIN32 #include #else #include #endif #include "compatibility.hpp" namespace zmqpp { /*! * \brief Possible byte order types. * * An enumeration of all the known order types, all two of them. * There is also an entry for unknown which is just used as a default. */ ZMQPP_COMPARABLE_ENUM order { big_endian, /*!< byte order is big endian */ little_endian /*!< byte order is little endian */ }; /*! * Common code for the 64bit versions of htons/htons and ntohs/ntohl * * As htons and ntohs (or htonl and ntohs) always just do the same thing, ie * swap bytes if the host order differs from network order or otherwise don't * do anything, it seemed silly to type the code twice. * * \note This code assumes network order is always big endian. Which it is. * \note The host endian is only checked once and afterwards assumed to remain * the same. * * \param value_to_check unsigned 64 bit integer to swap * \return swapped (or not) unsigned 64 bit integer */ inline uint64_t swap_if_needed(uint64_t const value_to_check) { static order host_order = (htonl(42) == 42) ? order::big_endian : order::little_endian; if (order::big_endian == host_order) { return value_to_check; } union { uint64_t integer; uint8_t bytes[8]; } value { value_to_check }; std::swap(value.bytes[0], value.bytes[7]); std::swap(value.bytes[1], value.bytes[6]); std::swap(value.bytes[2], value.bytes[5]); std::swap(value.bytes[3], value.bytes[4]); return value.integer; } /*! * 64 bit version of the htons/htonl * * I've used the name htonll to try and keep with the htonl naming scheme. * We do not define this function if the macro `htonll` exists. * * \param hostlonglong unsigned 64 bit host order integer * \return unsigned 64 bit network order integer */ #ifndef htonll inline uint64_t htonll(uint64_t const hostlonglong) { return zmqpp::swap_if_needed(hostlonglong); } #endif /*! * 64 bit version of the ntohs/ntohl * * I've used the name htonll to try and keep with the htonl naming scheme. * We do not define this function if the macro `ntohll` exists. * * \param networklonglong unsigned 64 bit network order integer * \return unsigned 64 bit host order integer */ #ifndef ntohll inline uint64_t ntohll(uint64_t const networklonglong) { return zmqpp::swap_if_needed(networklonglong); } #endif /*! * floating point version of the htons/htonl * * \param value host order floating point * \returns network order floating point */ inline float htonf(float value) { assert(sizeof(float) == sizeof(uint32_t)); uint32_t temp; memcpy(&temp, &value, sizeof(uint32_t)); temp = htonl( temp ); memcpy(&value, &temp, sizeof(uint32_t)); return value; } /*! * floating point version of the ntohs/ntohl * * \param value network order float * \returns host order float */ inline float ntohf(float value) { assert(sizeof(float) == sizeof(uint32_t)); uint32_t temp; memcpy(&temp, &value, sizeof(uint32_t)); temp = ntohl( temp ); memcpy(&value, &temp, sizeof(uint32_t)); return value; } /*! * double precision floating point version of the htons/htonl * * \param value host order double precision floating point * \returns network order double precision floating point */ inline double htond(double value) { assert(sizeof(double) == sizeof(uint64_t)); uint64_t temp; memcpy(&temp, &value, sizeof(uint64_t)); temp = htonll(temp); memcpy(&value, &temp, sizeof(uint64_t)); return value; } /*! * double precision floating point version of the ntohs/ntohl * * \param value network order double precision floating point * \returns host order double precision floating point */ inline double ntohd(double value) { assert(sizeof(double) == sizeof(uint64_t)); uint64_t temp; memcpy(&temp, &value, sizeof(uint64_t)); temp = ntohll(temp); memcpy(&value, &temp, sizeof(uint64_t)); return value; } } #endif /* INET_HPP_ */ zmqpp-4.1.2/src/zmqpp/message.cpp000066400000000000000000000275061254036632700167750ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * Created on: 9 Aug 2011 * Author: Ben Gray (@benjamg) */ #include #include #include "exception.hpp" #include "inet.hpp" #include "message.hpp" namespace zmqpp { /*! * \brief internal construct * \internal handles bubbling callback from zmq c style to the c++ functor provided */ struct callback_releaser { message::release_function func; }; message::message() : _parts() , _read_cursor(0) { } message::~message() { _parts.clear(); } size_t message::parts() const { return _parts.size(); } /* * The two const_casts in size and raw_data are a little bit hacky * but neither of these methods called this way actually modify data * so accurately represent the intent of these calls. */ size_t message::size(size_t const part /* = 0 */) const { if(part >= _parts.size()) { throw exception("attempting to request a message part outside the valid range"); } return _parts[part].size(); } void const* message::raw_data(size_t const part /* = 0 */) const { if(part >= _parts.size()) { throw exception("attempting to request a message part outside the valid range"); } return _parts[part].data(); } zmq_msg_t& message::raw_msg(size_t const part /* = 0 */) { if(part >= _parts.size()) { throw exception("attempting to request a message part outside the valid range"); } return _parts[part].msg(); } zmq_msg_t& message::raw_new_msg() { _parts.push_back( frame() ); return _parts.back().msg(); } zmq_msg_t& message::raw_new_msg(size_t const reserve_data_size) { _parts.push_back( frame(reserve_data_size) ); return _parts.back().msg(); } std::string message::get(size_t const part /* = 0 */) const { return std::string(static_cast(raw_data(part)), size(part)); } // Move operators will take ownership of message parts without copying void message::move(void* part, size_t const size, release_function const& release) { callback_releaser* hint = new callback_releaser(); hint->func = release; _parts.push_back( frame( part, size, &message::release_callback, hint ) ); } // Stream reader style void message::reset_read_cursor() { _read_cursor = 0; } void message::get(int8_t& integer, size_t const part) const { assert(sizeof(int8_t) == size(part)); int8_t const* byte = static_cast(raw_data(part)); integer = *byte; } void message::get(int16_t& integer, size_t const part) const { assert(sizeof(int16_t) == size(part)); uint16_t const* network_order = static_cast(raw_data(part)); integer = static_cast(ntohs(*network_order)); } void message::get(int32_t& integer, size_t const part) const { assert(sizeof(int32_t) == size(part)); uint32_t const* network_order = static_cast(raw_data(part)); integer = static_cast(htonl(*network_order)); } void message::get(int64_t& integer, size_t const part) const { assert(sizeof(int64_t) == size(part)); uint64_t const* network_order = static_cast(raw_data(part)); integer = static_cast(htonll(*network_order)); } void message::get(signal &sig, size_t const part) const { assert(sizeof(signal) == size(part)); int64_t v; get(v, part); sig = static_cast(v); } void message::get(uint8_t& unsigned_integer, size_t const part) const { assert(sizeof(uint8_t) == size(part)); uint8_t const* byte = static_cast(raw_data(part)); unsigned_integer = *byte; } void message::get(uint16_t& unsigned_integer, size_t const part) const { assert(sizeof(uint16_t) == size(part)); uint16_t const* network_order = static_cast(raw_data(part)); unsigned_integer = ntohs(*network_order); } void message::get(uint32_t& unsigned_integer, size_t const part) const { assert(sizeof(uint32_t) == size(part)); uint32_t const* network_order = static_cast(raw_data(part)); unsigned_integer = ntohl(*network_order); } void message::get(uint64_t& unsigned_integer, size_t const part) const { assert(sizeof(uint64_t) == size(part)); uint64_t const* network_order = static_cast(raw_data(part)); unsigned_integer = ntohll(*network_order); } void message::get(float& floating_point, size_t const part) const { assert(sizeof(float) == size(part)); float const* network_order = static_cast(raw_data(part)); floating_point = zmqpp::ntohf(*network_order); } void message::get(double& double_precision, size_t const part) const { assert(sizeof(double) == size(part)); double const* network_order = static_cast(raw_data(part)); double_precision = zmqpp::ntohd(*network_order); } void message::get(bool& boolean, size_t const part) const { assert(sizeof(uint8_t) == size(part)); uint8_t const* byte = static_cast(raw_data(part)); boolean = (*byte != 0); } void message::get(std::string& string, size_t const part) const { string.assign( get(part) ); } // Stream writer style - these all use copy styles message& message::operator<<(int8_t const integer) { add_raw(reinterpret_cast(&integer), sizeof(int8_t)); return *this; } message& message::operator<<(int16_t const integer) { uint16_t network_order = htons(static_cast(integer)); add_raw(reinterpret_cast(&network_order), sizeof(uint16_t)); return *this; } message& message::operator<<(int32_t const integer) { uint32_t network_order = htonl(static_cast(integer)); add_raw(reinterpret_cast(&network_order), sizeof(uint32_t)); return *this; } message& message::operator<<(int64_t const integer) { uint64_t network_order = htonll(static_cast(integer)); add_raw(reinterpret_cast(&network_order), sizeof(uint64_t)); return *this; } message &message::operator<<(signal const sig) { return (*this) << static_cast(sig); } message& message::operator<<(uint8_t const unsigned_integer) { add_raw(reinterpret_cast(&unsigned_integer), sizeof(uint8_t)); return *this; } message& message::operator<<(uint16_t const unsigned_integer) { uint16_t network_order = htons(unsigned_integer); add_raw(reinterpret_cast(&network_order), sizeof(uint16_t)); return *this; } message& message::operator<<(uint32_t const unsigned_integer) { uint32_t network_order = htonl(unsigned_integer); add_raw(reinterpret_cast(&network_order), sizeof(uint32_t)); return *this; } message& message::operator<<(uint64_t const unsigned_integer) { uint64_t network_order = htonll(unsigned_integer); add_raw(reinterpret_cast(&network_order), sizeof(uint64_t)); return *this; } message& message::operator<<(float const floating_point) { assert(sizeof(float) == 4); float network_order = zmqpp::htonf(floating_point); add_raw(&network_order, sizeof(float)); return *this; } message& message::operator<<(double const double_precision) { assert(sizeof(double) == 8); double network_order = zmqpp::htond(double_precision); add_raw(&network_order, sizeof(double)); return *this; } message& message::operator<<(bool const boolean) { uint8_t byte = (boolean) ? 1 : 0; add_raw(reinterpret_cast(&byte), sizeof(uint8_t)); return *this; } message& message::operator<<(char const* c_string) { add_raw(reinterpret_cast(c_string), strlen(c_string)); return *this; } message& message::operator<<(std::string const& string) { add_raw(reinterpret_cast(string.data()), string.size()); return *this; } void message::push_front(void const* part, size_t const size) { _parts.emplace( _parts.begin(), part, size ); } void message::push_front(int8_t const integer) { push_front(&integer, sizeof(int8_t)); } void message::push_front(int16_t const integer) { uint16_t network_order = htons(static_cast(integer)); push_front(&network_order, sizeof(uint16_t)); } void message::push_front(int32_t const integer) { uint32_t network_order = htonl(static_cast(integer)); push_front(&network_order, sizeof(uint32_t)); } void message::push_front(int64_t const integer) { uint64_t network_order = htonll(static_cast(integer)); push_front(&network_order, sizeof(uint64_t)); } void message::push_front(signal const sig) { push_front(static_cast(sig)); } void message::push_front(uint8_t const unsigned_integer) { push_front(&unsigned_integer, sizeof(uint8_t)); } void message::push_front(uint16_t const unsigned_integer) { uint16_t network_order = htons(unsigned_integer); push_front(&network_order, sizeof(uint16_t)); } void message::push_front(uint32_t const unsigned_integer) { uint32_t network_order = htonl(unsigned_integer); push_front(&network_order, sizeof(uint32_t)); } void message::push_front(uint64_t const unsigned_integer) { uint64_t network_order = htonll(unsigned_integer); push_front(&network_order, sizeof(uint64_t)); } void message::push_front(float const floating_point) { assert(sizeof(float) == 4); float network_order = zmqpp::htonf(floating_point); push_front(&network_order, sizeof(float)); } void message::push_front(double const double_precision) { assert(sizeof(double) == 8); double network_order = zmqpp::htond(double_precision); push_front(&network_order, sizeof(double)); } void message::push_front(bool const boolean) { uint8_t byte = (boolean) ? 1 : 0; push_front(&byte, sizeof(uint8_t)); } void message::push_front(char const* c_string) { push_front(c_string, strlen(c_string)); } void message::push_front(std::string const& string) { push_front(string.data(), string.size()); } void message::pop_front() { _parts.erase( _parts.begin() ); } void message::pop_back() { _parts.pop_back(); } message::message(message&& source) NOEXCEPT : _parts() , _read_cursor(source._read_cursor) { std::swap(_parts, source._parts); source._read_cursor = 0; } message& message::operator=(message&& source) NOEXCEPT { _read_cursor = source._read_cursor; source._read_cursor = 0; _parts = std::move(source._parts); return *this; } message message::copy() const { message msg; msg.copy(*this); return msg; } void message::copy(message const& source) { _parts.resize( source._parts.size() ); for(size_t i = 0; i < source._parts.size(); ++i) { _parts[i] = source._parts[i].copy(); } // we don't need a copy of the releasers as we did data copies of the internal data, //_releasers = source._releasers; //_strings = source._strings } // Used for internal tracking void message::sent(size_t const part) { // sanity check assert(!_parts[part].is_sent()); _parts[part].mark_sent(); } // Note that these releasers are not thread safe, the only safety is provided by // the socket class taking ownership so no updates can happen while zmq does it's thing // If used in a custom class this has to be dealt with. void message::release_callback(void* data, void* hint) { callback_releaser* releaser = static_cast(hint); releaser->func(data); delete releaser; } bool message::is_signal() const { if (parts() == 1 && size(0) == sizeof(signal)) { signal s; get(s, 0); if ((static_cast(s) >> 8) == static_cast(signal::header)) return true; } return false; } #if (ZMQ_VERSION_MAJOR == 4 && ZMQ_VERSION_MINOR >= 1) bool message::get_property(const std::string &property, std::string &out) { zmq_msg_t *zmq_raw_msg; try { zmq_raw_msg = &raw_msg(); } catch (zmqpp::exception const&) // empty { return false; } const char *property_value = zmq_msg_gets(zmq_raw_msg, property.c_str()); if (property_value == NULL) { // EINVAL is the only error code assert(errno == EINVAL); return false; } out = std::string(property_value); return true; } #endif } zmqpp-4.1.2/src/zmqpp/message.hpp000066400000000000000000000206631254036632700167770ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 9 Aug 2011 * \author Ben Gray (\@benjamg) */ #ifndef ZMQPP_MESSAGE_HPP_ #define ZMQPP_MESSAGE_HPP_ #include #include #include #include #include #include #include #include "compatibility.hpp" #include "frame.hpp" #include "signal.hpp" namespace zmqpp { /** * \brief a zmq message with optional multipart support * * A zmq message is made up of one or more parts which are sent together to * the target endpoints. zmq guarantees either the whole message or none * of the message will be delivered. */ class message { public: /** * \brief callback to release user allocated data. * * The release function will be called on any void* moved part. * It must be thread safe to the extent that the callback may occur on * one of the context threads. * * The function called will be passed a single variable which is the * pointer to the memory allocated. */ typedef std::function release_function; message(); ~message(); template message(T const &part, Args &&...args) : message() { add(part, std::forward(args)...); } size_t parts() const; size_t size(size_t const part) const; std::string get(size_t const part) const; void get(int8_t& integer, size_t const part) const; void get(int16_t& integer, size_t const part) const; void get(int32_t& integer, size_t const part) const; void get(int64_t& integer, size_t const part) const; void get(signal& sig, size_t const part) const; void get(uint8_t& unsigned_integer, size_t const part) const; void get(uint16_t& unsigned_integer, size_t const part) const; void get(uint32_t& unsigned_integer, size_t const part) const; void get(uint64_t& unsigned_integer, size_t const part) const; void get(float& floating_point, size_t const part) const; void get(double& double_precision, size_t const part) const; void get(bool& boolean, size_t const part) const; void get(std::string& string, size_t const part) const; // Warn: If a pointer type is requested the message (well zmq) still 'owns' // the data and will release it when the message object is freed. template Type get(size_t const part) { Type value; get(value, part); return value; } template void extract(T &nextpart, Args &...args) { assert(part < parts()); get(nextpart,part); extract(args...); } template void extract(T &nextpart) { assert(part < parts()); get(nextpart,part); } // Raw get data operations, useful with data structures more than anything else // Warn: The message (well zmq) still 'owns' the data and will release it // when the message object is freed. template void get(Type*& value, size_t const part) const { value = static_cast(raw_data(part)); } // Warn: The message (well zmq) still 'owns' the data and will release it // when the message object is freed. template void get(Type** value, size_t const part) const { *value = static_cast(raw_data(part)); } // Move operators will take ownership of message parts without copying void move(void* part, size_t const size, release_function const& release); // Raw move data operation, useful with data structures more than anything else template void move(Object *part) { move(part, sizeof(Object), &deleter_callback); } // Copy operators will take copies of any data template void add(Type const& part, Args &&...args) { *this << part; add(std::forward(args)...); } template void add(Type const part) { *this << part; } // Copy operators will take copies of any data with a given size template void add_raw(Type *part, size_t const data_size) { _parts.push_back( frame( part, data_size ) ); } // Use exact data past, neither zmqpp nor 0mq will copy, alter or delete // this data. It must remain as valid for at least the lifetime of the // 0mq message, recommended only with const data. template void add_const(Type *part, size_t const data_size) { _parts.push_back( frame( part, data_size, nullptr, nullptr ) ); } // Stream reader style void reset_read_cursor(); template message& operator>>(Type& value) { get(value, _read_cursor++); return *this; } // Stream writer style - these all use copy styles message& operator<<(int8_t const integer); message& operator<<(int16_t const integer); message& operator<<(int32_t const integer); message& operator<<(int64_t const integer); message& operator<<(signal const sig); message& operator<<(uint8_t const unsigned_integer); message& operator<<(uint16_t const unsigned_integer); message& operator<<(uint32_t const unsigned_integer); message& operator<<(uint64_t const unsigned_integer); message& operator<<(float const floating_point); message& operator<<(double const double_precision); message& operator<<(bool const boolean); message& operator<<(char const* c_string); message& operator<<(std::string const& string); // Queue manipulation void push_front(void const* part, size_t const size); // TODO: unify conversion of types with the stream operators void push_front(int8_t const integer); void push_front(int16_t const integer); void push_front(int32_t const integer); void push_front(int64_t const integer); void push_front(signal const sig); void push_front(uint8_t const unsigned_integer); void push_front(uint16_t const unsigned_integer); void push_front(uint32_t const unsigned_integer); void push_front(uint64_t const unsigned_integer); void push_front(float const floating_point); void push_front(double const double_precision); void push_front(bool const boolean); void push_front(char const* c_string); void push_front(std::string const& string); void pop_front(); void push_back(void const* part, size_t const data_size) { add_raw( part, data_size ); } template void push_back(Type const part) { *this << part; } void pop_back(); void remove(size_t const part); // Move supporting message(message&& source) NOEXCEPT; message& operator=(message&& source) NOEXCEPT; // Copy support message copy() const; void copy(message const& source); // Used for internal tracking void sent(size_t const part); // Access to raw zmq details void const* raw_data(size_t const part = 0) const; zmq_msg_t& raw_msg(size_t const part = 0); zmq_msg_t& raw_new_msg(); zmq_msg_t& raw_new_msg(size_t const reserve_data_size); /** * Check if the message is a signal. * If the message has 1 part, has the correct size and if the 7 first bytes match * the signal header we consider the message a signal. * @return true if the message is a signal, false otherwise */ bool is_signal() const; /** * Gets the read cursor. For using get_raw() with stream-style reading. */ size_t read_cursor() const NOEXCEPT { return _read_cursor; } /** * Gets the remaining number of parts in the message. */ size_t remaining() const NOEXCEPT { return _parts.size() - _read_cursor; } /** * Moves the read cursor to the next element. * @return the new read_cursor */ size_t next() NOEXCEPT { return ++_read_cursor; } #if (ZMQ_VERSION_MAJOR == 4 && ZMQ_VERSION_MINOR >= 1) /** * Attemps to retrieve a metadata property from a message. * The underlying call is `zmq_msg_gets()`. * * @note The message MUST have at least one frame, otherwise this wont work. */ bool get_property(const std::string &property, std::string &out); #endif private: typedef std::vector parts_type; parts_type _parts; size_t _read_cursor; // Disable implicit copy support, code must request a copy to clone message(message const&) NOEXCEPT ZMQPP_EXPLICITLY_DELETED; message& operator=(message const&) NOEXCEPT ZMQPP_EXPLICITLY_DELETED; static void release_callback(void* data, void* hint); template static void deleter_callback(void* data) { delete static_cast(data); } }; } #endif /* ZMQPP_MESSAGE_HPP_ */ zmqpp-4.1.2/src/zmqpp/poller.cpp000066400000000000000000000120261254036632700166350ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * Created on: 16 Aug 2011 * Author: Ben Gray (@benjamg) */ #include "exception.hpp" #include "socket.hpp" #include "poller.hpp" #include namespace zmqpp { const long poller::wait_forever = -1; const short poller::poll_none = 0; const short poller::poll_in = ZMQ_POLLIN; const short poller::poll_out = ZMQ_POLLOUT; const short poller::poll_error = ZMQ_POLLERR; #if ((ZMQ_VERSION_MAJOR == 4 && ZMQ_VERSION_MINOR >= 2) || ZMQ_VERSION_MAJOR > 4) const short poller::poll_pri = ZMQ_POLLPRI; #endif poller::poller() : _items() , _index() , _fdindex() { } poller::~poller() { _items.clear(); _index.clear(); _fdindex.clear(); } void poller::add(socket& socket, short const event /* = POLL_IN */) { zmq_pollitem_t const item { socket, 0, event, 0 }; add(item); } void poller::add(raw_socket_t const descriptor, short const event /* = POLL_IN */) { zmq_pollitem_t const item { nullptr, descriptor, event, 0 }; add(item); } void poller::add(zmq_pollitem_t const& item) { size_t index = _items.size(); _items.push_back(item); if (nullptr == item.socket) _fdindex[item.fd] = index; else _index[item.socket] = index; } bool poller::has(socket_t const& socket) { return _index.find(socket) != _index.end(); } bool poller::has(raw_socket_t const descriptor) { return _fdindex.find(descriptor) != _fdindex.end(); } bool poller::has(zmq_pollitem_t const& item) { if (nullptr != item.socket) return _index.find(item.socket) != _index.end(); return _fdindex.find(item.fd) != _fdindex.end(); } void poller::reindex(size_t const index) { if ( nullptr != _items[index].socket ) { auto found = _index.find( _items[index].socket ); if (_index.end() == found) { throw exception("unable to reindex socket in poller"); } found->second = index; } else { auto found = _fdindex.find( _items[index].fd ); if (_fdindex.end() == found) { throw exception("unable to reindex file descriptor in poller"); } found->second = index; } } void poller::remove(socket_t const& socket) { zmq_pollitem_t const item{ socket, 0, 0, 0 }; remove(item); } void poller::remove(raw_socket_t const descriptor) { zmq_pollitem_t const item{ nullptr, descriptor, 0, 0 }; remove(item); } void poller::remove(zmq_pollitem_t const& item) { if (nullptr == item.socket) return remove(item.fd); auto found = _index.find(item.socket); if (_index.end() == found) { return; } if ( _items.size() - 1 == found->second ) { _items.pop_back(); _index.erase(found); return; } std::swap(_items[found->second], _items.back()); _items.pop_back(); auto index = found->second; _index.erase(found); reindex( index ); } void poller::check_for(socket const& socket, short const event) { auto found = _index.find(socket); if (_index.end() == found) { throw exception("this socket is not represented within this poller"); } _items[found->second].events = event; } void poller::check_for(raw_socket_t const descriptor, short const event) { auto found = _fdindex.find(descriptor); if (_fdindex.end() == found) { throw exception("this standard socket is not represented within this poller"); } _items[found->second].events = event; } void poller::check_for(zmq_pollitem_t const& item, short const event) { if (nullptr == item.socket) check_for(item.fd, event); else { auto found = _index.find(item.socket); if (_index.end() == found) { throw exception("this socket is not represented within this poller"); } _items[found->second].events = event; } } bool poller::poll(long timeout /* = WAIT_FOREVER */) { int result = zmq_poll(_items.data(), _items.size(), timeout); if (result < 0) { if(EINTR == zmq_errno()) { return false; } throw zmq_internal_exception(); } return (result > 0); } short poller::events(socket const& socket) const { auto found = _index.find(socket); if (_index.end() == found) { throw exception("this socket is not represented within this poller"); } return _items[found->second].revents; } short poller::events(raw_socket_t const descriptor) const { auto found = _fdindex.find(descriptor); if (_fdindex.end() == found) { throw exception("this standard socket is not represented within this poller"); } return _items[found->second].revents; } short poller::events(zmq_pollitem_t const& item) const { if (nullptr == item.socket) { return events(item.fd); } auto found = _index.find(item.socket); if (_index.end() == found) { throw exception("this socket is not represented within this poller"); } return _items[found->second].revents; } } zmqpp-4.1.2/src/zmqpp/poller.hpp000066400000000000000000000154641254036632700166530ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 9 Aug 2011 * \author Ben Gray (\@benjamg) */ #ifndef ZMQPP_POLLER_HPP_ #define ZMQPP_POLLER_HPP_ #include #include #include "compatibility.hpp" namespace zmqpp { class socket; typedef socket socket_t; /** * Polling wrapper. * * Allows access to polling for any number of zmq sockets or standard sockets. */ class poller { public: static const long wait_forever; /*!< Block forever flag, default setting. */ static const short poll_none; /*!< No polling flags set. */ static const short poll_in; /*!< Monitor inbound flag. */ static const short poll_out; /*!< Monitor output flag. */ static const short poll_error; /*!< Monitor error flag.\n Only for file descriptors. */ #if ((ZMQ_VERSION_MAJOR == 4 && ZMQ_VERSION_MINOR >= 2) || ZMQ_VERSION_MAJOR > 4) static const short poll_pri; /*!< Priority input flag.\n Only for file descriptors. See POLLPRI) */ #endif /** * Construct an empty polling model. */ poller(); /** * Cleanup poller. * * Any sockets will need to be closed separately. */ ~poller(); /** * Add a socket to the polling model and set which events to monitor. * * \param socket the socket to monitor. * \param event the event flags to monitor on the socket. */ void add(socket_t& socket, short const event = poll_in); /** * Add a standard socket to the polling model and set which events to monitor. * * \param descriptor the raw socket to monitor (SOCKET under Windows, a file descriptor otherwise). * \param event the event flags to monitor. */ void add(raw_socket_t const descriptor, short const event = poll_in | poll_error); /** * Add a zmq_pollitem_t to the poller; Events to monitor are already configured. * If the zmq_pollitem_t has a null socket pointer it is added to the fdindex, * otherwise it is added to the socket index. * * \param item the pollitem to be added */ void add(zmq_pollitem_t const& item); /** * Check if we are monitoring a given socket with this poller. * * \param socket the socket to check. * \return true if it is there. */ bool has(socket_t const& socket); /** * Check if we are monitoring a given standard socket with this poller. * * \param descriptor the raw socket to check for. * \return true if it is there. */ bool has(raw_socket_t const descriptor); /** * Check if we are monitoring a given pollitem. * We assume the pollitem is a socket if it's socket is a non null pointer; otherwise, * it is considered as a file descriptor. * * \param item the pollitem to check for * \return true if it is there. */ bool has(zmq_pollitem_t const& item); /** * Stop monitoring a socket. * * \param socket the socket to stop monitoring. */ void remove(socket_t const& socket); /** * Stop monitoring a standard socket. * * \param descriptor the raw socket to stop monitoring (SOCKET under Windows, a file descriptor otherwise). */ void remove(raw_socket_t const descriptor); /** * Stop monitoring a zmq_pollitem_t * * \param item the pollitem to stop monitoring. */ void remove(zmq_pollitem_t const& item); /** * Update the monitored event flags for a given socket. * * \param socket the socket to update event flags. * \param event the event flags to monitor on the socket. */ void check_for(socket_t const& socket, short const event); /*! * Update the monitored event flags for a given standard socket. * * \param descriptor the raw socket to update event flags (SOCKET under Windows, a file descriptor otherwise). * \param event the event flags to monitor on the socket. */ void check_for(raw_socket_t const descriptor, short const event); /** * Update the monitored event flags for a given zmq_pollitem_t * * \param item the item to change event flags for. * \param event the event flags to monitor on the socket. */ void check_for(zmq_pollitem_t const& item, short const event); /** * Poll for monitored events. * * By default this method will block forever or until at least one of the monitored * sockets or file descriptors has events. * * If a timeout is set and was reached then this function returns false. * * \param timeout milliseconds to timeout. * \return true if there is an event.. */ bool poll(long timeout = wait_forever); /** * Get the event flags triggered for a socket. * * \param socket the socket to get triggered event flags for. * \return the event flags. */ short events(socket_t const& socket) const; /** * Get the event flags triggered for a standard socket. * * \param descriptor the raw socket to get triggered event flags for (SOCKET under Windows, a file descriptor otherwise). * \return the event flags. */ short events(raw_socket_t const descriptor) const; /** * Get the event flags triggered for a zmq_pollitem_t * * \param item the pollitem to get triggered event flags for. * \return the event flags. */ short events(zmq_pollitem_t const& item) const; /** * Check either a standard socket or zmq socket for input events. * * Templated helper method that calls through to event and checks for a given flag * * \param watchable either a standard socket or socket known to the poller. * \return true if there is input. */ template bool has_input(Watched const& watchable) const { return (events(watchable) & poll_in) != 0; } /** * Check either a standard socket or zmq socket for output events. * * Templated helper method that calls through to event and checks for a given flag * * \param watchable either a standard socket or zmq socket known to the poller. * \return true if there is output. */ template bool has_output(Watched const& watchable) const { return (events(watchable) & poll_out) != 0; } /** * Check a standard socket (file descriptor or SOCKET). * * Templated helper method that calls through to event and checks for a given flag * * Technically this template works for sockets as well but the error flag is never set for * sockets so I have no idea why someone would call it. * * \param watchable a standard socket known to the poller. * \return true if there is an error. */ template bool has_error(Watched const& watchable) const { return (events(watchable) & poll_error) != 0; } private: std::vector _items; std::unordered_map _index; std::unordered_map _fdindex; void reindex(size_t const index); }; } #endif /* ZMQPP_POLLER_HPP_ */ zmqpp-4.1.2/src/zmqpp/reactor.cpp000066400000000000000000000077221254036632700170060ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * Created on: 16 Aug 2011 * Author: Ben Gray (@benjamg) */ #include "exception.hpp" #include "socket.hpp" #include "reactor.hpp" #include #include namespace zmqpp { reactor::reactor() : dispatching_(false) { } reactor::~reactor() { } void reactor::add(socket& socket, Callable callable, short const event /* = POLL_IN */) { zmq_pollitem_t item{static_cast (socket), 0, event, 0}; add(item, callable); } void reactor::add(raw_socket_t const descriptor, Callable callable, short const event /* = POLL_IN */) { zmq_pollitem_t item{nullptr, descriptor, event, 0}; add(item, callable); } void reactor::add(const zmq_pollitem_t& item, Callable callable) { poller_.add(item); items_.push_back(std::make_pair(item, callable)); } bool reactor::has(socket_t const& socket) { return poller_.has(socket); } bool reactor::has(raw_socket_t const descriptor) { return poller_.has(descriptor); } void reactor::remove(socket_t const& socket) { if (dispatching_) { sockRemoveLater_.push_back(&socket); return; } items_.erase(std::remove_if(items_.begin(), items_.end(), [&socket](const PollItemCallablePair & pair) -> bool { const zmq_pollitem_t &item = pair.first; if (nullptr != item.socket && item.socket == static_cast (socket)) { return true; } return false; }), items_.end()); poller_.remove(socket); } void reactor::remove(raw_socket_t const descriptor) { if (dispatching_) { fdRemoveLater_.push_back(descriptor); return; } items_.erase(std::remove_if(items_.begin(), items_.end(), [descriptor](const PollItemCallablePair & pair) -> bool { const zmq_pollitem_t &item = pair.first; if (nullptr == item.socket && item.fd == descriptor) { return true; } return false; }), items_.end()); poller_.remove(descriptor); } void reactor::check_for(socket const& socket, short const event) { poller_.check_for(socket, event); } void reactor::check_for(raw_socket_t const descriptor, short const event) { poller_.check_for(descriptor, event); } bool reactor::poll(long timeout /* = WAIT_FOREVER */) { if (poller_.poll(timeout)) { dispatching_ = true; for (const PollItemCallablePair &pair : items_) { const zmq_pollitem_t &pollitem = pair.first; if (poller_.has_input(pollitem) || poller_.has_error(pollitem) || poller_.has_output(pollitem)) pair.second(); } dispatching_ = false; flush_remove_later(); return true; } return false; } short reactor::events(socket const& socket) const { return poller_.events(socket); } short reactor::events(raw_socket_t const descriptor) const { return poller_.events(descriptor); } poller& reactor::get_poller() { return poller_; } const poller& reactor::get_poller() const { return poller_; } void reactor::flush_remove_later() { for (raw_socket_t fd : fdRemoveLater_) remove(fd); for (const socket_t *sock : sockRemoveLater_) remove(*sock); fdRemoveLater_.clear(); sockRemoveLater_.clear(); } } zmqpp-4.1.2/src/zmqpp/reactor.hpp000066400000000000000000000131531254036632700170060ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ #pragma once #include #include #include #include #include "compatibility.hpp" #include "poller.hpp" namespace zmqpp { class socket; typedef socket socket_t; /** * Reactor object that helps to manage multiple socket by calling a user-defined handler for each socket * when a watched event occurs. * * It uses zmq::poller as the underlying polling mechanism. */ class reactor { public: typedef std::function Callable; typedef std::pair PollItemCallablePair; /** * Construct an empty polling model. */ reactor(); /** * Cleanup reactor. * * Any sockets will need to be closed separately. */ ~reactor(); /** * Add a socket to the reactor, providing a handler that will be called when the monitored events occur. * * \param socket the socket to monitor. * \param callable the function that will be called by the reactor when a registered event occurs on socket. * \param event the event flags to monitor on the socket. */ void add(socket_t& socket, Callable callable, short const event = poller::poll_in); /*! * Add a standard socket to the reactor, providing a handler that will be called when the monitored events occur. * * \param descriptor the standard socket to monitor (SOCKET under Windows, a file descriptor otherwise). * \param callable the function that will be called by the reactor when a registered event occurs on fd. * \param event the event flags to monitor. */ void add(raw_socket_t const descriptor, Callable callable, short const event = poller::poll_in | poller::poll_error); /** * Check if we are monitoring a given socket with this reactor. * * \param socket the socket to check. * \return true if it is there. */ bool has(socket_t const& socket); /** * Check if we are monitoring a given standard socket with this reactor. * * \param descriptor the raw socket to check (SOCKET under Windows, a file descriptor otherwise). * \return true if it is there. */ bool has(raw_socket_t const descriptor); /** * Stop monitoring a socket. * * \param socket the socket to stop monitoring. */ void remove(socket_t const& socket); /** * Stop monitoring a standard socket. * * \param descriptor the standard socket to stop monitoring. */ void remove(raw_socket_t const descriptor); /** * Update the monitored event flags for a given socket. * * \param socket the socket to update event flags. * \param event the event flags to monitor on the socket. */ void check_for(socket_t const& socket, short const event); /*! * Update the monitored event flags for a given standard socket. * * \param descriptor the raw socket to update event flags (SOCKET under Windows, a file descriptor otherwise). * \param event the event flags to monitor on the socket. */ void check_for(raw_socket_t const descriptor, short const event); /** * Poll for monitored events and call associated handler when needed. * * By default this method will block forever or until at least one of the monitored * sockets or file descriptors has events. * * If a timeout is set and was reached then this function returns false. * * \param timeout milliseconds to timeout. * \return true if there is an event.. */ bool poll(long timeout = poller::wait_forever); /** * Get the event flags triggered for a socket. * * \param socket the socket to get triggered event flags for. * \return the event flags. */ short events(socket_t const& socket) const; /** * Get the event flags triggered for a standard socket. * * \param descriptor the raw socket to get triggered event flags for (SOCKET under Windows, a file descriptor otherwise). * \return the event flags. */ short events(raw_socket_t const descriptor) const; /** * Get a reference to the underlying poller object used by the reactor. * Not sure this is useful. */ poller &get_poller(); /** * Get a reference to the underlying poller object used by the reactor (const version). * Not sure this is useful either. */ const poller &get_poller() const; protected: void add(const zmq_pollitem_t &item, Callable callable); private: std::vector items_; std::vector sockRemoveLater_; std::vector fdRemoveLater_; /** * Flush the fdRemoveLater_ and sockRemoveLater_ vector, effectively removing * the item for the reactor and poller. */ void flush_remove_later(); poller poller_; bool dispatching_; }; } zmqpp-4.1.2/src/zmqpp/signal.cpp000066400000000000000000000007501254036632700166160ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ #include "signal.hpp" namespace std { ostream &operator<<(ostream &s, const zmqpp::signal &sig) { s << static_cast (sig); return s; } }zmqpp-4.1.2/src/zmqpp/signal.hpp000066400000000000000000000022661254036632700166270ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ #pragma once #include #include #include "compatibility.hpp" namespace zmqpp { /** * Signal is a 8 bytes integer. 7 first bytes acts as a magic number so we can distinguish signal * from other message. The last byte is the signal's value. */ ZMQPP_COMPARABLE_ENUM signal : int64_t { /** * Only 7 bytes matter here */ header = 0x0077665544332211L, /** * Indicates a success. */ ok = (header << 8) | 0x00, /** * Indicates an error. */ ko = (header << 8) | 0x01, /** * Indicates a request to stop. This is used from parent thread to child within the actor class */ stop = (header << 8) | 0x02, test = (header << 8) | 0xFF }; } namespace std { /** * Write the value of the signal to the stream without removing the signal header.. */ ostream &operator<<(ostream &s, const zmqpp::signal &sig); } zmqpp-4.1.2/src/zmqpp/socket.cpp000066400000000000000000000523351254036632700166370ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * Created on: 9 Aug 2011 * Author: Ben Gray (@benjamg) */ #include #include #include #include #include "context.hpp" #include "exception.hpp" #include "message.hpp" #include "socket.hpp" namespace zmqpp { const int socket::normal = 0; #if (ZMQ_VERSION_MAJOR == 2) const int socket::dont_wait = ZMQ_NOBLOCK; #else const int socket::dont_wait = ZMQ_DONTWAIT; #endif const int socket::send_more = ZMQ_SNDMORE; #ifdef ZMQ_EXPERIMENTAL_LABELS const int socket::send_label = ZMQ_SNDLABEL; #endif const int max_socket_option_buffer_size = 256; const int max_stream_buffer_size = 4096; socket::socket(const context& context, socket_type const type) : _socket(nullptr) , _type(type) , _recv_buffer() { _socket = zmq_socket(context, static_cast(type)); if(nullptr == _socket) { throw zmq_internal_exception(); } zmq_msg_init(&_recv_buffer); } socket::~socket() { zmq_msg_close(&_recv_buffer); if (nullptr != _socket) { #ifndef NDEBUG // unused assert variable in release int result = zmq_close(_socket); assert(0 == result); #else zmq_close(_socket); #endif // NDEBUG _socket = nullptr; } } void socket::bind(endpoint_t const& endpoint) { int result = zmq_bind(_socket, endpoint.c_str()); if (0 != result) { throw zmq_internal_exception(); } } #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) void socket::unbind(endpoint_t const& endpoint) { int result = zmq_unbind(_socket, endpoint.c_str()); if (0 != result) { throw zmq_internal_exception(); } } #endif void socket::connect(endpoint_t const& endpoint) { int result = zmq_connect(_socket, endpoint.c_str()); if (0 != result) { throw zmq_internal_exception(); } } #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) void socket::disconnect(endpoint_t const& endpoint) { int result = zmq_disconnect(_socket, endpoint.c_str()); if (0 != result) { throw zmq_internal_exception(); } } #endif void socket::close() { int result = zmq_close(_socket); if (0 != result) { throw zmq_internal_exception(); } _socket = nullptr; } bool socket::send(zmqpp::signal sig, bool dont_block/* = false */) { message msg(sig); return send(msg, dont_block); } bool socket::receive(zmqpp::signal &sig, bool dont_block /* = false */) { message msg; bool ret = receive(msg, dont_block); if (ret) { assert(msg.is_signal()); msg.get(sig, 0); } return ret; } bool socket::send(message& message, bool const dont_block /* = false */) { size_t parts = message.parts(); if (parts == 0) { throw std::invalid_argument("sending requires messages have at least one part"); } bool dont_wait = dont_block; for(size_t i = 0; i < parts; ++i) { int flag = socket::normal; if(dont_wait) { flag |= socket::dont_wait; } if(i < (parts - 1)) { flag |= socket::send_more; } #if (ZMQ_VERSION_MAJOR == 2) int result = zmq_send( _socket, &message.raw_msg(i), flag ); #elif (ZMQ_VERSION_MAJOR < 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR < 2)) int result = zmq_sendmsg( _socket, &message.raw_msg(i), flag ); #else int result = zmq_msg_send( &message.raw_msg(i), _socket, flag ); #endif if (result < 0) { // the zmq framework should not block if the first part is accepted // so we should only ever get this error on the first part if((0 == i) && (EAGAIN == zmq_errno())) { return false; } if(EINTR == zmq_errno()) { if (0 == message.parts()) { return false; } // If we have an interrupt but it's not on the first part then we // know we can safely send out the rest of the message as we can // enforce that it won't wait on a blocking action dont_wait = true; continue; } // sanity checking assert(EAGAIN != zmq_errno()); throw zmq_internal_exception(); } message.sent(i); } // Leave message reference in a stable state zmqpp::message local; std::swap(local, message); return true; } bool socket::receive(message& message, bool const dont_block /* = false */) { if (message.parts() > 0) { // swap and discard old message zmqpp::message local; std::swap(local, message); } int flags = (dont_block) ? socket::dont_wait : socket::normal; bool more = true; while(more) { #if (ZMQ_VERSION_MAJOR == 2) int result = zmq_recv( _socket, &_recv_buffer, flags ); #elif (ZMQ_VERSION_MAJOR < 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR < 2)) int result = zmq_recvmsg( _socket, &_recv_buffer, flags ); #else int result = zmq_msg_recv( &_recv_buffer, _socket, flags ); #endif if(result < 0) { if ((0 == message.parts()) && (EAGAIN == zmq_errno())) { return false; } if(EINTR == zmq_errno()) { if (0 == message.parts()) { return false; } // If we have an interrupt but it's not on the first part then we // know we can safely pull out the rest of the message as it will // not be blocking continue; } assert(EAGAIN != zmq_errno()); throw zmq_internal_exception(); } zmq_msg_t& dest = message.raw_new_msg(); zmq_msg_move(&dest, &_recv_buffer); get(socket_option::receive_more, more); } return true; } bool socket::send(std::string const& string, int const flags /* = NORMAL */) { return send_raw(string.data(), string.size(), flags); } bool socket::receive(std::string& string, int const flags /* = NORMAL */) { #if (ZMQ_VERSION_MAJOR == 2) int result = zmq_recv( _socket, &_recv_buffer, flags ); #elif (ZMQ_VERSION_MAJOR < 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR < 2)) int result = zmq_recvmsg( _socket, &_recv_buffer, flags ); #else int result = zmq_msg_recv( &_recv_buffer, _socket, flags ); #endif if(result >= 0) { string.reserve(zmq_msg_size(&_recv_buffer)); string.assign(static_cast(zmq_msg_data(&_recv_buffer)), zmq_msg_size(&_recv_buffer)); return true; } if (EAGAIN == zmq_errno() || EINTR == zmq_errno()) { return false; } throw zmq_internal_exception(); } bool socket::send_raw(char const* buffer, size_t const length, int const flags /* = NORMAL */) { #if (ZMQ_VERSION_MAJOR == 2) zmq_msg_t msg; int result = zmq_msg_init_size(&msg, length); if (result != 0) { zmq_internal_exception(); } memcpy(zmq_msg_data(&msg), buffer, length); result = zmq_send(_socket, &msg, flags); #else int result = zmq_send(_socket, buffer, length, flags); #endif if(result >= 0) { return true; } #if (ZMQ_VERSION_MAJOR == 2) // only actually need to close this on error zmq_msg_close(&msg); #endif if (EAGAIN == zmq_errno() || EINTR == zmq_errno()) { return false; } throw zmq_internal_exception(); } bool socket::receive_raw(char* buffer, size_t& length, int const flags /* = NORMAL */) { #if (ZMQ_VERSION_MAJOR == 2) int result = zmq_recv( _socket, &_recv_buffer, flags ); #elif (ZMQ_VERSION_MAJOR < 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR < 2)) int result = zmq_recvmsg( _socket, &_recv_buffer, flags ); #else int result = zmq_msg_recv( &_recv_buffer, _socket, flags ); #endif if(result >= 0) { length = zmq_msg_size(&_recv_buffer); memcpy(buffer, zmq_msg_data(&_recv_buffer), length); return true; } if (EAGAIN == zmq_errno() || EINTR == zmq_errno()) { return false; } throw zmq_internal_exception(); } // Helper void socket::subscribe(std::string const& topic) { set(socket_option::subscribe, topic); } void socket::unsubscribe(std::string const& topic) { set(socket_option::unsubscribe, topic); } bool socket::has_more_parts() const { return get(socket_option::receive_more); } // Set socket options for different types of option void socket::set(socket_option const option, int const value) { switch(option) { // unsigned 64bit Integers #if (ZMQ_VERSION_MAJOR == 2) case socket_option::high_water_mark: case socket_option::send_buffer_size: case socket_option::receive_buffer_size: #endif case socket_option::affinity: if (value < 0) { throw exception("attempting to set an unsigned 64 bit integer option with a negative integer"); } set(option, static_cast(value)); break; // 64bit Integers #if (ZMQ_VERSION_MAJOR == 2) case socket_option::rate: case socket_option::recovery_interval: case socket_option::recovery_interval_seconds: case socket_option::swap_size: #else case socket_option::max_messsage_size: #endif set(option, static_cast(value)); break; // Boolean #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 1)) case socket_option::ipv4_only: #endif #if (ZMQ_VERSION_MAJOR == 2) case socket_option::multicast_loopback: #endif #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) #if (ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 2) case socket_option::delay_attach_on_connect: #else case socket_option::immediate: #endif case socket_option::router_mandatory: case socket_option::xpub_verbose: #endif #if (ZMQ_VERSION_MAJOR >= 4) case socket_option::ipv6: case socket_option::plain_server: case socket_option::conflate: case socket_option::curve_server: case socket_option::probe_router: case socket_option::request_correlate: case socket_option::request_relaxed: case socket_option::router_raw: #endif if (value == 0) { set(option, false); } else if (value == 1) { set(option, true); } else { throw exception("attempting to set a boolean option with a non 0 or 1 integer"); } break; // Default or Boolean #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) case socket_option::tcp_keepalive: if (value < -1 || value > 1) { throw exception("attempting to set a default or boolean option with a non -1, 0 or 1 integer"); } if (0 != zmq_setsockopt(_socket, static_cast(option), &value, sizeof(value))) { throw zmq_internal_exception(); } break; #endif // Integers that require +ve numbers case socket_option::backlog: #if (ZMQ_VERSION_MAJOR == 2) case socket_option::reconnect_interval_max: #else case socket_option::reconnect_interval_max: case socket_option::send_buffer_size: case socket_option::recovery_interval: case socket_option::receive_buffer_size: case socket_option::send_high_water_mark: case socket_option::receive_high_water_mark: case socket_option::multicast_hops: case socket_option::rate: #endif if (value < 0) { throw exception("attempting to set a positive only integer option with a negative integer"); } // Integers case socket_option::reconnect_interval: case socket_option::linger: case socket_option::receive_timeout: case socket_option::send_timeout: #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) case socket_option::tcp_keepalive_idle: case socket_option::tcp_keepalive_count: case socket_option::tcp_keepalive_interval: #endif if (0 != zmq_setsockopt(_socket, static_cast(option), &value, sizeof(value))) { throw zmq_internal_exception(); } break; default: throw exception("attempting to set a non signed integer option with a signed integer value"); } } void socket::set(socket_option const option, bool const value) { switch(option) { #if (ZMQ_VERSION_MAJOR == 2) case socket_option::multicast_loopback: #endif #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 1)) case socket_option::ipv4_only: #endif #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) #if (ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 2) case socket_option::delay_attach_on_connect: #else case socket_option::immediate: #endif case socket_option::router_mandatory: case socket_option::xpub_verbose: #endif #if (ZMQ_VERSION_MAJOR >= 4) case socket_option::ipv6: case socket_option::plain_server: case socket_option::conflate: case socket_option::curve_server: case socket_option::probe_router: case socket_option::request_correlate: case socket_option::request_relaxed: case socket_option::router_raw: #endif { int ivalue = value ? 1 : 0; if (0 != zmq_setsockopt(_socket, static_cast(option), &ivalue, sizeof(ivalue))) { throw zmq_internal_exception(); } break; } default: throw exception("attempting to set a non boolean option with a boolean value"); } } void socket::set(socket_option const option, uint64_t const value) { switch(option) { #if (ZMQ_VERSION_MAJOR == 2) // unsigned 64bit Integers case socket_option::high_water_mark: case socket_option::send_buffer_size: case socket_option::receive_buffer_size: #endif case socket_option::affinity: if (0 != zmq_setsockopt(_socket, static_cast(option), &value, sizeof(value))) { throw zmq_internal_exception(); } break; default: throw exception("attempting to set a non unsigned 64 bit integer option with a unsigned 64 bit integer value"); } } void socket::set(socket_option const option, int64_t const value) { switch(option) { #if (ZMQ_VERSION_MAJOR == 2) case socket_option::rate: case socket_option::recovery_interval: case socket_option::recovery_interval_seconds: case socket_option::swap_size: #else case socket_option::max_messsage_size: #endif // zmq only allowed +ve int64_t options if (value < 0) { throw exception("attempting to set a positive only 64 bit integer option with a negative 64bit integer"); } if (0 != zmq_setsockopt(_socket, static_cast(option), &value, sizeof(value))) { throw zmq_internal_exception(); } break; default: throw exception("attempting to set a non 64 bit integer option with a 64 bit integer value"); } } void socket::set(socket_option const option, char const* value, size_t const length) { switch(option) { case socket_option::identity: case socket_option::subscribe: case socket_option::unsubscribe: #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) case socket_option::tcp_accept_filter: #endif #if (ZMQ_VERSION_MAJOR >= 4) case socket_option::plain_password: case socket_option::plain_username: case socket_option::zap_domain: case socket_option::curve_public_key: case socket_option::curve_secret_key: case socket_option::curve_server_key: #endif if (0 != zmq_setsockopt(_socket, static_cast(option), value, length)) { throw zmq_internal_exception(); } break; default: throw exception("attempting to set a non string option with a string value"); } } // Get socket options, multiple versions for easy of use void socket::get(socket_option const option, int& value) const { size_t value_size = sizeof(int); switch(option) { #if (ZMQ_VERSION_MAJOR == 2) case socket_option::receive_more: case socket_option::multicast_loopback: value = static_cast(get(option)); break; #endif case socket_option::type: case socket_option::linger: case socket_option::backlog: case socket_option::reconnect_interval: case socket_option::reconnect_interval_max: case socket_option::receive_timeout: case socket_option::send_timeout: case socket_option::file_descriptor: case socket_option::events: #if (ZMQ_VERSION_MAJOR > 2) case socket_option::receive_more: case socket_option::send_buffer_size: case socket_option::receive_buffer_size: case socket_option::rate: case socket_option::recovery_interval: case socket_option::send_high_water_mark: case socket_option::receive_high_water_mark: case socket_option::multicast_hops: #endif #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 1)) case socket_option::ipv4_only: #endif #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) #if (ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 2) case socket_option::delay_attach_on_connect: #else case socket_option::immediate: #endif case socket_option::tcp_keepalive: case socket_option::tcp_keepalive_idle: case socket_option::tcp_keepalive_count: case socket_option::tcp_keepalive_interval: #endif #ifdef ZMQ_EXPERIMENTAL_LABELS case socket_option::receive_label: #endif #if (ZMQ_VERSION_MAJOR >= 4) case socket_option::ipv6: case socket_option::plain_server: case socket_option::mechanism: #endif if (0 != zmq_getsockopt(_socket, static_cast(option), &value, &value_size)) { throw zmq_internal_exception(); } // sanity check assert(value_size <= sizeof(int)); break; default: throw exception("attempting to get a non integer option with an integer value"); } } void socket::get(socket_option const option, bool& value) const { #if (ZMQ_VERSION_MAJOR == 2) int64_t int_value = 0; size_t value_size = sizeof(int64_t); #else int int_value = 0; size_t value_size = sizeof(int); #endif switch(option) { case socket_option::receive_more: #if (ZMQ_VERSION_MAJOR == 2) case socket_option::multicast_loopback: #endif #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 1)) case socket_option::ipv4_only: #endif #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) #if (ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR == 2) case socket_option::delay_attach_on_connect: #else case socket_option::immediate: #endif #endif #ifdef ZMQ_EXPERIMENTAL_LABELS case socket_option::receive_label: #endif #if (ZMQ_VERSION_MAJOR >= 4) case socket_option::ipv6: case socket_option::plain_server: #endif if (0 != zmq_getsockopt(_socket, static_cast(option), &int_value, &value_size)) { throw zmq_internal_exception(); } value = (int_value == 1) ? true : false; break; default: throw exception("attempting to get a non boolean option with a boolean value"); } } void socket::get(socket_option const option, uint64_t& value) const { size_t value_size = sizeof(uint64_t); switch(option) { #if (ZMQ_VERSION_MAJOR == 2) case socket_option::high_water_mark: case socket_option::send_buffer_size: case socket_option::receive_buffer_size: #endif case socket_option::affinity: if(0 != zmq_getsockopt(_socket, static_cast(option), &value, &value_size)) { throw zmq_internal_exception(); } break; default: throw exception("attempting to get a non unsigned 64 bit integer option with an unsigned 64 bit integer value"); } } void socket::get(socket_option const option, int64_t& value) const { size_t value_size = sizeof(int64_t); switch(option) { #if (ZMQ_VERSION_MAJOR == 2) case socket_option::rate: case socket_option::recovery_interval: case socket_option::recovery_interval_seconds: case socket_option::swap_size: case socket_option::receive_more: case socket_option::multicast_loopback: #else case socket_option::max_messsage_size: #endif if(0 != zmq_getsockopt(_socket, static_cast(option), &value, &value_size)) { throw zmq_internal_exception(); } break; default: throw exception("attempting to get a non 64 bit integer option with an 64 bit integer value"); } } void socket::get(socket_option const option, std::string& value) const { static std::array buffer; size_t size = max_socket_option_buffer_size; switch(option) { case socket_option::identity: #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) case socket_option::last_endpoint: #endif #if (ZMQ_VERSION_MAJOR >= 4) case socket_option::plain_password: case socket_option::plain_username: case socket_option::zap_domain: case socket_option::curve_public_key: case socket_option::curve_secret_key: case socket_option::curve_server_key: #endif if(0 != zmq_getsockopt(_socket, static_cast(option), buffer.data(), &size)) { throw zmq_internal_exception(); } value.assign(buffer.data(), size); break; default: throw exception("attempting to get a non string option with a string value"); } } socket::socket(socket&& source) NOEXCEPT : _socket(source._socket) , _type(source._type) , _recv_buffer() { // we steal the zmq_msg_t from the valid socket, we only init our own because it's cheap // and zmq_msg_move does a valid check zmq_msg_init(&_recv_buffer); zmq_msg_move(&_recv_buffer, &source._recv_buffer); // Clean up source a little, we will handle the deinit, it doesn't need to source._socket = nullptr; } socket& socket::operator=(socket&& source) NOEXCEPT { std::swap(_socket, source._socket); _type = source._type; // just clone? // we steal the zmq_msg_t from the valid socket, we only init our own because it's cheap // and zmq_msg_move does a valid check zmq_msg_init(&_recv_buffer); zmq_msg_move(&_recv_buffer, &source._recv_buffer); return *this; } socket::operator bool() const { return nullptr != _socket; } socket::operator void*() const { return _socket; } void socket::track_message(message const& /* message */, uint32_t const parts, bool& should_delete) { if (parts == 0) { should_delete = true; } } #if (ZMQ_VERSION_MAJOR >= 4) void socket::monitor(endpoint_t const monitor_endpoint, int events_required) { int result = zmq_socket_monitor( _socket, monitor_endpoint.c_str(), events_required ); if (0 != result) { throw zmq_internal_exception(); } } #endif signal socket::wait() { for (;;) { message msg; while(!receive(msg)); if (msg.is_signal()) { signal sig; msg.get(sig, 0); return sig; } } } } zmqpp-4.1.2/src/zmqpp/socket.hpp000066400000000000000000000421211254036632700166340ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 9 Aug 2011 * \author Ben Gray (\@benjamg) */ #ifndef ZMQPP_SOCKET_HPP_ #define ZMQPP_SOCKET_HPP_ #include #include #include #include #include "compatibility.hpp" #include "socket_mechanisms.hpp" #include "socket_types.hpp" #include "socket_options.hpp" #include "signal.hpp" namespace zmqpp { class context; class message; typedef std::string endpoint_t; typedef context context_t; typedef message message_t; #if (ZMQ_VERSION_MAJOR >= 4) namespace event { const int connected = ZMQ_EVENT_CONNECTED; /* 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) /** * Unbinds from a previously bound endpoint. * * \param endpoint the zmq endpoint to bind to */ void unbind(endpoint_t const& endpoint); #endif /** * Asynchronously connects to an endpoint. * If the endpoint is not inproc then zmq will happily keep trying * to connect until there is something there. * * Inproc sockets must have a valid target already bound before connection * will work. * * \param endpoint the zmq endpoint to connect to */ void connect(endpoint_t const& endpoint); /** * Asynchronously connects to multiple endpoints. * If the endpoint is not inproc then zmq will happily keep trying * to connect until there is something there. * * Inproc sockets must have a valid target already bound before connection * will work. * * This is a helper function that wraps the single item connect in a loop * * \param connections_begin the starting iterator for zmq endpoints. * \param connections_end the final iterator for zmq endpoints. */ template void connect(InputIterator const& connections_begin, InputIterator const& connections_end) { for(InputIterator it = connections_begin; it != connections_end; ++it) { connect(*it); } } /** * Disconnects a previously connected endpoint. * * \param endpoint the zmq endpoint to disconnect from */ #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) void disconnect(endpoint_t const& endpoint); /** * Disconnects from multiple previously connected endpoints. * * This is a helper function that wraps the single item disconnect in a loop * * \param disconnections_begin the starting iterator for zmq endpoints. * \param disconnections_end the final iterator for zmq endpoints. */ template void disconnect(InputIterator const& disconnections_begin, InputIterator const& disconnections_end) { for(InputIterator it = disconnections_begin; it != disconnections_end; ++it) { disconnect(*it); } } #endif /** * Closes the internal zmq socket and marks this instance * as invalid. */ void close(); /** * Sends the message over the connection, this may be a multipart message. * * If dont_block is true and we are unable to add a new message then this * function will return false. * * \param message message to send * \param dont_block boolean to dictate if we wait while sending. * \return true if message sent, false if it would have blocked */ bool send(message_t& message, bool const dont_block = false); /** * Gets a message from the connection, this may be a multipart message. * * If dont_block is true and we are unable to get a message then this * function will return false. * * \param message reference to fill with received data * \param dont_block boolean to dictate if we wait for data. * \return true if message sent, false if it would have blocked */ bool receive(message_t& message, bool const dont_block = false); /** * Sends the byte data held by the string as the next message part. * * If the socket::DONT_WAIT flag and we are unable to add a new message to * socket then this function will return false. * * \param string message part to send * \param flags message send flags * \return true if message part sent, false if it would have blocked */ bool send(std::string const& string, int const flags = normal); /** * If there is a message ready then get the next part as a string * * If the socket::DONT_WAIT flag and there is no message ready to receive * then this function will return false. * * \param string message part to receive into * \param flags message receive flags * \return true if message part received, false if it would have blocked */ bool receive(std::string& string, int const flags = normal); /** * Sends a signal over the socket. * * If dont_block is true and we are unable to send the signal e then this * function will return false. * * @param sig signal to send. * @param flags message send flags * @return true if message part sent, false if it would have blocked */ bool send(signal sig, bool dont_block = false); /** * If there is a message ready then we read a signal from it. * * If dont_block is true and we are unable to send the signal then this * function will return false. * * \param sig signal to receive into * \param flags message receive flags * \return true if signal received, false if it would have blocked */ bool receive(signal &sig, bool dont_block = false); /** * Sends the byte data pointed to by buffer as the next part of the message. * * If the socket::DONT_WAIT flag and we are unable to add a new message to * socket then this function will return false. * * \param buffer byte buffer pointer to start writing from * \param length max length of the buffer * \param flags message send flags * \return true if message part sent, false if it would have blocked */ bool send_raw(char const* buffer, size_t const length, int const flags = normal); /** * \warning If the buffer is not large enough for the message part then the * data will be truncated. The rest of the part is lost forever. * * If there is a message ready then get the next part of it as a raw * byte buffer. * * If the socket::DONT_WAIT flag and there is no message ready to receive * then this function will return false. * * \param buffer byte buffer pointer to start writing to * \param length max length of the buffer * \param flags message receive flags * \return true if message part received, false if it would have blocked */ bool receive_raw(char* buffer, size_t& length, int const flags = normal); /** * * Subscribe to a topic * * Helper function that is equivalent of calling * \code * set(zmqpp::socket_option::subscribe, topic); * \endcode * * This method is only useful for subscribe type sockets. * * \param topic the topic to subscribe to. */ void subscribe(std::string const& topic); /** * Subscribe to a topic * * Helper function that is equivalent of a loop calling * \code * set(zmqpp::socket_option::subscribe, topic); * \endcode * * This method is only useful for subscribe type sockets. * * Generally this will be used with stl collections using begin() and * end() functions to get the iterators. * For this reason the end loop runs until the end iterator, not inclusive * of it. * * \param topics_begin the starting iterator for topics. * \param topics_end the final iterator for topics. */ template void subscribe(InputIterator const& topics_begin, InputIterator const& topics_end) { for(InputIterator it = topics_begin; it != topics_end; ++it) { subscribe(*it); } } /** * Unsubscribe from a topic * * Helper function that is equivalent of calling * \code * set(zmqpp::socket_option::unsubscribe, topic); * \endcode * * This method is only useful for subscribe type sockets. * * \param topic the topic to unsubscribe from. */ void unsubscribe(std::string const& topic); /** * Unsubscribe from a topic * * Helper function that is equivalent of a loop calling * \code * set(zmqpp::socket_option::unsubscribe, topic); * \endcode * * This method is only useful for subscribe type sockets. * * Generally this will be used with stl collections using begin() and * end() functions to get the iterators. * For this reason the end loop runs until the end iterator, not inclusive * of it. * * \param topics_begin the starting iterator for topics. * \param topics_end the final iterator for topics. */ template void unsubscribe(InputIterator const& topics_begin, InputIterator const& topics_end) { for(InputIterator it = topics_begin; it != topics_end; ++it) { unsubscribe(*it); } } /** * If the last receive part call to the socket resulted * in a label or a non-terminating part of a multipart * message this will return true. * * \return true if there are more parts */ bool has_more_parts() const; /** * Set the value of an option in the underlaying zmq socket. * * \param option a valid ::socket_option * \param value to set the option to */ void set(socket_option const option, int const value); /** * Set the value of an option in the underlaying zmq socket. * * \since 2.0.0 (built against 0mq version 3.1.x or later) * * \param option a valid ::socket_option * \param value to set the optionbool to */ void set(socket_option const option, bool const value); /** * Set the value of an option in the underlaying zmq socket. * * \param option a valid ::socket_option * \param value to set the option to */ void set(socket_option const option, uint64_t const value); /** * Set the value of an option in the underlaying zmq socket. * * \param option a valid ::socket_option * \param value to set the option to */ void set(socket_option const option, int64_t const value); /** * Set the value of an option in the underlaying zmq socket. * * \param option a valid ::socket_option * \param pointer to raw byte value to set the option to * \param length the size of the raw byte value */ void set(socket_option const option, char const* value, size_t const length); /** * Set the value of an option in the underlaying zmq socket. * * \param option a valid ::socket_option * \param pointer to null terminated cstring value to set the option to */ inline void set(socket_option const option, char const* value) { set(option, value, strlen(value)); } /** * Set the value of an option in the underlaying zmq socket. * * \param option a valid ::socket_option * \param value to set the option to */ inline void set(socket_option const option, std::string const value) { set(option, value.c_str(), value.length()); } /** * Get a socket option from the underlaying zmq socket. * * \param option a valid ::socket_option * \param value referenced int to return value in */ void get(socket_option const option, int& value) const; /** * Get a socket option from the underlaying zmq socket. * * \param option a valid ::socket_option * \param value referenced bool to return value in */ void get(socket_option const option, bool& value) const; /** * Get a socket option from the underlaying zmq socket. * * \param option a valid ::socket_option * \param value referenced uint64_t to return value in */ void get(socket_option const option, uint64_t& value) const; /** * Get a socket option from the underlaying zmq socket. * * \param option a valid ::socket_option * \param value referenced uint64_t to return value in */ void get(socket_option const option, int64_t& value) const; /** * Get a socket option from the underlaying zmq socket. * * \param option a valid ::socket_option * \param value referenced std::string to return value in */ void get(socket_option const option, std::string& value) const; /** * For those that don't want to get into a referenced value this templated method * will return the value instead. * * \param option a valid ::socket_option * \return socket option value */ template Type get(socket_option const option) const { Type value = Type(); get(option, value); return value; } #if (ZMQ_VERSION_MAJOR >= 4) /** * Attach a monitor to this socket that will send events over inproc to the * specified endpoint. The monitor will bind on the endpoint given and will * be of type PAIR but not read from the stream. * * \param monitor_endpoint the valid inproc endpoint to bind to. * \param events_required a bit mask of required events. */ void monitor(endpoint_t const monitor_endpoint, int events_required); #endif /** * Wait on signal, this is useful to coordinate thread. * Block until a signal is received, and returns the received signal. * * Discard everything until something that looks like a signal is received. * \return the signal. */ signal wait(); /** * Move constructor * * Moves the internals of source to this object, there is no guarantee * that source will be left in a valid state. * * This constructor is noexcept and so will not throw exceptions * * \param source target socket to steal internals from */ socket(socket&& source) NOEXCEPT; /** * Move operator * * Moves the internals of source to this object, there is no guarantee * that source will be left in a valid state. * * This function is noexcept and so will not throw exceptions * * \param source target socket to steal internals from * \return socket reference to this */ socket& operator=(socket&& source) NOEXCEPT; /** * Check the socket is still valid * * This tests the internal state of the socket. * If creation failed for some reason or if the move functions were used * to move the socket internals to another instance this will return false. * * \return true if the socket is valid */ operator bool() const; /** * Access to the raw 0mq context * * \return void pointer to the underlying 0mq socket */ operator void*() const; private: void* _socket; socket_type _type; zmq_msg_t _recv_buffer; // No copy socket(socket const&) NOEXCEPT ZMQPP_EXPLICITLY_DELETED; socket& operator=(socket const&) NOEXCEPT ZMQPP_EXPLICITLY_DELETED; void track_message(message_t const&, uint32_t const, bool&); }; } #endif /* ZMQPP_SOCKET_HPP_ */ zmqpp-4.1.2/src/zmqpp/socket_mechanisms.hpp000066400000000000000000000031321254036632700210420ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 13 Aug 2014 * \author Ben Gray (\@benjamg) */ #ifndef ZMQPP_SOCKET_MECHANISMS_HPP_ #define ZMQPP_SOCKET_MECHANISMS_HPP_ namespace zmqpp { /*! * \brief Socket security mechanisms allowed by zmq * * Each is designed for a different use and has different limitations. */ ZMQPP_COMPARABLE_ENUM socket_security { #if (ZMQ_VERSION_MAJOR >= 4) /*! * The NULL mechanism is defined by the ZMTP 3.0 specification: * http://rfc.zeromq.org/spec:23. This is the default security mechanism * for new ZeroMQ sockets */ none = ZMQ_NULL, /*! * The PLAIN mechanism defines a simple username/password mechanism that * lets a server authenticate a client. PLAIN makes no attempt at security * or confidentiality. It is intended for use on internal networks where * security requirements are low. The PLAIN mechanism is defined by this * document: http://rfc.zeromq.org/spec:24 */ plain = ZMQ_PLAIN, /*! * The CURVE mechanism defines a mechanism for secure authentication and * confidentiality for communications between a client and a server. CURVE * is intended for use on public networks. The CURVE mechanism is defined * by this document: http://rfc.zeromq.org/spec:25 */ curve = ZMQ_CURVE, #endif }; } #endif /* ZMQPP_SOCKET_TYPES_HPP_ */ zmqpp-4.1.2/src/zmqpp/socket_options.hpp000066400000000000000000000155061254036632700204160ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 23 Sep 2011 * \author Ben Gray (\@benjamg) */ #ifndef ZMQPP_SOCKET_OPTIONS_HPP_ #define ZMQPP_SOCKET_OPTIONS_HPP_ namespace zmqpp { /** \todo Expand the information on the options to make it actually useful. */ /*! * \brief possible Socket options in zmq */ ZMQPP_COMPARABLE_ENUM socket_option { affinity = ZMQ_AFFINITY, /*!< I/O thread affinity */ identity = ZMQ_IDENTITY, /*!< Socket identity */ subscribe = ZMQ_SUBSCRIBE, /*!< Add topic subscription - set only */ unsubscribe = ZMQ_UNSUBSCRIBE, /*!< Remove topic subscription - set only */ rate = ZMQ_RATE, /*!< Multicast data rate */ send_buffer_size = ZMQ_SNDBUF, /*!< Kernel transmission buffer size */ receive_buffer_size = ZMQ_RCVBUF, /*!< Kernel receive buffer size */ receive_more = ZMQ_RCVMORE, /*!< Can receive more parts - get only */ file_descriptor = ZMQ_FD, /*!< Socket file descriptor - get only */ events = ZMQ_EVENTS, /*!< Socket event flags - get only */ type = ZMQ_TYPE, /*!< Socket type - get only */ linger = ZMQ_LINGER, /*!< Socket linger timeout */ backlog = ZMQ_BACKLOG, /*!< Maximum length of outstanding connections - get only */ reconnect_interval = ZMQ_RECONNECT_IVL, /*!< Reconnection interval */ reconnect_interval_max = ZMQ_RECONNECT_IVL_MAX, /*!< Maximum reconnection interval */ receive_timeout = ZMQ_RCVTIMEO, /*!< Maximum inbound block timeout */ send_timeout = ZMQ_SNDTIMEO, /*!< Maximum outbound block timeout */ #if (ZMQ_VERSION_MAJOR == 2) // Note that this is inverse of the zmq names for version 2.x recovery_interval_seconds = ZMQ_RECOVERY_IVL, /*!< Multicast recovery interval in seconds */ recovery_interval = ZMQ_RECOVERY_IVL_MSEC, /*!< Multicast recovery interval in milliseconds */ high_water_mark = ZMQ_HWM, /*!< High-water mark for all messages */ swap_size = ZMQ_SWAP, /*!< Maximum socket swap size in bytes */ multicast_loopback = ZMQ_MCAST_LOOP, /*!< Allow multicast packet loopback */ #else // version > 2 recovery_interval = ZMQ_RECOVERY_IVL, /*!< Multicast recovery interval in milliseconds */ max_messsage_size = ZMQ_MAXMSGSIZE, /*!< Maximum inbound message size */ send_high_water_mark = ZMQ_SNDHWM, /*!< High-water mark for outbound messages */ receive_high_water_mark = ZMQ_RCVHWM, /*!< High-water mark for inbound messages */ multicast_hops = ZMQ_MULTICAST_HOPS, /*!< Maximum number of multicast hops */ #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 1)) ipv4_only = ZMQ_IPV4ONLY, #endif #if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2)) #if ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR == 2)) delay_attach_on_connect = ZMQ_DELAY_ATTACH_ON_CONNECT, /*!< Delay buffer attachment until connect complete */ #else // ZMQ_DELAY_ATTACH_ON_CONNECT is renamed in ZeroMQ starting 3.3.x immediate = ZMQ_IMMEDIATE, /*!< Block message sending until connect complete */ #endif last_endpoint = ZMQ_LAST_ENDPOINT, /*!< Last bound endpoint - get only */ router_mandatory = ZMQ_ROUTER_MANDATORY, /*!< Require routable messages - set only */ xpub_verbose = ZMQ_XPUB_VERBOSE, /*!< Pass on existing subscriptions - set only */ tcp_keepalive = ZMQ_TCP_KEEPALIVE, /*!< Enable TCP keepalives */ tcp_keepalive_idle = ZMQ_TCP_KEEPALIVE_IDLE, /*!< TCP keepalive idle count (generally retry count) */ tcp_keepalive_count = ZMQ_TCP_KEEPALIVE_CNT, /*!< TCP keepalive retry count */ tcp_keepalive_interval = ZMQ_TCP_KEEPALIVE_INTVL, /*!< TCP keepalive interval */ tcp_accept_filter = ZMQ_TCP_ACCEPT_FILTER, /*!< Filter inbound connections - set only */ #endif #if (ZMQ_VERSION_MAJOR >= 4) ipv6 = ZMQ_IPV6, /*!< IPv6 socket support status */ mechanism = ZMQ_MECHANISM, /*!< Socket security mechanism - get only */ plain_password = ZMQ_PLAIN_PASSWORD, /*!< PLAIN password */ plain_server = ZMQ_PLAIN_SERVER, /*!< PLAIN server role */ plain_username = ZMQ_PLAIN_USERNAME, /*!< PLAIN username */ zap_domain = ZMQ_ZAP_DOMAIN, /*!< RFC 27 authentication domain */ conflate = ZMQ_CONFLATE, /*!< Keep only last message - set only */ curve_public_key = ZMQ_CURVE_PUBLICKEY, /*!< CURVE public key */ curve_secret_key = ZMQ_CURVE_SECRETKEY, /*!< CURVE secret key */ curve_server_key = ZMQ_CURVE_SERVERKEY, /*!< CURVE server key */ curve_server = ZMQ_CURVE_SERVER, /*!< CURVE server role - set only */ probe_router = ZMQ_PROBE_ROUTER, /*!< Bootstrap connections to ROUTER sockets - set only */ request_correlate = ZMQ_REQ_CORRELATE, /*!< Match replies with requests - set only */ request_relaxed = ZMQ_REQ_RELAXED, /*!< Relax strict alternation between request and reply - set only */ router_raw = ZMQ_ROUTER_RAW, /*!< Switch ROUTER socket to raw mode - set only */ #endif #if (ZMQ_VERSION_MAJOR > 4) || ((ZMQ_VERSION_MAJOR == 4) && (ZMQ_VERSION_MINOR >= 1)) handshake_interval = ZMQ_HANDSHAKE_IVL, /*!< Maximum handshake interval */ type_of_service = ZMQ_TOS, /*!< Type-of-Service socket override status */ connect_rid = ZMQ_CONNECT_RID, /*!< Assign the next outbound connection id - set only */ ipc_filter_gid = ZMQ_IPC_FILTER_GID, /*!< Group ID filters to allow new IPC connections - set only */ ipc_filter_pid = ZMQ_IPC_FILTER_PID, /*!< Process ID filters to allow new IPC connections - set only */ ipc_filter_uid = ZMQ_IPC_FILTER_UID, /*!< User ID filters to allow new IPC connections - set only */ router_handover = ZMQ_ROUTER_HANDOVER, /*!< Handle duplicate client identities on ROUTER sockets - set only */ #endif #endif // version > 2 #ifdef ZMQ_EXPERIMENTAL_LABELS receive_label = ZMQ_RCVLABEL, /*!< Received label part - get only */ #endif }; } #endif /* ZMQPP_SOCKET_OPTIONS_HPP_ */ zmqpp-4.1.2/src/zmqpp/socket_types.hpp000066400000000000000000000127421254036632700200660ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 23 Sep 2011 * \author Ben Gray (\@benjamg) */ #ifndef ZMQPP_SOCKET_TYPES_HPP_ #define ZMQPP_SOCKET_TYPES_HPP_ namespace zmqpp { /*! * \brief Socket types allowed by zmq * * The socket type choose at creation must be one of these types. * * Each is designed for a different use and has different limitations. */ ZMQPP_COMPARABLE_ENUM socket_type { /*! * One to one - two way connection.\n * Connect to ::pair.\n * A \c pair socket has to be connected only one other pair socket and allows * two way communication between them. */ pair = ZMQ_PAIR, /*! * One to many - fan out.\n * Connect to ::subscribe or ::xsubscribe.\n * Socket is send only.\n * Socket will drop messages and not block.\n * \c publish sockets allow sending of the same message to many subscribers * each subscriber can limit what is sent through the socket_option::subscribe * settings. */ publish = ZMQ_PUB, /*! * \note It seems doxygen can't work out which data is for the socket type and * which is for the socket option so both get listed for both. * * One to many - fair-queued.\n * Connect to ::publish or ::xpublish.\n * Socket is receive only.\n * The \c subscribe socket can connection to any number of publishers and will * fairly pull messages from each. The socket_option::subscribe settings can * be use to limit which messages are received and by default none are. */ subscribe = ZMQ_SUB, /*! * One to many - fair-queued.\n * Connect to ::push.\n * Socket is receive only.\n * The \c pull socket fairly pulls messages from all pushers it is connected * to. */ pull = ZMQ_PULL, /*! * One to many - load-balanced.\n * Connect to ::pull.\n * Socket is send only.\n * Socket will block if unable to send.\n * The \c push socket fairly distributes messages between any connected * puller sockets. */ push = ZMQ_PUSH, /*! * One to many - fair-queued outgoing, last peer incoming.\n * Connect to ::reply or ::xreply.\n * Socket flips between send and receive only.\n * Socket will block if unable to send.\n * The \c request socket will fairly balance requests sent out to a * replier and then can only be used to receive until that replier * sends a reply. */ request = ZMQ_REQ, /*! * One to many - load-balanced incoming, last peer outgoing.\n * Connect to ::request or ::xrequest.\n * Socket flips between send and receive only.\n * Socket will drop messages and not block.\n * The \c reply socket can only receive until it pulls a message from a * requester at which point it can only send until the reply is sent. */ reply = ZMQ_REP, /*! * One to many - fan out.\n * Connect to ::subscribe or ::xsubscribe.\n * Socket is send only with the exception of special subscription messages.\n * Socket will drop messages and not block.\n * \c xpublish act the same as ::publish sockets however also allow special * subscription messages to be received from subscribers. */ xpublish = ZMQ_XPUB, /*! * One to many - fair-queued.\n * Connect to ::publish or ::xpublish.\n * Socket is receive only with the exception of special subscription messages\n * \c xsubscribe act the same as ::subscribe sockets however also allow special * subscription messages to be send to connected publishers. */ xsubscribe = ZMQ_XSUB, /*! * One to many - fair-queued incoming, load-balanced outgoing.\n * Connect to ::reply or ::xreply.\n * Socket will block if unable to send.\n * An \c xrequest socket balances requests between repliers and pulls replies * back in a fair manner. Each request is expected to have exactly one reply. */ xrequest = ZMQ_XREQ, /*! * One to many - fair-queued incoming, targeted outgoing.\n * Connect to ::request or ::xrequest.\n * Socket will drop messages and not block.\n * An \c xreply socket fairly pulls in requests from requesters and will * label requests so it can return replies back to the correct target. */ xreply = ZMQ_XREP, /*! * One to many - fair-queued incoming, targeted outgoing.\n * Connect to non-0mq sockets.\n * Messages sent must consist of a identity target and a single data frame. */ #if (ZMQ_VERSION_MAJOR >= 4) stream = ZMQ_STREAM, #endif // To match for people who prefer the shorter versions pub = ZMQ_PUB, /*!< version of ::publish to match zmq name convention */ sub = ZMQ_SUB, /*!< version of ::subscribe to match zmq name convention */ req = ZMQ_REQ, /*!< version of ::request to match zmq name convention */ rep = ZMQ_REP, /*!< version of ::reply to match zmq name convention */ xpub = ZMQ_XPUB, /*!< version of ::xpublish to match zmq name convention */ xsub = ZMQ_XSUB, /*!< version of ::xsubscribe to match zmq name convention */ xreq = ZMQ_XREQ, /*!< version of ::xrequest to match zmq name convention */ xrep = ZMQ_XREP, /*!< version of ::xreply to match zmq name convention */ // For completion router = ZMQ_ROUTER, /*!< \deprecated Matches zmq 2.x xrep functionality. */ dealer = ZMQ_DEALER /*!< \deprecated Matches zmq 2.x xreq functionality. */ }; } #endif /* ZMQPP_SOCKET_TYPES_HPP_ */ zmqpp-4.1.2/src/zmqpp/z85.cpp000066400000000000000000000022361254036632700157700ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ #include "z85.hpp" #include #include #include "exception.hpp" using namespace zmqpp; #if (ZMQ_VERSION_MAJOR >= 4) std::string z85::encode(const std::string &raw_data) { return encode(reinterpret_cast(raw_data.c_str()), raw_data.size()); } std::string z85::encode(const uint8_t *data, size_t size) { std::unique_ptr storage(new char[size * 5 / 4 + 1]); if (zmq_z85_encode(&storage[0], const_cast(data), size) == nullptr) { throw z85_exception("Failed to encode to z85"); } return std::string(&storage[0]); } std::vector z85::decode(const std::string &string) { std::vector dest(string.size() * 4 / 5); if (zmq_z85_decode(&dest[0], const_cast(string.c_str())) == nullptr) { throw z85_exception("Failed to decode from z85"); } return dest; } #endif zmqpp-4.1.2/src/zmqpp/z85.hpp000066400000000000000000000025251254036632700157760ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ #pragma once #include #include #include namespace zmqpp { #if (ZMQ_VERSION_MAJOR >= 4) /** * Provide z85 encoding and decoding facilities. */ namespace z85 { /** * Encode a binary string into a string using Z85 representation. * @param raw_data the binary string to be encoded. * @return the encoded string. * See ZMQ RFC 32; */ std::string encode(const std::string &raw_data); /** * Encode a binary blob into a string using Z85 representation. * @param data pointer to raw data to be encoded. * @param size the size of the data to be encoded. * @return the encoded string. * See ZMQ RFC 32; */ std::string encode(const uint8_t *data, size_t size); /** * Decode a Z85 encoded string into a binary blob represented as a vector. * @param string the string to be decoded. * @return a vector of uint8_t: the binary block after string decoding. */ std::vector decode(const std::string &string); } #endif } zmqpp-4.1.2/src/zmqpp/zap_request.cpp000066400000000000000000000041661254036632700177100ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 25 Nov 2014 * \author Prem Shankar Kumar (\@meprem) */ #include "zap_request.hpp" #include "message.hpp" #include "socket.hpp" #include "z85.hpp" #if (ZMQ_VERSION_MAJOR > 3) namespace zmqpp { /*! * Receive a ZAP valid request from the handler socket */ zap_request::zap_request(socket& handler, bool logging) : zap_socket(handler), verbose(logging) { message msg; zap_socket.receive(msg); if(0 == msg.parts()) return; // Interrupted // Get all standard frames off the handler socket version = msg.get(0); sequence = msg.get(1); domain = msg.get(2); address = msg.get(3); identity = msg.get(4); mechanism = msg.get(5); // If the version is wrong, we're linked with a bogus libzmq, so die assert(version == "1.0"); // Get mechanism-specific frames if("PLAIN" == mechanism) { username = msg.get(6); password = msg.get(7); } else if("CURVE" == mechanism) { client_key = z85::encode(msg.get(6)); } else if("GSSAPI" == mechanism) { principal = msg.get(6); } if (verbose) { std::cout << "auth: ZAP request mechanism=" << mechanism <<" ipaddress=" << address << std::endl; } } /*! * Send a ZAP reply to the handler socket */ void zap_request::reply(const std::string &status_code, const std::string &status_text, const std::string &user_id) { if (verbose) { std::cout << "auth: ZAP reply status_code=" << status_code << " status_text=" << status_text << " user_id=" << user_id << std::endl; } message reply; reply << version << sequence << status_code << status_text << user_id << ""; zap_socket.send(reply); } } #endif zmqpp-4.1.2/src/zmqpp/zap_request.hpp000066400000000000000000000062641254036632700177160ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 25 Nov 2014 * \author Prem Shankar Kumar (\@meprem) */ #ifndef ZMQPP_ZAP_REQUEST_HPP_ #define ZMQPP_ZAP_REQUEST_HPP_ #include #include "socket.hpp" #if (ZMQ_VERSION_MAJOR > 3) namespace zmqpp { /** * A class for working with ZAP requests and replies. * Used in auth to simplify working with RFC 27 messages. * */ class zap_request { public: /** * Receive a ZAP valid request from the handler socket */ zap_request(socket& handler, bool logging); /** * Send a ZAP reply to the handler socket */ void reply(const std::string &status_code, const std::string &status_text, const std::string &user_id); /** * Get Version */ const std::string & get_version() const { return version; } /** * Get Domain */ const std::string & get_domain() const { return domain; } /** * Get Address */ const std::string & get_address() const { return address; } /** * Get Identity */ const std::string & get_identity() const { return identity; } /** * Get Security Mechanism */ const std::string & get_mechanism() const { return mechanism; } /** * Get username for PLAIN security mechanism */ const std::string & get_username() const { return username; } /** * Get password for PLAIN security mechanism */ const std::string & get_password() const { return password; } /*! * Get client_key for CURVE security mechanism. * The key is z85 encoded. */ const std::string & get_client_key() const { return client_key; } /** * Get principal for GSSAPI security mechanism */ const std::string & get_principal() const { return principal; } private: socket& zap_socket; //!< Socket we're talking to std::string version; //!< Version number, must be "1.0" std::string sequence; //!< Sequence number of request std::string domain; //!< Server socket domain std::string address; //!< Client IP address std::string identity; //!< Server socket idenntity std::string mechanism; //!< Security mechansim std::string username; //!< PLAIN user name std::string password; //!< PLAIN password, in clear text std::string client_key; //!< CURVE client public key in ASCII std::string principal; //!< GSSAPI client principal bool verbose; //!< Log ZAP requests and replies? // No copy - private and not implemented zap_request(zap_request const&) ZMQPP_EXPLICITLY_DELETED; zap_request& operator=(zap_request const&) NOEXCEPT ZMQPP_EXPLICITLY_DELETED; }; } #endif #endif /* ZMQPP_ZAP_REQUEST_HPP_ */ zmqpp-4.1.2/src/zmqpp/zmqpp.cpp000066400000000000000000000016251254036632700165120ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /* * Created on: 18 Aug 2011 * Author: Ben Gray (@benjamg) */ #include "zmqpp.hpp" #define STRINGIZE(val) #val namespace zmqpp { std::string version() { return STRINGIZE(ZMQPP_VERSION_MAJOR) "." STRINGIZE(ZMQPP_VERSION_MINOR) "." STRINGIZE(ZMQPP_VERSION_REVISION); } void version(uint8_t& major, uint8_t& minor, uint8_t& revision) { major = ZMQPP_VERSION_MAJOR; minor = ZMQPP_VERSION_MINOR; revision = ZMQPP_VERSION_REVISION; } void zmq_version(uint8_t& major, uint8_t& minor, uint8_t& patch) { major = ZMQ_VERSION_MAJOR; minor = ZMQ_VERSION_MINOR; patch = ZMQ_VERSION_PATCH; } } zmqpp-4.1.2/src/zmqpp/zmqpp.hpp000066400000000000000000000076041254036632700165220ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file is part of zmqpp. * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file. */ /** * \file * * \date 9 Aug 2011 * \author Ben Gray (\@benjamg) * * License: http://www.opensource.org/licenses/MIT * * Copyright (C) 2011 by Ben Gray * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #ifndef ZMQPP_ZMQPP_HPP_ #define ZMQPP_ZMQPP_HPP_ /** * \def ZMQPP_VERSION_MAJOR * zmqpp major version number */ #define ZMQPP_VERSION_MAJOR 4 /** * \def ZMQPP_VERSION_MINOR * zmqpp minor version number */ #define ZMQPP_VERSION_MINOR 1 /** * \def ZMQPP_VERSION_REVISION * zmqpp version revision number */ #define ZMQPP_VERSION_REVISION 1 #include #include "compatibility.hpp" #include "context.hpp" #include "exception.hpp" #include "message.hpp" #include "poller.hpp" #include "socket.hpp" #include "actor.hpp" #include "reactor.hpp" #include "zap_request.hpp" #include "auth.hpp" /*! * \brief C++ wrapper around zmq * * All zmq++ / zmqpp functions, constants and classes live within this namespace, */ namespace zmqpp { /*! * Returns the current major.minor.revision version number as a string. * * \return string version number. */ std::string version(); /*! * Retrieve the parts of the zmqpp version number. * * Set the three parameters to values representing the zmqpp version number. * These values are generated at library compile time. * * \param major an unsigned 8 bit reference to set to the major version. * \param minor an unsigned 8 bit reference to set to the minor version. * \param revision an unsigned 8 bit reference to set the current revision. */ void version(uint8_t& major, uint8_t& minor, uint8_t& revision); /*! * Retrieve the parts of the 0mq version this library was built against. * * Because sections of the library are optionally compiled in or ignored * depending on the version of 0mq it was compiled against this method is * provided to allow sanity checking for usage. * * Set the three parameters to values representing the 0mq version number. * These values are generated at library compile time. * * \param major an unsigned 8 bit reference to set to the major version. * \param minor an unsigned 8 bit reference to set to the minor version. * \param revision an unsigned 8 bit reference to set the current revision. */ void zmq_version(uint8_t& major, uint8_t& minor, uint8_t& patch); typedef context context_t; /*!< \brief context type */ typedef std::string endpoint_t; /*!< \brief endpoint type */ typedef message message_t; /*!< \brief message type */ typedef poller poller_t; /*!< \brief poller type */ typedef socket socket_t; /*!< \brief socket type */ } #endif /* ZMQPP_ZMQPP_HPP_ */ zmqpp-4.1.2/travis.sh000077500000000000000000000017171254036632700145520ustar00rootroot00000000000000#!/usr/bin/env bash set -e RCol='\e[0m' # Text Reset Red='\e[0;31m'; # Install libsodium is required if [ -n ${WITH_LIBSODIUM} ]; then git clone git://github.com/jedisct1/libsodium.git ( cd libsodium; ./autogen.sh ./configure make check || echo ${Red}"Warning: Libsodium tests failed. The build will continue but may fail."${RCol} sudo make install sudo ldconfig ) fi # Install specific libzmq version git clone git://github.com/zeromq/${ZMQ_REPO}.git; ( cd ${ZMQ_REPO} ./autogen.sh if [ -n ${WITH_LIBSODIUM} ]; then ./configure --with-libsodium else ./configure fi make check || echo ${Red}"Warning: ZeroMQ tests failed. The build will continue but may fail."${RCol} sudo make install sudo ldconfig ) # Build and test zmqpp if [ ${BUILD_TYPE} = "cmake" ]; then mkdir build; cd build; cmake ../ -DZMQPP_BUILD_TESTS=1 make ./zmqpp-test-runner else make CXXFLAGS='-DTRAVIS_CI_BUILD' check fi