Codebase list czmq / upstream/4.2.0
New upstream version 4.2.0 Luca Boccassi 5 years ago
299 changed file(s) with 34447 addition(s) and 6399 deletion(s). Raw diff Collapse all Expand all
1919
2020 # Will be used to add flags to pkg-config useful when apps want to statically link
2121 set(pkg_config_libs_private "")
22 set(pkg_config_names_private "")
2223
2324 ########################################################################
2425 # options
3738 OUTPUT_STRIP_TRAILING_WHITESPACE
3839 )
3940 message(STATUS "git workspace root [${git_result}]: ${git_root}")
40 if ( "${git_result}" == "0" )
41 if ( "${git_result}" STREQUAL "0" )
4142 set (CMAKE_BUILD_TYPE Debug)
4243 else ()
4344 set (CMAKE_BUILD_TYPE Release)
7071 CHECK_INCLUDE_FILE("net/if.h" HAVE_NET_IF_H)
7172 endif()
7273
73 file(WRITE "${SOURCE_DIR}/src/platform.h.in" "
74 file(REMOVE "${SOURCE_DIR}/src/platform.h")
75
76 file(WRITE "${CMAKE_BINARY_DIR}/platform.h.in" "
7477 #cmakedefine HAVE_LINUX_WIRELESS_H
7578 #cmakedefine HAVE_NET_IF_H
7679 #cmakedefine HAVE_NET_IF_MEDIA_H
7881 #cmakedefine HAVE_FREEIFADDRS
7982 ")
8083
81 configure_file("${SOURCE_DIR}/src/platform.h.in" "${SOURCE_DIR}/src/platform.h")
84 configure_file("${CMAKE_BINARY_DIR}/platform.h.in" "${CMAKE_BINARY_DIR}/platform.h")
8285
8386 #The MSVC C compiler is too out of date,
8487 #so the sources have to be compiled as c++
111114
112115 list(APPEND CMAKE_MODULE_PATH "${SOURCE_DIR}")
113116 set(OPTIONAL_LIBRARIES)
117 set(OPTIONAL_LIBRARIES_STATIC)
114118
115119 ########################################################################
116120 # LIBZMQ dependency
119123 IF (LIBZMQ_FOUND)
120124 include_directories(${LIBZMQ_INCLUDE_DIRS})
121125 list(APPEND MORE_LIBRARIES ${LIBZMQ_LIBRARIES})
122 set(pkg_config_libs_private "${pkg_config_libs_private} -lzmq")
126 IF (PC_LIBZMQ_FOUND)
127 set(pkg_config_names_private "${pkg_config_names_private} libzmq")
128 list(APPEND OPTIONAL_LIBRARIES_STATIC ${PC_LIBZMQ_STATIC_LDFLAGS})
129 ELSE (PC_LIBZMQ_FOUND)
130 set(pkg_config_libs_private "${pkg_config_libs_private} -lzmq")
131 ENDIF (PC_LIBZMQ_FOUND)
123132 ELSE (LIBZMQ_FOUND)
124133 message( FATAL_ERROR "libzmq not found." )
125134 ENDIF (LIBZMQ_FOUND)
131140 IF (UUID_FOUND)
132141 include_directories(${UUID_INCLUDE_DIRS})
133142 list(APPEND MORE_LIBRARIES ${UUID_LIBRARIES})
134 set(pkg_config_libs_private "${pkg_config_libs_private} -luuid")
143 IF (PC_UUID_FOUND)
144 set(pkg_config_names_private "${pkg_config_names_private} uuid")
145 list(APPEND OPTIONAL_LIBRARIES_STATIC ${PC_UUID_STATIC_LDFLAGS})
146 ELSE (PC_UUID_FOUND)
147 set(pkg_config_libs_private "${pkg_config_libs_private} -luuid")
148 ENDIF (PC_UUID_FOUND)
135149 add_definitions(-DHAVE_UUID)
136150 list(APPEND OPTIONAL_LIBRARIES ${UUID_LIBRARIES})
137151 ENDIF (UUID_FOUND)
143157 IF (SYSTEMD_FOUND)
144158 include_directories(${SYSTEMD_INCLUDE_DIRS})
145159 list(APPEND MORE_LIBRARIES ${SYSTEMD_LIBRARIES})
146 set(pkg_config_libs_private "${pkg_config_libs_private} -lsystemd")
160 IF (PC_SYSTEMD_FOUND)
161 set(pkg_config_names_private "${pkg_config_names_private} libsystemd >= 200.0.0")
162 list(APPEND OPTIONAL_LIBRARIES_STATIC ${PC_SYSTEMD_STATIC_LDFLAGS})
163 ELSE (PC_SYSTEMD_FOUND)
164 set(pkg_config_libs_private "${pkg_config_libs_private} -lsystemd")
165 ENDIF (PC_SYSTEMD_FOUND)
147166 add_definitions(-DHAVE_LIBSYSTEMD)
148167 list(APPEND OPTIONAL_LIBRARIES ${SYSTEMD_LIBRARIES})
149168 ENDIF (SYSTEMD_FOUND)
155174 IF (LZ4_FOUND)
156175 include_directories(${LZ4_INCLUDE_DIRS})
157176 list(APPEND MORE_LIBRARIES ${LZ4_LIBRARIES})
158 set(pkg_config_libs_private "${pkg_config_libs_private} -llz4")
177 IF (PC_LZ4_FOUND)
178 set(pkg_config_names_private "${pkg_config_names_private} liblz4")
179 list(APPEND OPTIONAL_LIBRARIES_STATIC ${PC_LZ4_STATIC_LDFLAGS})
180 ELSE (PC_LZ4_FOUND)
181 set(pkg_config_libs_private "${pkg_config_libs_private} -llz4")
182 ENDIF (PC_LZ4_FOUND)
159183 add_definitions(-DHAVE_LIBLZ4)
160184 list(APPEND OPTIONAL_LIBRARIES ${LZ4_LIBRARIES})
161185 ENDIF (LZ4_FOUND)
162186
163187 ########################################################################
188 # LIBCURL dependency
189 ########################################################################
190 find_package(libcurl)
191 IF (LIBCURL_FOUND)
192 include_directories(${LIBCURL_INCLUDE_DIRS})
193 list(APPEND MORE_LIBRARIES ${LIBCURL_LIBRARIES})
194 IF (PC_LIBCURL_FOUND)
195 set(pkg_config_names_private "${pkg_config_names_private} libcurl >= 7.28.0")
196 list(APPEND OPTIONAL_LIBRARIES_STATIC ${PC_LIBCURL_STATIC_LDFLAGS})
197 ELSE (PC_LIBCURL_FOUND)
198 set(pkg_config_libs_private "${pkg_config_libs_private} -lcurl")
199 ENDIF (PC_LIBCURL_FOUND)
200 add_definitions(-DHAVE_LIBCURL)
201 list(APPEND OPTIONAL_LIBRARIES ${LIBCURL_LIBRARIES})
202 ENDIF (LIBCURL_FOUND)
203
204 ########################################################################
205 # LIBMICROHTTPD dependency
206 ########################################################################
207 find_package(libmicrohttpd)
208 IF (LIBMICROHTTPD_FOUND)
209 include_directories(${LIBMICROHTTPD_INCLUDE_DIRS})
210 list(APPEND MORE_LIBRARIES ${LIBMICROHTTPD_LIBRARIES})
211 IF (PC_LIBMICROHTTPD_FOUND)
212 set(pkg_config_names_private "${pkg_config_names_private} libmicrohttpd")
213 list(APPEND OPTIONAL_LIBRARIES_STATIC ${PC_LIBMICROHTTPD_STATIC_LDFLAGS})
214 ELSE (PC_LIBMICROHTTPD_FOUND)
215 set(pkg_config_libs_private "${pkg_config_libs_private} -lmicrohttpd")
216 ENDIF (PC_LIBMICROHTTPD_FOUND)
217 add_definitions(-DHAVE_LIBMICROHTTPD)
218 list(APPEND OPTIONAL_LIBRARIES ${LIBMICROHTTPD_LIBRARIES})
219 ENDIF (LIBMICROHTTPD_FOUND)
220
221 ########################################################################
164222 # version
165223 ########################################################################
166224 set(CZMQ_VERSION_MAJOR 4)
167 set(CZMQ_VERSION_MINOR 1)
168 set(CZMQ_VERSION_PATCH 1)
225 set(CZMQ_VERSION_MINOR 2)
226 set(CZMQ_VERSION_PATCH 0)
169227 set(CZMQ_VERSION "${CZMQ_VERSION_MAJOR}.${CZMQ_VERSION_MINOR}.${CZMQ_VERSION_PATCH}")
170228 message(STATUS "Detected CZMQ Version - ${CZMQ_VERSION}")
171229
224282 include/zproc.h
225283 include/ztimerset.h
226284 include/ztrie.h
285 include/zhttp_client.h
286 include/zhttp_server.h
287 include/zhttp_server_options.h
288 include/zhttp_request.h
289 include/zhttp_response.h
227290 )
228291 ENDIF (ENABLE_DRAFTS)
229292
235298 ########################################################################
236299
237300
238 include_directories("${SOURCE_DIR}/src" "${SOURCE_DIR}/include")
301 include_directories("${SOURCE_DIR}/src" "${SOURCE_DIR}/include" "${CMAKE_BINARY_DIR}")
239302 set (czmq_sources
240303 src/zactor.c
241304 src/zarmour.c
276339 src/zproc.c
277340 src/ztimerset.c
278341 src/ztrie.c
342 src/zhttp_client.c
343 src/zhttp_server.c
344 src/zhttp_server_options.c
345 src/zhttp_request.c
346 src/zhttp_response.c
279347 )
280348 ENDIF (ENABLE_DRAFTS)
281349
321389 )
322390
323391 target_link_libraries(czmq
324 ${ZEROMQ_LIBRARIES} ${MORE_LIBRARIES}
392 PUBLIC ${MORE_LIBRARIES}
325393 )
326394
327395 install(TARGETS czmq
396 EXPORT czmq-targets
328397 LIBRARY DESTINATION "lib${LIB_SUFFIX}" # .so file
329398 ARCHIVE DESTINATION "lib${LIB_SUFFIX}" # .lib file
330399 RUNTIME DESTINATION bin # .dll file
331400 )
332401
333402 target_include_directories(czmq
334 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
403 PUBLIC
404 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
405 $<INSTALL_INTERFACE:include>
335406 )
336407 endif()
337408
351422 )
352423
353424 target_link_libraries(czmq-static
354 ${ZEROMQ_LIBRARIES} ${MORE_LIBRARIES}
425 PUBLIC ${MORE_LIBRARIES}
355426 )
356427
357428 install(TARGETS czmq-static
429 EXPORT czmq-targets
358430 LIBRARY DESTINATION "lib${LIB_SUFFIX}" # .so file
359431 ARCHIVE DESTINATION "lib${LIB_SUFFIX}" # .lib file
360432 RUNTIME DESTINATION bin # .dll file
361433 )
362434
363435 target_include_directories(czmq-static
364 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
436 PUBLIC
437 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
438 $<INSTALL_INTERFACE:include>
365439 )
366440 target_compile_definitions(czmq-static
367441 PUBLIC CZMQ_STATIC
375449 ########################################################################
376450 # pkgconfig
377451 ########################################################################
378 set (VERSION "4.1.1")
452 set (VERSION "4.2.0")
379453 set (prefix "${CMAKE_INSTALL_PREFIX}")
380454 set (exec_prefix "\${prefix}")
381455 set (libdir "\${prefix}/lib${LIB_SUFFIX}")
396470 )
397471
398472 ########################################################################
473 # installer
474 ########################################################################
475 include(CMakePackageConfigHelpers)
476 if (WIN32)
477 set(CMAKECONFIG_INSTALL_DIR "CMake" CACHE STRING "install path for czmqConfig.cmake")
478 else()
479 # GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
480 set(CMAKECONFIG_INSTALL_DIR "share/cmake/czmq" CACHE STRING "install path for czmqConfig.cmake")
481 endif()
482
483 if (NOT CMAKE_VERSION VERSION_LESS 3.0)
484 export(EXPORT czmq-targets
485 FILE "${CMAKE_CURRENT_BINARY_DIR}/czmqTargets.cmake")
486 endif()
487 configure_package_config_file(builds/cmake/Config.cmake.in
488 "${CMAKE_CURRENT_BINARY_DIR}/czmqConfig.cmake"
489 INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR})
490 write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/czmqConfigVersion.cmake
491 VERSION ${CZMQ_VERSION}
492 COMPATIBILITY AnyNewerVersion)
493 install(EXPORT czmq-targets
494 FILE czmqTargets.cmake
495 DESTINATION ${CMAKECONFIG_INSTALL_DIR})
496 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/czmqConfig.cmake
497 ${CMAKE_CURRENT_BINARY_DIR}/czmqConfigVersion.cmake
498 DESTINATION ${CMAKECONFIG_INSTALL_DIR})
499
500 ########################################################################
399501 # executables
400502 ########################################################################
401503 add_executable(
416518 czmq-static
417519 ${LIBZMQ_LIBRARIES}
418520 ${OPTIONAL_LIBRARIES}
521 ${OPTIONAL_LIBRARIES_STATIC}
419522 )
420523 endif()
421524 install(TARGETS zmakecert
439542 czmq-static
440543 ${LIBZMQ_LIBRARIES}
441544 ${OPTIONAL_LIBRARIES}
545 ${OPTIONAL_LIBRARIES_STATIC}
442546 )
443547 endif()
444548 add_executable(
459563 czmq-static
460564 ${LIBZMQ_LIBRARIES}
461565 ${OPTIONAL_LIBRARIES}
566 ${OPTIONAL_LIBRARIES_STATIC}
462567 )
463568 endif()
464569 add_executable(
479584 czmq-static
480585 ${LIBZMQ_LIBRARIES}
481586 ${OPTIONAL_LIBRARIES}
587 ${OPTIONAL_LIBRARIES_STATIC}
482588 )
483589 endif()
484590
534640 zproc
535641 ztimerset
536642 ztrie
643 zhttp_client
644 zhttp_server
645 zhttp_server_options
646 zhttp_request
647 zhttp_response
537648 )
538649 ENDIF (ENABLE_DRAFTS)
539650
589700 ${CMAKE_BINARY_DIR}/DartConfiguration.tcl
590701 ${CMAKE_BINARY_DIR}/Testing
591702 ${CMAKE_BINARY_DIR}/compile_commands.json
592 ${CMAKE_BINARY_DIR}/src/platform.h
703 ${CMAKE_BINARY_DIR}/platform.h
593704 ${CMAKE_BINARY_DIR}/src/libczmq.pc
594705 ${CMAKE_BINARY_DIR}/src/libczmq.so
595706 ${CMAKE_BINARY_DIR}/src/czmq_selftest
607718 TARGET distclean
608719 )
609720
610 include(ClangFormat)
721 include(ClangFormat OPTIONAL)
611722
612723 ########################################################################
613724 # summary
0 ################################################################################
1 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
2 # Read the zproject/README.md for information about making permanent changes. #
3 ################################################################################
4
5 if (NOT MSVC)
6 include(FindPkgConfig)
7 pkg_check_modules(PC_LIBCURL "libcurl")
8 if (PC_LIBCURL_FOUND)
9 # add CFLAGS from pkg-config file, e.g. draft api.
10 add_definitions(${PC_LIBCURL_CFLAGS} ${PC_LIBCURL_CFLAGS_OTHER})
11 # some libraries install the headers is a subdirectory of the include dir
12 # returned by pkg-config, so use a wildcard match to improve chances of finding
13 # headers and SOs.
14 set(PC_LIBCURL_INCLUDE_HINTS ${PC_LIBCURL_INCLUDE_DIRS} ${PC_LIBCURL_INCLUDE_DIRS}/*)
15 set(PC_LIBCURL_LIBRARY_HINTS ${PC_LIBCURL_LIBRARY_DIRS} ${PC_LIBCURL_LIBRARY_DIRS}/*)
16 endif(PC_LIBCURL_FOUND)
17 endif (NOT MSVC)
18
19 find_path (
20 LIBCURL_INCLUDE_DIRS
21 NAMES curl/curl.h
22 HINTS ${PC_LIBCURL_INCLUDE_HINTS}
23 )
24
25 find_library (
26 LIBCURL_LIBRARIES
27 NAMES curl
28 HINTS ${PC_LIBCURL_LIBRARY_HINTS}
29 )
30
31 include(FindPackageHandleStandardArgs)
32
33 find_package_handle_standard_args(
34 LIBCURL
35 REQUIRED_VARS LIBCURL_LIBRARIES LIBCURL_INCLUDE_DIRS
36 )
37 mark_as_advanced(
38 LIBCURL_FOUND
39 LIBCURL_LIBRARIES LIBCURL_INCLUDE_DIRS
40 )
41
42 ################################################################################
43 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
44 # Read the zproject/README.md for information about making permanent changes. #
45 ################################################################################
0 ################################################################################
1 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
2 # Read the zproject/README.md for information about making permanent changes. #
3 ################################################################################
4
5 if (NOT MSVC)
6 include(FindPkgConfig)
7 pkg_check_modules(PC_LIBMICROHTTPD "libmicrohttpd")
8 if (PC_LIBMICROHTTPD_FOUND)
9 # add CFLAGS from pkg-config file, e.g. draft api.
10 add_definitions(${PC_LIBMICROHTTPD_CFLAGS} ${PC_LIBMICROHTTPD_CFLAGS_OTHER})
11 # some libraries install the headers is a subdirectory of the include dir
12 # returned by pkg-config, so use a wildcard match to improve chances of finding
13 # headers and SOs.
14 set(PC_LIBMICROHTTPD_INCLUDE_HINTS ${PC_LIBMICROHTTPD_INCLUDE_DIRS} ${PC_LIBMICROHTTPD_INCLUDE_DIRS}/*)
15 set(PC_LIBMICROHTTPD_LIBRARY_HINTS ${PC_LIBMICROHTTPD_LIBRARY_DIRS} ${PC_LIBMICROHTTPD_LIBRARY_DIRS}/*)
16 endif(PC_LIBMICROHTTPD_FOUND)
17 endif (NOT MSVC)
18
19 find_path (
20 LIBMICROHTTPD_INCLUDE_DIRS
21 NAMES microhttpd.h
22 HINTS ${PC_LIBMICROHTTPD_INCLUDE_HINTS}
23 )
24
25 find_library (
26 LIBMICROHTTPD_LIBRARIES
27 NAMES microhttpd
28 HINTS ${PC_LIBMICROHTTPD_LIBRARY_HINTS}
29 )
30
31 include(FindPackageHandleStandardArgs)
32
33 find_package_handle_standard_args(
34 LIBMICROHTTPD
35 REQUIRED_VARS LIBMICROHTTPD_LIBRARIES LIBMICROHTTPD_INCLUDE_DIRS
36 )
37 mark_as_advanced(
38 LIBMICROHTTPD_FOUND
39 LIBMICROHTTPD_LIBRARIES LIBMICROHTTPD_INCLUDE_DIRS
40 )
41
42 ################################################################################
43 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
44 # Read the zproject/README.md for information about making permanent changes. #
45 ################################################################################
55 if (NOT MSVC)
66 include(FindPkgConfig)
77 pkg_check_modules(PC_LIBZMQ "libzmq")
8 if (NOT PC_LIBZMQ_FOUND)
9 pkg_check_modules(PC_LIBZMQ "libzmq")
10 endif (NOT PC_LIBZMQ_FOUND)
118 if (PC_LIBZMQ_FOUND)
129 # add CFLAGS from pkg-config file, e.g. draft api.
1310 add_definitions(${PC_LIBZMQ_CFLAGS} ${PC_LIBZMQ_CFLAGS_OTHER})
55 if (NOT MSVC)
66 include(FindPkgConfig)
77 pkg_check_modules(PC_LZ4 "liblz4")
8 if (NOT PC_LZ4_FOUND)
9 pkg_check_modules(PC_LZ4 "liblz4")
10 endif (NOT PC_LZ4_FOUND)
118 if (PC_LZ4_FOUND)
129 # add CFLAGS from pkg-config file, e.g. draft api.
1310 add_definitions(${PC_LZ4_CFLAGS} ${PC_LZ4_CFLAGS_OTHER})
55 if (NOT MSVC)
66 include(FindPkgConfig)
77 pkg_check_modules(PC_SYSTEMD "libsystemd")
8 if (NOT PC_SYSTEMD_FOUND)
9 pkg_check_modules(PC_SYSTEMD "libsystemd")
10 endif (NOT PC_SYSTEMD_FOUND)
118 if (PC_SYSTEMD_FOUND)
129 # add CFLAGS from pkg-config file, e.g. draft api.
1310 add_definitions(${PC_SYSTEMD_CFLAGS} ${PC_SYSTEMD_CFLAGS_OTHER})
2724
2825 find_library (
2926 SYSTEMD_LIBRARIES
30 NAMES libsystemd
27 NAMES systemd
3128 HINTS ${PC_SYSTEMD_LIBRARY_HINTS}
3229 )
3330
55 if (NOT MSVC)
66 include(FindPkgConfig)
77 pkg_check_modules(PC_UUID "uuid")
8 if (NOT PC_UUID_FOUND)
9 pkg_check_modules(PC_UUID "uuid")
10 endif (NOT PC_UUID_FOUND)
118 if (PC_UUID_FOUND)
129 # add CFLAGS from pkg-config file, e.g. draft api.
1310 add_definitions(${PC_UUID_CFLAGS} ${PC_UUID_CFLAGS_OTHER})
44
55 ACLOCAL_AMFLAGS = -I config
66
7 AM_CFLAGS = \
8 -Werror=format-security
9
107
118 AM_CPPFLAGS = \
129 ${libzmq_CFLAGS} \
1310 ${uuid_CFLAGS} \
1411 ${systemd_CFLAGS} \
1512 ${lz4_CFLAGS} \
13 ${libcurl_CFLAGS} \
14 ${libmicrohttpd_CFLAGS} \
1615 -I$(srcdir)/include
1716
18 project_libs = ${libzmq_LIBS} ${uuid_LIBS} ${systemd_LIBS} ${lz4_LIBS}
17 project_libs = ${libzmq_LIBS} ${uuid_LIBS} ${systemd_LIBS} ${lz4_LIBS} ${libcurl_LIBS} ${libmicrohttpd_LIBS}
1918
2019 SUBDIRS = doc
2120 SUBDIRS += include
4039 Finduuid.cmake \
4140 Findsystemd.cmake \
4241 Findlz4.cmake \
42 Findlibcurl.cmake \
43 Findlibmicrohttpd.cmake \
4344 src/CMakeLists-local.txt \
45 builds/cmake/Modules/ClangFormat.cmake \
46 builds/cmake/clang-format-check.sh.in \
47 builds/cmake/Config.cmake.in \
4448 CMakeLists.txt
4549 endif
4650
9595 @ENABLE_DIST_CMAKEFILES_TRUE@ Finduuid.cmake \
9696 @ENABLE_DIST_CMAKEFILES_TRUE@ Findsystemd.cmake \
9797 @ENABLE_DIST_CMAKEFILES_TRUE@ Findlz4.cmake \
98 @ENABLE_DIST_CMAKEFILES_TRUE@ Findlibcurl.cmake \
99 @ENABLE_DIST_CMAKEFILES_TRUE@ Findlibmicrohttpd.cmake \
98100 @ENABLE_DIST_CMAKEFILES_TRUE@ src/CMakeLists-local.txt \
101 @ENABLE_DIST_CMAKEFILES_TRUE@ builds/cmake/Modules/ClangFormat.cmake \
102 @ENABLE_DIST_CMAKEFILES_TRUE@ builds/cmake/clang-format-check.sh.in \
103 @ENABLE_DIST_CMAKEFILES_TRUE@ builds/cmake/Config.cmake.in \
99104 @ENABLE_DIST_CMAKEFILES_TRUE@ CMakeLists.txt
100105
101106 DIST_COMMON = $(srcdir)/src/Makemodule.am \
116121 @ENABLE_SHARED_FALSE@am__append_2 = -lstdc++ -lm
117122 @ENABLE_DRAFTS_TRUE@am__append_3 = src/zargs.c src/zproc.c \
118123 @ENABLE_DRAFTS_TRUE@ src/ztimerset.c src/ztrie.c \
124 @ENABLE_DRAFTS_TRUE@ src/zhttp_client.c src/zhttp_server.c \
125 @ENABLE_DRAFTS_TRUE@ src/zhttp_server_options.c \
126 @ENABLE_DRAFTS_TRUE@ src/zhttp_request.c src/zhttp_response.c \
119127 @ENABLE_DRAFTS_TRUE@ src/czmq_private_selftest.c
120128 @ON_MINGW_TRUE@am__append_4 = \
121129 @ON_MINGW_TRUE@ -no-undefined \
182190 LTLIBRARIES = $(lib_LTLIBRARIES) $(noinst_LTLIBRARIES)
183191 am__DEPENDENCIES_1 =
184192 am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
193 $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
185194 $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
186195 src_libczmq_la_DEPENDENCIES = $(am__DEPENDENCIES_2) \
187196 $(am__DEPENDENCIES_1)
197206 src/foreign/sha1/sha1.inc_c src/foreign/sha1/sha1.h \
198207 src/foreign/slre/slre.inc_c src/foreign/slre/slre.h \
199208 src/foreign/slre/readme.txt src/platform.h src/zargs.c \
200 src/zproc.c src/ztimerset.c src/ztrie.c \
209 src/zproc.c src/ztimerset.c src/ztrie.c src/zhttp_client.c \
210 src/zhttp_server.c src/zhttp_server_options.c \
211 src/zhttp_request.c src/zhttp_response.c \
201212 src/czmq_private_selftest.c
202213 am__dirstamp = $(am__leading_dot)dirstamp
203214 @ENABLE_DRAFTS_TRUE@am__objects_1 = src/src_libczmq_la-zargs.lo \
204215 @ENABLE_DRAFTS_TRUE@ src/src_libczmq_la-zproc.lo \
205216 @ENABLE_DRAFTS_TRUE@ src/src_libczmq_la-ztimerset.lo \
206217 @ENABLE_DRAFTS_TRUE@ src/src_libczmq_la-ztrie.lo \
218 @ENABLE_DRAFTS_TRUE@ src/src_libczmq_la-zhttp_client.lo \
219 @ENABLE_DRAFTS_TRUE@ src/src_libczmq_la-zhttp_server.lo \
220 @ENABLE_DRAFTS_TRUE@ src/src_libczmq_la-zhttp_server_options.lo \
221 @ENABLE_DRAFTS_TRUE@ src/src_libczmq_la-zhttp_request.lo \
222 @ENABLE_DRAFTS_TRUE@ src/src_libczmq_la-zhttp_response.lo \
207223 @ENABLE_DRAFTS_TRUE@ src/src_libczmq_la-czmq_private_selftest.lo
208224 am_src_libczmq_la_OBJECTS = src/src_libczmq_la-zactor.lo \
209225 src/src_libczmq_la-zarmour.lo src/src_libczmq_la-zcert.lo \
667683 includedir = @includedir@
668684 infodir = @infodir@
669685 install_sh = @install_sh@
686 libcurl_CFLAGS = @libcurl_CFLAGS@
687 libcurl_LIBS = @libcurl_LIBS@
670688 libdir = @libdir@
671689 libexecdir = @libexecdir@
690 libmicrohttpd_CFLAGS = @libmicrohttpd_CFLAGS@
691 libmicrohttpd_LIBS = @libmicrohttpd_LIBS@
672692 libzmq_CFLAGS = @libzmq_CFLAGS@
673693 libzmq_LIBS = @libzmq_LIBS@
674694 localedir = @localedir@
681701 pdfdir = @pdfdir@
682702 pkg_config_defines = @pkg_config_defines@
683703 pkg_config_libs_private = @pkg_config_libs_private@
684 pkgconfig_name_liblz4 = @pkgconfig_name_liblz4@
685 pkgconfig_name_libsystemd = @pkgconfig_name_libsystemd@
686 pkgconfig_name_libzmq = @pkgconfig_name_libzmq@
687 pkgconfig_name_uuid = @pkgconfig_name_uuid@
704 pkg_config_names_private = @pkg_config_names_private@
688705 pkgconfigdir = @pkgconfigdir@
689706 prefix = @prefix@
690707 program_transform_name = @program_transform_name@
702719 uuid_CFLAGS = @uuid_CFLAGS@
703720 uuid_LIBS = @uuid_LIBS@
704721 ACLOCAL_AMFLAGS = -I config
705 AM_CFLAGS = \
706 -Werror=format-security
707
708722 AM_CPPFLAGS = \
709723 ${libzmq_CFLAGS} \
710724 ${uuid_CFLAGS} \
711725 ${systemd_CFLAGS} \
712726 ${lz4_CFLAGS} \
727 ${libcurl_CFLAGS} \
728 ${libmicrohttpd_CFLAGS} \
713729 -I$(srcdir)/include
714730
715 project_libs = ${libzmq_LIBS} ${uuid_LIBS} ${systemd_LIBS} ${lz4_LIBS}
731 project_libs = ${libzmq_LIBS} ${uuid_LIBS} ${systemd_LIBS} ${lz4_LIBS} ${libcurl_LIBS} ${libmicrohttpd_LIBS}
716732 SUBDIRS = doc include
717733 DIST_SUBDIRS = doc include
718734 lib_LTLIBRARIES = src/libczmq.la
804820 api/ztimerset.api \
805821 api/ztrie.api \
806822 api/zuuid.api \
823 api/zhttp_client.api \
824 api/zhttp_server.api \
825 api/zhttp_server_options.api \
826 api/zhttp_request.api \
827 api/zhttp_response.api \
807828 api/zgossip_msg.api
808829
809830
10281049 src/src_libczmq_la-ztimerset.lo: src/$(am__dirstamp) \
10291050 src/$(DEPDIR)/$(am__dirstamp)
10301051 src/src_libczmq_la-ztrie.lo: src/$(am__dirstamp) \
1052 src/$(DEPDIR)/$(am__dirstamp)
1053 src/src_libczmq_la-zhttp_client.lo: src/$(am__dirstamp) \
1054 src/$(DEPDIR)/$(am__dirstamp)
1055 src/src_libczmq_la-zhttp_server.lo: src/$(am__dirstamp) \
1056 src/$(DEPDIR)/$(am__dirstamp)
1057 src/src_libczmq_la-zhttp_server_options.lo: src/$(am__dirstamp) \
1058 src/$(DEPDIR)/$(am__dirstamp)
1059 src/src_libczmq_la-zhttp_request.lo: src/$(am__dirstamp) \
1060 src/$(DEPDIR)/$(am__dirstamp)
1061 src/src_libczmq_la-zhttp_response.lo: src/$(am__dirstamp) \
10311062 src/$(DEPDIR)/$(am__dirstamp)
10321063 src/src_libczmq_la-czmq_private_selftest.lo: src/$(am__dirstamp) \
10331064 src/$(DEPDIR)/$(am__dirstamp)
11551186 @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_libczmq_la-zgossip_msg.Plo@am__quote@
11561187 @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_libczmq_la-zhash.Plo@am__quote@
11571188 @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_libczmq_la-zhashx.Plo@am__quote@
1189 @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_libczmq_la-zhttp_client.Plo@am__quote@
1190 @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_libczmq_la-zhttp_request.Plo@am__quote@
1191 @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_libczmq_la-zhttp_response.Plo@am__quote@
1192 @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_libczmq_la-zhttp_server.Plo@am__quote@
1193 @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_libczmq_la-zhttp_server_options.Plo@am__quote@
11581194 @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_libczmq_la-ziflist.Plo@am__quote@
11591195 @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_libczmq_la-zlist.Plo@am__quote@
11601196 @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_libczmq_la-zlistx.Plo@am__quote@
14431479 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/ztrie.c' object='src/src_libczmq_la-ztrie.lo' libtool=yes @AMDEPBACKSLASH@
14441480 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
14451481 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_libczmq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/src_libczmq_la-ztrie.lo `test -f 'src/ztrie.c' || echo '$(srcdir)/'`src/ztrie.c
1482
1483 src/src_libczmq_la-zhttp_client.lo: src/zhttp_client.c
1484 @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_libczmq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/src_libczmq_la-zhttp_client.lo -MD -MP -MF src/$(DEPDIR)/src_libczmq_la-zhttp_client.Tpo -c -o src/src_libczmq_la-zhttp_client.lo `test -f 'src/zhttp_client.c' || echo '$(srcdir)/'`src/zhttp_client.c
1485 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/src_libczmq_la-zhttp_client.Tpo src/$(DEPDIR)/src_libczmq_la-zhttp_client.Plo
1486 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/zhttp_client.c' object='src/src_libczmq_la-zhttp_client.lo' libtool=yes @AMDEPBACKSLASH@
1487 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
1488 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_libczmq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/src_libczmq_la-zhttp_client.lo `test -f 'src/zhttp_client.c' || echo '$(srcdir)/'`src/zhttp_client.c
1489
1490 src/src_libczmq_la-zhttp_server.lo: src/zhttp_server.c
1491 @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_libczmq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/src_libczmq_la-zhttp_server.lo -MD -MP -MF src/$(DEPDIR)/src_libczmq_la-zhttp_server.Tpo -c -o src/src_libczmq_la-zhttp_server.lo `test -f 'src/zhttp_server.c' || echo '$(srcdir)/'`src/zhttp_server.c
1492 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/src_libczmq_la-zhttp_server.Tpo src/$(DEPDIR)/src_libczmq_la-zhttp_server.Plo
1493 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/zhttp_server.c' object='src/src_libczmq_la-zhttp_server.lo' libtool=yes @AMDEPBACKSLASH@
1494 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
1495 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_libczmq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/src_libczmq_la-zhttp_server.lo `test -f 'src/zhttp_server.c' || echo '$(srcdir)/'`src/zhttp_server.c
1496
1497 src/src_libczmq_la-zhttp_server_options.lo: src/zhttp_server_options.c
1498 @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_libczmq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/src_libczmq_la-zhttp_server_options.lo -MD -MP -MF src/$(DEPDIR)/src_libczmq_la-zhttp_server_options.Tpo -c -o src/src_libczmq_la-zhttp_server_options.lo `test -f 'src/zhttp_server_options.c' || echo '$(srcdir)/'`src/zhttp_server_options.c
1499 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/src_libczmq_la-zhttp_server_options.Tpo src/$(DEPDIR)/src_libczmq_la-zhttp_server_options.Plo
1500 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/zhttp_server_options.c' object='src/src_libczmq_la-zhttp_server_options.lo' libtool=yes @AMDEPBACKSLASH@
1501 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
1502 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_libczmq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/src_libczmq_la-zhttp_server_options.lo `test -f 'src/zhttp_server_options.c' || echo '$(srcdir)/'`src/zhttp_server_options.c
1503
1504 src/src_libczmq_la-zhttp_request.lo: src/zhttp_request.c
1505 @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_libczmq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/src_libczmq_la-zhttp_request.lo -MD -MP -MF src/$(DEPDIR)/src_libczmq_la-zhttp_request.Tpo -c -o src/src_libczmq_la-zhttp_request.lo `test -f 'src/zhttp_request.c' || echo '$(srcdir)/'`src/zhttp_request.c
1506 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/src_libczmq_la-zhttp_request.Tpo src/$(DEPDIR)/src_libczmq_la-zhttp_request.Plo
1507 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/zhttp_request.c' object='src/src_libczmq_la-zhttp_request.lo' libtool=yes @AMDEPBACKSLASH@
1508 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
1509 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_libczmq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/src_libczmq_la-zhttp_request.lo `test -f 'src/zhttp_request.c' || echo '$(srcdir)/'`src/zhttp_request.c
1510
1511 src/src_libczmq_la-zhttp_response.lo: src/zhttp_response.c
1512 @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_libczmq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/src_libczmq_la-zhttp_response.lo -MD -MP -MF src/$(DEPDIR)/src_libczmq_la-zhttp_response.Tpo -c -o src/src_libczmq_la-zhttp_response.lo `test -f 'src/zhttp_response.c' || echo '$(srcdir)/'`src/zhttp_response.c
1513 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/src_libczmq_la-zhttp_response.Tpo src/$(DEPDIR)/src_libczmq_la-zhttp_response.Plo
1514 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/zhttp_response.c' object='src/src_libczmq_la-zhttp_response.lo' libtool=yes @AMDEPBACKSLASH@
1515 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
1516 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_libczmq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/src_libczmq_la-zhttp_response.lo `test -f 'src/zhttp_response.c' || echo '$(srcdir)/'`src/zhttp_response.c
14461517
14471518 src/src_libczmq_la-czmq_private_selftest.lo: src/czmq_private_selftest.c
14481519 @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_libczmq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/src_libczmq_la-czmq_private_selftest.lo -MD -MP -MF src/$(DEPDIR)/src_libczmq_la-czmq_private_selftest.Tpo -c -o src/src_libczmq_la-czmq_private_selftest.lo `test -f 'src/czmq_private_selftest.c' || echo '$(srcdir)/'`src/czmq_private_selftest.c
22872358 @WITH_GCOV_FALSE@coverage: src/czmq_selftest
22882359 @WITH_GCOV_FALSE@ @echo "call make clean && configure --with-gcov to enable code coverage"
22892360 @WITH_GCOV_FALSE@ @exit 1
2361
2362 bindings: python-bindings
2363
2364 python-bindings:
2365 @ENABLE_BINDINGS_PYTHON_TRUE@ -( cd bindings/python && python setup.py install )
2366 @ENABLE_BINDINGS_PYTHON_FALSE@ @echo "Python Bindings not enabled or missing setup.py... skipping"
22902367 check-style: $(CHECK_STYLE_DEPS)
22912368
22922369 # Check if any sources need to be fixed, report the filenames and an error code
0 CZMQ version 4.2.0 stable, released on 2019/02/10
1 =================================================
2
3 * Note for packagers: as pkg-config's Requires.private is now used to properly
4 propagate dependencies for static builds, the libczmq*-dev or czmq-devel or
5 equivalent package should now depend on the libfoo-dev or foo-devel packages
6 of all the libraries that czmq is linked against, or pkg-config --libs libczmq
7 will fail due to missing dependencies on end users machines.
8
9 * New STABLE APIs have been added to wrap new libzmq context
10 options:
11 - zsys_thread_name_prefix, zsys_set_thread_name_prefix
12 - zsys_thread_affinity_cpu_add, zsys_thread_affinity_cpu_remove
13 See zsys manpage for more details.
14
15 * New STABLE zsock API to match libzmq's 4.3.0 stable socket options:
16 - zsock_bindtodevice, zsock_set_bindtodevice
17 - zsock_gssapi_service_principal_nametype, zsock_set_gssapi_service_principal_nametype
18 - zsock_gssapi_principal_nametype, zsock_set_gssapi_principal_nametype
19 See zsock manpage for more details.
20
21 * New DRAFT zsock API to match libzmq's 4.3.0 stable socket options:
22 - zsock_router_notify, zsock_set_router_notify
23 - zsock_multicast_loop, zsock_set_multicast_loop
24 - zsock_metadata, zsock_set_metadata
25 - zsock_loopback_fastpath, zsock_set_loopback_fastpath
26 - zsock_zap_enforce_domain, zsock_set_zap_enforce_domain
27 See zsock manpage for more details.
28
29 * New DRAFT zconfig API to duplicate a zconfig instance:
30 - zconfig_dup
31 See zconfig manpage for more details.
32
33 * New DRAFT zproxy functionality to let SUB/XSUB subscribe to topics by appending
34 additional strings to the FRONTEND/BACKEND control messages.
35 See zproxy manpage for more details.
36
37 * New DRAFT zsys APIs to print python-like formatted strings:
38 - zsys_zprintf
39 - zsys_zprintf_error
40 - zsys_zplprintf
41 - zsys_zplprintf_error
42 See zsys manpage for more details.
43
44 * New DRAFT zgossip API to unpublish to stop sending a key/value pair to the
45 cluster. Use the UNPUBLISH keyword string as a command.
46 See zconfig manpage for more details.
47
48 * New DRAFT zlistx API to pack and unpack zframes:
49 - zlistx_pack, zlistx_unpack
50 zlistx are now supported by the zsock_send/receive APIs with type "l".
51 See zlistx manpage for more details.
52
53 * New DRAFT zlistx API to pack and unpack zframes:
54 - zlistx_pack, zlistx_unpack
55 zlistx are now supported by the zsock_send/receive APIs with type "l".
56 See zlistx manpage for more details.
57
58 * New DRAFT zhttp_client, zhttp_server, zhttp_server_options, zhttp_request and
59 zhttp_response to build both server and client http applications.
60 Requires linking with libcurl and libmicrohttpd.
61 See zhttp_* manpages for more details.
62
63 * New DRAFT zchunk API to create zero-copy chunks:
64 - zchunk_frommem
65 - zchunk_packx
66 See zchunk manpage for more details.
67
68 * Many fixes and improvements to the zproc and zargs DRAFT classes.
69
70 * Fixed #1825 - zbeacon_test and zpoller_test hang indefinitely with libzmq 2.x.
71
72 * Fixed #1899 - zsys_udp_new leaks file descriptor when process is exec'd.
73
74 * Fixed #1907 - build fails on debian/kfreebsd.
75
76 * Fixed #1948 - zlistx_head always returns NULL.
77
78 * Fixed #1959 - zhash_pack crash on armv7 due to unaligned pointer access.
79
80 * Fixed #1961 - unnecessary uuid includes in public headers break builds without
81 libuuid.
82
83 * Fixed #1995 - timers are called twice if they change the pollset.
84
085 CZMQ version 4.1.1 stable, released on 2018/03/22
186 =================================================
287
+2074
-1093
README.md less more
117117
118118 To start with, you need at least these packages:
119119
120 * {{git-all}} -- git is how we share code with other people.
120 * {{git}} -- git is how we share code with other people.
121121
122122 * {{build-essential}}, {{libtool}}, {{pkg-config}} - the C compiler and related tools.
123123
127127
128128 Plus some others:
129129
130 * {{uuid-dev}}, {{libpcre3-dev}} - utility libraries.
130 * {{uuid-dev}}, {{libpcre3-dev}}, {{libsodium-dev}} - utility libraries.
131131
132132 * {{valgrind}} - a useful tool for checking your code.
133133
137137
138138 sudo apt-get update
139139 sudo apt-get install -y \
140 git-all build-essential libtool \
140 git build-essential libtool \
141141 pkg-config autotools-dev autoconf automake cmake \
142 uuid-dev libpcre3-dev valgrind
142 uuid-dev libpcre3-dev libsodium-dev valgrind
143143
144144 # only execute this next line if interested in updating the man pages as well (adds to build time):
145145 sudo apt-get install -y asciidoc
310310 zactor_destroy (zactor_t **self_p);
311311
312312 // Send a zmsg message to the actor, take ownership of the message
313 // and destroy when it has been sent.
313 // and destroy when it has been sent.
314314 CZMQ_EXPORT int
315315 zactor_send (zactor_t *self, zmsg_t **msg_p);
316316
317 // Receive a zmsg message from the actor. Returns NULL if the actor
317 // Receive a zmsg message from the actor. Returns NULL if the actor
318318 // was interrupted before the message could be received, or if there
319 // was a timeout on the actor.
319 // was a timeout on the actor.
320320 // Caller owns return value and must destroy it when done.
321321 CZMQ_EXPORT zmsg_t *
322322 zactor_recv (zactor_t *self);
326326 zactor_is (void *self);
327327
328328 // Probe the supplied reference. If it looks like a zactor_t instance,
329 // return the underlying libzmq actor handle; else if it looks like
330 // a libzmq actor handle, return the supplied value.
329 // return the underlying libzmq actor handle; else if it looks like
330 // a libzmq actor handle, return the supplied value.
331331 CZMQ_EXPORT void *
332332 zactor_resolve (void *self);
333333
334334 // Return the actor's zsock handle. Use this when you absolutely need
335 // to work with the zsock instance rather than the actor.
335 // to work with the zsock instance rather than the actor.
336336 CZMQ_EXPORT zsock_t *
337337 zactor_sock (zactor_t *self);
338338
345345 //
346346 // An example - to send $KTHXBAI string
347347 //
348 // if (zstr_send (self->pipe, "$KTHXBAI") == 0)
349 // zsock_wait (self->pipe);
348 // if (zstr_send (self, "$KTHXBAI") == 0)
349 // zsock_wait (self);
350350 typedef void (zactor_destructor_fn) (
351351 zactor_t *self);
352
352
353353 // *** Draft method, for development use, may change without warning ***
354354 // Change default destructor by custom function. Actor MUST be able to handle new message instead of default $TERM.
355355 CZMQ_EXPORT void
356356 zactor_set_destructor (zactor_t *self, zactor_destructor_fn destructor);
357
357
358358 #endif // CZMQ_BUILD_DRAFT_API
359359 ```
360360 Please add '@interface' section in './../src/zactor.c'.
367367 zstr_sendx (actor, "ECHO", "This is a string", NULL);
368368 char *string = zstr_recv (actor);
369369 assert (streq (string, "This is a string"));
370 free (string);
370 freen (string);
371371 zactor_destroy (&actor);
372372
373373 // custom destructor
377377 // which is the one sent by KTHXBAI_destructor
378378 zactor_set_destructor (KTHXBAI, KTHXBAI_destructor);
379379 zactor_destroy (&KTHXBAI);
380
380
381 // custom destructor
382 // destructor using bsend/brecv
383 zactor_t *BSEND = zactor_new (BSEND_actor, NULL);
384 assert (BSEND);
385 zactor_set_destructor (BSEND, BSEND_destructor);
386 zactor_destroy (&BSEND);
381387 #if defined (__WINDOWS__)
382388 zsys_shutdown();
383389 #endif
473479 This is the class self test code:
474480
475481 ```c
482
483 const char *SELFTEST_DIR_RW = "src/selftest-rw";
484
485 const char *testbasedir = ".test_zauth";
486 const char *testpassfile = "password-file";
487 const char *testcertfile = "mycert.txt";
488 char *basedirpath = NULL; // subdir in a test, under SELFTEST_DIR_RW
489 char *passfilepath = NULL; // pathname to testfile in a test, in dirpath
490 char *certfilepath = NULL; // pathname to testfile in a test, in dirpath
491
492 basedirpath = zsys_sprintf ("%s/%s", SELFTEST_DIR_RW, testbasedir);
493 assert (basedirpath);
494 passfilepath = zsys_sprintf ("%s/%s", basedirpath, testpassfile);
495 assert (passfilepath);
496 certfilepath = zsys_sprintf ("%s/%s", basedirpath, testcertfile);
497 assert (certfilepath);
498
499 // Make sure old aborted tests do not hinder us
500 zdir_t *dir = zdir_new (basedirpath, NULL);
501 if (dir) {
502 zdir_remove (dir, true);
503 zdir_destroy (&dir);
504 }
505 zsys_file_delete (passfilepath);
506 zsys_file_delete (certfilepath);
507 zsys_dir_delete (basedirpath);
508
476509 // Create temporary directory for test files
477 # define TESTDIR ".test_zauth"
478 zsys_dir_create (TESTDIR);
510 zsys_dir_create (basedirpath);
479511
480512 // Check there's no authentication
481513 zsock_t *server = zsock_new (ZMQ_PULL);
518550 assert (success);
519551
520552 // Try PLAIN authentication
553 zsock_set_zap_domain (server, "global");
521554 zsock_set_plain_server (server, 1);
522555 zsock_set_plain_username (client, "admin");
523556 zsock_set_plain_password (client, "Password");
524557 success = s_can_connect (&server, &client, true);
525558 assert (!success);
526559
527 FILE *password = fopen (TESTDIR "/password-file", "w");
560 FILE *password = fopen (passfilepath, "w");
528561 assert (password);
529562 fprintf (password, "admin=Password\n");
530563 fclose (password);
564 zsock_set_zap_domain (server, "global");
531565 zsock_set_plain_server (server, 1);
532566 zsock_set_plain_username (client, "admin");
533567 zsock_set_plain_password (client, "Password");
534 zstr_sendx (auth, "PLAIN", TESTDIR "/password-file", NULL);
568 zstr_sendx (auth, "PLAIN", passfilepath, NULL);
535569 zsock_wait (auth);
536 success = s_can_connect (&server, &client, true);
570 success = s_can_connect (&server, &client, false);
537571 assert (success);
538572
573 #if (ZMQ_VERSION >= ZMQ_MAKE_VERSION (4, 1, 0))
574 // Test that the User-Id metadata is present
575 zframe_t *frame = zframe_recv (server);
576 assert (frame != NULL);
577 const char *user_id = zframe_meta (frame, "User-Id");
578 assert (user_id != NULL);
579 assert (streq (user_id, "admin"));
580 zframe_destroy (&frame);
581 #endif
582 s_renew_sockets(&server, &client);
583
584 zsock_set_zap_domain (server, "global");
539585 zsock_set_plain_server (server, 1);
540586 zsock_set_plain_username (client, "admin");
541587 zsock_set_plain_password (client, "Bogus");
558604 zcert_apply (client_cert, client);
559605 zsock_set_curve_server (server, 1);
560606 zsock_set_curve_serverkey (client, server_key);
607 zsock_set_zap_domain (server, "global");
561608 success = s_can_connect (&server, &client, true);
562609 assert (!success);
563610
577624 zcert_apply (client_cert, client);
578625 zsock_set_curve_server (server, 1);
579626 zsock_set_curve_serverkey (client, server_key);
580 zcert_save_public (client_cert, TESTDIR "/mycert.txt");
581 zstr_sendx (auth, "CURVE", TESTDIR, NULL);
627 zcert_save_public (client_cert, certfilepath);
628 zstr_sendx (auth, "CURVE", basedirpath, NULL);
582629 zsock_wait (auth);
630 zsock_set_zap_domain (server, "global");
583631 success = s_can_connect (&server, &client, false);
584632 assert (success);
585633
590638 const char *meta = zframe_meta (frame, "Hello");
591639 assert (meta != NULL);
592640 assert (streq (meta, "World!"));
641 const char *user_id = zframe_meta (frame, "User-Id");
642 assert (user_id != NULL);
643 assert (streq (user_id, zcert_public_txt(client_cert)));
593644 zframe_destroy (&frame);
594645 s_renew_sockets(&server, &client);
595646 #endif
635686 zsock_destroy (&server);
636687
637688 // Delete all test files
638 zdir_t *dir = zdir_new (TESTDIR, NULL);
689 dir = zdir_new (basedirpath, NULL);
639690 assert (dir);
640691 zdir_remove (dir, true);
641692 zdir_destroy (&dir);
693
694 zstr_free (&passfilepath);
695 zstr_free (&certfilepath);
696 zstr_free (&basedirpath);
697
642698 #endif
643699
644700 #if defined (__WINDOWS__)
738794 if (!*hostname) {
739795 printf ("OK (skipping test, no UDP broadcasting)\n");
740796 zactor_destroy (&speaker);
741 free (hostname);
797 freen (hostname);
742798 return;
743799 }
744 free (hostname);
800 freen (hostname);
745801
746802 // Create listener beacon on port 9999 to lookup service
747803 zactor_t *listener = zactor_new (zbeacon, NULL);
751807 zsock_send (listener, "si", "CONFIGURE", 9999);
752808 hostname = zstr_recv (listener);
753809 assert (*hostname);
754 free (hostname);
810 freen (hostname);
755811
756812 // We will broadcast the magic value 0xCAFE
757813 byte announcement [2] = { 0xCA, 0xFE };
780836 zsock_send (node1, "si", "CONFIGURE", 5670);
781837 hostname = zstr_recv (node1);
782838 assert (*hostname);
783 free (hostname);
839 freen (hostname);
784840
785841 zactor_t *node2 = zactor_new (zbeacon, NULL);
786842 assert (node2);
787843 zsock_send (node2, "si", "CONFIGURE", 5670);
788844 hostname = zstr_recv (node2);
789845 assert (*hostname);
790 free (hostname);
846 freen (hostname);
791847
792848 zactor_t *node3 = zactor_new (zbeacon, NULL);
793849 assert (node3);
794850 zsock_send (node3, "si", "CONFIGURE", 5670);
795851 hostname = zstr_recv (node3);
796852 assert (*hostname);
797 free (hostname);
853 freen (hostname);
798854
799855 zsock_send (node1, "sbi", "PUBLISH", "NODE/1", 6, 250);
800856 zsock_send (node2, "sbi", "PUBLISH", "NODE/2", 6, 250);
902958 zcert_set_meta (zcert_t *self, const char *name, const char *format, ...) CHECK_PRINTF (3);
903959
904960 // Get metadata value from certificate; if the metadata value doesn't
905 // exist, returns NULL.
961 // exist, returns NULL.
906962 CZMQ_EXPORT const char *
907963 zcert_meta (zcert_t *self, const char *name);
908964
909965 // Get list of metadata fields from certificate. Caller is responsible for
910 // destroying list. Caller should not modify the values of list items.
966 // destroying list. Caller should not modify the values of list items.
911967 CZMQ_EXPORT zlist_t *
912968 zcert_meta_keys (zcert_t *self);
913969
914 // Save full certificate (public + secret) to file for persistent storage
970 // Save full certificate (public + secret) to file for persistent storage
915971 // This creates one public file and one secret file (filename + "_secret").
916972 CZMQ_EXPORT int
917973 zcert_save (zcert_t *self, const char *filename);
925981 zcert_save_secret (zcert_t *self, const char *filename);
926982
927983 // Apply certificate to socket, i.e. use for CURVE security on socket.
928 // If certificate was loaded from public file, the secret key will be
929 // undefined, and this certificate will not work successfully.
984 // If certificate was loaded from public file, the secret key will be
985 // undefined, and this certificate will not work successfully.
930986 CZMQ_EXPORT void
931987 zcert_apply (zcert_t *self, void *socket);
932988
933989 // Return copy of certificate; if certificate is NULL or we exhausted
934 // heap memory, returns NULL.
990 // heap memory, returns NULL.
935991 // Caller owns return value and must destroy it when done.
936992 CZMQ_EXPORT zcert_t *
937993 zcert_dup (zcert_t *self);
9501006
9511007 #ifdef CZMQ_BUILD_DRAFT_API
9521008 // *** Draft method, for development use, may change without warning ***
1009 // Accepts public/secret key text pair from caller
1010 CZMQ_EXPORT zcert_t *
1011 zcert_new_from_txt (const char *public_txt, const char *secret_txt);
1012
1013 // *** Draft method, for development use, may change without warning ***
9531014 // Unset certificate metadata.
9541015 CZMQ_EXPORT void
9551016 zcert_unset_meta (zcert_t *self, const char *name);
9611022 This is the class self test code:
9621023
9631024 ```c
1025
1026 const char *SELFTEST_DIR_RW = "src/selftest-rw";
1027
1028 const char *testbasedir = ".test_zcert";
1029 const char *testfile = "mycert.txt";
1030 char *basedirpath = NULL; // subdir in a test, under SELFTEST_DIR_RW
1031 char *filepath = NULL; // pathname to testfile in a test, in dirpath
1032 char *filepath_s = NULL; // pathname to testfile+secret in a test, in dirpath
1033
1034 basedirpath = zsys_sprintf ("%s/%s", SELFTEST_DIR_RW, testbasedir);
1035 assert (basedirpath);
1036 filepath = zsys_sprintf ("%s/%s", basedirpath, testfile);
1037 assert (filepath);
1038 filepath_s = zsys_sprintf ("%s_secret", filepath);
1039 assert (filepath_s);
1040
1041 // Make sure old aborted tests do not hinder us
1042 zdir_t *dir = zdir_new (basedirpath, NULL);
1043 if (dir) {
1044 zdir_remove (dir, true);
1045 zdir_destroy (&dir);
1046 }
1047 zsys_file_delete (filepath);
1048 zsys_dir_delete (basedirpath);
1049
9641050 // Create temporary directory for test files
965 # define TESTDIR ".test_zcert"
966 zsys_dir_create (TESTDIR);
1051 zsys_dir_create (basedirpath);
9671052
9681053 // Create a simple certificate with metadata
9691054 zcert_t *cert = zcert_new ();
9851070 zcert_destroy (&shadow);
9861071
9871072 // Check we can save and load certificate
988 zcert_save (cert, TESTDIR "/mycert.txt");
989 assert (zsys_file_exists (TESTDIR "/mycert.txt"));
990 assert (zsys_file_exists (TESTDIR "/mycert.txt_secret"));
1073 zcert_save (cert, filepath);
1074 assert (zsys_file_exists (filepath));
1075 assert (zsys_file_exists (filepath_s));
9911076
9921077 // Load certificate, will in fact load secret one
993 shadow = zcert_load (TESTDIR "/mycert.txt");
1078 shadow = zcert_load (filepath);
9941079 assert (shadow);
9951080 assert (zcert_eq (cert, shadow));
9961081 zcert_destroy (&shadow);
9971082
9981083 // Delete secret certificate, load public one
999 int rc = zsys_file_delete (TESTDIR "/mycert.txt_secret");
1084 int rc = zsys_file_delete (filepath_s);
10001085 assert (rc == 0);
1001 shadow = zcert_load (TESTDIR "/mycert.txt");
1086 shadow = zcert_load (filepath);
10021087
10031088 // 32-byte null key encodes as 40 '0' characters
10041089 assert (streq (zcert_secret_txt (shadow), FORTY_ZEROES));
10051090
1091 #ifdef CZMQ_BUILD_DRAFT_API
1092 // test zcert_from_txt
1093 zcert_t *cert2 = zcert_new_from_txt(cert->public_txt, cert->secret_txt);
1094 assert (cert2);
1095 assert (zcert_eq (cert, cert2));
1096 zcert_destroy(&cert2);
1097 #endif
1098
10061099 zcert_destroy (&shadow);
10071100 zcert_destroy (&cert);
10081101
10091102 // Delete all test files
1010 zdir_t *dir = zdir_new (TESTDIR, NULL);
1103 dir = zdir_new (basedirpath, NULL);
10111104 assert (dir);
10121105 zdir_remove (dir, true);
10131106 zdir_destroy (&dir);
1107
1108 zstr_free (&basedirpath);
1109 zstr_free (&filepath);
1110 zstr_free (&filepath_s);
10141111
10151112 #if defined (__WINDOWS__)
10161113 zsys_shutdown();
10461143 // is provided in stable builds.
10471144 // This class has draft methods, which may change over time. They are not
10481145 // in stable releases, by default. Use --enable-drafts to enable.
1049 // Create a new certificate store from a disk directory, loading and
1050 // indexing all certificates in that location. The directory itself may be
1146 // Create a new certificate store from a disk directory, loading and
1147 // indexing all certificates in that location. The directory itself may be
10511148 // absent, and created later, or modified at any time. The certificate store
1052 // is automatically refreshed on any zcertstore_lookup() call. If the
1053 // location is specified as NULL, creates a pure-memory store, which you
1054 // can work with by inserting certificates at runtime.
1149 // is automatically refreshed on any zcertstore_lookup() call. If the
1150 // location is specified as NULL, creates a pure-memory store, which you
1151 // can work with by inserting certificates at runtime.
10551152 CZMQ_EXPORT zcertstore_t *
10561153 zcertstore_new (const char *location);
10571154
10581155 // Destroy a certificate store object in memory. Does not affect anything
1059 // stored on disk.
1156 // stored on disk.
10601157 CZMQ_EXPORT void
10611158 zcertstore_destroy (zcertstore_t **self_p);
10621159
10631160 // Look up certificate by public key, returns zcert_t object if found,
1064 // else returns NULL. The public key is provided in Z85 text format.
1161 // else returns NULL. The public key is provided in Z85 text format.
10651162 CZMQ_EXPORT zcert_t *
10661163 zcertstore_lookup (zcertstore_t *self, const char *public_key);
10671164
10681165 // Insert certificate into certificate store in memory. Note that this
10691166 // does not save the certificate to disk. To do that, use zcert_save()
1070 // directly on the certificate. Takes ownership of zcert_t object.
1167 // directly on the certificate. Takes ownership of zcert_t object.
10711168 CZMQ_EXPORT void
10721169 zcertstore_insert (zcertstore_t *self, zcert_t **cert_p);
10731170
10951192
10961193 // *** Draft method, for development use, may change without warning ***
10971194 // Empty certificate hashtable. This wrapper exists to be friendly to bindings,
1098 // which don't usually have access to struct internals.
1195 // which don't usually have access to struct internals.
10991196 CZMQ_EXPORT void
11001197 zcertstore_empty (zcertstore_t *self);
1198
1199 // *** Draft method, for development use, may change without warning ***
1200 // Return a list of all the certificates in the store.
1201 // The caller takes ownership of the zlistx_t object and is responsible
1202 // for destroying it. The caller does not take ownership of the zcert_t
1203 // objects.
1204 // Caller owns return value and must destroy it when done.
1205 CZMQ_EXPORT zlistx_t *
1206 zcertstore_certs (zcertstore_t *self);
11011207
11021208 #endif // CZMQ_BUILD_DRAFT_API
11031209 ```
11061212 This is the class self test code:
11071213
11081214 ```c
1215
1216 const char *SELFTEST_DIR_RW = "src/selftest-rw";
1217
1218 const char *testbasedir = ".test_zcertstore";
1219 const char *testfile = "mycert.txt";
1220 char *basedirpath = NULL; // subdir in a test, under SELFTEST_DIR_RW
1221 char *filepath = NULL; // pathname to testfile in a test, in dirpath
1222
1223 basedirpath = zsys_sprintf ("%s/%s", SELFTEST_DIR_RW, testbasedir);
1224 assert (basedirpath);
1225 filepath = zsys_sprintf ("%s/%s", basedirpath, testfile);
1226 assert (filepath);
1227
1228 // Make sure old aborted tests do not hinder us
1229 zdir_t *dir = zdir_new (basedirpath, NULL);
1230 if (dir) {
1231 zdir_remove (dir, true);
1232 zdir_destroy (&dir);
1233 }
1234 zsys_file_delete (filepath);
1235 zsys_dir_delete (basedirpath);
1236
11091237 // Create temporary directory for test files
1110 # define TESTDIR ".test_zcertstore"
1111 zsys_dir_create (TESTDIR);
1238 zsys_dir_create (basedirpath);
11121239
11131240 // Load certificate store from disk; it will be empty
1114 zcertstore_t *certstore = zcertstore_new (TESTDIR);
1241 zcertstore_t *certstore = zcertstore_new (basedirpath);
11151242 assert (certstore);
11161243
11171244 // Create a single new certificate and save to disk
11201247 char *client_key = strdup (zcert_public_txt (cert));
11211248 assert (client_key);
11221249 zcert_set_meta (cert, "name", "John Doe");
1123 zcert_save (cert, TESTDIR "/mycert.txt");
1250 zcert_save (cert, filepath);
11241251 zcert_destroy (&cert);
11251252
11261253 // Check that certificate store refreshes as expected
11271254 cert = zcertstore_lookup (certstore, client_key);
11281255 assert (cert);
11291256 assert (streq (zcert_meta (cert, "name"), "John Doe"));
1257
1258 #ifdef CZMQ_BUILD_DRAFT_API
1259 // Iterate through certs
1260 zlistx_t *certs = zcertstore_certs(certstore);
1261 cert = (zcert_t *) zlistx_first(certs);
1262 int cert_count = 0;
1263 while (cert) {
1264 assert (streq (zcert_meta (cert, "name"), "John Doe"));
1265 cert = (zcert_t *) zlistx_next(certs);
1266 cert_count++;
1267 }
1268 assert(cert_count==1);
1269 zlistx_destroy(&certs);
1270 #endif
11301271
11311272 // Test custom loader
11321273 test_loader_state *state = (test_loader_state *) zmalloc (sizeof (test_loader_state));
11391280 assert (cert);
11401281 #endif
11411282
1142 free (client_key);
1283 freen (client_key);
11431284
11441285 if (verbose)
11451286 zcertstore_print (certstore);
11461287 zcertstore_destroy (&certstore);
11471288
11481289 // Delete all test files
1149 zdir_t *dir = zdir_new (TESTDIR, NULL);
1290 dir = zdir_new (basedirpath, NULL);
11501291 assert (dir);
11511292 zdir_remove (dir, true);
11521293 zdir_destroy (&dir);
1294
1295 zstr_free (&basedirpath);
1296 zstr_free (&filepath);
11531297
11541298 #if defined (__WINDOWS__)
11551299 zsys_shutdown();
11691313 ```h
11701314 // This is a stable class, and may not change except for emergencies. It
11711315 // is provided in stable builds.
1172 // Create a new chunk of the specified size. If you specify the data, it
1173 // is copied into the chunk. If you do not specify the data, the chunk is
1316 // Create a new chunk of the specified size. If you specify the data, it
1317 // is copied into the chunk. If you do not specify the data, the chunk is
11741318 // allocated and left empty, and you can then add data using zchunk_append.
11751319 CZMQ_EXPORT zchunk_t *
11761320 zchunk_new (const void *data, size_t size);
11961340 zchunk_data (zchunk_t *self);
11971341
11981342 // Set chunk data from user-supplied data; truncate if too large. Data may
1199 // be null. Returns actual size of chunk
1343 // be null. Returns actual size of chunk
12001344 CZMQ_EXPORT size_t
12011345 zchunk_set (zchunk_t *self, const void *data, size_t size);
12021346
12041348 CZMQ_EXPORT size_t
12051349 zchunk_fill (zchunk_t *self, byte filler, size_t size);
12061350
1207 // Append user-supplied data to chunk, return resulting chunk size. If the
1351 // Append user-supplied data to chunk, return resulting chunk size. If the
12081352 // data would exceeded the available space, it is truncated. If you want to
1209 // grow the chunk to accommodate new data, use the zchunk_extend method.
1353 // grow the chunk to accommodate new data, use the zchunk_extend method.
12101354 CZMQ_EXPORT size_t
12111355 zchunk_append (zchunk_t *self, const void *data, size_t size);
12121356
12131357 // Append user-supplied data to chunk, return resulting chunk size. If the
1214 // data would exceeded the available space, the chunk grows in size.
1358 // data would exceeded the available space, the chunk grows in size.
12151359 CZMQ_EXPORT size_t
12161360 zchunk_extend (zchunk_t *self, const void *data, size_t size);
12171361
1218 // Copy as much data from 'source' into the chunk as possible; returns the
1219 // new size of chunk. If all data from 'source' is used, returns exhausted
1362 // Copy as much data from 'source' into the chunk as possible; returns the
1363 // new size of chunk. If all data from 'source' is used, returns exhausted
12201364 // on the source chunk. Source can be consumed as many times as needed until
1221 // it is exhausted. If source was already exhausted, does not change chunk.
1365 // it is exhausted. If source was already exhausted, does not change chunk.
12221366 CZMQ_EXPORT size_t
12231367 zchunk_consume (zchunk_t *self, zchunk_t *source);
12241368
12251369 // Returns true if the chunk was exhausted by consume methods, or if the
1226 // chunk has a size of zero.
1370 // chunk has a size of zero.
12271371 CZMQ_EXPORT bool
12281372 zchunk_exhausted (zchunk_t *self);
12291373
12361380 CZMQ_EXPORT int
12371381 zchunk_write (zchunk_t *self, FILE *handle);
12381382
1239 // Try to slurp an entire file into a chunk. Will read up to maxsize of
1240 // the file. If maxsize is 0, will attempt to read the entire file and
1241 // fail with an assertion if that cannot fit into memory. Returns a new
1383 // Try to slurp an entire file into a chunk. Will read up to maxsize of
1384 // the file. If maxsize is 0, will attempt to read the entire file and
1385 // fail with an assertion if that cannot fit into memory. Returns a new
12421386 // chunk containing the file data, or NULL if the file could not be read.
12431387 // Caller owns return value and must destroy it when done.
12441388 CZMQ_EXPORT zchunk_t *
12451389 zchunk_slurp (const char *filename, size_t maxsize);
12461390
1247 // Create copy of chunk, as new chunk object. Returns a fresh zchunk_t
1391 // Create copy of chunk, as new chunk object. Returns a fresh zchunk_t
12481392 // object, or null if there was not enough heap memory. If chunk is null,
1249 // returns null.
1393 // returns null.
12501394 // Caller owns return value and must destroy it when done.
12511395 CZMQ_EXPORT zchunk_t *
12521396 zchunk_dup (zchunk_t *self);
12531397
12541398 // Return chunk data encoded as printable hex string. Caller must free
1255 // string when finished with it.
1399 // string when finished with it.
12561400 // Caller owns return value and must destroy it when done.
12571401 CZMQ_EXPORT char *
12581402 zchunk_strhex (zchunk_t *self);
12591403
12601404 // Return chunk data copied into freshly allocated string
1261 // Caller must free string when finished with it.
1405 // Caller must free string when finished with it.
12621406 // Caller owns return value and must destroy it when done.
12631407 CZMQ_EXPORT char *
12641408 zchunk_strdup (zchunk_t *self);
12861430 zchunk_fprint (zchunk_t *self, FILE *file);
12871431
12881432 // Dump message to stderr, for debugging and tracing.
1289 // See zchunk_fprint for details
1433 // See zchunk_fprint for details
12901434 CZMQ_EXPORT void
12911435 zchunk_print (zchunk_t *self);
12921436
13211465 assert (streq (zchunk_digest (chunk), "01B307ACBA4F54F55AAFC33BB06BBBF6CA803E9A"));
13221466 char *string = zchunk_strdup (chunk);
13231467 assert (streq (string, "1234567890"));
1324 free (string);
1468 freen (string);
13251469 string = zchunk_strhex (chunk);
13261470 assert (streq (string, "31323334353637383930"));
1327 free (string);
1471 freen (string);
13281472
13291473 zframe_t *frame = zchunk_pack (chunk);
13301474 assert (frame);
13931537 CZMQ_EXPORT void
13941538 zclock_sleep (int msecs);
13951539
1396 // Return current system clock as milliseconds. Note that this clock can
1540 // Return current system clock as milliseconds. Note that this clock can
13971541 // jump backwards (if the system clock is changed) so is unsafe to use for
1398 // timers and time offsets. Use zclock_mono for that instead.
1542 // timers and time offsets. Use zclock_mono for that instead.
13991543 CZMQ_EXPORT int64_t
14001544 zclock_time (void);
14011545
14021546 // Return current monotonic clock in milliseconds. Use this when you compute
1403 // time offsets. The monotonic clock is not affected by system changes and
1404 // so will never be reset backwards, unlike a system clock.
1547 // time offsets. The monotonic clock is not affected by system changes and
1548 // so will never be reset backwards, unlike a system clock.
14051549 CZMQ_EXPORT int64_t
14061550 zclock_mono (void);
14071551
14081552 // Return current monotonic clock in microseconds. Use this when you compute
1409 // time offsets. The monotonic clock is not affected by system changes and
1410 // so will never be reset backwards, unlike a system clock.
1553 // time offsets. The monotonic clock is not affected by system changes and
1554 // so will never be reset backwards, unlike a system clock.
14111555 CZMQ_EXPORT int64_t
14121556 zclock_usecs (void);
14131557
14371581 char *timestr = zclock_timestr ();
14381582 if (verbose)
14391583 puts (timestr);
1440 free (timestr);
1584 freen (timestr);
14411585
14421586 #if defined (__WINDOWS__)
14431587 zsys_shutdown();
14891633 ```h
14901634 // This is a stable class, and may not change except for emergencies. It
14911635 // is provided in stable builds.
1492 //
1636 // This class has draft methods, which may change over time. They are not
1637 // in stable releases, by default. Use --enable-drafts to enable.
1638 //
14931639 typedef int (zconfig_fct) (
14941640 zconfig_t *self, void *arg, int level);
14951641
14971643 CZMQ_EXPORT zconfig_t *
14981644 zconfig_new (const char *name, zconfig_t *parent);
14991645
1500 // Load a config tree from a specified ZPL text file; returns a zconfig_t
1646 // Load a config tree from a specified ZPL text file; returns a zconfig_t
15011647 // reference for the root, if the file exists and is readable. Returns NULL
1502 // if the file does not exist.
1648 // if the file does not exist.
15031649 CZMQ_EXPORT zconfig_t *
15041650 zconfig_load (const char *filename);
15051651
15061652 // Equivalent to zconfig_load, taking a format string instead of a fixed
1507 // filename.
1653 // filename.
15081654 CZMQ_EXPORT zconfig_t *
15091655 zconfig_loadf (const char *format, ...) CHECK_PRINTF (1);
15101656
15251671 zconfig_put (zconfig_t *self, const char *path, const char *value);
15261672
15271673 // Equivalent to zconfig_put, accepting a format specifier and variable
1528 // argument list, instead of a single string value.
1674 // argument list, instead of a single string value.
15291675 CZMQ_EXPORT void
15301676 zconfig_putf (zconfig_t *self, const char *path, const char *format, ...) CHECK_PRINTF (3);
15311677
15321678 // Get value for config item into a string value; leading slash is optional
1533 // and ignored.
1679 // and ignored.
15341680 CZMQ_EXPORT char *
15351681 zconfig_get (zconfig_t *self, const char *path, const char *default_value);
15361682
15381684 CZMQ_EXPORT void
15391685 zconfig_set_name (zconfig_t *self, const char *name);
15401686
1541 // Set new value for config item. The new value may be a string, a printf
1542 // format, or NULL. Note that if string may possibly contain '%', or if it
1687 // Set new value for config item. The new value may be a string, a printf
1688 // format, or NULL. Note that if string may possibly contain '%', or if it
15431689 // comes from an insecure source, you must use '%s' as the format, followed
1544 // by the string.
1690 // by the string.
15451691 CZMQ_EXPORT void
15461692 zconfig_set_value (zconfig_t *self, const char *format, ...) CHECK_PRINTF (2);
15471693
15621708 zconfig_at_depth (zconfig_t *self, int level);
15631709
15641710 // Execute a callback for each config item in the tree; returns zero if
1565 // successful, else -1.
1711 // successful, else -1.
15661712 CZMQ_EXPORT int
15671713 zconfig_execute (zconfig_t *self, zconfig_fct handler, void *arg);
15681714
15691715 // Add comment to config item before saving to disk. You can add as many
15701716 // comment lines as you like. If you use a null format, all comments are
1571 // deleted.
1717 // deleted.
15721718 CZMQ_EXPORT void
15731719 zconfig_set_comment (zconfig_t *self, const char *format, ...) CHECK_PRINTF (2);
15741720
15771723 zconfig_comments (zconfig_t *self);
15781724
15791725 // Save a config tree to a specified ZPL text file, where a filename
1580 // "-" means dump to standard output.
1726 // "-" means dump to standard output.
15811727 CZMQ_EXPORT int
15821728 zconfig_save (zconfig_t *self, const char *filename);
15831729
15841730 // Equivalent to zconfig_save, taking a format string instead of a fixed
1585 // filename.
1731 // filename.
15861732 CZMQ_EXPORT int
15871733 zconfig_savef (zconfig_t *self, const char *format, ...) CHECK_PRINTF (2);
15881734
15911737 zconfig_filename (zconfig_t *self);
15921738
15931739 // Reload config tree from same file that it was previously loaded from.
1594 // Returns 0 if OK, -1 if there was an error (and then does not change
1595 // existing data).
1740 // Returns 0 if OK, -1 if there was an error (and then does not change
1741 // existing data).
15961742 CZMQ_EXPORT int
15971743 zconfig_reload (zconfig_t **self_p);
15981744
16151761 zconfig_str_save (zconfig_t *self);
16161762
16171763 // Return true if a configuration tree was loaded from a file and that
1618 // file has changed in since the tree was loaded.
1764 // file has changed in since the tree was loaded.
16191765 CZMQ_EXPORT bool
16201766 zconfig_has_changed (zconfig_t *self);
16211767
16311777 CZMQ_EXPORT void
16321778 zconfig_test (bool verbose);
16331779
1780 #ifdef CZMQ_BUILD_DRAFT_API
1781 // *** Draft method, for development use, may change without warning ***
1782 // Destroy subtree (all children)
1783 CZMQ_EXPORT void
1784 zconfig_remove_subtree (zconfig_t *self);
1785
1786 // *** Draft method, for development use, may change without warning ***
1787 // Destroy node and subtree (all children)
1788 CZMQ_EXPORT void
1789 zconfig_remove (zconfig_t **self_p);
1790
1791 #endif // CZMQ_BUILD_DRAFT_API
16341792 ```
16351793 Please add '@interface' section in './../src/zconfig.c'.
16361794
16371795 This is the class self test code:
16381796
16391797 ```c
1798
1799 const char *SELFTEST_DIR_RW = "src/selftest-rw";
1800
1801 const char *testbasedir = ".test_zconfig";
1802 const char *testfile = "test.cfg";
1803 char *basedirpath = NULL; // subdir in a test, under SELFTEST_DIR_RW
1804 char *filepath = NULL; // pathname to testfile in a test, in dirpath
1805
1806 basedirpath = zsys_sprintf ("%s/%s", SELFTEST_DIR_RW, testbasedir);
1807 assert (basedirpath);
1808 filepath = zsys_sprintf ("%s/%s", basedirpath, testfile);
1809 assert (filepath);
1810
1811 // Make sure old aborted tests do not hinder us
1812 zdir_t *dir = zdir_new (basedirpath, NULL);
1813 if (dir) {
1814 zdir_remove (dir, true);
1815 zdir_destroy (&dir);
1816 }
1817 zsys_file_delete (filepath);
1818 zsys_dir_delete (basedirpath);
1819
16401820 // Create temporary directory for test files
1641 # define TESTDIR ".test_zconfig"
1642 zsys_dir_create (TESTDIR);
1821 zsys_dir_create (basedirpath);
16431822
16441823 zconfig_t *root = zconfig_new ("root", NULL);
16451824 assert (root);
16571836 zconfig_set_comment (root, " CURVE certificate");
16581837 zconfig_set_comment (root, " -----------------");
16591838 assert (zconfig_comments (root));
1660 zconfig_save (root, TESTDIR "/test.cfg");
1839 zconfig_save (root, filepath);
16611840 zconfig_destroy (&root);
1662 root = zconfig_load (TESTDIR "/test.cfg");
1841 root = zconfig_load (filepath);
16631842 if (verbose)
16641843 zconfig_save (root, "-");
1665 assert (streq (zconfig_filename (root), TESTDIR "/test.cfg"));
1844 assert (streq (zconfig_filename (root), filepath));
16661845
16671846 char *email = zconfig_get (root, "/headers/email", NULL);
16681847 assert (email);
16711850 assert (passwd);
16721851 assert (streq (passwd, "Top Secret"));
16731852
1674 zconfig_savef (root, "%s/%s", TESTDIR, "test.cfg");
1853 zconfig_savef (root, "%s/%s", basedirpath, testfile);
16751854 assert (!zconfig_has_changed (root));
16761855 int rc = zconfig_reload (&root);
16771856 assert (rc == 0);
16931872 char *string = zconfig_str_save (root);
16941873 assert (string);
16951874 assert (streq (string, (char *) zchunk_data (chunk)));
1696 free (string);
1875 freen (string);
16971876 assert (chunk);
16981877 zconfig_destroy (&root);
16991878
17051884
17061885 // Test config can't be saved to a file in a path that doesn't
17071886 // exist or isn't writable
1708 rc = zconfig_savef (root, "%s/path/that/doesnt/exist/%s", TESTDIR, "test.cfg");
1887 rc = zconfig_savef (root, "%s/path/that/doesnt/exist/%s", basedirpath, testfile);
17091888 assert (rc == -1);
17101889
17111890 zconfig_destroy (&root);
17261905 assert (streq (zconfig_get (config, "malamute/endpoint", NULL), "ipc://@/malamute"));
17271906 assert (streq (zconfig_get (config, "malamute/producer", NULL), "STREAM"));
17281907 assert (zconfig_locate (config, "malamute/consumer"));
1729
1908
17301909 zconfig_t *c = zconfig_child (zconfig_locate (config, "malamute/consumer"));
17311910 assert (c);
17321911 assert (streq (zconfig_name (c), "STREAM2"));
17331912 assert (streq (zconfig_value (c), ".*"));
1734
1913
17351914 c = zconfig_next (c);
17361915 assert (c);
17371916 assert (streq (zconfig_name (c), "STREAM3"));
17381917 assert (streq (zconfig_value (c), "HAM"));
1739
1918
17401919 c = zconfig_next (c);
17411920 assert (!c);
1742
1921
17431922 assert (streq (zconfig_get (config, "server/verbose", NULL), "true"));
1744
1923
17451924 zconfig_destroy (&config);
1746
1925
1926 // Test subtree removal
1927 {
1928 zconfig_t *root = zconfig_str_load (
1929 "context\n"
1930 " iothreads = 1\n"
1931 " verbose = 1 # Ask for a trace\n"
1932 "main\n"
1933 " type = zqueue # ZMQ_DEVICE type\n"
1934 " frontend\n"
1935 " option\n"
1936 " hwm = 1000\n"
1937 " swap = 25000000 # 25MB\n"
1938 " bind = 'inproc://addr1'\n"
1939 " bind = 'ipc://addr2'\n"
1940 " backend\n"
1941 " bind = inproc://addr3\n"
1942 );
1943
1944 // no subtree
1945 zconfig_t *to_delete = zconfig_locate (root, "context/iothreads");
1946 assert (to_delete);
1947
1948 zconfig_remove_subtree (to_delete);
1949
1950 zconfig_t *check = zconfig_locate (root, "context/iothreads");
1951 assert (check);
1952 assert (streq (zconfig_value (check), "1"));
1953
1954 check = zconfig_locate (root, "context/verbose");
1955 assert (check);
1956 assert (streq (zconfig_value (check), "1"));
1957
1958 // existing subtree
1959 to_delete = zconfig_locate (root, "main/frontend/option");
1960 assert (to_delete);
1961
1962 zconfig_remove_subtree (to_delete);
1963
1964 check = zconfig_locate (root, "main/frontend/option/hwm");
1965 assert (check == NULL);
1966 check = zconfig_locate (root, "main/frontend/option/swap");
1967 assert (check == NULL);
1968 check = zconfig_locate (root, "main/frontend/option");
1969 assert (check);
1970 assert (streq (zconfig_value (check), ""));
1971 check = zconfig_next (check);
1972 assert (check);
1973 assert (streq (zconfig_name (check), "bind"));
1974 assert (streq (zconfig_value (check), "inproc://addr1"));
1975 check = zconfig_next (check);
1976 assert (check);
1977 assert (streq (zconfig_name (check), "bind"));
1978 assert (streq (zconfig_value (check), "ipc://addr2"));
1979 assert (zconfig_next (check) == NULL);
1980
1981 to_delete = zconfig_locate (root, "main/frontend");
1982 assert (to_delete);
1983
1984 zconfig_remove_subtree (to_delete);
1985
1986 check = zconfig_locate (root, "main/frontend/option/hwm");
1987 assert (check == NULL);
1988 check = zconfig_locate (root, "main/frontend/option/swap");
1989 assert (check == NULL);
1990 check = zconfig_locate (root, "main/frontend/option");
1991 assert (check == NULL);
1992 check = zconfig_locate (root, "main/frontend/bind");
1993 assert (check == NULL);
1994 check = zconfig_locate (root, "main/frontend");
1995 assert (check);
1996 assert (streq (zconfig_value (check), ""));
1997 assert (zconfig_child (check) == NULL);
1998 check = zconfig_next (check);
1999 assert (check);
2000 assert (streq (zconfig_name (check), "backend"));
2001 assert (streq (zconfig_value (check), ""));
2002
2003 to_delete = zconfig_locate (root, "main");
2004 assert (to_delete);
2005
2006 zconfig_remove_subtree (to_delete);
2007
2008 check = zconfig_locate (root, "main/type");
2009 assert (check == NULL);
2010 check = zconfig_locate (root, "main/frontend");
2011 assert (check == NULL);
2012 check = zconfig_locate (root, "main/backend");
2013 assert (check == NULL);
2014 check = zconfig_locate (root, "main");
2015 assert (check);
2016
2017 // root
2018 zconfig_remove_subtree (root);
2019
2020 assert (root);
2021 assert (zconfig_child (root) == NULL);
2022 check = zconfig_locate (root, "main");
2023 assert (check == NULL);
2024 check = zconfig_locate (root, "context");
2025 assert (check == NULL);
2026
2027 zconfig_destroy (&root);
2028 }
2029
2030 // Test node and subtree removal
2031 {
2032 zconfig_t *root = zconfig_str_load (
2033 "A1 = abc\n"
2034 " x\n"
2035 " 1\n"
2036 " 2\n"
2037 " y = 1 # Ask for a trace\n"
2038 "A2\n"
2039 " B1 = zqueue # ZMQ_DEVICE type\n"
2040 " B2\n"
2041 " C1\n"
2042 " hwm = 1000\n"
2043 " swap = 25000000 # 25MB\n"
2044 " C2 = 50\n"
2045 " C3\n"
2046 " bind = addr3\n"
2047 " B3\n"
2048 " bind = inproc://addr4\n"
2049 " B4 = Ignac\n"
2050 " z = 5\n"
2051 "A3\n"
2052 "A4\n"
2053 );
2054
2055 zconfig_t *to_delete = zconfig_locate (root, "A2/B2/C3");
2056 assert (to_delete);
2057
2058 zconfig_remove (&to_delete);
2059
2060 zconfig_t *check = zconfig_locate (root, "A2/B2/C2");
2061 assert (check);
2062 assert (streq (zconfig_value (check), "50"));
2063 assert (zconfig_next (check) == NULL);
2064 assert (zconfig_locate (root, "A2/B2/C3/bind") == NULL);
2065 assert (zconfig_locate (root, "A2/B2/C3") == NULL);
2066
2067 to_delete = zconfig_locate (root, "A2/B2");
2068 assert (to_delete);
2069
2070 zconfig_remove (&to_delete);
2071
2072 check = zconfig_locate (root, "A2");
2073 assert (check);
2074 check = zconfig_child (check);
2075 assert (check);
2076 assert (streq (zconfig_name (check), "B1"));
2077 assert (streq (zconfig_value (check), "zqueue"));
2078 check = zconfig_next (check);
2079 assert (check);
2080 assert (streq (zconfig_name (check), "B3"));
2081 assert (streq (zconfig_value (check), ""));
2082 assert (zconfig_locate (root, "A2/B2/C1") == NULL);
2083 assert (zconfig_locate (root, "A2/B2/C2") == NULL);
2084 assert (zconfig_locate (root, "A2/B2") == NULL);
2085 assert (zconfig_locate (root, "A2/B4"));
2086
2087 to_delete = zconfig_locate (root, "A2/B1");
2088 assert (to_delete);
2089
2090 zconfig_remove (&to_delete);
2091
2092 check = zconfig_locate (root, "A2");
2093 assert (check);
2094 check = zconfig_child (check);
2095 assert (check);
2096 assert (streq (zconfig_name (check), "B3"));
2097 assert (streq (zconfig_value (check), ""));
2098 check = zconfig_next (check);
2099 assert (check);
2100 assert (streq (zconfig_name (check), "B4"));
2101 assert (streq (zconfig_value (check), "Ignac"));
2102 assert (zconfig_next (check) == NULL);
2103 assert (zconfig_locate (root, "A2/B1") == NULL);
2104 assert (zconfig_locate (root, "A2/B2") == NULL);
2105
2106 to_delete = zconfig_locate (root, "A2/B3");
2107 assert (to_delete);
2108
2109 zconfig_remove (&to_delete);
2110
2111 check = zconfig_locate (root, "A2");
2112 assert (check);
2113 check = zconfig_child (check);
2114 assert (check);
2115 assert (streq (zconfig_name (check), "B4"));
2116 assert (streq (zconfig_value (check), "Ignac"));
2117 assert (zconfig_next (check) == NULL);
2118
2119 to_delete = zconfig_locate (root, "A2");
2120 assert (to_delete);
2121
2122 zconfig_remove (&to_delete);
2123
2124 check = zconfig_locate (root, "A1");
2125 assert (check);
2126 check = zconfig_next (check);
2127 assert (check);
2128 assert (streq (zconfig_name (check), "A3"));
2129 assert (zconfig_locate (root, "A2/B4") == NULL);
2130 assert (zconfig_locate (root, "A2") == NULL);
2131
2132 to_delete = zconfig_locate (root, "A1");
2133 assert (to_delete);
2134
2135 zconfig_remove (&to_delete);
2136
2137 check = zconfig_child (root);
2138 assert (check);
2139 assert (streq (zconfig_name (check), "A3"));
2140 assert (zconfig_locate (root, "A1/x/1") == NULL);
2141 assert (zconfig_locate (root, "A1/x") == NULL);
2142 assert (zconfig_locate (root, "A1/y") == NULL);
2143 assert (zconfig_locate (root, "A3"));
2144 assert (zconfig_locate (root, "A4"));
2145
2146 // called on root should be equivalent to zconfig_destroy (&root)
2147 zconfig_remove (&root);
2148 }
2149
17472150 // Delete all test files
1748 zdir_t *dir = zdir_new (TESTDIR, NULL);
2151 dir = zdir_new (basedirpath, NULL);
17492152 assert (dir);
17502153 zdir_remove (dir, true);
17512154 zdir_destroy (&dir);
2155
2156 zstr_free (&basedirpath);
2157 zstr_free (&filepath);
17522158
17532159 #if defined (__WINDOWS__)
17542160 zsys_shutdown();
17712177 // This is a stable class, and may not change except for emergencies. It
17722178 // is provided in stable builds.
17732179 // Constructor - creates new digest object, which you use to build up a
1774 // digest by repeatedly calling zdigest_update() on chunks of data.
2180 // digest by repeatedly calling zdigest_update() on chunks of data.
17752181 CZMQ_EXPORT zdigest_t *
17762182 zdigest_new (void);
17772183
17842190 zdigest_update (zdigest_t *self, const byte *buffer, size_t length);
17852191
17862192 // Return final digest hash data. If built without crypto support,
1787 // returns NULL.
2193 // returns NULL.
17882194 CZMQ_EXPORT const byte *
17892195 zdigest_data (zdigest_t *self);
17902196
17922198 CZMQ_EXPORT size_t
17932199 zdigest_size (zdigest_t *self);
17942200
1795 // Return digest as printable hex string; caller should not modify nor
2201 // Return digest as printable hex string; caller should not modify nor
17962202 // free this string. After calling this, you may not use zdigest_update()
1797 // on the same digest. If built without crypto support, returns NULL.
2203 // on the same digest. If built without crypto support, returns NULL.
17982204 CZMQ_EXPORT char *
17992205 zdigest_string (zdigest_t *self);
18002206
18222228 assert (streq (zdigest_string (digest),
18232229 "DEB23807D4FE025E900FE9A9C7D8410C3DDE9671"));
18242230 zdigest_destroy (&digest);
1825 free (buffer);
2231 freen (buffer);
18262232
18272233 #if defined (__WINDOWS__)
18282234 zsys_shutdown();
18442250 // This is a stable class, and may not change except for emergencies. It
18452251 // is provided in stable builds.
18462252 // Create a new directory item that loads in the full tree of the specified
1847 // path, optionally located under some parent path. If parent is "-", then
1848 // loads only the top-level directory, and does not use parent as a path.
2253 // path, optionally located under some parent path. If parent is "-", then
2254 // loads only the top-level directory, and does not use parent as a path.
18492255 CZMQ_EXPORT zdir_t *
18502256 zdir_new (const char *path, const char *parent);
18512257
18622268 zdir_modified (zdir_t *self);
18632269
18642270 // Return total hierarchy size, in bytes of data contained in all files
1865 // in the directory tree.
2271 // in the directory tree.
18662272 CZMQ_EXPORT off_t
18672273 zdir_cursize (zdir_t *self);
18682274
18712277 zdir_count (zdir_t *self);
18722278
18732279 // Returns a sorted list of zfile objects; Each entry in the list is a pointer
1874 // to a zfile_t item already allocated in the zdir tree. Do not destroy the
1875 // original zdir tree until you are done with this list.
2280 // to a zfile_t item already allocated in the zdir tree. Do not destroy the
2281 // original zdir tree until you are done with this list.
18762282 // Caller owns return value and must destroy it when done.
18772283 CZMQ_EXPORT zlist_t *
18782284 zdir_list (zdir_t *self);
18792285
1880 // Remove directory, optionally including all files that it contains, at
2286 // Remove directory, optionally including all files that it contains, at
18812287 // all levels. If force is false, will only remove the directory if empty.
1882 // If force is true, will remove all files and all subdirectories.
2288 // If force is true, will remove all files and all subdirectories.
18832289 CZMQ_EXPORT void
18842290 zdir_remove (zdir_t *self, bool force);
18852291
1886 // Calculate differences between two versions of a directory tree.
1887 // Returns a list of zdir_patch_t patches. Either older or newer may
2292 // Calculate differences between two versions of a directory tree.
2293 // Returns a list of zdir_patch_t patches. Either older or newer may
18882294 // be null, indicating the directory is empty/absent. If alias is set,
1889 // generates virtual filename (minus path, plus alias).
2295 // generates virtual filename (minus path, plus alias).
18902296 // Caller owns return value and must destroy it when done.
18912297 CZMQ_EXPORT zlist_t *
18922298 zdir_diff (zdir_t *older, zdir_t *newer, const char *alias);
18972303 zdir_resync (zdir_t *self, const char *alias);
18982304
18992305 // Load directory cache; returns a hash table containing the SHA-1 digests
1900 // of every file in the tree. The cache is saved between runs in .cache.
2306 // of every file in the tree. The cache is saved between runs in .cache.
19012307 // Caller owns return value and must destroy it when done.
19022308 CZMQ_EXPORT zhash_t *
19032309 zdir_cache (zdir_t *self);
19102316 CZMQ_EXPORT void
19112317 zdir_print (zdir_t *self, int indent);
19122318
1913 // Create a new zdir_watch actor instance:
1914 //
1915 // zactor_t *watch = zactor_new (zdir_watch, NULL);
1916 //
1917 // Destroy zdir_watch instance:
1918 //
1919 // zactor_destroy (&watch);
1920 //
1921 // Enable verbose logging of commands and activity:
1922 //
1923 // zstr_send (watch, "VERBOSE");
1924 //
1925 // Subscribe to changes to a directory path:
1926 //
1927 // zsock_send (watch, "ss", "SUBSCRIBE", "directory_path");
1928 //
1929 // Unsubscribe from changes to a directory path:
1930 //
2319 // Create a new zdir_watch actor instance:
2320 //
2321 // zactor_t *watch = zactor_new (zdir_watch, NULL);
2322 //
2323 // Destroy zdir_watch instance:
2324 //
2325 // zactor_destroy (&watch);
2326 //
2327 // Enable verbose logging of commands and activity:
2328 //
2329 // zstr_send (watch, "VERBOSE");
2330 //
2331 // Subscribe to changes to a directory path:
2332 //
2333 // zsock_send (watch, "ss", "SUBSCRIBE", "directory_path");
2334 //
2335 // Unsubscribe from changes to a directory path:
2336 //
19312337 // zsock_send (watch, "ss", "UNSUBSCRIBE", "directory_path");
1932 //
1933 // Receive directory changes:
1934 // zsock_recv (watch, "sp", &path, &patches);
1935 //
1936 // // Delete the received data.
1937 // free (path);
1938 // zlist_destroy (&patches);
2338 //
2339 // Receive directory changes:
2340 // zsock_recv (watch, "sp", &path, &patches);
2341 //
2342 // // Delete the received data.
2343 // free (path);
2344 // zlist_destroy (&patches);
19392345 CZMQ_EXPORT void
19402346 zdir_watch (zsock_t *pipe, void *unused);
19412347
19492355 This is the class self test code:
19502356
19512357 ```c
2358
2359 const char *SELFTEST_DIR_RW = "src/selftest-rw";
2360
2361 const char *testbasedir = "zdir-test-dir";
2362 const char *testfile1 = "initial_file";
2363 const char *testfile2 = "test_abc";
2364 char *basedirpath = NULL; // subdir in a test, under SELFTEST_DIR_RW
2365 char *filepath1 = NULL; // pathname to testfile in a test, in dirpath
2366 char *filepath2 = NULL; // pathname to testfile in a test, in dirpath
2367
2368 basedirpath = zsys_sprintf ("%s/%s", SELFTEST_DIR_RW, testbasedir);
2369 assert (basedirpath);
2370 filepath1 = zsys_sprintf ("%s/%s", basedirpath, testfile1);
2371 assert (filepath1);
2372 filepath2 = zsys_sprintf ("%s/%s", basedirpath, testfile2);
2373 assert (filepath2);
2374
2375 /*
2376 char *relfilepath2 = NULL; // pathname to testfile in a test, in dirpath
2377 relfilepath2 = zsys_sprintf ("%s/%s", testbasedir, testfile2);
2378 assert (relfilepath2);
2379 */
2380
2381 // Make sure old aborted tests do not hinder us
2382 zdir_t *dir = zdir_new (basedirpath, NULL);
2383 if (dir) {
2384 zdir_remove (dir, true);
2385 zdir_destroy (&dir);
2386 }
2387 zsys_file_delete (filepath1);
2388 zsys_file_delete (filepath2);
2389 zsys_dir_delete (basedirpath);
2390
2391 dir = zdir_new ("does-not-exist", NULL);
2392 if (dir) {
2393 zdir_remove (dir, true);
2394 zdir_destroy (&dir);
2395 }
2396
19522397 // need to create a file in the test directory we're watching
19532398 // in order to ensure the directory exists
1954 zfile_t *initfile = zfile_new ("./zdir-test-dir", "initial_file");
2399 zfile_t *initfile = zfile_new (basedirpath, testfile1);
19552400 assert (initfile);
19562401 zfile_output (initfile);
19572402 fprintf (zfile_handle (initfile), "initial file\n");
19582403 zfile_close (initfile);
19592404 zfile_destroy (&initfile);
19602405
1961 zdir_t *older = zdir_new ("zdir-test-dir", NULL);
2406 zdir_t *older = zdir_new (basedirpath, NULL);
19622407 assert (older);
19632408 if (verbose) {
19642409 printf ("\n");
19652410 zdir_dump (older, 0);
19662411 }
1967 zdir_t *newer = zdir_new (".", NULL);
2412 zdir_t *newer = zdir_new (SELFTEST_DIR_RW, NULL);
19682413 assert (newer);
19692414 zlist_t *patches = zdir_diff (older, newer, "/");
19702415 assert (patches);
19902435 assert ( synced == 0);
19912436 }
19922437
1993 zclock_sleep (1001); // wait for initial file to become 'stable'
2438 // wait for initial file to become 'stable'
2439 #ifdef CZMQ_BUILD_DRAFT_API
2440 zclock_sleep ((int)zsys_file_stable_age_msec() + 50);
2441 #else
2442 zclock_sleep (5050);
2443 #endif
19942444
19952445 zsock_send (watch, "si", "TIMEOUT", 100);
19962446 synced = zsock_wait(watch);
19972447 assert (synced == 0);
19982448
1999 zsock_send (watch, "ss", "SUBSCRIBE", "zdir-test-dir");
2449 zsock_send (watch, "ss", "SUBSCRIBE", basedirpath);
20002450 synced = zsock_wait(watch);
20012451 assert(synced == 0);
20022452
2003 zsock_send (watch, "ss", "UNSUBSCRIBE", "zdir-test-dir");
2453 zsock_send (watch, "ss", "UNSUBSCRIBE", basedirpath);
20042454 synced = zsock_wait(watch);
20052455 assert(synced == 0);
20062456
2007 zsock_send (watch, "ss", "SUBSCRIBE", "zdir-test-dir");
2457 zsock_send (watch, "ss", "SUBSCRIBE", basedirpath);
20082458 synced = zsock_wait(watch);
20092459 assert(synced == 0);
20102460
2011 zfile_t *newfile = zfile_new ("zdir-test-dir", "test_abc");
2461 zfile_t *newfile = zfile_new (basedirpath, testfile2);
20122462 zfile_output (newfile);
20132463 fprintf (zfile_handle (newfile), "test file\n");
20142464 zfile_close (newfile);
20152465
20162466 zpoller_t *watch_poll = zpoller_new (watch, NULL);
20172467
2018 // poll for a certain timeout before giving up and failing the test.
2019 void* polled = zpoller_wait(watch_poll, 1001);
2468 // poll for a certain timeout before giving up and failing the test
2469 void* polled = NULL;
2470 #ifdef CZMQ_BUILD_DRAFT_API
2471 polled = zpoller_wait(watch_poll, (int)zsys_file_stable_age_msec() + 150);
2472 #else
2473 polled = zpoller_wait(watch_poll, 5150);
2474 #endif
20202475 assert (polled == watch);
20212476
20222477 // wait for notification of the file being added
20242479 int rc = zsock_recv (watch, "sp", &path, &patches);
20252480 assert (rc == 0);
20262481
2027 assert (streq (path, "zdir-test-dir"));
2028 free (path);
2029
2482 assert (streq (path, basedirpath));
2483 freen (path);
2484
2485 if (verbose)
2486 zsys_debug("zdir_test() : added : zlist_size (patches)=%d",
2487 zlist_size (patches) );
20302488 assert (zlist_size (patches) == 1);
20312489
20322490 zdir_patch_t *patch = (zdir_patch_t *) zlist_pop (patches);
2033 assert (streq (zdir_patch_path (patch), "zdir-test-dir"));
2491 if (verbose)
2492 zsys_debug("zdir_test() : added : zdir_patch_path (patch)='%s'",
2493 zdir_patch_path (patch) );
2494 assert (streq (zdir_patch_path (patch), basedirpath));
20342495
20352496 zfile_t *patch_file = zdir_patch_file (patch);
2036 assert (streq (zfile_filename (patch_file, ""), "zdir-test-dir/test_abc"));
2497 if (verbose)
2498 zsys_debug("zdir_test() : added : zfile_filename (patch_file, \"\")='%s'",
2499 zfile_filename (patch_file, "") );
2500 assert (streq (zfile_filename (patch_file, ""), filepath2));
20372501
20382502 zdir_patch_destroy (&patch);
20392503 zlist_destroy (&patches);
20432507 zfile_destroy (&newfile);
20442508
20452509 // poll for a certain timeout before giving up and failing the test.
2046 polled = zpoller_wait(watch_poll, 1001);
2510 #ifdef CZMQ_BUILD_DRAFT_API
2511 polled = zpoller_wait(watch_poll, (int)zsys_file_stable_age_msec() + 150);
2512 #else
2513 polled = zpoller_wait(watch_poll, 5150);
2514 #endif
20472515 assert (polled == watch);
20482516
20492517 // wait for notification of the file being removed
20502518 rc = zsock_recv (watch, "sp", &path, &patches);
20512519 assert (rc == 0);
20522520
2053 assert (streq (path, "zdir-test-dir"));
2054 free (path);
2055
2521 assert (streq (path, basedirpath));
2522 freen (path);
2523
2524 if (verbose)
2525 zsys_debug("zdir_test() : removed : zlist_size (patches)=%d",
2526 zlist_size (patches) );
20562527 assert (zlist_size (patches) == 1);
20572528
20582529 patch = (zdir_patch_t *) zlist_pop (patches);
2059 assert (streq (zdir_patch_path (patch), "zdir-test-dir"));
2530 if (verbose)
2531 zsys_debug("zdir_test() : removed : zdir_patch_path (patch)='%s'",
2532 zdir_patch_path (patch) );
2533 assert (streq (zdir_patch_path (patch), basedirpath));
20602534
20612535 patch_file = zdir_patch_file (patch);
2062 assert (streq (zfile_filename (patch_file, ""), "zdir-test-dir/test_abc"));
2536 if (verbose)
2537 zsys_debug("zdir_test() : removed : zfile_filename (patch_file, \"\")='%s'",
2538 zfile_filename (patch_file, "") );
2539 assert (streq (zfile_filename (patch_file, ""), filepath2));
20632540
20642541 zdir_patch_destroy (&patch);
20652542 zlist_destroy (&patches);
20682545 zactor_destroy (&watch);
20692546
20702547 // clean up by removing the test directory.
2071 zdir_t *testdir = zdir_new ("zdir-test-dir", NULL);
2072 zdir_remove (testdir, true);
2073 zdir_destroy (&testdir);
2548 dir = zdir_new (basedirpath, NULL);
2549 assert (dir);
2550 zdir_remove (dir, true);
2551 zdir_destroy (&dir);
2552
2553 zstr_free (&basedirpath);
2554 zstr_free (&filepath1);
2555 zstr_free (&filepath2);
20742556
20752557 #if defined (__WINDOWS__)
20762558 zsys_shutdown();
21012583 zdir_patch_destroy (zdir_patch_t **self_p);
21022584
21032585 // Create copy of a patch. If the patch is null, or memory was exhausted,
2104 // returns null.
2586 // returns null.
21052587 // Caller owns return value and must destroy it when done.
21062588 CZMQ_EXPORT zdir_patch_t *
21072589 zdir_patch_dup (zdir_patch_t *self);
21402622 This is the class self test code:
21412623
21422624 ```c
2143 zfile_t *file = zfile_new (".", "bilbo");
2625
2626 const char *SELFTEST_DIR_RW = "src/selftest-rw";
2627
2628 const char *testfile = "bilbo";
2629 const char *prefix = "/";
2630 char *prefixed_testfile = zsys_sprintf ("%s%s", prefix, testfile);
2631 assert (prefixed_testfile);
2632
2633 // Make sure old aborted tests do not hinder us
2634 zsys_file_delete (prefixed_testfile);
2635
2636 zfile_t *file = zfile_new (SELFTEST_DIR_RW, testfile);
21442637 assert (file);
2145 zdir_patch_t *patch = zdir_patch_new (".", file, patch_create, "/");
2638 zdir_patch_t *patch = zdir_patch_new (SELFTEST_DIR_RW, file, patch_create, prefix);
21462639 assert (patch);
21472640 zfile_destroy (&file);
21482641
21492642 file = zdir_patch_file (patch);
21502643 assert (file);
2151 assert (streq (zfile_filename (file, "."), "bilbo"));
2152 assert (streq (zdir_patch_vpath (patch), "/bilbo"));
2644 assert (streq (zfile_filename (file, SELFTEST_DIR_RW), testfile));
2645 assert (streq (zdir_patch_vpath (patch), prefixed_testfile));
21532646 zdir_patch_destroy (&patch);
2647
2648 zstr_free (&prefixed_testfile);
21542649
21552650 #if defined (__WINDOWS__)
21562651 zsys_shutdown();
21822677 // links, which are files with the extension ".ln". A symbolic link is a
21832678 // text file containing one line, the filename of a target file. Reading
21842679 // data from the symbolic link actually reads from the target file. Path
2185 // may be NULL, in which case it is not used.
2680 // may be NULL, in which case it is not used.
21862681 CZMQ_EXPORT zfile_t *
21872682 zfile_new (const char *path, const char *name);
21882683
21912686 zfile_destroy (zfile_t **self_p);
21922687
21932688 // Duplicate a file item, returns a newly constructed item. If the file
2194 // is null, or memory was exhausted, returns null.
2689 // is null, or memory was exhausted, returns null.
21952690 // Caller owns return value and must destroy it when done.
21962691 CZMQ_EXPORT zfile_t *
21972692 zfile_dup (zfile_t *self);
22002695 CZMQ_EXPORT const char *
22012696 zfile_filename (zfile_t *self, const char *path);
22022697
2203 // Refresh file properties from disk; this is not done automatically
2698 // Refresh file properties from disk; this is not done automatically
22042699 // on access methods, otherwise it is not possible to compare directory
2205 // snapshots.
2700 // snapshots.
22062701 CZMQ_EXPORT void
22072702 zfile_restat (zfile_t *self);
22082703
22092704 // Return when the file was last modified. If you want this to reflect the
2210 // current situation, call zfile_restat before checking this property.
2705 // current situation, call zfile_restat before checking this property.
22112706 CZMQ_EXPORT time_t
22122707 zfile_modified (zfile_t *self);
22132708
22142709 // Return the last-known size of the file. If you want this to reflect the
2215 // current situation, call zfile_restat before checking this property.
2710 // current situation, call zfile_restat before checking this property.
22162711 CZMQ_EXPORT off_t
22172712 zfile_cursize (zfile_t *self);
22182713
2219 // Return true if the file is a directory. If you want this to reflect
2714 // Return true if the file is a directory. If you want this to reflect
22202715 // any external changes, call zfile_restat before checking this property.
22212716 CZMQ_EXPORT bool
22222717 zfile_is_directory (zfile_t *self);
22272722 zfile_is_regular (zfile_t *self);
22282723
22292724 // Return true if the file is readable by this process. If you want this to
2230 // reflect any external changes, call zfile_restat before checking this
2231 // property.
2725 // reflect any external changes, call zfile_restat before checking this
2726 // property.
22322727 CZMQ_EXPORT bool
22332728 zfile_is_readable (zfile_t *self);
22342729
2235 // Return true if the file is writeable by this process. If you want this
2730 // Return true if the file is writeable by this process. If you want this
22362731 // to reflect any external changes, call zfile_restat before checking this
2237 // property.
2732 // property.
22382733 CZMQ_EXPORT bool
22392734 zfile_is_writeable (zfile_t *self);
22402735
22412736 // Check if file has stopped changing and can be safely processed.
2242 // Updates the file statistics from disk at every call.
2737 // Updates the file statistics from disk at every call.
22432738 CZMQ_EXPORT bool
22442739 zfile_is_stable (zfile_t *self);
22452740
22462741 // Return true if the file was changed on disk since the zfile_t object
2247 // was created, or the last zfile_restat() call made on it.
2742 // was created, or the last zfile_restat() call made on it.
22482743 CZMQ_EXPORT bool
22492744 zfile_has_changed (zfile_t *self);
22502745
22522747 CZMQ_EXPORT void
22532748 zfile_remove (zfile_t *self);
22542749
2255 // Open file for reading
2750 // Open file for reading
22562751 // Returns 0 if OK, -1 if not found or not accessible
22572752 CZMQ_EXPORT int
22582753 zfile_input (zfile_t *self);
22592754
2260 // Open file for writing, creating directory if needed
2755 // Open file for writing, creating directory if needed
22612756 // File is created if necessary; chunks can be written to file at any
2262 // location. Returns 0 if OK, -1 if error.
2757 // location. Returns 0 if OK, -1 if error.
22632758 CZMQ_EXPORT int
22642759 zfile_output (zfile_t *self);
22652760
22662761 // Read chunk from file at specified position. If this was the last chunk,
2267 // sets the eof property. Returns a null chunk in case of error.
2762 // sets the eof property. Returns a null chunk in case of error.
22682763 // Caller owns return value and must destroy it when done.
22692764 CZMQ_EXPORT zchunk_t *
22702765 zfile_read (zfile_t *self, size_t bytes, off_t offset);
22742769 zfile_eof (zfile_t *self);
22752770
22762771 // Write chunk to file at specified position
2277 // Return 0 if OK, else -1
2772 // Return 0 if OK, else -1
22782773 CZMQ_EXPORT int
22792774 zfile_write (zfile_t *self, zchunk_t *chunk, off_t offset);
22802775
22812776 // Read next line of text from file. Returns a pointer to the text line,
2282 // or NULL if there was nothing more to read from the file.
2777 // or NULL if there was nothing more to read from the file.
22832778 CZMQ_EXPORT const char *
22842779 zfile_readln (zfile_t *self);
22852780
22992794 CZMQ_EXPORT void
23002795 zfile_test (bool verbose);
23012796
2797 #ifdef CZMQ_BUILD_DRAFT_API
2798 // *** Draft method, for development use, may change without warning ***
2799 // Create new temporary file for writing via tmpfile. File is automatically
2800 // deleted on destroy
2801 CZMQ_EXPORT zfile_t *
2802 zfile_tmp (void);
2803
2804 #endif // CZMQ_BUILD_DRAFT_API
23022805 // These methods are deprecated, and now moved to zsys class.
23032806 CZMQ_EXPORT bool
23042807 zfile_exists (const char *filename);
23242827 This is the class self test code:
23252828
23262829 ```c
2327 zfile_t *file = zfile_new (NULL, "bilbo");
2830
2831 const char *SELFTEST_DIR_RW = "src/selftest-rw";
2832
2833 const char *testbasedir = "this";
2834 const char *testsubdir = "is/a/test";
2835 const char *testfile = "bilbo";
2836 const char *testlink = "bilbo.ln";
2837 char *basedirpath = NULL; // subdir in a test, under SELFTEST_DIR_RW
2838 char *dirpath = NULL; // subdir in a test, under basedirpath
2839 char *filepath = NULL; // pathname to testfile in a test, in dirpath
2840 char *linkpath = NULL; // pathname to testlink in a test, in dirpath
2841
2842 basedirpath = zsys_sprintf ("%s/%s", SELFTEST_DIR_RW, testbasedir);
2843 assert (basedirpath);
2844 dirpath = zsys_sprintf ("%s/%s", basedirpath, testsubdir);
2845 assert (dirpath);
2846 filepath = zsys_sprintf ("%s/%s", dirpath, testfile);
2847 assert (filepath);
2848 linkpath = zsys_sprintf ("%s/%s", dirpath, testlink);
2849 assert (linkpath);
2850
2851 // This subtest is specifically for NULL as current directory, so
2852 // no SELFTEST_DIR_RW here; testfile should have no slashes inside.
2853 // Normally tests clean up in zfile_destroy(), but if a selftest run
2854 // dies e.g. on assert(), workspace remains dirty. Better clean it up.
2855 if (zfile_exists (testfile) ) {
2856 if (verbose)
2857 zsys_debug ("zfile_test() has to remove ./%s that should not have been here", testfile);
2858 zfile_delete (testfile);
2859 }
2860 zfile_t *file = zfile_new (NULL, testfile);
23282861 assert (file);
2329 assert (streq (zfile_filename (file, "."), "bilbo"));
2862 assert (streq (zfile_filename (file, "."), testfile));
23302863 assert (zfile_is_readable (file) == false);
23312864 zfile_destroy (&file);
23322865
23332866 // Create a test file in some random subdirectory
2334 file = zfile_new ("./this/is/a/test", "bilbo");
2867 if (verbose)
2868 zsys_debug ("zfile_test() at timestamp %" PRIi64 ": "
2869 "Creating new zfile %s",
2870 zclock_time(), filepath );
2871
2872 if (zfile_exists (filepath) ) {
2873 if (verbose)
2874 zsys_debug ("zfile_test() has to remove %s that should not have been here", filepath);
2875 zfile_delete (filepath);
2876 }
2877
2878 file = zfile_new (dirpath, testfile);
23352879 assert (file);
23362880 int rc = zfile_output (file);
23372881 assert (rc == 0);
23402884 zchunk_fill (chunk, 0, 100);
23412885
23422886 // Write 100 bytes at position 1,000,000 in the file
2887 if (verbose)
2888 zsys_debug ("zfile_test() at timestamp %" PRIi64 ": "
2889 "Writing 100 bytes at position 1,000,000 in the file",
2890 zclock_time() );
23432891 rc = zfile_write (file, chunk, 1000000);
2892 if (verbose)
2893 zsys_debug ("zfile_test() at timestamp %" PRIi64 ": "
2894 "Wrote 100 bytes at position 1,000,000 in the file, result code %d",
2895 zclock_time(), rc );
23442896 assert (rc == 0);
23452897 zchunk_destroy (&chunk);
23462898 zfile_close (file);
23472899 assert (zfile_is_readable (file));
23482900 assert (zfile_cursize (file) == 1000100);
2901 if (verbose)
2902 zsys_debug ("zfile_test() at timestamp %" PRIi64 ": "
2903 "Testing if file is NOT stable (is younger than 1 sec)",
2904 zclock_time() );
23492905 assert (!zfile_is_stable (file));
2906 if (verbose)
2907 zsys_debug ("zfile_test() at timestamp %" PRIi64 ": "
2908 "Passed the lag-dependent tests",
2909 zclock_time() );
23502910 assert (zfile_digest (file));
23512911
23522912 // Now truncate file from outside
2353 int handle = open ("./this/is/a/test/bilbo", O_WRONLY | O_TRUNC | O_BINARY, 0);
2913 int handle = open (filepath, O_WRONLY | O_TRUNC | O_BINARY, 0);
23542914 assert (handle >= 0);
23552915 rc = write (handle, "Hello, World\n", 13);
23562916 assert (rc == 13);
23572917 close (handle);
23582918 assert (zfile_has_changed (file));
2359 zclock_sleep (1001);
2919 #ifdef CZMQ_BUILD_DRAFT_API
2920 zclock_sleep ((int)zsys_file_stable_age_msec() + 50);
2921 #else
2922 zclock_sleep (5050);
2923 #endif
23602924 assert (zfile_has_changed (file));
23612925
23622926 assert (!zfile_is_stable (file));
23832947 zfile_close (file);
23842948
23852949 // Try some fun with symbolic links
2386 zfile_t *link = zfile_new ("./this/is/a/test", "bilbo.ln");
2950 zfile_t *link = zfile_new (dirpath, testlink);
23872951 assert (link);
23882952 rc = zfile_output (link);
23892953 assert (rc == 0);
2390 fprintf (zfile_handle (link), "./this/is/a/test/bilbo\n");
2954 fprintf (zfile_handle (link), "%s\n", filepath);
23912955 zfile_destroy (&link);
23922956
2393 link = zfile_new ("./this/is/a/test", "bilbo.ln");
2957 link = zfile_new (dirpath, testlink);
23942958 assert (link);
23952959 rc = zfile_input (link);
23962960 assert (rc == 0);
24012965 zfile_destroy (&link);
24022966
24032967 // Remove file and directory
2404 zdir_t *dir = zdir_new ("./this", NULL);
2968 zdir_t *dir = zdir_new (basedirpath, NULL);
24052969 assert (dir);
24062970 assert (zdir_cursize (dir) == 26);
24072971 zdir_remove (dir, true);
24162980 assert (rc == -1);
24172981 zfile_destroy (&file);
24182982
2419 file = zfile_new ("./", "eof_checkfile");
2983 // This set of tests is done, free the strings for reuse
2984 zstr_free (&basedirpath);
2985 zstr_free (&dirpath);
2986 zstr_free (&filepath);
2987 zstr_free (&linkpath);
2988
2989 const char *eof_checkfile = "eof_checkfile";
2990 filepath = zsys_sprintf ("%s/%s", SELFTEST_DIR_RW, eof_checkfile);
2991 assert (filepath);
2992
2993 if (zfile_exists (filepath) ) {
2994 if (verbose)
2995 zsys_debug ("zfile_test() has to remove %s that should not have been here", filepath);
2996 zfile_delete (filepath);
2997 }
2998 zstr_free (&filepath);
2999
3000 file = zfile_new (SELFTEST_DIR_RW, eof_checkfile);
24203001 assert (file);
3002
24213003 // 1. Write something first
24223004 rc = zfile_output (file);
24233005 assert (rc == 0);
24543036 zfile_close (file);
24553037 zfile_destroy (&file);
24563038
3039 #ifdef CZMQ_BUILD_DRAFT_API
3040 zfile_t *tempfile = zfile_tmp ();
3041 assert (tempfile);
3042 assert (zfile_filename (tempfile, NULL));
3043 assert (zsys_file_exists (zfile_filename (tempfile, NULL)));
3044 zchunk_t *tchunk = zchunk_new ("HELLO", 6);
3045 assert (zfile_write (tempfile, tchunk, 0) == 0);
3046 zchunk_destroy (&tchunk);
3047
3048 char *filename = strdup (zfile_filename (tempfile, NULL));
3049 zfile_destroy (&tempfile);
3050 assert (!zsys_file_exists (filename));
3051 zstr_free (&filename);
3052 #endif // CZMQ_BUILD_DRAFT_API
3053
24573054 #if defined (__WINDOWS__)
24583055 zsys_shutdown();
24593056 #endif
24793076 // is provided in stable builds.
24803077 // This class has draft methods, which may change over time. They are not
24813078 // in stable releases, by default. Use --enable-drafts to enable.
2482 #define ZFRAME_MORE 1 //
2483 #define ZFRAME_REUSE 2 //
2484 #define ZFRAME_DONTWAIT 4 //
3079 #define ZFRAME_MORE 1 //
3080 #define ZFRAME_REUSE 2 //
3081 #define ZFRAME_DONTWAIT 4 //
24853082
24863083 // Create a new frame. If size is not null, allocates the frame data
2487 // to the specified size. If additionally, data is not null, copies
2488 // size octets from the specified data into the frame body.
3084 // to the specified size. If additionally, data is not null, copies
3085 // size octets from the specified data into the frame body.
24893086 CZMQ_EXPORT zframe_t *
24903087 zframe_new (const void *data, size_t size);
24913088
24973094 CZMQ_EXPORT zframe_t *
24983095 zframe_from (const char *string);
24993096
2500 // Receive frame from socket, returns zframe_t object or NULL if the recv
3097 // Receive frame from socket, returns zframe_t object or NULL if the recv
25013098 // was interrupted. Does a blocking recv, if you want to not block then use
2502 // zpoller or zloop.
3099 // zpoller or zloop.
25033100 CZMQ_EXPORT zframe_t *
25043101 zframe_recv (void *source);
25053102
25083105 zframe_destroy (zframe_t **self_p);
25093106
25103107 // Send a frame to a socket, destroy frame after sending.
2511 // Return -1 on error, 0 on success.
3108 // Return -1 on error, 0 on success.
25123109 CZMQ_EXPORT int
25133110 zframe_send (zframe_t **self_p, void *dest, int flags);
25143111
25273124 zframe_meta (zframe_t *self, const char *property);
25283125
25293126 // Create a new frame that duplicates an existing frame. If frame is null,
2530 // or memory was exhausted, returns null.
3127 // or memory was exhausted, returns null.
25313128 // Caller owns return value and must destroy it when done.
25323129 CZMQ_EXPORT zframe_t *
25333130 zframe_dup (zframe_t *self);
25343131
25353132 // Return frame data encoded as printable hex string, useful for ØMQ UUIDs.
2536 // Caller must free string when finished with it.
3133 // Caller must free string when finished with it.
25373134 // Caller owns return value and must destroy it when done.
25383135 CZMQ_EXPORT char *
25393136 zframe_strhex (zframe_t *self);
25403137
25413138 // Return frame data copied into freshly allocated string
2542 // Caller must free string when finished with it.
3139 // Caller must free string when finished with it.
25433140 // Caller owns return value and must destroy it when done.
25443141 CZMQ_EXPORT char *
25453142 zframe_strdup (zframe_t *self);
25493146 zframe_streq (zframe_t *self, const char *string);
25503147
25513148 // Return frame MORE indicator (1 or 0), set when reading frame from socket
2552 // or by the zframe_set_more() method
3149 // or by the zframe_set_more() method
25533150 CZMQ_EXPORT int
25543151 zframe_more (zframe_t *self);
25553152
25563153 // Set frame MORE indicator (1 or 0). Note this is NOT used when sending
2557 // frame to socket, you have to specify flag explicitly.
3154 // frame to socket, you have to specify flag explicitly.
25583155 CZMQ_EXPORT void
25593156 zframe_set_more (zframe_t *self, int more);
25603157
25613158 // Return TRUE if two frames have identical size and data
2562 // If either frame is NULL, equality is always false.
3159 // If either frame is NULL, equality is always false.
25633160 CZMQ_EXPORT bool
25643161 zframe_eq (zframe_t *self, zframe_t *other);
25653162
25673164 CZMQ_EXPORT void
25683165 zframe_reset (zframe_t *self, const void *data, size_t size);
25693166
2570 // Send message to zsys log sink (may be stdout, or system facility as
3167 // Send message to zsys log sink (may be stdout, or system facility as
25713168 // configured by zsys_set_logstream). Prefix shows before frame, if not null.
25723169 CZMQ_EXPORT void
25733170 zframe_print (zframe_t *self, const char *prefix);
25833180 #ifdef CZMQ_BUILD_DRAFT_API
25843181 // *** Draft method, for development use, may change without warning ***
25853182 // Return frame routing ID, if the frame came from a ZMQ_SERVER socket.
2586 // Else returns zero.
3183 // Else returns zero.
25873184 CZMQ_EXPORT uint32_t
25883185 zframe_routing_id (zframe_t *self);
25893186
25903187 // *** Draft method, for development use, may change without warning ***
25913188 // Set routing ID on frame. This is used if/when the frame is sent to a
2592 // ZMQ_SERVER socket.
3189 // ZMQ_SERVER socket.
25933190 CZMQ_EXPORT void
25943191 zframe_set_routing_id (zframe_t *self, uint32_t routing_id);
25953192
26003197
26013198 // *** Draft method, for development use, may change without warning ***
26023199 // Set group on frame. This is used if/when the frame is sent to a
2603 // ZMQ_RADIO socket.
2604 // Return -1 on error, 0 on success.
3200 // ZMQ_RADIO socket.
3201 // Return -1 on error, 0 on success.
26053202 CZMQ_EXPORT int
26063203 zframe_set_group (zframe_t *self, const char *group);
26073204
26133210
26143211 ```c
26153212 // Create two PAIR sockets and connect over inproc
2616 zsock_t *output = zsock_new_pair ("@tcp://127.0.0.1:9001");
3213 zsock_t *output = zsock_new (ZMQ_PAIR);
26173214 assert (output);
2618 zsock_t *input = zsock_new_pair (">tcp://127.0.0.1:9001");
3215 int port = zsock_bind (output, "tcp://127.0.0.1:*");
3216 assert (port != -1);
3217 zsock_t *input = zsock_new (ZMQ_PAIR);
26193218 assert (input);
3219 rc = zsock_connect (input, "tcp://127.0.0.1:%d", port);
3220 assert (rc != -1);
26203221
26213222 // Send five different frames, test ZFRAME_MORE
26223223 int frame_nbr;
26543255 zframe_reset (frame, "END", 3);
26553256 char *string = zframe_strhex (frame);
26563257 assert (streq (string, "454E44"));
2657 free (string);
3258 freen (string);
26583259 string = zframe_strdup (frame);
26593260 assert (streq (string, "END"));
2660 free (string);
3261 freen (string);
26613262 rc = zframe_send (&frame, output, 0);
26623263 assert (rc == 0);
26633264
27673368
27683369 zsock_destroy (&dish);
27693370 zsock_destroy (&radio);
3371 #else
3372 frame = zframe_new ("Hello", 5);
3373 rc = zframe_set_group (frame, "World");
3374 assert(rc == -1);
3375 assert(errno == ENOTSUP);
3376 zframe_destroy (&frame);
27703377 #endif
27713378
27723379 #if defined (__WINDOWS__)
27933400 * CONNECT endpoint -- connect the gossip service to the specified peer
27943401 * PUBLISH key value -- publish a key/value pair to the gossip cluster
27953402 * STATUS -- return number of key/value pairs held by gossip service
3403 * ZAP DOMAIN domain -- set the ZAP DOMAIN domain = value
27963404
27973405 Returns these messages:
27983406
28683476 // zstr_send (zgossip, "VERBOSE");
28693477 //
28703478 // Bind zgossip to specified endpoint. TCP endpoints may specify
2871 // the port number as "*" to aquire an ephemeral port:
3479 // the port number as "*" to acquire an ephemeral port:
28723480 //
28733481 // zstr_sendx (zgossip, "BIND", endpoint, NULL);
28743482 //
30123620 zactor_destroy (&alpha);
30133621 zactor_destroy (&beta);
30143622
3623 #ifdef CZMQ_BUILD_DRAFT_API
3624 // curve
3625 if (zsys_has_curve()) {
3626 if (verbose)
3627 printf("testing CURVE support");
3628 zclock_sleep (2000);
3629 zactor_t *auth = zactor_new(zauth, NULL);
3630 assert (auth);
3631 if (verbose) {
3632 zstr_sendx (auth, "VERBOSE", NULL);
3633 zsock_wait (auth);
3634 }
3635 zstr_sendx(auth,"ALLOW","127.0.0.1",NULL);
3636 zsock_wait(auth);
3637 zstr_sendx (auth, "CURVE", CURVE_ALLOW_ANY, NULL);
3638 zsock_wait (auth);
3639
3640 server = zactor_new (zgossip, "server");
3641 if (verbose)
3642 zstr_send (server, "VERBOSE");
3643 assert (server);
3644
3645 zcert_t *client1_cert = zcert_new ();
3646 zcert_t *server_cert = zcert_new ();
3647
3648 zstr_sendx (server, "SET PUBLICKEY", zcert_public_txt (server_cert), NULL);
3649 zstr_sendx (server, "SET SECRETKEY", zcert_secret_txt (server_cert), NULL);
3650 zstr_sendx (server, "ZAP DOMAIN", "TEST", NULL);
3651
3652 zstr_sendx (server, "BIND", "tcp://127.0.0.1:*", NULL);
3653 zstr_sendx (server, "PORT", NULL);
3654 zstr_recvx (server, &command, &value, NULL);
3655 assert (streq (command, "PORT"));
3656 int port = atoi (value);
3657 zstr_free (&command);
3658 zstr_free (&value);
3659 char endpoint [32];
3660 sprintf (endpoint, "tcp://127.0.0.1:%d", port);
3661
3662 zactor_t *client1 = zactor_new (zgossip, "client");
3663 if (verbose)
3664 zstr_send (client1, "VERBOSE");
3665 assert (client1);
3666
3667 zstr_sendx (client1, "SET PUBLICKEY", zcert_public_txt (client1_cert), NULL);
3668 zstr_sendx (client1, "SET SECRETKEY", zcert_secret_txt (client1_cert), NULL);
3669 zstr_sendx (client1, "ZAP DOMAIN", "TEST", NULL);
3670
3671 const char *public_txt = zcert_public_txt (server_cert);
3672 zstr_sendx (client1, "CONNECT", endpoint, public_txt, NULL);
3673 zstr_sendx (client1, "PUBLISH", "tcp://127.0.0.1:9001", "service1", NULL);
3674
3675 zclock_sleep (500);
3676
3677 zstr_send (server, "STATUS");
3678 zclock_sleep (500);
3679
3680 zstr_recvx (server, &command, &key, &value, NULL);
3681 assert (streq (command, "DELIVER"));
3682 assert (streq (value, "service1"));
3683
3684 zstr_free (&command);
3685 zstr_free (&key);
3686 zstr_free (&value);
3687
3688 zstr_sendx (client1, "$TERM", NULL);
3689 zstr_sendx (server, "$TERM", NULL);
3690
3691 zclock_sleep(500);
3692
3693 zcert_destroy (&client1_cert);
3694 zcert_destroy (&server_cert);
3695
3696 zactor_destroy (&client1);
3697 zactor_destroy (&server);
3698 zactor_destroy (&auth);
3699 }
3700 #endif
3701
30153702 #if defined (__WINDOWS__)
30163703 zsys_shutdown();
30173704 #endif
30413728 zhash_new (void);
30423729
30433730 // Unpack binary frame into a new hash table. Packed data must follow format
3044 // defined by zhash_pack. Hash table is set to autofree. An empty frame
3045 // unpacks to an empty hash table.
3731 // defined by zhash_pack. Hash table is set to autofree. An empty frame
3732 // unpacks to an empty hash table.
30463733 CZMQ_EXPORT zhash_t *
30473734 zhash_unpack (zframe_t *frame);
30483735
30503737 CZMQ_EXPORT void
30513738 zhash_destroy (zhash_t **self_p);
30523739
3053 // Insert item into hash table with specified key and item.
3740 // Insert item into hash table with specified key and item.
30543741 // If key is already present returns -1 and leaves existing item unchanged
3055 // Returns 0 on success.
3742 // Returns 0 on success.
30563743 CZMQ_EXPORT int
30573744 zhash_insert (zhash_t *self, const char *key, void *item);
30583745
3059 // Update item into hash table with specified key and item.
3060 // If key is already present, destroys old item and inserts new one.
3746 // Update item into hash table with specified key and item.
3747 // If key is already present, destroys old item and inserts new one.
30613748 // Use free_fn method to ensure deallocator is properly called on item.
30623749 CZMQ_EXPORT void
30633750 zhash_update (zhash_t *self, const char *key, void *item);
30643751
30653752 // Remove an item specified by key from the hash table. If there was no such
3066 // item, this function does nothing.
3753 // item, this function does nothing.
30673754 CZMQ_EXPORT void
30683755 zhash_delete (zhash_t *self, const char *key);
30693756
30723759 zhash_lookup (zhash_t *self, const char *key);
30733760
30743761 // Reindexes an item from an old key to a new key. If there was no such
3075 // item, does nothing. Returns 0 if successful, else -1.
3762 // item, does nothing. Returns 0 if successful, else -1.
30763763 CZMQ_EXPORT int
30773764 zhash_rename (zhash_t *self, const char *old_key, const char *new_key);
30783765
30793766 // Set a free function for the specified hash table item. When the item is
3080 // destroyed, the free function, if any, is called on that item.
3081 // Use this when hash items are dynamically allocated, to ensure that
3082 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
3083 // Returns the item, or NULL if there is no such item.
3767 // destroyed, the free function, if any, is called on that item.
3768 // Use this when hash items are dynamically allocated, to ensure that
3769 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
3770 // Returns the item, or NULL if there is no such item.
30843771 CZMQ_EXPORT void *
30853772 zhash_freefn (zhash_t *self, const char *key, zhash_free_fn free_fn);
30863773
30883775 CZMQ_EXPORT size_t
30893776 zhash_size (zhash_t *self);
30903777
3091 // Make copy of hash table; if supplied table is null, returns null.
3092 // Does not copy items themselves. Rebuilds new table so may be slow on
3778 // Make copy of hash table; if supplied table is null, returns null.
3779 // Does not copy items themselves. Rebuilds new table so may be slow on
30933780 // very large tables. NOTE: only works with item values that are strings
3094 // since there's no other way to know how to duplicate the item value.
3781 // since there's no other way to know how to duplicate the item value.
30953782 // Caller owns return value and must destroy it when done.
30963783 CZMQ_EXPORT zhash_t *
30973784 zhash_dup (zhash_t *self);
31013788 CZMQ_EXPORT zlist_t *
31023789 zhash_keys (zhash_t *self);
31033790
3104 // Simple iterator; returns first item in hash table, in no given order,
3105 // or NULL if the table is empty. This method is simpler to use than the
3791 // Simple iterator; returns first item in hash table, in no given order,
3792 // or NULL if the table is empty. This method is simpler to use than the
31063793 // foreach() method, which is deprecated. To access the key for this item
3107 // use zhash_cursor(). NOTE: do NOT modify the table while iterating.
3794 // use zhash_cursor(). NOTE: do NOT modify the table while iterating.
31083795 CZMQ_EXPORT void *
31093796 zhash_first (zhash_t *self);
31103797
3111 // Simple iterator; returns next item in hash table, in no given order,
3798 // Simple iterator; returns next item in hash table, in no given order,
31123799 // or NULL if the last item was already returned. Use this together with
3113 // zhash_first() to process all items in a hash table. If you need the
3114 // items in sorted order, use zhash_keys() and then zlist_sort(). To
3115 // access the key for this item use zhash_cursor(). NOTE: do NOT modify
3116 // the table while iterating.
3800 // zhash_first() to process all items in a hash table. If you need the
3801 // items in sorted order, use zhash_keys() and then zlist_sort(). To
3802 // access the key for this item use zhash_cursor(). NOTE: do NOT modify
3803 // the table while iterating.
31173804 CZMQ_EXPORT void *
31183805 zhash_next (zhash_t *self);
31193806
31203807 // After a successful first/next method, returns the key for the item that
3121 // was returned. This is a constant string that you may not modify or
3122 // deallocate, and which lasts as long as the item in the hash. After an
3123 // unsuccessful first/next, returns NULL.
3808 // was returned. This is a constant string that you may not modify or
3809 // deallocate, and which lasts as long as the item in the hash. After an
3810 // unsuccessful first/next, returns NULL.
31243811 CZMQ_EXPORT const char *
31253812 zhash_cursor (zhash_t *self);
31263813
3127 // Add a comment to hash table before saving to disk. You can add as many
3814 // Add a comment to hash table before saving to disk. You can add as many
31283815 // comment lines as you like. These comment lines are discarded when loading
3129 // the file. If you use a null format, all comments are deleted.
3816 // the file. If you use a null format, all comments are deleted.
31303817 CZMQ_EXPORT void
31313818 zhash_comment (zhash_t *self, const char *format, ...) CHECK_PRINTF (2);
31323819
31333820 // Serialize hash table to a binary frame that can be sent in a message.
31343821 // The packed format is compatible with the 'dictionary' type defined in
3135 // http://rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
3136 //
3137 // ; A list of name/value pairs
3138 // dictionary = dict-count *( dict-name dict-value )
3139 // dict-count = number-4
3140 // dict-value = longstr
3141 // dict-name = string
3142 //
3143 // ; Strings are always length + text contents
3144 // longstr = number-4 *VCHAR
3145 // string = number-1 *VCHAR
3146 //
3147 // ; Numbers are unsigned integers in network byte order
3148 // number-1 = 1OCTET
3149 // number-4 = 4OCTET
3150 //
3151 // Comments are not included in the packed data. Item values MUST be
3152 // strings.
3822 // http://rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
3823 //
3824 // ; A list of name/value pairs
3825 // dictionary = dict-count *( dict-name dict-value )
3826 // dict-count = number-4
3827 // dict-value = longstr
3828 // dict-name = string
3829 //
3830 // ; Strings are always length + text contents
3831 // longstr = number-4 *VCHAR
3832 // string = number-1 *VCHAR
3833 //
3834 // ; Numbers are unsigned integers in network byte order
3835 // number-1 = 1OCTET
3836 // number-4 = 4OCTET
3837 //
3838 // Comments are not included in the packed data. Item values MUST be
3839 // strings.
31533840 // Caller owns return value and must destroy it when done.
31543841 CZMQ_EXPORT zframe_t *
31553842 zhash_pack (zhash_t *self);
31563843
31573844 // Save hash table to a text file in name=value format. Hash values must be
3158 // printable strings; keys may not contain '=' character. Returns 0 if OK,
3159 // else -1 if a file error occurred.
3845 // printable strings; keys may not contain '=' character. Returns 0 if OK,
3846 // else -1 if a file error occurred.
31603847 CZMQ_EXPORT int
31613848 zhash_save (zhash_t *self, const char *filename);
31623849
3163 // Load hash table from a text file in name=value format; hash table must
3850 // Load hash table from a text file in name=value format; hash table must
31643851 // already exist. Hash values must printable strings; keys may not contain
3165 // '=' character. Returns 0 if OK, else -1 if a file was not readable.
3852 // '=' character. Returns 0 if OK, else -1 if a file was not readable.
31663853 CZMQ_EXPORT int
31673854 zhash_load (zhash_t *self, const char *filename);
31683855
31693856 // When a hash table was loaded from a file by zhash_load, this method will
31703857 // reload the file if it has been modified since, and is "stable", i.e. not
3171 // still changing. Returns 0 if OK, -1 if there was an error reloading the
3172 // file.
3858 // still changing. Returns 0 if OK, -1 if there was an error reloading the
3859 // file.
31733860 CZMQ_EXPORT int
31743861 zhash_refresh (zhash_t *self);
31753862
31763863 // Set hash for automatic value destruction. Note that this assumes that
3177 // values are NULL-terminated strings. Do not use with different types.
3864 // values are NULL-terminated strings. Do not use with different types.
31783865 CZMQ_EXPORT void
31793866 zhash_autofree (zhash_t *self);
31803867
33924079 typedef size_t (zhashx_hash_fn) (
33934080 const void *key);
33944081
3395 // Serializes an item to a longstr.
4082 // Serializes an item to a longstr.
33964083 // The caller takes ownership of the newly created object.
33974084 typedef char * (zhashx_serializer_fn) (
33984085 const void *item);
33994086
3400 // Deserializes a longstr into an item.
4087 // Deserializes a longstr into an item.
34014088 // The caller takes ownership of the newly created object.
34024089 typedef void * (zhashx_deserializer_fn) (
34034090 const char *item_str);
34074094 zhashx_new (void);
34084095
34094096 // Unpack binary frame into a new hash table. Packed data must follow format
3410 // defined by zhashx_pack. Hash table is set to autofree. An empty frame
3411 // unpacks to an empty hash table.
4097 // defined by zhashx_pack. Hash table is set to autofree. An empty frame
4098 // unpacks to an empty hash table.
34124099 CZMQ_EXPORT zhashx_t *
34134100 zhashx_unpack (zframe_t *frame);
34144101
34164103 CZMQ_EXPORT void
34174104 zhashx_destroy (zhashx_t **self_p);
34184105
3419 // Insert item into hash table with specified key and item.
4106 // Insert item into hash table with specified key and item.
34204107 // If key is already present returns -1 and leaves existing item unchanged
3421 // Returns 0 on success.
4108 // Returns 0 on success.
34224109 CZMQ_EXPORT int
34234110 zhashx_insert (zhashx_t *self, const void *key, void *item);
34244111
34254112 // Update or insert item into hash table with specified key and item. If the
34264113 // key is already present, destroys old item and inserts new one. If you set
3427 // a container item destructor, this is called on the old value. If the key
3428 // was not already present, inserts a new item. Sets the hash cursor to the
3429 // new item.
4114 // a container item destructor, this is called on the old value. If the key
4115 // was not already present, inserts a new item. Sets the hash cursor to the
4116 // new item.
34304117 CZMQ_EXPORT void
34314118 zhashx_update (zhashx_t *self, const void *key, void *item);
34324119
34334120 // Remove an item specified by key from the hash table. If there was no such
3434 // item, this function does nothing.
4121 // item, this function does nothing.
34354122 CZMQ_EXPORT void
34364123 zhashx_delete (zhashx_t *self, const void *key);
34374124
3438 // Delete all items from the hash table. If the key destructor is
4125 // Delete all items from the hash table. If the key destructor is
34394126 // set, calls it on every key. If the item destructor is set, calls
3440 // it on every item.
4127 // it on every item.
34414128 CZMQ_EXPORT void
34424129 zhashx_purge (zhashx_t *self);
34434130
34464133 zhashx_lookup (zhashx_t *self, const void *key);
34474134
34484135 // Reindexes an item from an old key to a new key. If there was no such
3449 // item, does nothing. Returns 0 if successful, else -1.
4136 // item, does nothing. Returns 0 if successful, else -1.
34504137 CZMQ_EXPORT int
34514138 zhashx_rename (zhashx_t *self, const void *old_key, const void *new_key);
34524139
34534140 // Set a free function for the specified hash table item. When the item is
3454 // destroyed, the free function, if any, is called on that item.
3455 // Use this when hash items are dynamically allocated, to ensure that
3456 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
3457 // Returns the item, or NULL if there is no such item.
4141 // destroyed, the free function, if any, is called on that item.
4142 // Use this when hash items are dynamically allocated, to ensure that
4143 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
4144 // Returns the item, or NULL if there is no such item.
34584145 CZMQ_EXPORT void *
34594146 zhashx_freefn (zhashx_t *self, const void *key, zhashx_free_fn free_fn);
34604147
34624149 CZMQ_EXPORT size_t
34634150 zhashx_size (zhashx_t *self);
34644151
3465 // Return a zlistx_t containing the keys for the items in the
4152 // Return a zlistx_t containing the keys for the items in the
34664153 // table. Uses the key_duplicator to duplicate all keys and sets the
3467 // key_destructor as destructor for the list.
4154 // key_destructor as destructor for the list.
34684155 // Caller owns return value and must destroy it when done.
34694156 CZMQ_EXPORT zlistx_t *
34704157 zhashx_keys (zhashx_t *self);
34714158
3472 // Return a zlistx_t containing the values for the items in the
4159 // Return a zlistx_t containing the values for the items in the
34734160 // table. Uses the duplicator to duplicate all items and sets the
3474 // destructor as destructor for the list.
4161 // destructor as destructor for the list.
34754162 // Caller owns return value and must destroy it when done.
34764163 CZMQ_EXPORT zlistx_t *
34774164 zhashx_values (zhashx_t *self);
34784165
3479 // Simple iterator; returns first item in hash table, in no given order,
3480 // or NULL if the table is empty. This method is simpler to use than the
4166 // Simple iterator; returns first item in hash table, in no given order,
4167 // or NULL if the table is empty. This method is simpler to use than the
34814168 // foreach() method, which is deprecated. To access the key for this item
3482 // use zhashx_cursor(). NOTE: do NOT modify the table while iterating.
4169 // use zhashx_cursor(). NOTE: do NOT modify the table while iterating.
34834170 CZMQ_EXPORT void *
34844171 zhashx_first (zhashx_t *self);
34854172
3486 // Simple iterator; returns next item in hash table, in no given order,
4173 // Simple iterator; returns next item in hash table, in no given order,
34874174 // or NULL if the last item was already returned. Use this together with
3488 // zhashx_first() to process all items in a hash table. If you need the
3489 // items in sorted order, use zhashx_keys() and then zlistx_sort(). To
4175 // zhashx_first() to process all items in a hash table. If you need the
4176 // items in sorted order, use zhashx_keys() and then zlistx_sort(). To
34904177 // access the key for this item use zhashx_cursor(). NOTE: do NOT modify
3491 // the table while iterating.
4178 // the table while iterating.
34924179 CZMQ_EXPORT void *
34934180 zhashx_next (zhashx_t *self);
34944181
34954182 // After a successful first/next method, returns the key for the item that
3496 // was returned. This is a constant string that you may not modify or
3497 // deallocate, and which lasts as long as the item in the hash. After an
3498 // unsuccessful first/next, returns NULL.
4183 // was returned. This is a constant string that you may not modify or
4184 // deallocate, and which lasts as long as the item in the hash. After an
4185 // unsuccessful first/next, returns NULL.
34994186 CZMQ_EXPORT const void *
35004187 zhashx_cursor (zhashx_t *self);
35014188
3502 // Add a comment to hash table before saving to disk. You can add as many
4189 // Add a comment to hash table before saving to disk. You can add as many
35034190 // comment lines as you like. These comment lines are discarded when loading
3504 // the file. If you use a null format, all comments are deleted.
4191 // the file. If you use a null format, all comments are deleted.
35054192 CZMQ_EXPORT void
35064193 zhashx_comment (zhashx_t *self, const char *format, ...) CHECK_PRINTF (2);
35074194
35084195 // Save hash table to a text file in name=value format. Hash values must be
3509 // printable strings; keys may not contain '=' character. Returns 0 if OK,
3510 // else -1 if a file error occurred.
4196 // printable strings; keys may not contain '=' character. Returns 0 if OK,
4197 // else -1 if a file error occurred.
35114198 CZMQ_EXPORT int
35124199 zhashx_save (zhashx_t *self, const char *filename);
35134200
3514 // Load hash table from a text file in name=value format; hash table must
4201 // Load hash table from a text file in name=value format; hash table must
35154202 // already exist. Hash values must printable strings; keys may not contain
3516 // '=' character. Returns 0 if OK, else -1 if a file was not readable.
4203 // '=' character. Returns 0 if OK, else -1 if a file was not readable.
35174204 CZMQ_EXPORT int
35184205 zhashx_load (zhashx_t *self, const char *filename);
35194206
35204207 // When a hash table was loaded from a file by zhashx_load, this method will
3521 // reload the file if it has been modified since, and is "stable", i.e. not
3522 // still changing. Returns 0 if OK, -1 if there was an error reloading the
3523 // file.
4208 // reload the file if it has been modified since, and is "stable", i.e. not
4209 // still changing. Returns 0 if OK, -1 if there was an error reloading the
4210 // file.
35244211 CZMQ_EXPORT int
35254212 zhashx_refresh (zhashx_t *self);
35264213
35274214 // Serialize hash table to a binary frame that can be sent in a message.
35284215 // The packed format is compatible with the 'dictionary' type defined in
3529 // http://rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
3530 //
3531 // ; A list of name/value pairs
3532 // dictionary = dict-count *( dict-name dict-value )
3533 // dict-count = number-4
3534 // dict-value = longstr
3535 // dict-name = string
3536 //
3537 // ; Strings are always length + text contents
3538 // longstr = number-4 *VCHAR
3539 // string = number-1 *VCHAR
3540 //
3541 // ; Numbers are unsigned integers in network byte order
3542 // number-1 = 1OCTET
3543 // number-4 = 4OCTET
3544 //
3545 // Comments are not included in the packed data. Item values MUST be
3546 // strings.
4216 // http://rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
4217 //
4218 // ; A list of name/value pairs
4219 // dictionary = dict-count *( dict-name dict-value )
4220 // dict-count = number-4
4221 // dict-value = longstr
4222 // dict-name = string
4223 //
4224 // ; Strings are always length + text contents
4225 // longstr = number-4 *VCHAR
4226 // string = number-1 *VCHAR
4227 //
4228 // ; Numbers are unsigned integers in network byte order
4229 // number-1 = 1OCTET
4230 // number-4 = 4OCTET
4231 //
4232 // Comments are not included in the packed data. Item values MUST be
4233 // strings.
35474234 // Caller owns return value and must destroy it when done.
35484235 CZMQ_EXPORT zframe_t *
35494236 zhashx_pack (zhashx_t *self);
35504237
3551 // Make a copy of the list; items are duplicated if you set a duplicator
3552 // for the list, otherwise not. Copying a null reference returns a null
3553 // reference. Note that this method's behavior changed slightly for CZMQ
4238 // Make a copy of the list; items are duplicated if you set a duplicator
4239 // for the list, otherwise not. Copying a null reference returns a null
4240 // reference. Note that this method's behavior changed slightly for CZMQ
35544241 // v3.x, as it does not set nor respect autofree. It does however let you
35554242 // duplicate any hash table safely. The old behavior is in zhashx_dup_v2.
35564243 // Caller owns return value and must destroy it when done.
35584245 zhashx_dup (zhashx_t *self);
35594246
35604247 // Set a user-defined deallocator for hash items; by default items are not
3561 // freed when the hash is destroyed.
4248 // freed when the hash is destroyed.
35624249 CZMQ_EXPORT void
35634250 zhashx_set_destructor (zhashx_t *self, zhashx_destructor_fn destructor);
35644251
35654252 // Set a user-defined duplicator for hash items; by default items are not
3566 // copied when the hash is duplicated.
4253 // copied when the hash is duplicated.
35674254 CZMQ_EXPORT void
35684255 zhashx_set_duplicator (zhashx_t *self, zhashx_duplicator_fn duplicator);
35694256
35704257 // Set a user-defined deallocator for keys; by default keys are freed
3571 // when the hash is destroyed using free().
4258 // when the hash is destroyed using free().
35724259 CZMQ_EXPORT void
35734260 zhashx_set_key_destructor (zhashx_t *self, zhashx_destructor_fn destructor);
35744261
35754262 // Set a user-defined duplicator for keys; by default keys are duplicated
3576 // using strdup.
4263 // using strdup.
35774264 CZMQ_EXPORT void
35784265 zhashx_set_key_duplicator (zhashx_t *self, zhashx_duplicator_fn duplicator);
35794266
35804267 // Set a user-defined comparator for keys; by default keys are
3581 // compared using strcmp.
4268 // compared using strcmp.
4269 // The callback function should return zero (0) on matching
4270 // items.
35824271 CZMQ_EXPORT void
35834272 zhashx_set_key_comparator (zhashx_t *self, zhashx_comparator_fn comparator);
35844273
3585 // Set a user-defined comparator for keys; by default keys are
3586 // compared using strcmp.
4274 // Set a user-defined hash function for keys; by default keys are
4275 // hashed by a modified Bernstein hashing function.
35874276 CZMQ_EXPORT void
35884277 zhashx_set_key_hasher (zhashx_t *self, zhashx_hash_fn hasher);
35894278
3590 // Make copy of hash table; if supplied table is null, returns null.
3591 // Does not copy items themselves. Rebuilds new table so may be slow on
4279 // Make copy of hash table; if supplied table is null, returns null.
4280 // Does not copy items themselves. Rebuilds new table so may be slow on
35924281 // very large tables. NOTE: only works with item values that are strings
3593 // since there's no other way to know how to duplicate the item value.
4282 // since there's no other way to know how to duplicate the item value.
35944283 CZMQ_EXPORT zhashx_t *
35954284 zhashx_dup_v2 (zhashx_t *self);
35964285
36014290 #ifdef CZMQ_BUILD_DRAFT_API
36024291 // *** Draft method, for development use, may change without warning ***
36034292 // Same as unpack but uses a user-defined deserializer function to convert
3604 // a longstr back into item format.
4293 // a longstr back into item format.
36054294 CZMQ_EXPORT zhashx_t *
36064295 zhashx_unpack_own (zframe_t *frame, zhashx_deserializer_fn deserializer);
36074296
36084297 // *** Draft method, for development use, may change without warning ***
36094298 // Same as pack but uses a user-defined serializer function to convert items
3610 // into longstr.
4299 // into longstr.
36114300 // Caller owns return value and must destroy it when done.
36124301 CZMQ_EXPORT zframe_t *
36134302 zhashx_pack_own (zhashx_t *self, zhashx_serializer_fn serializer);
37654454 srandom ((unsigned) time (NULL));
37664455 for (iteration = 0; iteration < 25000; iteration++) {
37674456 testnbr = randof (testmax);
4457 assert (testnbr != testmax);
4458 assert (testnbr < testmax);
37684459 if (testset [testnbr].exists) {
37694460 item = (char *) zhashx_lookup (hash, testset [testnbr].name);
37704461 assert (item);
37854476 zhashx_destroy (&hash);
37864477 zhashx_destroy (&hash);
37874478 assert (hash == NULL);
4479
4480 // Test randof() limits - should be within (0..testmax)
4481 // and randomness distribution - should not have (many) zero-counts
4482 // If there are - maybe the ZSYS_RANDOF_MAX is too big for this platform
4483 // Note: This test can take a while on systems with weak floating point HW
4484 testmax = 999;
4485 size_t rndcnt[999];
4486 assert ((sizeof (rndcnt)/sizeof(rndcnt[0])) == testmax);
4487 memset (rndcnt, 0, sizeof (rndcnt));
4488 for (iteration = 0; iteration < 10000000; iteration++) {
4489 testnbr = randof (testmax);
4490 assert (testnbr != testmax);
4491 assert (testnbr < testmax);
4492 assert (testnbr >= 0);
4493 rndcnt[testnbr]++;
4494 }
4495 int rndmisses = 0;
4496 for (iteration = 0; iteration < testmax; iteration++) {
4497 if (rndcnt[iteration] == 0) {
4498 zsys_warning("zhashx_test() : random distribution fault : got 0 hits for %d/%d",
4499 iteration, testmax);
4500 rndmisses++;
4501 }
4502 }
4503 // Too many misses are suspicious... we can lose half the entries
4504 // for each bit not used in the assumed ZSYS_RANDOF_MAX...
4505 assert ( (rndmisses < (testmax / 3 )) );
37884506
37894507 // Test destructor; automatically copies and frees string values
37904508 hash = zhashx_new ();
38264544 assert (streq ((char *) zhashx_lookup (hash, "key4"), "So say we all!"));
38274545 zhashx_purge (hash);
38284546 zhashx_destroy (&hash);
3829
4547
38304548 #if defined (__WINDOWS__)
38314549 zsys_shutdown();
38324550 #endif
38964614 #ifdef CZMQ_BUILD_DRAFT_API
38974615 // *** Draft method, for development use, may change without warning ***
38984616 // Get a list of network interfaces currently defined on the system
3899 // Includes IPv6 interfaces
4617 // Includes IPv6 interfaces
39004618 // Caller owns return value and must destroy it when done.
39014619 CZMQ_EXPORT ziflist_t *
39024620 ziflist_new_ipv6 (void);
39734691 zlist_destroy (zlist_t **self_p);
39744692
39754693 // Return the item at the head of list. If the list is empty, returns NULL.
3976 // Leaves cursor pointing at the head item, or NULL if the list is empty.
4694 // Leaves cursor pointing at the head item, or NULL if the list is empty.
39774695 CZMQ_EXPORT void *
39784696 zlist_first (zlist_t *self);
39794697
39804698 // Return the next item. If the list is empty, returns NULL. To move to
3981 // the start of the list call zlist_first (). Advances the cursor.
4699 // the start of the list call zlist_first (). Advances the cursor.
39824700 CZMQ_EXPORT void *
39834701 zlist_next (zlist_t *self);
39844702
39854703 // Return the item at the tail of list. If the list is empty, returns NULL.
3986 // Leaves cursor pointing at the tail item, or NULL if the list is empty.
4704 // Leaves cursor pointing at the tail item, or NULL if the list is empty.
39874705 CZMQ_EXPORT void *
39884706 zlist_last (zlist_t *self);
39894707
39954713 CZMQ_EXPORT void *
39964714 zlist_tail (zlist_t *self);
39974715
3998 // Return the current item of list. If the list is empty, returns NULL.
4716 // Return the current item of list. If the list is empty, returns NULL.
39994717 // Leaves cursor pointing at the current item, or NULL if the list is empty.
40004718 CZMQ_EXPORT void *
40014719 zlist_item (zlist_t *self);
40024720
4003 // Append an item to the end of the list, return 0 if OK or -1 if this
4721 // Append an item to the end of the list, return 0 if OK or -1 if this
40044722 // failed for some reason (out of memory). Note that if a duplicator has
4005 // been set, this method will also duplicate the item.
4723 // been set, this method will also duplicate the item.
40064724 CZMQ_EXPORT int
40074725 zlist_append (zlist_t *self, void *item);
40084726
4009 // Push an item to the start of the list, return 0 if OK or -1 if this
4727 // Push an item to the start of the list, return 0 if OK or -1 if this
40104728 // failed for some reason (out of memory). Note that if a duplicator has
4011 // been set, this method will also duplicate the item.
4729 // been set, this method will also duplicate the item.
40124730 CZMQ_EXPORT int
40134731 zlist_push (zlist_t *self, void *item);
40144732
40164734 CZMQ_EXPORT void *
40174735 zlist_pop (zlist_t *self);
40184736
4019 // Checks if an item already is present. Uses compare method to determine if
4737 // Checks if an item already is present. Uses compare method to determine if
40204738 // items are equal. If the compare method is NULL the check will only compare
4021 // pointers. Returns true if item is present else false.
4739 // pointers. Returns true if item is present else false.
40224740 CZMQ_EXPORT bool
40234741 zlist_exists (zlist_t *self, void *item);
40244742
40264744 CZMQ_EXPORT void
40274745 zlist_remove (zlist_t *self, void *item);
40284746
4029 // Make a copy of list. If the list has autofree set, the copied list will
4747 // Make a copy of list. If the list has autofree set, the copied list will
40304748 // duplicate all items, which must be strings. Otherwise, the list will hold
40314749 // pointers back to the items in the original list. If list is null, returns
4032 // NULL.
4750 // NULL.
40334751 // Caller owns return value and must destroy it when done.
40344752 CZMQ_EXPORT zlist_t *
40354753 zlist_dup (zlist_t *self);
40424760 CZMQ_EXPORT size_t
40434761 zlist_size (zlist_t *self);
40444762
4045 // Sort the list. If the compare function is null, sorts the list by
4046 // ascending key value using a straight ASCII comparison. If you specify
4763 // Sort the list. If the compare function is null, sorts the list by
4764 // ascending key value using a straight ASCII comparison. If you specify
40474765 // a compare function, this decides how items are sorted. The sort is not
40484766 // stable, so may reorder items with the same keys. The algorithm used is
4049 // combsort, a compromise between performance and simplicity.
4767 // combsort, a compromise between performance and simplicity.
40504768 CZMQ_EXPORT void
40514769 zlist_sort (zlist_t *self, zlist_compare_fn compare);
40524770
4053 // Set list for automatic item destruction; item values MUST be strings.
4054 // By default a list item refers to a value held elsewhere. When you set
4771 // Set list for automatic item destruction; item values MUST be strings.
4772 // By default a list item refers to a value held elsewhere. When you set
40554773 // this, each time you append or push a list item, zlist will take a copy
40564774 // of the string value. Then, when you destroy the list, it will free all
4057 // item values automatically. If you use any other technique to allocate
4775 // item values automatically. If you use any other technique to allocate
40584776 // list values, you must free them explicitly before destroying the list.
4059 // The usual technique is to pop list items and destroy them, until the
4060 // list is empty.
4777 // The usual technique is to pop list items and destroy them, until the
4778 // list is empty.
40614779 CZMQ_EXPORT void
40624780 zlist_autofree (zlist_t *self);
40634781
40644782 // Sets a compare function for this list. The function compares two items.
4065 // It returns an integer less than, equal to, or greater than zero if the
4066 // first item is found, respectively, to be less than, to match, or be
4067 // greater than the second item.
4068 // This function is used for sorting, removal and exists checking.
4783 // It returns an integer less than, equal to, or greater than zero if the
4784 // first item is found, respectively, to be less than, to match, or be
4785 // greater than the second item.
4786 // This function is used for sorting, removal and exists checking.
40694787 CZMQ_EXPORT void
40704788 zlist_comparefn (zlist_t *self, zlist_compare_fn fn);
40714789
4072 // Set a free function for the specified list item. When the item is
4073 // destroyed, the free function, if any, is called on that item.
4074 // Use this when list items are dynamically allocated, to ensure that
4790 // Set a free function for the specified list item. When the item is
4791 // destroyed, the free function, if any, is called on that item.
4792 // Use this when list items are dynamically allocated, to ensure that
40754793 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
4076 // Returns the item, or NULL if there is no such item.
4794 // Returns the item, or NULL if there is no such item.
40774795 CZMQ_EXPORT void *
40784796 zlist_freefn (zlist_t *self, void *item, zlist_free_fn fn, bool at_tail);
40794797
41984916 assert (streq ((const char *) zlist_first (list), bread));
41994917 item = (char *) zlist_pop (list);
42004918 assert (streq (item, bread));
4201 free (item);
4919 freen (item);
42024920 item = (char *) zlist_pop (list);
42034921 assert (streq (item, cheese));
4204 free (item);
4922 freen (item);
42054923
42064924 zlist_destroy (&list);
42074925 assert (list == NULL);
42444962 zlistx_new (void);
42454963
42464964 // Destroy a list. If an item destructor was specified, all items in the
4247 // list are automatically destroyed as well.
4965 // list are automatically destroyed as well.
42484966 CZMQ_EXPORT void
42494967 zlistx_destroy (zlistx_t **self_p);
42504968
42514969 // Add an item to the head of the list. Calls the item duplicator, if any,
4252 // on the item. Resets cursor to list head. Returns an item handle on
4253 // success, NULL if memory was exhausted.
4970 // on the item. Resets cursor to list head. Returns an item handle on
4971 // success, NULL if memory was exhausted.
42544972 CZMQ_EXPORT void *
42554973 zlistx_add_start (zlistx_t *self, void *item);
42564974
42574975 // Add an item to the tail of the list. Calls the item duplicator, if any,
4258 // on the item. Resets cursor to list head. Returns an item handle on
4259 // success, NULL if memory was exhausted.
4976 // on the item. Resets cursor to list head. Returns an item handle on
4977 // success, NULL if memory was exhausted.
42604978 CZMQ_EXPORT void *
42614979 zlistx_add_end (zlistx_t *self, void *item);
42624980
42734991 zlistx_tail (zlistx_t *self);
42744992
42754993 // Return the item at the head of list. If the list is empty, returns NULL.
4276 // Leaves cursor pointing at the head item, or NULL if the list is empty.
4994 // Leaves cursor pointing at the head item, or NULL if the list is empty.
42774995 CZMQ_EXPORT void *
42784996 zlistx_first (zlistx_t *self);
42794997
4280 // Return the next item. At the end of the list (or in an empty list),
4998 // Return the next item. At the end of the list (or in an empty list),
42814999 // returns NULL. Use repeated zlistx_next () calls to work through the list
4282 // from zlistx_first (). First time, acts as zlistx_first().
5000 // from zlistx_first (). First time, acts as zlistx_first().
42835001 CZMQ_EXPORT void *
42845002 zlistx_next (zlistx_t *self);
42855003
42865004 // Return the previous item. At the start of the list (or in an empty list),
4287 // returns NULL. Use repeated zlistx_prev () calls to work through the list
4288 // backwards from zlistx_last (). First time, acts as zlistx_last().
5005 // returns NULL. Use repeated zlistx_prev () calls to work through the list
5006 // backwards from zlistx_last (). First time, acts as zlistx_last().
42895007 CZMQ_EXPORT void *
42905008 zlistx_prev (zlistx_t *self);
42915009
42925010 // Return the item at the tail of list. If the list is empty, returns NULL.
4293 // Leaves cursor pointing at the tail item, or NULL if the list is empty.
5011 // Leaves cursor pointing at the tail item, or NULL if the list is empty.
42945012 CZMQ_EXPORT void *
42955013 zlistx_last (zlistx_t *self);
42965014
42975015 // Returns the value of the item at the cursor, or NULL if the cursor is
4298 // not pointing to an item.
5016 // not pointing to an item.
42995017 CZMQ_EXPORT void *
43005018 zlistx_item (zlistx_t *self);
43015019
43025020 // Returns the handle of the item at the cursor, or NULL if the cursor is
4303 // not pointing to an item.
5021 // not pointing to an item.
43045022 CZMQ_EXPORT void *
43055023 zlistx_cursor (zlistx_t *self);
43065024
4307 // Returns the item associated with the given list handle, or NULL if passed
5025 // Returns the item associated with the given list handle, or NULL if passed
43085026 // in handle is NULL. Asserts that the passed in handle points to a list element.
43095027 CZMQ_EXPORT void *
43105028 zlistx_handle_item (void *handle);
43115029
4312 // Find an item in the list, searching from the start. Uses the item
4313 // comparator, if any, else compares item values directly. Returns the
5030 // Find an item in the list, searching from the start. Uses the item
5031 // comparator, if any, else compares item values directly. Returns the
43145032 // item handle found, or NULL. Sets the cursor to the found item, if any.
43155033 CZMQ_EXPORT void *
43165034 zlistx_find (zlistx_t *self, void *item);
43175035
4318 // Detach an item from the list, using its handle. The item is not modified,
5036 // Detach an item from the list, using its handle. The item is not modified,
43195037 // and the caller is responsible for destroying it if necessary. If handle is
43205038 // null, detaches the first item on the list. Returns item that was detached,
43215039 // or null if none was. If cursor was at item, moves cursor to previous item,
4322 // so you can detach items while iterating forwards through a list.
5040 // so you can detach items while iterating forwards through a list.
43235041 CZMQ_EXPORT void *
43245042 zlistx_detach (zlistx_t *self, void *handle);
43255043
43265044 // Detach item at the cursor, if any, from the list. The item is not modified,
4327 // and the caller is responsible for destroying it as necessary. Returns item
4328 // that was detached, or null if none was. Moves cursor to previous item, so
4329 // you can detach items while iterating forwards through a list.
5045 // and the caller is responsible for destroying it as necessary. Returns item
5046 // that was detached, or null if none was. Moves cursor to previous item, so
5047 // you can detach items while iterating forwards through a list.
43305048 CZMQ_EXPORT void *
43315049 zlistx_detach_cur (zlistx_t *self);
43325050
4333 // Delete an item, using its handle. Calls the item destructor is any is
4334 // set. If handle is null, deletes the first item on the list. Returns 0
5051 // Delete an item, using its handle. Calls the item destructor is any is
5052 // set. If handle is null, deletes the first item on the list. Returns 0
43355053 // if an item was deleted, -1 if not. If cursor was at item, moves cursor
4336 // to previous item, so you can delete items while iterating forwards
4337 // through a list.
5054 // to previous item, so you can delete items while iterating forwards
5055 // through a list.
43385056 CZMQ_EXPORT int
43395057 zlistx_delete (zlistx_t *self, void *handle);
43405058
43475065 zlistx_move_end (zlistx_t *self, void *handle);
43485066
43495067 // Remove all items from the list, and destroy them if the item destructor
4350 // is set.
5068 // is set.
43515069 CZMQ_EXPORT void
43525070 zlistx_purge (zlistx_t *self);
43535071
4354 // Sort the list. If an item comparator was set, calls that to compare
5072 // Sort the list. If an item comparator was set, calls that to compare
43555073 // items, otherwise compares on item value. The sort is not stable, so may
4356 // reorder equal items.
5074 // reorder equal items.
43575075 CZMQ_EXPORT void
43585076 zlistx_sort (zlistx_t *self);
43595077
4360 // Create a new node and insert it into a sorted list. Calls the item
4361 // duplicator, if any, on the item. If low_value is true, starts searching
4362 // from the start of the list, otherwise searches from the end. Use the item
4363 // comparator, if any, to find where to place the new node. Returns a handle
5078 // Create a new node and insert it into a sorted list. Calls the item
5079 // duplicator, if any, on the item. If low_value is true, starts searching
5080 // from the start of the list, otherwise searches from the end. Use the item
5081 // comparator, if any, to find where to place the new node. Returns a handle
43645082 // to the new node, or NULL if memory was exhausted. Resets the cursor to the
4365 // list head.
5083 // list head.
43665084 CZMQ_EXPORT void *
43675085 zlistx_insert (zlistx_t *self, void *item, bool low_value);
43685086
4369 // Move an item, specified by handle, into position in a sorted list. Uses
5087 // Move an item, specified by handle, into position in a sorted list. Uses
43705088 // the item comparator, if any, to determine the new location. If low_value
43715089 // is true, starts searching from the start of the list, otherwise searches
4372 // from the end.
5090 // from the end.
43735091 CZMQ_EXPORT void
43745092 zlistx_reorder (zlistx_t *self, void *handle, bool low_value);
43755093
43765094 // Make a copy of the list; items are duplicated if you set a duplicator
4377 // for the list, otherwise not. Copying a null reference returns a null
4378 // reference.
5095 // for the list, otherwise not. Copying a null reference returns a null
5096 // reference.
43795097 CZMQ_EXPORT zlistx_t *
43805098 zlistx_dup (zlistx_t *self);
43815099
43825100 // Set a user-defined deallocator for list items; by default items are not
4383 // freed when the list is destroyed.
5101 // freed when the list is destroyed.
43845102 CZMQ_EXPORT void
43855103 zlistx_set_destructor (zlistx_t *self, zlistx_destructor_fn destructor);
43865104
43875105 // Set a user-defined duplicator for list items; by default items are not
4388 // copied when the list is duplicated.
5106 // copied when the list is duplicated.
43895107 CZMQ_EXPORT void
43905108 zlistx_set_duplicator (zlistx_t *self, zlistx_duplicator_fn duplicator);
43915109
4392 // Set a user-defined comparator for zlistx_find and zlistx_sort; the method
5110 // Set a user-defined comparator for zlistx_find and zlistx_sort; the method
43935111 // must return -1, 0, or 1 depending on whether item1 is less than, equal to,
4394 // or greater than, item2.
5112 // or greater than, item2.
43955113 CZMQ_EXPORT void
43965114 zlistx_set_comparator (zlistx_t *self, zlistx_comparator_fn comparator);
43975115
44445162 assert (zlistx_size (list) == 1);
44455163 char *string = (char *) zlistx_detach (list, NULL);
44465164 assert (streq (string, "world"));
4447 free (string);
5165 freen (string);
44485166 assert (zlistx_size (list) == 0);
44495167
44505168 // Check next/back work
45465264 CZMQ_EXPORT void
45475265 zloop_destroy (zloop_t **self_p);
45485266
4549 // Register socket reader with the reactor. When the reader has messages,
5267 // Register socket reader with the reactor. When the reader has messages,
45505268 // the reactor will call the handler, passing the arg. Returns 0 if OK, -1
4551 // if there was an error. If you register the same socket more than once,
4552 // each instance will invoke its corresponding handler.
5269 // if there was an error. If you register the same socket more than once,
5270 // each instance will invoke its corresponding handler.
45535271 CZMQ_EXPORT int
45545272 zloop_reader (zloop_t *self, zsock_t *sock, zloop_reader_fn handler, void *arg);
45555273
45565274 // Cancel a socket reader from the reactor. If multiple readers exist for
4557 // same socket, cancels ALL of them.
5275 // same socket, cancels ALL of them.
45585276 CZMQ_EXPORT void
45595277 zloop_reader_end (zloop_t *self, zsock_t *sock);
45605278
45615279 // Configure a registered reader to ignore errors. If you do not set this,
4562 // then readers that have errors are removed from the reactor silently.
5280 // then readers that have errors are removed from the reactor silently.
45635281 CZMQ_EXPORT void
45645282 zloop_reader_set_tolerant (zloop_t *self, zsock_t *sock);
45655283
4566 // Register low-level libzmq pollitem with the reactor. When the pollitem
4567 // is ready, will call the handler, passing the arg. Returns 0 if OK, -1
5284 // Register low-level libzmq pollitem with the reactor. When the pollitem
5285 // is ready, will call the handler, passing the arg. Returns 0 if OK, -1
45685286 // if there was an error. If you register the pollitem more than once, each
4569 // instance will invoke its corresponding handler. A pollitem with
4570 // socket=NULL and fd=0 means 'poll on FD zero'.
5287 // instance will invoke its corresponding handler. A pollitem with
5288 // socket=NULL and fd=0 means 'poll on FD zero'.
45715289 CZMQ_EXPORT int
45725290 zloop_poller (zloop_t *self, zmq_pollitem_t *item, zloop_fn handler, void *arg);
45735291
45745292 // Cancel a pollitem from the reactor, specified by socket or FD. If both
45755293 // are specified, uses only socket. If multiple poll items exist for same
4576 // socket/FD, cancels ALL of them.
5294 // socket/FD, cancels ALL of them.
45775295 CZMQ_EXPORT void
45785296 zloop_poller_end (zloop_t *self, zmq_pollitem_t *item);
45795297
45805298 // Configure a registered poller to ignore errors. If you do not set this,
4581 // then poller that have errors are removed from the reactor silently.
5299 // then poller that have errors are removed from the reactor silently.
45825300 CZMQ_EXPORT void
45835301 zloop_poller_set_tolerant (zloop_t *self, zmq_pollitem_t *item);
45845302
45855303 // Register a timer that expires after some delay and repeats some number of
4586 // times. At each expiry, will call the handler, passing the arg. To run a
5304 // times. At each expiry, will call the handler, passing the arg. To run a
45875305 // timer forever, use 0 times. Returns a timer_id that is used to cancel the
4588 // timer in the future. Returns -1 if there was an error.
5306 // timer in the future. Returns -1 if there was an error.
45895307 CZMQ_EXPORT int
45905308 zloop_timer (zloop_t *self, size_t delay, size_t times, zloop_timer_fn handler, void *arg);
45915309
45925310 // Cancel a specific timer identified by a specific timer_id (as returned by
4593 // zloop_timer).
5311 // zloop_timer).
45945312 CZMQ_EXPORT int
45955313 zloop_timer_end (zloop_t *self, int timer_id);
45965314
4597 // Register a ticket timer. Ticket timers are very fast in the case where
4598 // you use a lot of timers (thousands), and frequently remove and add them.
4599 // The main use case is expiry timers for servers that handle many clients,
5315 // Register a ticket timer. Ticket timers are very fast in the case where
5316 // you use a lot of timers (thousands), and frequently remove and add them.
5317 // The main use case is expiry timers for servers that handle many clients,
46005318 // and which reset the expiry timer for each message received from a client.
4601 // Whereas normal timers perform poorly as the number of clients grows, the
4602 // cost of ticket timers is constant, no matter the number of clients. You
4603 // must set the ticket delay using zloop_set_ticket_delay before creating a
4604 // ticket. Returns a handle to the timer that you should use in
4605 // zloop_ticket_reset and zloop_ticket_delete.
5319 // Whereas normal timers perform poorly as the number of clients grows, the
5320 // cost of ticket timers is constant, no matter the number of clients. You
5321 // must set the ticket delay using zloop_set_ticket_delay before creating a
5322 // ticket. Returns a handle to the timer that you should use in
5323 // zloop_ticket_reset and zloop_ticket_delete.
46065324 CZMQ_EXPORT void *
46075325 zloop_ticket (zloop_t *self, zloop_timer_fn handler, void *arg);
46085326
46095327 // Reset a ticket timer, which moves it to the end of the ticket list and
4610 // resets its execution time. This is a very fast operation.
5328 // resets its execution time. This is a very fast operation.
46115329 CZMQ_EXPORT void
46125330 zloop_ticket_reset (zloop_t *self, void *handle);
46135331
4614 // Delete a ticket timer. We do not actually delete the ticket here, as
5332 // Delete a ticket timer. We do not actually delete the ticket here, as
46155333 // other code may still refer to the ticket. We mark as deleted, and remove
4616 // later and safely.
5334 // later and safely.
46175335 CZMQ_EXPORT void
46185336 zloop_ticket_delete (zloop_t *self, void *handle);
46195337
4620 // Set the ticket delay, which applies to all tickets. If you lower the
5338 // Set the ticket delay, which applies to all tickets. If you lower the
46215339 // delay and there are already tickets created, the results are undefined.
46225340 CZMQ_EXPORT void
46235341 zloop_set_ticket_delay (zloop_t *self, size_t ticket_delay);
46245342
4625 // Set hard limit on number of timers allowed. Setting more than a small
5343 // Set hard limit on number of timers allowed. Setting more than a small
46265344 // number of timers (10-100) can have a dramatic impact on the performance
4627 // of the reactor. For high-volume cases, use ticket timers. If the hard
4628 // limit is reached, the reactor stops creating new timers and logs an
4629 // error.
5345 // of the reactor. For high-volume cases, use ticket timers. If the hard
5346 // limit is reached, the reactor stops creating new timers and logs an
5347 // error.
46305348 CZMQ_EXPORT void
46315349 zloop_set_max_timers (zloop_t *self, size_t max_timers);
46325350
46335351 // Set verbose tracing of reactor on/off. The default verbose setting is
4634 // off (false).
5352 // off (false).
46355353 CZMQ_EXPORT void
46365354 zloop_set_verbose (zloop_t *self, bool verbose);
46375355
4638 // By default the reactor stops if the process receives a SIGINT or SIGTERM
5356 // By default the reactor stops if the process receives a SIGINT or SIGTERM
46395357 // signal. This makes it impossible to shut-down message based architectures
46405358 // like zactors. This method lets you switch off break handling. The default
4641 // nonstop setting is off (false).
5359 // nonstop setting is off (false).
46425360 CZMQ_EXPORT void
46435361 zloop_set_nonstop (zloop_t *self, bool nonstop);
46445362
4645 // Start the reactor. Takes control of the thread and returns when the ØMQ
5363 // Start the reactor. Takes control of the thread and returns when the ØMQ
46465364 // context is terminated or the process is interrupted, or any event handler
4647 // returns -1. Event handlers may register new sockets and timers, and
4648 // cancel sockets. Returns 0 if interrupted, -1 if canceled by a handler.
5365 // returns -1. Event handlers may register new sockets and timers, and
5366 // cancel sockets. Returns 0 if interrupted, -1 if canceled by a handler.
46495367 CZMQ_EXPORT int
46505368 zloop_start (zloop_t *self);
46515369
48155533 #if defined (ZMQ_EVENT_HANDSHAKE_SUCCEED)
48165534 zstr_sendx (clientmon, "LISTEN", "HANDSHAKE_SUCCEED", NULL);
48175535 #endif
5536 #if defined (ZMQ_EVENT_HANDSHAKE_SUCCEEDED)
5537 zstr_sendx (clientmon, "LISTEN", "HANDSHAKE_SUCCEEDED", NULL);
5538 #endif
48185539 zstr_sendx (clientmon, "START", NULL);
48195540 zsock_wait (clientmon);
48205541
48455566 #if defined (ZMQ_EVENT_HANDSHAKE_SUCCEED)
48465567 s_assert_event (clientmon, "HANDSHAKE_SUCCEED");
48475568 #endif
5569 #if defined (ZMQ_EVENT_HANDSHAKE_SUCCEEDED)
5570 s_assert_event (clientmon, "HANDSHAKE_SUCCEEDED");
5571 #endif
48485572
48495573 zactor_destroy (&clientmon);
48505574 zactor_destroy (&servermon);
48775601 CZMQ_EXPORT zmsg_t *
48785602 zmsg_new (void);
48795603
4880 // Receive message from socket, returns zmsg_t object or NULL if the recv
4881 // was interrupted. Does a blocking recv. If you want to not block then use
5604 // Receive message from socket, returns zmsg_t object or NULL if the recv
5605 // was interrupted. Does a blocking recv. If you want to not block then use
48825606 // the zloop class or zmsg_recv_nowait or zmq_poll to check for socket input
4883 // before receiving.
5607 // before receiving.
48845608 CZMQ_EXPORT zmsg_t *
48855609 zmsg_recv (void *source);
48865610
48875611 // Load/append an open file into new message, return the message.
4888 // Returns NULL if the message could not be loaded.
5612 // Returns NULL if the message could not be loaded.
48895613 CZMQ_EXPORT zmsg_t *
48905614 zmsg_load (FILE *file);
48915615
48925616 // Decodes a serialized message frame created by zmsg_encode () and returns
4893 // a new zmsg_t object. Returns NULL if the frame was badly formatted or
4894 // there was insufficient memory to work.
5617 // a new zmsg_t object. Returns NULL if the frame was badly formatted or
5618 // there was insufficient memory to work.
48955619 CZMQ_EXPORT zmsg_t *
48965620 zmsg_decode (zframe_t *frame);
48975621
48985622 // Generate a signal message encoding the given status. A signal is a short
4899 // message carrying a 1-byte success/failure code (by convention, 0 means
4900 // OK). Signals are encoded to be distinguishable from "normal" messages.
5623 // message carrying a 1-byte success/failure code (by convention, 0 means
5624 // OK). Signals are encoded to be distinguishable from "normal" messages.
49015625 CZMQ_EXPORT zmsg_t *
49025626 zmsg_new_signal (byte status);
49035627
49075631
49085632 // Send message to destination socket, and destroy the message after sending
49095633 // it successfully. If the message has no frames, sends nothing but destroys
4910 // the message anyhow. Nullifies the caller's reference to the message (as
4911 // it is a destructor).
5634 // the message anyhow. Nullifies the caller's reference to the message (as
5635 // it is a destructor).
49125636 CZMQ_EXPORT int
49135637 zmsg_send (zmsg_t **self_p, void *dest);
49145638
4915 // Send message to destination socket as part of a multipart sequence, and
4916 // destroy the message after sending it successfully. Note that after a
5639 // Send message to destination socket as part of a multipart sequence, and
5640 // destroy the message after sending it successfully. Note that after a
49175641 // zmsg_sendm, you must call zmsg_send or another method that sends a final
4918 // message part. If the message has no frames, sends nothing but destroys
4919 // the message anyhow. Nullifies the caller's reference to the message (as
4920 // it is a destructor).
5642 // message part. If the message has no frames, sends nothing but destroys
5643 // the message anyhow. Nullifies the caller's reference to the message (as
5644 // it is a destructor).
49215645 CZMQ_EXPORT int
49225646 zmsg_sendm (zmsg_t **self_p, void *dest);
49235647
49295653 CZMQ_EXPORT size_t
49305654 zmsg_content_size (zmsg_t *self);
49315655
4932 // Push frame to the front of the message, i.e. before all other frames.
5656 // Push frame to the front of the message, i.e. before all other frames.
49335657 // Message takes ownership of frame, will destroy it when message is sent.
4934 // Returns 0 on success, -1 on error. Deprecates zmsg_push, which did not
4935 // nullify the caller's frame reference.
5658 // Returns 0 on success, -1 on error. Deprecates zmsg_push, which did not
5659 // nullify the caller's frame reference.
49365660 CZMQ_EXPORT int
49375661 zmsg_prepend (zmsg_t *self, zframe_t **frame_p);
49385662
4939 // Add frame to the end of the message, i.e. after all other frames.
5663 // Add frame to the end of the message, i.e. after all other frames.
49405664 // Message takes ownership of frame, will destroy it when message is sent.
4941 // Returns 0 on success. Deprecates zmsg_add, which did not nullify the
4942 // caller's frame reference.
5665 // Returns 0 on success. Deprecates zmsg_add, which did not nullify the
5666 // caller's frame reference.
49435667 CZMQ_EXPORT int
49445668 zmsg_append (zmsg_t *self, zframe_t **frame_p);
49455669
49495673 zmsg_pop (zmsg_t *self);
49505674
49515675 // Push block of memory to front of message, as a new frame.
4952 // Returns 0 on success, -1 on error.
5676 // Returns 0 on success, -1 on error.
49535677 CZMQ_EXPORT int
49545678 zmsg_pushmem (zmsg_t *self, const void *data, size_t size);
49555679
49565680 // Add block of memory to the end of the message, as a new frame.
4957 // Returns 0 on success, -1 on error.
5681 // Returns 0 on success, -1 on error.
49585682 CZMQ_EXPORT int
49595683 zmsg_addmem (zmsg_t *self, const void *data, size_t size);
49605684
49615685 // Push string as new frame to front of message.
4962 // Returns 0 on success, -1 on error.
5686 // Returns 0 on success, -1 on error.
49635687 CZMQ_EXPORT int
49645688 zmsg_pushstr (zmsg_t *self, const char *string);
49655689
49665690 // Push string as new frame to end of message.
4967 // Returns 0 on success, -1 on error.
5691 // Returns 0 on success, -1 on error.
49685692 CZMQ_EXPORT int
49695693 zmsg_addstr (zmsg_t *self, const char *string);
49705694
49715695 // Push formatted string as new frame to front of message.
4972 // Returns 0 on success, -1 on error.
5696 // Returns 0 on success, -1 on error.
49735697 CZMQ_EXPORT int
49745698 zmsg_pushstrf (zmsg_t *self, const char *format, ...) CHECK_PRINTF (2);
49755699
49765700 // Push formatted string as new frame to end of message.
4977 // Returns 0 on success, -1 on error.
5701 // Returns 0 on success, -1 on error.
49785702 CZMQ_EXPORT int
49795703 zmsg_addstrf (zmsg_t *self, const char *format, ...) CHECK_PRINTF (2);
49805704
49815705 // Pop frame off front of message, return as fresh string. If there were
4982 // no more frames in the message, returns NULL.
5706 // no more frames in the message, returns NULL.
49835707 // Caller owns return value and must destroy it when done.
49845708 CZMQ_EXPORT char *
49855709 zmsg_popstr (zmsg_t *self);
49865710
4987 // Push encoded message as a new frame. Message takes ownership of
5711 // Push encoded message as a new frame. Message takes ownership of
49885712 // submessage, so the original is destroyed in this call. Returns 0 on
4989 // success, -1 on error.
5713 // success, -1 on error.
49905714 CZMQ_EXPORT int
49915715 zmsg_addmsg (zmsg_t *self, zmsg_t **msg_p);
49925716
49935717 // Remove first submessage from message, if any. Returns zmsg_t, or NULL if
4994 // decoding was not successful.
5718 // decoding was not successful.
49955719 // Caller owns return value and must destroy it when done.
49965720 CZMQ_EXPORT zmsg_t *
49975721 zmsg_popmsg (zmsg_t *self);
50015725 zmsg_remove (zmsg_t *self, zframe_t *frame);
50025726
50035727 // Set cursor to first frame in message. Returns frame, or NULL, if the
5004 // message is empty. Use this to navigate the frames as a list.
5728 // message is empty. Use this to navigate the frames as a list.
50055729 CZMQ_EXPORT zframe_t *
50065730 zmsg_first (zmsg_t *self);
50075731
50085732 // Return the next frame. If there are no more frames, returns NULL. To move
5009 // to the first frame call zmsg_first(). Advances the cursor.
5733 // to the first frame call zmsg_first(). Advances the cursor.
50105734 CZMQ_EXPORT zframe_t *
50115735 zmsg_next (zmsg_t *self);
50125736
50145738 CZMQ_EXPORT zframe_t *
50155739 zmsg_last (zmsg_t *self);
50165740
5017 // Save message to an open file, return 0 if OK, else -1. The message is
5018 // saved as a series of frames, each with length and data. Note that the
5019 // file is NOT guaranteed to be portable between operating systems, not
5741 // Save message to an open file, return 0 if OK, else -1. The message is
5742 // saved as a series of frames, each with length and data. Note that the
5743 // file is NOT guaranteed to be portable between operating systems, not
50205744 // versions of CZMQ. The file format is at present undocumented and liable
5021 // to arbitrary change.
5745 // to arbitrary change.
50225746 CZMQ_EXPORT int
50235747 zmsg_save (zmsg_t *self, FILE *file);
50245748
50255749 // Serialize multipart message to a single message frame. Use this method
5026 // to send structured messages across transports that do not support
5027 // multipart data. Allocates and returns a new frame containing the
5028 // serialized message. To decode a serialized message frame, use
5029 // zmsg_decode ().
5750 // to send structured messages across transports that do not support
5751 // multipart data. Allocates and returns a new frame containing the
5752 // serialized message. To decode a serialized message frame, use
5753 // zmsg_decode ().
50305754 // Caller owns return value and must destroy it when done.
50315755 CZMQ_EXPORT zframe_t *
50325756 zmsg_encode (zmsg_t *self);
50335757
50345758 // Create copy of message, as new message object. Returns a fresh zmsg_t
5035 // object. If message is null, or memory was exhausted, returns null.
5759 // object. If message is null, or memory was exhausted, returns null.
50365760 // Caller owns return value and must destroy it when done.
50375761 CZMQ_EXPORT zmsg_t *
50385762 zmsg_dup (zmsg_t *self);
50395763
50405764 // Send message to zsys log sink (may be stdout, or system facility as
5041 // configured by zsys_set_logstream).
5765 // configured by zsys_set_logstream).
50425766 CZMQ_EXPORT void
50435767 zmsg_print (zmsg_t *self);
50445768
5045 // Return true if the two messages have the same number of frames and each
5769 // Return true if the two messages have the same number of frames and each
50465770 // frame in the first message is identical to the corresponding frame in the
50475771 // other message. As with zframe_eq, return false if either message is NULL.
50485772 CZMQ_EXPORT bool
50635787 #ifdef CZMQ_BUILD_DRAFT_API
50645788 // *** Draft method, for development use, may change without warning ***
50655789 // Return message routing ID, if the message came from a ZMQ_SERVER socket.
5066 // Else returns zero.
5790 // Else returns zero.
50675791 CZMQ_EXPORT uint32_t
50685792 zmsg_routing_id (zmsg_t *self);
50695793
50705794 // *** Draft method, for development use, may change without warning ***
50715795 // Set routing ID on message. This is used if/when the message is sent to a
5072 // ZMQ_SERVER socket.
5796 // ZMQ_SERVER socket.
50735797 CZMQ_EXPORT void
50745798 zmsg_set_routing_id (zmsg_t *self, uint32_t routing_id);
50755799
51915915 assert (zmsg_size (msg) == 3);
51925916 char *body = zmsg_popstr (msg);
51935917 assert (streq (body, "Frame0"));
5194 free (body);
5918 freen (body);
51955919 zmsg_destroy (&msg);
51965920
51975921 // Test encoding/decoding
52175941 assert (rc == 0);
52185942 rc = zmsg_addmem (msg, blank, 65537);
52195943 assert (rc == 0);
5220 free (blank);
5944 freen (blank);
52215945 assert (zmsg_size (msg) == 9);
52225946 frame = zmsg_encode (msg);
52235947 zmsg_destroy (&msg);
52415965 assert (submsg);
52425966 body = zmsg_popstr (submsg);
52435967 assert (streq (body, "joska"));
5244 free (body);
5968 freen (body);
52455969 zmsg_destroy (&submsg);
52465970 frame = zmsg_pop (msg);
52475971 assert (frame == NULL);
53846108 ```h
53856109 // This is a stable class, and may not change except for emergencies. It
53866110 // is provided in stable builds.
5387 // Create new poller, specifying zero or more readers. The list of
6111 // Create new poller, specifying zero or more readers. The list of
53886112 // readers ends in a NULL. Each reader can be a zsock_t instance, a
5389 // zactor_t instance, a libzmq socket (void *), or a file handle.
6113 // zactor_t instance, a libzmq socket (void *), or a file handle.
53906114 CZMQ_EXPORT zpoller_t *
53916115 zpoller_new (void *reader, ...);
53926116
53956119 zpoller_destroy (zpoller_t **self_p);
53966120
53976121 // Add a reader to be polled. Returns 0 if OK, -1 on failure. The reader may
5398 // be a libzmq void * socket, a zsock_t instance, or a zactor_t instance.
6122 // be a libzmq void * socket, a zsock_t instance, or a zactor_t instance.
53996123 CZMQ_EXPORT int
54006124 zpoller_add (zpoller_t *self, void *reader);
54016125
54026126 // Remove a reader from the poller; returns 0 if OK, -1 on failure. The reader
5403 // must have been passed during construction, or in an zpoller_add () call.
6127 // must have been passed during construction, or in an zpoller_add () call.
54046128 CZMQ_EXPORT int
54056129 zpoller_remove (zpoller_t *self, void *reader);
54066130
5407 // By default the poller stops if the process receives a SIGINT or SIGTERM
6131 // By default the poller stops if the process receives a SIGINT or SIGTERM
54086132 // signal. This makes it impossible to shut-down message based architectures
54096133 // like zactors. This method lets you switch off break handling. The default
5410 // nonstop setting is off (false).
6134 // nonstop setting is off (false).
54116135 CZMQ_EXPORT void
54126136 zpoller_set_nonstop (zpoller_t *self, bool nonstop);
54136137
5414 // Poll the registered readers for I/O, return first reader that has input.
5415 // The reader will be a libzmq void * socket, or a zsock_t or zactor_t
5416 // instance as specified in zpoller_new/zpoller_add. The timeout should be
5417 // zero or greater, or -1 to wait indefinitely. Socket priority is defined
5418 // by their order in the poll list. If you need a balanced poll, use the low
6138 // Poll the registered readers for I/O, return first reader that has input.
6139 // The reader will be a libzmq void * socket, or a zsock_t or zactor_t
6140 // instance as specified in zpoller_new/zpoller_add. The timeout should be
6141 // zero or greater, or -1 to wait indefinitely. Socket priority is defined
6142 // by their order in the poll list. If you need a balanced poll, use the low
54196143 // level zmq_poll method directly. If the poll call was interrupted (SIGINT),
5420 // or the ZMQ context was destroyed, or the timeout expired, returns NULL.
5421 // You can test the actual exit condition by calling zpoller_expired () and
5422 // zpoller_terminated (). The timeout is in msec.
6144 // or the ZMQ context was destroyed, or the timeout expired, returns NULL.
6145 // You can test the actual exit condition by calling zpoller_expired () and
6146 // zpoller_terminated (). The timeout is in msec.
54236147 CZMQ_EXPORT void *
54246148 zpoller_wait (zpoller_t *self, int timeout);
54256149
54266150 // Return true if the last zpoller_wait () call ended because the timeout
5427 // expired, without any error.
6151 // expired, without any error.
54286152 CZMQ_EXPORT bool
54296153 zpoller_expired (zpoller_t *self);
54306154
54316155 // Return true if the last zpoller_wait () call ended because the process
5432 // was interrupted, or the parent context was destroyed.
6156 // was interrupted, or the parent context was destroyed.
54336157 CZMQ_EXPORT bool
54346158 zpoller_terminated (zpoller_t *self);
54356159
55746298 |zmq://stdin |zmq://stdout |zmq://stderr |
55756299 | [zproc supervisor] |
55766300 +----------------------------------------+
5577
6301
55786302 ----------> zeromq magic here <-----------
55796303
55806304 +----------------------------------------+
55966320 // for it to be pushed to stable state. Use --enable-drafts to enable.
55976321 #ifdef CZMQ_BUILD_DRAFT_API
55986322 // *** Draft method, for development use, may change without warning ***
5599 // Create a new zproc.
6323 // Create a new zproc.
56006324 // NOTE: On Windows and with libzmq3 and libzmq2 this function
5601 // returns NULL. Code needs to be ported there.
6325 // returns NULL. Code needs to be ported there.
56026326 CZMQ_EXPORT zproc_t *
56036327 zproc_new (void);
56046328
56086332 zproc_destroy (zproc_t **self_p);
56096333
56106334 // *** Draft method, for development use, may change without warning ***
6335 // Return command line arguments (the first item is the executable) or
6336 // NULL if not set.
6337 // Caller owns return value and must destroy it when done.
6338 CZMQ_EXPORT zlist_t *
6339 zproc_args (zproc_t *self);
6340
6341 // *** Draft method, for development use, may change without warning ***
56116342 // Setup the command line arguments, the first item must be an (absolute) filename
5612 // to run.
5613 CZMQ_EXPORT void
5614 zproc_set_args (zproc_t *self, zlistx_t *args);
6343 // to run.
6344 CZMQ_EXPORT void
6345 zproc_set_args (zproc_t *self, zlist_t **arguments);
6346
6347 // *** Draft method, for development use, may change without warning ***
6348 // Setup the command line arguments, the first item must be an (absolute) filename
6349 // to run. Variadic function, must be NULL terminated.
6350 CZMQ_EXPORT void
6351 zproc_set_argsx (zproc_t *self, const char *arguments, ...);
56156352
56166353 // *** Draft method, for development use, may change without warning ***
56176354 // Setup the environment variables for the process.
56186355 CZMQ_EXPORT void
5619 zproc_set_env (zproc_t *self, zhashx_t *args);
6356 zproc_set_env (zproc_t *self, zhash_t **arguments);
56206357
56216358 // *** Draft method, for development use, may change without warning ***
56226359 // Connects process stdin with a readable ('>', connect) zeromq socket. If
5623 // socket argument is NULL, zproc creates own managed pair of inproc
5624 // sockets. The writable one is then accessbile via zproc_stdin method.
6360 // socket argument is NULL, zproc creates own managed pair of inproc
6361 // sockets. The writable one is then accessbile via zproc_stdin method.
56256362 CZMQ_EXPORT void
56266363 zproc_set_stdin (zproc_t *self, void *socket);
56276364
56286365 // *** Draft method, for development use, may change without warning ***
5629 // Connects process stdout with a writable ('@', bind) zeromq socket. If
5630 // socket argument is NULL, zproc creates own managed pair of inproc
6366 // Connects process stdout with a writable ('@', bind) zeromq socket. If
6367 // socket argument is NULL, zproc creates own managed pair of inproc
56316368 // sockets. The readable one is then accessbile via zproc_stdout method.
56326369 CZMQ_EXPORT void
56336370 zproc_set_stdout (zproc_t *self, void *socket);
56346371
56356372 // *** Draft method, for development use, may change without warning ***
5636 // Connects process stderr with a writable ('@', bind) zeromq socket. If
5637 // socket argument is NULL, zproc creates own managed pair of inproc
6373 // Connects process stderr with a writable ('@', bind) zeromq socket. If
6374 // socket argument is NULL, zproc creates own managed pair of inproc
56386375 // sockets. The readable one is then accessbile via zproc_stderr method.
56396376 CZMQ_EXPORT void
56406377 zproc_set_stderr (zproc_t *self, void *socket);
56416378
56426379 // *** Draft method, for development use, may change without warning ***
56436380 // Return subprocess stdin writable socket. NULL for
5644 // not initialized or external sockets.
6381 // not initialized or external sockets.
56456382 CZMQ_EXPORT void *
56466383 zproc_stdin (zproc_t *self);
56476384
56486385 // *** Draft method, for development use, may change without warning ***
56496386 // Return subprocess stdout readable socket. NULL for
5650 // not initialized or external sockets.
6387 // not initialized or external sockets.
56516388 CZMQ_EXPORT void *
56526389 zproc_stdout (zproc_t *self);
56536390
56546391 // *** Draft method, for development use, may change without warning ***
56556392 // Return subprocess stderr readable socket. NULL for
5656 // not initialized or external sockets.
6393 // not initialized or external sockets.
56576394 CZMQ_EXPORT void *
56586395 zproc_stderr (zproc_t *self);
56596396
56606397 // *** Draft method, for development use, may change without warning ***
5661 // Starts the process.
6398 // Starts the process, return just before execve/CreateProcess.
56626399 CZMQ_EXPORT int
56636400 zproc_run (zproc_t *self);
56646401
56836420 zproc_wait (zproc_t *self, bool hang);
56846421
56856422 // *** Draft method, for development use, may change without warning ***
5686 // return internal actor, usefull for the polling if process died
6423 // return internal actor, useful for the polling if process died
56876424 CZMQ_EXPORT void *
56886425 zproc_actor (zproc_t *self);
56896426
56966433 // set verbose mode
56976434 CZMQ_EXPORT void
56986435 zproc_set_verbose (zproc_t *self, bool verbose);
5699
5700 // *** Draft method, for development use, may change without warning ***
5701 // Returns CZMQ version as a single 6-digit integer encoding the major
5702 // version (x 10000), the minor version (x 100) and the patch.
5703 CZMQ_EXPORT int
5704 zproc_czmq_version (void);
5705
5706 // *** Draft method, for development use, may change without warning ***
5707 // Returns true if the process received a SIGINT or SIGTERM signal.
5708 // It is good practice to use this method to exit any infinite loop
5709 // processing messages.
5710 CZMQ_EXPORT bool
5711 zproc_interrupted (void);
5712
5713 // *** Draft method, for development use, may change without warning ***
5714 // Returns true if the underlying libzmq supports CURVE security.
5715 CZMQ_EXPORT bool
5716 zproc_has_curve (void);
5717
5718 // *** Draft method, for development use, may change without warning ***
5719 // Return current host name, for use in public tcp:// endpoints.
5720 // If the host name is not resolvable, returns NULL.
5721 // Caller owns return value and must destroy it when done.
5722 CZMQ_EXPORT char *
5723 zproc_hostname (void);
5724
5725 // *** Draft method, for development use, may change without warning ***
5726 // Move the current process into the background. The precise effect
5727 // depends on the operating system. On POSIX boxes, moves to a specified
5728 // working directory (if specified), closes all file handles, reopens
5729 // stdin, stdout, and stderr to the null device, and sets the process to
5730 // ignore SIGHUP. On Windows, does nothing. Returns 0 if OK, -1 if there
5731 // was an error.
5732 CZMQ_EXPORT void
5733 zproc_daemonize (const char *workdir);
5734
5735 // *** Draft method, for development use, may change without warning ***
5736 // Drop the process ID into the lockfile, with exclusive lock, and
5737 // switch the process to the specified group and/or user. Any of the
5738 // arguments may be null, indicating a no-op. Returns 0 on success,
5739 // -1 on failure. Note if you combine this with zsys_daemonize, run
5740 // after, not before that method, or the lockfile will hold the wrong
5741 // process ID.
5742 CZMQ_EXPORT void
5743 zproc_run_as (const char *lockfile, const char *group, const char *user);
5744
5745 // *** Draft method, for development use, may change without warning ***
5746 // Configure the number of I/O threads that ZeroMQ will use. A good
5747 // rule of thumb is one thread per gigabit of traffic in or out. The
5748 // default is 1, sufficient for most applications. If the environment
5749 // variable ZSYS_IO_THREADS is defined, that provides the default.
5750 // Note that this method is valid only before any socket is created.
5751 CZMQ_EXPORT void
5752 zproc_set_io_threads (size_t io_threads);
5753
5754 // *** Draft method, for development use, may change without warning ***
5755 // Configure the number of sockets that ZeroMQ will allow. The default
5756 // is 1024. The actual limit depends on the system, and you can query it
5757 // by using zsys_socket_limit (). A value of zero means "maximum".
5758 // Note that this method is valid only before any socket is created.
5759 CZMQ_EXPORT void
5760 zproc_set_max_sockets (size_t max_sockets);
5761
5762 // *** Draft method, for development use, may change without warning ***
5763 // Set network interface name to use for broadcasts, particularly zbeacon.
5764 // This lets the interface be configured for test environments where required.
5765 // For example, on Mac OS X, zbeacon cannot bind to 255.255.255.255 which is
5766 // the default when there is no specified interface. If the environment
5767 // variable ZSYS_INTERFACE is set, use that as the default interface name.
5768 // Setting the interface to "*" means "use all available interfaces".
5769 CZMQ_EXPORT void
5770 zproc_set_biface (const char *value);
5771
5772 // *** Draft method, for development use, may change without warning ***
5773 // Return network interface to use for broadcasts, or "" if none was set.
5774 CZMQ_EXPORT const char *
5775 zproc_biface (void);
5776
5777 // *** Draft method, for development use, may change without warning ***
5778 // Set log identity, which is a string that prefixes all log messages sent
5779 // by this process. The log identity defaults to the environment variable
5780 // ZSYS_LOGIDENT, if that is set.
5781 CZMQ_EXPORT void
5782 zproc_set_log_ident (const char *value);
5783
5784 // *** Draft method, for development use, may change without warning ***
5785 // Sends log output to a PUB socket bound to the specified endpoint. To
5786 // collect such log output, create a SUB socket, subscribe to the traffic
5787 // you care about, and connect to the endpoint. Log traffic is sent as a
5788 // single string frame, in the same format as when sent to stdout. The
5789 // log system supports a single sender; multiple calls to this method will
5790 // bind the same sender to multiple endpoints. To disable the sender, call
5791 // this method with a null argument.
5792 CZMQ_EXPORT void
5793 zproc_set_log_sender (const char *endpoint);
5794
5795 // *** Draft method, for development use, may change without warning ***
5796 // Enable or disable logging to the system facility (syslog on POSIX boxes,
5797 // event log on Windows). By default this is disabled.
5798 CZMQ_EXPORT void
5799 zproc_set_log_system (bool logsystem);
5800
5801 // *** Draft method, for development use, may change without warning ***
5802 // Log error condition - highest priority
5803 CZMQ_EXPORT void
5804 zproc_log_error (const char *format, ...) CHECK_PRINTF (1);
5805
5806 // *** Draft method, for development use, may change without warning ***
5807 // Log warning condition - high priority
5808 CZMQ_EXPORT void
5809 zproc_log_warning (const char *format, ...) CHECK_PRINTF (1);
5810
5811 // *** Draft method, for development use, may change without warning ***
5812 // Log normal, but significant, condition - normal priority
5813 CZMQ_EXPORT void
5814 zproc_log_notice (const char *format, ...) CHECK_PRINTF (1);
5815
5816 // *** Draft method, for development use, may change without warning ***
5817 // Log informational message - low priority
5818 CZMQ_EXPORT void
5819 zproc_log_info (const char *format, ...) CHECK_PRINTF (1);
5820
5821 // *** Draft method, for development use, may change without warning ***
5822 // Log debug-level message - lowest priority
5823 CZMQ_EXPORT void
5824 zproc_log_debug (const char *format, ...) CHECK_PRINTF (1);
58256436
58266437 // *** Draft method, for development use, may change without warning ***
58276438 // Self test of this class.
58356446 This is the class self test code:
58366447
58376448 ```c
6449
6450 // variable file contains path to zsp executable:
6451 // char *file = "path/to/zsp";
6452
58386453 #if defined (__WINDOWS__)
5839 printf ("SKIPPED (on Windows)\n");
6454 printf ("Very limited (on Windows) ");
6455 {
6456 zsys_init ();
6457 zproc_t *self = zproc_new ();
6458 assert (self);
6459
6460 zproc_set_verbose (self, verbose);
6461 zproc_set_argsx (self, file, "-v", NULL);
6462 zproc_run (self);
6463 zclock_sleep (100); // to let actor start the process
6464 assert (zproc_pid (self));
6465
6466 zproc_kill (self, SIGTERM);
6467 assert (zproc_returncode (self) == 255);
6468 zproc_destroy (&self);
6469 }
6470 printf ("OK\n");
58406471 return;
58416472 #endif
5842 #if ZMQ_VERSION_MAJOR < 4
5843 printf ("SKIPPED (on zmq pre-4)\n");
5844 return;
5845 #endif
5846 int major, minor, patch;
5847 zsys_version (&major, &minor, &patch);
5848 if (major < 4) {
5849 printf ("SKIPPED (on zmq pre-4)\n");
5850 return;
5851 }
5852
5853 // @selftest
5854 // 0. initialization
5855 // find the right binary
5856 char *file = "src/zsp";
5857 if (zsys_file_exists ("_build/../src/zsp"))
5858 file = "_build/../src/zsp";
5859 else
5860 if (zsys_file_exists ("zsp"))
5861 file = "./zsp";
5862
5863 if (!zsys_file_exists (file)) {
5864 zsys_warning ("cannot detect zsp binary, %s does not exists", file);
5865 printf ("SKIPPED (zsp not found");
5866 return;
5867 }
5868
5869 // Create new subproc instance
6473 // Test case #1: run command, wait until it ends and get the (stdandard) output
58706474 zproc_t *self = zproc_new ();
6475 assert (self);
6476 zproc_set_verbose (self, verbose);
6477
6478 // join stdout of the process to zeromq socket
6479 // all data will be readable from zproc_stdout socket
6480 assert (!zproc_stdout (self));
6481 zproc_set_stdout (self, NULL);
6482 assert (zproc_stdout (self));
6483
6484 zproc_set_argsx (self, file, "--help", NULL);
6485
6486 if (verbose)
6487 zsys_debug("zproc_test() : launching helper '%s' --help", file );
6488
6489 int r = zproc_run (self);
6490 assert (r == 0);
6491 zframe_t *frame;
6492 zsock_brecv (zproc_stdout (self), "f", &frame);
6493 assert (frame);
6494 assert (zframe_data (frame));
6495 // TODO: real test
6496 if (verbose)
6497 zframe_print (frame, "1:");
6498 zframe_destroy (&frame);
6499 r = zproc_wait (self, true);
6500 assert (r == 0);
6501 zproc_destroy (&self);
6502
6503 // Test case #2: use never ending subprocess and poller to read data from it
6504 // Create new zproc instance
6505 self = zproc_new ();
58716506 zproc_set_verbose (self, verbose);
58726507 assert (self);
58736508 // join stdout of the process to zeromq socket
58746509 // all data will be readable from zproc_stdout socket
58756510 zproc_set_stdout (self, NULL);
58766511
5877 zlistx_t *args = zlistx_new ();
5878 zlistx_add_end (args, file);
5879 zlistx_add_end (args, "--stdout");
5880 zproc_set_args (self, args);
5881
5882 zhashx_t *env = zhashx_new ();
5883 zhashx_insert (env, "ZSP_MESSAGE", "czmq is great\n");
5884 zproc_set_env (self, env);
6512 zlist_t *args = zlist_new ();
6513 zlist_autofree (args);
6514 zlist_append (args, file);
6515 zlist_append (args, "--stdout");
6516 zproc_set_args (self, &args);
6517
6518 zhash_t *env = zhash_new ();
6519 zhash_autofree (env);
6520 zhash_insert (env, "ZSP_MESSAGE", "czmq is great\n");
6521 zproc_set_env (self, &env);
58856522
58866523 // execute the binary. It runs in own actor, which monitor the process and
58876524 // pass data accross pipes and zeromq sockets
6525 if (verbose)
6526 zsys_debug("zproc_test() : launching helper '%s'", file );
58886527 zproc_run (self);
58896528 zpoller_t *poller = zpoller_new (zproc_stdout (self), NULL);
58906529
5891 // kill the binary, it never ends, but the test must
5892 zclock_sleep (800);
6530 // kill the binary, it never ends, but the test must:
6531 // termination also flushes the output streams so we can
6532 // read them entirely; note that other process runs in
6533 // parallel to this thread
6534 if (verbose)
6535 zsys_debug("zproc_test() : sleeping 4000 msec to gather some output from helper");
6536 zclock_sleep (4000);
58936537 zproc_kill (self, SIGTERM);
58946538 zproc_wait (self, true);
58956539
58966540 // read the content from zproc_stdout - use zpoller and a loop
58976541 bool stdout_read = false;
6542 int64_t zproc_timeout_msec = 10000;
6543 int64_t zproc_test_start_msec = zclock_mono();
6544 int64_t zproc_test_elapsed_msec = 0;
6545
58986546 while (!zsys_interrupted) {
58996547 void *which = zpoller_wait (poller, 800);
5900
5901 if (!which)
6548 zproc_test_elapsed_msec = zclock_mono() - zproc_test_start_msec;
6549
6550 if (!which) {
6551 if (stdout_read) {
6552 if (verbose)
6553 zsys_debug("zproc_test() : did not get stdout from helper, but we already have some (%" PRIi64 " msec remaining to retry)", (zproc_timeout_msec - zproc_test_elapsed_msec) );
6554 break;
6555 }
6556 if (zproc_timeout_msec > zproc_test_elapsed_msec) {
6557 if (verbose)
6558 zsys_debug("zproc_test() : did not get stdout from helper, %" PRIi64 " msec remaining to retry", (zproc_timeout_msec - zproc_test_elapsed_msec) );
6559 continue;
6560 }
6561 // ...else : we've slept a lot and got no response; kill the helper
6562 if (verbose)
6563 zsys_debug("zproc_test() : did not get stdout from helper, patience expired (%" PRIi64 " msec remaining to retry)", (zproc_timeout_msec - zproc_test_elapsed_msec) );
59026564 break;
6565 }
59036566
59046567 if (which == zproc_stdout (self)) {
5905 stdout_read = true;
6568 // it suffices for us to have read something
6569 // we only check the first frame, others may start with the
6570 // expected key string broken mid-way due to alignment etc.,
6571 // but we drain the whole incoming queue of stdout frames.
59066572 zframe_t *frame;
59076573 zsock_brecv (zproc_stdout (self), "f", &frame);
5908 assert (!strncmp(
5909 "czmq is great\n",
5910 (char*) zframe_data (frame),
5911 14));
6574 assert (frame);
6575 assert (zframe_data (frame));
6576 if (!stdout_read) {
6577 if (verbose)
6578 zsys_debug("zproc_test() : got stdout from helper, %" PRIi64 " msec was remaining to retry", (zproc_timeout_msec - zproc_test_elapsed_msec));
6579 assert (!strncmp(
6580 "czmq is great\n",
6581 (char*) zframe_data (frame),
6582 14));
6583 stdout_read = true;
6584 }
59126585
59136586 if (verbose)
59146587 zframe_print (frame, "zproc_test");
59186591 }
59196592
59206593 // should not get there
6594 if (verbose)
6595 zsys_debug("zproc_test() : reached the unreachable point (unexpected zpoller result), %" PRIi64 " msec was remaining to retry", (zproc_timeout_msec - zproc_test_elapsed_msec) );
59216596 assert (false);
59226597 }
59236598
61026777 #ifdef WIN32
61036778 sink = zsock_new_sub(">inproc://backend", "whatever");
61046779 #else
6105 sink = zsock_new_sub (">ipc://backend", "whatever");
6780 // vagrant vms don't like using shared storage for ipc pipes..
6781 if (getenv("USER") && streq(getenv("USER"), "vagrant"))
6782 sink = zsock_new_sub (">ipc:///tmp/backend", "whatever");
6783 else
6784 sink = zsock_new_sub (">ipc://backend", "whatever");
61066785 #endif // WIN32
61076786 assert (sink);
61086787
61096788 #ifdef WIN32
61106789 zstr_sendx (proxy, "BACKEND", "XPUB", "inproc://backend", NULL);
61116790 #else
6112 zstr_sendx(proxy, "BACKEND", "XPUB", "ipc://backend", NULL);
6791 // vagrant vms don't like using shared storage for ipc pipes..
6792 if (getenv("USER") && streq(getenv("USER"), "vagrant"))
6793 zstr_sendx(proxy, "BACKEND", "XPUB", "ipc:///tmp/backend", NULL);
6794 else
6795 zstr_sendx(proxy, "BACKEND", "XPUB", "ipc://backend", NULL);
61136796 #endif
61146797 zsock_wait (proxy);
61156798
61186801
61196802 #if (ZMQ_VERSION_MAJOR == 4)
61206803 // Test authentication functionality
6121 # define TESTDIR ".test_zproxy"
6804 const char *basedirpath = "src/selftest-rw/.test_zproxy";
6805 const char *passfilepath = "src/selftest-rw/.test_zproxy/password-file";
6806 const char *certfilepath = "src/selftest-rw/.test_zproxy/mycert.txt";
6807
6808 // Make sure old aborted tests do not hinder us
6809 zdir_t *dir = zdir_new (basedirpath, NULL);
6810 if (dir) {
6811 zdir_remove (dir, true);
6812 zdir_destroy (&dir);
6813 }
6814 zsys_file_delete (passfilepath);
6815 zsys_file_delete (certfilepath);
6816 zsys_dir_delete (basedirpath);
61226817
61236818 // Create temporary directory for test files
6124 zsys_dir_create (TESTDIR);
6819 zsys_dir_create (basedirpath);
61256820
61266821 char *frontend = NULL;
61276822 char *backend = NULL;
61846879 // Test negative case (no server-side passwords defined)
61856880 zstr_sendx (proxy, "PLAIN", "FRONTEND", NULL);
61866881 zsock_wait (proxy);
6882 zstr_sendx (proxy, "DOMAIN", "FRONTEND", "global", NULL);
6883 zsock_wait (proxy);
61876884 s_bind_test_sockets (proxy, &frontend, &backend);
61886885 zsock_set_plain_username (faucet, "admin");
61896886 zsock_set_plain_password (faucet, "Password");
61926889 assert (!success);
61936890
61946891 // Test positive case (server-side passwords defined)
6195 FILE *password = fopen (TESTDIR "/password-file", "w");
6892 FILE *password = fopen (passfilepath, "w");
61966893 assert (password);
61976894 fprintf (password, "admin=Password\n");
61986895 fclose (password);
61996896 zstr_sendx (proxy, "PLAIN", "FRONTEND", NULL);
62006897 zsock_wait (proxy);
6898 zstr_sendx (proxy, "DOMAIN", "FRONTEND", "global", NULL);
6899 zsock_wait (proxy);
62016900 zstr_sendx (proxy, "PLAIN", "BACKEND", NULL);
6901 zsock_wait (proxy);
6902 zstr_sendx (proxy, "DOMAIN", "BACKEND", "global", NULL);
62026903 zsock_wait (proxy);
62036904 s_bind_test_sockets (proxy, &frontend, &backend);
62046905 zsock_set_plain_username (faucet, "admin");
62056906 zsock_set_plain_password (faucet, "Password");
62066907 zsock_set_plain_username (sink, "admin");
62076908 zsock_set_plain_password (sink, "Password");
6208 zstr_sendx (auth, "PLAIN", TESTDIR "/password-file", NULL);
6909 zstr_sendx (auth, "PLAIN", passfilepath, NULL);
62096910 zsock_wait (auth);
62106911 success = s_can_connect (&proxy, &faucet, &sink, frontend, backend, verbose,
62116912 true);
62136914
62146915 // Test negative case (bad client password)
62156916 zstr_sendx (proxy, "PLAIN", "FRONTEND", NULL);
6917 zsock_wait (proxy);
6918 zstr_sendx (proxy, "DOMAIN", "FRONTEND", "global", NULL);
62166919 zsock_wait (proxy);
62176920 s_bind_test_sockets (proxy, &frontend, &backend);
62186921 zsock_set_plain_username (faucet, "admin");
62356938
62366939 // Test without setting-up any authentication
62376940 zstr_sendx (proxy, "CURVE", "FRONTEND", public_key, secret_key, NULL);
6941 zsock_wait (proxy);
6942 zstr_sendx (proxy, "DOMAIN", "FRONTEND", "global", NULL);
62386943 zsock_wait (proxy);
62396944 s_bind_test_sockets (proxy, &frontend, &backend);
62406945 zcert_apply (client_cert, faucet);
62656970 zsock_set_curve_serverkey (faucet, public_key);
62666971 zcert_apply (client_cert, sink);
62676972 zsock_set_curve_serverkey (sink, public_key);
6268 zcert_save_public (client_cert, TESTDIR "/mycert.txt");
6269 zstr_sendx (auth, "CURVE", TESTDIR, NULL);
6973 zcert_save_public (client_cert, certfilepath);
6974 zstr_sendx (auth, "CURVE", basedirpath, NULL);
62706975 zsock_wait (auth);
62716976 success = s_can_connect (&proxy, &faucet, &sink, frontend, backend,
62726977 verbose, true);
62916996 zstr_free (&backend);
62926997
62936998 // Delete temporary directory and test files
6294 zsys_file_delete (TESTDIR "/password-file");
6295 zsys_file_delete (TESTDIR "/mycert.txt");
6296 zsys_dir_delete (TESTDIR);
6999 zsys_file_delete (passfilepath);
7000 zsys_file_delete (certfilepath);
7001 zsys_dir_delete (basedirpath);
62977002 #endif
62987003
62997004 #if defined (__WINDOWS__)
64617166 // This class has draft methods, which may change over time. They are not
64627167 // in stable releases, by default. Use --enable-drafts to enable.
64637168 // Create a new socket. Returns the new socket, or NULL if the new socket
6464 // could not be created. Note that the symbol zsock_new (and other
6465 // constructors/destructors for zsock) are redirected to the *_checked
6466 // variant, enabling intelligent socket leak detection. This can have
7169 // could not be created. Note that the symbol zsock_new (and other
7170 // constructors/destructors for zsock) are redirected to the *_checked
7171 // variant, enabling intelligent socket leak detection. This can have
64677172 // performance implications if you use a LOT of sockets. To turn off this
6468 // redirection behaviour, define ZSOCK_NOCHECK.
7173 // redirection behaviour, define ZSOCK_NOCHECK.
64697174 CZMQ_EXPORT zsock_t *
64707175 zsock_new (int type);
64717176
64747179 zsock_new_pub (const char *endpoint);
64757180
64767181 // Create a SUB socket, and optionally subscribe to some prefix string. Default
6477 // action is connect.
7182 // action is connect.
64787183 CZMQ_EXPORT zsock_t *
64797184 zsock_new_sub (const char *endpoint, const char *subscribe);
64807185
65197224 zsock_new_stream (const char *endpoint);
65207225
65217226 // Destroy the socket. You must use this for any socket created via the
6522 // zsock_new method.
7227 // zsock_new method.
65237228 CZMQ_EXPORT void
65247229 zsock_destroy (zsock_t **self_p);
65257230
6526 // Bind a socket to a formatted endpoint. For tcp:// endpoints, supports
6527 // ephemeral ports, if you specify the port number as "*". By default
6528 // zsock uses the IANA designated range from C000 (49152) to FFFF (65535).
6529 // To override this range, follow the "*" with "[first-last]". Either or
6530 // both first and last may be empty. To bind to a random port within the
6531 // range, use "!" in place of "*".
6532 //
6533 // Examples:
6534 // tcp://127.0.0.1:* bind to first free port from C000 up
6535 // tcp://127.0.0.1:! bind to random port from C000 to FFFF
6536 // tcp://127.0.0.1:*[60000-] bind to first free port from 60000 up
6537 // tcp://127.0.0.1:![-60000] bind to random port from C000 to 60000
6538 // tcp://127.0.0.1:![55000-55999]
6539 // bind to random port from 55000 to 55999
6540 //
6541 // On success, returns the actual port number used, for tcp:// endpoints,
7231 // Bind a socket to a formatted endpoint. For tcp:// endpoints, supports
7232 // ephemeral ports, if you specify the port number as "*". By default
7233 // zsock uses the IANA designated range from C000 (49152) to FFFF (65535).
7234 // To override this range, follow the "*" with "[first-last]". Either or
7235 // both first and last may be empty. To bind to a random port within the
7236 // range, use "!" in place of "*".
7237 //
7238 // Examples:
7239 // tcp://127.0.0.1:* bind to first free port from C000 up
7240 // tcp://127.0.0.1:! bind to random port from C000 to FFFF
7241 // tcp://127.0.0.1:*[60000-] bind to first free port from 60000 up
7242 // tcp://127.0.0.1:![-60000] bind to random port from C000 to 60000
7243 // tcp://127.0.0.1:![55000-55999]
7244 // bind to random port from 55000 to 55999
7245 //
7246 // On success, returns the actual port number used, for tcp:// endpoints,
65427247 // and 0 for other transports. On failure, returns -1. Note that when using
6543 // ephemeral ports, a port may be reused by different services without
6544 // clients being aware. Protocols that run on ephemeral ports should take
6545 // this into account.
7248 // ephemeral ports, a port may be reused by different services without
7249 // clients being aware. Protocols that run on ephemeral ports should take
7250 // this into account.
65467251 CZMQ_EXPORT int
65477252 zsock_bind (zsock_t *self, const char *format, ...) CHECK_PRINTF (2);
65487253
65507255 CZMQ_EXPORT const char *
65517256 zsock_endpoint (zsock_t *self);
65527257
6553 // Unbind a socket from a formatted endpoint.
7258 // Unbind a socket from a formatted endpoint.
65547259 // Returns 0 if OK, -1 if the endpoint was invalid or the function
6555 // isn't supported.
7260 // isn't supported.
65567261 CZMQ_EXPORT int
65577262 zsock_unbind (zsock_t *self, const char *format, ...) CHECK_PRINTF (2);
65587263
6559 // Connect a socket to a formatted endpoint
7264 // Connect a socket to a formatted endpoint
65607265 // Returns 0 if OK, -1 if the endpoint was invalid.
65617266 CZMQ_EXPORT int
65627267 zsock_connect (zsock_t *self, const char *format, ...) CHECK_PRINTF (2);
65637268
6564 // Disconnect a socket from a formatted endpoint
7269 // Disconnect a socket from a formatted endpoint
65657270 // Returns 0 if OK, -1 if the endpoint was invalid or the function
6566 // isn't supported.
7271 // isn't supported.
65677272 CZMQ_EXPORT int
65687273 zsock_disconnect (zsock_t *self, const char *format, ...) CHECK_PRINTF (2);
65697274
6570 // Attach a socket to zero or more endpoints. If endpoints is not null,
6571 // parses as list of ZeroMQ endpoints, separated by commas, and prefixed by
7275 // Attach a socket to zero or more endpoints. If endpoints is not null,
7276 // parses as list of ZeroMQ endpoints, separated by commas, and prefixed by
65727277 // '@' (to bind the socket) or '>' (to connect the socket). Returns 0 if all
6573 // endpoints were valid, or -1 if there was a syntax error. If the endpoint
6574 // does not start with '@' or '>', the serverish argument defines whether
6575 // it is used to bind (serverish = true) or connect (serverish = false).
7278 // endpoints were valid, or -1 if there was a syntax error. If the endpoint
7279 // does not start with '@' or '>', the serverish argument defines whether
7280 // it is used to bind (serverish = true) or connect (serverish = false).
65767281 CZMQ_EXPORT int
65777282 zsock_attach (zsock_t *self, const char *endpoints, bool serverish);
65787283
65807285 CZMQ_EXPORT const char *
65817286 zsock_type_str (zsock_t *self);
65827287
6583 // Send a 'picture' message to the socket (or actor). The picture is a
7288 // Send a 'picture' message to the socket (or actor). The picture is a
65847289 // string that defines the type of each frame. This makes it easy to send
6585 // a complex multiframe message in one call. The picture can contain any
6586 // of these characters, each corresponding to one or two arguments:
6587 //
6588 // i = int (signed)
6589 // 1 = uint8_t
6590 // 2 = uint16_t
6591 // 4 = uint32_t
6592 // 8 = uint64_t
6593 // s = char *
6594 // b = byte *, size_t (2 arguments)
6595 // c = zchunk_t *
6596 // f = zframe_t *
6597 // h = zhashx_t *
6598 // U = zuuid_t *
6599 // p = void * (sends the pointer value, only meaningful over inproc)
6600 // m = zmsg_t * (sends all frames in the zmsg)
6601 // z = sends zero-sized frame (0 arguments)
6602 // u = uint (deprecated)
6603 //
6604 // Note that s, b, c, and f are encoded the same way and the choice is
6605 // offered as a convenience to the sender, which may or may not already
6606 // have data in a zchunk or zframe. Does not change or take ownership of
6607 // any arguments. Returns 0 if successful, -1 if sending failed for any
6608 // reason.
7290 // a complex multiframe message in one call. The picture can contain any
7291 // of these characters, each corresponding to one or two arguments:
7292 //
7293 // i = int (signed)
7294 // 1 = uint8_t
7295 // 2 = uint16_t
7296 // 4 = uint32_t
7297 // 8 = uint64_t
7298 // s = char *
7299 // b = byte *, size_t (2 arguments)
7300 // c = zchunk_t *
7301 // f = zframe_t *
7302 // h = zhashx_t *
7303 // U = zuuid_t *
7304 // p = void * (sends the pointer value, only meaningful over inproc)
7305 // m = zmsg_t * (sends all frames in the zmsg)
7306 // z = sends zero-sized frame (0 arguments)
7307 // u = uint (deprecated)
7308 //
7309 // Note that s, b, c, and f are encoded the same way and the choice is
7310 // offered as a convenience to the sender, which may or may not already
7311 // have data in a zchunk or zframe. Does not change or take ownership of
7312 // any arguments. Returns 0 if successful, -1 if sending failed for any
7313 // reason.
66097314 CZMQ_EXPORT int
66107315 zsock_send (void *self, const char *picture, ...);
66117316
6612 // Send a 'picture' message to the socket (or actor). This is a va_list
7317 // Send a 'picture' message to the socket (or actor). This is a va_list
66137318 // version of zsock_send (), so please consult its documentation for the
6614 // details.
7319 // details.
66157320 CZMQ_EXPORT int
66167321 zsock_vsend (void *self, const char *picture, va_list argptr);
66177322
66187323 // Receive a 'picture' message to the socket (or actor). See zsock_send for
66197324 // the format and meaning of the picture. Returns the picture elements into
6620 // a series of pointers as provided by the caller:
6621 //
6622 // i = int * (stores signed integer)
6623 // 4 = uint32_t * (stores 32-bit unsigned integer)
6624 // 8 = uint64_t * (stores 64-bit unsigned integer)
6625 // s = char ** (allocates new string)
6626 // b = byte **, size_t * (2 arguments) (allocates memory)
6627 // c = zchunk_t ** (creates zchunk)
6628 // f = zframe_t ** (creates zframe)
6629 // U = zuuid_t * (creates a zuuid with the data)
6630 // h = zhashx_t ** (creates zhashx)
6631 // p = void ** (stores pointer)
6632 // m = zmsg_t ** (creates a zmsg with the remaing frames)
6633 // z = null, asserts empty frame (0 arguments)
6634 // u = uint * (stores unsigned integer, deprecated)
6635 //
6636 // Note that zsock_recv creates the returned objects, and the caller must
6637 // destroy them when finished with them. The supplied pointers do not need
6638 // to be initialized. Returns 0 if successful, or -1 if it failed to recv
6639 // a message, in which case the pointers are not modified. When message
7325 // a series of pointers as provided by the caller:
7326 //
7327 // i = int * (stores signed integer)
7328 // 4 = uint32_t * (stores 32-bit unsigned integer)
7329 // 8 = uint64_t * (stores 64-bit unsigned integer)
7330 // s = char ** (allocates new string)
7331 // b = byte **, size_t * (2 arguments) (allocates memory)
7332 // c = zchunk_t ** (creates zchunk)
7333 // f = zframe_t ** (creates zframe)
7334 // U = zuuid_t * (creates a zuuid with the data)
7335 // h = zhashx_t ** (creates zhashx)
7336 // p = void ** (stores pointer)
7337 // m = zmsg_t ** (creates a zmsg with the remaining frames)
7338 // z = null, asserts empty frame (0 arguments)
7339 // u = uint * (stores unsigned integer, deprecated)
7340 //
7341 // Note that zsock_recv creates the returned objects, and the caller must
7342 // destroy them when finished with them. The supplied pointers do not need
7343 // to be initialized. Returns 0 if successful, or -1 if it failed to recv
7344 // a message, in which case the pointers are not modified. When message
66407345 // frames are truncated (a short message), sets return values to zero/null.
6641 // If an argument pointer is NULL, does not store any value (skips it).
6642 // An 'n' picture matches an empty frame; if the message does not match,
6643 // the method will return -1.
7346 // If an argument pointer is NULL, does not store any value (skips it).
7347 // An 'n' picture matches an empty frame; if the message does not match,
7348 // the method will return -1.
66447349 CZMQ_EXPORT int
66457350 zsock_recv (void *self, const char *picture, ...);
66467351
6647 // Receive a 'picture' message from the socket (or actor). This is a
7352 // Receive a 'picture' message from the socket (or actor). This is a
66487353 // va_list version of zsock_recv (), so please consult its documentation
6649 // for the details.
7354 // for the details.
66507355 CZMQ_EXPORT int
66517356 zsock_vrecv (void *self, const char *picture, va_list argptr);
66527357
6653 // Send a binary encoded 'picture' message to the socket (or actor). This
6654 // method is similar to zsock_send, except the arguments are encoded in a
7358 // Send a binary encoded 'picture' message to the socket (or actor). This
7359 // method is similar to zsock_send, except the arguments are encoded in a
66557360 // binary format that is compatible with zproto, and is designed to reduce
6656 // memory allocations. The pattern argument is a string that defines the
6657 // type of each argument. Supports these argument types:
6658 //
6659 // pattern C type zproto type:
6660 // 1 uint8_t type = "number" size = "1"
6661 // 2 uint16_t type = "number" size = "2"
6662 // 4 uint32_t type = "number" size = "3"
6663 // 8 uint64_t type = "number" size = "4"
6664 // s char *, 0-255 chars type = "string"
6665 // S char *, 0-2^32-1 chars type = "longstr"
6666 // c zchunk_t * type = "chunk"
6667 // f zframe_t * type = "frame"
6668 // u zuuid_t * type = "uuid"
6669 // m zmsg_t * type = "msg"
6670 // p void *, sends pointer value, only over inproc
6671 //
6672 // Does not change or take ownership of any arguments. Returns 0 if
6673 // successful, -1 if sending failed for any reason.
7361 // memory allocations. The pattern argument is a string that defines the
7362 // type of each argument. Supports these argument types:
7363 //
7364 // pattern C type zproto type:
7365 // 1 uint8_t type = "number" size = "1"
7366 // 2 uint16_t type = "number" size = "2"
7367 // 4 uint32_t type = "number" size = "3"
7368 // 8 uint64_t type = "number" size = "4"
7369 // s char *, 0-255 chars type = "string"
7370 // S char *, 0-2^32-1 chars type = "longstr"
7371 // c zchunk_t * type = "chunk"
7372 // f zframe_t * type = "frame"
7373 // u zuuid_t * type = "uuid"
7374 // m zmsg_t * type = "msg"
7375 // p void *, sends pointer value, only over inproc
7376 //
7377 // Does not change or take ownership of any arguments. Returns 0 if
7378 // successful, -1 if sending failed for any reason.
66747379 CZMQ_EXPORT int
66757380 zsock_bsend (void *self, const char *picture, ...);
66767381
66957400 zsock_brecv (void *self, const char *picture, ...);
66967401
66977402 // Set socket to use unbounded pipes (HWM=0); use this in cases when you are
6698 // totally certain the message volume can fit in memory. This method works
6699 // across all versions of ZeroMQ. Takes a polymorphic socket reference.
7403 // totally certain the message volume can fit in memory. This method works
7404 // across all versions of ZeroMQ. Takes a polymorphic socket reference.
67007405 CZMQ_EXPORT void
67017406 zsock_set_unbounded (void *self);
67027407
6703 // Send a signal over a socket. A signal is a short message carrying a
6704 // success/failure code (by convention, 0 means OK). Signals are encoded
6705 // to be distinguishable from "normal" messages. Accepts a zsock_t or a
7408 // Send a signal over a socket. A signal is a short message carrying a
7409 // success/failure code (by convention, 0 means OK). Signals are encoded
7410 // to be distinguishable from "normal" messages. Accepts a zsock_t or a
67067411 // zactor_t argument, and returns 0 if successful, -1 if the signal could
6707 // not be sent. Takes a polymorphic socket reference.
7412 // not be sent. Takes a polymorphic socket reference.
67087413 CZMQ_EXPORT int
67097414 zsock_signal (void *self, byte status);
67107415
6711 // Wait on a signal. Use this to coordinate between threads, over pipe
7416 // Wait on a signal. Use this to coordinate between threads, over pipe
67127417 // pairs. Blocks until the signal is received. Returns -1 on error, 0 or
6713 // greater on success. Accepts a zsock_t or a zactor_t as argument.
6714 // Takes a polymorphic socket reference.
7418 // greater on success. Accepts a zsock_t or a zactor_t as argument.
7419 // Takes a polymorphic socket reference.
67157420 CZMQ_EXPORT int
67167421 zsock_wait (void *self);
67177422
6718 // If there is a partial message still waiting on the socket, remove and
7423 // If there is a partial message still waiting on the socket, remove and
67197424 // discard it. This is useful when reading partial messages, to get specific
6720 // message types.
7425 // message types.
67217426 CZMQ_EXPORT void
67227427 zsock_flush (void *self);
67237428
67247429 // Probe the supplied object, and report if it looks like a zsock_t.
6725 // Takes a polymorphic socket reference.
7430 // Takes a polymorphic socket reference.
67267431 CZMQ_EXPORT bool
67277432 zsock_is (void *self);
67287433
67297434 // Probe the supplied reference. If it looks like a zsock_t instance, return
6730 // the underlying libzmq socket handle; else if it looks like a file
6731 // descriptor, return NULL; else if it looks like a libzmq socket handle,
6732 // return the supplied value. Takes a polymorphic socket reference.
7435 // the underlying libzmq socket handle; else if it looks like a file
7436 // descriptor, return NULL; else if it looks like a libzmq socket handle,
7437 // return the supplied value. Takes a polymorphic socket reference.
67337438 CZMQ_EXPORT void *
67347439 zsock_resolve (void *self);
67357440
7441 // Get socket option `gssapi_principal_nametype`.
7442 // Available from libzmq 4.3.0.
7443 // Caller owns return value and must destroy it when done.
7444 CZMQ_EXPORT int
7445 zsock_gssapi_principal_nametype (void *self);
7446
7447 // Set socket option `gssapi_principal_nametype`.
7448 // Available from libzmq 4.3.0.
7449 CZMQ_EXPORT void
7450 zsock_set_gssapi_principal_nametype (void *self, int gssapi_principal_nametype);
7451
7452 // Get socket option `gssapi_service_principal_nametype`.
7453 // Available from libzmq 4.3.0.
7454 // Caller owns return value and must destroy it when done.
7455 CZMQ_EXPORT int
7456 zsock_gssapi_service_principal_nametype (void *self);
7457
7458 // Set socket option `gssapi_service_principal_nametype`.
7459 // Available from libzmq 4.3.0.
7460 CZMQ_EXPORT void
7461 zsock_set_gssapi_service_principal_nametype (void *self, int gssapi_service_principal_nametype);
7462
7463 // Get socket option `bindtodevice`.
7464 // Available from libzmq 4.3.0.
7465 // Caller owns return value and must destroy it when done.
7466 CZMQ_EXPORT char *
7467 zsock_bindtodevice (void *self);
7468
7469 // Set socket option `bindtodevice`.
7470 // Available from libzmq 4.3.0.
7471 CZMQ_EXPORT void
7472 zsock_set_bindtodevice (void *self, const char *bindtodevice);
7473
67367474 // Get socket option `heartbeat_ivl`.
6737 // Available from libzmq 4.2.0.
7475 // Available from libzmq 4.2.0.
67387476 // Caller owns return value and must destroy it when done.
67397477 CZMQ_EXPORT int
67407478 zsock_heartbeat_ivl (void *self);
67417479
67427480 // Set socket option `heartbeat_ivl`.
6743 // Available from libzmq 4.2.0.
7481 // Available from libzmq 4.2.0.
67447482 CZMQ_EXPORT void
67457483 zsock_set_heartbeat_ivl (void *self, int heartbeat_ivl);
67467484
67477485 // Get socket option `heartbeat_ttl`.
6748 // Available from libzmq 4.2.0.
7486 // Available from libzmq 4.2.0.
67497487 // Caller owns return value and must destroy it when done.
67507488 CZMQ_EXPORT int
67517489 zsock_heartbeat_ttl (void *self);
67527490
67537491 // Set socket option `heartbeat_ttl`.
6754 // Available from libzmq 4.2.0.
7492 // Available from libzmq 4.2.0.
67557493 CZMQ_EXPORT void
67567494 zsock_set_heartbeat_ttl (void *self, int heartbeat_ttl);
67577495
67587496 // Get socket option `heartbeat_timeout`.
6759 // Available from libzmq 4.2.0.
7497 // Available from libzmq 4.2.0.
67607498 // Caller owns return value and must destroy it when done.
67617499 CZMQ_EXPORT int
67627500 zsock_heartbeat_timeout (void *self);
67637501
67647502 // Set socket option `heartbeat_timeout`.
6765 // Available from libzmq 4.2.0.
7503 // Available from libzmq 4.2.0.
67667504 CZMQ_EXPORT void
67677505 zsock_set_heartbeat_timeout (void *self, int heartbeat_timeout);
67687506
6769 // Get socket option `use_fd`.
7507 // Get socket option `use_fd`.
67707508 // Available from libzmq 4.2.0.
67717509 // Caller owns return value and must destroy it when done.
67727510 CZMQ_EXPORT int
67737511 zsock_use_fd (void *self);
67747512
6775 // Set socket option `use_fd`.
7513 // Set socket option `use_fd`.
67767514 // Available from libzmq 4.2.0.
67777515 CZMQ_EXPORT void
67787516 zsock_set_use_fd (void *self, int use_fd);
67797517
67807518 // Set socket option `xpub_manual`.
6781 // Available from libzmq 4.2.0.
7519 // Available from libzmq 4.2.0.
67827520 CZMQ_EXPORT void
67837521 zsock_set_xpub_manual (void *self, int xpub_manual);
67847522
67857523 // Set socket option `xpub_welcome_msg`.
6786 // Available from libzmq 4.2.0.
7524 // Available from libzmq 4.2.0.
67877525 CZMQ_EXPORT void
67887526 zsock_set_xpub_welcome_msg (void *self, const char *xpub_welcome_msg);
67897527
67907528 // Set socket option `stream_notify`.
6791 // Available from libzmq 4.2.0.
7529 // Available from libzmq 4.2.0.
67927530 CZMQ_EXPORT void
67937531 zsock_set_stream_notify (void *self, int stream_notify);
67947532
67957533 // Get socket option `invert_matching`.
6796 // Available from libzmq 4.2.0.
7534 // Available from libzmq 4.2.0.
67977535 // Caller owns return value and must destroy it when done.
67987536 CZMQ_EXPORT int
67997537 zsock_invert_matching (void *self);
68007538
68017539 // Set socket option `invert_matching`.
6802 // Available from libzmq 4.2.0.
7540 // Available from libzmq 4.2.0.
68037541 CZMQ_EXPORT void
68047542 zsock_set_invert_matching (void *self, int invert_matching);
68057543
68067544 // Set socket option `xpub_verboser`.
6807 // Available from libzmq 4.2.0.
7545 // Available from libzmq 4.2.0.
68087546 CZMQ_EXPORT void
68097547 zsock_set_xpub_verboser (void *self, int xpub_verboser);
68107548
68117549 // Get socket option `connect_timeout`.
6812 // Available from libzmq 4.2.0.
7550 // Available from libzmq 4.2.0.
68137551 // Caller owns return value and must destroy it when done.
68147552 CZMQ_EXPORT int
68157553 zsock_connect_timeout (void *self);
68167554
68177555 // Set socket option `connect_timeout`.
6818 // Available from libzmq 4.2.0.
7556 // Available from libzmq 4.2.0.
68197557 CZMQ_EXPORT void
68207558 zsock_set_connect_timeout (void *self, int connect_timeout);
68217559
68227560 // Get socket option `tcp_maxrt`.
6823 // Available from libzmq 4.2.0.
7561 // Available from libzmq 4.2.0.
68247562 // Caller owns return value and must destroy it when done.
68257563 CZMQ_EXPORT int
68267564 zsock_tcp_maxrt (void *self);
68277565
68287566 // Set socket option `tcp_maxrt`.
6829 // Available from libzmq 4.2.0.
7567 // Available from libzmq 4.2.0.
68307568 CZMQ_EXPORT void
68317569 zsock_set_tcp_maxrt (void *self, int tcp_maxrt);
68327570
68337571 // Get socket option `thread_safe`.
6834 // Available from libzmq 4.2.0.
7572 // Available from libzmq 4.2.0.
68357573 // Caller owns return value and must destroy it when done.
68367574 CZMQ_EXPORT int
68377575 zsock_thread_safe (void *self);
68387576
68397577 // Get socket option `multicast_maxtpdu`.
6840 // Available from libzmq 4.2.0.
7578 // Available from libzmq 4.2.0.
68417579 // Caller owns return value and must destroy it when done.
68427580 CZMQ_EXPORT int
68437581 zsock_multicast_maxtpdu (void *self);
68447582
68457583 // Set socket option `multicast_maxtpdu`.
6846 // Available from libzmq 4.2.0.
7584 // Available from libzmq 4.2.0.
68477585 CZMQ_EXPORT void
68487586 zsock_set_multicast_maxtpdu (void *self, int multicast_maxtpdu);
68497587
68507588 // Get socket option `vmci_buffer_size`.
6851 // Available from libzmq 4.2.0.
7589 // Available from libzmq 4.2.0.
68527590 // Caller owns return value and must destroy it when done.
68537591 CZMQ_EXPORT int
68547592 zsock_vmci_buffer_size (void *self);
68557593
68567594 // Set socket option `vmci_buffer_size`.
6857 // Available from libzmq 4.2.0.
7595 // Available from libzmq 4.2.0.
68587596 CZMQ_EXPORT void
68597597 zsock_set_vmci_buffer_size (void *self, int vmci_buffer_size);
68607598
68617599 // Get socket option `vmci_buffer_min_size`.
6862 // Available from libzmq 4.2.0.
7600 // Available from libzmq 4.2.0.
68637601 // Caller owns return value and must destroy it when done.
68647602 CZMQ_EXPORT int
68657603 zsock_vmci_buffer_min_size (void *self);
68667604
68677605 // Set socket option `vmci_buffer_min_size`.
6868 // Available from libzmq 4.2.0.
7606 // Available from libzmq 4.2.0.
68697607 CZMQ_EXPORT void
68707608 zsock_set_vmci_buffer_min_size (void *self, int vmci_buffer_min_size);
68717609
68727610 // Get socket option `vmci_buffer_max_size`.
6873 // Available from libzmq 4.2.0.
7611 // Available from libzmq 4.2.0.
68747612 // Caller owns return value and must destroy it when done.
68757613 CZMQ_EXPORT int
68767614 zsock_vmci_buffer_max_size (void *self);
68777615
68787616 // Set socket option `vmci_buffer_max_size`.
6879 // Available from libzmq 4.2.0.
7617 // Available from libzmq 4.2.0.
68807618 CZMQ_EXPORT void
68817619 zsock_set_vmci_buffer_max_size (void *self, int vmci_buffer_max_size);
68827620
68837621 // Get socket option `vmci_connect_timeout`.
6884 // Available from libzmq 4.2.0.
7622 // Available from libzmq 4.2.0.
68857623 // Caller owns return value and must destroy it when done.
68867624 CZMQ_EXPORT int
68877625 zsock_vmci_connect_timeout (void *self);
68887626
68897627 // Set socket option `vmci_connect_timeout`.
6890 // Available from libzmq 4.2.0.
7628 // Available from libzmq 4.2.0.
68917629 CZMQ_EXPORT void
68927630 zsock_set_vmci_connect_timeout (void *self, int vmci_connect_timeout);
68937631
6894 // Get socket option `tos`.
7632 // Get socket option `tos`.
68957633 // Available from libzmq 4.1.0.
68967634 // Caller owns return value and must destroy it when done.
68977635 CZMQ_EXPORT int
68987636 zsock_tos (void *self);
68997637
6900 // Set socket option `tos`.
7638 // Set socket option `tos`.
69017639 // Available from libzmq 4.1.0.
69027640 CZMQ_EXPORT void
69037641 zsock_set_tos (void *self, int tos);
69047642
69057643 // Set socket option `router_handover`.
6906 // Available from libzmq 4.1.0.
7644 // Available from libzmq 4.1.0.
69077645 CZMQ_EXPORT void
69087646 zsock_set_router_handover (void *self, int router_handover);
69097647
69107648 // Set socket option `connect_rid`.
6911 // Available from libzmq 4.1.0.
7649 // Available from libzmq 4.1.0.
69127650 CZMQ_EXPORT void
69137651 zsock_set_connect_rid (void *self, const char *connect_rid);
69147652
69157653 // Set socket option `connect_rid` from 32-octet binary
6916 // Available from libzmq 4.1.0.
7654 // Available from libzmq 4.1.0.
69177655 CZMQ_EXPORT void
69187656 zsock_set_connect_rid_bin (void *self, const byte *connect_rid);
69197657
69207658 // Get socket option `handshake_ivl`.
6921 // Available from libzmq 4.1.0.
7659 // Available from libzmq 4.1.0.
69227660 // Caller owns return value and must destroy it when done.
69237661 CZMQ_EXPORT int
69247662 zsock_handshake_ivl (void *self);
69257663
69267664 // Set socket option `handshake_ivl`.
6927 // Available from libzmq 4.1.0.
7665 // Available from libzmq 4.1.0.
69287666 CZMQ_EXPORT void
69297667 zsock_set_handshake_ivl (void *self, int handshake_ivl);
69307668
69317669 // Get socket option `socks_proxy`.
6932 // Available from libzmq 4.1.0.
7670 // Available from libzmq 4.1.0.
69337671 // Caller owns return value and must destroy it when done.
69347672 CZMQ_EXPORT char *
69357673 zsock_socks_proxy (void *self);
69367674
69377675 // Set socket option `socks_proxy`.
6938 // Available from libzmq 4.1.0.
7676 // Available from libzmq 4.1.0.
69397677 CZMQ_EXPORT void
69407678 zsock_set_socks_proxy (void *self, const char *socks_proxy);
69417679
69427680 // Set socket option `xpub_nodrop`.
6943 // Available from libzmq 4.1.0.
7681 // Available from libzmq 4.1.0.
69447682 CZMQ_EXPORT void
69457683 zsock_set_xpub_nodrop (void *self, int xpub_nodrop);
69467684
69477685 // Set socket option `router_mandatory`.
6948 // Available from libzmq 4.0.0.
7686 // Available from libzmq 4.0.0.
69497687 CZMQ_EXPORT void
69507688 zsock_set_router_mandatory (void *self, int router_mandatory);
69517689
69527690 // Set socket option `probe_router`.
6953 // Available from libzmq 4.0.0.
7691 // Available from libzmq 4.0.0.
69547692 CZMQ_EXPORT void
69557693 zsock_set_probe_router (void *self, int probe_router);
69567694
69577695 // Set socket option `req_relaxed`.
6958 // Available from libzmq 4.0.0.
7696 // Available from libzmq 4.0.0.
69597697 CZMQ_EXPORT void
69607698 zsock_set_req_relaxed (void *self, int req_relaxed);
69617699
69627700 // Set socket option `req_correlate`.
6963 // Available from libzmq 4.0.0.
7701 // Available from libzmq 4.0.0.
69647702 CZMQ_EXPORT void
69657703 zsock_set_req_correlate (void *self, int req_correlate);
69667704
69677705 // Set socket option `conflate`.
6968 // Available from libzmq 4.0.0.
7706 // Available from libzmq 4.0.0.
69697707 CZMQ_EXPORT void
69707708 zsock_set_conflate (void *self, int conflate);
69717709
69727710 // Get socket option `zap_domain`.
6973 // Available from libzmq 4.0.0.
7711 // Available from libzmq 4.0.0.
69747712 // Caller owns return value and must destroy it when done.
69757713 CZMQ_EXPORT char *
69767714 zsock_zap_domain (void *self);
69777715
69787716 // Set socket option `zap_domain`.
6979 // Available from libzmq 4.0.0.
7717 // Available from libzmq 4.0.0.
69807718 CZMQ_EXPORT void
69817719 zsock_set_zap_domain (void *self, const char *zap_domain);
69827720
69837721 // Get socket option `mechanism`.
6984 // Available from libzmq 4.0.0.
7722 // Available from libzmq 4.0.0.
69857723 // Caller owns return value and must destroy it when done.
69867724 CZMQ_EXPORT int
69877725 zsock_mechanism (void *self);
69887726
69897727 // Get socket option `plain_server`.
6990 // Available from libzmq 4.0.0.
7728 // Available from libzmq 4.0.0.
69917729 // Caller owns return value and must destroy it when done.
69927730 CZMQ_EXPORT int
69937731 zsock_plain_server (void *self);
69947732
69957733 // Set socket option `plain_server`.
6996 // Available from libzmq 4.0.0.
7734 // Available from libzmq 4.0.0.
69977735 CZMQ_EXPORT void
69987736 zsock_set_plain_server (void *self, int plain_server);
69997737
70007738 // Get socket option `plain_username`.
7001 // Available from libzmq 4.0.0.
7739 // Available from libzmq 4.0.0.
70027740 // Caller owns return value and must destroy it when done.
70037741 CZMQ_EXPORT char *
70047742 zsock_plain_username (void *self);
70057743
70067744 // Set socket option `plain_username`.
7007 // Available from libzmq 4.0.0.
7745 // Available from libzmq 4.0.0.
70087746 CZMQ_EXPORT void
70097747 zsock_set_plain_username (void *self, const char *plain_username);
70107748
70117749 // Get socket option `plain_password`.
7012 // Available from libzmq 4.0.0.
7750 // Available from libzmq 4.0.0.
70137751 // Caller owns return value and must destroy it when done.
70147752 CZMQ_EXPORT char *
70157753 zsock_plain_password (void *self);
70167754
70177755 // Set socket option `plain_password`.
7018 // Available from libzmq 4.0.0.
7756 // Available from libzmq 4.0.0.
70197757 CZMQ_EXPORT void
70207758 zsock_set_plain_password (void *self, const char *plain_password);
70217759
70227760 // Get socket option `curve_server`.
7023 // Available from libzmq 4.0.0.
7761 // Available from libzmq 4.0.0.
70247762 // Caller owns return value and must destroy it when done.
70257763 CZMQ_EXPORT int
70267764 zsock_curve_server (void *self);
70277765
70287766 // Set socket option `curve_server`.
7029 // Available from libzmq 4.0.0.
7767 // Available from libzmq 4.0.0.
70307768 CZMQ_EXPORT void
70317769 zsock_set_curve_server (void *self, int curve_server);
70327770
70337771 // Get socket option `curve_publickey`.
7034 // Available from libzmq 4.0.0.
7772 // Available from libzmq 4.0.0.
70357773 // Caller owns return value and must destroy it when done.
70367774 CZMQ_EXPORT char *
70377775 zsock_curve_publickey (void *self);
70387776
70397777 // Set socket option `curve_publickey`.
7040 // Available from libzmq 4.0.0.
7778 // Available from libzmq 4.0.0.
70417779 CZMQ_EXPORT void
70427780 zsock_set_curve_publickey (void *self, const char *curve_publickey);
70437781
70447782 // Set socket option `curve_publickey` from 32-octet binary
7045 // Available from libzmq 4.0.0.
7783 // Available from libzmq 4.0.0.
70467784 CZMQ_EXPORT void
70477785 zsock_set_curve_publickey_bin (void *self, const byte *curve_publickey);
70487786
70497787 // Get socket option `curve_secretkey`.
7050 // Available from libzmq 4.0.0.
7788 // Available from libzmq 4.0.0.
70517789 // Caller owns return value and must destroy it when done.
70527790 CZMQ_EXPORT char *
70537791 zsock_curve_secretkey (void *self);
70547792
70557793 // Set socket option `curve_secretkey`.
7056 // Available from libzmq 4.0.0.
7794 // Available from libzmq 4.0.0.
70577795 CZMQ_EXPORT void
70587796 zsock_set_curve_secretkey (void *self, const char *curve_secretkey);
70597797
70607798 // Set socket option `curve_secretkey` from 32-octet binary
7061 // Available from libzmq 4.0.0.
7799 // Available from libzmq 4.0.0.
70627800 CZMQ_EXPORT void
70637801 zsock_set_curve_secretkey_bin (void *self, const byte *curve_secretkey);
70647802
70657803 // Get socket option `curve_serverkey`.
7066 // Available from libzmq 4.0.0.
7804 // Available from libzmq 4.0.0.
70677805 // Caller owns return value and must destroy it when done.
70687806 CZMQ_EXPORT char *
70697807 zsock_curve_serverkey (void *self);
70707808
70717809 // Set socket option `curve_serverkey`.
7072 // Available from libzmq 4.0.0.
7810 // Available from libzmq 4.0.0.
70737811 CZMQ_EXPORT void
70747812 zsock_set_curve_serverkey (void *self, const char *curve_serverkey);
70757813
70767814 // Set socket option `curve_serverkey` from 32-octet binary
7077 // Available from libzmq 4.0.0.
7815 // Available from libzmq 4.0.0.
70787816 CZMQ_EXPORT void
70797817 zsock_set_curve_serverkey_bin (void *self, const byte *curve_serverkey);
70807818
70817819 // Get socket option `gssapi_server`.
7082 // Available from libzmq 4.0.0.
7820 // Available from libzmq 4.0.0.
70837821 // Caller owns return value and must destroy it when done.
70847822 CZMQ_EXPORT int
70857823 zsock_gssapi_server (void *self);
70867824
70877825 // Set socket option `gssapi_server`.
7088 // Available from libzmq 4.0.0.
7826 // Available from libzmq 4.0.0.
70897827 CZMQ_EXPORT void
70907828 zsock_set_gssapi_server (void *self, int gssapi_server);
70917829
70927830 // Get socket option `gssapi_plaintext`.
7093 // Available from libzmq 4.0.0.
7831 // Available from libzmq 4.0.0.
70947832 // Caller owns return value and must destroy it when done.
70957833 CZMQ_EXPORT int
70967834 zsock_gssapi_plaintext (void *self);
70977835
70987836 // Set socket option `gssapi_plaintext`.
7099 // Available from libzmq 4.0.0.
7837 // Available from libzmq 4.0.0.
71007838 CZMQ_EXPORT void
71017839 zsock_set_gssapi_plaintext (void *self, int gssapi_plaintext);
71027840
71037841 // Get socket option `gssapi_principal`.
7104 // Available from libzmq 4.0.0.
7842 // Available from libzmq 4.0.0.
71057843 // Caller owns return value and must destroy it when done.
71067844 CZMQ_EXPORT char *
71077845 zsock_gssapi_principal (void *self);
71087846
71097847 // Set socket option `gssapi_principal`.
7110 // Available from libzmq 4.0.0.
7848 // Available from libzmq 4.0.0.
71117849 CZMQ_EXPORT void
71127850 zsock_set_gssapi_principal (void *self, const char *gssapi_principal);
71137851
71147852 // Get socket option `gssapi_service_principal`.
7115 // Available from libzmq 4.0.0.
7853 // Available from libzmq 4.0.0.
71167854 // Caller owns return value and must destroy it when done.
71177855 CZMQ_EXPORT char *
71187856 zsock_gssapi_service_principal (void *self);
71197857
71207858 // Set socket option `gssapi_service_principal`.
7121 // Available from libzmq 4.0.0.
7859 // Available from libzmq 4.0.0.
71227860 CZMQ_EXPORT void
71237861 zsock_set_gssapi_service_principal (void *self, const char *gssapi_service_principal);
71247862
7125 // Get socket option `ipv6`.
7863 // Get socket option `ipv6`.
71267864 // Available from libzmq 4.0.0.
71277865 // Caller owns return value and must destroy it when done.
71287866 CZMQ_EXPORT int
71297867 zsock_ipv6 (void *self);
71307868
7131 // Set socket option `ipv6`.
7869 // Set socket option `ipv6`.
71327870 // Available from libzmq 4.0.0.
71337871 CZMQ_EXPORT void
71347872 zsock_set_ipv6 (void *self, int ipv6);
71357873
71367874 // Get socket option `immediate`.
7137 // Available from libzmq 4.0.0.
7875 // Available from libzmq 4.0.0.
71387876 // Caller owns return value and must destroy it when done.
71397877 CZMQ_EXPORT int
71407878 zsock_immediate (void *self);
71417879
71427880 // Set socket option `immediate`.
7143 // Available from libzmq 4.0.0.
7881 // Available from libzmq 4.0.0.
71447882 CZMQ_EXPORT void
71457883 zsock_set_immediate (void *self, int immediate);
71467884
7147 // Get socket option `sndhwm`.
7885 // Get socket option `sndhwm`.
71487886 // Available from libzmq 3.0.0.
71497887 // Caller owns return value and must destroy it when done.
71507888 CZMQ_EXPORT int
71517889 zsock_sndhwm (void *self);
71527890
7153 // Set socket option `sndhwm`.
7891 // Set socket option `sndhwm`.
71547892 // Available from libzmq 3.0.0.
71557893 CZMQ_EXPORT void
71567894 zsock_set_sndhwm (void *self, int sndhwm);
71577895
7158 // Get socket option `rcvhwm`.
7896 // Get socket option `rcvhwm`.
71597897 // Available from libzmq 3.0.0.
71607898 // Caller owns return value and must destroy it when done.
71617899 CZMQ_EXPORT int
71627900 zsock_rcvhwm (void *self);
71637901
7164 // Set socket option `rcvhwm`.
7902 // Set socket option `rcvhwm`.
71657903 // Available from libzmq 3.0.0.
71667904 CZMQ_EXPORT void
71677905 zsock_set_rcvhwm (void *self, int rcvhwm);
71687906
71697907 // Get socket option `maxmsgsize`.
7170 // Available from libzmq 3.0.0.
7908 // Available from libzmq 3.0.0.
71717909 // Caller owns return value and must destroy it when done.
71727910 CZMQ_EXPORT int
71737911 zsock_maxmsgsize (void *self);
71747912
71757913 // Set socket option `maxmsgsize`.
7176 // Available from libzmq 3.0.0.
7914 // Available from libzmq 3.0.0.
71777915 CZMQ_EXPORT void
71787916 zsock_set_maxmsgsize (void *self, int maxmsgsize);
71797917
71807918 // Get socket option `multicast_hops`.
7181 // Available from libzmq 3.0.0.
7919 // Available from libzmq 3.0.0.
71827920 // Caller owns return value and must destroy it when done.
71837921 CZMQ_EXPORT int
71847922 zsock_multicast_hops (void *self);
71857923
71867924 // Set socket option `multicast_hops`.
7187 // Available from libzmq 3.0.0.
7925 // Available from libzmq 3.0.0.
71887926 CZMQ_EXPORT void
71897927 zsock_set_multicast_hops (void *self, int multicast_hops);
71907928
71917929 // Set socket option `xpub_verbose`.
7192 // Available from libzmq 3.0.0.
7930 // Available from libzmq 3.0.0.
71937931 CZMQ_EXPORT void
71947932 zsock_set_xpub_verbose (void *self, int xpub_verbose);
71957933
71967934 // Get socket option `tcp_keepalive`.
7197 // Available from libzmq 3.0.0.
7935 // Available from libzmq 3.0.0.
71987936 // Caller owns return value and must destroy it when done.
71997937 CZMQ_EXPORT int
72007938 zsock_tcp_keepalive (void *self);
72017939
72027940 // Set socket option `tcp_keepalive`.
7203 // Available from libzmq 3.0.0.
7941 // Available from libzmq 3.0.0.
72047942 CZMQ_EXPORT void
72057943 zsock_set_tcp_keepalive (void *self, int tcp_keepalive);
72067944
72077945 // Get socket option `tcp_keepalive_idle`.
7208 // Available from libzmq 3.0.0.
7946 // Available from libzmq 3.0.0.
72097947 // Caller owns return value and must destroy it when done.
72107948 CZMQ_EXPORT int
72117949 zsock_tcp_keepalive_idle (void *self);
72127950
72137951 // Set socket option `tcp_keepalive_idle`.
7214 // Available from libzmq 3.0.0.
7952 // Available from libzmq 3.0.0.
72157953 CZMQ_EXPORT void
72167954 zsock_set_tcp_keepalive_idle (void *self, int tcp_keepalive_idle);
72177955
72187956 // Get socket option `tcp_keepalive_cnt`.
7219 // Available from libzmq 3.0.0.
7957 // Available from libzmq 3.0.0.
72207958 // Caller owns return value and must destroy it when done.
72217959 CZMQ_EXPORT int
72227960 zsock_tcp_keepalive_cnt (void *self);
72237961
72247962 // Set socket option `tcp_keepalive_cnt`.
7225 // Available from libzmq 3.0.0.
7963 // Available from libzmq 3.0.0.
72267964 CZMQ_EXPORT void
72277965 zsock_set_tcp_keepalive_cnt (void *self, int tcp_keepalive_cnt);
72287966
72297967 // Get socket option `tcp_keepalive_intvl`.
7230 // Available from libzmq 3.0.0.
7968 // Available from libzmq 3.0.0.
72317969 // Caller owns return value and must destroy it when done.
72327970 CZMQ_EXPORT int
72337971 zsock_tcp_keepalive_intvl (void *self);
72347972
72357973 // Set socket option `tcp_keepalive_intvl`.
7236 // Available from libzmq 3.0.0.
7974 // Available from libzmq 3.0.0.
72377975 CZMQ_EXPORT void
72387976 zsock_set_tcp_keepalive_intvl (void *self, int tcp_keepalive_intvl);
72397977
72407978 // Get socket option `tcp_accept_filter`.
7241 // Available from libzmq 3.0.0.
7979 // Available from libzmq 3.0.0.
72427980 // Caller owns return value and must destroy it when done.
72437981 CZMQ_EXPORT char *
72447982 zsock_tcp_accept_filter (void *self);
72457983
72467984 // Set socket option `tcp_accept_filter`.
7247 // Available from libzmq 3.0.0.
7985 // Available from libzmq 3.0.0.
72487986 CZMQ_EXPORT void
72497987 zsock_set_tcp_accept_filter (void *self, const char *tcp_accept_filter);
72507988
72517989 // Get socket option `last_endpoint`.
7252 // Available from libzmq 3.0.0.
7990 // Available from libzmq 3.0.0.
72537991 // Caller owns return value and must destroy it when done.
72547992 CZMQ_EXPORT char *
72557993 zsock_last_endpoint (void *self);
72567994
72577995 // Set socket option `router_raw`.
7258 // Available from libzmq 3.0.0.
7996 // Available from libzmq 3.0.0.
72597997 CZMQ_EXPORT void
72607998 zsock_set_router_raw (void *self, int router_raw);
72617999
72628000 // Get socket option `ipv4only`.
7263 // Available from libzmq 3.0.0.
8001 // Available from libzmq 3.0.0.
72648002 // Caller owns return value and must destroy it when done.
72658003 CZMQ_EXPORT int
72668004 zsock_ipv4only (void *self);
72678005
72688006 // Set socket option `ipv4only`.
7269 // Available from libzmq 3.0.0.
8007 // Available from libzmq 3.0.0.
72708008 CZMQ_EXPORT void
72718009 zsock_set_ipv4only (void *self, int ipv4only);
72728010
72738011 // Set socket option `delay_attach_on_connect`.
7274 // Available from libzmq 3.0.0.
8012 // Available from libzmq 3.0.0.
72758013 CZMQ_EXPORT void
72768014 zsock_set_delay_attach_on_connect (void *self, int delay_attach_on_connect);
72778015
7278 // Get socket option `hwm`.
8016 // Get socket option `hwm`.
72798017 // Available from libzmq 2.0.0 to 3.0.0.
72808018 // Caller owns return value and must destroy it when done.
72818019 CZMQ_EXPORT int
72828020 zsock_hwm (void *self);
72838021
7284 // Set socket option `hwm`.
8022 // Set socket option `hwm`.
72858023 // Available from libzmq 2.0.0 to 3.0.0.
72868024 CZMQ_EXPORT void
72878025 zsock_set_hwm (void *self, int hwm);
72888026
7289 // Get socket option `swap`.
8027 // Get socket option `swap`.
72908028 // Available from libzmq 2.0.0 to 3.0.0.
72918029 // Caller owns return value and must destroy it when done.
72928030 CZMQ_EXPORT int
72938031 zsock_swap (void *self);
72948032
7295 // Set socket option `swap`.
8033 // Set socket option `swap`.
72968034 // Available from libzmq 2.0.0 to 3.0.0.
72978035 CZMQ_EXPORT void
72988036 zsock_set_swap (void *self, int swap);
72998037
73008038 // Get socket option `affinity`.
7301 // Available from libzmq 2.0.0.
8039 // Available from libzmq 2.0.0.
73028040 // Caller owns return value and must destroy it when done.
73038041 CZMQ_EXPORT int
73048042 zsock_affinity (void *self);
73058043
73068044 // Set socket option `affinity`.
7307 // Available from libzmq 2.0.0.
8045 // Available from libzmq 2.0.0.
73088046 CZMQ_EXPORT void
73098047 zsock_set_affinity (void *self, int affinity);
73108048
73118049 // Get socket option `identity`.
7312 // Available from libzmq 2.0.0.
8050 // Available from libzmq 2.0.0.
73138051 // Caller owns return value and must destroy it when done.
73148052 CZMQ_EXPORT char *
73158053 zsock_identity (void *self);
73168054
73178055 // Set socket option `identity`.
7318 // Available from libzmq 2.0.0.
8056 // Available from libzmq 2.0.0.
73198057 CZMQ_EXPORT void
73208058 zsock_set_identity (void *self, const char *identity);
73218059
7322 // Get socket option `rate`.
8060 // Get socket option `rate`.
73238061 // Available from libzmq 2.0.0.
73248062 // Caller owns return value and must destroy it when done.
73258063 CZMQ_EXPORT int
73268064 zsock_rate (void *self);
73278065
7328 // Set socket option `rate`.
8066 // Set socket option `rate`.
73298067 // Available from libzmq 2.0.0.
73308068 CZMQ_EXPORT void
73318069 zsock_set_rate (void *self, int rate);
73328070
73338071 // Get socket option `recovery_ivl`.
7334 // Available from libzmq 2.0.0.
8072 // Available from libzmq 2.0.0.
73358073 // Caller owns return value and must destroy it when done.
73368074 CZMQ_EXPORT int
73378075 zsock_recovery_ivl (void *self);
73388076
73398077 // Set socket option `recovery_ivl`.
7340 // Available from libzmq 2.0.0.
8078 // Available from libzmq 2.0.0.
73418079 CZMQ_EXPORT void
73428080 zsock_set_recovery_ivl (void *self, int recovery_ivl);
73438081
73448082 // Get socket option `recovery_ivl_msec`.
7345 // Available from libzmq 2.0.0 to 3.0.0.
8083 // Available from libzmq 2.0.0 to 3.0.0.
73468084 // Caller owns return value and must destroy it when done.
73478085 CZMQ_EXPORT int
73488086 zsock_recovery_ivl_msec (void *self);
73498087
73508088 // Set socket option `recovery_ivl_msec`.
7351 // Available from libzmq 2.0.0 to 3.0.0.
8089 // Available from libzmq 2.0.0 to 3.0.0.
73528090 CZMQ_EXPORT void
73538091 zsock_set_recovery_ivl_msec (void *self, int recovery_ivl_msec);
73548092
7355 // Get socket option `mcast_loop`.
8093 // Get socket option `mcast_loop`.
73568094 // Available from libzmq 2.0.0 to 3.0.0.
73578095 // Caller owns return value and must destroy it when done.
73588096 CZMQ_EXPORT int
73598097 zsock_mcast_loop (void *self);
73608098
7361 // Set socket option `mcast_loop`.
8099 // Set socket option `mcast_loop`.
73628100 // Available from libzmq 2.0.0 to 3.0.0.
73638101 CZMQ_EXPORT void
73648102 zsock_set_mcast_loop (void *self, int mcast_loop);
73658103
73668104 // Get socket option `rcvtimeo`.
7367 // Available from libzmq 2.2.0.
8105 // Available from libzmq 2.2.0.
73688106 // Caller owns return value and must destroy it when done.
73698107 CZMQ_EXPORT int
73708108 zsock_rcvtimeo (void *self);
73718109
73728110 // Set socket option `rcvtimeo`.
7373 // Available from libzmq 2.2.0.
8111 // Available from libzmq 2.2.0.
73748112 CZMQ_EXPORT void
73758113 zsock_set_rcvtimeo (void *self, int rcvtimeo);
73768114
73778115 // Get socket option `sndtimeo`.
7378 // Available from libzmq 2.2.0.
8116 // Available from libzmq 2.2.0.
73798117 // Caller owns return value and must destroy it when done.
73808118 CZMQ_EXPORT int
73818119 zsock_sndtimeo (void *self);
73828120
73838121 // Set socket option `sndtimeo`.
7384 // Available from libzmq 2.2.0.
8122 // Available from libzmq 2.2.0.
73858123 CZMQ_EXPORT void
73868124 zsock_set_sndtimeo (void *self, int sndtimeo);
73878125
7388 // Get socket option `sndbuf`.
8126 // Get socket option `sndbuf`.
73898127 // Available from libzmq 2.0.0.
73908128 // Caller owns return value and must destroy it when done.
73918129 CZMQ_EXPORT int
73928130 zsock_sndbuf (void *self);
73938131
7394 // Set socket option `sndbuf`.
8132 // Set socket option `sndbuf`.
73958133 // Available from libzmq 2.0.0.
73968134 CZMQ_EXPORT void
73978135 zsock_set_sndbuf (void *self, int sndbuf);
73988136
7399 // Get socket option `rcvbuf`.
8137 // Get socket option `rcvbuf`.
74008138 // Available from libzmq 2.0.0.
74018139 // Caller owns return value and must destroy it when done.
74028140 CZMQ_EXPORT int
74038141 zsock_rcvbuf (void *self);
74048142
7405 // Set socket option `rcvbuf`.
8143 // Set socket option `rcvbuf`.
74068144 // Available from libzmq 2.0.0.
74078145 CZMQ_EXPORT void
74088146 zsock_set_rcvbuf (void *self, int rcvbuf);
74098147
7410 // Get socket option `linger`.
8148 // Get socket option `linger`.
74118149 // Available from libzmq 2.0.0.
74128150 // Caller owns return value and must destroy it when done.
74138151 CZMQ_EXPORT int
74148152 zsock_linger (void *self);
74158153
7416 // Set socket option `linger`.
8154 // Set socket option `linger`.
74178155 // Available from libzmq 2.0.0.
74188156 CZMQ_EXPORT void
74198157 zsock_set_linger (void *self, int linger);
74208158
74218159 // Get socket option `reconnect_ivl`.
7422 // Available from libzmq 2.0.0.
8160 // Available from libzmq 2.0.0.
74238161 // Caller owns return value and must destroy it when done.
74248162 CZMQ_EXPORT int
74258163 zsock_reconnect_ivl (void *self);
74268164
74278165 // Set socket option `reconnect_ivl`.
7428 // Available from libzmq 2.0.0.
8166 // Available from libzmq 2.0.0.
74298167 CZMQ_EXPORT void
74308168 zsock_set_reconnect_ivl (void *self, int reconnect_ivl);
74318169
74328170 // Get socket option `reconnect_ivl_max`.
7433 // Available from libzmq 2.0.0.
8171 // Available from libzmq 2.0.0.
74348172 // Caller owns return value and must destroy it when done.
74358173 CZMQ_EXPORT int
74368174 zsock_reconnect_ivl_max (void *self);
74378175
74388176 // Set socket option `reconnect_ivl_max`.
7439 // Available from libzmq 2.0.0.
8177 // Available from libzmq 2.0.0.
74408178 CZMQ_EXPORT void
74418179 zsock_set_reconnect_ivl_max (void *self, int reconnect_ivl_max);
74428180
74528190 zsock_set_backlog (void *self, int backlog);
74538191
74548192 // Set socket option `subscribe`.
7455 // Available from libzmq 2.0.0.
8193 // Available from libzmq 2.0.0.
74568194 CZMQ_EXPORT void
74578195 zsock_set_subscribe (void *self, const char *subscribe);
74588196
74598197 // Set socket option `unsubscribe`.
7460 // Available from libzmq 2.0.0.
8198 // Available from libzmq 2.0.0.
74618199 CZMQ_EXPORT void
74628200 zsock_set_unsubscribe (void *self, const char *unsubscribe);
74638201
7464 // Get socket option `type`.
8202 // Get socket option `type`.
74658203 // Available from libzmq 2.0.0.
74668204 // Caller owns return value and must destroy it when done.
74678205 CZMQ_EXPORT int
74738211 CZMQ_EXPORT int
74748212 zsock_rcvmore (void *self);
74758213
7476 // Get socket option `fd`.
8214 // Get socket option `fd`.
74778215 // Available from libzmq 2.0.0.
74788216 // Caller owns return value and must destroy it when done.
74798217 CZMQ_EXPORT SOCKET
74808218 zsock_fd (void *self);
74818219
7482 // Get socket option `events`.
8220 // Get socket option `events`.
74838221 // Available from libzmq 2.0.0.
74848222 // Caller owns return value and must destroy it when done.
74858223 CZMQ_EXPORT int
75228260
75238261 // *** Draft method, for development use, may change without warning ***
75248262 // Return socket routing ID if any. This returns 0 if the socket is not
7525 // of type ZMQ_SERVER or if no request was already received on it.
8263 // of type ZMQ_SERVER or if no request was already received on it.
75268264 CZMQ_EXPORT uint32_t
75278265 zsock_routing_id (zsock_t *self);
75288266
75298267 // *** Draft method, for development use, may change without warning ***
7530 // Set routing ID on socket. The socket MUST be of type ZMQ_SERVER.
8268 // Set routing ID on socket. The socket MUST be of type ZMQ_SERVER.
75318269 // This will be used when sending messages on the socket via the zsock API.
75328270 CZMQ_EXPORT void
75338271 zsock_set_routing_id (zsock_t *self, uint32_t routing_id);
75348272
75358273 // *** Draft method, for development use, may change without warning ***
75368274 // Join a group for the RADIO-DISH pattern. Call only on ZMQ_DISH.
7537 // Returns 0 if OK, -1 if failed.
8275 // Returns 0 if OK, -1 if failed.
75388276 CZMQ_EXPORT int
75398277 zsock_join (void *self, const char *group);
75408278
75418279 // *** Draft method, for development use, may change without warning ***
75428280 // Leave a group for the RADIO-DISH pattern. Call only on ZMQ_DISH.
7543 // Returns 0 if OK, -1 if failed.
8281 // Returns 0 if OK, -1 if failed.
75448282 CZMQ_EXPORT int
75458283 zsock_leave (void *self, const char *group);
75468284
75518289 This is the class self test code:
75528290
75538291 ```c
7554 zsock_t *writer = zsock_new_push ("@tcp://127.0.0.1:5560");
8292 zsock_t *writer = zsock_new (ZMQ_PUSH);
75558293 assert (writer);
8294 int port = zsock_bind (writer, "tcp://127.0.0.1:*");
8295 assert (port != -1);
75568296 assert (zsock_resolve (writer) != writer);
75578297 assert (streq (zsock_type_str (writer), "PUSH"));
75588298
75598299 int rc;
75608300 #if (ZMQ_VERSION >= ZMQ_MAKE_VERSION (3, 2, 0))
75618301 // Check unbind
7562 rc = zsock_unbind (writer, "tcp://127.0.0.1:%d", 5560);
8302 rc = zsock_unbind (writer, "tcp://127.0.0.1:%d", port);
75638303 assert (rc == 0);
75648304
75658305 // In some cases and especially when running under Valgrind, doing
75688308 zclock_sleep (100);
75698309
75708310 // Bind again
7571 rc = zsock_bind (writer, "tcp://127.0.0.1:%d", 5560);
7572 assert (rc == 5560);
7573 assert (streq (zsock_endpoint (writer), "tcp://127.0.0.1:5560"));
8311 rc = zsock_bind (writer, "tcp://127.0.0.1:%d", port);
8312 assert (rc == port);
8313 char endpoint [40];
8314 sprintf (endpoint, "tcp://127.0.0.1:%d", port);
8315 assert (streq (zsock_endpoint (writer), endpoint));
75748316 #endif
75758317
7576 zsock_t *reader = zsock_new_pull (">tcp://127.0.0.1:5560");
8318 zsock_t *reader = zsock_new (ZMQ_PULL);
75778319 assert (reader);
8320 rc = zsock_connect (reader, "tcp://127.0.0.1:%d", port);
8321 assert (rc != -1);
75788322 assert (zsock_resolve (reader) != reader);
75798323 assert (streq (zsock_type_str (reader), "PULL"));
75808324
75848328 assert (msg);
75858329 char *string = zmsg_popstr (msg);
75868330 assert (streq (string, "Hello, World"));
7587 free (string);
8331 freen (string);
75888332 zmsg_destroy (&msg);
75898333
75908334 // Test resolve libzmq socket
76018345 zmq_ctx_term (zmq_ctx);
76028346
76038347 // Test resolve zsock
7604 zsock_t *resolve = zsock_new_pub("@tcp://127.0.0.1:5561");
8348 zsock_t *resolve = zsock_new_pub("@tcp://127.0.0.1:*");
76058349 assert (resolve);
76068350 assert (zsock_resolve (resolve) == resolve->handle);
76078351 zsock_destroy (&resolve);
76118355 assert (zsock_resolve ((void *) &fd) == NULL);
76128356
76138357 // Test binding to ephemeral ports, sequential and random
7614 int port = zsock_bind (writer, "tcp://127.0.0.1:*");
8358 port = zsock_bind (writer, "tcp://127.0.0.1:*");
76158359 assert (port >= DYNAMIC_FIRST && port <= DYNAMIC_LAST);
76168360 port = zsock_bind (writer, "tcp://127.0.0.1:*[50000-]");
76178361 assert (port >= 50000 && port <= DYNAMIC_LAST);
76188362 port = zsock_bind (writer, "tcp://127.0.0.1:*[-50001]");
76198363 assert (port >= DYNAMIC_FIRST && port <= 50001);
7620 port = zsock_bind (writer, "tcp://127.0.0.1:*[60000-60050]");
7621 assert (port >= 60000 && port <= 60050);
8364 port = zsock_bind (writer, "tcp://127.0.0.1:*[60000-60500]");
8365 assert (port >= 60000 && port <= 60500);
76228366
76238367 port = zsock_bind (writer, "tcp://127.0.0.1:!");
76248368 assert (port >= DYNAMIC_FIRST && port <= DYNAMIC_LAST);
76268370 assert (port >= 50000 && port <= DYNAMIC_LAST);
76278371 port = zsock_bind (writer, "tcp://127.0.0.1:![-50001]");
76288372 assert (port >= DYNAMIC_FIRST && port <= 50001);
7629 port = zsock_bind (writer, "tcp://127.0.0.1:![60000-60050]");
7630 assert (port >= 60000 && port <= 60050);
8373 port = zsock_bind (writer, "tcp://127.0.0.1:![60000-60500]");
8374 assert (port >= 60000 && port <= 60500);
76318375
76328376 // Test zsock_attach method
7633 zsock_t *server = zsock_new (ZMQ_DEALER);
7634 assert (server);
7635 rc = zsock_attach (server, "@inproc://myendpoint,tcp://127.0.0.1:5556,inproc://others", true);
8377 zsock_t *dealer = zsock_new (ZMQ_DEALER);
8378 assert (dealer);
8379 rc = zsock_attach (dealer, "@inproc://myendpoint,tcp://127.0.0.1:*,inproc://others", true);
76368380 assert (rc == 0);
7637 rc = zsock_attach (server, "", false);
8381 rc = zsock_attach (dealer, "", false);
76388382 assert (rc == 0);
7639 rc = zsock_attach (server, NULL, true);
8383 rc = zsock_attach (dealer, NULL, true);
76408384 assert (rc == 0);
7641 rc = zsock_attach (server, ">a,@b, c,, ", false);
8385 rc = zsock_attach (dealer, ">a,@b, c,, ", false);
76428386 assert (rc == -1);
7643 zsock_destroy (&server);
8387 zsock_destroy (&dealer);
76448388
76458389 // Test zsock_endpoint method
76468390 rc = zsock_bind (writer, "inproc://test.%s", "writer");
77258469 value = (char *) zhashx_lookup (hash, "2");
77268470 assert (streq (value, "value B"));
77278471 assert (original == pointer);
7728 free (string);
7729 free (data);
7730 free (uuid_str);
8472 freen (string);
8473 freen (data);
8474 freen (uuid_str);
77318475 zframe_destroy (&frame);
77328476 zchunk_destroy (&chunk);
77338477 zhashx_destroy (&hash);
78178561 #ifdef ZMQ_SERVER
78188562
78198563 // Test zsock_bsend/brecv pictures with binary encoding on SERVER and CLIENT sockets
7820 server = zsock_new_server ("tcp://127.0.0.1:5561");
8564 zsock_t *server = zsock_new (ZMQ_SERVER);
78218565 assert (server);
7822 zsock_t* client = zsock_new_client ("tcp://127.0.0.1:5561");
8566 port = zsock_bind (server, "tcp://127.0.0.1:*");
8567 assert (port != -1);
8568 zsock_t* client = zsock_new (ZMQ_CLIENT);
78238569 assert (client);
8570 rc = zsock_connect (client, "tcp://127.0.0.1:%d", port);
8571 assert (rc != -1);
78248572
78258573 // From client to server
78268574 chunk = zchunk_new ("World", 5);
78798627 zsock_destroy (&client);
78808628 zsock_destroy (&server);
78818629
8630 #else
8631 errno = 0;
8632 zsock_t* server = zsock_new_server (NULL);
8633 assert(server == NULL);
8634 assert(errno == ENOTSUP);
8635
8636 errno = 0;
8637 zsock_t* client = zsock_new_client (NULL);
8638 assert(client == NULL);
8639 assert(errno == ENOTSUP);
78828640 #endif
78838641
78848642 #ifdef ZMQ_SCATTER
78988656
78998657 zsock_destroy (&gather);
79008658 zsock_destroy (&scatter);
7901
8659 #else
8660 errno = 0;
8661 zsock_t* scatter = zsock_new_scatter (NULL);
8662 assert(scatter == NULL);
8663 assert(errno == ENOTSUP);
8664
8665 errno = 0;
8666 zsock_t* gather = zsock_new_gather (NULL);
8667 assert(gather == NULL);
8668 assert(errno == ENOTSUP);
8669 #endif
8670
8671 #ifndef ZMQ_RADIO
8672 errno = 0;
8673 zsock_t* radio = zsock_new_radio (NULL);
8674 assert(radio == NULL);
8675 assert(errno == ENOTSUP);
8676
8677 errno = 0;
8678 zsock_t* dish = zsock_new_dish (NULL);
8679 assert(dish == NULL);
8680 assert(errno == ENOTSUP);
8681
8682 errno = 0;
8683 zsock_t* sock = zsock_new_req (NULL); // any supported socket type
8684 rc = zsock_join (sock, "group1");
8685 assert(rc == -1);
8686 assert(errno == ENOTSUP);
8687 errno = 0;
8688 rc = zsock_leave (sock, "group1");
8689 assert(rc == -1);
8690 assert(errno == ENOTSUP);
8691 zsock_destroy (&sock);
79028692 #endif
79038693
79048694 // Check that we can send a zproto format message
79388728 // This class has draft methods, which may change over time. They are not
79398729 // in stable releases, by default. Use --enable-drafts to enable.
79408730 // Receive C string from socket. Caller must free returned string using
7941 // zstr_free(). Returns NULL if the context is being terminated or the
7942 // process was interrupted.
8731 // zstr_free(). Returns NULL if the context is being terminated or the
8732 // process was interrupted.
79438733 // Caller owns return value and must destroy it when done.
79448734 CZMQ_EXPORT char *
79458735 zstr_recv (void *source);
79468736
7947 // Receive a series of strings (until NULL) from multipart data.
7948 // Each string is allocated and filled with string data; if there
7949 // are not enough frames, unallocated strings are set to NULL.
7950 // Returns -1 if the message could not be read, else returns the
8737 // Receive a series of strings (until NULL) from multipart data.
8738 // Each string is allocated and filled with string data; if there
8739 // are not enough frames, unallocated strings are set to NULL.
8740 // Returns -1 if the message could not be read, else returns the
79518741 // number of strings filled, zero or more. Free each returned string
7952 // using zstr_free(). If not enough strings are provided, remaining
7953 // multipart frames in the message are dropped.
8742 // using zstr_free(). If not enough strings are provided, remaining
8743 // multipart frames in the message are dropped.
79548744 CZMQ_EXPORT int
79558745 zstr_recvx (void *source, char **string_p, ...);
79568746
7957 // Send a C string to a socket, as a frame. The string is sent without
8747 // Send a C string to a socket, as a frame. The string is sent without
79588748 // trailing null byte; to read this you can use zstr_recv, or a similar
7959 // method that adds a null terminator on the received string. String
7960 // may be NULL, which is sent as "".
8749 // method that adds a null terminator on the received string. String
8750 // may be NULL, which is sent as "".
79618751 CZMQ_EXPORT int
79628752 zstr_send (void *dest, const char *string);
79638753
79648754 // Send a C string to a socket, as zstr_send(), with a MORE flag, so that
7965 // you can send further strings in the same multi-part message.
8755 // you can send further strings in the same multi-part message.
79668756 CZMQ_EXPORT int
79678757 zstr_sendm (void *dest, const char *string);
79688758
79698759 // Send a formatted string to a socket. Note that you should NOT use
7970 // user-supplied strings in the format (they may contain '%' which
7971 // will create security holes).
8760 // user-supplied strings in the format (they may contain '%' which
8761 // will create security holes).
79728762 CZMQ_EXPORT int
79738763 zstr_sendf (void *dest, const char *format, ...) CHECK_PRINTF (2);
79748764
7975 // Send a formatted string to a socket, as for zstr_sendf(), with a
8765 // Send a formatted string to a socket, as for zstr_sendf(), with a
79768766 // MORE flag, so that you can send further strings in the same multi-part
7977 // message.
8767 // message.
79788768 CZMQ_EXPORT int
79798769 zstr_sendfm (void *dest, const char *format, ...) CHECK_PRINTF (2);
79808770
7981 // Send a series of strings (until NULL) as multipart data
8771 // Send a series of strings (until NULL) as multipart data
79828772 // Returns 0 if the strings could be sent OK, or -1 on error.
79838773 CZMQ_EXPORT int
79848774 zstr_sendx (void *dest, const char *string, ...);
79858775
79868776 // Free a provided string, and nullify the parent pointer. Safe to call on
7987 // a null pointer.
8777 // a null pointer.
79888778 CZMQ_EXPORT void
79898779 zstr_free (char **string_p);
79908780
79948784
79958785 #ifdef CZMQ_BUILD_DRAFT_API
79968786 // *** Draft method, for development use, may change without warning ***
8787 // De-compress and receive C string from socket, received as a message
8788 // with two frames: size of the uncompressed string, and the string itself.
8789 // Caller must free returned string using zstr_free(). Returns NULL if the
8790 // context is being terminated or the process was interrupted.
8791 // Caller owns return value and must destroy it when done.
8792 CZMQ_EXPORT char *
8793 zstr_recv_compress (void *source);
8794
8795 // *** Draft method, for development use, may change without warning ***
8796 // Compress and send a C string to a socket, as a message with two frames:
8797 // size of the uncompressed string, and the string itself. The string is
8798 // sent without trailing null byte; to read this you can use
8799 // zstr_recv_compress, or a similar method that de-compresses and adds a
8800 // null terminator on the received string.
8801 CZMQ_EXPORT int
8802 zstr_send_compress (void *dest, const char *string);
8803
8804 // *** Draft method, for development use, may change without warning ***
8805 // Compress and send a C string to a socket, as zstr_send_compress(),
8806 // with a MORE flag, so that you can send further strings in the same
8807 // multi-part message.
8808 CZMQ_EXPORT int
8809 zstr_sendm_compress (void *dest, const char *string);
8810
8811 // *** Draft method, for development use, may change without warning ***
79978812 // Accepts a void pointer and returns a fresh character string. If source
7998 // is null, returns an empty string.
8813 // is null, returns an empty string.
79998814 // Caller owns return value and must destroy it when done.
80008815 CZMQ_EXPORT char *
80018816 zstr_str (void *source);
80328847 }
80338848 assert (string_nbr == 15);
80348849
8850 #ifdef HAVE_LIBLZ4
8851 int ret = zstr_send_compress (output, "loooong");
8852 assert (ret == 0);
8853 char *string = zstr_recv_compress (input);
8854 assert (string);
8855 assert (streq (string, "loooong"));
8856 zstr_free (&string);
8857
8858 zstr_send_compress (output, "loooong");
8859 assert (ret == 0);
8860 zmsg_t *msg = zmsg_recv (input);
8861 assert (msg);
8862 assert (*((size_t *)zframe_data (zmsg_first (msg))) == strlen ("loooong"));
8863 zmsg_destroy (&msg);
8864 #endif
8865
80358866 zsock_destroy (&input);
80368867 zsock_destroy (&output);
80378868
80488879 char *request = zstr_recv (server);
80498880 assert (streq (request, "Hello"));
80508881 assert (zsock_routing_id (server));
8051 free (request);
8882 freen (request);
80528883
80538884 rc = zstr_send (server, "World");
80548885 assert (rc == 0);
80558886 char *reply = zstr_recv (client);
80568887 assert (streq (reply, "World"));
8057 free (reply);
8888 freen (reply);
80588889
80598890 rc = zstr_sendf (server, "%s", "World");
80608891 assert (rc == 0);
80618892 reply = zstr_recv (client);
80628893 assert (streq (reply, "World"));
8063 free (reply);
8894 freen (reply);
80648895
80658896 // Try ping-pong using sendx and recx
80668897 rc = zstr_sendx (client, "Hello", NULL);
80688899 rc = zstr_recvx (server, &request, NULL);
80698900 assert (rc >= 0);
80708901 assert (streq (request, "Hello"));
8071 free (request);
8902 freen (request);
80728903
80738904 rc = zstr_sendx (server, "World", NULL);
80748905 assert (rc == 0);
80758906 rc = zstr_recvx (client, &reply, NULL);
80768907 assert (rc >= 0);
80778908 assert (streq (reply, "World"));
8078 free (reply);
8909 freen (reply);
80798910
80808911 // Client and server disallow multipart
80818912 rc = zstr_sendm (client, "Hello");
81058936 ```h
81068937 // This is a stable class, and may not change except for emergencies. It
81078938 // is provided in stable builds.
8939 // This class has draft methods, which may change over time. They are not
8940 // in stable releases, by default. Use --enable-drafts to enable.
81088941 // Callback for interrupt signal handler
81098942 typedef void (zsys_handler_fn) (
81108943 int signal_value);
81428975 // *** This is for CZMQ internal use only and may change arbitrarily ***
81438976 CZMQ_EXPORT char *
81448977 zsys_sockname (int socktype);
8145
8978
81468979 // Create a pipe, which consists of two PAIR sockets connected over inproc.
81478980 // The pipe is configured to use the zsys_pipehwm setting. Returns the
81488981 // frontend socket successful, NULL if failed.
81498982 CZMQ_EXPORT zsock_t *
81508983 zsys_create_pipe (zsock_t **backend_p);
8151
8984
81528985 // Set interrupt handler; this saves the default handlers so that a
81538986 // zsys_handler_reset () can restore them. If you call this multiple times
81548987 // then the last handler will take affect. If handler_fn is NULL, disables
81628995
81638996 // Set default interrupt handler, so Ctrl-C or SIGTERM will set
81648997 // zsys_interrupted. Idempotent; safe to call multiple times.
8998 // Can be suppressed by ZSYS_SIGHANDLER=false
81658999 // *** This is for CZMQ internal use only and may change arbitrarily ***
81669000 CZMQ_EXPORT void
81679001 zsys_catch_interrupts (void);
84399273 // traffic (it may still be sent to the system facility).
84409274 CZMQ_EXPORT void
84419275 zsys_set_logstream (FILE *stream);
8442
9276
84439277 // Sends log output to a PUB socket bound to the specified endpoint. To
84449278 // collect such log output, create a SUB socket, subscribe to the traffic
84459279 // you care about, and connect to the endpoint. Log traffic is sent as a
84549288 // event log on Windows). By default this is disabled.
84559289 CZMQ_EXPORT void
84569290 zsys_set_logsystem (bool logsystem);
8457
9291
84589292 // Log error condition - highest priority
84599293 CZMQ_EXPORT void
84609294 zsys_error (const char *format, ...);
84629296 // Log warning condition - high priority
84639297 CZMQ_EXPORT void
84649298 zsys_warning (const char *format, ...);
8465
9299
84669300 // Log normal, but significant, condition - normal priority
84679301 CZMQ_EXPORT void
84689302 zsys_notice (const char *format, ...);
8469
9303
84709304 // Log informational message - low priority
84719305 CZMQ_EXPORT void
84729306 zsys_info (const char *format, ...);
8473
9307
84749308 // Log debug-level message - lowest priority
84759309 CZMQ_EXPORT void
84769310 zsys_debug (const char *format, ...);
84789312 // Self test of this class.
84799313 CZMQ_EXPORT void
84809314 zsys_test (bool verbose);
8481
9315
9316 #ifdef CZMQ_BUILD_DRAFT_API
9317 // *** Draft method, for development use, may change without warning ***
9318 // Check if default interrupt handler of Ctrl-C or SIGTERM was called.
9319 // Does not work if ZSYS_SIGHANDLER is false and code does not call
9320 // set interrupted on signal.
9321 CZMQ_EXPORT bool
9322 zsys_is_interrupted (void);
9323
9324 // *** Draft method, for development use, may change without warning ***
9325 // Set interrupted flag. This is done by default signal handler, however
9326 // this can be handy for language bindings or cases without default
9327 // signal handler.
9328 CZMQ_EXPORT void
9329 zsys_set_interrupted (void);
9330
9331 // *** Draft method, for development use, may change without warning ***
9332 // Configure whether to use zero copy strategy in libzmq. If the environment
9333 // variable ZSYS_ZERO_COPY_RECV is defined, that provides the default.
9334 // Otherwise the default is 1.
9335 CZMQ_EXPORT void
9336 zsys_set_zero_copy_recv (int zero_copy);
9337
9338 // *** Draft method, for development use, may change without warning ***
9339 // Return ZMQ_ZERO_COPY_RECV option.
9340 CZMQ_EXPORT int
9341 zsys_zero_copy_recv (void);
9342
9343 // *** Draft method, for development use, may change without warning ***
9344 // Configure the threshold value of filesystem object age per st_mtime
9345 // that should elapse until we consider that object "stable" at the
9346 // current zclock_time() moment.
9347 // The default is S_DEFAULT_ZSYS_FILE_STABLE_AGE_MSEC defined in zsys.c
9348 // which generally depends on host OS, with fallback value of 5000.
9349 CZMQ_EXPORT void
9350 zsys_set_file_stable_age_msec (int64_t file_stable_age_msec);
9351
9352 // *** Draft method, for development use, may change without warning ***
9353 // Return current threshold value of file stable age in msec.
9354 // This can be used in code that chooses to wait for this timeout
9355 // before testing if a filesystem object is "stable" or not.
9356 CZMQ_EXPORT int64_t
9357 zsys_file_stable_age_msec (void);
9358
9359 #endif // CZMQ_BUILD_DRAFT_API
84829360 ```
84839361 Please add '@interface' section in './../src/zsys.c'.
84849362
84899367
84909368 // Check capabilities without using the return value
84919369 int rc = zsys_has_curve ();
9370
9371 const char *SELFTEST_DIR_RW = "src/selftest-rw";
84929372
84939373 if (verbose) {
84949374 char *hostname = zsys_hostname ();
84959375 zsys_info ("host name is %s", hostname);
8496 free (hostname);
9376 freen (hostname);
84979377 zsys_info ("system limit is %zu ZeroMQ sockets", zsys_socket_limit ());
84989378 }
9379 #ifdef CZMQ_BUILD_DRAFT_API
9380 zsys_set_file_stable_age_msec (5123);
9381 assert (zsys_file_stable_age_msec() == 5123);
9382 zsys_set_file_stable_age_msec (-1);
9383 assert (zsys_file_stable_age_msec() == 5123);
9384 #endif // CZMQ_BUILD_DRAFT_API
84999385 zsys_set_linger (0);
85009386 zsys_set_sndhwm (1000);
85019387 zsys_set_rcvhwm (1000);
85049390 zsys_set_ipv6 (0);
85059391 zsys_set_thread_priority (-1);
85069392 zsys_set_thread_sched_policy (-1);
9393 zsys_set_zero_copy_recv(0);
9394 assert (0 == zsys_zero_copy_recv());
9395 zsys_set_zero_copy_recv(1);
9396 assert (1 == zsys_zero_copy_recv());
85079397
85089398 // Test pipe creation
85099399 zsock_t *pipe_back;
85119401 zstr_send (pipe_front, "Hello");
85129402 char *string = zstr_recv (pipe_back);
85139403 assert (streq (string, "Hello"));
8514 free (string);
9404 freen (string);
85159405 zsock_destroy (&pipe_back);
85169406 zsock_destroy (&pipe_front);
85179407
85189408 // Test file manipulation
9409
9410 // Don't let anyone fool our workspace
9411 if (zsys_file_exists ("nosuchfile")) {
9412 zsys_warning ("zsys_test() had to remove 'nosuchfile' which was not expected here at all");
9413 zsys_file_delete ("nosuchfile");
9414 }
9415
85199416 rc = zsys_file_delete ("nosuchfile");
85209417 assert (rc == -1);
85219418
85339430 assert (mode & S_IRUSR);
85349431 assert (mode & S_IWUSR);
85359432
9433 const char *testbasedir = ".testsys";
9434 const char *testsubdir = "subdir";
9435 char *basedirpath = NULL; // subdir in a test, under SELFTEST_DIR_RW
9436 char *dirpath = NULL; // subdir in a test, under basedirpath
9437 char *relsubdir = NULL; // relative short "path" of subdir under testbasedir
9438
9439 basedirpath = zsys_sprintf ("%s/%s", SELFTEST_DIR_RW, testbasedir);
9440 assert (basedirpath);
9441 dirpath = zsys_sprintf ("%s/%s", basedirpath, testsubdir);
9442 assert (dirpath);
9443 relsubdir = zsys_sprintf ("%s/%s", testbasedir, testsubdir);
9444 assert (relsubdir);
9445
9446 // Normally tests clean up in the end, but if a selftest run dies
9447 // e.g. on assert(), workspace remains dirty. Better clean it up.
9448 // We do not really care about results here - we clean up a possible
9449 // dirty exit of an older build. If there are permission errors etc.
9450 // the actual tests below would explode.
9451 if (zsys_file_exists(dirpath)) {
9452 if (verbose)
9453 zsys_debug ("zsys_test() has to remove ./%s that should not have been here", dirpath);
9454 zsys_dir_delete (dirpath);
9455 }
9456 if (zsys_file_exists (basedirpath)) {
9457 if (verbose)
9458 zsys_debug ("zsys_test() has to remove ./%s that should not have been here", basedirpath);
9459 zsys_dir_delete (basedirpath);
9460 }
9461
9462 // Added tracing because this file-age check fails on some systems
9463 // presumably due to congestion in a mass-build and valgrind on top
85369464 zsys_file_mode_private ();
8537 rc = zsys_dir_create ("%s/%s", ".", ".testsys/subdir");
9465 if (verbose)
9466 printf ("zsys_test() at timestamp %" PRIi64 ": "
9467 "Creating %s\n",
9468 zclock_time(), relsubdir );
9469 rc = zsys_dir_create ("%s/%s", SELFTEST_DIR_RW, relsubdir);
9470 if (verbose)
9471 printf ("zsys_test() at timestamp %" PRIi64 ": "
9472 "Finished creating %s with return-code %d\n",
9473 zclock_time(), relsubdir, rc );
85389474 assert (rc == 0);
8539 when = zsys_file_modified ("./.testsys/subdir");
9475 when = zsys_file_modified (dirpath);
9476 if (verbose)
9477 printf ("zsys_test() at timestamp %" PRIi64 ": "
9478 "Finished calling zsys_file_modified(), got age %jd\n",
9479 zclock_time(), (intmax_t)when );
85409480 assert (when > 0);
8541 assert (!zsys_file_stable ("./.testsys/subdir"));
8542 rc = zsys_dir_delete ("%s/%s", ".", ".testsys/subdir");
9481 if (verbose)
9482 printf ("zsys_test() at timestamp %" PRIi64 ": "
9483 "Checking if file is NOT stable (is younger than 1 sec)\n",
9484 zclock_time() );
9485 assert (!s_zsys_file_stable (dirpath, verbose));
9486 if (verbose)
9487 printf ("zsys_test() at timestamp %" PRIi64 ": "
9488 "Passed the test, file is not stable - as expected\n",
9489 zclock_time() );
9490 rc = zsys_dir_delete ("%s/%s", SELFTEST_DIR_RW, relsubdir);
85439491 assert (rc == 0);
8544 rc = zsys_dir_delete ("%s/%s", ".", ".testsys");
9492 rc = zsys_dir_delete ("%s/%s", SELFTEST_DIR_RW, testbasedir);
85459493 assert (rc == 0);
85469494 zsys_file_mode_default ();
8547 assert (zsys_dir_change (".") == 0);
8548
9495
9496 #if (defined (PATH_MAX))
9497 char cwd[PATH_MAX];
9498 #else
9499 # if (defined (_MAX_PATH))
9500 char cwd[_MAX_PATH];
9501 # else
9502 char cwd[1024];
9503 # endif
9504 #endif
9505 memset (cwd, 0, sizeof(cwd));
9506 #if (defined (WIN32))
9507 if (_getcwd(cwd, sizeof(cwd)) != NULL) {
9508 #else
9509 if (getcwd(cwd, sizeof(cwd)) != NULL) {
9510 #endif
9511 if (verbose)
9512 printf ("zsys_test() at timestamp %" PRIi64 ": "
9513 "current working directory is %s\n",
9514 zclock_time(), cwd);
9515 assert (zsys_dir_change (SELFTEST_DIR_RW) == 0);
9516 assert (zsys_dir_change (cwd) == 0);
9517 }
9518 else {
9519 zsys_warning ("zsys_test() : got getcwd() error... "
9520 "testing zsys_dir_change() anyway, but it can confuse "
9521 "subsequent tests in this process");
9522 assert (zsys_dir_change (SELFTEST_DIR_RW) == 0);
9523 }
9524
9525 zstr_free (&basedirpath);
9526 zstr_free (&dirpath);
9527 zstr_free (&relsubdir);
9528
9529 // Other subtests
85499530 int major, minor, patch;
85509531 zsys_version (&major, &minor, &patch);
85519532 assert (major == CZMQ_VERSION_MAJOR);
85549535
85559536 string = zsys_sprintf ("%s %02x", "Hello", 16);
85569537 assert (streq (string, "Hello 10"));
8557 free (string);
9538 freen (string);
85589539
85599540 char *str64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890,.";
85609541 int num10 = 1234567890;
85619542 string = zsys_sprintf ("%s%s%s%s%d", str64, str64, str64, str64, num10);
85629543 assert (strlen (string) == (4 * 64 + 10));
8563 free (string);
9544 freen (string);
85649545
85659546 // Test logging system
85669547 zsys_set_logident ("czmq_selftest");
86289609 ztimerset_cancel (ztimerset_t *self, int timer_id);
86299610
86309611 // *** Draft method, for development use, may change without warning ***
8631 // Set timer interval. Returns 0 if OK, -1 on failure.
9612 // Set timer interval. Returns 0 if OK, -1 on failure.
86329613 // This method is slow, canceling the timer and adding a new one yield better performance.
86339614 CZMQ_EXPORT int
86349615 ztimerset_set_interval (ztimerset_t *self, int timer_id, size_t interval);
86359616
86369617 // *** Draft method, for development use, may change without warning ***
86379618 // Reset timer to start interval counting from current time. Returns 0 if OK, -1 on failure.
8638 // This method is slow, canceling the timer and adding a new one yield better performance.
9619 // This method is slow, canceling the timer and adding a new one yield better performance.
86399620 CZMQ_EXPORT int
86409621 ztimerset_reset (ztimerset_t *self, int timer_id);
86419622
86429623 // *** Draft method, for development use, may change without warning ***
8643 // Return the time until the next interval.
9624 // Return the time until the next interval.
86449625 // Should be used as timeout parameter for the zpoller wait method.
8645 // The timeout is in msec.
9626 // The timeout is in msec.
86469627 CZMQ_EXPORT int
86479628 ztimerset_timeout (ztimerset_t *self);
86489629
86499630 // *** Draft method, for development use, may change without warning ***
86509631 // Invoke callback function of all timers which their interval has elapsed.
8651 // Should be call after zpoller wait method.
8652 // Returns 0 if OK, -1 on failure.
9632 // Should be call after zpoller wait method.
9633 // Returns 0 if OK, -1 on failure.
86539634 CZMQ_EXPORT int
86549635 ztimerset_execute (ztimerset_t *self);
86559636
87539734 ztrie_destroy (ztrie_t **self_p);
87549735
87559736 // *** Draft method, for development use, may change without warning ***
8756 // Inserts a new route into the tree and attaches the data. Returns -1
9737 // Inserts a new route into the tree and attaches the data. Returns -1
87579738 // if the route already exists, otherwise 0. This method takes ownership of
8758 // the provided data if a destroy_data_fn is provided.
9739 // the provided data if a destroy_data_fn is provided.
87599740 CZMQ_EXPORT int
87609741 ztrie_insert_route (ztrie_t *self, const char *path, void *data, ztrie_destroy_data_fn destroy_data_fn);
87619742
87629743 // *** Draft method, for development use, may change without warning ***
87639744 // Removes a route from the trie and destroys its data. Returns -1 if the
8764 // route does not exists, otherwise 0.
8765 // the start of the list call zlist_first (). Advances the cursor.
9745 // route does not exists, otherwise 0.
9746 // the start of the list call zlist_first (). Advances the cursor.
87669747 CZMQ_EXPORT int
87679748 ztrie_remove_route (ztrie_t *self, const char *path);
87689749
87739754
87749755 // *** Draft method, for development use, may change without warning ***
87759756 // Returns the data of a matched route from last ztrie_matches. If the path
8776 // did not match, returns NULL. Do not delete the data as it's owned by
8777 // ztrie.
9757 // did not match, returns NULL. Do not delete the data as it's owned by
9758 // ztrie.
87789759 CZMQ_EXPORT void *
87799760 ztrie_hit_data (ztrie_t *self);
87809761
87849765 ztrie_hit_parameter_count (ztrie_t *self);
87859766
87869767 // *** Draft method, for development use, may change without warning ***
8787 // Returns the parameters of a matched route with named regexes from last
9768 // Returns the parameters of a matched route with named regexes from last
87889769 // ztrie_matches. If the path did not match or the route did not contain any
8789 // named regexes, returns NULL.
9770 // named regexes, returns NULL.
87909771 CZMQ_EXPORT zhashx_t *
87919772 ztrie_hit_parameters (ztrie_t *self);
87929773
87939774 // *** Draft method, for development use, may change without warning ***
87949775 // Returns the asterisk matched part of a route, if there has been no match
8795 // or no asterisk match, returns NULL.
9776 // or no asterisk match, returns NULL.
87969777 CZMQ_EXPORT const char *
87979778 ztrie_hit_asterisk_match (ztrie_t *self);
87989779
89019882 assert (ret == 0);
89029883
89039884 // There is a lot you can do with regular expression but matching routes
8904 // of arbitrary length wont work. Therefore we make use of the asterisk
9885 // of arbitrary length won't work. Therefore we make use of the asterisk
89059886 // operator. Just place it at the end of your route, e.g. '/config/bar/*'.
89069887 ret = ztrie_insert_route (self, "/config/bar/*", NULL, NULL);
89079888 assert (ret == 0);
89989979 zuuid_set (zuuid_t *self, const byte *source);
89999980
90009981 // Set UUID to new supplied string value skipping '-' and '{' '}'
9001 // optional delimiters. Return 0 if OK, else returns -1.
9982 // optional delimiters. Return 0 if OK, else returns -1.
90029983 CZMQ_EXPORT int
90039984 zuuid_set_str (zuuid_t *self, const char *source);
90049985
90159996 zuuid_str (zuuid_t *self);
90169997
90179998 // Return UUID in the canonical string format: 8-4-4-4-12, in lower
9018 // case. Caller does not modify or free returned value. See
9019 // http://en.wikipedia.org/wiki/Universally_unique_identifier
9999 // case. Caller does not modify or free returned value. See
10000 // http://en.wikipedia.org/wiki/Universally_unique_identifier
902010001 CZMQ_EXPORT const char *
902110002 zuuid_str_canonical (zuuid_t *self);
902210003
903310014 zuuid_neq (zuuid_t *self, const byte *compare);
903410015
903510016 // Make copy of UUID object; if uuid is null, or memory was exhausted,
9036 // returns null.
10017 // returns null.
903710018 CZMQ_EXPORT zuuid_t *
903810019 zuuid_dup (zuuid_t *self);
903910020
33 [CFLAGS="${CFLAGS} -pthread"],
44 [AC_MSG_WARN([cannot link with -pthread.])]
55 )
6
7 AC_CACHE_CHECK([whether SOCK_CLOEXEC is supported], [czmq_cv_sock_cloexec],
8 [AC_TRY_RUN([/* SOCK_CLOEXEC test */
9 #include <sys/types.h>
10 #include <sys/socket.h>
11
12 int main (int argc, char *argv [])
13 {
14 int s = socket (PF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
15 return (s == -1);
16 }
17 ],
18 [czmq_cv_sock_cloexec="yes"],
19 [czmq_cv_sock_cloexec="no"],
20 [czmq_cv_sock_cloexec="not during cross-compile"]
21 )]
22 )
23 AS_IF([test "x$czmq_cv_sock_cloexec" = "xyes"],
24 AC_DEFINE([CZMQ_HAVE_SOCK_CLOEXEC],
25 [1],
26 [Whether SOCK_CLOEXEC is defined and functioning.])
27 )
628 ])
5757 typedef struct _ztimerset_t ztimerset_t;
5858 typedef struct _ztrie_t ztrie_t;
5959 typedef struct _zuuid_t zuuid_t;
60 typedef struct _zhttp_client_t zhttp_client_t;
61 typedef struct _zhttp_server_options_t zhttp_server_options_t;
62 typedef struct _zhttp_server_t zhttp_server_t;
63 typedef struct _zhttp_request_t zhttp_request_t;
64 typedef struct _zhttp_response_t zhttp_response_t;
6065 // Actors get a pipe and arguments from caller
6166 typedef void (zactor_fn) (
6267 zsock_t *pipe, void *args);
7883 typedef void (zcertstore_destructor) (
7984 void **self_p);
8085
86 // Destroy an item
87 typedef void (zchunk_destructor_fn) (
88 void **hint);
89
8190 //
8291 typedef int (zconfig_fct) (
8392 zconfig_t *self, void *arg, int level);
93
94 // Destroy an item
95 typedef void (zframe_destructor_fn) (
96 void **hint);
8497
8598 // Callback function for zhash_freefn method
8699 typedef void (zhash_free_fn) (
238251 const char *
239252 zargs_param_next (zargs_t *self);
240253
241 // Return current parameter name, or NULL if there are no named
242 // parameters.
254 // Return current parameter name, or NULL if there are no named parameters.
243255 const char *
244256 zargs_param_name (zargs_t *self);
245257
246 // Return value of named parameter, NULL if no given parameter has
247 // been specified, or special value for wich zargs_param_empty ()
248 // returns true.
258 // Return value of named parameter or NULL is it has no value (or was not specified)
249259 const char *
250 zargs_param_lookup (zargs_t *self, const char *keys);
251
252 // Return value of named parameter(s), NULL if no given parameter has
253 // been specified, or special value for wich zargs_param_empty ()
254 // returns true.
260 zargs_get (zargs_t *self, const char *name);
261
262 // Return value of one of parameter(s) or NULL is it has no value (or was not specified)
255263 const char *
256 zargs_param_lookupx (zargs_t *self, const char *keys, ...);
257
258 // Returns true if there are --help -h arguments
264 zargs_getx (zargs_t *self, const char *name, ...);
265
266 // Returns true if named parameter was specified on command line
259267 bool
260 zargs_has_help (zargs_t *self);
261
262 // Returns true if parameter did not have a value
268 zargs_has (zargs_t *self, const char *name);
269
270 // Returns true if named parameter(s) was specified on command line
263271 bool
264 zargs_param_empty (const char *arg);
272 zargs_hasx (zargs_t *self, const char *name, ...);
265273
266274 // Print an instance of zargs.
267275 void
492500 zchunk_t *
493501 zchunk_new (const void *data, size_t size);
494502
503 // Create a new chunk from memory. Take ownership of the memory and calling the destructor
504 // on destroy.
505 zchunk_t *
506 zchunk_frommem (void *data, size_t size, zchunk_destructor_fn destructor, void *hint);
507
495508 // Destroy a chunk
496509 void
497510 zchunk_destroy (zchunk_t **self_p);
583596 zframe_t *
584597 zchunk_pack (zchunk_t *self);
585598
599 // Transform zchunk into a zframe that can be sent in a message.
600 // Take ownership of the chunk.
601 zframe_t *
602 zchunk_packx (zchunk_t **self_p);
603
586604 // Transform a zframe into a zchunk.
587605 zchunk_t *
588606 zchunk_unpack (zframe_t *frame);
658676 // filename.
659677 zconfig_t *
660678 zconfig_loadf (const char *format, ...);
679
680 // Create copy of zconfig, caller MUST free the value
681 // Create copy of config, as new zconfig object. Returns a fresh zconfig_t
682 // object. If config is null, or memory was exhausted, returns null.
683 zconfig_t *
684 zconfig_dup (zconfig_t *self);
661685
662686 // Return name of config item
663687 char *
965989 zfile_t *
966990 zfile_new (const char *path, const char *name);
967991
968 // Create new temporary file for writing via tmpfile. File is automaticaly
992 // Create new temporary file for writing via tmpfile. File is automatically
969993 // deleted on destroy
970994 zfile_t *
971995 zfile_tmp (void);
10991123 // Create a frame with a specified string content.
11001124 zframe_t *
11011125 zframe_from (const char *string);
1126
1127 // Create a new frame from memory. Take ownership of the memory and calling the destructor
1128 // on destroy.
1129 zframe_t *
1130 zframe_frommem (void *data, size_t size, zframe_destructor_fn destructor, void *hint);
11021131
11031132 // Receive frame from socket, returns zframe_t object or NULL if the recv
11041133 // was interrupted. Does a blocking recv, if you want to not block then use
17301759 void
17311760 zlistx_destroy (zlistx_t **self_p);
17321761
1762 // Unpack binary frame into a new list. Packed data must follow format
1763 // defined by zlistx_pack. List is set to autofree. An empty frame
1764 // unpacks to an empty list.
1765 zlistx_t *
1766 zlistx_unpack (zframe_t *frame);
1767
17331768 // Add an item to the head of the list. Calls the item duplicator, if any,
17341769 // on the item. Resets cursor to list head. Returns an item handle on
17351770 // success, NULL if memory was exhausted.
18761911 // or greater than, item2.
18771912 void
18781913 zlistx_set_comparator (zlistx_t *self, zlistx_comparator_fn comparator);
1914
1915 // Serialize list to a binary frame that can be sent in a message.
1916 // The packed format is compatible with the 'strings' type implemented by zproto:
1917 //
1918 // ; A list of strings
1919 // list = list-count *longstr
1920 // list-count = number-4
1921 //
1922 // ; Strings are always length + text contents
1923 // longstr = number-4 *VCHAR
1924 //
1925 // ; Numbers are unsigned integers in network byte order
1926 // number-4 = 4OCTET
1927 zframe_t *
1928 zlistx_pack (zlistx_t *self);
18791929
18801930 // Self test of this class.
18811931 void
23232373 bool
23242374 zproc_running (zproc_t *self);
23252375
2376 // The timeout should be zero or greater, or -1 to wait indefinitely.
23262377 // wait or poll process status, return return code
23272378 int
2328 zproc_wait (zproc_t *self, bool hang);
2329
2330 // return internal actor, usefull for the polling if process died
2379 zproc_wait (zproc_t *self, int timeout);
2380
2381 // send SIGTERM signal to the subprocess, wait for grace period and
2382 // eventually send SIGKILL
2383 void
2384 zproc_shutdown (zproc_t *self, int timeout);
2385
2386 // return internal actor, useful for the polling if process died
23312387 void *
23322388 zproc_actor (zproc_t *self);
23332389
25032559 // c = zchunk_t *
25042560 // f = zframe_t *
25052561 // h = zhashx_t *
2562 // l = zlistx_t * (DRAFT)
25062563 // U = zuuid_t *
25072564 // p = void * (sends the pointer value, only meaningful over inproc)
25082565 // m = zmsg_t * (sends all frames in the zmsg)
25362593 // f = zframe_t ** (creates zframe)
25372594 // U = zuuid_t * (creates a zuuid with the data)
25382595 // h = zhashx_t ** (creates zhashx)
2596 // l = zlistx_t ** (creates zlistx) (DRAFT)
25392597 // p = void ** (stores pointer)
2540 // m = zmsg_t ** (creates a zmsg with the remaing frames)
2598 // m = zmsg_t ** (creates a zmsg with the remaining frames)
25412599 // z = null, asserts empty frame (0 arguments)
25422600 // u = uint * (stores unsigned integer, deprecated)
25432601 //
26612719 void *
26622720 zsock_resolve (void *self);
26632721
2722 // Check whether the socket has available message to read.
2723 bool
2724 zsock_has_in (void *self);
2725
2726 // Get socket option `router_notify`.
2727 // Available from libzmq 4.3.0.
2728 int
2729 zsock_router_notify (void *self);
2730
2731 // Set socket option `router_notify`.
2732 // Available from libzmq 4.3.0.
2733 void
2734 zsock_set_router_notify (void *self, int router_notify);
2735
2736 // Get socket option `multicast_loop`.
2737 // Available from libzmq 4.3.0.
2738 int
2739 zsock_multicast_loop (void *self);
2740
2741 // Set socket option `multicast_loop`.
2742 // Available from libzmq 4.3.0.
2743 void
2744 zsock_set_multicast_loop (void *self, int multicast_loop);
2745
2746 // Get socket option `metadata`.
2747 // Available from libzmq 4.3.0.
2748 char *
2749 zsock_metadata (void *self);
2750
2751 // Set socket option `metadata`.
2752 // Available from libzmq 4.3.0.
2753 void
2754 zsock_set_metadata (void *self, const char *metadata);
2755
2756 // Get socket option `loopback_fastpath`.
2757 // Available from libzmq 4.3.0.
2758 int
2759 zsock_loopback_fastpath (void *self);
2760
2761 // Set socket option `loopback_fastpath`.
2762 // Available from libzmq 4.3.0.
2763 void
2764 zsock_set_loopback_fastpath (void *self, int loopback_fastpath);
2765
2766 // Get socket option `zap_enforce_domain`.
2767 // Available from libzmq 4.3.0.
2768 int
2769 zsock_zap_enforce_domain (void *self);
2770
2771 // Set socket option `zap_enforce_domain`.
2772 // Available from libzmq 4.3.0.
2773 void
2774 zsock_set_zap_enforce_domain (void *self, int zap_enforce_domain);
2775
2776 // Get socket option `gssapi_principal_nametype`.
2777 // Available from libzmq 4.3.0.
2778 int
2779 zsock_gssapi_principal_nametype (void *self);
2780
2781 // Set socket option `gssapi_principal_nametype`.
2782 // Available from libzmq 4.3.0.
2783 void
2784 zsock_set_gssapi_principal_nametype (void *self, int gssapi_principal_nametype);
2785
2786 // Get socket option `gssapi_service_principal_nametype`.
2787 // Available from libzmq 4.3.0.
2788 int
2789 zsock_gssapi_service_principal_nametype (void *self);
2790
2791 // Set socket option `gssapi_service_principal_nametype`.
2792 // Available from libzmq 4.3.0.
2793 void
2794 zsock_set_gssapi_service_principal_nametype (void *self, int gssapi_service_principal_nametype);
2795
2796 // Get socket option `bindtodevice`.
2797 // Available from libzmq 4.3.0.
2798 char *
2799 zsock_bindtodevice (void *self);
2800
2801 // Set socket option `bindtodevice`.
2802 // Available from libzmq 4.3.0.
2803 void
2804 zsock_set_bindtodevice (void *self, const char *bindtodevice);
2805
26642806 // Get socket option `heartbeat_ivl`.
26652807 // Available from libzmq 4.2.0.
26662808 int
34903632
34913633 // Set default interrupt handler, so Ctrl-C or SIGTERM will set
34923634 // zsys_interrupted. Idempotent; safe to call multiple times.
3493 // Can be supressed by ZSYS_SIGHANDLER=false
3635 // Can be suppressed by ZSYS_SIGHANDLER=false
34943636 // *** This is for CZMQ internal use only and may change arbitrarily ***
34953637 void
34963638 zsys_catch_interrupts (void);
35563698 // number into provided fields, providing reference isn't null in each case.
35573699 void
35583700 zsys_version (int *major, int *minor, int *patch);
3701
3702 // Format a string using printf formatting, returning a freshly allocated
3703 // buffer. If there was insufficient memory, returns NULL. Free the returned
3704 // string using zstr_free(). The hinted version allows to optimize by using
3705 // a larger starting buffer size (known to/assumed by the developer) and so
3706 // avoid reallocations.
3707 char *
3708 zsys_sprintf_hint (int hint, const char *format, ...);
35593709
35603710 // Format a string using printf formatting, returning a freshly allocated
35613711 // buffer. If there was insufficient memory, returns NULL. Free the returned
36513801 void
36523802 zsys_set_thread_priority (int priority);
36533803
3804 // Configure the numeric prefix to each thread created for the internal
3805 // context's thread pool. This option is only supported on Linux.
3806 // If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
3807 // provides the default.
3808 // Note that this method is valid only before any socket is created.
3809 void
3810 zsys_set_thread_name_prefix (int prefix);
3811
3812 // Return thread name prefix.
3813 int
3814 zsys_thread_name_prefix (void);
3815
3816 // Adds a specific CPU to the affinity list of the ZMQ context thread pool.
3817 // This option is only supported on Linux.
3818 // Note that this method is valid only before any socket is created.
3819 void
3820 zsys_thread_affinity_cpu_add (int cpu);
3821
3822 // Removes a specific CPU to the affinity list of the ZMQ context thread pool.
3823 // This option is only supported on Linux.
3824 // Note that this method is valid only before any socket is created.
3825 void
3826 zsys_thread_affinity_cpu_remove (int cpu);
3827
36543828 // Configure the number of sockets that ZeroMQ will allow. The default
36553829 // is 1024. The actual limit depends on the system, and you can query it
36563830 // by using zsys_socket_limit (). A value of zero means "maximum".
37923966 // Return use of automatic pre-allocated FDs for zsock instances.
37933967 int
37943968 zsys_auto_use_fd (void);
3969
3970 // Print formatted string. Format is specified by variable names
3971 // in Python-like format style
3972 //
3973 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
3974 // become
3975 // "key=value"
3976 //
3977 // Returns freshly allocated string or NULL in a case of error.
3978 // Not enough memory, invalid format specifier, name not in args
3979 char *
3980 zsys_zprintf (const char *format, zhash_t *args);
3981
3982 // Return error string for given format/args combination.
3983 char *
3984 zsys_zprintf_error (const char *format, zhash_t *args);
3985
3986 // Print formatted string. Format is specified by variable names
3987 // in Python-like format style
3988 //
3989 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
3990 // become
3991 // "key=value"
3992 //
3993 // Returns freshly allocated string or NULL in a case of error.
3994 // Not enough memory, invalid format specifier, name not in args
3995 char *
3996 zsys_zplprintf (const char *format, zconfig_t *args);
3997
3998 // Return error string for given format/args combination.
3999 char *
4000 zsys_zplprintf_error (const char *format, zconfig_t *args);
37954001
37964002 // Set log identity, which is a string that prefixes all log messages sent
37974003 // by this process. The log identity defaults to the environment variable
40024208 void
40034209 zuuid_test (bool verbose);
40044210
4211 // CLASS: zhttp_client
4212 // Create a new http client
4213 zhttp_client_t *
4214 zhttp_client_new (bool verbose);
4215
4216 // Destroy an http client
4217 void
4218 zhttp_client_destroy (zhttp_client_t **self_p);
4219
4220 // Self test of this class.
4221 void
4222 zhttp_client_test (bool verbose);
4223
4224 // CLASS: zhttp_server
4225 // Create a new http server
4226 zhttp_server_t *
4227 zhttp_server_new (zhttp_server_options_t *options);
4228
4229 // Destroy an http server
4230 void
4231 zhttp_server_destroy (zhttp_server_t **self_p);
4232
4233 // Return the port the server is listening on.
4234 int
4235 zhttp_server_port (zhttp_server_t *self);
4236
4237 // Self test of this class.
4238 void
4239 zhttp_server_test (bool verbose);
4240
4241 // CLASS: zhttp_server_options
4242 // Create a new zhttp_server_options.
4243 zhttp_server_options_t *
4244 zhttp_server_options_new (void);
4245
4246 // Create options from config tree.
4247 zhttp_server_options_t *
4248 zhttp_server_options_from_config (zconfig_t *config);
4249
4250 // Destroy the zhttp_server_options.
4251 void
4252 zhttp_server_options_destroy (zhttp_server_options_t **self_p);
4253
4254 // Get the server listening port.
4255 int
4256 zhttp_server_options_port (zhttp_server_options_t *self);
4257
4258 // Set the server listening port
4259 void
4260 zhttp_server_options_set_port (zhttp_server_options_t *self, int port);
4261
4262 // Get the address sockets should connect to in order to receive requests.
4263 const char *
4264 zhttp_server_options_backend_address (zhttp_server_options_t *self);
4265
4266 // Set the address sockets should connect to in order to receive requests.
4267 void
4268 zhttp_server_options_set_backend_address (zhttp_server_options_t *self, const char *address);
4269
4270 // Self test of this class.
4271 void
4272 zhttp_server_options_test (bool verbose);
4273
4274 // CLASS: zhttp_request
4275 // Create a new http request.
4276 zhttp_request_t *
4277 zhttp_request_new (void);
4278
4279 // Destroy an http request.
4280 void
4281 zhttp_request_destroy (zhttp_request_t **self_p);
4282
4283 // Receive a new request from zhttp_server.
4284 // Return the underlying connection if successful, to be used when calling zhttp_response_send.
4285 void *
4286 zhttp_request_recv (zhttp_request_t *self, zsock_t *sock);
4287
4288 // Send a request to zhttp_client.
4289 // Url and the request path will be concatenated.
4290 // This behavior is useful for url rewrite and reverse proxy.
4291 //
4292 // Send also allow two user provided arguments which will be returned with the response.
4293 // The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an arg.
4294 int
4295 zhttp_request_send (zhttp_request_t *self, zhttp_client_t *client, int timeout, void *arg, void *arg2);
4296
4297 // Get the request method
4298 const char *
4299 zhttp_request_method (zhttp_request_t *self);
4300
4301 // Set the request method
4302 void
4303 zhttp_request_set_method (zhttp_request_t *self, const char *method);
4304
4305 // Get the request url.
4306 // When receiving a request from http server this is only the path part of the url.
4307 const char *
4308 zhttp_request_url (zhttp_request_t *self);
4309
4310 // Set the request url
4311 // When sending a request to http client this should be full url.
4312 void
4313 zhttp_request_set_url (zhttp_request_t *self, const char *url);
4314
4315 // Get the request content type
4316 const char *
4317 zhttp_request_content_type (zhttp_request_t *self);
4318
4319 // Set the request content type
4320 void
4321 zhttp_request_set_content_type (zhttp_request_t *self, const char *content_type);
4322
4323 // Get the content length of the request
4324 size_t
4325 zhttp_request_content_length (zhttp_request_t *self);
4326
4327 // Get the headers of the request
4328 zhash_t *
4329 zhttp_request_headers (zhttp_request_t *self);
4330
4331 // Get the content of the request.
4332 const char *
4333 zhttp_request_content (zhttp_request_t *self);
4334
4335 // Get the content of the request.
4336 char *
4337 zhttp_request_get_content (zhttp_request_t *self);
4338
4339 // Set the content of the request.
4340 // Content must by dynamically allocated string.
4341 // Takes ownership of the content.
4342 void
4343 zhttp_request_set_content (zhttp_request_t *self, char **content);
4344
4345 // Set the content of the request..
4346 // The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
4347 void
4348 zhttp_request_set_content_const (zhttp_request_t *self, const char *content);
4349
4350 // Set the content to NULL
4351 void
4352 zhttp_request_reset_content (zhttp_request_t *self);
4353
4354 // Match the path of the request.
4355 // Support wildcards with '%s' symbol inside the match string.
4356 // Matching wildcards until the next '/', '?' or '\0'.
4357 // On successful match the variadic arguments will be filled with the matching strings.
4358 // On successful match the method is modifying the url field and break it into substrings.
4359 // If you need to use the url, do it before matching or take a copy.
4360 //
4361 // User must not free the variadic arguments as they are part of the url.
4362 //
4363 // To use the percent symbol, just double it, e.g "%%something".
4364 //
4365 // Example:
4366 // if (zhttp_request_match (request, "POST", "/send/%s/%s", &name, &id))
4367 bool
4368 zhttp_request_match (zhttp_request_t *self, const char *method, const char *path, ...);
4369
4370 // Self test of this class.
4371 void
4372 zhttp_request_test (bool verbose);
4373
4374 // CLASS: zhttp_response
4375 // Create a new zhttp_response.
4376 zhttp_response_t *
4377 zhttp_response_new (void);
4378
4379 // Destroy the zhttp_response.
4380 void
4381 zhttp_response_destroy (zhttp_response_t **self_p);
4382
4383 // Send a response to a request.
4384 // Returns 0 if successful and -1 otherwise.
4385 int
4386 zhttp_response_send (zhttp_response_t *self, zsock_t *sock, void **connection);
4387
4388 // Receive a response from zhttp_client.
4389 // On success return 0, -1 otherwise.
4390 //
4391 // Recv returns the two user arguments which was provided with the request.
4392 // The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an argument.
4393 int
4394 zhttp_response_recv (zhttp_response_t *self, zhttp_client_t *client, void **arg, void **arg2);
4395
4396 // Get the response content type
4397 const char *
4398 zhttp_response_content_type (zhttp_response_t *self);
4399
4400 // Set the content type of the response.
4401 void
4402 zhttp_response_set_content_type (zhttp_response_t *self, const char *value);
4403
4404 // Get the status code of the response.
4405 uint32_t
4406 zhttp_response_status_code (zhttp_response_t *self);
4407
4408 // Set the status code of the response.
4409 void
4410 zhttp_response_set_status_code (zhttp_response_t *self, uint32_t status_code);
4411
4412 // Get the headers of the response.
4413 zhash_t *
4414 zhttp_response_headers (zhttp_response_t *self);
4415
4416 // Get the content length of the response
4417 size_t
4418 zhttp_response_content_length (zhttp_response_t *self);
4419
4420 // Get the content of the response.
4421 const char *
4422 zhttp_response_content (zhttp_response_t *self);
4423
4424 // Get the content of the response.
4425 char *
4426 zhttp_response_get_content (zhttp_response_t *self);
4427
4428 // Set the content of the response.
4429 // Content must by dynamically allocated string.
4430 // Takes ownership of the content.
4431 void
4432 zhttp_response_set_content (zhttp_response_t *self, char **content);
4433
4434 // Set the content of the response.
4435 // The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
4436 void
4437 zhttp_response_set_content_const (zhttp_response_t *self, const char *content);
4438
4439 // Set the content to NULL
4440 void
4441 zhttp_response_reset_content (zhttp_response_t *self);
4442
4443 // Self test of this class.
4444 void
4445 zhttp_response_test (bool verbose);
4446
40054447 ''')
1010 Platform independent command line argument parsing helpers
1111
1212 There are two kind of elements provided by this class
13 foo --named-parameter --parameter with_value positional arguments -a gain-parameter
14 zargs keeps poision only for arguments, parameters are to be accessed like hash.
13 Named parameters, accessed by param_get and param_has methods
14 * --named-parameter
15 * --parameter with_value
16 * -a val
17 Positional arguments, accessed by zargs_first, zargs_next
1518
1619 It DOES:
1720 * provide easy to use CLASS compatible API for accessing argv
1821 * is platform independent
1922 * provide getopt_long style -- argument, which delimits parameters from arguments
20 * makes parameters positon independent
23 * makes parameters position independent
2124
2225 It does NOT
2326 * change argv
7073 </method>
7174
7275 <method name = "param name" >
73 Return current parameter name, or NULL if there are no named
74 parameters.
76 Return current parameter name, or NULL if there are no named parameters.
7577 <return type = "string" />
7678 </method>
7779
78 <method name = "param lookup">
79 Return value of named parameter, NULL if no given parameter has
80 been specified, or special value for wich zargs_param_empty ()
81 returns true.
82 <argument name = "keys" type = "string" />
80 <method name = "get">
81 Return value of named parameter or NULL is it has no value (or was not specified)
82 <argument name = "name" type = "string" />
8383 <return type="string" />
8484 </method>
8585
86 <method name = "param lookupx">
87 Return value of named parameter(s), NULL if no given parameter has
88 been specified, or special value for wich zargs_param_empty ()
89 returns true.
90 <argument name = "keys" type = "string" variadic="1" />
86 <method name = "getx">
87 Return value of one of parameter(s) or NULL is it has no value (or was not specified)
88 <argument name = "name" type = "string" variadic = "1" />
9189 <return type="string" />
9290 </method>
9391
94 <method name = "has help">
95 Returns true if there are --help -h arguments
92 <method name = "has">
93 Returns true if named parameter was specified on command line
94 <argument name ="name" type = "string" />
9695 <return type="boolean" />
9796 </method>
9897
99 <!-- helpers -->
100 <method name = "param empty" singleton = "1">
101 Returns true if parameter did not have a value
102 <argument name ="arg" type = "string" />
98 <method name = "hasx">
99 Returns true if named parameter(s) was specified on command line
100 <argument name ="name" type = "string" variadic = "1" />
103101 <return type="boolean" />
104102 </method>
105103
88 file, You can obtain one at http://mozilla.org/MPL/2.0/.
99 -->
1010 work with memory chunks
11
12 <callback_type name = "destructor_fn" state = "draft">
13 Destroy an item
14 <argument name = "hint" type = "anything" by_reference = "1" />
15 </callback_type>
1116
1217 <constructor>
1318 Create a new chunk of the specified size. If you specify the data, it
1621 <argument name = "data" type = "buffer" c_type = "const void *" />
1722 <argument name = "size" type = "size" />
1823 </constructor>
24
25 <constructor name = "frommem" state = "draft">
26 Create a new chunk from memory. Take ownership of the memory and calling the destructor
27 on destroy.
28 <argument name = "data" type = "buffer" c_type = "void *" />
29 <argument name = "size" type = "size" />
30 <argument name = "destructor" type = "zchunk_destructor_fn" callback = "1" />
31 <argument name = "hint" type = "anything" />
32 </constructor>
33
1934
2035 <destructor>
2136 Destroy a chunk
141156 <return type = "zframe" fresh = "1" />
142157 </method>
143158
159 <method name = "packx" state = "draft" singleton = "1">
160 Transform zchunk into a zframe that can be sent in a message.
161 Take ownership of the chunk.
162 <argument name = "self_p" type = "zchunk" by_reference = "1" />
163 <return type = "zframe" fresh = "1" />
164 </method>
165
144166 <method name = "unpack" singleton = "1">
145167 Transform a zframe into a zchunk.
146168 <argument name = "frame" type = "zframe" mutable = "1" />
2525 <destructor>
2626 Destroy a config item and all its children
2727 </destructor>
28
29 <method name = "dup" state = "draft">
30 Create copy of zconfig, caller MUST free the value
31 Create copy of config, as new zconfig object. Returns a fresh zconfig_t
32 object. If config is null, or memory was exhausted, returns null.
33 <return type = "zconfig" fresh = "1" />
34 </method>
35
2836
2937 <method name = "name">
3038 Return name of config item
2020 </constructor>
2121
2222 <constructor name="tmp" state="draft">
23 Create new temporary file for writing via tmpfile. File is automaticaly
23 Create new temporary file for writing via tmpfile. File is automatically
2424 deleted on destroy
2525 </constructor>
2626
1212 <constant name = "more" value = "1" />
1313 <constant name = "reuse" value = "2" />
1414 <constant name = "dontwait" value = "4" />
15
16 <callback_type name = "destructor_fn" state = "draft">
17 Destroy an item
18 <argument name = "hint" type = "anything" by_reference = "1" />
19 </callback_type>
1520
1621 <constructor>
1722 Create a new frame. If size is not null, allocates the frame data
3237 <constructor name = "from">
3338 Create a frame with a specified string content.
3439 <argument name = "string" type = "string" />
40 </constructor>
41
42 <constructor name = "frommem" state = "draft">
43 Create a new frame from memory. Take ownership of the memory and calling the destructor
44 on destroy.
45 <argument name = "data" type = "buffer" c_type = "void *" />
46 <argument name = "size" type = "size" />
47 <argument name = "destructor" type = "zframe_destructor_fn" callback = "1" />
48 <argument name = "hint" type = "anything" />
3549 </constructor>
3650
3751 <constructor name = "recv">
0 <class name = "zhttp_client" state = "draft">
1 <!--
2 Copyright (c) the Contributors as noted in the AUTHORS file.
3 This file is part of CZMQ, the high-level C binding for 0MQ:
4 http://czmq.zeromq.org.
5
6 This Source Code Form is subject to the terms of the Mozilla Public
7 License, v. 2.0. If a copy of the MPL was not distributed with this
8 file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 -->
10 Http client, allowing multiple requests simultaneously and integrate easily with zpoller.
11 Use zhttp_request class to create and send the request.
12 Use zhttp_response class to receive the response.
13
14 <constructor>
15 Create a new http client
16 <argument name = "verbose" type = "boolean" />
17 </constructor>
18
19 <destructor>
20 Destroy an http client
21 </destructor>
22 </class>
0 <class name = "zhttp_request" state = "draft">
1 <!--
2 Copyright (c) the Contributors as noted in the AUTHORS file.
3 This file is part of CZMQ, the high-level C binding for 0MQ:
4 http://czmq.zeromq.org.
5
6 This Source Code Form is subject to the terms of the Mozilla Public
7 License, v. 2.0. If a copy of the MPL was not distributed with this
8 file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 -->
10 Http request that can be received from zhttp_server or sent to zhttp_client.
11 Class can be reused between send & recv calls.
12 Headers and Content is being destroyed after every send call.
13
14 <constructor>
15 Create a new http request.
16 </constructor>
17
18 <destructor>
19 Destroy an http request.
20 </destructor>
21
22 <method name = "recv">
23 Receive a new request from zhttp_server.
24 Return the underlying connection if successful, to be used when calling zhttp_response_send.
25
26 <argument name = "sock" type = "zsock" />
27 <return type = "anything" />
28 </method>
29
30 <method name = "send">
31 Send a request to zhttp_client.
32 Url and the request path will be concatenated.
33 This behavior is useful for url rewrite and reverse proxy.
34
35 Send also allow two user provided arguments which will be returned with the response.
36 The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an arg.
37 <argument name = "client" type = "zhttp_client" />
38 <argument name = "timeout" type = "integer" />
39 <argument name = "arg" type = "anything" />
40 <argument name = "arg2" type = "anything" />
41
42 <return type = "integer" />
43 </method>
44
45 <method name = "method">
46 Get the request method
47 <return type = "string" />
48 </method>
49
50 <method name = "set method">
51 Set the request method
52 <argument name = "method" type = "string" />
53 </method>
54
55 <method name = "url">
56 Get the request url.
57 When receiving a request from http server this is only the path part of the url.
58 <return type = "string" />
59 </method>
60
61 <method name = "set url">
62 Set the request url
63 When sending a request to http client this should be full url.
64 <argument name = "url" type = "string" />
65 </method>
66
67 <method name = "content type">
68 Get the request content type
69 <return type = "string" />
70 </method>
71
72 <method name = "set content type">
73 Set the request content type
74 <argument name = "content type" type = "string" />
75 </method>
76
77 <method name = "content length">
78 Get the content length of the request
79 <return type = "size" />
80 </method>
81
82 <method name = "headers">
83 Get the headers of the request
84 <return type = "zhash" />
85 </method>
86
87 <method name = "content">
88 Get the content of the request.
89 <return type = "string" />
90 </method>
91
92 <method name = "get content">
93 Get the content of the request.
94 <return type = "string" fresh = "1" />
95 </method>
96
97 <method name = "set content">
98 Set the content of the request.
99 Content must by dynamically allocated string.
100 Takes ownership of the content.
101 <argument name = "content" type = "string" by_reference = "1" />
102 </method>
103
104 <method name = "set content const">
105 Set the content of the request..
106 The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
107 <argument name = "content" type = "string" />
108 </method>
109
110 <method name = "reset content">
111 Set the content to NULL
112 </method>
113
114 <method name = "match">
115 Match the path of the request.
116 Support wildcards with '%s' symbol inside the match string.
117 Matching wildcards until the next '/', '?' or '\0'.
118 On successful match the variadic arguments will be filled with the matching strings.
119 On successful match the method is modifying the url field and break it into substrings.
120 If you need to use the url, do it before matching or take a copy.
121
122 User must not free the variadic arguments as they are part of the url.
123
124 To use the percent symbol, just double it, e.g "%%something".
125
126 Example:
127 if (zhttp_request_match (request, "POST", "/send/%s/%s", &name, &id))
128
129 <argument name = "method" type = "string" />
130 <argument name = "path" type = "string" variadic = "1" />
131
132 <return type = "boolean" />
133 </method>
134 </class>
0 <class name = "zhttp_response" state = "draft">
1 <!--
2 Copyright (c) the Contributors as noted in the AUTHORS file.
3 This file is part of CZMQ, the high-level C binding for 0MQ:
4 http://czmq.zeromq.org.
5
6 This Source Code Form is subject to the terms of the Mozilla Public
7 License, v. 2.0. If a copy of the MPL was not distributed with this
8 file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 -->
10 Http response that can be received from zhttp_client or sent to zhttp_server.
11 Class can be reused between send & recv calls.
12 Headers and Content is being destroyed after every send call.
13
14 <constructor>
15 </constructor>
16
17 <destructor>
18 </destructor>
19
20 <method name = "send">
21 Send a response to a request.
22 Returns 0 if successful and -1 otherwise.
23
24 <argument name = "sock" type = "zsock" />
25 <argument name = "connection" type = "anything" by_reference = "1" />
26
27 <return type = "integer" />
28 </method>
29
30 <method name = "recv">
31 Receive a response from zhttp_client.
32 On success return 0, -1 otherwise.
33
34 Recv returns the two user arguments which was provided with the request.
35 The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an argument.
36
37 <argument name = "client" type = "zhttp_client" />
38 <argument name = "arg" type = "anything" by_reference = "1" />
39 <argument name = "arg2" type = "anything" by_reference = "1" />
40 <return type = "integer" />
41 </method>
42
43 <method name = "content_type">
44 Get the response content type
45 <return type = "string" />
46 </method>
47
48 <method name = "set_content_type">
49 Set the content type of the response.
50 <argument name = "value" type = "string" />
51 </method>
52
53 <method name = "status_code">
54 Get the status code of the response.
55 <return type = "number" size = "4" />
56 </method>
57
58 <method name = "set_status_code">
59 Set the status code of the response.
60 <argument name = "status_code" type = "number" size = "4" />
61 </method>
62
63 <method name = "headers">
64 Get the headers of the response.
65 <return type = "zhash" />
66 </method>
67
68 <method name = "content_length">
69 Get the content length of the response
70 <return type = "size" />
71 </method>
72
73 <method name = "content">
74 Get the content of the response.
75 <return type = "string" />
76 </method>
77
78 <method name = "get content">
79 Get the content of the response.
80 <return type = "string" fresh = "1" />
81 </method>
82
83 <method name = "set content">
84 Set the content of the response.
85 Content must by dynamically allocated string.
86 Takes ownership of the content.
87 <argument name = "content" type = "string" by_reference = "1" />
88 </method>
89
90 <method name = "set content const">
91 Set the content of the response.
92 The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
93 <argument name = "content" type = "string" />
94 </method>
95
96 <method name = "reset content">
97 Set the content to NULL
98 </method>
99 </class>
0 <class name = "zhttp_server" state = "draft">
1 <!--
2 Copyright (c) the Contributors as noted in the AUTHORS file.
3 This file is part of CZMQ, the high-level C binding for 0MQ:
4 http://czmq.zeromq.org.
5
6 This Source Code Form is subject to the terms of the Mozilla Public
7 License, v. 2.0. If a copy of the MPL was not distributed with this
8 file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 -->
10 Simple http server.
11 To start handling requests:
12 1. Create a dealer socket
13 2. Connect the socket to the server backend address provided in the options.
14 3. Create a zhttp_request.
15 4. Call zhttp_request_recv to accept a new request.
16 5. Call zhttp_response_send to send a response.
17
18 You can connect as many dealers as you want.
19 The Server is using simple dealer socket to route the requests.
20
21 NOTE: when using libmicrohttpd << 0.9.34 the application might experience
22 high CPU usage due to the lack of MHD_suspend_connection and
23 MHD_resume_connection APIs. It is recommended to use this class only with
24 libmicrohttpd at least 0.9.34 in production.
25
26 <constructor>
27 Create a new http server
28 <argument name = "options" type = "zhttp_server_options" />
29 </constructor>
30
31 <destructor>
32 Destroy an http server
33 </destructor>
34
35 <method name = "port">
36 Return the port the server is listening on.
37 <return type = "integer" />
38 </method>
39 </class>
0 <class name = "zhttp_server_options" state = "draft">
1 <!--
2 Copyright (c) the Contributors as noted in the AUTHORS file.
3 This file is part of CZMQ, the high-level C binding for 0MQ:
4 http://czmq.zeromq.org.
5
6 This Source Code Form is subject to the terms of the Mozilla Public
7 License, v. 2.0. If a copy of the MPL was not distributed with this
8 file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 -->
10 zhttp server.
11
12 <constructor>
13 </constructor>
14
15 <constructor name = "from config">
16 Create options from config tree.
17 <argument name = "config" type = "zconfig" />
18 </constructor>
19
20 <destructor>
21 </destructor>
22
23 <method name = "port" >
24 Get the server listening port.
25 <return type = "integer" />
26 </method>
27
28 <method name = "set port">
29 Set the server listening port
30 <argument name = "port" type = "integer" />
31 </method>
32
33 <method name = "backend address">
34 Get the address sockets should connect to in order to receive requests.
35 <return type = "string" />
36 </method>
37
38 <method name = "set backend address">
39 Set the address sockets should connect to in order to receive requests.
40 <argument name = "address" type = "string" />
41 </method>
42 </class>
216216 <argument name = "comparator" type = "zlistx_comparator_fn" callback = "1" />
217217 </method>
218218
219 <method name = "pack" state = "draft">
220 Serialize list to a binary frame that can be sent in a message.
221 The packed format is compatible with the 'strings' type implemented by zproto:
222
223 ; A list of strings
224 list = list-count *longstr
225 list-count = number-4
226
227 ; Strings are always length + text contents
228 longstr = number-4 *VCHAR
229
230 ; Numbers are unsigned integers in network byte order
231 number-4 = 4OCTET
232
233 <return type = "zframe" fresh = "1" />
234 </method>
235
236 <constructor name = "unpack" state = "draft">
237 Unpack binary frame into a new list. Packed data must follow format
238 defined by zlistx_pack. List is set to autofree. An empty frame
239 unpacks to an empty list.
240 <argument name = "frame" type = "zframe" />
241 </constructor>
219242 </class>
102102 </method>
103103
104104 <method name = "wait">
105 The timeout should be zero or greater, or -1 to wait indefinitely.
105106 wait or poll process status, return return code
106 <argument name = "hang" type = "boolean" />
107 <argument name = "timeout" type = "integer" />
107108 <return type="integer" />
108109 </method>
109110
111 <method name = "shutdown">
112 send SIGTERM signal to the subprocess, wait for grace period and
113 eventually send SIGKILL
114 <argument name = "timeout" type = "integer" />
115 </method>
116
110117 <method name = "actor">
111 return internal actor, usefull for the polling if process died
118 return internal actor, useful for the polling if process died
112119 <return type="anything" />
113120 </method>
114121
223223 c = zchunk_t *
224224 f = zframe_t *
225225 h = zhashx_t *
226 l = zlistx_t * (DRAFT)
226227 U = zuuid_t *
227228 p = void * (sends the pointer value, only meaningful over inproc)
228229 m = zmsg_t * (sends all frames in the zmsg)
261262 f = zframe_t ** (creates zframe)
262263 U = zuuid_t * (creates a zuuid with the data)
263264 h = zhashx_t ** (creates zhashx)
265 l = zlistx_t ** (creates zlistx) (DRAFT)
264266 p = void ** (stores pointer)
265 m = zmsg_t ** (creates a zmsg with the remaing frames)
267 m = zmsg_t ** (creates a zmsg with the remaining frames)
266268 z = null, asserts empty frame (0 arguments)
267269 u = uint * (stores unsigned integer, deprecated)
268270
407409 <return type = "anything" />
408410 </method>
409411
412 <method name = "has_in" state = "draft" polymorphic = "1">
413 Check whether the socket has available message to read.
414 <return type = "boolean" />
415 </method>
416
410417 <include filename = "zsock_option.api" />
411418 </class>
77 ******************************************************************
88 -->
99
10 <!-- The following socket options are available in libzmq from version 4.3.0 -->
11
12 <method name = "router notify" polymorphic = "1">
13 Get socket option `router_notify`.
14 Available from libzmq 4.3.0.
15 <return type = "integer" fresh = "1" />
16 </method>
17
18 <method name = "set router notify" polymorphic = "1">
19 Set socket option `router_notify`.
20 Available from libzmq 4.3.0.
21 <argument name = "router notify" type = "integer" />
22 </method>
23
24 <method name = "multicast loop" polymorphic = "1">
25 Get socket option `multicast_loop`.
26 Available from libzmq 4.3.0.
27 <return type = "integer" fresh = "1" />
28 </method>
29
30 <method name = "set multicast loop" polymorphic = "1">
31 Set socket option `multicast_loop`.
32 Available from libzmq 4.3.0.
33 <argument name = "multicast loop" type = "integer" />
34 </method>
35
36 <method name = "metadata" polymorphic = "1">
37 Get socket option `metadata`.
38 Available from libzmq 4.3.0.
39 <return type = "string" fresh = "1" />
40 </method>
41
42 <method name = "set metadata" polymorphic = "1">
43 Set socket option `metadata`.
44 Available from libzmq 4.3.0.
45 <argument name = "metadata" type = "string" />
46 </method>
47
48 <method name = "loopback fastpath" polymorphic = "1">
49 Get socket option `loopback_fastpath`.
50 Available from libzmq 4.3.0.
51 <return type = "integer" fresh = "1" />
52 </method>
53
54 <method name = "set loopback fastpath" polymorphic = "1">
55 Set socket option `loopback_fastpath`.
56 Available from libzmq 4.3.0.
57 <argument name = "loopback fastpath" type = "integer" />
58 </method>
59
60 <method name = "zap enforce domain" polymorphic = "1">
61 Get socket option `zap_enforce_domain`.
62 Available from libzmq 4.3.0.
63 <return type = "integer" fresh = "1" />
64 </method>
65
66 <method name = "set zap enforce domain" polymorphic = "1">
67 Set socket option `zap_enforce_domain`.
68 Available from libzmq 4.3.0.
69 <argument name = "zap enforce domain" type = "integer" />
70 </method>
71
72 <method name = "gssapi principal nametype" polymorphic = "1">
73 Get socket option `gssapi_principal_nametype`.
74 Available from libzmq 4.3.0.
75 <return type = "integer" fresh = "1" />
76 </method>
77
78 <method name = "set gssapi principal nametype" polymorphic = "1">
79 Set socket option `gssapi_principal_nametype`.
80 Available from libzmq 4.3.0.
81 <argument name = "gssapi principal nametype" type = "integer" />
82 </method>
83
84 <method name = "gssapi service principal nametype" polymorphic = "1">
85 Get socket option `gssapi_service_principal_nametype`.
86 Available from libzmq 4.3.0.
87 <return type = "integer" fresh = "1" />
88 </method>
89
90 <method name = "set gssapi service principal nametype" polymorphic = "1">
91 Set socket option `gssapi_service_principal_nametype`.
92 Available from libzmq 4.3.0.
93 <argument name = "gssapi service principal nametype" type = "integer" />
94 </method>
95
96 <method name = "bindtodevice" polymorphic = "1">
97 Get socket option `bindtodevice`.
98 Available from libzmq 4.3.0.
99 <return type = "string" fresh = "1" />
100 </method>
101
102 <method name = "set bindtodevice" polymorphic = "1">
103 Set socket option `bindtodevice`.
104 Available from libzmq 4.3.0.
105 <argument name = "bindtodevice" type = "string" />
106 </method>
107
10108 <!-- The following socket options are available in libzmq from version 4.2.0 -->
11109
12110 <method name = "heartbeat ivl" polymorphic = "1">
8181 <method name = "catch interrupts" singleton = "1">
8282 Set default interrupt handler, so Ctrl-C or SIGTERM will set
8383 zsys_interrupted. Idempotent; safe to call multiple times.
84 Can be supressed by ZSYS_SIGHANDLER=false
84 Can be suppressed by ZSYS_SIGHANDLER=false
8585 *** This is for CZMQ internal use only and may change arbitrarily ***
8686 </method>
8787
165165 <argument name = "major" type = "integer" by_reference = "1" />
166166 <argument name = "minor" type = "integer" by_reference = "1" />
167167 <argument name = "patch" type = "integer" by_reference = "1" />
168 </method>
169
170 <method name = "sprintf hint" singleton = "1" polymorphic = "1" state = "draft">
171 Format a string using printf formatting, returning a freshly allocated
172 buffer. If there was insufficient memory, returns NULL. Free the returned
173 string using zstr_free(). The hinted version allows to optimize by using
174 a larger starting buffer size (known to/assumed by the developer) and so
175 avoid reallocations.
176
177 <argument name = "hint" type = "integer" />
178 <argument name = "format" type = "string" variadic = "1" />
179 <return type = "string" mutable = "1" />
168180 </method>
169181
170182 <method name = "sprintf" singleton = "1" polymorphic = "1">
291303 <argument name = "priority" type = "integer" />
292304 </method>
293305
306 <method name = "set thread name prefix" singleton = "1">
307 Configure the numeric prefix to each thread created for the internal
308 context's thread pool. This option is only supported on Linux.
309 If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
310 provides the default.
311 Note that this method is valid only before any socket is created.
312 <argument name = "prefix" type = "integer" />
313 </method>
314
315 <method name = "thread name prefix" singleton = "1">
316 Return thread name prefix.
317 <return type = "integer" />
318 </method>
319
320 <method name = "thread affinity cpu add" singleton = "1">
321 Adds a specific CPU to the affinity list of the ZMQ context thread pool.
322 This option is only supported on Linux.
323 Note that this method is valid only before any socket is created.
324 <argument name = "cpu" type = "integer" />
325 </method>
326
327 <method name = "thread affinity cpu remove" singleton = "1">
328 Removes a specific CPU to the affinity list of the ZMQ context thread pool.
329 This option is only supported on Linux.
330 Note that this method is valid only before any socket is created.
331 <argument name = "cpu" type = "integer" />
332 </method>
333
294334 <method name = "set max sockets" singleton = "1">
295335 Configure the number of sockets that ZeroMQ will allow. The default
296336 is 1024. The actual limit depends on the system, and you can query it
454494 <method name = "auto use fd" singleton = "1">
455495 Return use of automatic pre-allocated FDs for zsock instances.
456496 <return type = "integer" />
497 </method>
498
499 <method name = "zprintf" singleton = "1" state = "draft">
500 Print formatted string. Format is specified by variable names
501 in Python-like format style
502
503 "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
504 become
505 "key=value"
506
507 Returns freshly allocated string or NULL in a case of error.
508 Not enough memory, invalid format specifier, name not in args
509 <argument name = "format" type = "string" />
510 <argument name = "args" type = "zhash" />
511 <return type = "string" fresh = "1" />
512 </method>
513 <method name = "zprintf_error" singleton = "1" state = "draft">
514 Return error string for given format/args combination.
515
516 <argument name = "format" type = "string" />
517 <argument name = "args" type = "zhash" />
518 <return type = "string" fresh = "1" />
519 </method>
520
521 <method name = "zplprintf" singleton = "1" state = "draft">
522 Print formatted string. Format is specified by variable names
523 in Python-like format style
524
525 "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
526 become
527 "key=value"
528
529 Returns freshly allocated string or NULL in a case of error.
530 Not enough memory, invalid format specifier, name not in args
531 <argument name = "format" type = "string" />
532 <argument name = "args" type = "zconfig" />
533 <return type = "string" fresh = "1" />
534 </method>
535
536 <method name = "zplprintf_error" singleton = "1" state = "draft">
537 Return error string for given format/args combination.
538
539 <argument name = "format" type = "string" />
540 <argument name = "args" type = "zconfig" />
541 <return type = "string" fresh = "1" />
457542 </method>
458543
459544 <method name = "set logident" singleton = "1">
0 (*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 *)
6
7 unit CZMQ;
8
9 interface
10
11 uses
12 libczmq, Winapi.Windows, Winapi.Winsock2;
13
14 // forward declarations
15 type
16 IZactor = interface;
17 IZarmour = interface;
18 IZcert = interface;
19 IZcertstore = interface;
20 IZchunk = interface;
21 IZconfig = interface;
22 IZdigest = interface;
23 IZdir = interface;
24 IZdirPatch = interface;
25 IZfile = interface;
26 IZframe = interface;
27 IZhash = interface;
28 IZhashx = interface;
29 IZiflist = interface;
30 IZlist = interface;
31 IZlistx = interface;
32 IZloop = interface;
33 IZmsg = interface;
34 IZpoller = interface;
35 IZsock = interface;
36 IZuuid = interface;
37
38 // provides a simple actor framework
39 IZactor = interface
40
41 // Send a zmsg message to the actor, take ownership of the message
42 // and destroy when it has been sent.
43 function Send(var MsgP: IZmsg): Integer;
44
45 // Receive a zmsg message from the actor. Returns NULL if the actor
46 // was interrupted before the message could be received, or if there
47 // was a timeout on the actor.
48 function Recv: IZmsg;
49
50 // Return the actor's zsock handle. Use this when you absolutely need
51 // to work with the zsock instance rather than the actor.
52 function Sock: IZsock;
53
54 // Change default destructor by custom function. Actor MUST be able to handle new message instead of default $TERM.
55 procedure SetDestructor(&Destructor: TZactorDestructorFn);
56 end;
57
58 // armoured text encoding and decoding
59 IZarmour = interface
60
61 // Encode a stream of bytes into an armoured string. Returns the armoured
62 // string, or NULL if there was insufficient memory available to allocate
63 // a new string.
64 function Encode(Data: PByte; Size: NativeUInt): string;
65
66 // Decode an armoured string into a chunk. The decoded output is
67 // null-terminated, so it may be treated as a string, if that's what
68 // it was prior to encoding.
69 function Decode(const Data: string): IZchunk;
70
71 // Get the mode property.
72 function Mode: Integer;
73
74 // Get printable string for mode.
75 function ModeStr: string;
76
77 // Set the mode property.
78 procedure SetMode(Mode: Integer);
79
80 // Return true if padding is turned on.
81 function Pad: Boolean;
82
83 // Turn padding on or off. Default is on.
84 procedure SetPad(Pad: Boolean);
85
86 // Get the padding character.
87 function PadChar: AnsiChar;
88
89 // Set the padding character.
90 procedure SetPadChar(PadChar: AnsiChar);
91
92 // Return if splitting output into lines is turned on. Default is off.
93 function LineBreaks: Boolean;
94
95 // Turn splitting output into lines on or off.
96 procedure SetLineBreaks(LineBreaks: Boolean);
97
98 // Get the line length used for splitting lines.
99 function LineLength: NativeUInt;
100
101 // Set the line length used for splitting lines.
102 procedure SetLineLength(LineLength: NativeUInt);
103
104 // Print properties of object
105 procedure Print;
106 end;
107
108 // work with CURVE security certificates
109 IZcert = interface
110
111 // Return public part of key pair as 32-byte binary string
112 function PublicKey: PByte;
113
114 // Return secret part of key pair as 32-byte binary string
115 function SecretKey: PByte;
116
117 // Return public part of key pair as Z85 armored string
118 function PublicTxt: string;
119
120 // Return secret part of key pair as Z85 armored string
121 function SecretTxt: string;
122
123 // Set certificate metadata from formatted string.
124 procedure SetMeta(const Name: string; const Format: string);
125
126 // Unset certificate metadata.
127 procedure UnsetMeta(const Name: string);
128
129 // Get metadata value from certificate; if the metadata value doesn't
130 // exist, returns NULL.
131 function Meta(const Name: string): string;
132
133 // Get list of metadata fields from certificate. Caller is responsible for
134 // destroying list. Caller should not modify the values of list items.
135 function MetaKeys: IZlist;
136
137 // Save full certificate (public + secret) to file for persistent storage
138 // This creates one public file and one secret file (filename + "_secret").
139 function Save(const Filename: string): Integer;
140
141 // Save public certificate only to file for persistent storage
142 function SavePublic(const Filename: string): Integer;
143
144 // Save secret certificate only to file for persistent storage
145 function SaveSecret(const Filename: string): Integer;
146
147 // Apply certificate to socket, i.e. use for CURVE security on socket.
148 // If certificate was loaded from public file, the secret key will be
149 // undefined, and this certificate will not work successfully.
150 procedure Apply(const Socket: IZSock);
151
152 // Return copy of certificate; if certificate is NULL or we exhausted
153 // heap memory, returns NULL.
154 function Dup: IZcert;
155
156 // Return true if two certificates have the same keys
157 function Eq(const Compare: IZcert): Boolean;
158
159 // Print certificate contents to stdout
160 procedure Print;
161 end;
162
163 // work with CURVE security certificate stores
164 IZcertstore = interface
165
166 // Override the default disk loader with a custom loader fn.
167 procedure SetLoader(Loader: TZcertstoreLoader; &Destructor: TZcertstoreDestructor; State: PByte);
168
169 // Look up certificate by public key, returns zcert_t object if found,
170 // else returns NULL. The public key is provided in Z85 text format.
171 function Lookup(const PublicKey: string): IZcert;
172
173 // Insert certificate into certificate store in memory. Note that this
174 // does not save the certificate to disk. To do that, use zcert_save()
175 // directly on the certificate. Takes ownership of zcert_t object.
176 procedure Insert(var CertP: IZcert);
177
178 // Empty certificate hashtable. This wrapper exists to be friendly to bindings,
179 // which don't usually have access to struct internals.
180 procedure Empty;
181
182 // Print list of certificates in store to logging facility
183 procedure Print;
184
185 // Return a list of all the certificates in the store.
186 // The caller takes ownership of the zlistx_t object and is responsible
187 // for destroying it. The caller does not take ownership of the zcert_t
188 // objects.
189 function Certs: IZlistx;
190 end;
191
192 // work with memory chunks
193 IZchunk = interface
194
195 // Resizes chunk max_size as requested; chunk_cur size is set to zero
196 procedure Resize(Size: NativeUInt);
197
198 // Return chunk cur size
199 function Size: NativeUInt;
200
201 // Return chunk max size
202 function MaxSize: NativeUInt;
203
204 // Return chunk data
205 function Data: PByte;
206
207 // Set chunk data from user-supplied data; truncate if too large. Data may
208 // be null. Returns actual size of chunk
209 function &Set(Data: PByte; Size: NativeUInt): NativeUInt;
210
211 // Fill chunk data from user-supplied octet
212 function Fill(Filler: Byte; Size: NativeUInt): NativeUInt;
213
214 // Append user-supplied data to chunk, return resulting chunk size. If the
215 // data would exceeded the available space, it is truncated. If you want to
216 // grow the chunk to accommodate new data, use the zchunk_extend method.
217 function Append(Data: PByte; Size: NativeUInt): NativeUInt;
218
219 // Append user-supplied data to chunk, return resulting chunk size. If the
220 // data would exceeded the available space, the chunk grows in size.
221 function Extend(Data: PByte; Size: NativeUInt): NativeUInt;
222
223 // Copy as much data from 'source' into the chunk as possible; returns the
224 // new size of chunk. If all data from 'source' is used, returns exhausted
225 // on the source chunk. Source can be consumed as many times as needed until
226 // it is exhausted. If source was already exhausted, does not change chunk.
227 function Consume(const Source: IZchunk): NativeUInt;
228
229 // Returns true if the chunk was exhausted by consume methods, or if the
230 // chunk has a size of zero.
231 function Exhausted: Boolean;
232
233 // Write chunk to an open file descriptor
234 function Write(Handle: Pointer): Integer;
235
236 // Create copy of chunk, as new chunk object. Returns a fresh zchunk_t
237 // object, or null if there was not enough heap memory. If chunk is null,
238 // returns null.
239 function Dup: IZchunk;
240
241 // Return chunk data encoded as printable hex string. Caller must free
242 // string when finished with it.
243 function Strhex: string;
244
245 // Return chunk data copied into freshly allocated string
246 // Caller must free string when finished with it.
247 function Strdup: string;
248
249 // Return TRUE if chunk body is equal to string, excluding terminator
250 function Streq(const &String: string): Boolean;
251
252 // Transform zchunk into a zframe that can be sent in a message.
253 function Pack: IZframe;
254
255 // Calculate SHA1 digest for chunk, using zdigest class.
256 function Digest: string;
257
258 // Dump chunk to FILE stream, for debugging and tracing.
259 procedure Fprint(&File: Pointer);
260
261 // Dump message to stderr, for debugging and tracing.
262 // See zchunk_fprint for details
263 procedure Print;
264 end;
265
266 // work with config files written in rfc.zeromq.org/spec:4/ZPL.
267 IZconfig = interface
268
269 // Create copy of zconfig, caller MUST free the value
270 // Create copy of config, as new zconfig object. Returns a fresh zconfig_t
271 // object. If config is null, or memory was exhausted, returns null.
272 function Dup: IZconfig;
273
274 // Return name of config item
275 function Name: string;
276
277 // Return value of config item
278 function Value: string;
279
280 // Insert or update configuration key with value
281 procedure Put(const Path: string; const Value: string);
282
283 // Equivalent to zconfig_put, accepting a format specifier and variable
284 // argument list, instead of a single string value.
285 procedure Putf(const Path: string; const Format: string);
286
287 // Get value for config item into a string value; leading slash is optional
288 // and ignored.
289 function Get(const Path: string; const DefaultValue: string): string;
290
291 // Set config item name, name may be NULL
292 procedure SetName(const Name: string);
293
294 // Set new value for config item. The new value may be a string, a printf
295 // format, or NULL. Note that if string may possibly contain '%', or if it
296 // comes from an insecure source, you must use '%s' as the format, followed
297 // by the string.
298 procedure SetValue(const Format: string);
299
300 // Find our first child, if any
301 function Child: IZconfig;
302
303 // Find our first sibling, if any
304 function Next: IZconfig;
305
306 // Find a config item along a path; leading slash is optional and ignored.
307 function Locate(const Path: string): IZconfig;
308
309 // Locate the last config item at a specified depth
310 function AtDepth(Level: Integer): IZconfig;
311
312 // Execute a callback for each config item in the tree; returns zero if
313 // successful, else -1.
314 function Execute(Handler: TZconfigFct; Arg: Pointer): Integer;
315
316 // Add comment to config item before saving to disk. You can add as many
317 // comment lines as you like. If you use a null format, all comments are
318 // deleted.
319 procedure SetComment(const Format: string);
320
321 // Return comments of config item, as zlist.
322 function Comments: IZlist;
323
324 // Save a config tree to a specified ZPL text file, where a filename
325 // "-" means dump to standard output.
326 function Save(const Filename: string): Integer;
327
328 // Equivalent to zconfig_save, taking a format string instead of a fixed
329 // filename.
330 function Savef(const Format: string): Integer;
331
332 // Report filename used during zconfig_load, or NULL if none
333 function Filename: string;
334
335 // Save a config tree to a new memory chunk
336 function ChunkSave: IZchunk;
337
338 // Save a config tree to a new null terminated string
339 function StrSave: string;
340
341 // Return true if a configuration tree was loaded from a file and that
342 // file has changed in since the tree was loaded.
343 function HasChanged: Boolean;
344
345 // Destroy subtree (all children)
346 procedure RemoveSubtree;
347
348 // Print the config file to open stream
349 procedure Fprint(&File: Pointer);
350
351 // Print properties of object
352 procedure Print;
353 end;
354
355 // provides hashing functions (SHA-1 at present)
356 IZdigest = interface
357
358 // Add buffer into digest calculation
359 procedure Update(Buffer: PByte; Length: NativeUInt);
360
361 // Return final digest hash data. If built without crypto support,
362 // returns NULL.
363 function Data: PByte;
364
365 // Return final digest hash size
366 function Size: NativeUInt;
367
368 // Return digest as printable hex string; caller should not modify nor
369 // free this string. After calling this, you may not use zdigest_update()
370 // on the same digest. If built without crypto support, returns NULL.
371 function &String: string;
372 end;
373
374 // work with file-system directories
375 IZdir = interface
376
377 // Return directory path
378 function Path: string;
379
380 // Return last modification time for directory.
381 function Modified: Int64;
382
383 // Return total hierarchy size, in bytes of data contained in all files
384 // in the directory tree.
385 function Cursize: Longint;
386
387 // Return directory count
388 function Count: NativeUInt;
389
390 // Returns a sorted list of zfile objects; Each entry in the list is a pointer
391 // to a zfile_t item already allocated in the zdir tree. Do not destroy the
392 // original zdir tree until you are done with this list.
393 function List: IZlist;
394
395 // Remove directory, optionally including all files that it contains, at
396 // all levels. If force is false, will only remove the directory if empty.
397 // If force is true, will remove all files and all subdirectories.
398 procedure Remove(Force: Boolean);
399
400 // Return full contents of directory as a zdir_patch list.
401 function Resync(const Alias: string): IZlist;
402
403 // Load directory cache; returns a hash table containing the SHA-1 digests
404 // of every file in the tree. The cache is saved between runs in .cache.
405 function Cache: IZhash;
406
407 // Print contents of directory to open stream
408 procedure Fprint(&File: Pointer; Indent: Integer);
409
410 // Print contents of directory to stdout
411 procedure Print(Indent: Integer);
412 end;
413
414 // work with directory patches
415 IZdirPatch = interface
416
417 // Create copy of a patch. If the patch is null, or memory was exhausted,
418 // returns null.
419 function Dup: IZdirPatch;
420
421 // Return patch file directory path
422 function Path: string;
423
424 // Return patch file item
425 function &File: IZfile;
426
427 // Return operation
428 function Op: Integer;
429
430 // Return patch virtual file path
431 function Vpath: string;
432
433 // Calculate hash digest for file (create only)
434 procedure DigestSet;
435
436 // Return hash digest for patch file
437 function Digest: string;
438 end;
439
440 // helper functions for working with files.
441 IZfile = interface
442
443 // Duplicate a file item, returns a newly constructed item. If the file
444 // is null, or memory was exhausted, returns null.
445 function Dup: IZfile;
446
447 // Return file name, remove path if provided
448 function Filename(const Path: string): string;
449
450 // Refresh file properties from disk; this is not done automatically
451 // on access methods, otherwise it is not possible to compare directory
452 // snapshots.
453 procedure Restat;
454
455 // Return when the file was last modified. If you want this to reflect the
456 // current situation, call zfile_restat before checking this property.
457 function Modified: Int64;
458
459 // Return the last-known size of the file. If you want this to reflect the
460 // current situation, call zfile_restat before checking this property.
461 function Cursize: Longint;
462
463 // Return true if the file is a directory. If you want this to reflect
464 // any external changes, call zfile_restat before checking this property.
465 function IsDirectory: Boolean;
466
467 // Return true if the file is a regular file. If you want this to reflect
468 // any external changes, call zfile_restat before checking this property.
469 function IsRegular: Boolean;
470
471 // Return true if the file is readable by this process. If you want this to
472 // reflect any external changes, call zfile_restat before checking this
473 // property.
474 function IsReadable: Boolean;
475
476 // Return true if the file is writeable by this process. If you want this
477 // to reflect any external changes, call zfile_restat before checking this
478 // property.
479 function IsWriteable: Boolean;
480
481 // Check if file has stopped changing and can be safely processed.
482 // Updates the file statistics from disk at every call.
483 function IsStable: Boolean;
484
485 // Return true if the file was changed on disk since the zfile_t object
486 // was created, or the last zfile_restat() call made on it.
487 function HasChanged: Boolean;
488
489 // Remove the file from disk
490 procedure Remove;
491
492 // Open file for reading
493 // Returns 0 if OK, -1 if not found or not accessible
494 function Input: Integer;
495
496 // Open file for writing, creating directory if needed
497 // File is created if necessary; chunks can be written to file at any
498 // location. Returns 0 if OK, -1 if error.
499 function Output: Integer;
500
501 // Read chunk from file at specified position. If this was the last chunk,
502 // sets the eof property. Returns a null chunk in case of error.
503 function Read(Bytes: NativeUInt; Offset: Longint): IZchunk;
504
505 // Returns true if zfile_read() just read the last chunk in the file.
506 function Eof: Boolean;
507
508 // Write chunk to file at specified position
509 // Return 0 if OK, else -1
510 function Write(const Chunk: IZchunk; Offset: Longint): Integer;
511
512 // Read next line of text from file. Returns a pointer to the text line,
513 // or NULL if there was nothing more to read from the file.
514 function Readln: string;
515
516 // Close file, if open
517 procedure Close;
518
519 // Return file handle, if opened
520 function Handle: Pointer;
521
522 // Calculate SHA1 digest for file, using zdigest class.
523 function Digest: string;
524 end;
525
526 // working with single message frames
527 IZframe = interface
528
529 // Return number of bytes in frame data
530 function Size: NativeUInt;
531
532 // Return address of frame data
533 function Data: PByte;
534
535 // Return meta data property for frame
536 // The caller shall not modify or free the returned value, which shall be
537 // owned by the message.
538 function Meta(const &Property: string): string;
539
540 // Create a new frame that duplicates an existing frame. If frame is null,
541 // or memory was exhausted, returns null.
542 function Dup: IZframe;
543
544 // Return frame data encoded as printable hex string, useful for 0MQ UUIDs.
545 // Caller must free string when finished with it.
546 function Strhex: string;
547
548 // Return frame data copied into freshly allocated string
549 // Caller must free string when finished with it.
550 function Strdup: string;
551
552 // Return TRUE if frame body is equal to string, excluding terminator
553 function Streq(const &String: string): Boolean;
554
555 // Return frame MORE indicator (1 or 0), set when reading frame from socket
556 // or by the zframe_set_more() method
557 function More: Integer;
558
559 // Set frame MORE indicator (1 or 0). Note this is NOT used when sending
560 // frame to socket, you have to specify flag explicitly.
561 procedure SetMore(More: Integer);
562
563 // Return frame routing ID, if the frame came from a ZMQ_SERVER socket.
564 // Else returns zero.
565 function RoutingId: Cardinal;
566
567 // Set routing ID on frame. This is used if/when the frame is sent to a
568 // ZMQ_SERVER socket.
569 procedure SetRoutingId(RoutingId: Cardinal);
570
571 // Return frame group of radio-dish pattern.
572 function Group: string;
573
574 // Set group on frame. This is used if/when the frame is sent to a
575 // ZMQ_RADIO socket.
576 // Return -1 on error, 0 on success.
577 function SetGroup(const Group: string): Integer;
578
579 // Return TRUE if two frames have identical size and data
580 // If either frame is NULL, equality is always false.
581 function Eq(const Other: IZframe): Boolean;
582
583 // Set new contents for frame
584 procedure Reset(Data: PByte; Size: NativeUInt);
585
586 // Send message to zsys log sink (may be stdout, or system facility as
587 // configured by zsys_set_logstream). Prefix shows before frame, if not null.
588 procedure Print(const Prefix: string);
589 end;
590
591 // generic type-free hash container (simple)
592 IZhash = interface
593
594 // Insert item into hash table with specified key and item.
595 // If key is already present returns -1 and leaves existing item unchanged
596 // Returns 0 on success.
597 function Insert(const Key: string; Item: Pointer): Integer;
598
599 // Update item into hash table with specified key and item.
600 // If key is already present, destroys old item and inserts new one.
601 // Use free_fn method to ensure deallocator is properly called on item.
602 procedure Update(const Key: string; Item: Pointer);
603
604 // Remove an item specified by key from the hash table. If there was no such
605 // item, this function does nothing.
606 procedure Delete(const Key: string);
607
608 // Return the item at the specified key, or null
609 function Lookup(const Key: string): Pointer;
610
611 // Reindexes an item from an old key to a new key. If there was no such
612 // item, does nothing. Returns 0 if successful, else -1.
613 function Rename(const OldKey: string; const NewKey: string): Integer;
614
615 // Set a free function for the specified hash table item. When the item is
616 // destroyed, the free function, if any, is called on that item.
617 // Use this when hash items are dynamically allocated, to ensure that
618 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
619 // Returns the item, or NULL if there is no such item.
620 function Freefn(const Key: string; FreeFn: TZhashFreeFn): Pointer;
621
622 // Return the number of keys/items in the hash table
623 function Size: NativeUInt;
624
625 // Make copy of hash table; if supplied table is null, returns null.
626 // Does not copy items themselves. Rebuilds new table so may be slow on
627 // very large tables. NOTE: only works with item values that are strings
628 // since there's no other way to know how to duplicate the item value.
629 function Dup: IZhash;
630
631 // Return keys for items in table
632 function Keys: IZlist;
633
634 // Simple iterator; returns first item in hash table, in no given order,
635 // or NULL if the table is empty. This method is simpler to use than the
636 // foreach() method, which is deprecated. To access the key for this item
637 // use zhash_cursor(). NOTE: do NOT modify the table while iterating.
638 function First: Pointer;
639
640 // Simple iterator; returns next item in hash table, in no given order,
641 // or NULL if the last item was already returned. Use this together with
642 // zhash_first() to process all items in a hash table. If you need the
643 // items in sorted order, use zhash_keys() and then zlist_sort(). To
644 // access the key for this item use zhash_cursor(). NOTE: do NOT modify
645 // the table while iterating.
646 function Next: Pointer;
647
648 // After a successful first/next method, returns the key for the item that
649 // was returned. This is a constant string that you may not modify or
650 // deallocate, and which lasts as long as the item in the hash. After an
651 // unsuccessful first/next, returns NULL.
652 function Cursor: string;
653
654 // Add a comment to hash table before saving to disk. You can add as many
655 // comment lines as you like. These comment lines are discarded when loading
656 // the file. If you use a null format, all comments are deleted.
657 procedure Comment(const Format: string);
658
659 // Serialize hash table to a binary frame that can be sent in a message.
660 // The packed format is compatible with the 'dictionary' type defined in
661 // http://rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
662 //
663 // ; A list of name/value pairs
664 // dictionary = dict-count *( dict-name dict-value )
665 // dict-count = number-4
666 // dict-value = longstr
667 // dict-name = string
668 //
669 // ; Strings are always length + text contents
670 // longstr = number-4 *VCHAR
671 // string = number-1 *VCHAR
672 //
673 // ; Numbers are unsigned integers in network byte order
674 // number-1 = 1OCTET
675 // number-4 = 4OCTET
676 //
677 // Comments are not included in the packed data. Item values MUST be
678 // strings.
679 function Pack: IZframe;
680
681 // Save hash table to a text file in name=value format. Hash values must be
682 // printable strings; keys may not contain '=' character. Returns 0 if OK,
683 // else -1 if a file error occurred.
684 function Save(const Filename: string): Integer;
685
686 // Load hash table from a text file in name=value format; hash table must
687 // already exist. Hash values must printable strings; keys may not contain
688 // '=' character. Returns 0 if OK, else -1 if a file was not readable.
689 function Load(const Filename: string): Integer;
690
691 // When a hash table was loaded from a file by zhash_load, this method will
692 // reload the file if it has been modified since, and is "stable", i.e. not
693 // still changing. Returns 0 if OK, -1 if there was an error reloading the
694 // file.
695 function Refresh: Integer;
696
697 // Set hash for automatic value destruction. Note that this assumes that
698 // values are NULL-terminated strings. Do not use with different types.
699 procedure Autofree;
700 end;
701
702 // extended generic type-free hash container
703 IZhashx = interface
704
705 // Insert item into hash table with specified key and item.
706 // If key is already present returns -1 and leaves existing item unchanged
707 // Returns 0 on success.
708 function Insert(Key: Pointer; Item: Pointer): Integer;
709
710 // Update or insert item into hash table with specified key and item. If the
711 // key is already present, destroys old item and inserts new one. If you set
712 // a container item destructor, this is called on the old value. If the key
713 // was not already present, inserts a new item. Sets the hash cursor to the
714 // new item.
715 procedure Update(Key: Pointer; Item: Pointer);
716
717 // Remove an item specified by key from the hash table. If there was no such
718 // item, this function does nothing.
719 procedure Delete(Key: Pointer);
720
721 // Delete all items from the hash table. If the key destructor is
722 // set, calls it on every key. If the item destructor is set, calls
723 // it on every item.
724 procedure Purge;
725
726 // Return the item at the specified key, or null
727 function Lookup(Key: Pointer): Pointer;
728
729 // Reindexes an item from an old key to a new key. If there was no such
730 // item, does nothing. Returns 0 if successful, else -1.
731 function Rename(OldKey: Pointer; NewKey: Pointer): Integer;
732
733 // Set a free function for the specified hash table item. When the item is
734 // destroyed, the free function, if any, is called on that item.
735 // Use this when hash items are dynamically allocated, to ensure that
736 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
737 // Returns the item, or NULL if there is no such item.
738 function Freefn(Key: Pointer; FreeFn: TZhashxFreeFn): Pointer;
739
740 // Return the number of keys/items in the hash table
741 function Size: NativeUInt;
742
743 // Return a zlistx_t containing the keys for the items in the
744 // table. Uses the key_duplicator to duplicate all keys and sets the
745 // key_destructor as destructor for the list.
746 function Keys: IZlistx;
747
748 // Return a zlistx_t containing the values for the items in the
749 // table. Uses the duplicator to duplicate all items and sets the
750 // destructor as destructor for the list.
751 function Values: IZlistx;
752
753 // Simple iterator; returns first item in hash table, in no given order,
754 // or NULL if the table is empty. This method is simpler to use than the
755 // foreach() method, which is deprecated. To access the key for this item
756 // use zhashx_cursor(). NOTE: do NOT modify the table while iterating.
757 function First: Pointer;
758
759 // Simple iterator; returns next item in hash table, in no given order,
760 // or NULL if the last item was already returned. Use this together with
761 // zhashx_first() to process all items in a hash table. If you need the
762 // items in sorted order, use zhashx_keys() and then zlistx_sort(). To
763 // access the key for this item use zhashx_cursor(). NOTE: do NOT modify
764 // the table while iterating.
765 function Next: Pointer;
766
767 // After a successful first/next method, returns the key for the item that
768 // was returned. This is a constant string that you may not modify or
769 // deallocate, and which lasts as long as the item in the hash. After an
770 // unsuccessful first/next, returns NULL.
771 function Cursor: Pointer;
772
773 // Add a comment to hash table before saving to disk. You can add as many
774 // comment lines as you like. These comment lines are discarded when loading
775 // the file. If you use a null format, all comments are deleted.
776 procedure Comment(const Format: string);
777
778 // Save hash table to a text file in name=value format. Hash values must be
779 // printable strings; keys may not contain '=' character. Returns 0 if OK,
780 // else -1 if a file error occurred.
781 function Save(const Filename: string): Integer;
782
783 // Load hash table from a text file in name=value format; hash table must
784 // already exist. Hash values must printable strings; keys may not contain
785 // '=' character. Returns 0 if OK, else -1 if a file was not readable.
786 function Load(const Filename: string): Integer;
787
788 // When a hash table was loaded from a file by zhashx_load, this method will
789 // reload the file if it has been modified since, and is "stable", i.e. not
790 // still changing. Returns 0 if OK, -1 if there was an error reloading the
791 // file.
792 function Refresh: Integer;
793
794 // Serialize hash table to a binary frame that can be sent in a message.
795 // The packed format is compatible with the 'dictionary' type defined in
796 // http://rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
797 //
798 // ; A list of name/value pairs
799 // dictionary = dict-count *( dict-name dict-value )
800 // dict-count = number-4
801 // dict-value = longstr
802 // dict-name = string
803 //
804 // ; Strings are always length + text contents
805 // longstr = number-4 *VCHAR
806 // string = number-1 *VCHAR
807 //
808 // ; Numbers are unsigned integers in network byte order
809 // number-1 = 1OCTET
810 // number-4 = 4OCTET
811 //
812 // Comments are not included in the packed data. Item values MUST be
813 // strings.
814 function Pack: IZframe;
815
816 // Same as pack but uses a user-defined serializer function to convert items
817 // into longstr.
818 function PackOwn(Serializer: TZhashxSerializerFn): IZframe;
819
820 // Make a copy of the list; items are duplicated if you set a duplicator
821 // for the list, otherwise not. Copying a null reference returns a null
822 // reference. Note that this method's behavior changed slightly for CZMQ
823 // v3.x, as it does not set nor respect autofree. It does however let you
824 // duplicate any hash table safely. The old behavior is in zhashx_dup_v2.
825 function Dup: IZhashx;
826
827 // Set a user-defined deallocator for hash items; by default items are not
828 // freed when the hash is destroyed.
829 procedure SetDestructor(&Destructor: TZhashxDestructorFn);
830
831 // Set a user-defined duplicator for hash items; by default items are not
832 // copied when the hash is duplicated.
833 procedure SetDuplicator(Duplicator: TZhashxDuplicatorFn);
834
835 // Set a user-defined deallocator for keys; by default keys are freed
836 // when the hash is destroyed using free().
837 procedure SetKeyDestructor(&Destructor: TZhashxDestructorFn);
838
839 // Set a user-defined duplicator for keys; by default keys are duplicated
840 // using strdup.
841 procedure SetKeyDuplicator(Duplicator: TZhashxDuplicatorFn);
842
843 // Set a user-defined comparator for keys; by default keys are
844 // compared using strcmp.
845 // The callback function should return zero (0) on matching
846 // items.
847 procedure SetKeyComparator(Comparator: TZhashxComparatorFn);
848
849 // Set a user-defined hash function for keys; by default keys are
850 // hashed by a modified Bernstein hashing function.
851 procedure SetKeyHasher(Hasher: TZhashxHashFn);
852
853 // Make copy of hash table; if supplied table is null, returns null.
854 // Does not copy items themselves. Rebuilds new table so may be slow on
855 // very large tables. NOTE: only works with item values that are strings
856 // since there's no other way to know how to duplicate the item value.
857 function DupV2: IZhashx;
858 end;
859
860 // List of network interfaces available on system
861 IZiflist = interface
862
863 // Reload network interfaces from system
864 procedure Reload;
865
866 // Return the number of network interfaces on system
867 function Size: NativeUInt;
868
869 // Get first network interface, return NULL if there are none
870 function First: string;
871
872 // Get next network interface, return NULL if we hit the last one
873 function Next: string;
874
875 // Return the current interface IP address as a printable string
876 function Address: string;
877
878 // Return the current interface broadcast address as a printable string
879 function Broadcast: string;
880
881 // Return the current interface network mask as a printable string
882 function Netmask: string;
883
884 // Return the list of interfaces.
885 procedure Print;
886
887 // Reload network interfaces from system, including IPv6
888 procedure ReloadIpv6;
889
890 // Return true if the current interface uses IPv6
891 function IsIpv6: Boolean;
892 end;
893
894 // simple generic list container
895 IZlist = interface
896
897 // Return the item at the head of list. If the list is empty, returns NULL.
898 // Leaves cursor pointing at the head item, or NULL if the list is empty.
899 function First: Pointer;
900
901 // Return the next item. If the list is empty, returns NULL. To move to
902 // the start of the list call zlist_first (). Advances the cursor.
903 function Next: Pointer;
904
905 // Return the item at the tail of list. If the list is empty, returns NULL.
906 // Leaves cursor pointing at the tail item, or NULL if the list is empty.
907 function Last: Pointer;
908
909 // Return first item in the list, or null, leaves the cursor
910 function Head: Pointer;
911
912 // Return last item in the list, or null, leaves the cursor
913 function Tail: Pointer;
914
915 // Return the current item of list. If the list is empty, returns NULL.
916 // Leaves cursor pointing at the current item, or NULL if the list is empty.
917 function Item: Pointer;
918
919 // Append an item to the end of the list, return 0 if OK or -1 if this
920 // failed for some reason (out of memory). Note that if a duplicator has
921 // been set, this method will also duplicate the item.
922 function Append(Item: Pointer): Integer;
923
924 // Push an item to the start of the list, return 0 if OK or -1 if this
925 // failed for some reason (out of memory). Note that if a duplicator has
926 // been set, this method will also duplicate the item.
927 function Push(Item: Pointer): Integer;
928
929 // Pop the item off the start of the list, if any
930 function Pop: Pointer;
931
932 // Checks if an item already is present. Uses compare method to determine if
933 // items are equal. If the compare method is NULL the check will only compare
934 // pointers. Returns true if item is present else false.
935 function Exists(Item: Pointer): Boolean;
936
937 // Remove the specified item from the list if present
938 procedure Remove(Item: Pointer);
939
940 // Make a copy of list. If the list has autofree set, the copied list will
941 // duplicate all items, which must be strings. Otherwise, the list will hold
942 // pointers back to the items in the original list. If list is null, returns
943 // NULL.
944 function Dup: IZlist;
945
946 // Purge all items from list
947 procedure Purge;
948
949 // Return number of items in the list
950 function Size: NativeUInt;
951
952 // Sort the list. If the compare function is null, sorts the list by
953 // ascending key value using a straight ASCII comparison. If you specify
954 // a compare function, this decides how items are sorted. The sort is not
955 // stable, so may reorder items with the same keys. The algorithm used is
956 // combsort, a compromise between performance and simplicity.
957 procedure Sort(Compare: TZlistCompareFn);
958
959 // Set list for automatic item destruction; item values MUST be strings.
960 // By default a list item refers to a value held elsewhere. When you set
961 // this, each time you append or push a list item, zlist will take a copy
962 // of the string value. Then, when you destroy the list, it will free all
963 // item values automatically. If you use any other technique to allocate
964 // list values, you must free them explicitly before destroying the list.
965 // The usual technique is to pop list items and destroy them, until the
966 // list is empty.
967 procedure Autofree;
968
969 // Sets a compare function for this list. The function compares two items.
970 // It returns an integer less than, equal to, or greater than zero if the
971 // first item is found, respectively, to be less than, to match, or be
972 // greater than the second item.
973 // This function is used for sorting, removal and exists checking.
974 procedure Comparefn(Fn: TZlistCompareFn);
975
976 // Set a free function for the specified list item. When the item is
977 // destroyed, the free function, if any, is called on that item.
978 // Use this when list items are dynamically allocated, to ensure that
979 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
980 // Returns the item, or NULL if there is no such item.
981 function Freefn(Item: Pointer; Fn: TZlistFreeFn; AtTail: Boolean): Pointer;
982 end;
983
984 // extended generic list container
985 IZlistx = interface
986
987 // Add an item to the head of the list. Calls the item duplicator, if any,
988 // on the item. Resets cursor to list head. Returns an item handle on
989 // success, NULL if memory was exhausted.
990 function AddStart(Item: Pointer): Pointer;
991
992 // Add an item to the tail of the list. Calls the item duplicator, if any,
993 // on the item. Resets cursor to list head. Returns an item handle on
994 // success, NULL if memory was exhausted.
995 function AddEnd(Item: Pointer): Pointer;
996
997 // Return the number of items in the list
998 function Size: NativeUInt;
999
1000 // Return first item in the list, or null, leaves the cursor
1001 function Head: Pointer;
1002
1003 // Return last item in the list, or null, leaves the cursor
1004 function Tail: Pointer;
1005
1006 // Return the item at the head of list. If the list is empty, returns NULL.
1007 // Leaves cursor pointing at the head item, or NULL if the list is empty.
1008 function First: Pointer;
1009
1010 // Return the next item. At the end of the list (or in an empty list),
1011 // returns NULL. Use repeated zlistx_next () calls to work through the list
1012 // from zlistx_first (). First time, acts as zlistx_first().
1013 function Next: Pointer;
1014
1015 // Return the previous item. At the start of the list (or in an empty list),
1016 // returns NULL. Use repeated zlistx_prev () calls to work through the list
1017 // backwards from zlistx_last (). First time, acts as zlistx_last().
1018 function Prev: Pointer;
1019
1020 // Return the item at the tail of list. If the list is empty, returns NULL.
1021 // Leaves cursor pointing at the tail item, or NULL if the list is empty.
1022 function Last: Pointer;
1023
1024 // Returns the value of the item at the cursor, or NULL if the cursor is
1025 // not pointing to an item.
1026 function Item: Pointer;
1027
1028 // Returns the handle of the item at the cursor, or NULL if the cursor is
1029 // not pointing to an item.
1030 function Cursor: Pointer;
1031
1032 // Find an item in the list, searching from the start. Uses the item
1033 // comparator, if any, else compares item values directly. Returns the
1034 // item handle found, or NULL. Sets the cursor to the found item, if any.
1035 function Find(Item: Pointer): Pointer;
1036
1037 // Detach an item from the list, using its handle. The item is not modified,
1038 // and the caller is responsible for destroying it if necessary. If handle is
1039 // null, detaches the first item on the list. Returns item that was detached,
1040 // or null if none was. If cursor was at item, moves cursor to previous item,
1041 // so you can detach items while iterating forwards through a list.
1042 function Detach(Handle: Pointer): Pointer;
1043
1044 // Detach item at the cursor, if any, from the list. The item is not modified,
1045 // and the caller is responsible for destroying it as necessary. Returns item
1046 // that was detached, or null if none was. Moves cursor to previous item, so
1047 // you can detach items while iterating forwards through a list.
1048 function DetachCur: Pointer;
1049
1050 // Delete an item, using its handle. Calls the item destructor is any is
1051 // set. If handle is null, deletes the first item on the list. Returns 0
1052 // if an item was deleted, -1 if not. If cursor was at item, moves cursor
1053 // to previous item, so you can delete items while iterating forwards
1054 // through a list.
1055 function Delete(Handle: Pointer): Integer;
1056
1057 // Move an item to the start of the list, via its handle.
1058 procedure MoveStart(Handle: Pointer);
1059
1060 // Move an item to the end of the list, via its handle.
1061 procedure MoveEnd(Handle: Pointer);
1062
1063 // Remove all items from the list, and destroy them if the item destructor
1064 // is set.
1065 procedure Purge;
1066
1067 // Sort the list. If an item comparator was set, calls that to compare
1068 // items, otherwise compares on item value. The sort is not stable, so may
1069 // reorder equal items.
1070 procedure Sort;
1071
1072 // Create a new node and insert it into a sorted list. Calls the item
1073 // duplicator, if any, on the item. If low_value is true, starts searching
1074 // from the start of the list, otherwise searches from the end. Use the item
1075 // comparator, if any, to find where to place the new node. Returns a handle
1076 // to the new node, or NULL if memory was exhausted. Resets the cursor to the
1077 // list head.
1078 function Insert(Item: Pointer; LowValue: Boolean): Pointer;
1079
1080 // Move an item, specified by handle, into position in a sorted list. Uses
1081 // the item comparator, if any, to determine the new location. If low_value
1082 // is true, starts searching from the start of the list, otherwise searches
1083 // from the end.
1084 procedure Reorder(Handle: Pointer; LowValue: Boolean);
1085
1086 // Make a copy of the list; items are duplicated if you set a duplicator
1087 // for the list, otherwise not. Copying a null reference returns a null
1088 // reference.
1089 function Dup: IZlistx;
1090
1091 // Set a user-defined deallocator for list items; by default items are not
1092 // freed when the list is destroyed.
1093 procedure SetDestructor(&Destructor: TZlistxDestructorFn);
1094
1095 // Set a user-defined duplicator for list items; by default items are not
1096 // copied when the list is duplicated.
1097 procedure SetDuplicator(Duplicator: TZlistxDuplicatorFn);
1098
1099 // Set a user-defined comparator for zlistx_find and zlistx_sort; the method
1100 // must return -1, 0, or 1 depending on whether item1 is less than, equal to,
1101 // or greater than, item2.
1102 procedure SetComparator(Comparator: TZlistxComparatorFn);
1103
1104 // Serialize list to a binary frame that can be sent in a message.
1105 // The packed format is compatible with the 'strings' type implemented by zproto:
1106 //
1107 // ; A list of strings
1108 // list = list-count *longstr
1109 // list-count = number-4
1110 //
1111 // ; Strings are always length + text contents
1112 // longstr = number-4 *VCHAR
1113 //
1114 // ; Numbers are unsigned integers in network byte order
1115 // number-4 = 4OCTET
1116 function Pack: IZframe;
1117 end;
1118
1119 // event-driven reactor
1120 IZloop = interface
1121
1122 // Register socket reader with the reactor. When the reader has messages,
1123 // the reactor will call the handler, passing the arg. Returns 0 if OK, -1
1124 // if there was an error. If you register the same socket more than once,
1125 // each instance will invoke its corresponding handler.
1126 function Reader(const Sock: IZsock; Handler: TZloopReaderFn; Arg: Pointer): Integer;
1127
1128 // Cancel a socket reader from the reactor. If multiple readers exist for
1129 // same socket, cancels ALL of them.
1130 procedure ReaderEnd(const Sock: IZsock);
1131
1132 // Configure a registered reader to ignore errors. If you do not set this,
1133 // then readers that have errors are removed from the reactor silently.
1134 procedure ReaderSetTolerant(const Sock: IZsock);
1135
1136 // Register low-level libzmq pollitem with the reactor. When the pollitem
1137 // is ready, will call the handler, passing the arg. Returns 0 if OK, -1
1138 // if there was an error. If you register the pollitem more than once, each
1139 // instance will invoke its corresponding handler. A pollitem with
1140 // socket=NULL and fd=0 means 'poll on FD zero'.
1141 function Poller(Item: Pointer; Handler: TZloopFn; Arg: Pointer): Integer;
1142
1143 // Cancel a pollitem from the reactor, specified by socket or FD. If both
1144 // are specified, uses only socket. If multiple poll items exist for same
1145 // socket/FD, cancels ALL of them.
1146 procedure PollerEnd(Item: Pointer);
1147
1148 // Configure a registered poller to ignore errors. If you do not set this,
1149 // then poller that have errors are removed from the reactor silently.
1150 procedure PollerSetTolerant(Item: Pointer);
1151
1152 // Register a timer that expires after some delay and repeats some number of
1153 // times. At each expiry, will call the handler, passing the arg. To run a
1154 // timer forever, use 0 times. Returns a timer_id that is used to cancel the
1155 // timer in the future. Returns -1 if there was an error.
1156 function Timer(Delay: NativeUInt; Times: NativeUInt; Handler: TZloopTimerFn; Arg: Pointer): Integer;
1157
1158 // Cancel a specific timer identified by a specific timer_id (as returned by
1159 // zloop_timer).
1160 function TimerEnd(TimerId: Integer): Integer;
1161
1162 // Register a ticket timer. Ticket timers are very fast in the case where
1163 // you use a lot of timers (thousands), and frequently remove and add them.
1164 // The main use case is expiry timers for servers that handle many clients,
1165 // and which reset the expiry timer for each message received from a client.
1166 // Whereas normal timers perform poorly as the number of clients grows, the
1167 // cost of ticket timers is constant, no matter the number of clients. You
1168 // must set the ticket delay using zloop_set_ticket_delay before creating a
1169 // ticket. Returns a handle to the timer that you should use in
1170 // zloop_ticket_reset and zloop_ticket_delete.
1171 function Ticket(Handler: TZloopTimerFn; Arg: Pointer): Pointer;
1172
1173 // Reset a ticket timer, which moves it to the end of the ticket list and
1174 // resets its execution time. This is a very fast operation.
1175 procedure TicketReset(Handle: Pointer);
1176
1177 // Delete a ticket timer. We do not actually delete the ticket here, as
1178 // other code may still refer to the ticket. We mark as deleted, and remove
1179 // later and safely.
1180 procedure TicketDelete(Handle: Pointer);
1181
1182 // Set the ticket delay, which applies to all tickets. If you lower the
1183 // delay and there are already tickets created, the results are undefined.
1184 procedure SetTicketDelay(TicketDelay: NativeUInt);
1185
1186 // Set hard limit on number of timers allowed. Setting more than a small
1187 // number of timers (10-100) can have a dramatic impact on the performance
1188 // of the reactor. For high-volume cases, use ticket timers. If the hard
1189 // limit is reached, the reactor stops creating new timers and logs an
1190 // error.
1191 procedure SetMaxTimers(MaxTimers: NativeUInt);
1192
1193 // Set verbose tracing of reactor on/off. The default verbose setting is
1194 // off (false).
1195 procedure SetVerbose(Verbose: Boolean);
1196
1197 // By default the reactor stops if the process receives a SIGINT or SIGTERM
1198 // signal. This makes it impossible to shut-down message based architectures
1199 // like zactors. This method lets you switch off break handling. The default
1200 // nonstop setting is off (false).
1201 procedure SetNonstop(Nonstop: Boolean);
1202
1203 // Start the reactor. Takes control of the thread and returns when the 0MQ
1204 // context is terminated or the process is interrupted, or any event handler
1205 // returns -1. Event handlers may register new sockets and timers, and
1206 // cancel sockets. Returns 0 if interrupted, -1 if canceled by a handler.
1207 function Start: Integer;
1208 end;
1209
1210 // working with multipart messages
1211 IZmsg = interface
1212
1213 // Return size of message, i.e. number of frames (0 or more).
1214 function Size: NativeUInt;
1215
1216 // Return total size of all frames in message.
1217 function ContentSize: NativeUInt;
1218
1219 // Return message routing ID, if the message came from a ZMQ_SERVER socket.
1220 // Else returns zero.
1221 function RoutingId: Cardinal;
1222
1223 // Set routing ID on message. This is used if/when the message is sent to a
1224 // ZMQ_SERVER socket.
1225 procedure SetRoutingId(RoutingId: Cardinal);
1226
1227 // Push frame to the front of the message, i.e. before all other frames.
1228 // Message takes ownership of frame, will destroy it when message is sent.
1229 // Returns 0 on success, -1 on error. Deprecates zmsg_push, which did not
1230 // nullify the caller's frame reference.
1231 function Prepend(var FrameP: IZframe): Integer;
1232
1233 // Add frame to the end of the message, i.e. after all other frames.
1234 // Message takes ownership of frame, will destroy it when message is sent.
1235 // Returns 0 on success. Deprecates zmsg_add, which did not nullify the
1236 // caller's frame reference.
1237 function Append(var FrameP: IZframe): Integer;
1238
1239 // Remove first frame from message, if any. Returns frame, or NULL.
1240 function Pop: IZframe;
1241
1242 // Push block of memory to front of message, as a new frame.
1243 // Returns 0 on success, -1 on error.
1244 function Pushmem(Data: PByte; Size: NativeUInt): Integer;
1245
1246 // Add block of memory to the end of the message, as a new frame.
1247 // Returns 0 on success, -1 on error.
1248 function Addmem(Data: PByte; Size: NativeUInt): Integer;
1249
1250 // Push string as new frame to front of message.
1251 // Returns 0 on success, -1 on error.
1252 function Pushstr(const &String: string): Integer;
1253
1254 // Push string as new frame to end of message.
1255 // Returns 0 on success, -1 on error.
1256 function Addstr(const &String: string): Integer;
1257
1258 // Push formatted string as new frame to front of message.
1259 // Returns 0 on success, -1 on error.
1260 function Pushstrf(const Format: string): Integer;
1261
1262 // Push formatted string as new frame to end of message.
1263 // Returns 0 on success, -1 on error.
1264 function Addstrf(const Format: string): Integer;
1265
1266 // Pop frame off front of message, return as fresh string. If there were
1267 // no more frames in the message, returns NULL.
1268 function Popstr: string;
1269
1270 // Push encoded message as a new frame. Message takes ownership of
1271 // submessage, so the original is destroyed in this call. Returns 0 on
1272 // success, -1 on error.
1273 function Addmsg(var MsgP: IZmsg): Integer;
1274
1275 // Remove first submessage from message, if any. Returns zmsg_t, or NULL if
1276 // decoding was not successful.
1277 function Popmsg: IZmsg;
1278
1279 // Remove specified frame from list, if present. Does not destroy frame.
1280 procedure Remove(const Frame: IZframe);
1281
1282 // Set cursor to first frame in message. Returns frame, or NULL, if the
1283 // message is empty. Use this to navigate the frames as a list.
1284 function First: IZframe;
1285
1286 // Return the next frame. If there are no more frames, returns NULL. To move
1287 // to the first frame call zmsg_first(). Advances the cursor.
1288 function Next: IZframe;
1289
1290 // Return the last frame. If there are no frames, returns NULL.
1291 function Last: IZframe;
1292
1293 // Save message to an open file, return 0 if OK, else -1. The message is
1294 // saved as a series of frames, each with length and data. Note that the
1295 // file is NOT guaranteed to be portable between operating systems, not
1296 // versions of CZMQ. The file format is at present undocumented and liable
1297 // to arbitrary change.
1298 function Save(&File: Pointer): Integer;
1299
1300 // Serialize multipart message to a single message frame. Use this method
1301 // to send structured messages across transports that do not support
1302 // multipart data. Allocates and returns a new frame containing the
1303 // serialized message. To decode a serialized message frame, use
1304 // zmsg_decode ().
1305 function Encode: IZframe;
1306
1307 // Create copy of message, as new message object. Returns a fresh zmsg_t
1308 // object. If message is null, or memory was exhausted, returns null.
1309 function Dup: IZmsg;
1310
1311 // Send message to zsys log sink (may be stdout, or system facility as
1312 // configured by zsys_set_logstream).
1313 procedure Print;
1314
1315 // Return true if the two messages have the same number of frames and each
1316 // frame in the first message is identical to the corresponding frame in the
1317 // other message. As with zframe_eq, return false if either message is NULL.
1318 function Eq(const Other: IZmsg): Boolean;
1319
1320 // Return signal value, 0 or greater, if message is a signal, -1 if not.
1321 function Signal: Integer;
1322 end;
1323
1324 // event-driven reactor
1325 IZpoller = interface
1326
1327 // Add a reader to be polled. Returns 0 if OK, -1 on failure. The reader may
1328 // be a libzmq void * socket, a zsock_t instance, or a zactor_t instance.
1329 function Add(const Reader: IZSock): Integer;
1330
1331 // Remove a reader from the poller; returns 0 if OK, -1 on failure. The reader
1332 // must have been passed during construction, or in an zpoller_add () call.
1333 function Remove(Reader: Pointer): Integer;
1334
1335 // By default the poller stops if the process receives a SIGINT or SIGTERM
1336 // signal. This makes it impossible to shut-down message based architectures
1337 // like zactors. This method lets you switch off break handling. The default
1338 // nonstop setting is off (false).
1339 procedure SetNonstop(Nonstop: Boolean);
1340
1341 // Poll the registered readers for I/O, return first reader that has input.
1342 // The reader will be a libzmq void * socket, or a zsock_t or zactor_t
1343 // instance as specified in zpoller_new/zpoller_add. The timeout should be
1344 // zero or greater, or -1 to wait indefinitely. Socket priority is defined
1345 // by their order in the poll list. If you need a balanced poll, use the low
1346 // level zmq_poll method directly. If the poll call was interrupted (SIGINT),
1347 // or the ZMQ context was destroyed, or the timeout expired, returns NULL.
1348 // You can test the actual exit condition by calling zpoller_expired () and
1349 // zpoller_terminated (). The timeout is in msec.
1350 function Wait(Timeout: Integer): IZSock;
1351
1352 // Return true if the last zpoller_wait () call ended because the timeout
1353 // expired, without any error.
1354 function Expired: Boolean;
1355
1356 // Return true if the last zpoller_wait () call ended because the process
1357 // was interrupted, or the parent context was destroyed.
1358 function Terminated: Boolean;
1359 end;
1360
1361 // high-level socket API that hides libzmq contexts and sockets
1362 IZsock = interface
1363
1364 // Bind a socket to a formatted endpoint. For tcp:// endpoints, supports
1365 // ephemeral ports, if you specify the port number as "*". By default
1366 // zsock uses the IANA designated range from C000 (49152) to FFFF (65535).
1367 // To override this range, follow the "*" with "[first-last]". Either or
1368 // both first and last may be empty. To bind to a random port within the
1369 // range, use "!" in place of "*".
1370 //
1371 // Examples:
1372 // tcp://127.0.0.1:* bind to first free port from C000 up
1373 // tcp://127.0.0.1:! bind to random port from C000 to FFFF
1374 // tcp://127.0.0.1:*[60000-] bind to first free port from 60000 up
1375 // tcp://127.0.0.1:![-60000] bind to random port from C000 to 60000
1376 // tcp://127.0.0.1:![55000-55999]
1377 // bind to random port from 55000 to 55999
1378 //
1379 // On success, returns the actual port number used, for tcp:// endpoints,
1380 // and 0 for other transports. On failure, returns -1. Note that when using
1381 // ephemeral ports, a port may be reused by different services without
1382 // clients being aware. Protocols that run on ephemeral ports should take
1383 // this into account.
1384 function Bind(const Format: string): Integer;
1385
1386 // Returns last bound endpoint, if any.
1387 function Endpoint: string;
1388
1389 // Unbind a socket from a formatted endpoint.
1390 // Returns 0 if OK, -1 if the endpoint was invalid or the function
1391 // isn't supported.
1392 function Unbind(const Format: string): Integer;
1393
1394 // Connect a socket to a formatted endpoint
1395 // Returns 0 if OK, -1 if the endpoint was invalid.
1396 function Connect(const Format: string): Integer;
1397
1398 // Disconnect a socket from a formatted endpoint
1399 // Returns 0 if OK, -1 if the endpoint was invalid or the function
1400 // isn't supported.
1401 function Disconnect(const Format: string): Integer;
1402
1403 // Attach a socket to zero or more endpoints. If endpoints is not null,
1404 // parses as list of ZeroMQ endpoints, separated by commas, and prefixed by
1405 // '@' (to bind the socket) or '>' (to connect the socket). Returns 0 if all
1406 // endpoints were valid, or -1 if there was a syntax error. If the endpoint
1407 // does not start with '@' or '>', the serverish argument defines whether
1408 // it is used to bind (serverish = true) or connect (serverish = false).
1409 function Attach(const Endpoints: string; Serverish: Boolean): Integer;
1410
1411 // Returns socket type as printable constant string.
1412 function TypeStr: string;
1413
1414 // Send a 'picture' message to the socket (or actor). The picture is a
1415 // string that defines the type of each frame. This makes it easy to send
1416 // a complex multiframe message in one call. The picture can contain any
1417 // of these characters, each corresponding to one or two arguments:
1418 //
1419 // i = int (signed)
1420 // 1 = uint8_t
1421 // 2 = uint16_t
1422 // 4 = uint32_t
1423 // 8 = uint64_t
1424 // s = char *
1425 // b = byte *, size_t (2 arguments)
1426 // c = zchunk_t *
1427 // f = zframe_t *
1428 // h = zhashx_t *
1429 // l = zlistx_t * (DRAFT)
1430 // U = zuuid_t *
1431 // p = void * (sends the pointer value, only meaningful over inproc)
1432 // m = zmsg_t * (sends all frames in the zmsg)
1433 // z = sends zero-sized frame (0 arguments)
1434 // u = uint (deprecated)
1435 //
1436 // Note that s, b, c, and f are encoded the same way and the choice is
1437 // offered as a convenience to the sender, which may or may not already
1438 // have data in a zchunk or zframe. Does not change or take ownership of
1439 // any arguments. Returns 0 if successful, -1 if sending failed for any
1440 // reason.
1441 function Send(const Picture: string): Integer;
1442
1443 // Send a 'picture' message to the socket (or actor). This is a va_list
1444 // version of zsock_send (), so please consult its documentation for the
1445 // details.
1446 function Vsend(const Picture: string; Argptr: va_list): Integer;
1447
1448 // Receive a 'picture' message to the socket (or actor). See zsock_send for
1449 // the format and meaning of the picture. Returns the picture elements into
1450 // a series of pointers as provided by the caller:
1451 //
1452 // i = int * (stores signed integer)
1453 // 4 = uint32_t * (stores 32-bit unsigned integer)
1454 // 8 = uint64_t * (stores 64-bit unsigned integer)
1455 // s = char ** (allocates new string)
1456 // b = byte **, size_t * (2 arguments) (allocates memory)
1457 // c = zchunk_t ** (creates zchunk)
1458 // f = zframe_t ** (creates zframe)
1459 // U = zuuid_t * (creates a zuuid with the data)
1460 // h = zhashx_t ** (creates zhashx)
1461 // l = zlistx_t ** (creates zlistx) (DRAFT)
1462 // p = void ** (stores pointer)
1463 // m = zmsg_t ** (creates a zmsg with the remaining frames)
1464 // z = null, asserts empty frame (0 arguments)
1465 // u = uint * (stores unsigned integer, deprecated)
1466 //
1467 // Note that zsock_recv creates the returned objects, and the caller must
1468 // destroy them when finished with them. The supplied pointers do not need
1469 // to be initialized. Returns 0 if successful, or -1 if it failed to recv
1470 // a message, in which case the pointers are not modified. When message
1471 // frames are truncated (a short message), sets return values to zero/null.
1472 // If an argument pointer is NULL, does not store any value (skips it).
1473 // An 'n' picture matches an empty frame; if the message does not match,
1474 // the method will return -1.
1475 function Recv(const Picture: string): Integer;
1476
1477 // Receive a 'picture' message from the socket (or actor). This is a
1478 // va_list version of zsock_recv (), so please consult its documentation
1479 // for the details.
1480 function Vrecv(const Picture: string; Argptr: va_list): Integer;
1481
1482 // Send a binary encoded 'picture' message to the socket (or actor). This
1483 // method is similar to zsock_send, except the arguments are encoded in a
1484 // binary format that is compatible with zproto, and is designed to reduce
1485 // memory allocations. The pattern argument is a string that defines the
1486 // type of each argument. Supports these argument types:
1487 //
1488 // pattern C type zproto type:
1489 // 1 uint8_t type = "number" size = "1"
1490 // 2 uint16_t type = "number" size = "2"
1491 // 4 uint32_t type = "number" size = "3"
1492 // 8 uint64_t type = "number" size = "4"
1493 // s char *, 0-255 chars type = "string"
1494 // S char *, 0-2^32-1 chars type = "longstr"
1495 // c zchunk_t * type = "chunk"
1496 // f zframe_t * type = "frame"
1497 // u zuuid_t * type = "uuid"
1498 // m zmsg_t * type = "msg"
1499 // p void *, sends pointer value, only over inproc
1500 //
1501 // Does not change or take ownership of any arguments. Returns 0 if
1502 // successful, -1 if sending failed for any reason.
1503 function Bsend(const Picture: string): Integer;
1504
1505 // Receive a binary encoded 'picture' message from the socket (or actor).
1506 // This method is similar to zsock_recv, except the arguments are encoded
1507 // in a binary format that is compatible with zproto, and is designed to
1508 // reduce memory allocations. The pattern argument is a string that defines
1509 // the type of each argument. See zsock_bsend for the supported argument
1510 // types. All arguments must be pointers; this call sets them to point to
1511 // values held on a per-socket basis.
1512 // For types 1, 2, 4 and 8 the caller must allocate the memory itself before
1513 // calling zsock_brecv.
1514 // For types S, the caller must free the value once finished with it, as
1515 // zsock_brecv will allocate the buffer.
1516 // For type s, the caller must not free the value as it is stored in a
1517 // local cache for performance purposes.
1518 // For types c, f, u and m the caller must call the appropriate destructor
1519 // depending on the object as zsock_brecv will create new objects.
1520 // For type p the caller must coordinate with the sender, as it is just a
1521 // pointer value being passed.
1522 function Brecv(const Picture: string): Integer;
1523
1524 // Return socket routing ID if any. This returns 0 if the socket is not
1525 // of type ZMQ_SERVER or if no request was already received on it.
1526 function RoutingId: Cardinal;
1527
1528 // Set routing ID on socket. The socket MUST be of type ZMQ_SERVER.
1529 // This will be used when sending messages on the socket via the zsock API.
1530 procedure SetRoutingId(RoutingId: Cardinal);
1531
1532 // Set socket to use unbounded pipes (HWM=0); use this in cases when you are
1533 // totally certain the message volume can fit in memory. This method works
1534 // across all versions of ZeroMQ. Takes a polymorphic socket reference.
1535 procedure SetUnbounded;
1536
1537 // Send a signal over a socket. A signal is a short message carrying a
1538 // success/failure code (by convention, 0 means OK). Signals are encoded
1539 // to be distinguishable from "normal" messages. Accepts a zsock_t or a
1540 // zactor_t argument, and returns 0 if successful, -1 if the signal could
1541 // not be sent. Takes a polymorphic socket reference.
1542 function Signal(Status: Byte): Integer;
1543
1544 // Wait on a signal. Use this to coordinate between threads, over pipe
1545 // pairs. Blocks until the signal is received. Returns -1 on error, 0 or
1546 // greater on success. Accepts a zsock_t or a zactor_t as argument.
1547 // Takes a polymorphic socket reference.
1548 function Wait: Integer;
1549
1550 // If there is a partial message still waiting on the socket, remove and
1551 // discard it. This is useful when reading partial messages, to get specific
1552 // message types.
1553 procedure Flush;
1554
1555 // Join a group for the RADIO-DISH pattern. Call only on ZMQ_DISH.
1556 // Returns 0 if OK, -1 if failed.
1557 function Join(const Group: string): Integer;
1558
1559 // Leave a group for the RADIO-DISH pattern. Call only on ZMQ_DISH.
1560 // Returns 0 if OK, -1 if failed.
1561 function Leave(const Group: string): Integer;
1562
1563 // Check whether the socket has available message to read.
1564 function HasIn: Boolean;
1565
1566 // Get socket option `router_notify`.
1567 // Available from libzmq 4.3.0.
1568 function RouterNotify: Integer;
1569
1570 // Set socket option `router_notify`.
1571 // Available from libzmq 4.3.0.
1572 procedure SetRouterNotify(RouterNotify: Integer);
1573
1574 // Get socket option `multicast_loop`.
1575 // Available from libzmq 4.3.0.
1576 function MulticastLoop: Integer;
1577
1578 // Set socket option `multicast_loop`.
1579 // Available from libzmq 4.3.0.
1580 procedure SetMulticastLoop(MulticastLoop: Integer);
1581
1582 // Get socket option `metadata`.
1583 // Available from libzmq 4.3.0.
1584 function Metadata: string;
1585
1586 // Set socket option `metadata`.
1587 // Available from libzmq 4.3.0.
1588 procedure SetMetadata(const Metadata: string);
1589
1590 // Get socket option `loopback_fastpath`.
1591 // Available from libzmq 4.3.0.
1592 function LoopbackFastpath: Integer;
1593
1594 // Set socket option `loopback_fastpath`.
1595 // Available from libzmq 4.3.0.
1596 procedure SetLoopbackFastpath(LoopbackFastpath: Integer);
1597
1598 // Get socket option `zap_enforce_domain`.
1599 // Available from libzmq 4.3.0.
1600 function ZapEnforceDomain: Integer;
1601
1602 // Set socket option `zap_enforce_domain`.
1603 // Available from libzmq 4.3.0.
1604 procedure SetZapEnforceDomain(ZapEnforceDomain: Integer);
1605
1606 // Get socket option `gssapi_principal_nametype`.
1607 // Available from libzmq 4.3.0.
1608 function GssapiPrincipalNametype: Integer;
1609
1610 // Set socket option `gssapi_principal_nametype`.
1611 // Available from libzmq 4.3.0.
1612 procedure SetGssapiPrincipalNametype(GssapiPrincipalNametype: Integer);
1613
1614 // Get socket option `gssapi_service_principal_nametype`.
1615 // Available from libzmq 4.3.0.
1616 function GssapiServicePrincipalNametype: Integer;
1617
1618 // Set socket option `gssapi_service_principal_nametype`.
1619 // Available from libzmq 4.3.0.
1620 procedure SetGssapiServicePrincipalNametype(GssapiServicePrincipalNametype: Integer);
1621
1622 // Get socket option `bindtodevice`.
1623 // Available from libzmq 4.3.0.
1624 function Bindtodevice: string;
1625
1626 // Set socket option `bindtodevice`.
1627 // Available from libzmq 4.3.0.
1628 procedure SetBindtodevice(const Bindtodevice: string);
1629
1630 // Get socket option `heartbeat_ivl`.
1631 // Available from libzmq 4.2.0.
1632 function HeartbeatIvl: Integer;
1633
1634 // Set socket option `heartbeat_ivl`.
1635 // Available from libzmq 4.2.0.
1636 procedure SetHeartbeatIvl(HeartbeatIvl: Integer);
1637
1638 // Get socket option `heartbeat_ttl`.
1639 // Available from libzmq 4.2.0.
1640 function HeartbeatTtl: Integer;
1641
1642 // Set socket option `heartbeat_ttl`.
1643 // Available from libzmq 4.2.0.
1644 procedure SetHeartbeatTtl(HeartbeatTtl: Integer);
1645
1646 // Get socket option `heartbeat_timeout`.
1647 // Available from libzmq 4.2.0.
1648 function HeartbeatTimeout: Integer;
1649
1650 // Set socket option `heartbeat_timeout`.
1651 // Available from libzmq 4.2.0.
1652 procedure SetHeartbeatTimeout(HeartbeatTimeout: Integer);
1653
1654 // Get socket option `use_fd`.
1655 // Available from libzmq 4.2.0.
1656 function UseFd: Integer;
1657
1658 // Set socket option `use_fd`.
1659 // Available from libzmq 4.2.0.
1660 procedure SetUseFd(UseFd: Integer);
1661
1662 // Set socket option `xpub_manual`.
1663 // Available from libzmq 4.2.0.
1664 procedure SetXpubManual(XpubManual: Integer);
1665
1666 // Set socket option `xpub_welcome_msg`.
1667 // Available from libzmq 4.2.0.
1668 procedure SetXpubWelcomeMsg(const XpubWelcomeMsg: string);
1669
1670 // Set socket option `stream_notify`.
1671 // Available from libzmq 4.2.0.
1672 procedure SetStreamNotify(StreamNotify: Integer);
1673
1674 // Get socket option `invert_matching`.
1675 // Available from libzmq 4.2.0.
1676 function InvertMatching: Integer;
1677
1678 // Set socket option `invert_matching`.
1679 // Available from libzmq 4.2.0.
1680 procedure SetInvertMatching(InvertMatching: Integer);
1681
1682 // Set socket option `xpub_verboser`.
1683 // Available from libzmq 4.2.0.
1684 procedure SetXpubVerboser(XpubVerboser: Integer);
1685
1686 // Get socket option `connect_timeout`.
1687 // Available from libzmq 4.2.0.
1688 function ConnectTimeout: Integer;
1689
1690 // Set socket option `connect_timeout`.
1691 // Available from libzmq 4.2.0.
1692 procedure SetConnectTimeout(ConnectTimeout: Integer);
1693
1694 // Get socket option `tcp_maxrt`.
1695 // Available from libzmq 4.2.0.
1696 function TcpMaxrt: Integer;
1697
1698 // Set socket option `tcp_maxrt`.
1699 // Available from libzmq 4.2.0.
1700 procedure SetTcpMaxrt(TcpMaxrt: Integer);
1701
1702 // Get socket option `thread_safe`.
1703 // Available from libzmq 4.2.0.
1704 function ThreadSafe: Integer;
1705
1706 // Get socket option `multicast_maxtpdu`.
1707 // Available from libzmq 4.2.0.
1708 function MulticastMaxtpdu: Integer;
1709
1710 // Set socket option `multicast_maxtpdu`.
1711 // Available from libzmq 4.2.0.
1712 procedure SetMulticastMaxtpdu(MulticastMaxtpdu: Integer);
1713
1714 // Get socket option `vmci_buffer_size`.
1715 // Available from libzmq 4.2.0.
1716 function VmciBufferSize: Integer;
1717
1718 // Set socket option `vmci_buffer_size`.
1719 // Available from libzmq 4.2.0.
1720 procedure SetVmciBufferSize(VmciBufferSize: Integer);
1721
1722 // Get socket option `vmci_buffer_min_size`.
1723 // Available from libzmq 4.2.0.
1724 function VmciBufferMinSize: Integer;
1725
1726 // Set socket option `vmci_buffer_min_size`.
1727 // Available from libzmq 4.2.0.
1728 procedure SetVmciBufferMinSize(VmciBufferMinSize: Integer);
1729
1730 // Get socket option `vmci_buffer_max_size`.
1731 // Available from libzmq 4.2.0.
1732 function VmciBufferMaxSize: Integer;
1733
1734 // Set socket option `vmci_buffer_max_size`.
1735 // Available from libzmq 4.2.0.
1736 procedure SetVmciBufferMaxSize(VmciBufferMaxSize: Integer);
1737
1738 // Get socket option `vmci_connect_timeout`.
1739 // Available from libzmq 4.2.0.
1740 function VmciConnectTimeout: Integer;
1741
1742 // Set socket option `vmci_connect_timeout`.
1743 // Available from libzmq 4.2.0.
1744 procedure SetVmciConnectTimeout(VmciConnectTimeout: Integer);
1745
1746 // Get socket option `tos`.
1747 // Available from libzmq 4.1.0.
1748 function Tos: Integer;
1749
1750 // Set socket option `tos`.
1751 // Available from libzmq 4.1.0.
1752 procedure SetTos(Tos: Integer);
1753
1754 // Set socket option `router_handover`.
1755 // Available from libzmq 4.1.0.
1756 procedure SetRouterHandover(RouterHandover: Integer);
1757
1758 // Set socket option `connect_rid`.
1759 // Available from libzmq 4.1.0.
1760 procedure SetConnectRid(const ConnectRid: string);
1761
1762 // Set socket option `connect_rid` from 32-octet binary
1763 // Available from libzmq 4.1.0.
1764 procedure SetConnectRidBin(ConnectRid: PByte);
1765
1766 // Get socket option `handshake_ivl`.
1767 // Available from libzmq 4.1.0.
1768 function HandshakeIvl: Integer;
1769
1770 // Set socket option `handshake_ivl`.
1771 // Available from libzmq 4.1.0.
1772 procedure SetHandshakeIvl(HandshakeIvl: Integer);
1773
1774 // Get socket option `socks_proxy`.
1775 // Available from libzmq 4.1.0.
1776 function SocksProxy: string;
1777
1778 // Set socket option `socks_proxy`.
1779 // Available from libzmq 4.1.0.
1780 procedure SetSocksProxy(const SocksProxy: string);
1781
1782 // Set socket option `xpub_nodrop`.
1783 // Available from libzmq 4.1.0.
1784 procedure SetXpubNodrop(XpubNodrop: Integer);
1785
1786 // Set socket option `router_mandatory`.
1787 // Available from libzmq 4.0.0.
1788 procedure SetRouterMandatory(RouterMandatory: Integer);
1789
1790 // Set socket option `probe_router`.
1791 // Available from libzmq 4.0.0.
1792 procedure SetProbeRouter(ProbeRouter: Integer);
1793
1794 // Set socket option `req_relaxed`.
1795 // Available from libzmq 4.0.0.
1796 procedure SetReqRelaxed(ReqRelaxed: Integer);
1797
1798 // Set socket option `req_correlate`.
1799 // Available from libzmq 4.0.0.
1800 procedure SetReqCorrelate(ReqCorrelate: Integer);
1801
1802 // Set socket option `conflate`.
1803 // Available from libzmq 4.0.0.
1804 procedure SetConflate(Conflate: Integer);
1805
1806 // Get socket option `zap_domain`.
1807 // Available from libzmq 4.0.0.
1808 function ZapDomain: string;
1809
1810 // Set socket option `zap_domain`.
1811 // Available from libzmq 4.0.0.
1812 procedure SetZapDomain(const ZapDomain: string);
1813
1814 // Get socket option `mechanism`.
1815 // Available from libzmq 4.0.0.
1816 function Mechanism: Integer;
1817
1818 // Get socket option `plain_server`.
1819 // Available from libzmq 4.0.0.
1820 function PlainServer: Integer;
1821
1822 // Set socket option `plain_server`.
1823 // Available from libzmq 4.0.0.
1824 procedure SetPlainServer(PlainServer: Integer);
1825
1826 // Get socket option `plain_username`.
1827 // Available from libzmq 4.0.0.
1828 function PlainUsername: string;
1829
1830 // Set socket option `plain_username`.
1831 // Available from libzmq 4.0.0.
1832 procedure SetPlainUsername(const PlainUsername: string);
1833
1834 // Get socket option `plain_password`.
1835 // Available from libzmq 4.0.0.
1836 function PlainPassword: string;
1837
1838 // Set socket option `plain_password`.
1839 // Available from libzmq 4.0.0.
1840 procedure SetPlainPassword(const PlainPassword: string);
1841
1842 // Get socket option `curve_server`.
1843 // Available from libzmq 4.0.0.
1844 function CurveServer: Integer;
1845
1846 // Set socket option `curve_server`.
1847 // Available from libzmq 4.0.0.
1848 procedure SetCurveServer(CurveServer: Integer);
1849
1850 // Get socket option `curve_publickey`.
1851 // Available from libzmq 4.0.0.
1852 function CurvePublickey: string;
1853
1854 // Set socket option `curve_publickey`.
1855 // Available from libzmq 4.0.0.
1856 procedure SetCurvePublickey(const CurvePublickey: string);
1857
1858 // Set socket option `curve_publickey` from 32-octet binary
1859 // Available from libzmq 4.0.0.
1860 procedure SetCurvePublickeyBin(CurvePublickey: PByte);
1861
1862 // Get socket option `curve_secretkey`.
1863 // Available from libzmq 4.0.0.
1864 function CurveSecretkey: string;
1865
1866 // Set socket option `curve_secretkey`.
1867 // Available from libzmq 4.0.0.
1868 procedure SetCurveSecretkey(const CurveSecretkey: string);
1869
1870 // Set socket option `curve_secretkey` from 32-octet binary
1871 // Available from libzmq 4.0.0.
1872 procedure SetCurveSecretkeyBin(CurveSecretkey: PByte);
1873
1874 // Get socket option `curve_serverkey`.
1875 // Available from libzmq 4.0.0.
1876 function CurveServerkey: string;
1877
1878 // Set socket option `curve_serverkey`.
1879 // Available from libzmq 4.0.0.
1880 procedure SetCurveServerkey(const CurveServerkey: string);
1881
1882 // Set socket option `curve_serverkey` from 32-octet binary
1883 // Available from libzmq 4.0.0.
1884 procedure SetCurveServerkeyBin(CurveServerkey: PByte);
1885
1886 // Get socket option `gssapi_server`.
1887 // Available from libzmq 4.0.0.
1888 function GssapiServer: Integer;
1889
1890 // Set socket option `gssapi_server`.
1891 // Available from libzmq 4.0.0.
1892 procedure SetGssapiServer(GssapiServer: Integer);
1893
1894 // Get socket option `gssapi_plaintext`.
1895 // Available from libzmq 4.0.0.
1896 function GssapiPlaintext: Integer;
1897
1898 // Set socket option `gssapi_plaintext`.
1899 // Available from libzmq 4.0.0.
1900 procedure SetGssapiPlaintext(GssapiPlaintext: Integer);
1901
1902 // Get socket option `gssapi_principal`.
1903 // Available from libzmq 4.0.0.
1904 function GssapiPrincipal: string;
1905
1906 // Set socket option `gssapi_principal`.
1907 // Available from libzmq 4.0.0.
1908 procedure SetGssapiPrincipal(const GssapiPrincipal: string);
1909
1910 // Get socket option `gssapi_service_principal`.
1911 // Available from libzmq 4.0.0.
1912 function GssapiServicePrincipal: string;
1913
1914 // Set socket option `gssapi_service_principal`.
1915 // Available from libzmq 4.0.0.
1916 procedure SetGssapiServicePrincipal(const GssapiServicePrincipal: string);
1917
1918 // Get socket option `ipv6`.
1919 // Available from libzmq 4.0.0.
1920 function Ipv6: Integer;
1921
1922 // Set socket option `ipv6`.
1923 // Available from libzmq 4.0.0.
1924 procedure SetIpv6(Ipv6: Integer);
1925
1926 // Get socket option `immediate`.
1927 // Available from libzmq 4.0.0.
1928 function Immediate: Integer;
1929
1930 // Set socket option `immediate`.
1931 // Available from libzmq 4.0.0.
1932 procedure SetImmediate(Immediate: Integer);
1933
1934 // Get socket option `sndhwm`.
1935 // Available from libzmq 3.0.0.
1936 function Sndhwm: Integer;
1937
1938 // Set socket option `sndhwm`.
1939 // Available from libzmq 3.0.0.
1940 procedure SetSndhwm(Sndhwm: Integer);
1941
1942 // Get socket option `rcvhwm`.
1943 // Available from libzmq 3.0.0.
1944 function Rcvhwm: Integer;
1945
1946 // Set socket option `rcvhwm`.
1947 // Available from libzmq 3.0.0.
1948 procedure SetRcvhwm(Rcvhwm: Integer);
1949
1950 // Get socket option `maxmsgsize`.
1951 // Available from libzmq 3.0.0.
1952 function Maxmsgsize: Integer;
1953
1954 // Set socket option `maxmsgsize`.
1955 // Available from libzmq 3.0.0.
1956 procedure SetMaxmsgsize(Maxmsgsize: Integer);
1957
1958 // Get socket option `multicast_hops`.
1959 // Available from libzmq 3.0.0.
1960 function MulticastHops: Integer;
1961
1962 // Set socket option `multicast_hops`.
1963 // Available from libzmq 3.0.0.
1964 procedure SetMulticastHops(MulticastHops: Integer);
1965
1966 // Set socket option `xpub_verbose`.
1967 // Available from libzmq 3.0.0.
1968 procedure SetXpubVerbose(XpubVerbose: Integer);
1969
1970 // Get socket option `tcp_keepalive`.
1971 // Available from libzmq 3.0.0.
1972 function TcpKeepalive: Integer;
1973
1974 // Set socket option `tcp_keepalive`.
1975 // Available from libzmq 3.0.0.
1976 procedure SetTcpKeepalive(TcpKeepalive: Integer);
1977
1978 // Get socket option `tcp_keepalive_idle`.
1979 // Available from libzmq 3.0.0.
1980 function TcpKeepaliveIdle: Integer;
1981
1982 // Set socket option `tcp_keepalive_idle`.
1983 // Available from libzmq 3.0.0.
1984 procedure SetTcpKeepaliveIdle(TcpKeepaliveIdle: Integer);
1985
1986 // Get socket option `tcp_keepalive_cnt`.
1987 // Available from libzmq 3.0.0.
1988 function TcpKeepaliveCnt: Integer;
1989
1990 // Set socket option `tcp_keepalive_cnt`.
1991 // Available from libzmq 3.0.0.
1992 procedure SetTcpKeepaliveCnt(TcpKeepaliveCnt: Integer);
1993
1994 // Get socket option `tcp_keepalive_intvl`.
1995 // Available from libzmq 3.0.0.
1996 function TcpKeepaliveIntvl: Integer;
1997
1998 // Set socket option `tcp_keepalive_intvl`.
1999 // Available from libzmq 3.0.0.
2000 procedure SetTcpKeepaliveIntvl(TcpKeepaliveIntvl: Integer);
2001
2002 // Get socket option `tcp_accept_filter`.
2003 // Available from libzmq 3.0.0.
2004 function TcpAcceptFilter: string;
2005
2006 // Set socket option `tcp_accept_filter`.
2007 // Available from libzmq 3.0.0.
2008 procedure SetTcpAcceptFilter(const TcpAcceptFilter: string);
2009
2010 // Get socket option `last_endpoint`.
2011 // Available from libzmq 3.0.0.
2012 function LastEndpoint: string;
2013
2014 // Set socket option `router_raw`.
2015 // Available from libzmq 3.0.0.
2016 procedure SetRouterRaw(RouterRaw: Integer);
2017
2018 // Get socket option `ipv4only`.
2019 // Available from libzmq 3.0.0.
2020 function Ipv4only: Integer;
2021
2022 // Set socket option `ipv4only`.
2023 // Available from libzmq 3.0.0.
2024 procedure SetIpv4only(Ipv4only: Integer);
2025
2026 // Set socket option `delay_attach_on_connect`.
2027 // Available from libzmq 3.0.0.
2028 procedure SetDelayAttachOnConnect(DelayAttachOnConnect: Integer);
2029
2030 // Get socket option `hwm`.
2031 // Available from libzmq 2.0.0 to 3.0.0.
2032 function Hwm: Integer;
2033
2034 // Set socket option `hwm`.
2035 // Available from libzmq 2.0.0 to 3.0.0.
2036 procedure SetHwm(Hwm: Integer);
2037
2038 // Get socket option `swap`.
2039 // Available from libzmq 2.0.0 to 3.0.0.
2040 function Swap: Integer;
2041
2042 // Set socket option `swap`.
2043 // Available from libzmq 2.0.0 to 3.0.0.
2044 procedure SetSwap(Swap: Integer);
2045
2046 // Get socket option `affinity`.
2047 // Available from libzmq 2.0.0.
2048 function Affinity: Integer;
2049
2050 // Set socket option `affinity`.
2051 // Available from libzmq 2.0.0.
2052 procedure SetAffinity(Affinity: Integer);
2053
2054 // Get socket option `identity`.
2055 // Available from libzmq 2.0.0.
2056 function Identity: string;
2057
2058 // Set socket option `identity`.
2059 // Available from libzmq 2.0.0.
2060 procedure SetIdentity(const Identity: string);
2061
2062 // Get socket option `rate`.
2063 // Available from libzmq 2.0.0.
2064 function Rate: Integer;
2065
2066 // Set socket option `rate`.
2067 // Available from libzmq 2.0.0.
2068 procedure SetRate(Rate: Integer);
2069
2070 // Get socket option `recovery_ivl`.
2071 // Available from libzmq 2.0.0.
2072 function RecoveryIvl: Integer;
2073
2074 // Set socket option `recovery_ivl`.
2075 // Available from libzmq 2.0.0.
2076 procedure SetRecoveryIvl(RecoveryIvl: Integer);
2077
2078 // Get socket option `recovery_ivl_msec`.
2079 // Available from libzmq 2.0.0 to 3.0.0.
2080 function RecoveryIvlMsec: Integer;
2081
2082 // Set socket option `recovery_ivl_msec`.
2083 // Available from libzmq 2.0.0 to 3.0.0.
2084 procedure SetRecoveryIvlMsec(RecoveryIvlMsec: Integer);
2085
2086 // Get socket option `mcast_loop`.
2087 // Available from libzmq 2.0.0 to 3.0.0.
2088 function McastLoop: Integer;
2089
2090 // Set socket option `mcast_loop`.
2091 // Available from libzmq 2.0.0 to 3.0.0.
2092 procedure SetMcastLoop(McastLoop: Integer);
2093
2094 // Get socket option `rcvtimeo`.
2095 // Available from libzmq 2.2.0.
2096 function Rcvtimeo: Integer;
2097
2098 // Set socket option `rcvtimeo`.
2099 // Available from libzmq 2.2.0.
2100 procedure SetRcvtimeo(Rcvtimeo: Integer);
2101
2102 // Get socket option `sndtimeo`.
2103 // Available from libzmq 2.2.0.
2104 function Sndtimeo: Integer;
2105
2106 // Set socket option `sndtimeo`.
2107 // Available from libzmq 2.2.0.
2108 procedure SetSndtimeo(Sndtimeo: Integer);
2109
2110 // Get socket option `sndbuf`.
2111 // Available from libzmq 2.0.0.
2112 function Sndbuf: Integer;
2113
2114 // Set socket option `sndbuf`.
2115 // Available from libzmq 2.0.0.
2116 procedure SetSndbuf(Sndbuf: Integer);
2117
2118 // Get socket option `rcvbuf`.
2119 // Available from libzmq 2.0.0.
2120 function Rcvbuf: Integer;
2121
2122 // Set socket option `rcvbuf`.
2123 // Available from libzmq 2.0.0.
2124 procedure SetRcvbuf(Rcvbuf: Integer);
2125
2126 // Get socket option `linger`.
2127 // Available from libzmq 2.0.0.
2128 function Linger: Integer;
2129
2130 // Set socket option `linger`.
2131 // Available from libzmq 2.0.0.
2132 procedure SetLinger(Linger: Integer);
2133
2134 // Get socket option `reconnect_ivl`.
2135 // Available from libzmq 2.0.0.
2136 function ReconnectIvl: Integer;
2137
2138 // Set socket option `reconnect_ivl`.
2139 // Available from libzmq 2.0.0.
2140 procedure SetReconnectIvl(ReconnectIvl: Integer);
2141
2142 // Get socket option `reconnect_ivl_max`.
2143 // Available from libzmq 2.0.0.
2144 function ReconnectIvlMax: Integer;
2145
2146 // Set socket option `reconnect_ivl_max`.
2147 // Available from libzmq 2.0.0.
2148 procedure SetReconnectIvlMax(ReconnectIvlMax: Integer);
2149
2150 // Get socket option `backlog`.
2151 // Available from libzmq 2.0.0.
2152 function Backlog: Integer;
2153
2154 // Set socket option `backlog`.
2155 // Available from libzmq 2.0.0.
2156 procedure SetBacklog(Backlog: Integer);
2157
2158 // Set socket option `subscribe`.
2159 // Available from libzmq 2.0.0.
2160 procedure SetSubscribe(const Subscribe: string);
2161
2162 // Set socket option `unsubscribe`.
2163 // Available from libzmq 2.0.0.
2164 procedure SetUnsubscribe(const Unsubscribe: string);
2165
2166 // Get socket option `type`.
2167 // Available from libzmq 2.0.0.
2168 function &Type: Integer;
2169
2170 // Get socket option `rcvmore`.
2171 // Available from libzmq 2.0.0.
2172 function Rcvmore: Integer;
2173
2174 // Get socket option `fd`.
2175 // Available from libzmq 2.0.0.
2176 function Fd: TSocket;
2177
2178 // Get socket option `events`.
2179 // Available from libzmq 2.0.0.
2180 function Events: Integer;
2181 end;
2182
2183 // UUID support class
2184 IZuuid = interface
2185
2186 // Set UUID to new supplied ZUUID_LEN-octet value.
2187 procedure &Set(Source: PByte);
2188
2189 // Set UUID to new supplied string value skipping '-' and '{' '}'
2190 // optional delimiters. Return 0 if OK, else returns -1.
2191 function SetStr(const Source: string): Integer;
2192
2193 // Return UUID binary data.
2194 function Data: PByte;
2195
2196 // Return UUID binary size
2197 function Size: NativeUInt;
2198
2199 // Returns UUID as string
2200 function Str: string;
2201
2202 // Return UUID in the canonical string format: 8-4-4-4-12, in lower
2203 // case. Caller does not modify or free returned value. See
2204 // http://en.wikipedia.org/wiki/Universally_unique_identifier
2205 function StrCanonical: string;
2206
2207 // Store UUID blob in target array
2208 procedure Export(Target: PByte);
2209
2210 // Check if UUID is same as supplied value
2211 function Eq(Compare: PByte): Boolean;
2212
2213 // Check if UUID is different from supplied value
2214 function Neq(Compare: PByte): Boolean;
2215
2216 // Make copy of UUID object; if uuid is null, or memory was exhausted,
2217 // returns null.
2218 function Dup: IZuuid;
2219 end;
2220
2221 // provides a simple actor framework
2222 TZactor = class(TInterfacedObject, IZactor)
2223 public
2224 FOwned: Boolean;
2225 FHandle: PZactor;
2226 constructor Create(handle: PZactor; owned: Boolean);
2227 public
2228
2229 // Create a new actor passing arbitrary arguments reference.
2230 constructor New(Task: TZactorFn; Args: Pointer);
2231
2232 // Destroy an actor.
2233 destructor Destroy; override;
2234
2235 // Probe the supplied object, and report if it looks like a zactor_t.
2236 class function &Is(This: Pointer): Boolean;
2237
2238 // Probe the supplied reference. If it looks like a zactor_t instance,
2239 // return the underlying libzmq actor handle; else if it looks like
2240 // a libzmq actor handle, return the supplied value.
2241 class function Resolve(This: Pointer): Pointer;
2242
2243 // Self test of this class.
2244 class procedure Test(Verbose: Boolean);
2245
2246 class function Wrap(handle: PZactor; owned: Boolean): IZactor;
2247 class function UnWrap(const Value: IZactor): PZactor;
2248 protected
2249
2250 // Send a zmsg message to the actor, take ownership of the message
2251 // and destroy when it has been sent.
2252 function Send(var MsgP: IZmsg): Integer;
2253
2254 // Receive a zmsg message from the actor. Returns NULL if the actor
2255 // was interrupted before the message could be received, or if there
2256 // was a timeout on the actor.
2257 function Recv: IZmsg;
2258
2259 // Return the actor's zsock handle. Use this when you absolutely need
2260 // to work with the zsock instance rather than the actor.
2261 function Sock: IZsock;
2262
2263 // Change default destructor by custom function. Actor MUST be able to handle new message instead of default $TERM.
2264 procedure SetDestructor(&Destructor: TZactorDestructorFn);
2265 end;
2266
2267 // armoured text encoding and decoding
2268 TZarmour = class(TInterfacedObject, IZarmour)
2269 public
2270 FOwned: Boolean;
2271 FHandle: PZarmour;
2272 constructor Create(handle: PZarmour; owned: Boolean);
2273 public
2274
2275 // Create a new zarmour
2276 constructor New;
2277
2278 // Destroy the zarmour
2279 destructor Destroy; override;
2280
2281 // Self test of this class.
2282 class procedure Test(Verbose: Boolean);
2283
2284 class function Wrap(handle: PZarmour; owned: Boolean): IZarmour;
2285 class function UnWrap(const Value: IZarmour): PZarmour;
2286 protected
2287
2288 // Encode a stream of bytes into an armoured string. Returns the armoured
2289 // string, or NULL if there was insufficient memory available to allocate
2290 // a new string.
2291 function Encode(Data: PByte; Size: NativeUInt): string;
2292
2293 // Decode an armoured string into a chunk. The decoded output is
2294 // null-terminated, so it may be treated as a string, if that's what
2295 // it was prior to encoding.
2296 function Decode(const Data: string): IZchunk;
2297
2298 // Get the mode property.
2299 function Mode: Integer;
2300
2301 // Get printable string for mode.
2302 function ModeStr: string;
2303
2304 // Set the mode property.
2305 procedure SetMode(Mode: Integer);
2306
2307 // Return true if padding is turned on.
2308 function Pad: Boolean;
2309
2310 // Turn padding on or off. Default is on.
2311 procedure SetPad(Pad: Boolean);
2312
2313 // Get the padding character.
2314 function PadChar: AnsiChar;
2315
2316 // Set the padding character.
2317 procedure SetPadChar(PadChar: AnsiChar);
2318
2319 // Return if splitting output into lines is turned on. Default is off.
2320 function LineBreaks: Boolean;
2321
2322 // Turn splitting output into lines on or off.
2323 procedure SetLineBreaks(LineBreaks: Boolean);
2324
2325 // Get the line length used for splitting lines.
2326 function LineLength: NativeUInt;
2327
2328 // Set the line length used for splitting lines.
2329 procedure SetLineLength(LineLength: NativeUInt);
2330
2331 // Print properties of object
2332 procedure Print;
2333 end;
2334
2335 // work with CURVE security certificates
2336 TZcert = class(TInterfacedObject, IZcert)
2337 public
2338 FOwned: Boolean;
2339 FHandle: PZcert;
2340 constructor Create(handle: PZcert; owned: Boolean);
2341 public
2342
2343 // Create and initialize a new certificate in memory
2344 constructor New;
2345
2346 // Accepts public/secret key pair from caller
2347 constructor NewFrom(PublicKey: PByte; SecretKey: PByte);
2348
2349 // Accepts public/secret key text pair from caller
2350 constructor NewFromTxt(const PublicTxt: string; const SecretTxt: string);
2351
2352 // Load certificate from file
2353 constructor Load(const Filename: string);
2354
2355 // Destroy a certificate in memory
2356 destructor Destroy; override;
2357
2358 // Self test of this class
2359 class procedure Test(Verbose: Boolean);
2360
2361 class function Wrap(handle: PZcert; owned: Boolean): IZcert;
2362 class function UnWrap(const Value: IZcert): PZcert;
2363 protected
2364
2365 // Return public part of key pair as 32-byte binary string
2366 function PublicKey: PByte;
2367
2368 // Return secret part of key pair as 32-byte binary string
2369 function SecretKey: PByte;
2370
2371 // Return public part of key pair as Z85 armored string
2372 function PublicTxt: string;
2373
2374 // Return secret part of key pair as Z85 armored string
2375 function SecretTxt: string;
2376
2377 // Set certificate metadata from formatted string.
2378 procedure SetMeta(const Name: string; const Format: string);
2379
2380 // Unset certificate metadata.
2381 procedure UnsetMeta(const Name: string);
2382
2383 // Get metadata value from certificate; if the metadata value doesn't
2384 // exist, returns NULL.
2385 function Meta(const Name: string): string;
2386
2387 // Get list of metadata fields from certificate. Caller is responsible for
2388 // destroying list. Caller should not modify the values of list items.
2389 function MetaKeys: IZlist;
2390
2391 // Save full certificate (public + secret) to file for persistent storage
2392 // This creates one public file and one secret file (filename + "_secret").
2393 function Save(const Filename: string): Integer;
2394
2395 // Save public certificate only to file for persistent storage
2396 function SavePublic(const Filename: string): Integer;
2397
2398 // Save secret certificate only to file for persistent storage
2399 function SaveSecret(const Filename: string): Integer;
2400
2401 // Apply certificate to socket, i.e. use for CURVE security on socket.
2402 // If certificate was loaded from public file, the secret key will be
2403 // undefined, and this certificate will not work successfully.
2404 procedure Apply(const Socket: IZSock);
2405
2406 // Return copy of certificate; if certificate is NULL or we exhausted
2407 // heap memory, returns NULL.
2408 function Dup: IZcert;
2409
2410 // Return true if two certificates have the same keys
2411 function Eq(const Compare: IZcert): Boolean;
2412
2413 // Print certificate contents to stdout
2414 procedure Print;
2415 end;
2416
2417 // work with CURVE security certificate stores
2418 TZcertstore = class(TInterfacedObject, IZcertstore)
2419 public
2420 FOwned: Boolean;
2421 FHandle: PZcertstore;
2422 constructor Create(handle: PZcertstore; owned: Boolean);
2423 public
2424
2425 // Create a new certificate store from a disk directory, loading and
2426 // indexing all certificates in that location. The directory itself may be
2427 // absent, and created later, or modified at any time. The certificate store
2428 // is automatically refreshed on any zcertstore_lookup() call. If the
2429 // location is specified as NULL, creates a pure-memory store, which you
2430 // can work with by inserting certificates at runtime.
2431 constructor New(const Location: string);
2432
2433 // Destroy a certificate store object in memory. Does not affect anything
2434 // stored on disk.
2435 destructor Destroy; override;
2436
2437 // Self test of this class
2438 class procedure Test(Verbose: Boolean);
2439
2440 class function Wrap(handle: PZcertstore; owned: Boolean): IZcertstore;
2441 class function UnWrap(const Value: IZcertstore): PZcertstore;
2442 protected
2443
2444 // Override the default disk loader with a custom loader fn.
2445 procedure SetLoader(Loader: TZcertstoreLoader; &Destructor: TZcertstoreDestructor; State: PByte);
2446
2447 // Look up certificate by public key, returns zcert_t object if found,
2448 // else returns NULL. The public key is provided in Z85 text format.
2449 function Lookup(const PublicKey: string): IZcert;
2450
2451 // Insert certificate into certificate store in memory. Note that this
2452 // does not save the certificate to disk. To do that, use zcert_save()
2453 // directly on the certificate. Takes ownership of zcert_t object.
2454 procedure Insert(var CertP: IZcert);
2455
2456 // Empty certificate hashtable. This wrapper exists to be friendly to bindings,
2457 // which don't usually have access to struct internals.
2458 procedure Empty;
2459
2460 // Print list of certificates in store to logging facility
2461 procedure Print;
2462
2463 // Return a list of all the certificates in the store.
2464 // The caller takes ownership of the zlistx_t object and is responsible
2465 // for destroying it. The caller does not take ownership of the zcert_t
2466 // objects.
2467 function Certs: IZlistx;
2468 end;
2469
2470 // work with memory chunks
2471 TZchunk = class(TInterfacedObject, IZchunk)
2472 public
2473 FOwned: Boolean;
2474 FHandle: PZchunk;
2475 constructor Create(handle: PZchunk; owned: Boolean);
2476 public
2477
2478 // Create a new chunk of the specified size. If you specify the data, it
2479 // is copied into the chunk. If you do not specify the data, the chunk is
2480 // allocated and left empty, and you can then add data using zchunk_append.
2481 constructor New(Data: PByte; Size: NativeUInt);
2482
2483 // Create a new chunk from memory. Take ownership of the memory and calling the destructor
2484 // on destroy.
2485 constructor Frommem(Data: PByte; Size: NativeUInt; &Destructor: TZchunkDestructorFn; Hint: Pointer);
2486
2487 // Destroy a chunk
2488 destructor Destroy; override;
2489
2490 // Read chunk from an open file descriptor
2491 class function Read(Handle: Pointer; Bytes: NativeUInt): IZchunk;
2492
2493 // Try to slurp an entire file into a chunk. Will read up to maxsize of
2494 // the file. If maxsize is 0, will attempt to read the entire file and
2495 // fail with an assertion if that cannot fit into memory. Returns a new
2496 // chunk containing the file data, or NULL if the file could not be read.
2497 class function Slurp(const Filename: string; Maxsize: NativeUInt): IZchunk;
2498
2499 // Transform zchunk into a zframe that can be sent in a message.
2500 // Take ownership of the chunk.
2501 class function Packx(var SelfP: IZchunk): IZframe;
2502
2503 // Transform a zframe into a zchunk.
2504 class function Unpack(const Frame: IZframe): IZchunk;
2505
2506 // Probe the supplied object, and report if it looks like a zchunk_t.
2507 class function &Is(This: Pointer): Boolean;
2508
2509 // Self test of this class.
2510 class procedure Test(Verbose: Boolean);
2511
2512 class function Wrap(handle: PZchunk; owned: Boolean): IZchunk;
2513 class function UnWrap(const Value: IZchunk): PZchunk;
2514 protected
2515
2516 // Resizes chunk max_size as requested; chunk_cur size is set to zero
2517 procedure Resize(Size: NativeUInt);
2518
2519 // Return chunk cur size
2520 function Size: NativeUInt;
2521
2522 // Return chunk max size
2523 function MaxSize: NativeUInt;
2524
2525 // Return chunk data
2526 function Data: PByte;
2527
2528 // Set chunk data from user-supplied data; truncate if too large. Data may
2529 // be null. Returns actual size of chunk
2530 function &Set(Data: PByte; Size: NativeUInt): NativeUInt;
2531
2532 // Fill chunk data from user-supplied octet
2533 function Fill(Filler: Byte; Size: NativeUInt): NativeUInt;
2534
2535 // Append user-supplied data to chunk, return resulting chunk size. If the
2536 // data would exceeded the available space, it is truncated. If you want to
2537 // grow the chunk to accommodate new data, use the zchunk_extend method.
2538 function Append(Data: PByte; Size: NativeUInt): NativeUInt;
2539
2540 // Append user-supplied data to chunk, return resulting chunk size. If the
2541 // data would exceeded the available space, the chunk grows in size.
2542 function Extend(Data: PByte; Size: NativeUInt): NativeUInt;
2543
2544 // Copy as much data from 'source' into the chunk as possible; returns the
2545 // new size of chunk. If all data from 'source' is used, returns exhausted
2546 // on the source chunk. Source can be consumed as many times as needed until
2547 // it is exhausted. If source was already exhausted, does not change chunk.
2548 function Consume(const Source: IZchunk): NativeUInt;
2549
2550 // Returns true if the chunk was exhausted by consume methods, or if the
2551 // chunk has a size of zero.
2552 function Exhausted: Boolean;
2553
2554 // Write chunk to an open file descriptor
2555 function Write(Handle: Pointer): Integer;
2556
2557 // Create copy of chunk, as new chunk object. Returns a fresh zchunk_t
2558 // object, or null if there was not enough heap memory. If chunk is null,
2559 // returns null.
2560 function Dup: IZchunk;
2561
2562 // Return chunk data encoded as printable hex string. Caller must free
2563 // string when finished with it.
2564 function Strhex: string;
2565
2566 // Return chunk data copied into freshly allocated string
2567 // Caller must free string when finished with it.
2568 function Strdup: string;
2569
2570 // Return TRUE if chunk body is equal to string, excluding terminator
2571 function Streq(const &String: string): Boolean;
2572
2573 // Transform zchunk into a zframe that can be sent in a message.
2574 function Pack: IZframe;
2575
2576 // Calculate SHA1 digest for chunk, using zdigest class.
2577 function Digest: string;
2578
2579 // Dump chunk to FILE stream, for debugging and tracing.
2580 procedure Fprint(&File: Pointer);
2581
2582 // Dump message to stderr, for debugging and tracing.
2583 // See zchunk_fprint for details
2584 procedure Print;
2585 end;
2586
2587 // millisecond clocks and delays
2588 TZclock = class
2589 public
2590
2591 // Sleep for a number of milliseconds
2592 class procedure Sleep(Msecs: Integer);
2593
2594 // Return current system clock as milliseconds. Note that this clock can
2595 // jump backwards (if the system clock is changed) so is unsafe to use for
2596 // timers and time offsets. Use zclock_mono for that instead.
2597 class function Time: Int64;
2598
2599 // Return current monotonic clock in milliseconds. Use this when you compute
2600 // time offsets. The monotonic clock is not affected by system changes and
2601 // so will never be reset backwards, unlike a system clock.
2602 class function Mono: Int64;
2603
2604 // Return current monotonic clock in microseconds. Use this when you compute
2605 // time offsets. The monotonic clock is not affected by system changes and
2606 // so will never be reset backwards, unlike a system clock.
2607 class function Usecs: Int64;
2608
2609 // Return formatted date/time as fresh string. Free using zstr_free().
2610 class function Timestr: string;
2611
2612 // Self test of this class.
2613 class procedure Test(Verbose: Boolean);
2614 end;
2615
2616 // work with config files written in rfc.zeromq.org/spec:4/ZPL.
2617 TZconfig = class(TInterfacedObject, IZconfig)
2618 public
2619 FOwned: Boolean;
2620 FHandle: PZconfig;
2621 constructor Create(handle: PZconfig; owned: Boolean);
2622 public
2623
2624 // Create new config item
2625 constructor New(const Name: string; const Parent: IZconfig);
2626
2627 // Load a config tree from a specified ZPL text file; returns a zconfig_t
2628 // reference for the root, if the file exists and is readable. Returns NULL
2629 // if the file does not exist.
2630 constructor Load(const Filename: string);
2631
2632 // Equivalent to zconfig_load, taking a format string instead of a fixed
2633 // filename.
2634 constructor Loadf(const Format: string);
2635
2636 // Destroy a config item and all its children
2637 destructor Destroy; override;
2638
2639 // Reload config tree from same file that it was previously loaded from.
2640 // Returns 0 if OK, -1 if there was an error (and then does not change
2641 // existing data).
2642 class function Reload(var SelfP: IZconfig): Integer;
2643
2644 // Load a config tree from a memory chunk
2645 class function ChunkLoad(const Chunk: IZchunk): IZconfig;
2646
2647 // Load a config tree from a null-terminated string
2648 class function StrLoad(const &String: string): IZconfig;
2649
2650 // Destroy node and subtree (all children)
2651 class procedure Remove(var SelfP: IZconfig);
2652
2653 // Self test of this class
2654 class procedure Test(Verbose: Boolean);
2655
2656 class function Wrap(handle: PZconfig; owned: Boolean): IZconfig;
2657 class function UnWrap(const Value: IZconfig): PZconfig;
2658 protected
2659
2660 // Create copy of zconfig, caller MUST free the value
2661 // Create copy of config, as new zconfig object. Returns a fresh zconfig_t
2662 // object. If config is null, or memory was exhausted, returns null.
2663 function Dup: IZconfig;
2664
2665 // Return name of config item
2666 function Name: string;
2667
2668 // Return value of config item
2669 function Value: string;
2670
2671 // Insert or update configuration key with value
2672 procedure Put(const Path: string; const Value: string);
2673
2674 // Equivalent to zconfig_put, accepting a format specifier and variable
2675 // argument list, instead of a single string value.
2676 procedure Putf(const Path: string; const Format: string);
2677
2678 // Get value for config item into a string value; leading slash is optional
2679 // and ignored.
2680 function Get(const Path: string; const DefaultValue: string): string;
2681
2682 // Set config item name, name may be NULL
2683 procedure SetName(const Name: string);
2684
2685 // Set new value for config item. The new value may be a string, a printf
2686 // format, or NULL. Note that if string may possibly contain '%', or if it
2687 // comes from an insecure source, you must use '%s' as the format, followed
2688 // by the string.
2689 procedure SetValue(const Format: string);
2690
2691 // Find our first child, if any
2692 function Child: IZconfig;
2693
2694 // Find our first sibling, if any
2695 function Next: IZconfig;
2696
2697 // Find a config item along a path; leading slash is optional and ignored.
2698 function Locate(const Path: string): IZconfig;
2699
2700 // Locate the last config item at a specified depth
2701 function AtDepth(Level: Integer): IZconfig;
2702
2703 // Execute a callback for each config item in the tree; returns zero if
2704 // successful, else -1.
2705 function Execute(Handler: TZconfigFct; Arg: Pointer): Integer;
2706
2707 // Add comment to config item before saving to disk. You can add as many
2708 // comment lines as you like. If you use a null format, all comments are
2709 // deleted.
2710 procedure SetComment(const Format: string);
2711
2712 // Return comments of config item, as zlist.
2713 function Comments: IZlist;
2714
2715 // Save a config tree to a specified ZPL text file, where a filename
2716 // "-" means dump to standard output.
2717 function Save(const Filename: string): Integer;
2718
2719 // Equivalent to zconfig_save, taking a format string instead of a fixed
2720 // filename.
2721 function Savef(const Format: string): Integer;
2722
2723 // Report filename used during zconfig_load, or NULL if none
2724 function Filename: string;
2725
2726 // Save a config tree to a new memory chunk
2727 function ChunkSave: IZchunk;
2728
2729 // Save a config tree to a new null terminated string
2730 function StrSave: string;
2731
2732 // Return true if a configuration tree was loaded from a file and that
2733 // file has changed in since the tree was loaded.
2734 function HasChanged: Boolean;
2735
2736 // Destroy subtree (all children)
2737 procedure RemoveSubtree;
2738
2739 // Print the config file to open stream
2740 procedure Fprint(&File: Pointer);
2741
2742 // Print properties of object
2743 procedure Print;
2744 end;
2745
2746 // provides hashing functions (SHA-1 at present)
2747 TZdigest = class(TInterfacedObject, IZdigest)
2748 public
2749 FOwned: Boolean;
2750 FHandle: PZdigest;
2751 constructor Create(handle: PZdigest; owned: Boolean);
2752 public
2753
2754 // Constructor - creates new digest object, which you use to build up a
2755 // digest by repeatedly calling zdigest_update() on chunks of data.
2756 constructor New;
2757
2758 // Destroy a digest object
2759 destructor Destroy; override;
2760
2761 // Self test of this class.
2762 class procedure Test(Verbose: Boolean);
2763
2764 class function Wrap(handle: PZdigest; owned: Boolean): IZdigest;
2765 class function UnWrap(const Value: IZdigest): PZdigest;
2766 protected
2767
2768 // Add buffer into digest calculation
2769 procedure Update(Buffer: PByte; Length: NativeUInt);
2770
2771 // Return final digest hash data. If built without crypto support,
2772 // returns NULL.
2773 function Data: PByte;
2774
2775 // Return final digest hash size
2776 function Size: NativeUInt;
2777
2778 // Return digest as printable hex string; caller should not modify nor
2779 // free this string. After calling this, you may not use zdigest_update()
2780 // on the same digest. If built without crypto support, returns NULL.
2781 function &String: string;
2782 end;
2783
2784 // work with file-system directories
2785 TZdir = class(TInterfacedObject, IZdir)
2786 public
2787 FOwned: Boolean;
2788 FHandle: PZdir;
2789 constructor Create(handle: PZdir; owned: Boolean);
2790 public
2791
2792 // Create a new directory item that loads in the full tree of the specified
2793 // path, optionally located under some parent path. If parent is "-", then
2794 // loads only the top-level directory, and does not use parent as a path.
2795 constructor New(const Path: string; const Parent: string);
2796
2797 // Destroy a directory tree and all children it contains.
2798 destructor Destroy; override;
2799
2800 // Calculate differences between two versions of a directory tree.
2801 // Returns a list of zdir_patch_t patches. Either older or newer may
2802 // be null, indicating the directory is empty/absent. If alias is set,
2803 // generates virtual filename (minus path, plus alias).
2804 class function Diff(const Older: IZdir; const Newer: IZdir; const Alias: string): IZlist;
2805
2806 // Create a new zdir_watch actor instance:
2807 //
2808 // zactor_t *watch = zactor_new (zdir_watch, NULL);
2809 //
2810 // Destroy zdir_watch instance:
2811 //
2812 // zactor_destroy (&watch);
2813 //
2814 // Enable verbose logging of commands and activity:
2815 //
2816 // zstr_send (watch, "VERBOSE");
2817 //
2818 // Subscribe to changes to a directory path:
2819 //
2820 // zsock_send (watch, "ss", "SUBSCRIBE", "directory_path");
2821 //
2822 // Unsubscribe from changes to a directory path:
2823 //
2824 // zsock_send (watch, "ss", "UNSUBSCRIBE", "directory_path");
2825 //
2826 // Receive directory changes:
2827 // zsock_recv (watch, "sp", &path, &patches);
2828 //
2829 // // Delete the received data.
2830 // free (path);
2831 // zlist_destroy (&patches);
2832 class procedure Watch(const Pipe: IZsock; Unused: Pointer);
2833
2834 // Self test of this class.
2835 class procedure Test(Verbose: Boolean);
2836
2837 class function Wrap(handle: PZdir; owned: Boolean): IZdir;
2838 class function UnWrap(const Value: IZdir): PZdir;
2839 protected
2840
2841 // Return directory path
2842 function Path: string;
2843
2844 // Return last modification time for directory.
2845 function Modified: Int64;
2846
2847 // Return total hierarchy size, in bytes of data contained in all files
2848 // in the directory tree.
2849 function Cursize: Longint;
2850
2851 // Return directory count
2852 function Count: NativeUInt;
2853
2854 // Returns a sorted list of zfile objects; Each entry in the list is a pointer
2855 // to a zfile_t item already allocated in the zdir tree. Do not destroy the
2856 // original zdir tree until you are done with this list.
2857 function List: IZlist;
2858
2859 // Remove directory, optionally including all files that it contains, at
2860 // all levels. If force is false, will only remove the directory if empty.
2861 // If force is true, will remove all files and all subdirectories.
2862 procedure Remove(Force: Boolean);
2863
2864 // Return full contents of directory as a zdir_patch list.
2865 function Resync(const Alias: string): IZlist;
2866
2867 // Load directory cache; returns a hash table containing the SHA-1 digests
2868 // of every file in the tree. The cache is saved between runs in .cache.
2869 function Cache: IZhash;
2870
2871 // Print contents of directory to open stream
2872 procedure Fprint(&File: Pointer; Indent: Integer);
2873
2874 // Print contents of directory to stdout
2875 procedure Print(Indent: Integer);
2876 end;
2877
2878 // work with directory patches
2879 TZdirPatch = class(TInterfacedObject, IZdirPatch)
2880 public
2881 FOwned: Boolean;
2882 FHandle: PZdirPatch;
2883 constructor Create(handle: PZdirPatch; owned: Boolean);
2884 public
2885
2886 // Create new patch
2887 constructor New(const Path: string; const &File: IZfile; Op: Integer; const Alias: string);
2888
2889 // Destroy a patch
2890 destructor Destroy; override;
2891
2892 // Self test of this class.
2893 class procedure Test(Verbose: Boolean);
2894
2895 class function Wrap(handle: PZdirPatch; owned: Boolean): IZdirPatch;
2896 class function UnWrap(const Value: IZdirPatch): PZdirPatch;
2897 protected
2898
2899 // Create copy of a patch. If the patch is null, or memory was exhausted,
2900 // returns null.
2901 function Dup: IZdirPatch;
2902
2903 // Return patch file directory path
2904 function Path: string;
2905
2906 // Return patch file item
2907 function &File: IZfile;
2908
2909 // Return operation
2910 function Op: Integer;
2911
2912 // Return patch virtual file path
2913 function Vpath: string;
2914
2915 // Calculate hash digest for file (create only)
2916 procedure DigestSet;
2917
2918 // Return hash digest for patch file
2919 function Digest: string;
2920 end;
2921
2922 // helper functions for working with files.
2923 TZfile = class(TInterfacedObject, IZfile)
2924 public
2925 FOwned: Boolean;
2926 FHandle: PZfile;
2927 constructor Create(handle: PZfile; owned: Boolean);
2928 public
2929
2930 // If file exists, populates properties. CZMQ supports portable symbolic
2931 // links, which are files with the extension ".ln". A symbolic link is a
2932 // text file containing one line, the filename of a target file. Reading
2933 // data from the symbolic link actually reads from the target file. Path
2934 // may be NULL, in which case it is not used.
2935 constructor New(const Path: string; const Name: string);
2936
2937 // Create new temporary file for writing via tmpfile. File is automatically
2938 // deleted on destroy
2939 constructor Tmp;
2940
2941 // Destroy a file item
2942 destructor Destroy; override;
2943
2944 // Self test of this class.
2945 class procedure Test(Verbose: Boolean);
2946
2947 class function Wrap(handle: PZfile; owned: Boolean): IZfile;
2948 class function UnWrap(const Value: IZfile): PZfile;
2949 protected
2950
2951 // Duplicate a file item, returns a newly constructed item. If the file
2952 // is null, or memory was exhausted, returns null.
2953 function Dup: IZfile;
2954
2955 // Return file name, remove path if provided
2956 function Filename(const Path: string): string;
2957
2958 // Refresh file properties from disk; this is not done automatically
2959 // on access methods, otherwise it is not possible to compare directory
2960 // snapshots.
2961 procedure Restat;
2962
2963 // Return when the file was last modified. If you want this to reflect the
2964 // current situation, call zfile_restat before checking this property.
2965 function Modified: Int64;
2966
2967 // Return the last-known size of the file. If you want this to reflect the
2968 // current situation, call zfile_restat before checking this property.
2969 function Cursize: Longint;
2970
2971 // Return true if the file is a directory. If you want this to reflect
2972 // any external changes, call zfile_restat before checking this property.
2973 function IsDirectory: Boolean;
2974
2975 // Return true if the file is a regular file. If you want this to reflect
2976 // any external changes, call zfile_restat before checking this property.
2977 function IsRegular: Boolean;
2978
2979 // Return true if the file is readable by this process. If you want this to
2980 // reflect any external changes, call zfile_restat before checking this
2981 // property.
2982 function IsReadable: Boolean;
2983
2984 // Return true if the file is writeable by this process. If you want this
2985 // to reflect any external changes, call zfile_restat before checking this
2986 // property.
2987 function IsWriteable: Boolean;
2988
2989 // Check if file has stopped changing and can be safely processed.
2990 // Updates the file statistics from disk at every call.
2991 function IsStable: Boolean;
2992
2993 // Return true if the file was changed on disk since the zfile_t object
2994 // was created, or the last zfile_restat() call made on it.
2995 function HasChanged: Boolean;
2996
2997 // Remove the file from disk
2998 procedure Remove;
2999
3000 // Open file for reading
3001 // Returns 0 if OK, -1 if not found or not accessible
3002 function Input: Integer;
3003
3004 // Open file for writing, creating directory if needed
3005 // File is created if necessary; chunks can be written to file at any
3006 // location. Returns 0 if OK, -1 if error.
3007 function Output: Integer;
3008
3009 // Read chunk from file at specified position. If this was the last chunk,
3010 // sets the eof property. Returns a null chunk in case of error.
3011 function Read(Bytes: NativeUInt; Offset: Longint): IZchunk;
3012
3013 // Returns true if zfile_read() just read the last chunk in the file.
3014 function Eof: Boolean;
3015
3016 // Write chunk to file at specified position
3017 // Return 0 if OK, else -1
3018 function Write(const Chunk: IZchunk; Offset: Longint): Integer;
3019
3020 // Read next line of text from file. Returns a pointer to the text line,
3021 // or NULL if there was nothing more to read from the file.
3022 function Readln: string;
3023
3024 // Close file, if open
3025 procedure Close;
3026
3027 // Return file handle, if opened
3028 function Handle: Pointer;
3029
3030 // Calculate SHA1 digest for file, using zdigest class.
3031 function Digest: string;
3032 end;
3033
3034 // working with single message frames
3035 TZframe = class(TInterfacedObject, IZframe)
3036 public
3037 FOwned: Boolean;
3038 FHandle: PZframe;
3039 constructor Create(handle: PZframe; owned: Boolean);
3040 public
3041
3042 // Create a new frame. If size is not null, allocates the frame data
3043 // to the specified size. If additionally, data is not null, copies
3044 // size octets from the specified data into the frame body.
3045 constructor New(Data: PByte; Size: NativeUInt);
3046
3047 // Create an empty (zero-sized) frame
3048 constructor NewEmpty;
3049
3050 // Create a frame with a specified string content.
3051 constructor From(const &String: string);
3052
3053 // Create a new frame from memory. Take ownership of the memory and calling the destructor
3054 // on destroy.
3055 constructor Frommem(Data: PByte; Size: NativeUInt; &Destructor: TZframeDestructorFn; Hint: Pointer);
3056
3057 // Receive frame from socket, returns zframe_t object or NULL if the recv
3058 // was interrupted. Does a blocking recv, if you want to not block then use
3059 // zpoller or zloop.
3060 constructor Recv(const Source: IZSock);
3061
3062 // Destroy a frame
3063 destructor Destroy; override;
3064
3065 // Send a frame to a socket, destroy frame after sending.
3066 // Return -1 on error, 0 on success.
3067 class function Send(var SelfP: IZframe; const Dest: IZSock; Flags: Integer): Integer;
3068
3069 // Probe the supplied object, and report if it looks like a zframe_t.
3070 class function &Is(This: Pointer): Boolean;
3071
3072 // Self test of this class.
3073 class procedure Test(Verbose: Boolean);
3074
3075 class function Wrap(handle: PZframe; owned: Boolean): IZframe;
3076 class function UnWrap(const Value: IZframe): PZframe;
3077 protected
3078
3079 // Return number of bytes in frame data
3080 function Size: NativeUInt;
3081
3082 // Return address of frame data
3083 function Data: PByte;
3084
3085 // Return meta data property for frame
3086 // The caller shall not modify or free the returned value, which shall be
3087 // owned by the message.
3088 function Meta(const &Property: string): string;
3089
3090 // Create a new frame that duplicates an existing frame. If frame is null,
3091 // or memory was exhausted, returns null.
3092 function Dup: IZframe;
3093
3094 // Return frame data encoded as printable hex string, useful for 0MQ UUIDs.
3095 // Caller must free string when finished with it.
3096 function Strhex: string;
3097
3098 // Return frame data copied into freshly allocated string
3099 // Caller must free string when finished with it.
3100 function Strdup: string;
3101
3102 // Return TRUE if frame body is equal to string, excluding terminator
3103 function Streq(const &String: string): Boolean;
3104
3105 // Return frame MORE indicator (1 or 0), set when reading frame from socket
3106 // or by the zframe_set_more() method
3107 function More: Integer;
3108
3109 // Set frame MORE indicator (1 or 0). Note this is NOT used when sending
3110 // frame to socket, you have to specify flag explicitly.
3111 procedure SetMore(More: Integer);
3112
3113 // Return frame routing ID, if the frame came from a ZMQ_SERVER socket.
3114 // Else returns zero.
3115 function RoutingId: Cardinal;
3116
3117 // Set routing ID on frame. This is used if/when the frame is sent to a
3118 // ZMQ_SERVER socket.
3119 procedure SetRoutingId(RoutingId: Cardinal);
3120
3121 // Return frame group of radio-dish pattern.
3122 function Group: string;
3123
3124 // Set group on frame. This is used if/when the frame is sent to a
3125 // ZMQ_RADIO socket.
3126 // Return -1 on error, 0 on success.
3127 function SetGroup(const Group: string): Integer;
3128
3129 // Return TRUE if two frames have identical size and data
3130 // If either frame is NULL, equality is always false.
3131 function Eq(const Other: IZframe): Boolean;
3132
3133 // Set new contents for frame
3134 procedure Reset(Data: PByte; Size: NativeUInt);
3135
3136 // Send message to zsys log sink (may be stdout, or system facility as
3137 // configured by zsys_set_logstream). Prefix shows before frame, if not null.
3138 procedure Print(const Prefix: string);
3139 end;
3140
3141 // generic type-free hash container (simple)
3142 TZhash = class(TInterfacedObject, IZhash)
3143 public
3144 FOwned: Boolean;
3145 FHandle: PZhash;
3146 constructor Create(handle: PZhash; owned: Boolean);
3147 public
3148
3149 // Create a new, empty hash container
3150 constructor New;
3151
3152 // Unpack binary frame into a new hash table. Packed data must follow format
3153 // defined by zhash_pack. Hash table is set to autofree. An empty frame
3154 // unpacks to an empty hash table.
3155 constructor Unpack(const Frame: IZframe);
3156
3157 // Destroy a hash container and all items in it
3158 destructor Destroy; override;
3159
3160 // Self test of this class.
3161 class procedure Test(Verbose: Boolean);
3162
3163 class function Wrap(handle: PZhash; owned: Boolean): IZhash;
3164 class function UnWrap(const Value: IZhash): PZhash;
3165 protected
3166
3167 // Insert item into hash table with specified key and item.
3168 // If key is already present returns -1 and leaves existing item unchanged
3169 // Returns 0 on success.
3170 function Insert(const Key: string; Item: Pointer): Integer;
3171
3172 // Update item into hash table with specified key and item.
3173 // If key is already present, destroys old item and inserts new one.
3174 // Use free_fn method to ensure deallocator is properly called on item.
3175 procedure Update(const Key: string; Item: Pointer);
3176
3177 // Remove an item specified by key from the hash table. If there was no such
3178 // item, this function does nothing.
3179 procedure Delete(const Key: string);
3180
3181 // Return the item at the specified key, or null
3182 function Lookup(const Key: string): Pointer;
3183
3184 // Reindexes an item from an old key to a new key. If there was no such
3185 // item, does nothing. Returns 0 if successful, else -1.
3186 function Rename(const OldKey: string; const NewKey: string): Integer;
3187
3188 // Set a free function for the specified hash table item. When the item is
3189 // destroyed, the free function, if any, is called on that item.
3190 // Use this when hash items are dynamically allocated, to ensure that
3191 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
3192 // Returns the item, or NULL if there is no such item.
3193 function Freefn(const Key: string; FreeFn: TZhashFreeFn): Pointer;
3194
3195 // Return the number of keys/items in the hash table
3196 function Size: NativeUInt;
3197
3198 // Make copy of hash table; if supplied table is null, returns null.
3199 // Does not copy items themselves. Rebuilds new table so may be slow on
3200 // very large tables. NOTE: only works with item values that are strings
3201 // since there's no other way to know how to duplicate the item value.
3202 function Dup: IZhash;
3203
3204 // Return keys for items in table
3205 function Keys: IZlist;
3206
3207 // Simple iterator; returns first item in hash table, in no given order,
3208 // or NULL if the table is empty. This method is simpler to use than the
3209 // foreach() method, which is deprecated. To access the key for this item
3210 // use zhash_cursor(). NOTE: do NOT modify the table while iterating.
3211 function First: Pointer;
3212
3213 // Simple iterator; returns next item in hash table, in no given order,
3214 // or NULL if the last item was already returned. Use this together with
3215 // zhash_first() to process all items in a hash table. If you need the
3216 // items in sorted order, use zhash_keys() and then zlist_sort(). To
3217 // access the key for this item use zhash_cursor(). NOTE: do NOT modify
3218 // the table while iterating.
3219 function Next: Pointer;
3220
3221 // After a successful first/next method, returns the key for the item that
3222 // was returned. This is a constant string that you may not modify or
3223 // deallocate, and which lasts as long as the item in the hash. After an
3224 // unsuccessful first/next, returns NULL.
3225 function Cursor: string;
3226
3227 // Add a comment to hash table before saving to disk. You can add as many
3228 // comment lines as you like. These comment lines are discarded when loading
3229 // the file. If you use a null format, all comments are deleted.
3230 procedure Comment(const Format: string);
3231
3232 // Serialize hash table to a binary frame that can be sent in a message.
3233 // The packed format is compatible with the 'dictionary' type defined in
3234 // http://rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
3235 //
3236 // ; A list of name/value pairs
3237 // dictionary = dict-count *( dict-name dict-value )
3238 // dict-count = number-4
3239 // dict-value = longstr
3240 // dict-name = string
3241 //
3242 // ; Strings are always length + text contents
3243 // longstr = number-4 *VCHAR
3244 // string = number-1 *VCHAR
3245 //
3246 // ; Numbers are unsigned integers in network byte order
3247 // number-1 = 1OCTET
3248 // number-4 = 4OCTET
3249 //
3250 // Comments are not included in the packed data. Item values MUST be
3251 // strings.
3252 function Pack: IZframe;
3253
3254 // Save hash table to a text file in name=value format. Hash values must be
3255 // printable strings; keys may not contain '=' character. Returns 0 if OK,
3256 // else -1 if a file error occurred.
3257 function Save(const Filename: string): Integer;
3258
3259 // Load hash table from a text file in name=value format; hash table must
3260 // already exist. Hash values must printable strings; keys may not contain
3261 // '=' character. Returns 0 if OK, else -1 if a file was not readable.
3262 function Load(const Filename: string): Integer;
3263
3264 // When a hash table was loaded from a file by zhash_load, this method will
3265 // reload the file if it has been modified since, and is "stable", i.e. not
3266 // still changing. Returns 0 if OK, -1 if there was an error reloading the
3267 // file.
3268 function Refresh: Integer;
3269
3270 // Set hash for automatic value destruction. Note that this assumes that
3271 // values are NULL-terminated strings. Do not use with different types.
3272 procedure Autofree;
3273 end;
3274
3275 // extended generic type-free hash container
3276 TZhashx = class(TInterfacedObject, IZhashx)
3277 public
3278 FOwned: Boolean;
3279 FHandle: PZhashx;
3280 constructor Create(handle: PZhashx; owned: Boolean);
3281 public
3282
3283 // Create a new, empty hash container
3284 constructor New;
3285
3286 // Unpack binary frame into a new hash table. Packed data must follow format
3287 // defined by zhashx_pack. Hash table is set to autofree. An empty frame
3288 // unpacks to an empty hash table.
3289 constructor Unpack(const Frame: IZframe);
3290
3291 // Same as unpack but uses a user-defined deserializer function to convert
3292 // a longstr back into item format.
3293 constructor UnpackOwn(const Frame: IZframe; Deserializer: TZhashxDeserializerFn);
3294
3295 // Destroy a hash container and all items in it
3296 destructor Destroy; override;
3297
3298 // Self test of this class.
3299 class procedure Test(Verbose: Boolean);
3300
3301 class function Wrap(handle: PZhashx; owned: Boolean): IZhashx;
3302 class function UnWrap(const Value: IZhashx): PZhashx;
3303 protected
3304
3305 // Insert item into hash table with specified key and item.
3306 // If key is already present returns -1 and leaves existing item unchanged
3307 // Returns 0 on success.
3308 function Insert(Key: Pointer; Item: Pointer): Integer;
3309
3310 // Update or insert item into hash table with specified key and item. If the
3311 // key is already present, destroys old item and inserts new one. If you set
3312 // a container item destructor, this is called on the old value. If the key
3313 // was not already present, inserts a new item. Sets the hash cursor to the
3314 // new item.
3315 procedure Update(Key: Pointer; Item: Pointer);
3316
3317 // Remove an item specified by key from the hash table. If there was no such
3318 // item, this function does nothing.
3319 procedure Delete(Key: Pointer);
3320
3321 // Delete all items from the hash table. If the key destructor is
3322 // set, calls it on every key. If the item destructor is set, calls
3323 // it on every item.
3324 procedure Purge;
3325
3326 // Return the item at the specified key, or null
3327 function Lookup(Key: Pointer): Pointer;
3328
3329 // Reindexes an item from an old key to a new key. If there was no such
3330 // item, does nothing. Returns 0 if successful, else -1.
3331 function Rename(OldKey: Pointer; NewKey: Pointer): Integer;
3332
3333 // Set a free function for the specified hash table item. When the item is
3334 // destroyed, the free function, if any, is called on that item.
3335 // Use this when hash items are dynamically allocated, to ensure that
3336 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
3337 // Returns the item, or NULL if there is no such item.
3338 function Freefn(Key: Pointer; FreeFn: TZhashxFreeFn): Pointer;
3339
3340 // Return the number of keys/items in the hash table
3341 function Size: NativeUInt;
3342
3343 // Return a zlistx_t containing the keys for the items in the
3344 // table. Uses the key_duplicator to duplicate all keys and sets the
3345 // key_destructor as destructor for the list.
3346 function Keys: IZlistx;
3347
3348 // Return a zlistx_t containing the values for the items in the
3349 // table. Uses the duplicator to duplicate all items and sets the
3350 // destructor as destructor for the list.
3351 function Values: IZlistx;
3352
3353 // Simple iterator; returns first item in hash table, in no given order,
3354 // or NULL if the table is empty. This method is simpler to use than the
3355 // foreach() method, which is deprecated. To access the key for this item
3356 // use zhashx_cursor(). NOTE: do NOT modify the table while iterating.
3357 function First: Pointer;
3358
3359 // Simple iterator; returns next item in hash table, in no given order,
3360 // or NULL if the last item was already returned. Use this together with
3361 // zhashx_first() to process all items in a hash table. If you need the
3362 // items in sorted order, use zhashx_keys() and then zlistx_sort(). To
3363 // access the key for this item use zhashx_cursor(). NOTE: do NOT modify
3364 // the table while iterating.
3365 function Next: Pointer;
3366
3367 // After a successful first/next method, returns the key for the item that
3368 // was returned. This is a constant string that you may not modify or
3369 // deallocate, and which lasts as long as the item in the hash. After an
3370 // unsuccessful first/next, returns NULL.
3371 function Cursor: Pointer;
3372
3373 // Add a comment to hash table before saving to disk. You can add as many
3374 // comment lines as you like. These comment lines are discarded when loading
3375 // the file. If you use a null format, all comments are deleted.
3376 procedure Comment(const Format: string);
3377
3378 // Save hash table to a text file in name=value format. Hash values must be
3379 // printable strings; keys may not contain '=' character. Returns 0 if OK,
3380 // else -1 if a file error occurred.
3381 function Save(const Filename: string): Integer;
3382
3383 // Load hash table from a text file in name=value format; hash table must
3384 // already exist. Hash values must printable strings; keys may not contain
3385 // '=' character. Returns 0 if OK, else -1 if a file was not readable.
3386 function Load(const Filename: string): Integer;
3387
3388 // When a hash table was loaded from a file by zhashx_load, this method will
3389 // reload the file if it has been modified since, and is "stable", i.e. not
3390 // still changing. Returns 0 if OK, -1 if there was an error reloading the
3391 // file.
3392 function Refresh: Integer;
3393
3394 // Serialize hash table to a binary frame that can be sent in a message.
3395 // The packed format is compatible with the 'dictionary' type defined in
3396 // http://rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
3397 //
3398 // ; A list of name/value pairs
3399 // dictionary = dict-count *( dict-name dict-value )
3400 // dict-count = number-4
3401 // dict-value = longstr
3402 // dict-name = string
3403 //
3404 // ; Strings are always length + text contents
3405 // longstr = number-4 *VCHAR
3406 // string = number-1 *VCHAR
3407 //
3408 // ; Numbers are unsigned integers in network byte order
3409 // number-1 = 1OCTET
3410 // number-4 = 4OCTET
3411 //
3412 // Comments are not included in the packed data. Item values MUST be
3413 // strings.
3414 function Pack: IZframe;
3415
3416 // Same as pack but uses a user-defined serializer function to convert items
3417 // into longstr.
3418 function PackOwn(Serializer: TZhashxSerializerFn): IZframe;
3419
3420 // Make a copy of the list; items are duplicated if you set a duplicator
3421 // for the list, otherwise not. Copying a null reference returns a null
3422 // reference. Note that this method's behavior changed slightly for CZMQ
3423 // v3.x, as it does not set nor respect autofree. It does however let you
3424 // duplicate any hash table safely. The old behavior is in zhashx_dup_v2.
3425 function Dup: IZhashx;
3426
3427 // Set a user-defined deallocator for hash items; by default items are not
3428 // freed when the hash is destroyed.
3429 procedure SetDestructor(&Destructor: TZhashxDestructorFn);
3430
3431 // Set a user-defined duplicator for hash items; by default items are not
3432 // copied when the hash is duplicated.
3433 procedure SetDuplicator(Duplicator: TZhashxDuplicatorFn);
3434
3435 // Set a user-defined deallocator for keys; by default keys are freed
3436 // when the hash is destroyed using free().
3437 procedure SetKeyDestructor(&Destructor: TZhashxDestructorFn);
3438
3439 // Set a user-defined duplicator for keys; by default keys are duplicated
3440 // using strdup.
3441 procedure SetKeyDuplicator(Duplicator: TZhashxDuplicatorFn);
3442
3443 // Set a user-defined comparator for keys; by default keys are
3444 // compared using strcmp.
3445 // The callback function should return zero (0) on matching
3446 // items.
3447 procedure SetKeyComparator(Comparator: TZhashxComparatorFn);
3448
3449 // Set a user-defined hash function for keys; by default keys are
3450 // hashed by a modified Bernstein hashing function.
3451 procedure SetKeyHasher(Hasher: TZhashxHashFn);
3452
3453 // Make copy of hash table; if supplied table is null, returns null.
3454 // Does not copy items themselves. Rebuilds new table so may be slow on
3455 // very large tables. NOTE: only works with item values that are strings
3456 // since there's no other way to know how to duplicate the item value.
3457 function DupV2: IZhashx;
3458 end;
3459
3460 // List of network interfaces available on system
3461 TZiflist = class(TInterfacedObject, IZiflist)
3462 public
3463 FOwned: Boolean;
3464 FHandle: PZiflist;
3465 constructor Create(handle: PZiflist; owned: Boolean);
3466 public
3467
3468 // Get a list of network interfaces currently defined on the system
3469 constructor New;
3470
3471 // Destroy a ziflist instance
3472 destructor Destroy; override;
3473
3474 // Get a list of network interfaces currently defined on the system
3475 // Includes IPv6 interfaces
3476 class function NewIpv6: IZiflist;
3477
3478 // Self test of this class.
3479 class procedure Test(Verbose: Boolean);
3480
3481 class function Wrap(handle: PZiflist; owned: Boolean): IZiflist;
3482 class function UnWrap(const Value: IZiflist): PZiflist;
3483 protected
3484
3485 // Reload network interfaces from system
3486 procedure Reload;
3487
3488 // Return the number of network interfaces on system
3489 function Size: NativeUInt;
3490
3491 // Get first network interface, return NULL if there are none
3492 function First: string;
3493
3494 // Get next network interface, return NULL if we hit the last one
3495 function Next: string;
3496
3497 // Return the current interface IP address as a printable string
3498 function Address: string;
3499
3500 // Return the current interface broadcast address as a printable string
3501 function Broadcast: string;
3502
3503 // Return the current interface network mask as a printable string
3504 function Netmask: string;
3505
3506 // Return the list of interfaces.
3507 procedure Print;
3508
3509 // Reload network interfaces from system, including IPv6
3510 procedure ReloadIpv6;
3511
3512 // Return true if the current interface uses IPv6
3513 function IsIpv6: Boolean;
3514 end;
3515
3516 // simple generic list container
3517 TZlist = class(TInterfacedObject, IZlist)
3518 public
3519 FOwned: Boolean;
3520 FHandle: PZlist;
3521 constructor Create(handle: PZlist; owned: Boolean);
3522 public
3523
3524 // Create a new list container
3525 constructor New;
3526
3527 // Destroy a list container
3528 destructor Destroy; override;
3529
3530 // Self test of this class.
3531 class procedure Test(Verbose: Boolean);
3532
3533 class function Wrap(handle: PZlist; owned: Boolean): IZlist;
3534 class function UnWrap(const Value: IZlist): PZlist;
3535 protected
3536
3537 // Return the item at the head of list. If the list is empty, returns NULL.
3538 // Leaves cursor pointing at the head item, or NULL if the list is empty.
3539 function First: Pointer;
3540
3541 // Return the next item. If the list is empty, returns NULL. To move to
3542 // the start of the list call zlist_first (). Advances the cursor.
3543 function Next: Pointer;
3544
3545 // Return the item at the tail of list. If the list is empty, returns NULL.
3546 // Leaves cursor pointing at the tail item, or NULL if the list is empty.
3547 function Last: Pointer;
3548
3549 // Return first item in the list, or null, leaves the cursor
3550 function Head: Pointer;
3551
3552 // Return last item in the list, or null, leaves the cursor
3553 function Tail: Pointer;
3554
3555 // Return the current item of list. If the list is empty, returns NULL.
3556 // Leaves cursor pointing at the current item, or NULL if the list is empty.
3557 function Item: Pointer;
3558
3559 // Append an item to the end of the list, return 0 if OK or -1 if this
3560 // failed for some reason (out of memory). Note that if a duplicator has
3561 // been set, this method will also duplicate the item.
3562 function Append(Item: Pointer): Integer;
3563
3564 // Push an item to the start of the list, return 0 if OK or -1 if this
3565 // failed for some reason (out of memory). Note that if a duplicator has
3566 // been set, this method will also duplicate the item.
3567 function Push(Item: Pointer): Integer;
3568
3569 // Pop the item off the start of the list, if any
3570 function Pop: Pointer;
3571
3572 // Checks if an item already is present. Uses compare method to determine if
3573 // items are equal. If the compare method is NULL the check will only compare
3574 // pointers. Returns true if item is present else false.
3575 function Exists(Item: Pointer): Boolean;
3576
3577 // Remove the specified item from the list if present
3578 procedure Remove(Item: Pointer);
3579
3580 // Make a copy of list. If the list has autofree set, the copied list will
3581 // duplicate all items, which must be strings. Otherwise, the list will hold
3582 // pointers back to the items in the original list. If list is null, returns
3583 // NULL.
3584 function Dup: IZlist;
3585
3586 // Purge all items from list
3587 procedure Purge;
3588
3589 // Return number of items in the list
3590 function Size: NativeUInt;
3591
3592 // Sort the list. If the compare function is null, sorts the list by
3593 // ascending key value using a straight ASCII comparison. If you specify
3594 // a compare function, this decides how items are sorted. The sort is not
3595 // stable, so may reorder items with the same keys. The algorithm used is
3596 // combsort, a compromise between performance and simplicity.
3597 procedure Sort(Compare: TZlistCompareFn);
3598
3599 // Set list for automatic item destruction; item values MUST be strings.
3600 // By default a list item refers to a value held elsewhere. When you set
3601 // this, each time you append or push a list item, zlist will take a copy
3602 // of the string value. Then, when you destroy the list, it will free all
3603 // item values automatically. If you use any other technique to allocate
3604 // list values, you must free them explicitly before destroying the list.
3605 // The usual technique is to pop list items and destroy them, until the
3606 // list is empty.
3607 procedure Autofree;
3608
3609 // Sets a compare function for this list. The function compares two items.
3610 // It returns an integer less than, equal to, or greater than zero if the
3611 // first item is found, respectively, to be less than, to match, or be
3612 // greater than the second item.
3613 // This function is used for sorting, removal and exists checking.
3614 procedure Comparefn(Fn: TZlistCompareFn);
3615
3616 // Set a free function for the specified list item. When the item is
3617 // destroyed, the free function, if any, is called on that item.
3618 // Use this when list items are dynamically allocated, to ensure that
3619 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
3620 // Returns the item, or NULL if there is no such item.
3621 function Freefn(Item: Pointer; Fn: TZlistFreeFn; AtTail: Boolean): Pointer;
3622 end;
3623
3624 // extended generic list container
3625 TZlistx = class(TInterfacedObject, IZlistx)
3626 public
3627 FOwned: Boolean;
3628 FHandle: PZlistx;
3629 constructor Create(handle: PZlistx; owned: Boolean);
3630 public
3631
3632 // Create a new, empty list.
3633 constructor New;
3634
3635 // Unpack binary frame into a new list. Packed data must follow format
3636 // defined by zlistx_pack. List is set to autofree. An empty frame
3637 // unpacks to an empty list.
3638 constructor Unpack(const Frame: IZframe);
3639
3640 // Destroy a list. If an item destructor was specified, all items in the
3641 // list are automatically destroyed as well.
3642 destructor Destroy; override;
3643
3644 // Returns the item associated with the given list handle, or NULL if passed
3645 // in handle is NULL. Asserts that the passed in handle points to a list element.
3646 class function HandleItem(Handle: Pointer): Pointer;
3647
3648 // Self test of this class.
3649 class procedure Test(Verbose: Boolean);
3650
3651 class function Wrap(handle: PZlistx; owned: Boolean): IZlistx;
3652 class function UnWrap(const Value: IZlistx): PZlistx;
3653 protected
3654
3655 // Add an item to the head of the list. Calls the item duplicator, if any,
3656 // on the item. Resets cursor to list head. Returns an item handle on
3657 // success, NULL if memory was exhausted.
3658 function AddStart(Item: Pointer): Pointer;
3659
3660 // Add an item to the tail of the list. Calls the item duplicator, if any,
3661 // on the item. Resets cursor to list head. Returns an item handle on
3662 // success, NULL if memory was exhausted.
3663 function AddEnd(Item: Pointer): Pointer;
3664
3665 // Return the number of items in the list
3666 function Size: NativeUInt;
3667
3668 // Return first item in the list, or null, leaves the cursor
3669 function Head: Pointer;
3670
3671 // Return last item in the list, or null, leaves the cursor
3672 function Tail: Pointer;
3673
3674 // Return the item at the head of list. If the list is empty, returns NULL.
3675 // Leaves cursor pointing at the head item, or NULL if the list is empty.
3676 function First: Pointer;
3677
3678 // Return the next item. At the end of the list (or in an empty list),
3679 // returns NULL. Use repeated zlistx_next () calls to work through the list
3680 // from zlistx_first (). First time, acts as zlistx_first().
3681 function Next: Pointer;
3682
3683 // Return the previous item. At the start of the list (or in an empty list),
3684 // returns NULL. Use repeated zlistx_prev () calls to work through the list
3685 // backwards from zlistx_last (). First time, acts as zlistx_last().
3686 function Prev: Pointer;
3687
3688 // Return the item at the tail of list. If the list is empty, returns NULL.
3689 // Leaves cursor pointing at the tail item, or NULL if the list is empty.
3690 function Last: Pointer;
3691
3692 // Returns the value of the item at the cursor, or NULL if the cursor is
3693 // not pointing to an item.
3694 function Item: Pointer;
3695
3696 // Returns the handle of the item at the cursor, or NULL if the cursor is
3697 // not pointing to an item.
3698 function Cursor: Pointer;
3699
3700 // Find an item in the list, searching from the start. Uses the item
3701 // comparator, if any, else compares item values directly. Returns the
3702 // item handle found, or NULL. Sets the cursor to the found item, if any.
3703 function Find(Item: Pointer): Pointer;
3704
3705 // Detach an item from the list, using its handle. The item is not modified,
3706 // and the caller is responsible for destroying it if necessary. If handle is
3707 // null, detaches the first item on the list. Returns item that was detached,
3708 // or null if none was. If cursor was at item, moves cursor to previous item,
3709 // so you can detach items while iterating forwards through a list.
3710 function Detach(Handle: Pointer): Pointer;
3711
3712 // Detach item at the cursor, if any, from the list. The item is not modified,
3713 // and the caller is responsible for destroying it as necessary. Returns item
3714 // that was detached, or null if none was. Moves cursor to previous item, so
3715 // you can detach items while iterating forwards through a list.
3716 function DetachCur: Pointer;
3717
3718 // Delete an item, using its handle. Calls the item destructor is any is
3719 // set. If handle is null, deletes the first item on the list. Returns 0
3720 // if an item was deleted, -1 if not. If cursor was at item, moves cursor
3721 // to previous item, so you can delete items while iterating forwards
3722 // through a list.
3723 function Delete(Handle: Pointer): Integer;
3724
3725 // Move an item to the start of the list, via its handle.
3726 procedure MoveStart(Handle: Pointer);
3727
3728 // Move an item to the end of the list, via its handle.
3729 procedure MoveEnd(Handle: Pointer);
3730
3731 // Remove all items from the list, and destroy them if the item destructor
3732 // is set.
3733 procedure Purge;
3734
3735 // Sort the list. If an item comparator was set, calls that to compare
3736 // items, otherwise compares on item value. The sort is not stable, so may
3737 // reorder equal items.
3738 procedure Sort;
3739
3740 // Create a new node and insert it into a sorted list. Calls the item
3741 // duplicator, if any, on the item. If low_value is true, starts searching
3742 // from the start of the list, otherwise searches from the end. Use the item
3743 // comparator, if any, to find where to place the new node. Returns a handle
3744 // to the new node, or NULL if memory was exhausted. Resets the cursor to the
3745 // list head.
3746 function Insert(Item: Pointer; LowValue: Boolean): Pointer;
3747
3748 // Move an item, specified by handle, into position in a sorted list. Uses
3749 // the item comparator, if any, to determine the new location. If low_value
3750 // is true, starts searching from the start of the list, otherwise searches
3751 // from the end.
3752 procedure Reorder(Handle: Pointer; LowValue: Boolean);
3753
3754 // Make a copy of the list; items are duplicated if you set a duplicator
3755 // for the list, otherwise not. Copying a null reference returns a null
3756 // reference.
3757 function Dup: IZlistx;
3758
3759 // Set a user-defined deallocator for list items; by default items are not
3760 // freed when the list is destroyed.
3761 procedure SetDestructor(&Destructor: TZlistxDestructorFn);
3762
3763 // Set a user-defined duplicator for list items; by default items are not
3764 // copied when the list is duplicated.
3765 procedure SetDuplicator(Duplicator: TZlistxDuplicatorFn);
3766
3767 // Set a user-defined comparator for zlistx_find and zlistx_sort; the method
3768 // must return -1, 0, or 1 depending on whether item1 is less than, equal to,
3769 // or greater than, item2.
3770 procedure SetComparator(Comparator: TZlistxComparatorFn);
3771
3772 // Serialize list to a binary frame that can be sent in a message.
3773 // The packed format is compatible with the 'strings' type implemented by zproto:
3774 //
3775 // ; A list of strings
3776 // list = list-count *longstr
3777 // list-count = number-4
3778 //
3779 // ; Strings are always length + text contents
3780 // longstr = number-4 *VCHAR
3781 //
3782 // ; Numbers are unsigned integers in network byte order
3783 // number-4 = 4OCTET
3784 function Pack: IZframe;
3785 end;
3786
3787 // event-driven reactor
3788 TZloop = class(TInterfacedObject, IZloop)
3789 public
3790 FOwned: Boolean;
3791 FHandle: PZloop;
3792 constructor Create(handle: PZloop; owned: Boolean);
3793 public
3794
3795 // Create a new zloop reactor
3796 constructor New;
3797
3798 // Destroy a reactor
3799 destructor Destroy; override;
3800
3801 // Self test of this class.
3802 class procedure Test(Verbose: Boolean);
3803
3804 class function Wrap(handle: PZloop; owned: Boolean): IZloop;
3805 class function UnWrap(const Value: IZloop): PZloop;
3806 protected
3807
3808 // Register socket reader with the reactor. When the reader has messages,
3809 // the reactor will call the handler, passing the arg. Returns 0 if OK, -1
3810 // if there was an error. If you register the same socket more than once,
3811 // each instance will invoke its corresponding handler.
3812 function Reader(const Sock: IZsock; Handler: TZloopReaderFn; Arg: Pointer): Integer;
3813
3814 // Cancel a socket reader from the reactor. If multiple readers exist for
3815 // same socket, cancels ALL of them.
3816 procedure ReaderEnd(const Sock: IZsock);
3817
3818 // Configure a registered reader to ignore errors. If you do not set this,
3819 // then readers that have errors are removed from the reactor silently.
3820 procedure ReaderSetTolerant(const Sock: IZsock);
3821
3822 // Register low-level libzmq pollitem with the reactor. When the pollitem
3823 // is ready, will call the handler, passing the arg. Returns 0 if OK, -1
3824 // if there was an error. If you register the pollitem more than once, each
3825 // instance will invoke its corresponding handler. A pollitem with
3826 // socket=NULL and fd=0 means 'poll on FD zero'.
3827 function Poller(Item: Pointer; Handler: TZloopFn; Arg: Pointer): Integer;
3828
3829 // Cancel a pollitem from the reactor, specified by socket or FD. If both
3830 // are specified, uses only socket. If multiple poll items exist for same
3831 // socket/FD, cancels ALL of them.
3832 procedure PollerEnd(Item: Pointer);
3833
3834 // Configure a registered poller to ignore errors. If you do not set this,
3835 // then poller that have errors are removed from the reactor silently.
3836 procedure PollerSetTolerant(Item: Pointer);
3837
3838 // Register a timer that expires after some delay and repeats some number of
3839 // times. At each expiry, will call the handler, passing the arg. To run a
3840 // timer forever, use 0 times. Returns a timer_id that is used to cancel the
3841 // timer in the future. Returns -1 if there was an error.
3842 function Timer(Delay: NativeUInt; Times: NativeUInt; Handler: TZloopTimerFn; Arg: Pointer): Integer;
3843
3844 // Cancel a specific timer identified by a specific timer_id (as returned by
3845 // zloop_timer).
3846 function TimerEnd(TimerId: Integer): Integer;
3847
3848 // Register a ticket timer. Ticket timers are very fast in the case where
3849 // you use a lot of timers (thousands), and frequently remove and add them.
3850 // The main use case is expiry timers for servers that handle many clients,
3851 // and which reset the expiry timer for each message received from a client.
3852 // Whereas normal timers perform poorly as the number of clients grows, the
3853 // cost of ticket timers is constant, no matter the number of clients. You
3854 // must set the ticket delay using zloop_set_ticket_delay before creating a
3855 // ticket. Returns a handle to the timer that you should use in
3856 // zloop_ticket_reset and zloop_ticket_delete.
3857 function Ticket(Handler: TZloopTimerFn; Arg: Pointer): Pointer;
3858
3859 // Reset a ticket timer, which moves it to the end of the ticket list and
3860 // resets its execution time. This is a very fast operation.
3861 procedure TicketReset(Handle: Pointer);
3862
3863 // Delete a ticket timer. We do not actually delete the ticket here, as
3864 // other code may still refer to the ticket. We mark as deleted, and remove
3865 // later and safely.
3866 procedure TicketDelete(Handle: Pointer);
3867
3868 // Set the ticket delay, which applies to all tickets. If you lower the
3869 // delay and there are already tickets created, the results are undefined.
3870 procedure SetTicketDelay(TicketDelay: NativeUInt);
3871
3872 // Set hard limit on number of timers allowed. Setting more than a small
3873 // number of timers (10-100) can have a dramatic impact on the performance
3874 // of the reactor. For high-volume cases, use ticket timers. If the hard
3875 // limit is reached, the reactor stops creating new timers and logs an
3876 // error.
3877 procedure SetMaxTimers(MaxTimers: NativeUInt);
3878
3879 // Set verbose tracing of reactor on/off. The default verbose setting is
3880 // off (false).
3881 procedure SetVerbose(Verbose: Boolean);
3882
3883 // By default the reactor stops if the process receives a SIGINT or SIGTERM
3884 // signal. This makes it impossible to shut-down message based architectures
3885 // like zactors. This method lets you switch off break handling. The default
3886 // nonstop setting is off (false).
3887 procedure SetNonstop(Nonstop: Boolean);
3888
3889 // Start the reactor. Takes control of the thread and returns when the 0MQ
3890 // context is terminated or the process is interrupted, or any event handler
3891 // returns -1. Event handlers may register new sockets and timers, and
3892 // cancel sockets. Returns 0 if interrupted, -1 if canceled by a handler.
3893 function Start: Integer;
3894 end;
3895
3896 // working with multipart messages
3897 TZmsg = class(TInterfacedObject, IZmsg)
3898 public
3899 FOwned: Boolean;
3900 FHandle: PZmsg;
3901 constructor Create(handle: PZmsg; owned: Boolean);
3902 public
3903
3904 // Create a new empty message object
3905 constructor New;
3906
3907 // Receive message from socket, returns zmsg_t object or NULL if the recv
3908 // was interrupted. Does a blocking recv. If you want to not block then use
3909 // the zloop class or zmsg_recv_nowait or zmq_poll to check for socket input
3910 // before receiving.
3911 constructor Recv(const Source: IZSock);
3912
3913 // Load/append an open file into new message, return the message.
3914 // Returns NULL if the message could not be loaded.
3915 constructor Load(&File: Pointer);
3916
3917 // Decodes a serialized message frame created by zmsg_encode () and returns
3918 // a new zmsg_t object. Returns NULL if the frame was badly formatted or
3919 // there was insufficient memory to work.
3920 constructor Decode(const Frame: IZframe);
3921
3922 // Generate a signal message encoding the given status. A signal is a short
3923 // message carrying a 1-byte success/failure code (by convention, 0 means
3924 // OK). Signals are encoded to be distinguishable from "normal" messages.
3925 constructor NewSignal(Status: Byte);
3926
3927 // Destroy a message object and all frames it contains
3928 destructor Destroy; override;
3929
3930 // Send message to destination socket, and destroy the message after sending
3931 // it successfully. If the message has no frames, sends nothing but destroys
3932 // the message anyhow. Nullifies the caller's reference to the message (as
3933 // it is a destructor).
3934 class function Send(var SelfP: IZmsg; const Dest: IZSock): Integer;
3935
3936 // Send message to destination socket as part of a multipart sequence, and
3937 // destroy the message after sending it successfully. Note that after a
3938 // zmsg_sendm, you must call zmsg_send or another method that sends a final
3939 // message part. If the message has no frames, sends nothing but destroys
3940 // the message anyhow. Nullifies the caller's reference to the message (as
3941 // it is a destructor).
3942 class function Sendm(var SelfP: IZmsg; const Dest: IZSock): Integer;
3943
3944 // Probe the supplied object, and report if it looks like a zmsg_t.
3945 class function &Is(This: Pointer): Boolean;
3946
3947 // Self test of this class.
3948 class procedure Test(Verbose: Boolean);
3949
3950 class function Wrap(handle: PZmsg; owned: Boolean): IZmsg;
3951 class function UnWrap(const Value: IZmsg): PZmsg;
3952 protected
3953
3954 // Return size of message, i.e. number of frames (0 or more).
3955 function Size: NativeUInt;
3956
3957 // Return total size of all frames in message.
3958 function ContentSize: NativeUInt;
3959
3960 // Return message routing ID, if the message came from a ZMQ_SERVER socket.
3961 // Else returns zero.
3962 function RoutingId: Cardinal;
3963
3964 // Set routing ID on message. This is used if/when the message is sent to a
3965 // ZMQ_SERVER socket.
3966 procedure SetRoutingId(RoutingId: Cardinal);
3967
3968 // Push frame to the front of the message, i.e. before all other frames.
3969 // Message takes ownership of frame, will destroy it when message is sent.
3970 // Returns 0 on success, -1 on error. Deprecates zmsg_push, which did not
3971 // nullify the caller's frame reference.
3972 function Prepend(var FrameP: IZframe): Integer;
3973
3974 // Add frame to the end of the message, i.e. after all other frames.
3975 // Message takes ownership of frame, will destroy it when message is sent.
3976 // Returns 0 on success. Deprecates zmsg_add, which did not nullify the
3977 // caller's frame reference.
3978 function Append(var FrameP: IZframe): Integer;
3979
3980 // Remove first frame from message, if any. Returns frame, or NULL.
3981 function Pop: IZframe;
3982
3983 // Push block of memory to front of message, as a new frame.
3984 // Returns 0 on success, -1 on error.
3985 function Pushmem(Data: PByte; Size: NativeUInt): Integer;
3986
3987 // Add block of memory to the end of the message, as a new frame.
3988 // Returns 0 on success, -1 on error.
3989 function Addmem(Data: PByte; Size: NativeUInt): Integer;
3990
3991 // Push string as new frame to front of message.
3992 // Returns 0 on success, -1 on error.
3993 function Pushstr(const &String: string): Integer;
3994
3995 // Push string as new frame to end of message.
3996 // Returns 0 on success, -1 on error.
3997 function Addstr(const &String: string): Integer;
3998
3999 // Push formatted string as new frame to front of message.
4000 // Returns 0 on success, -1 on error.
4001 function Pushstrf(const Format: string): Integer;
4002
4003 // Push formatted string as new frame to end of message.
4004 // Returns 0 on success, -1 on error.
4005 function Addstrf(const Format: string): Integer;
4006
4007 // Pop frame off front of message, return as fresh string. If there were
4008 // no more frames in the message, returns NULL.
4009 function Popstr: string;
4010
4011 // Push encoded message as a new frame. Message takes ownership of
4012 // submessage, so the original is destroyed in this call. Returns 0 on
4013 // success, -1 on error.
4014 function Addmsg(var MsgP: IZmsg): Integer;
4015
4016 // Remove first submessage from message, if any. Returns zmsg_t, or NULL if
4017 // decoding was not successful.
4018 function Popmsg: IZmsg;
4019
4020 // Remove specified frame from list, if present. Does not destroy frame.
4021 procedure Remove(const Frame: IZframe);
4022
4023 // Set cursor to first frame in message. Returns frame, or NULL, if the
4024 // message is empty. Use this to navigate the frames as a list.
4025 function First: IZframe;
4026
4027 // Return the next frame. If there are no more frames, returns NULL. To move
4028 // to the first frame call zmsg_first(). Advances the cursor.
4029 function Next: IZframe;
4030
4031 // Return the last frame. If there are no frames, returns NULL.
4032 function Last: IZframe;
4033
4034 // Save message to an open file, return 0 if OK, else -1. The message is
4035 // saved as a series of frames, each with length and data. Note that the
4036 // file is NOT guaranteed to be portable between operating systems, not
4037 // versions of CZMQ. The file format is at present undocumented and liable
4038 // to arbitrary change.
4039 function Save(&File: Pointer): Integer;
4040
4041 // Serialize multipart message to a single message frame. Use this method
4042 // to send structured messages across transports that do not support
4043 // multipart data. Allocates and returns a new frame containing the
4044 // serialized message. To decode a serialized message frame, use
4045 // zmsg_decode ().
4046 function Encode: IZframe;
4047
4048 // Create copy of message, as new message object. Returns a fresh zmsg_t
4049 // object. If message is null, or memory was exhausted, returns null.
4050 function Dup: IZmsg;
4051
4052 // Send message to zsys log sink (may be stdout, or system facility as
4053 // configured by zsys_set_logstream).
4054 procedure Print;
4055
4056 // Return true if the two messages have the same number of frames and each
4057 // frame in the first message is identical to the corresponding frame in the
4058 // other message. As with zframe_eq, return false if either message is NULL.
4059 function Eq(const Other: IZmsg): Boolean;
4060
4061 // Return signal value, 0 or greater, if message is a signal, -1 if not.
4062 function Signal: Integer;
4063 end;
4064
4065 // event-driven reactor
4066 TZpoller = class(TInterfacedObject, IZpoller)
4067 public
4068 FOwned: Boolean;
4069 FHandle: PZpoller;
4070 constructor Create(handle: PZpoller; owned: Boolean);
4071 public
4072
4073 // Create new poller, specifying zero or more readers. The list of
4074 // readers ends in a NULL. Each reader can be a zsock_t instance, a
4075 // zactor_t instance, a libzmq socket (void *), or a file handle.
4076 constructor New(const Reader: IZSock);
4077
4078 // Destroy a poller
4079 destructor Destroy; override;
4080
4081 // Self test of this class.
4082 class procedure Test(Verbose: Boolean);
4083
4084 class function Wrap(handle: PZpoller; owned: Boolean): IZpoller;
4085 class function UnWrap(const Value: IZpoller): PZpoller;
4086 protected
4087
4088 // Add a reader to be polled. Returns 0 if OK, -1 on failure. The reader may
4089 // be a libzmq void * socket, a zsock_t instance, or a zactor_t instance.
4090 function Add(const Reader: IZSock): Integer;
4091
4092 // Remove a reader from the poller; returns 0 if OK, -1 on failure. The reader
4093 // must have been passed during construction, or in an zpoller_add () call.
4094 function Remove(Reader: Pointer): Integer;
4095
4096 // By default the poller stops if the process receives a SIGINT or SIGTERM
4097 // signal. This makes it impossible to shut-down message based architectures
4098 // like zactors. This method lets you switch off break handling. The default
4099 // nonstop setting is off (false).
4100 procedure SetNonstop(Nonstop: Boolean);
4101
4102 // Poll the registered readers for I/O, return first reader that has input.
4103 // The reader will be a libzmq void * socket, or a zsock_t or zactor_t
4104 // instance as specified in zpoller_new/zpoller_add. The timeout should be
4105 // zero or greater, or -1 to wait indefinitely. Socket priority is defined
4106 // by their order in the poll list. If you need a balanced poll, use the low
4107 // level zmq_poll method directly. If the poll call was interrupted (SIGINT),
4108 // or the ZMQ context was destroyed, or the timeout expired, returns NULL.
4109 // You can test the actual exit condition by calling zpoller_expired () and
4110 // zpoller_terminated (). The timeout is in msec.
4111 function Wait(Timeout: Integer): IZSock;
4112
4113 // Return true if the last zpoller_wait () call ended because the timeout
4114 // expired, without any error.
4115 function Expired: Boolean;
4116
4117 // Return true if the last zpoller_wait () call ended because the process
4118 // was interrupted, or the parent context was destroyed.
4119 function Terminated: Boolean;
4120 end;
4121
4122 // high-level socket API that hides libzmq contexts and sockets
4123 TZsock = class(TInterfacedObject, IZsock)
4124 public
4125 FOwned: Boolean;
4126 FHandle: PZsock;
4127 constructor Create(handle: PZsock; owned: Boolean);
4128 public
4129
4130 // Create a new socket. Returns the new socket, or NULL if the new socket
4131 // could not be created. Note that the symbol zsock_new (and other
4132 // constructors/destructors for zsock) are redirected to the *_checked
4133 // variant, enabling intelligent socket leak detection. This can have
4134 // performance implications if you use a LOT of sockets. To turn off this
4135 // redirection behaviour, define ZSOCK_NOCHECK.
4136 constructor New(&Type: Integer);
4137
4138 // Create a PUB socket. Default action is bind.
4139 constructor NewPub(const Endpoint: string);
4140
4141 // Create a SUB socket, and optionally subscribe to some prefix string. Default
4142 // action is connect.
4143 constructor NewSub(const Endpoint: string; const Subscribe: string);
4144
4145 // Create a REQ socket. Default action is connect.
4146 constructor NewReq(const Endpoint: string);
4147
4148 // Create a REP socket. Default action is bind.
4149 constructor NewRep(const Endpoint: string);
4150
4151 // Create a DEALER socket. Default action is connect.
4152 constructor NewDealer(const Endpoint: string);
4153
4154 // Create a ROUTER socket. Default action is bind.
4155 constructor NewRouter(const Endpoint: string);
4156
4157 // Create a PUSH socket. Default action is connect.
4158 constructor NewPush(const Endpoint: string);
4159
4160 // Create a PULL socket. Default action is bind.
4161 constructor NewPull(const Endpoint: string);
4162
4163 // Create an XPUB socket. Default action is bind.
4164 constructor NewXpub(const Endpoint: string);
4165
4166 // Create an XSUB socket. Default action is connect.
4167 constructor NewXsub(const Endpoint: string);
4168
4169 // Create a PAIR socket. Default action is connect.
4170 constructor NewPair(const Endpoint: string);
4171
4172 // Create a STREAM socket. Default action is connect.
4173 constructor NewStream(const Endpoint: string);
4174
4175 // Create a SERVER socket. Default action is bind.
4176 constructor NewServer(const Endpoint: string);
4177
4178 // Create a CLIENT socket. Default action is connect.
4179 constructor NewClient(const Endpoint: string);
4180
4181 // Create a RADIO socket. Default action is bind.
4182 constructor NewRadio(const Endpoint: string);
4183
4184 // Create a DISH socket. Default action is connect.
4185 constructor NewDish(const Endpoint: string);
4186
4187 // Create a GATHER socket. Default action is bind.
4188 constructor NewGather(const Endpoint: string);
4189
4190 // Create a SCATTER socket. Default action is connect.
4191 constructor NewScatter(const Endpoint: string);
4192
4193 // Destroy the socket. You must use this for any socket created via the
4194 // zsock_new method.
4195 destructor Destroy; override;
4196
4197 // Probe the supplied object, and report if it looks like a zsock_t.
4198 // Takes a polymorphic socket reference.
4199 class function &Is(This: Pointer): Boolean;
4200
4201 // Probe the supplied reference. If it looks like a zsock_t instance, return
4202 // the underlying libzmq socket handle; else if it looks like a file
4203 // descriptor, return NULL; else if it looks like a libzmq socket handle,
4204 // return the supplied value. Takes a polymorphic socket reference.
4205 class function Resolve(This: Pointer): Pointer;
4206
4207 // Self test of this class.
4208 class procedure Test(Verbose: Boolean);
4209
4210 class function Wrap(handle: PZsock; owned: Boolean): IZsock;
4211 class function UnWrap(const Value: IZsock): PZsock;
4212 protected
4213
4214 // Bind a socket to a formatted endpoint. For tcp:// endpoints, supports
4215 // ephemeral ports, if you specify the port number as "*". By default
4216 // zsock uses the IANA designated range from C000 (49152) to FFFF (65535).
4217 // To override this range, follow the "*" with "[first-last]". Either or
4218 // both first and last may be empty. To bind to a random port within the
4219 // range, use "!" in place of "*".
4220 //
4221 // Examples:
4222 // tcp://127.0.0.1:* bind to first free port from C000 up
4223 // tcp://127.0.0.1:! bind to random port from C000 to FFFF
4224 // tcp://127.0.0.1:*[60000-] bind to first free port from 60000 up
4225 // tcp://127.0.0.1:![-60000] bind to random port from C000 to 60000
4226 // tcp://127.0.0.1:![55000-55999]
4227 // bind to random port from 55000 to 55999
4228 //
4229 // On success, returns the actual port number used, for tcp:// endpoints,
4230 // and 0 for other transports. On failure, returns -1. Note that when using
4231 // ephemeral ports, a port may be reused by different services without
4232 // clients being aware. Protocols that run on ephemeral ports should take
4233 // this into account.
4234 function Bind(const Format: string): Integer;
4235
4236 // Returns last bound endpoint, if any.
4237 function Endpoint: string;
4238
4239 // Unbind a socket from a formatted endpoint.
4240 // Returns 0 if OK, -1 if the endpoint was invalid or the function
4241 // isn't supported.
4242 function Unbind(const Format: string): Integer;
4243
4244 // Connect a socket to a formatted endpoint
4245 // Returns 0 if OK, -1 if the endpoint was invalid.
4246 function Connect(const Format: string): Integer;
4247
4248 // Disconnect a socket from a formatted endpoint
4249 // Returns 0 if OK, -1 if the endpoint was invalid or the function
4250 // isn't supported.
4251 function Disconnect(const Format: string): Integer;
4252
4253 // Attach a socket to zero or more endpoints. If endpoints is not null,
4254 // parses as list of ZeroMQ endpoints, separated by commas, and prefixed by
4255 // '@' (to bind the socket) or '>' (to connect the socket). Returns 0 if all
4256 // endpoints were valid, or -1 if there was a syntax error. If the endpoint
4257 // does not start with '@' or '>', the serverish argument defines whether
4258 // it is used to bind (serverish = true) or connect (serverish = false).
4259 function Attach(const Endpoints: string; Serverish: Boolean): Integer;
4260
4261 // Returns socket type as printable constant string.
4262 function TypeStr: string;
4263
4264 // Send a 'picture' message to the socket (or actor). The picture is a
4265 // string that defines the type of each frame. This makes it easy to send
4266 // a complex multiframe message in one call. The picture can contain any
4267 // of these characters, each corresponding to one or two arguments:
4268 //
4269 // i = int (signed)
4270 // 1 = uint8_t
4271 // 2 = uint16_t
4272 // 4 = uint32_t
4273 // 8 = uint64_t
4274 // s = char *
4275 // b = byte *, size_t (2 arguments)
4276 // c = zchunk_t *
4277 // f = zframe_t *
4278 // h = zhashx_t *
4279 // l = zlistx_t * (DRAFT)
4280 // U = zuuid_t *
4281 // p = void * (sends the pointer value, only meaningful over inproc)
4282 // m = zmsg_t * (sends all frames in the zmsg)
4283 // z = sends zero-sized frame (0 arguments)
4284 // u = uint (deprecated)
4285 //
4286 // Note that s, b, c, and f are encoded the same way and the choice is
4287 // offered as a convenience to the sender, which may or may not already
4288 // have data in a zchunk or zframe. Does not change or take ownership of
4289 // any arguments. Returns 0 if successful, -1 if sending failed for any
4290 // reason.
4291 function Send(const Picture: string): Integer;
4292
4293 // Send a 'picture' message to the socket (or actor). This is a va_list
4294 // version of zsock_send (), so please consult its documentation for the
4295 // details.
4296 function Vsend(const Picture: string; Argptr: va_list): Integer;
4297
4298 // Receive a 'picture' message to the socket (or actor). See zsock_send for
4299 // the format and meaning of the picture. Returns the picture elements into
4300 // a series of pointers as provided by the caller:
4301 //
4302 // i = int * (stores signed integer)
4303 // 4 = uint32_t * (stores 32-bit unsigned integer)
4304 // 8 = uint64_t * (stores 64-bit unsigned integer)
4305 // s = char ** (allocates new string)
4306 // b = byte **, size_t * (2 arguments) (allocates memory)
4307 // c = zchunk_t ** (creates zchunk)
4308 // f = zframe_t ** (creates zframe)
4309 // U = zuuid_t * (creates a zuuid with the data)
4310 // h = zhashx_t ** (creates zhashx)
4311 // l = zlistx_t ** (creates zlistx) (DRAFT)
4312 // p = void ** (stores pointer)
4313 // m = zmsg_t ** (creates a zmsg with the remaining frames)
4314 // z = null, asserts empty frame (0 arguments)
4315 // u = uint * (stores unsigned integer, deprecated)
4316 //
4317 // Note that zsock_recv creates the returned objects, and the caller must
4318 // destroy them when finished with them. The supplied pointers do not need
4319 // to be initialized. Returns 0 if successful, or -1 if it failed to recv
4320 // a message, in which case the pointers are not modified. When message
4321 // frames are truncated (a short message), sets return values to zero/null.
4322 // If an argument pointer is NULL, does not store any value (skips it).
4323 // An 'n' picture matches an empty frame; if the message does not match,
4324 // the method will return -1.
4325 function Recv(const Picture: string): Integer;
4326
4327 // Receive a 'picture' message from the socket (or actor). This is a
4328 // va_list version of zsock_recv (), so please consult its documentation
4329 // for the details.
4330 function Vrecv(const Picture: string; Argptr: va_list): Integer;
4331
4332 // Send a binary encoded 'picture' message to the socket (or actor). This
4333 // method is similar to zsock_send, except the arguments are encoded in a
4334 // binary format that is compatible with zproto, and is designed to reduce
4335 // memory allocations. The pattern argument is a string that defines the
4336 // type of each argument. Supports these argument types:
4337 //
4338 // pattern C type zproto type:
4339 // 1 uint8_t type = "number" size = "1"
4340 // 2 uint16_t type = "number" size = "2"
4341 // 4 uint32_t type = "number" size = "3"
4342 // 8 uint64_t type = "number" size = "4"
4343 // s char *, 0-255 chars type = "string"
4344 // S char *, 0-2^32-1 chars type = "longstr"
4345 // c zchunk_t * type = "chunk"
4346 // f zframe_t * type = "frame"
4347 // u zuuid_t * type = "uuid"
4348 // m zmsg_t * type = "msg"
4349 // p void *, sends pointer value, only over inproc
4350 //
4351 // Does not change or take ownership of any arguments. Returns 0 if
4352 // successful, -1 if sending failed for any reason.
4353 function Bsend(const Picture: string): Integer;
4354
4355 // Receive a binary encoded 'picture' message from the socket (or actor).
4356 // This method is similar to zsock_recv, except the arguments are encoded
4357 // in a binary format that is compatible with zproto, and is designed to
4358 // reduce memory allocations. The pattern argument is a string that defines
4359 // the type of each argument. See zsock_bsend for the supported argument
4360 // types. All arguments must be pointers; this call sets them to point to
4361 // values held on a per-socket basis.
4362 // For types 1, 2, 4 and 8 the caller must allocate the memory itself before
4363 // calling zsock_brecv.
4364 // For types S, the caller must free the value once finished with it, as
4365 // zsock_brecv will allocate the buffer.
4366 // For type s, the caller must not free the value as it is stored in a
4367 // local cache for performance purposes.
4368 // For types c, f, u and m the caller must call the appropriate destructor
4369 // depending on the object as zsock_brecv will create new objects.
4370 // For type p the caller must coordinate with the sender, as it is just a
4371 // pointer value being passed.
4372 function Brecv(const Picture: string): Integer;
4373
4374 // Return socket routing ID if any. This returns 0 if the socket is not
4375 // of type ZMQ_SERVER or if no request was already received on it.
4376 function RoutingId: Cardinal;
4377
4378 // Set routing ID on socket. The socket MUST be of type ZMQ_SERVER.
4379 // This will be used when sending messages on the socket via the zsock API.
4380 procedure SetRoutingId(RoutingId: Cardinal);
4381
4382 // Set socket to use unbounded pipes (HWM=0); use this in cases when you are
4383 // totally certain the message volume can fit in memory. This method works
4384 // across all versions of ZeroMQ. Takes a polymorphic socket reference.
4385 procedure SetUnbounded;
4386
4387 // Send a signal over a socket. A signal is a short message carrying a
4388 // success/failure code (by convention, 0 means OK). Signals are encoded
4389 // to be distinguishable from "normal" messages. Accepts a zsock_t or a
4390 // zactor_t argument, and returns 0 if successful, -1 if the signal could
4391 // not be sent. Takes a polymorphic socket reference.
4392 function Signal(Status: Byte): Integer;
4393
4394 // Wait on a signal. Use this to coordinate between threads, over pipe
4395 // pairs. Blocks until the signal is received. Returns -1 on error, 0 or
4396 // greater on success. Accepts a zsock_t or a zactor_t as argument.
4397 // Takes a polymorphic socket reference.
4398 function Wait: Integer;
4399
4400 // If there is a partial message still waiting on the socket, remove and
4401 // discard it. This is useful when reading partial messages, to get specific
4402 // message types.
4403 procedure Flush;
4404
4405 // Join a group for the RADIO-DISH pattern. Call only on ZMQ_DISH.
4406 // Returns 0 if OK, -1 if failed.
4407 function Join(const Group: string): Integer;
4408
4409 // Leave a group for the RADIO-DISH pattern. Call only on ZMQ_DISH.
4410 // Returns 0 if OK, -1 if failed.
4411 function Leave(const Group: string): Integer;
4412
4413 // Check whether the socket has available message to read.
4414 function HasIn: Boolean;
4415
4416 // Get socket option `router_notify`.
4417 // Available from libzmq 4.3.0.
4418 function RouterNotify: Integer;
4419
4420 // Set socket option `router_notify`.
4421 // Available from libzmq 4.3.0.
4422 procedure SetRouterNotify(RouterNotify: Integer);
4423
4424 // Get socket option `multicast_loop`.
4425 // Available from libzmq 4.3.0.
4426 function MulticastLoop: Integer;
4427
4428 // Set socket option `multicast_loop`.
4429 // Available from libzmq 4.3.0.
4430 procedure SetMulticastLoop(MulticastLoop: Integer);
4431
4432 // Get socket option `metadata`.
4433 // Available from libzmq 4.3.0.
4434 function Metadata: string;
4435
4436 // Set socket option `metadata`.
4437 // Available from libzmq 4.3.0.
4438 procedure SetMetadata(const Metadata: string);
4439
4440 // Get socket option `loopback_fastpath`.
4441 // Available from libzmq 4.3.0.
4442 function LoopbackFastpath: Integer;
4443
4444 // Set socket option `loopback_fastpath`.
4445 // Available from libzmq 4.3.0.
4446 procedure SetLoopbackFastpath(LoopbackFastpath: Integer);
4447
4448 // Get socket option `zap_enforce_domain`.
4449 // Available from libzmq 4.3.0.
4450 function ZapEnforceDomain: Integer;
4451
4452 // Set socket option `zap_enforce_domain`.
4453 // Available from libzmq 4.3.0.
4454 procedure SetZapEnforceDomain(ZapEnforceDomain: Integer);
4455
4456 // Get socket option `gssapi_principal_nametype`.
4457 // Available from libzmq 4.3.0.
4458 function GssapiPrincipalNametype: Integer;
4459
4460 // Set socket option `gssapi_principal_nametype`.
4461 // Available from libzmq 4.3.0.
4462 procedure SetGssapiPrincipalNametype(GssapiPrincipalNametype: Integer);
4463
4464 // Get socket option `gssapi_service_principal_nametype`.
4465 // Available from libzmq 4.3.0.
4466 function GssapiServicePrincipalNametype: Integer;
4467
4468 // Set socket option `gssapi_service_principal_nametype`.
4469 // Available from libzmq 4.3.0.
4470 procedure SetGssapiServicePrincipalNametype(GssapiServicePrincipalNametype: Integer);
4471
4472 // Get socket option `bindtodevice`.
4473 // Available from libzmq 4.3.0.
4474 function Bindtodevice: string;
4475
4476 // Set socket option `bindtodevice`.
4477 // Available from libzmq 4.3.0.
4478 procedure SetBindtodevice(const Bindtodevice: string);
4479
4480 // Get socket option `heartbeat_ivl`.
4481 // Available from libzmq 4.2.0.
4482 function HeartbeatIvl: Integer;
4483
4484 // Set socket option `heartbeat_ivl`.
4485 // Available from libzmq 4.2.0.
4486 procedure SetHeartbeatIvl(HeartbeatIvl: Integer);
4487
4488 // Get socket option `heartbeat_ttl`.
4489 // Available from libzmq 4.2.0.
4490 function HeartbeatTtl: Integer;
4491
4492 // Set socket option `heartbeat_ttl`.
4493 // Available from libzmq 4.2.0.
4494 procedure SetHeartbeatTtl(HeartbeatTtl: Integer);
4495
4496 // Get socket option `heartbeat_timeout`.
4497 // Available from libzmq 4.2.0.
4498 function HeartbeatTimeout: Integer;
4499
4500 // Set socket option `heartbeat_timeout`.
4501 // Available from libzmq 4.2.0.
4502 procedure SetHeartbeatTimeout(HeartbeatTimeout: Integer);
4503
4504 // Get socket option `use_fd`.
4505 // Available from libzmq 4.2.0.
4506 function UseFd: Integer;
4507
4508 // Set socket option `use_fd`.
4509 // Available from libzmq 4.2.0.
4510 procedure SetUseFd(UseFd: Integer);
4511
4512 // Set socket option `xpub_manual`.
4513 // Available from libzmq 4.2.0.
4514 procedure SetXpubManual(XpubManual: Integer);
4515
4516 // Set socket option `xpub_welcome_msg`.
4517 // Available from libzmq 4.2.0.
4518 procedure SetXpubWelcomeMsg(const XpubWelcomeMsg: string);
4519
4520 // Set socket option `stream_notify`.
4521 // Available from libzmq 4.2.0.
4522 procedure SetStreamNotify(StreamNotify: Integer);
4523
4524 // Get socket option `invert_matching`.
4525 // Available from libzmq 4.2.0.
4526 function InvertMatching: Integer;
4527
4528 // Set socket option `invert_matching`.
4529 // Available from libzmq 4.2.0.
4530 procedure SetInvertMatching(InvertMatching: Integer);
4531
4532 // Set socket option `xpub_verboser`.
4533 // Available from libzmq 4.2.0.
4534 procedure SetXpubVerboser(XpubVerboser: Integer);
4535
4536 // Get socket option `connect_timeout`.
4537 // Available from libzmq 4.2.0.
4538 function ConnectTimeout: Integer;
4539
4540 // Set socket option `connect_timeout`.
4541 // Available from libzmq 4.2.0.
4542 procedure SetConnectTimeout(ConnectTimeout: Integer);
4543
4544 // Get socket option `tcp_maxrt`.
4545 // Available from libzmq 4.2.0.
4546 function TcpMaxrt: Integer;
4547
4548 // Set socket option `tcp_maxrt`.
4549 // Available from libzmq 4.2.0.
4550 procedure SetTcpMaxrt(TcpMaxrt: Integer);
4551
4552 // Get socket option `thread_safe`.
4553 // Available from libzmq 4.2.0.
4554 function ThreadSafe: Integer;
4555
4556 // Get socket option `multicast_maxtpdu`.
4557 // Available from libzmq 4.2.0.
4558 function MulticastMaxtpdu: Integer;
4559
4560 // Set socket option `multicast_maxtpdu`.
4561 // Available from libzmq 4.2.0.
4562 procedure SetMulticastMaxtpdu(MulticastMaxtpdu: Integer);
4563
4564 // Get socket option `vmci_buffer_size`.
4565 // Available from libzmq 4.2.0.
4566 function VmciBufferSize: Integer;
4567
4568 // Set socket option `vmci_buffer_size`.
4569 // Available from libzmq 4.2.0.
4570 procedure SetVmciBufferSize(VmciBufferSize: Integer);
4571
4572 // Get socket option `vmci_buffer_min_size`.
4573 // Available from libzmq 4.2.0.
4574 function VmciBufferMinSize: Integer;
4575
4576 // Set socket option `vmci_buffer_min_size`.
4577 // Available from libzmq 4.2.0.
4578 procedure SetVmciBufferMinSize(VmciBufferMinSize: Integer);
4579
4580 // Get socket option `vmci_buffer_max_size`.
4581 // Available from libzmq 4.2.0.
4582 function VmciBufferMaxSize: Integer;
4583
4584 // Set socket option `vmci_buffer_max_size`.
4585 // Available from libzmq 4.2.0.
4586 procedure SetVmciBufferMaxSize(VmciBufferMaxSize: Integer);
4587
4588 // Get socket option `vmci_connect_timeout`.
4589 // Available from libzmq 4.2.0.
4590 function VmciConnectTimeout: Integer;
4591
4592 // Set socket option `vmci_connect_timeout`.
4593 // Available from libzmq 4.2.0.
4594 procedure SetVmciConnectTimeout(VmciConnectTimeout: Integer);
4595
4596 // Get socket option `tos`.
4597 // Available from libzmq 4.1.0.
4598 function Tos: Integer;
4599
4600 // Set socket option `tos`.
4601 // Available from libzmq 4.1.0.
4602 procedure SetTos(Tos: Integer);
4603
4604 // Set socket option `router_handover`.
4605 // Available from libzmq 4.1.0.
4606 procedure SetRouterHandover(RouterHandover: Integer);
4607
4608 // Set socket option `connect_rid`.
4609 // Available from libzmq 4.1.0.
4610 procedure SetConnectRid(const ConnectRid: string);
4611
4612 // Set socket option `connect_rid` from 32-octet binary
4613 // Available from libzmq 4.1.0.
4614 procedure SetConnectRidBin(ConnectRid: PByte);
4615
4616 // Get socket option `handshake_ivl`.
4617 // Available from libzmq 4.1.0.
4618 function HandshakeIvl: Integer;
4619
4620 // Set socket option `handshake_ivl`.
4621 // Available from libzmq 4.1.0.
4622 procedure SetHandshakeIvl(HandshakeIvl: Integer);
4623
4624 // Get socket option `socks_proxy`.
4625 // Available from libzmq 4.1.0.
4626 function SocksProxy: string;
4627
4628 // Set socket option `socks_proxy`.
4629 // Available from libzmq 4.1.0.
4630 procedure SetSocksProxy(const SocksProxy: string);
4631
4632 // Set socket option `xpub_nodrop`.
4633 // Available from libzmq 4.1.0.
4634 procedure SetXpubNodrop(XpubNodrop: Integer);
4635
4636 // Set socket option `router_mandatory`.
4637 // Available from libzmq 4.0.0.
4638 procedure SetRouterMandatory(RouterMandatory: Integer);
4639
4640 // Set socket option `probe_router`.
4641 // Available from libzmq 4.0.0.
4642 procedure SetProbeRouter(ProbeRouter: Integer);
4643
4644 // Set socket option `req_relaxed`.
4645 // Available from libzmq 4.0.0.
4646 procedure SetReqRelaxed(ReqRelaxed: Integer);
4647
4648 // Set socket option `req_correlate`.
4649 // Available from libzmq 4.0.0.
4650 procedure SetReqCorrelate(ReqCorrelate: Integer);
4651
4652 // Set socket option `conflate`.
4653 // Available from libzmq 4.0.0.
4654 procedure SetConflate(Conflate: Integer);
4655
4656 // Get socket option `zap_domain`.
4657 // Available from libzmq 4.0.0.
4658 function ZapDomain: string;
4659
4660 // Set socket option `zap_domain`.
4661 // Available from libzmq 4.0.0.
4662 procedure SetZapDomain(const ZapDomain: string);
4663
4664 // Get socket option `mechanism`.
4665 // Available from libzmq 4.0.0.
4666 function Mechanism: Integer;
4667
4668 // Get socket option `plain_server`.
4669 // Available from libzmq 4.0.0.
4670 function PlainServer: Integer;
4671
4672 // Set socket option `plain_server`.
4673 // Available from libzmq 4.0.0.
4674 procedure SetPlainServer(PlainServer: Integer);
4675
4676 // Get socket option `plain_username`.
4677 // Available from libzmq 4.0.0.
4678 function PlainUsername: string;
4679
4680 // Set socket option `plain_username`.
4681 // Available from libzmq 4.0.0.
4682 procedure SetPlainUsername(const PlainUsername: string);
4683
4684 // Get socket option `plain_password`.
4685 // Available from libzmq 4.0.0.
4686 function PlainPassword: string;
4687
4688 // Set socket option `plain_password`.
4689 // Available from libzmq 4.0.0.
4690 procedure SetPlainPassword(const PlainPassword: string);
4691
4692 // Get socket option `curve_server`.
4693 // Available from libzmq 4.0.0.
4694 function CurveServer: Integer;
4695
4696 // Set socket option `curve_server`.
4697 // Available from libzmq 4.0.0.
4698 procedure SetCurveServer(CurveServer: Integer);
4699
4700 // Get socket option `curve_publickey`.
4701 // Available from libzmq 4.0.0.
4702 function CurvePublickey: string;
4703
4704 // Set socket option `curve_publickey`.
4705 // Available from libzmq 4.0.0.
4706 procedure SetCurvePublickey(const CurvePublickey: string);
4707
4708 // Set socket option `curve_publickey` from 32-octet binary
4709 // Available from libzmq 4.0.0.
4710 procedure SetCurvePublickeyBin(CurvePublickey: PByte);
4711
4712 // Get socket option `curve_secretkey`.
4713 // Available from libzmq 4.0.0.
4714 function CurveSecretkey: string;
4715
4716 // Set socket option `curve_secretkey`.
4717 // Available from libzmq 4.0.0.
4718 procedure SetCurveSecretkey(const CurveSecretkey: string);
4719
4720 // Set socket option `curve_secretkey` from 32-octet binary
4721 // Available from libzmq 4.0.0.
4722 procedure SetCurveSecretkeyBin(CurveSecretkey: PByte);
4723
4724 // Get socket option `curve_serverkey`.
4725 // Available from libzmq 4.0.0.
4726 function CurveServerkey: string;
4727
4728 // Set socket option `curve_serverkey`.
4729 // Available from libzmq 4.0.0.
4730 procedure SetCurveServerkey(const CurveServerkey: string);
4731
4732 // Set socket option `curve_serverkey` from 32-octet binary
4733 // Available from libzmq 4.0.0.
4734 procedure SetCurveServerkeyBin(CurveServerkey: PByte);
4735
4736 // Get socket option `gssapi_server`.
4737 // Available from libzmq 4.0.0.
4738 function GssapiServer: Integer;
4739
4740 // Set socket option `gssapi_server`.
4741 // Available from libzmq 4.0.0.
4742 procedure SetGssapiServer(GssapiServer: Integer);
4743
4744 // Get socket option `gssapi_plaintext`.
4745 // Available from libzmq 4.0.0.
4746 function GssapiPlaintext: Integer;
4747
4748 // Set socket option `gssapi_plaintext`.
4749 // Available from libzmq 4.0.0.
4750 procedure SetGssapiPlaintext(GssapiPlaintext: Integer);
4751
4752 // Get socket option `gssapi_principal`.
4753 // Available from libzmq 4.0.0.
4754 function GssapiPrincipal: string;
4755
4756 // Set socket option `gssapi_principal`.
4757 // Available from libzmq 4.0.0.
4758 procedure SetGssapiPrincipal(const GssapiPrincipal: string);
4759
4760 // Get socket option `gssapi_service_principal`.
4761 // Available from libzmq 4.0.0.
4762 function GssapiServicePrincipal: string;
4763
4764 // Set socket option `gssapi_service_principal`.
4765 // Available from libzmq 4.0.0.
4766 procedure SetGssapiServicePrincipal(const GssapiServicePrincipal: string);
4767
4768 // Get socket option `ipv6`.
4769 // Available from libzmq 4.0.0.
4770 function Ipv6: Integer;
4771
4772 // Set socket option `ipv6`.
4773 // Available from libzmq 4.0.0.
4774 procedure SetIpv6(Ipv6: Integer);
4775
4776 // Get socket option `immediate`.
4777 // Available from libzmq 4.0.0.
4778 function Immediate: Integer;
4779
4780 // Set socket option `immediate`.
4781 // Available from libzmq 4.0.0.
4782 procedure SetImmediate(Immediate: Integer);
4783
4784 // Get socket option `sndhwm`.
4785 // Available from libzmq 3.0.0.
4786 function Sndhwm: Integer;
4787
4788 // Set socket option `sndhwm`.
4789 // Available from libzmq 3.0.0.
4790 procedure SetSndhwm(Sndhwm: Integer);
4791
4792 // Get socket option `rcvhwm`.
4793 // Available from libzmq 3.0.0.
4794 function Rcvhwm: Integer;
4795
4796 // Set socket option `rcvhwm`.
4797 // Available from libzmq 3.0.0.
4798 procedure SetRcvhwm(Rcvhwm: Integer);
4799
4800 // Get socket option `maxmsgsize`.
4801 // Available from libzmq 3.0.0.
4802 function Maxmsgsize: Integer;
4803
4804 // Set socket option `maxmsgsize`.
4805 // Available from libzmq 3.0.0.
4806 procedure SetMaxmsgsize(Maxmsgsize: Integer);
4807
4808 // Get socket option `multicast_hops`.
4809 // Available from libzmq 3.0.0.
4810 function MulticastHops: Integer;
4811
4812 // Set socket option `multicast_hops`.
4813 // Available from libzmq 3.0.0.
4814 procedure SetMulticastHops(MulticastHops: Integer);
4815
4816 // Set socket option `xpub_verbose`.
4817 // Available from libzmq 3.0.0.
4818 procedure SetXpubVerbose(XpubVerbose: Integer);
4819
4820 // Get socket option `tcp_keepalive`.
4821 // Available from libzmq 3.0.0.
4822 function TcpKeepalive: Integer;
4823
4824 // Set socket option `tcp_keepalive`.
4825 // Available from libzmq 3.0.0.
4826 procedure SetTcpKeepalive(TcpKeepalive: Integer);
4827
4828 // Get socket option `tcp_keepalive_idle`.
4829 // Available from libzmq 3.0.0.
4830 function TcpKeepaliveIdle: Integer;
4831
4832 // Set socket option `tcp_keepalive_idle`.
4833 // Available from libzmq 3.0.0.
4834 procedure SetTcpKeepaliveIdle(TcpKeepaliveIdle: Integer);
4835
4836 // Get socket option `tcp_keepalive_cnt`.
4837 // Available from libzmq 3.0.0.
4838 function TcpKeepaliveCnt: Integer;
4839
4840 // Set socket option `tcp_keepalive_cnt`.
4841 // Available from libzmq 3.0.0.
4842 procedure SetTcpKeepaliveCnt(TcpKeepaliveCnt: Integer);
4843
4844 // Get socket option `tcp_keepalive_intvl`.
4845 // Available from libzmq 3.0.0.
4846 function TcpKeepaliveIntvl: Integer;
4847
4848 // Set socket option `tcp_keepalive_intvl`.
4849 // Available from libzmq 3.0.0.
4850 procedure SetTcpKeepaliveIntvl(TcpKeepaliveIntvl: Integer);
4851
4852 // Get socket option `tcp_accept_filter`.
4853 // Available from libzmq 3.0.0.
4854 function TcpAcceptFilter: string;
4855
4856 // Set socket option `tcp_accept_filter`.
4857 // Available from libzmq 3.0.0.
4858 procedure SetTcpAcceptFilter(const TcpAcceptFilter: string);
4859
4860 // Get socket option `last_endpoint`.
4861 // Available from libzmq 3.0.0.
4862 function LastEndpoint: string;
4863
4864 // Set socket option `router_raw`.
4865 // Available from libzmq 3.0.0.
4866 procedure SetRouterRaw(RouterRaw: Integer);
4867
4868 // Get socket option `ipv4only`.
4869 // Available from libzmq 3.0.0.
4870 function Ipv4only: Integer;
4871
4872 // Set socket option `ipv4only`.
4873 // Available from libzmq 3.0.0.
4874 procedure SetIpv4only(Ipv4only: Integer);
4875
4876 // Set socket option `delay_attach_on_connect`.
4877 // Available from libzmq 3.0.0.
4878 procedure SetDelayAttachOnConnect(DelayAttachOnConnect: Integer);
4879
4880 // Get socket option `hwm`.
4881 // Available from libzmq 2.0.0 to 3.0.0.
4882 function Hwm: Integer;
4883
4884 // Set socket option `hwm`.
4885 // Available from libzmq 2.0.0 to 3.0.0.
4886 procedure SetHwm(Hwm: Integer);
4887
4888 // Get socket option `swap`.
4889 // Available from libzmq 2.0.0 to 3.0.0.
4890 function Swap: Integer;
4891
4892 // Set socket option `swap`.
4893 // Available from libzmq 2.0.0 to 3.0.0.
4894 procedure SetSwap(Swap: Integer);
4895
4896 // Get socket option `affinity`.
4897 // Available from libzmq 2.0.0.
4898 function Affinity: Integer;
4899
4900 // Set socket option `affinity`.
4901 // Available from libzmq 2.0.0.
4902 procedure SetAffinity(Affinity: Integer);
4903
4904 // Get socket option `identity`.
4905 // Available from libzmq 2.0.0.
4906 function Identity: string;
4907
4908 // Set socket option `identity`.
4909 // Available from libzmq 2.0.0.
4910 procedure SetIdentity(const Identity: string);
4911
4912 // Get socket option `rate`.
4913 // Available from libzmq 2.0.0.
4914 function Rate: Integer;
4915
4916 // Set socket option `rate`.
4917 // Available from libzmq 2.0.0.
4918 procedure SetRate(Rate: Integer);
4919
4920 // Get socket option `recovery_ivl`.
4921 // Available from libzmq 2.0.0.
4922 function RecoveryIvl: Integer;
4923
4924 // Set socket option `recovery_ivl`.
4925 // Available from libzmq 2.0.0.
4926 procedure SetRecoveryIvl(RecoveryIvl: Integer);
4927
4928 // Get socket option `recovery_ivl_msec`.
4929 // Available from libzmq 2.0.0 to 3.0.0.
4930 function RecoveryIvlMsec: Integer;
4931
4932 // Set socket option `recovery_ivl_msec`.
4933 // Available from libzmq 2.0.0 to 3.0.0.
4934 procedure SetRecoveryIvlMsec(RecoveryIvlMsec: Integer);
4935
4936 // Get socket option `mcast_loop`.
4937 // Available from libzmq 2.0.0 to 3.0.0.
4938 function McastLoop: Integer;
4939
4940 // Set socket option `mcast_loop`.
4941 // Available from libzmq 2.0.0 to 3.0.0.
4942 procedure SetMcastLoop(McastLoop: Integer);
4943
4944 // Get socket option `rcvtimeo`.
4945 // Available from libzmq 2.2.0.
4946 function Rcvtimeo: Integer;
4947
4948 // Set socket option `rcvtimeo`.
4949 // Available from libzmq 2.2.0.
4950 procedure SetRcvtimeo(Rcvtimeo: Integer);
4951
4952 // Get socket option `sndtimeo`.
4953 // Available from libzmq 2.2.0.
4954 function Sndtimeo: Integer;
4955
4956 // Set socket option `sndtimeo`.
4957 // Available from libzmq 2.2.0.
4958 procedure SetSndtimeo(Sndtimeo: Integer);
4959
4960 // Get socket option `sndbuf`.
4961 // Available from libzmq 2.0.0.
4962 function Sndbuf: Integer;
4963
4964 // Set socket option `sndbuf`.
4965 // Available from libzmq 2.0.0.
4966 procedure SetSndbuf(Sndbuf: Integer);
4967
4968 // Get socket option `rcvbuf`.
4969 // Available from libzmq 2.0.0.
4970 function Rcvbuf: Integer;
4971
4972 // Set socket option `rcvbuf`.
4973 // Available from libzmq 2.0.0.
4974 procedure SetRcvbuf(Rcvbuf: Integer);
4975
4976 // Get socket option `linger`.
4977 // Available from libzmq 2.0.0.
4978 function Linger: Integer;
4979
4980 // Set socket option `linger`.
4981 // Available from libzmq 2.0.0.
4982 procedure SetLinger(Linger: Integer);
4983
4984 // Get socket option `reconnect_ivl`.
4985 // Available from libzmq 2.0.0.
4986 function ReconnectIvl: Integer;
4987
4988 // Set socket option `reconnect_ivl`.
4989 // Available from libzmq 2.0.0.
4990 procedure SetReconnectIvl(ReconnectIvl: Integer);
4991
4992 // Get socket option `reconnect_ivl_max`.
4993 // Available from libzmq 2.0.0.
4994 function ReconnectIvlMax: Integer;
4995
4996 // Set socket option `reconnect_ivl_max`.
4997 // Available from libzmq 2.0.0.
4998 procedure SetReconnectIvlMax(ReconnectIvlMax: Integer);
4999
5000 // Get socket option `backlog`.
5001 // Available from libzmq 2.0.0.
5002 function Backlog: Integer;
5003
5004 // Set socket option `backlog`.
5005 // Available from libzmq 2.0.0.
5006 procedure SetBacklog(Backlog: Integer);
5007
5008 // Set socket option `subscribe`.
5009 // Available from libzmq 2.0.0.
5010 procedure SetSubscribe(const Subscribe: string);
5011
5012 // Set socket option `unsubscribe`.
5013 // Available from libzmq 2.0.0.
5014 procedure SetUnsubscribe(const Unsubscribe: string);
5015
5016 // Get socket option `type`.
5017 // Available from libzmq 2.0.0.
5018 function &Type: Integer;
5019
5020 // Get socket option `rcvmore`.
5021 // Available from libzmq 2.0.0.
5022 function Rcvmore: Integer;
5023
5024 // Get socket option `fd`.
5025 // Available from libzmq 2.0.0.
5026 function Fd: TSocket;
5027
5028 // Get socket option `events`.
5029 // Available from libzmq 2.0.0.
5030 function Events: Integer;
5031 end;
5032
5033 // sending and receiving strings
5034 TZstr = class
5035 public
5036
5037 // Receive C string from socket. Caller must free returned string using
5038 // zstr_free(). Returns NULL if the context is being terminated or the
5039 // process was interrupted.
5040 class function Recv(const Source: IZSock): string;
5041
5042 // De-compress and receive C string from socket, received as a message
5043 // with two frames: size of the uncompressed string, and the string itself.
5044 // Caller must free returned string using zstr_free(). Returns NULL if the
5045 // context is being terminated or the process was interrupted.
5046 class function RecvCompress(const Source: IZSock): string;
5047
5048 // Send a C string to a socket, as a frame. The string is sent without
5049 // trailing null byte; to read this you can use zstr_recv, or a similar
5050 // method that adds a null terminator on the received string. String
5051 // may be NULL, which is sent as "".
5052 class function Send(const Dest: IZSock; const &String: string): Integer;
5053
5054 // Send a C string to a socket, as zstr_send(), with a MORE flag, so that
5055 // you can send further strings in the same multi-part message.
5056 class function Sendm(const Dest: IZSock; const &String: string): Integer;
5057
5058 // Send a formatted string to a socket. Note that you should NOT use
5059 // user-supplied strings in the format (they may contain '%' which
5060 // will create security holes).
5061 class function Sendf(const Dest: IZSock; const Format: string): Integer;
5062
5063 // Send a formatted string to a socket, as for zstr_sendf(), with a
5064 // MORE flag, so that you can send further strings in the same multi-part
5065 // message.
5066 class function Sendfm(const Dest: IZSock; const Format: string): Integer;
5067
5068 // Send a series of strings (until NULL) as multipart data
5069 // Returns 0 if the strings could be sent OK, or -1 on error.
5070 class function Sendx(const Dest: IZSock; const &String: string): Integer;
5071
5072 // Compress and send a C string to a socket, as a message with two frames:
5073 // size of the uncompressed string, and the string itself. The string is
5074 // sent without trailing null byte; to read this you can use
5075 // zstr_recv_compress, or a similar method that de-compresses and adds a
5076 // null terminator on the received string.
5077 class function SendCompress(const Dest: IZSock; const &String: string): Integer;
5078
5079 // Compress and send a C string to a socket, as zstr_send_compress(),
5080 // with a MORE flag, so that you can send further strings in the same
5081 // multi-part message.
5082 class function SendmCompress(const Dest: IZSock; const &String: string): Integer;
5083
5084 // Accepts a void pointer and returns a fresh character string. If source
5085 // is null, returns an empty string.
5086 class function Str(const Source: IZSock): string;
5087
5088 // Self test of this class.
5089 class procedure Test(Verbose: Boolean);
5090 end;
5091
5092 //
5093 TZsys = class
5094 public
5095
5096 // Initialize CZMQ zsys layer; this happens automatically when you create
5097 // a socket or an actor; however this call lets you force initialization
5098 // earlier, so e.g. logging is properly set-up before you start working.
5099 // Not threadsafe, so call only from main thread. Safe to call multiple
5100 // times. Returns global CZMQ context.
5101 class function Init: Pointer;
5102
5103 // Optionally shut down the CZMQ zsys layer; this normally happens automatically
5104 // when the process exits; however this call lets you force a shutdown
5105 // earlier, avoiding any potential problems with atexit() ordering, especially
5106 // with Windows dlls.
5107 class procedure Shutdown;
5108
5109 // Get a new ZMQ socket, automagically creating a ZMQ context if this is
5110 // the first time. Caller is responsible for destroying the ZMQ socket
5111 // before process exits, to avoid a ZMQ deadlock. Note: you should not use
5112 // this method in CZMQ apps, use zsock_new() instead.
5113 // *** This is for CZMQ internal use only and may change arbitrarily ***
5114 class function Socket(&Type: Integer; const Filename: string; LineNbr: NativeUInt): Pointer;
5115
5116 // Destroy/close a ZMQ socket. You should call this for every socket you
5117 // create using zsys_socket().
5118 // *** This is for CZMQ internal use only and may change arbitrarily ***
5119 class function Close(Handle: Pointer; const Filename: string; LineNbr: NativeUInt): Integer;
5120
5121 // Return ZMQ socket name for socket type
5122 // *** This is for CZMQ internal use only and may change arbitrarily ***
5123 class function Sockname(Socktype: Integer): string;
5124
5125 // Create a pipe, which consists of two PAIR sockets connected over inproc.
5126 // The pipe is configured to use the zsys_pipehwm setting. Returns the
5127 // frontend socket successful, NULL if failed.
5128 class function CreatePipe(var BackendP: IZsock): IZsock;
5129
5130 // Set interrupt handler; this saves the default handlers so that a
5131 // zsys_handler_reset () can restore them. If you call this multiple times
5132 // then the last handler will take affect. If handler_fn is NULL, disables
5133 // default SIGINT/SIGTERM handling in CZMQ.
5134 class procedure HandlerSet(HandlerFn: PZsysHandlerFn);
5135
5136 // Reset interrupt handler, call this at exit if needed
5137 class procedure HandlerReset;
5138
5139 // Set default interrupt handler, so Ctrl-C or SIGTERM will set
5140 // zsys_interrupted. Idempotent; safe to call multiple times.
5141 // Can be suppressed by ZSYS_SIGHANDLER=false
5142 // *** This is for CZMQ internal use only and may change arbitrarily ***
5143 class procedure CatchInterrupts;
5144
5145 // Check if default interrupt handler of Ctrl-C or SIGTERM was called.
5146 // Does not work if ZSYS_SIGHANDLER is false and code does not call
5147 // set interrupted on signal.
5148 class function IsInterrupted: Boolean;
5149
5150 // Set interrupted flag. This is done by default signal handler, however
5151 // this can be handy for language bindings or cases without default
5152 // signal handler.
5153 class procedure SetInterrupted;
5154
5155 // Return 1 if file exists, else zero
5156 class function FileExists(const Filename: string): Boolean;
5157
5158 // Return file modification time. Returns 0 if the file does not exist.
5159 class function FileModified(const Filename: string): Int64;
5160
5161 // Return file mode; provides at least support for the POSIX S_ISREG(m)
5162 // and S_ISDIR(m) macros and the S_IRUSR and S_IWUSR bits, on all boxes.
5163 // Returns a mode_t cast to int, or -1 in case of error.
5164 class function FileMode(const Filename: string): Integer;
5165
5166 // Delete file. Does not complain if the file is absent
5167 class function FileDelete(const Filename: string): Integer;
5168
5169 // Check if file is 'stable'
5170 class function FileStable(const Filename: string): Boolean;
5171
5172 // Create a file path if it doesn't exist. The file path is treated as
5173 // printf format.
5174 class function DirCreate(const Pathname: string): Integer;
5175
5176 // Remove a file path if empty; the pathname is treated as printf format.
5177 class function DirDelete(const Pathname: string): Integer;
5178
5179 // Move to a specified working directory. Returns 0 if OK, -1 if this failed.
5180 class function DirChange(const Pathname: string): Integer;
5181
5182 // Set private file creation mode; all files created from here will be
5183 // readable/writable by the owner only.
5184 class procedure FileModePrivate;
5185
5186 // Reset default file creation mode; all files created from here will use
5187 // process file mode defaults.
5188 class procedure FileModeDefault;
5189
5190 // Return the CZMQ version for run-time API detection; returns version
5191 // number into provided fields, providing reference isn't null in each case.
5192 class procedure Version(var Major: Integer; var Minor: Integer; var Patch: Integer);
5193
5194 // Format a string using printf formatting, returning a freshly allocated
5195 // buffer. If there was insufficient memory, returns NULL. Free the returned
5196 // string using zstr_free(). The hinted version allows to optimize by using
5197 // a larger starting buffer size (known to/assumed by the developer) and so
5198 // avoid reallocations.
5199 class function SprintfHint(Hint: Integer; const Format: string): string;
5200
5201 // Format a string using printf formatting, returning a freshly allocated
5202 // buffer. If there was insufficient memory, returns NULL. Free the returned
5203 // string using zstr_free().
5204 class function Sprintf(const Format: string): string;
5205
5206 // Format a string with a va_list argument, returning a freshly allocated
5207 // buffer. If there was insufficient memory, returns NULL. Free the returned
5208 // string using zstr_free().
5209 class function Vprintf(const Format: string; Argptr: va_list): string;
5210
5211 // Create UDP beacon socket; if the routable option is true, uses
5212 // multicast (not yet implemented), else uses broadcast. This method
5213 // and related ones might _eventually_ be moved to a zudp class.
5214 // *** This is for CZMQ internal use only and may change arbitrarily ***
5215 class function UdpNew(Routable: Boolean): TSocket;
5216
5217 // Close a UDP socket
5218 // *** This is for CZMQ internal use only and may change arbitrarily ***
5219 class function UdpClose(Handle: TSocket): Integer;
5220
5221 // Send zframe to UDP socket, return -1 if sending failed due to
5222 // interface having disappeared (happens easily with WiFi)
5223 // *** This is for CZMQ internal use only and may change arbitrarily ***
5224 class function UdpSend(Udpsock: TSocket; const Frame: IZframe; Address: Pointer; Addrlen: Integer): Integer;
5225
5226 // Receive zframe from UDP socket, and set address of peer that sent it
5227 // The peername must be a char [INET_ADDRSTRLEN] array if IPv6 is disabled or
5228 // NI_MAXHOST if it's enabled. Returns NULL when failing to get peer address.
5229 // *** This is for CZMQ internal use only and may change arbitrarily ***
5230 class function UdpRecv(Udpsock: TSocket; const Peername: string; Peerlen: Integer): IZframe;
5231
5232 // Handle an I/O error on some socket operation; will report and die on
5233 // fatal errors, and continue silently on "try again" errors.
5234 // *** This is for CZMQ internal use only and may change arbitrarily ***
5235 class procedure SocketError(const Reason: string);
5236
5237 // Return current host name, for use in public tcp:// endpoints. Caller gets
5238 // a freshly allocated string, should free it using zstr_free(). If the host
5239 // name is not resolvable, returns NULL.
5240 class function Hostname: string;
5241
5242 // Move the current process into the background. The precise effect depends
5243 // on the operating system. On POSIX boxes, moves to a specified working
5244 // directory (if specified), closes all file handles, reopens stdin, stdout,
5245 // and stderr to the null device, and sets the process to ignore SIGHUP. On
5246 // Windows, does nothing. Returns 0 if OK, -1 if there was an error.
5247 class function Daemonize(const Workdir: string): Integer;
5248
5249 // Drop the process ID into the lockfile, with exclusive lock, and switch
5250 // the process to the specified group and/or user. Any of the arguments
5251 // may be null, indicating a no-op. Returns 0 on success, -1 on failure.
5252 // Note if you combine this with zsys_daemonize, run after, not before
5253 // that method, or the lockfile will hold the wrong process ID.
5254 class function RunAs(const Lockfile: string; const Group: string; const User: string): Integer;
5255
5256 // Returns true if the underlying libzmq supports CURVE security.
5257 // Uses a heuristic probe according to the version of libzmq being used.
5258 class function HasCurve: Boolean;
5259
5260 // Configure the number of I/O threads that ZeroMQ will use. A good
5261 // rule of thumb is one thread per gigabit of traffic in or out. The
5262 // default is 1, sufficient for most applications. If the environment
5263 // variable ZSYS_IO_THREADS is defined, that provides the default.
5264 // Note that this method is valid only before any socket is created.
5265 class procedure SetIoThreads(IoThreads: NativeUInt);
5266
5267 // Configure the scheduling policy of the ZMQ context thread pool.
5268 // Not available on Windows. See the sched_setscheduler man page or sched.h
5269 // for more information. If the environment variable ZSYS_THREAD_SCHED_POLICY
5270 // is defined, that provides the default.
5271 // Note that this method is valid only before any socket is created.
5272 class procedure SetThreadSchedPolicy(Policy: Integer);
5273
5274 // Configure the scheduling priority of the ZMQ context thread pool.
5275 // Not available on Windows. See the sched_setscheduler man page or sched.h
5276 // for more information. If the environment variable ZSYS_THREAD_PRIORITY is
5277 // defined, that provides the default.
5278 // Note that this method is valid only before any socket is created.
5279 class procedure SetThreadPriority(Priority: Integer);
5280
5281 // Configure the numeric prefix to each thread created for the internal
5282 // context's thread pool. This option is only supported on Linux.
5283 // If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
5284 // provides the default.
5285 // Note that this method is valid only before any socket is created.
5286 class procedure SetThreadNamePrefix(Prefix: Integer);
5287
5288 // Return thread name prefix.
5289 class function ThreadNamePrefix: Integer;
5290
5291 // Adds a specific CPU to the affinity list of the ZMQ context thread pool.
5292 // This option is only supported on Linux.
5293 // Note that this method is valid only before any socket is created.
5294 class procedure ThreadAffinityCpuAdd(Cpu: Integer);
5295
5296 // Removes a specific CPU to the affinity list of the ZMQ context thread pool.
5297 // This option is only supported on Linux.
5298 // Note that this method is valid only before any socket is created.
5299 class procedure ThreadAffinityCpuRemove(Cpu: Integer);
5300
5301 // Configure the number of sockets that ZeroMQ will allow. The default
5302 // is 1024. The actual limit depends on the system, and you can query it
5303 // by using zsys_socket_limit (). A value of zero means "maximum".
5304 // Note that this method is valid only before any socket is created.
5305 class procedure SetMaxSockets(MaxSockets: NativeUInt);
5306
5307 // Return maximum number of ZeroMQ sockets that the system will support.
5308 class function SocketLimit: NativeUInt;
5309
5310 // Configure the maximum allowed size of a message sent.
5311 // The default is INT_MAX.
5312 class procedure SetMaxMsgsz(MaxMsgsz: Integer);
5313
5314 // Return maximum message size.
5315 class function MaxMsgsz: Integer;
5316
5317 // Configure whether to use zero copy strategy in libzmq. If the environment
5318 // variable ZSYS_ZERO_COPY_RECV is defined, that provides the default.
5319 // Otherwise the default is 1.
5320 class procedure SetZeroCopyRecv(ZeroCopy: Integer);
5321
5322 // Return ZMQ_ZERO_COPY_RECV option.
5323 class function ZeroCopyRecv: Integer;
5324
5325 // Configure the threshold value of filesystem object age per st_mtime
5326 // that should elapse until we consider that object "stable" at the
5327 // current zclock_time() moment.
5328 // The default is S_DEFAULT_ZSYS_FILE_STABLE_AGE_MSEC defined in zsys.c
5329 // which generally depends on host OS, with fallback value of 5000.
5330 class procedure SetFileStableAgeMsec(FileStableAgeMsec: Int64);
5331
5332 // Return current threshold value of file stable age in msec.
5333 // This can be used in code that chooses to wait for this timeout
5334 // before testing if a filesystem object is "stable" or not.
5335 class function FileStableAgeMsec: Int64;
5336
5337 // Configure the default linger timeout in msecs for new zsock instances.
5338 // You can also set this separately on each zsock_t instance. The default
5339 // linger time is zero, i.e. any pending messages will be dropped. If the
5340 // environment variable ZSYS_LINGER is defined, that provides the default.
5341 // Note that process exit will typically be delayed by the linger time.
5342 class procedure SetLinger(Linger: NativeUInt);
5343
5344 // Configure the default outgoing pipe limit (HWM) for new zsock instances.
5345 // You can also set this separately on each zsock_t instance. The default
5346 // HWM is 1,000, on all versions of ZeroMQ. If the environment variable
5347 // ZSYS_SNDHWM is defined, that provides the default. Note that a value of
5348 // zero means no limit, i.e. infinite memory consumption.
5349 class procedure SetSndhwm(Sndhwm: NativeUInt);
5350
5351 // Configure the default incoming pipe limit (HWM) for new zsock instances.
5352 // You can also set this separately on each zsock_t instance. The default
5353 // HWM is 1,000, on all versions of ZeroMQ. If the environment variable
5354 // ZSYS_RCVHWM is defined, that provides the default. Note that a value of
5355 // zero means no limit, i.e. infinite memory consumption.
5356 class procedure SetRcvhwm(Rcvhwm: NativeUInt);
5357
5358 // Configure the default HWM for zactor internal pipes; this is set on both
5359 // ends of the pipe, for outgoing messages only (sndhwm). The default HWM is
5360 // 1,000, on all versions of ZeroMQ. If the environment var ZSYS_ACTORHWM is
5361 // defined, that provides the default. Note that a value of zero means no
5362 // limit, i.e. infinite memory consumption.
5363 class procedure SetPipehwm(Pipehwm: NativeUInt);
5364
5365 // Return the HWM for zactor internal pipes.
5366 class function Pipehwm: NativeUInt;
5367
5368 // Configure use of IPv6 for new zsock instances. By default sockets accept
5369 // and make only IPv4 connections. When you enable IPv6, sockets will accept
5370 // and connect to both IPv4 and IPv6 peers. You can override the setting on
5371 // each zsock_t instance. The default is IPv4 only (ipv6 set to 0). If the
5372 // environment variable ZSYS_IPV6 is defined (as 1 or 0), this provides the
5373 // default. Note: has no effect on ZMQ v2.
5374 class procedure SetIpv6(Ipv6: Integer);
5375
5376 // Return use of IPv6 for zsock instances.
5377 class function Ipv6: Integer;
5378
5379 // Set network interface name to use for broadcasts, particularly zbeacon.
5380 // This lets the interface be configured for test environments where required.
5381 // For example, on Mac OS X, zbeacon cannot bind to 255.255.255.255 which is
5382 // the default when there is no specified interface. If the environment
5383 // variable ZSYS_INTERFACE is set, use that as the default interface name.
5384 // Setting the interface to "*" means "use all available interfaces".
5385 class procedure SetInterface(const Value: string);
5386
5387 // Return network interface to use for broadcasts, or "" if none was set.
5388 class function &Interface: string;
5389
5390 // Set IPv6 address to use zbeacon socket, particularly for receiving zbeacon.
5391 // This needs to be set IPv6 is enabled as IPv6 can have multiple addresses
5392 // on a given interface. If the environment variable ZSYS_IPV6_ADDRESS is set,
5393 // use that as the default IPv6 address.
5394 class procedure SetIpv6Address(const Value: string);
5395
5396 // Return IPv6 address to use for zbeacon reception, or "" if none was set.
5397 class function Ipv6Address: string;
5398
5399 // Set IPv6 milticast address to use for sending zbeacon messages. This needs
5400 // to be set if IPv6 is enabled. If the environment variable
5401 // ZSYS_IPV6_MCAST_ADDRESS is set, use that as the default IPv6 multicast
5402 // address.
5403 class procedure SetIpv6McastAddress(const Value: string);
5404
5405 // Return IPv6 multicast address to use for sending zbeacon, or "" if none was
5406 // set.
5407 class function Ipv6McastAddress: string;
5408
5409 // Configure the automatic use of pre-allocated FDs when creating new sockets.
5410 // If 0 (default), nothing will happen. Else, when a new socket is bound, the
5411 // system API will be used to check if an existing pre-allocated FD with a
5412 // matching port (if TCP) or path (if IPC) exists, and if it does it will be
5413 // set via the ZMQ_USE_FD socket option so that the library will use it
5414 // instead of creating a new socket.
5415 class procedure SetAutoUseFd(AutoUseFd: Integer);
5416
5417 // Return use of automatic pre-allocated FDs for zsock instances.
5418 class function AutoUseFd: Integer;
5419
5420 // Print formatted string. Format is specified by variable names
5421 // in Python-like format style
5422 //
5423 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
5424 // become
5425 // "key=value"
5426 //
5427 // Returns freshly allocated string or NULL in a case of error.
5428 // Not enough memory, invalid format specifier, name not in args
5429 class function Zprintf(const Format: string; const Args: IZhash): string;
5430
5431 // Return error string for given format/args combination.
5432 class function ZprintfError(const Format: string; const Args: IZhash): string;
5433
5434 // Print formatted string. Format is specified by variable names
5435 // in Python-like format style
5436 //
5437 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
5438 // become
5439 // "key=value"
5440 //
5441 // Returns freshly allocated string or NULL in a case of error.
5442 // Not enough memory, invalid format specifier, name not in args
5443 class function Zplprintf(const Format: string; const Args: IZconfig): string;
5444
5445 // Return error string for given format/args combination.
5446 class function ZplprintfError(const Format: string; const Args: IZconfig): string;
5447
5448 // Set log identity, which is a string that prefixes all log messages sent
5449 // by this process. The log identity defaults to the environment variable
5450 // ZSYS_LOGIDENT, if that is set.
5451 class procedure SetLogident(const Value: string);
5452
5453 // Set stream to receive log traffic. By default, log traffic is sent to
5454 // stdout. If you set the stream to NULL, no stream will receive the log
5455 // traffic (it may still be sent to the system facility).
5456 class procedure SetLogstream(Stream: Pointer);
5457
5458 // Sends log output to a PUB socket bound to the specified endpoint. To
5459 // collect such log output, create a SUB socket, subscribe to the traffic
5460 // you care about, and connect to the endpoint. Log traffic is sent as a
5461 // single string frame, in the same format as when sent to stdout. The
5462 // log system supports a single sender; multiple calls to this method will
5463 // bind the same sender to multiple endpoints. To disable the sender, call
5464 // this method with a null argument.
5465 class procedure SetLogsender(const Endpoint: string);
5466
5467 // Enable or disable logging to the system facility (syslog on POSIX boxes,
5468 // event log on Windows). By default this is disabled.
5469 class procedure SetLogsystem(Logsystem: Boolean);
5470
5471 // Log error condition - highest priority
5472 class procedure Error(const Format: string);
5473
5474 // Log warning condition - high priority
5475 class procedure Warning(const Format: string);
5476
5477 // Log normal, but significant, condition - normal priority
5478 class procedure Notice(const Format: string);
5479
5480 // Log informational message - low priority
5481 class procedure Info(const Format: string);
5482
5483 // Log debug-level message - lowest priority
5484 class procedure Debug(const Format: string);
5485
5486 // Self test of this class.
5487 class procedure Test(Verbose: Boolean);
5488 end;
5489
5490 // UUID support class
5491 TZuuid = class(TInterfacedObject, IZuuid)
5492 public
5493 FOwned: Boolean;
5494 FHandle: PZuuid;
5495 constructor Create(handle: PZuuid; owned: Boolean);
5496 public
5497
5498 // Create a new UUID object.
5499 constructor New;
5500
5501 // Create UUID object from supplied ZUUID_LEN-octet value.
5502 constructor NewFrom(Source: PByte);
5503
5504 // Destroy a specified UUID object.
5505 destructor Destroy; override;
5506
5507 // Self test of this class.
5508 class procedure Test(Verbose: Boolean);
5509
5510 class function Wrap(handle: PZuuid; owned: Boolean): IZuuid;
5511 class function UnWrap(const Value: IZuuid): PZuuid;
5512 protected
5513
5514 // Set UUID to new supplied ZUUID_LEN-octet value.
5515 procedure &Set(Source: PByte);
5516
5517 // Set UUID to new supplied string value skipping '-' and '{' '}'
5518 // optional delimiters. Return 0 if OK, else returns -1.
5519 function SetStr(const Source: string): Integer;
5520
5521 // Return UUID binary data.
5522 function Data: PByte;
5523
5524 // Return UUID binary size
5525 function Size: NativeUInt;
5526
5527 // Returns UUID as string
5528 function Str: string;
5529
5530 // Return UUID in the canonical string format: 8-4-4-4-12, in lower
5531 // case. Caller does not modify or free returned value. See
5532 // http://en.wikipedia.org/wiki/Universally_unique_identifier
5533 function StrCanonical: string;
5534
5535 // Store UUID blob in target array
5536 procedure Export(Target: PByte);
5537
5538 // Check if UUID is same as supplied value
5539 function Eq(Compare: PByte): Boolean;
5540
5541 // Check if UUID is different from supplied value
5542 function Neq(Compare: PByte): Boolean;
5543
5544 // Make copy of UUID object; if uuid is null, or memory was exhausted,
5545 // returns null.
5546 function Dup: IZuuid;
5547 end;
5548
5549 //
5550 TZauth = class
5551 public
5552
5553 // Self test of this class.
5554 class procedure Test(Verbose: Boolean);
5555 end;
5556
5557 //
5558 TZbeacon = class
5559 public
5560
5561 // Self test of this class.
5562 class procedure Test(Verbose: Boolean);
5563 end;
5564
5565 //
5566 TZgossip = class
5567 public
5568
5569 // Self test of this class.
5570 class procedure Test(Verbose: Boolean);
5571 end;
5572
5573 //
5574 TZmonitor = class
5575 public
5576
5577 // Self test of this class.
5578 class procedure Test(Verbose: Boolean);
5579 end;
5580
5581 //
5582 TZproxy = class
5583 public
5584
5585 // Self test of this class.
5586 class procedure Test(Verbose: Boolean);
5587 end;
5588
5589 //
5590 TZrex = class
5591 public
5592
5593 // Self test of this class.
5594 class procedure Test(Verbose: Boolean);
5595 end;
5596
5597 function ZFreeString(const str: PAnsiChar): string;
5598
5599 implementation
5600
5601 uses
5602 System.SysUtils;
5603
5604 function ZFreeString(const str: PAnsiChar): string;
5605 var
5606 p: PAnsiChar;
5607 begin
5608 Result := string(UTF8String(str));
5609 p := str;
5610 zstr_free(p);
5611 end;
5612
5613 (* TZactor *)
5614
5615 constructor TZactor.New(Task: TZactorFn; Args: Pointer);
5616 begin
5617 Create(zactor_new(Task, Args), True);
5618 end;
5619
5620 constructor TZactor.Create(handle: PZactor; owned: Boolean);
5621 begin
5622 FHandle := handle;
5623 FOwned := owned;
5624 end;
5625
5626 class function TZactor.Wrap(handle: PZactor; owned: Boolean): IZactor;
5627 begin
5628 if handle <> nil then Result := TZactor.Create(handle, owned) else Result := nil;
5629 end;
5630
5631 class function TZactor.UnWrap(const value: IZactor): PZactor;
5632 begin
5633 if value <> nil then Result := TZactor(value).FHandle else Result := nil;
5634 end;
5635
5636 destructor TZactor.Destroy;
5637 begin
5638 if FOwned and (FHandle <> nil) then
5639 zactor_destroy(FHandle);
5640 end;
5641
5642 class function TZactor.&Is(This: Pointer): Boolean;
5643 begin
5644 Result := zactor_is(This);
5645 end;
5646
5647 class function TZactor.Resolve(This: Pointer): Pointer;
5648 begin
5649 Result := zactor_resolve(This);
5650 end;
5651
5652 class procedure TZactor.Test(Verbose: Boolean);
5653 begin
5654 zactor_test(Verbose);
5655 end;
5656
5657 function TZactor.Send(var MsgP: IZmsg): Integer;
5658 begin
5659 Result := zactor_send(FHandle, TZmsg(MsgP).FHandle);
5660 if TZmsg(MsgP).FHandle = nil then
5661 MsgP := nil;
5662 end;
5663
5664 function TZactor.Recv: IZmsg;
5665 begin
5666 Result := TZmsg.Wrap(zactor_recv(FHandle), true);
5667 end;
5668
5669 function TZactor.Sock: IZsock;
5670 begin
5671 Result := TZsock.Wrap(zactor_sock(FHandle), false);
5672 end;
5673
5674 procedure TZactor.SetDestructor(&Destructor: TZactorDestructorFn);
5675 begin
5676 zactor_set_destructor(FHandle, &Destructor);
5677 end;
5678
5679 (* TZarmour *)
5680
5681 constructor TZarmour.New;
5682 begin
5683 Create(zarmour_new, True);
5684 end;
5685
5686 constructor TZarmour.Create(handle: PZarmour; owned: Boolean);
5687 begin
5688 FHandle := handle;
5689 FOwned := owned;
5690 end;
5691
5692 class function TZarmour.Wrap(handle: PZarmour; owned: Boolean): IZarmour;
5693 begin
5694 if handle <> nil then Result := TZarmour.Create(handle, owned) else Result := nil;
5695 end;
5696
5697 class function TZarmour.UnWrap(const value: IZarmour): PZarmour;
5698 begin
5699 if value <> nil then Result := TZarmour(value).FHandle else Result := nil;
5700 end;
5701
5702 destructor TZarmour.Destroy;
5703 begin
5704 if FOwned and (FHandle <> nil) then
5705 zarmour_destroy(FHandle);
5706 end;
5707
5708 class procedure TZarmour.Test(Verbose: Boolean);
5709 begin
5710 zarmour_test(Verbose);
5711 end;
5712
5713 function TZarmour.Encode(Data: PByte; Size: NativeUInt): string;
5714 begin
5715 Result := ZFreeString(zarmour_encode(FHandle, Data, Size));
5716 end;
5717
5718 function TZarmour.Decode(const Data: string): IZchunk;
5719 var
5720 __Data__: UTF8String;
5721 begin
5722 __Data__ := UTF8String(Data);
5723 Result := TZchunk.Wrap(zarmour_decode(FHandle, PAnsiChar(__Data__)), true);
5724 end;
5725
5726 function TZarmour.Mode: Integer;
5727 begin
5728 Result := zarmour_mode(FHandle);
5729 end;
5730
5731 function TZarmour.ModeStr: string;
5732 begin
5733 Result := string(UTF8String(zarmour_mode_str(FHandle)));
5734 end;
5735
5736 procedure TZarmour.SetMode(Mode: Integer);
5737 begin
5738 zarmour_set_mode(FHandle, Mode);
5739 end;
5740
5741 function TZarmour.Pad: Boolean;
5742 begin
5743 Result := zarmour_pad(FHandle);
5744 end;
5745
5746 procedure TZarmour.SetPad(Pad: Boolean);
5747 begin
5748 zarmour_set_pad(FHandle, Pad);
5749 end;
5750
5751 function TZarmour.PadChar: AnsiChar;
5752 begin
5753 Result := zarmour_pad_char(FHandle);
5754 end;
5755
5756 procedure TZarmour.SetPadChar(PadChar: AnsiChar);
5757 begin
5758 zarmour_set_pad_char(FHandle, PadChar);
5759 end;
5760
5761 function TZarmour.LineBreaks: Boolean;
5762 begin
5763 Result := zarmour_line_breaks(FHandle);
5764 end;
5765
5766 procedure TZarmour.SetLineBreaks(LineBreaks: Boolean);
5767 begin
5768 zarmour_set_line_breaks(FHandle, LineBreaks);
5769 end;
5770
5771 function TZarmour.LineLength: NativeUInt;
5772 begin
5773 Result := zarmour_line_length(FHandle);
5774 end;
5775
5776 procedure TZarmour.SetLineLength(LineLength: NativeUInt);
5777 begin
5778 zarmour_set_line_length(FHandle, LineLength);
5779 end;
5780
5781 procedure TZarmour.Print;
5782 begin
5783 zarmour_print(FHandle);
5784 end;
5785
5786 (* TZcert *)
5787
5788 constructor TZcert.New;
5789 begin
5790 Create(zcert_new, True);
5791 end;
5792
5793 constructor TZcert.NewFrom(PublicKey: PByte; SecretKey: PByte);
5794 begin
5795 Create(zcert_new_from(PublicKey, SecretKey), True);
5796 end;
5797
5798 constructor TZcert.NewFromTxt(const PublicTxt: string; const SecretTxt: string);
5799 var
5800 __PublicTxt__: UTF8String;
5801 __SecretTxt__: UTF8String;
5802 begin
5803 __PublicTxt__ := UTF8String(PublicTxt);
5804 __SecretTxt__ := UTF8String(SecretTxt);
5805 Create(zcert_new_from_txt(PAnsiChar(__PublicTxt__), PAnsiChar(__SecretTxt__)), True);
5806 end;
5807
5808 constructor TZcert.Load(const Filename: string);
5809 var
5810 __Filename__: UTF8String;
5811 begin
5812 __Filename__ := UTF8String(Filename);
5813 Create(zcert_load(PAnsiChar(__Filename__)), True);
5814 end;
5815
5816 constructor TZcert.Create(handle: PZcert; owned: Boolean);
5817 begin
5818 FHandle := handle;
5819 FOwned := owned;
5820 end;
5821
5822 class function TZcert.Wrap(handle: PZcert; owned: Boolean): IZcert;
5823 begin
5824 if handle <> nil then Result := TZcert.Create(handle, owned) else Result := nil;
5825 end;
5826
5827 class function TZcert.UnWrap(const value: IZcert): PZcert;
5828 begin
5829 if value <> nil then Result := TZcert(value).FHandle else Result := nil;
5830 end;
5831
5832 destructor TZcert.Destroy;
5833 begin
5834 if FOwned and (FHandle <> nil) then
5835 zcert_destroy(FHandle);
5836 end;
5837
5838 class procedure TZcert.Test(Verbose: Boolean);
5839 begin
5840 zcert_test(Verbose);
5841 end;
5842
5843 function TZcert.PublicKey: PByte;
5844 begin
5845 Result := zcert_public_key(FHandle);
5846 end;
5847
5848 function TZcert.SecretKey: PByte;
5849 begin
5850 Result := zcert_secret_key(FHandle);
5851 end;
5852
5853 function TZcert.PublicTxt: string;
5854 begin
5855 Result := string(UTF8String(zcert_public_txt(FHandle)));
5856 end;
5857
5858 function TZcert.SecretTxt: string;
5859 begin
5860 Result := string(UTF8String(zcert_secret_txt(FHandle)));
5861 end;
5862
5863 procedure TZcert.SetMeta(const Name: string; const Format: string);
5864 var
5865 __Name__: UTF8String;
5866 __Format__: UTF8String;
5867 begin
5868 __Name__ := UTF8String(Name);
5869 __Format__ := UTF8String(Format);
5870 zcert_set_meta(FHandle, PAnsiChar(__Name__), PAnsiChar(__Format__));
5871 end;
5872
5873 procedure TZcert.UnsetMeta(const Name: string);
5874 var
5875 __Name__: UTF8String;
5876 begin
5877 __Name__ := UTF8String(Name);
5878 zcert_unset_meta(FHandle, PAnsiChar(__Name__));
5879 end;
5880
5881 function TZcert.Meta(const Name: string): string;
5882 var
5883 __Name__: UTF8String;
5884 begin
5885 __Name__ := UTF8String(Name);
5886 Result := string(UTF8String(zcert_meta(FHandle, PAnsiChar(__Name__))));
5887 end;
5888
5889 function TZcert.MetaKeys: IZlist;
5890 begin
5891 Result := TZlist.Wrap(zcert_meta_keys(FHandle), false);
5892 end;
5893
5894 function TZcert.Save(const Filename: string): Integer;
5895 var
5896 __Filename__: UTF8String;
5897 begin
5898 __Filename__ := UTF8String(Filename);
5899 Result := zcert_save(FHandle, PAnsiChar(__Filename__));
5900 end;
5901
5902 function TZcert.SavePublic(const Filename: string): Integer;
5903 var
5904 __Filename__: UTF8String;
5905 begin
5906 __Filename__ := UTF8String(Filename);
5907 Result := zcert_save_public(FHandle, PAnsiChar(__Filename__));
5908 end;
5909
5910 function TZcert.SaveSecret(const Filename: string): Integer;
5911 var
5912 __Filename__: UTF8String;
5913 begin
5914 __Filename__ := UTF8String(Filename);
5915 Result := zcert_save_secret(FHandle, PAnsiChar(__Filename__));
5916 end;
5917
5918 procedure TZcert.Apply(const Socket: IZSock);
5919 begin
5920 zcert_apply(FHandle, TZsock.UnWrap(Socket));
5921 end;
5922
5923 function TZcert.Dup: IZcert;
5924 begin
5925 Result := TZcert.Wrap(zcert_dup(FHandle), true);
5926 end;
5927
5928 function TZcert.Eq(const Compare: IZcert): Boolean;
5929 begin
5930 Result := zcert_eq(FHandle, TZcert.UnWrap(Compare));
5931 end;
5932
5933 procedure TZcert.Print;
5934 begin
5935 zcert_print(FHandle);
5936 end;
5937
5938 (* TZcertstore *)
5939
5940 constructor TZcertstore.New(const Location: string);
5941 var
5942 __Location__: UTF8String;
5943 begin
5944 __Location__ := UTF8String(Location);
5945 Create(zcertstore_new(PAnsiChar(__Location__)), True);
5946 end;
5947
5948 constructor TZcertstore.Create(handle: PZcertstore; owned: Boolean);
5949 begin
5950 FHandle := handle;
5951 FOwned := owned;
5952 end;
5953
5954 class function TZcertstore.Wrap(handle: PZcertstore; owned: Boolean): IZcertstore;
5955 begin
5956 if handle <> nil then Result := TZcertstore.Create(handle, owned) else Result := nil;
5957 end;
5958
5959 class function TZcertstore.UnWrap(const value: IZcertstore): PZcertstore;
5960 begin
5961 if value <> nil then Result := TZcertstore(value).FHandle else Result := nil;
5962 end;
5963
5964 destructor TZcertstore.Destroy;
5965 begin
5966 if FOwned and (FHandle <> nil) then
5967 zcertstore_destroy(FHandle);
5968 end;
5969
5970 class procedure TZcertstore.Test(Verbose: Boolean);
5971 begin
5972 zcertstore_test(Verbose);
5973 end;
5974
5975 procedure TZcertstore.SetLoader(Loader: TZcertstoreLoader; &Destructor: TZcertstoreDestructor; State: PByte);
5976 begin
5977 zcertstore_set_loader(FHandle, Loader, &Destructor, State);
5978 end;
5979
5980 function TZcertstore.Lookup(const PublicKey: string): IZcert;
5981 var
5982 __PublicKey__: UTF8String;
5983 begin
5984 __PublicKey__ := UTF8String(PublicKey);
5985 Result := TZcert.Wrap(zcertstore_lookup(FHandle, PAnsiChar(__PublicKey__)), false);
5986 end;
5987
5988 procedure TZcertstore.Insert(var CertP: IZcert);
5989 begin
5990 zcertstore_insert(FHandle, TZcert(CertP).FHandle);
5991 if TZcert(CertP).FHandle = nil then
5992 CertP := nil;
5993 end;
5994
5995 procedure TZcertstore.Empty;
5996 begin
5997 zcertstore_empty(FHandle);
5998 end;
5999
6000 procedure TZcertstore.Print;
6001 begin
6002 zcertstore_print(FHandle);
6003 end;
6004
6005 function TZcertstore.Certs: IZlistx;
6006 begin
6007 Result := TZlistx.Wrap(zcertstore_certs(FHandle), true);
6008 end;
6009
6010 (* TZchunk *)
6011
6012 constructor TZchunk.New(Data: PByte; Size: NativeUInt);
6013 begin
6014 Create(zchunk_new(Data, Size), True);
6015 end;
6016
6017 constructor TZchunk.Frommem(Data: PByte; Size: NativeUInt; &Destructor: TZchunkDestructorFn; Hint: Pointer);
6018 begin
6019 Create(zchunk_frommem(Data, Size, &Destructor, Hint), True);
6020 end;
6021
6022 constructor TZchunk.Create(handle: PZchunk; owned: Boolean);
6023 begin
6024 FHandle := handle;
6025 FOwned := owned;
6026 end;
6027
6028 class function TZchunk.Wrap(handle: PZchunk; owned: Boolean): IZchunk;
6029 begin
6030 if handle <> nil then Result := TZchunk.Create(handle, owned) else Result := nil;
6031 end;
6032
6033 class function TZchunk.UnWrap(const value: IZchunk): PZchunk;
6034 begin
6035 if value <> nil then Result := TZchunk(value).FHandle else Result := nil;
6036 end;
6037
6038 destructor TZchunk.Destroy;
6039 begin
6040 if FOwned and (FHandle <> nil) then
6041 zchunk_destroy(FHandle);
6042 end;
6043
6044 class function TZchunk.Read(Handle: Pointer; Bytes: NativeUInt): IZchunk;
6045 begin
6046 Result := TZchunk.Wrap(zchunk_read(Handle, Bytes), true);
6047 end;
6048
6049 class function TZchunk.Slurp(const Filename: string; Maxsize: NativeUInt): IZchunk;
6050 var
6051 __Filename__: UTF8String;
6052 begin
6053 __Filename__ := UTF8String(Filename);
6054 Result := TZchunk.Wrap(zchunk_slurp(PAnsiChar(__Filename__), Maxsize), true);
6055 end;
6056
6057 class function TZchunk.Packx(var SelfP: IZchunk): IZframe;
6058 begin
6059 Result := TZframe.Wrap(zchunk_packx(TZchunk(SelfP).FHandle), true);
6060 if TZchunk(SelfP).FHandle = nil then
6061 SelfP := nil;
6062 end;
6063
6064 class function TZchunk.Unpack(const Frame: IZframe): IZchunk;
6065 begin
6066 Result := TZchunk.Wrap(zchunk_unpack(TZframe.UnWrap(Frame)), true);
6067 end;
6068
6069 class function TZchunk.&Is(This: Pointer): Boolean;
6070 begin
6071 Result := zchunk_is(This);
6072 end;
6073
6074 class procedure TZchunk.Test(Verbose: Boolean);
6075 begin
6076 zchunk_test(Verbose);
6077 end;
6078
6079 procedure TZchunk.Resize(Size: NativeUInt);
6080 begin
6081 zchunk_resize(FHandle, Size);
6082 end;
6083
6084 function TZchunk.Size: NativeUInt;
6085 begin
6086 Result := zchunk_size(FHandle);
6087 end;
6088
6089 function TZchunk.MaxSize: NativeUInt;
6090 begin
6091 Result := zchunk_max_size(FHandle);
6092 end;
6093
6094 function TZchunk.Data: PByte;
6095 begin
6096 Result := zchunk_data(FHandle);
6097 end;
6098
6099 function TZchunk.&Set(Data: PByte; Size: NativeUInt): NativeUInt;
6100 begin
6101 Result := zchunk_set(FHandle, Data, Size);
6102 end;
6103
6104 function TZchunk.Fill(Filler: Byte; Size: NativeUInt): NativeUInt;
6105 begin
6106 Result := zchunk_fill(FHandle, Filler, Size);
6107 end;
6108
6109 function TZchunk.Append(Data: PByte; Size: NativeUInt): NativeUInt;
6110 begin
6111 Result := zchunk_append(FHandle, Data, Size);
6112 end;
6113
6114 function TZchunk.Extend(Data: PByte; Size: NativeUInt): NativeUInt;
6115 begin
6116 Result := zchunk_extend(FHandle, Data, Size);
6117 end;
6118
6119 function TZchunk.Consume(const Source: IZchunk): NativeUInt;
6120 begin
6121 Result := zchunk_consume(FHandle, TZchunk.UnWrap(Source));
6122 end;
6123
6124 function TZchunk.Exhausted: Boolean;
6125 begin
6126 Result := zchunk_exhausted(FHandle);
6127 end;
6128
6129 function TZchunk.Write(Handle: Pointer): Integer;
6130 begin
6131 Result := zchunk_write(FHandle, Handle);
6132 end;
6133
6134 function TZchunk.Dup: IZchunk;
6135 begin
6136 Result := TZchunk.Wrap(zchunk_dup(FHandle), true);
6137 end;
6138
6139 function TZchunk.Strhex: string;
6140 begin
6141 Result := ZFreeString(zchunk_strhex(FHandle));
6142 end;
6143
6144 function TZchunk.Strdup: string;
6145 begin
6146 Result := ZFreeString(zchunk_strdup(FHandle));
6147 end;
6148
6149 function TZchunk.Streq(const &String: string): Boolean;
6150 var
6151 __String__: UTF8String;
6152 begin
6153 __String__ := UTF8String(&String);
6154 Result := zchunk_streq(FHandle, PAnsiChar(__String__));
6155 end;
6156
6157 function TZchunk.Pack: IZframe;
6158 begin
6159 Result := TZframe.Wrap(zchunk_pack(FHandle), true);
6160 end;
6161
6162 function TZchunk.Digest: string;
6163 begin
6164 Result := string(UTF8String(zchunk_digest(FHandle)));
6165 end;
6166
6167 procedure TZchunk.Fprint(&File: Pointer);
6168 begin
6169 zchunk_fprint(FHandle, &File);
6170 end;
6171
6172 procedure TZchunk.Print;
6173 begin
6174 zchunk_print(FHandle);
6175 end;
6176
6177 (* TZclock *)
6178
6179 class procedure TZclock.Sleep(Msecs: Integer);
6180 begin
6181 zclock_sleep(Msecs);
6182 end;
6183
6184 class function TZclock.Time: Int64;
6185 begin
6186 Result := zclock_time;
6187 end;
6188
6189 class function TZclock.Mono: Int64;
6190 begin
6191 Result := zclock_mono;
6192 end;
6193
6194 class function TZclock.Usecs: Int64;
6195 begin
6196 Result := zclock_usecs;
6197 end;
6198
6199 class function TZclock.Timestr: string;
6200 begin
6201 Result := ZFreeString(zclock_timestr);
6202 end;
6203
6204 class procedure TZclock.Test(Verbose: Boolean);
6205 begin
6206 zclock_test(Verbose);
6207 end;
6208
6209 (* TZconfig *)
6210
6211 constructor TZconfig.New(const Name: string; const Parent: IZconfig);
6212 var
6213 __Name__: UTF8String;
6214 begin
6215 __Name__ := UTF8String(Name);
6216 Create(zconfig_new(PAnsiChar(__Name__), TZconfig.UnWrap(Parent)), True);
6217 end;
6218
6219 constructor TZconfig.Load(const Filename: string);
6220 var
6221 __Filename__: UTF8String;
6222 begin
6223 __Filename__ := UTF8String(Filename);
6224 Create(zconfig_load(PAnsiChar(__Filename__)), True);
6225 end;
6226
6227 constructor TZconfig.Loadf(const Format: string);
6228 var
6229 __Format__: UTF8String;
6230 begin
6231 __Format__ := UTF8String(Format);
6232 Create(zconfig_loadf(PAnsiChar(__Format__)), True);
6233 end;
6234
6235 constructor TZconfig.Create(handle: PZconfig; owned: Boolean);
6236 begin
6237 FHandle := handle;
6238 FOwned := owned;
6239 end;
6240
6241 class function TZconfig.Wrap(handle: PZconfig; owned: Boolean): IZconfig;
6242 begin
6243 if handle <> nil then Result := TZconfig.Create(handle, owned) else Result := nil;
6244 end;
6245
6246 class function TZconfig.UnWrap(const value: IZconfig): PZconfig;
6247 begin
6248 if value <> nil then Result := TZconfig(value).FHandle else Result := nil;
6249 end;
6250
6251 destructor TZconfig.Destroy;
6252 begin
6253 if FOwned and (FHandle <> nil) then
6254 zconfig_destroy(FHandle);
6255 end;
6256
6257 class function TZconfig.Reload(var SelfP: IZconfig): Integer;
6258 begin
6259 Result := zconfig_reload(TZconfig(SelfP).FHandle);
6260 if TZconfig(SelfP).FHandle = nil then
6261 SelfP := nil;
6262 end;
6263
6264 class function TZconfig.ChunkLoad(const Chunk: IZchunk): IZconfig;
6265 begin
6266 Result := TZconfig.Wrap(zconfig_chunk_load(TZchunk.UnWrap(Chunk)), false);
6267 end;
6268
6269 class function TZconfig.StrLoad(const &String: string): IZconfig;
6270 var
6271 __String__: UTF8String;
6272 begin
6273 __String__ := UTF8String(&String);
6274 Result := TZconfig.Wrap(zconfig_str_load(PAnsiChar(__String__)), true);
6275 end;
6276
6277 class procedure TZconfig.Remove(var SelfP: IZconfig);
6278 begin
6279 zconfig_remove(TZconfig(SelfP).FHandle);
6280 if TZconfig(SelfP).FHandle = nil then
6281 SelfP := nil;
6282 end;
6283
6284 class procedure TZconfig.Test(Verbose: Boolean);
6285 begin
6286 zconfig_test(Verbose);
6287 end;
6288
6289 function TZconfig.Dup: IZconfig;
6290 begin
6291 Result := TZconfig.Wrap(zconfig_dup(FHandle), true);
6292 end;
6293
6294 function TZconfig.Name: string;
6295 begin
6296 Result := string(UTF8String(zconfig_name(FHandle)));
6297 end;
6298
6299 function TZconfig.Value: string;
6300 begin
6301 Result := string(UTF8String(zconfig_value(FHandle)));
6302 end;
6303
6304 procedure TZconfig.Put(const Path: string; const Value: string);
6305 var
6306 __Path__: UTF8String;
6307 __Value__: UTF8String;
6308 begin
6309 __Path__ := UTF8String(Path);
6310 __Value__ := UTF8String(Value);
6311 zconfig_put(FHandle, PAnsiChar(__Path__), PAnsiChar(__Value__));
6312 end;
6313
6314 procedure TZconfig.Putf(const Path: string; const Format: string);
6315 var
6316 __Path__: UTF8String;
6317 __Format__: UTF8String;
6318 begin
6319 __Path__ := UTF8String(Path);
6320 __Format__ := UTF8String(Format);
6321 zconfig_putf(FHandle, PAnsiChar(__Path__), PAnsiChar(__Format__));
6322 end;
6323
6324 function TZconfig.Get(const Path: string; const DefaultValue: string): string;
6325 var
6326 __Path__: UTF8String;
6327 __DefaultValue__: UTF8String;
6328 begin
6329 __Path__ := UTF8String(Path);
6330 __DefaultValue__ := UTF8String(DefaultValue);
6331 Result := string(UTF8String(zconfig_get(FHandle, PAnsiChar(__Path__), PAnsiChar(__DefaultValue__))));
6332 end;
6333
6334 procedure TZconfig.SetName(const Name: string);
6335 var
6336 __Name__: UTF8String;
6337 begin
6338 __Name__ := UTF8String(Name);
6339 zconfig_set_name(FHandle, PAnsiChar(__Name__));
6340 end;
6341
6342 procedure TZconfig.SetValue(const Format: string);
6343 var
6344 __Format__: UTF8String;
6345 begin
6346 __Format__ := UTF8String(Format);
6347 zconfig_set_value(FHandle, PAnsiChar(__Format__));
6348 end;
6349
6350 function TZconfig.Child: IZconfig;
6351 begin
6352 Result := TZconfig.Wrap(zconfig_child(FHandle), false);
6353 end;
6354
6355 function TZconfig.Next: IZconfig;
6356 begin
6357 Result := TZconfig.Wrap(zconfig_next(FHandle), false);
6358 end;
6359
6360 function TZconfig.Locate(const Path: string): IZconfig;
6361 var
6362 __Path__: UTF8String;
6363 begin
6364 __Path__ := UTF8String(Path);
6365 Result := TZconfig.Wrap(zconfig_locate(FHandle, PAnsiChar(__Path__)), false);
6366 end;
6367
6368 function TZconfig.AtDepth(Level: Integer): IZconfig;
6369 begin
6370 Result := TZconfig.Wrap(zconfig_at_depth(FHandle, Level), false);
6371 end;
6372
6373 function TZconfig.Execute(Handler: TZconfigFct; Arg: Pointer): Integer;
6374 begin
6375 Result := zconfig_execute(FHandle, Handler, Arg);
6376 end;
6377
6378 procedure TZconfig.SetComment(const Format: string);
6379 var
6380 __Format__: UTF8String;
6381 begin
6382 __Format__ := UTF8String(Format);
6383 zconfig_set_comment(FHandle, PAnsiChar(__Format__));
6384 end;
6385
6386 function TZconfig.Comments: IZlist;
6387 begin
6388 Result := TZlist.Wrap(zconfig_comments(FHandle), false);
6389 end;
6390
6391 function TZconfig.Save(const Filename: string): Integer;
6392 var
6393 __Filename__: UTF8String;
6394 begin
6395 __Filename__ := UTF8String(Filename);
6396 Result := zconfig_save(FHandle, PAnsiChar(__Filename__));
6397 end;
6398
6399 function TZconfig.Savef(const Format: string): Integer;
6400 var
6401 __Format__: UTF8String;
6402 begin
6403 __Format__ := UTF8String(Format);
6404 Result := zconfig_savef(FHandle, PAnsiChar(__Format__));
6405 end;
6406
6407 function TZconfig.Filename: string;
6408 begin
6409 Result := string(UTF8String(zconfig_filename(FHandle)));
6410 end;
6411
6412 function TZconfig.ChunkSave: IZchunk;
6413 begin
6414 Result := TZchunk.Wrap(zconfig_chunk_save(FHandle), false);
6415 end;
6416
6417 function TZconfig.StrSave: string;
6418 begin
6419 Result := ZFreeString(zconfig_str_save(FHandle));
6420 end;
6421
6422 function TZconfig.HasChanged: Boolean;
6423 begin
6424 Result := zconfig_has_changed(FHandle);
6425 end;
6426
6427 procedure TZconfig.RemoveSubtree;
6428 begin
6429 zconfig_remove_subtree(FHandle);
6430 end;
6431
6432 procedure TZconfig.Fprint(&File: Pointer);
6433 begin
6434 zconfig_fprint(FHandle, &File);
6435 end;
6436
6437 procedure TZconfig.Print;
6438 begin
6439 zconfig_print(FHandle);
6440 end;
6441
6442 (* TZdigest *)
6443
6444 constructor TZdigest.New;
6445 begin
6446 Create(zdigest_new, True);
6447 end;
6448
6449 constructor TZdigest.Create(handle: PZdigest; owned: Boolean);
6450 begin
6451 FHandle := handle;
6452 FOwned := owned;
6453 end;
6454
6455 class function TZdigest.Wrap(handle: PZdigest; owned: Boolean): IZdigest;
6456 begin
6457 if handle <> nil then Result := TZdigest.Create(handle, owned) else Result := nil;
6458 end;
6459
6460 class function TZdigest.UnWrap(const value: IZdigest): PZdigest;
6461 begin
6462 if value <> nil then Result := TZdigest(value).FHandle else Result := nil;
6463 end;
6464
6465 destructor TZdigest.Destroy;
6466 begin
6467 if FOwned and (FHandle <> nil) then
6468 zdigest_destroy(FHandle);
6469 end;
6470
6471 class procedure TZdigest.Test(Verbose: Boolean);
6472 begin
6473 zdigest_test(Verbose);
6474 end;
6475
6476 procedure TZdigest.Update(Buffer: PByte; Length: NativeUInt);
6477 begin
6478 zdigest_update(FHandle, Buffer, Length);
6479 end;
6480
6481 function TZdigest.Data: PByte;
6482 begin
6483 Result := zdigest_data(FHandle);
6484 end;
6485
6486 function TZdigest.Size: NativeUInt;
6487 begin
6488 Result := zdigest_size(FHandle);
6489 end;
6490
6491 function TZdigest.&String: string;
6492 begin
6493 Result := string(UTF8String(zdigest_string(FHandle)));
6494 end;
6495
6496 (* TZdir *)
6497
6498 constructor TZdir.New(const Path: string; const Parent: string);
6499 var
6500 __Path__: UTF8String;
6501 __Parent__: UTF8String;
6502 begin
6503 __Path__ := UTF8String(Path);
6504 __Parent__ := UTF8String(Parent);
6505 Create(zdir_new(PAnsiChar(__Path__), PAnsiChar(__Parent__)), True);
6506 end;
6507
6508 constructor TZdir.Create(handle: PZdir; owned: Boolean);
6509 begin
6510 FHandle := handle;
6511 FOwned := owned;
6512 end;
6513
6514 class function TZdir.Wrap(handle: PZdir; owned: Boolean): IZdir;
6515 begin
6516 if handle <> nil then Result := TZdir.Create(handle, owned) else Result := nil;
6517 end;
6518
6519 class function TZdir.UnWrap(const value: IZdir): PZdir;
6520 begin
6521 if value <> nil then Result := TZdir(value).FHandle else Result := nil;
6522 end;
6523
6524 destructor TZdir.Destroy;
6525 begin
6526 if FOwned and (FHandle <> nil) then
6527 zdir_destroy(FHandle);
6528 end;
6529
6530 class function TZdir.Diff(const Older: IZdir; const Newer: IZdir; const Alias: string): IZlist;
6531 var
6532 __Alias__: UTF8String;
6533 begin
6534 __Alias__ := UTF8String(Alias);
6535 Result := TZlist.Wrap(zdir_diff(TZdir.UnWrap(Older), TZdir.UnWrap(Newer), PAnsiChar(__Alias__)), true);
6536 end;
6537
6538 class procedure TZdir.Watch(const Pipe: IZsock; Unused: Pointer);
6539 begin
6540 zdir_watch(TZsock.UnWrap(Pipe), Unused);
6541 end;
6542
6543 class procedure TZdir.Test(Verbose: Boolean);
6544 begin
6545 zdir_test(Verbose);
6546 end;
6547
6548 function TZdir.Path: string;
6549 begin
6550 Result := string(UTF8String(zdir_path(FHandle)));
6551 end;
6552
6553 function TZdir.Modified: Int64;
6554 begin
6555 Result := zdir_modified(FHandle);
6556 end;
6557
6558 function TZdir.Cursize: Longint;
6559 begin
6560 Result := zdir_cursize(FHandle);
6561 end;
6562
6563 function TZdir.Count: NativeUInt;
6564 begin
6565 Result := zdir_count(FHandle);
6566 end;
6567
6568 function TZdir.List: IZlist;
6569 begin
6570 Result := TZlist.Wrap(zdir_list(FHandle), true);
6571 end;
6572
6573 procedure TZdir.Remove(Force: Boolean);
6574 begin
6575 zdir_remove(FHandle, Force);
6576 end;
6577
6578 function TZdir.Resync(const Alias: string): IZlist;
6579 var
6580 __Alias__: UTF8String;
6581 begin
6582 __Alias__ := UTF8String(Alias);
6583 Result := TZlist.Wrap(zdir_resync(FHandle, PAnsiChar(__Alias__)), true);
6584 end;
6585
6586 function TZdir.Cache: IZhash;
6587 begin
6588 Result := TZhash.Wrap(zdir_cache(FHandle), true);
6589 end;
6590
6591 procedure TZdir.Fprint(&File: Pointer; Indent: Integer);
6592 begin
6593 zdir_fprint(FHandle, &File, Indent);
6594 end;
6595
6596 procedure TZdir.Print(Indent: Integer);
6597 begin
6598 zdir_print(FHandle, Indent);
6599 end;
6600
6601 (* TZdirPatch *)
6602
6603 constructor TZdirPatch.New(const Path: string; const &File: IZfile; Op: Integer; const Alias: string);
6604 var
6605 __Path__: UTF8String;
6606 __Alias__: UTF8String;
6607 begin
6608 __Path__ := UTF8String(Path);
6609 __Alias__ := UTF8String(Alias);
6610 Create(zdir_patch_new(PAnsiChar(__Path__), TZfile.UnWrap(&File), Op, PAnsiChar(__Alias__)), True);
6611 end;
6612
6613 constructor TZdirPatch.Create(handle: PZdirPatch; owned: Boolean);
6614 begin
6615 FHandle := handle;
6616 FOwned := owned;
6617 end;
6618
6619 class function TZdirPatch.Wrap(handle: PZdirPatch; owned: Boolean): IZdirPatch;
6620 begin
6621 if handle <> nil then Result := TZdirPatch.Create(handle, owned) else Result := nil;
6622 end;
6623
6624 class function TZdirPatch.UnWrap(const value: IZdirPatch): PZdirPatch;
6625 begin
6626 if value <> nil then Result := TZdirPatch(value).FHandle else Result := nil;
6627 end;
6628
6629 destructor TZdirPatch.Destroy;
6630 begin
6631 if FOwned and (FHandle <> nil) then
6632 zdir_patch_destroy(FHandle);
6633 end;
6634
6635 class procedure TZdirPatch.Test(Verbose: Boolean);
6636 begin
6637 zdir_patch_test(Verbose);
6638 end;
6639
6640 function TZdirPatch.Dup: IZdirPatch;
6641 begin
6642 Result := TZdirPatch.Wrap(zdir_patch_dup(FHandle), true);
6643 end;
6644
6645 function TZdirPatch.Path: string;
6646 begin
6647 Result := string(UTF8String(zdir_patch_path(FHandle)));
6648 end;
6649
6650 function TZdirPatch.&File: IZfile;
6651 begin
6652 Result := TZfile.Wrap(zdir_patch_file(FHandle), false);
6653 end;
6654
6655 function TZdirPatch.Op: Integer;
6656 begin
6657 Result := zdir_patch_op(FHandle);
6658 end;
6659
6660 function TZdirPatch.Vpath: string;
6661 begin
6662 Result := string(UTF8String(zdir_patch_vpath(FHandle)));
6663 end;
6664
6665 procedure TZdirPatch.DigestSet;
6666 begin
6667 zdir_patch_digest_set(FHandle);
6668 end;
6669
6670 function TZdirPatch.Digest: string;
6671 begin
6672 Result := string(UTF8String(zdir_patch_digest(FHandle)));
6673 end;
6674
6675 (* TZfile *)
6676
6677 constructor TZfile.New(const Path: string; const Name: string);
6678 var
6679 __Path__: UTF8String;
6680 __Name__: UTF8String;
6681 begin
6682 __Path__ := UTF8String(Path);
6683 __Name__ := UTF8String(Name);
6684 Create(zfile_new(PAnsiChar(__Path__), PAnsiChar(__Name__)), True);
6685 end;
6686
6687 constructor TZfile.Tmp;
6688 begin
6689 Create(zfile_tmp, True);
6690 end;
6691
6692 constructor TZfile.Create(handle: PZfile; owned: Boolean);
6693 begin
6694 FHandle := handle;
6695 FOwned := owned;
6696 end;
6697
6698 class function TZfile.Wrap(handle: PZfile; owned: Boolean): IZfile;
6699 begin
6700 if handle <> nil then Result := TZfile.Create(handle, owned) else Result := nil;
6701 end;
6702
6703 class function TZfile.UnWrap(const value: IZfile): PZfile;
6704 begin
6705 if value <> nil then Result := TZfile(value).FHandle else Result := nil;
6706 end;
6707
6708 destructor TZfile.Destroy;
6709 begin
6710 if FOwned and (FHandle <> nil) then
6711 zfile_destroy(FHandle);
6712 end;
6713
6714 class procedure TZfile.Test(Verbose: Boolean);
6715 begin
6716 zfile_test(Verbose);
6717 end;
6718
6719 function TZfile.Dup: IZfile;
6720 begin
6721 Result := TZfile.Wrap(zfile_dup(FHandle), true);
6722 end;
6723
6724 function TZfile.Filename(const Path: string): string;
6725 var
6726 __Path__: UTF8String;
6727 begin
6728 __Path__ := UTF8String(Path);
6729 Result := string(UTF8String(zfile_filename(FHandle, PAnsiChar(__Path__))));
6730 end;
6731
6732 procedure TZfile.Restat;
6733 begin
6734 zfile_restat(FHandle);
6735 end;
6736
6737 function TZfile.Modified: Int64;
6738 begin
6739 Result := zfile_modified(FHandle);
6740 end;
6741
6742 function TZfile.Cursize: Longint;
6743 begin
6744 Result := zfile_cursize(FHandle);
6745 end;
6746
6747 function TZfile.IsDirectory: Boolean;
6748 begin
6749 Result := zfile_is_directory(FHandle);
6750 end;
6751
6752 function TZfile.IsRegular: Boolean;
6753 begin
6754 Result := zfile_is_regular(FHandle);
6755 end;
6756
6757 function TZfile.IsReadable: Boolean;
6758 begin
6759 Result := zfile_is_readable(FHandle);
6760 end;
6761
6762 function TZfile.IsWriteable: Boolean;
6763 begin
6764 Result := zfile_is_writeable(FHandle);
6765 end;
6766
6767 function TZfile.IsStable: Boolean;
6768 begin
6769 Result := zfile_is_stable(FHandle);
6770 end;
6771
6772 function TZfile.HasChanged: Boolean;
6773 begin
6774 Result := zfile_has_changed(FHandle);
6775 end;
6776
6777 procedure TZfile.Remove;
6778 begin
6779 zfile_remove(FHandle);
6780 end;
6781
6782 function TZfile.Input: Integer;
6783 begin
6784 Result := zfile_input(FHandle);
6785 end;
6786
6787 function TZfile.Output: Integer;
6788 begin
6789 Result := zfile_output(FHandle);
6790 end;
6791
6792 function TZfile.Read(Bytes: NativeUInt; Offset: Longint): IZchunk;
6793 begin
6794 Result := TZchunk.Wrap(zfile_read(FHandle, Bytes, Offset), true);
6795 end;
6796
6797 function TZfile.Eof: Boolean;
6798 begin
6799 Result := zfile_eof(FHandle);
6800 end;
6801
6802 function TZfile.Write(const Chunk: IZchunk; Offset: Longint): Integer;
6803 begin
6804 Result := zfile_write(FHandle, TZchunk.UnWrap(Chunk), Offset);
6805 end;
6806
6807 function TZfile.Readln: string;
6808 begin
6809 Result := string(UTF8String(zfile_readln(FHandle)));
6810 end;
6811
6812 procedure TZfile.Close;
6813 begin
6814 zfile_close(FHandle);
6815 end;
6816
6817 function TZfile.Handle: Pointer;
6818 begin
6819 Result := zfile_handle(FHandle);
6820 end;
6821
6822 function TZfile.Digest: string;
6823 begin
6824 Result := string(UTF8String(zfile_digest(FHandle)));
6825 end;
6826
6827 (* TZframe *)
6828
6829 constructor TZframe.New(Data: PByte; Size: NativeUInt);
6830 begin
6831 Create(zframe_new(Data, Size), True);
6832 end;
6833
6834 constructor TZframe.NewEmpty;
6835 begin
6836 Create(zframe_new_empty, True);
6837 end;
6838
6839 constructor TZframe.From(const &String: string);
6840 var
6841 __String__: UTF8String;
6842 begin
6843 __String__ := UTF8String(&String);
6844 Create(zframe_from(PAnsiChar(__String__)), True);
6845 end;
6846
6847 constructor TZframe.Frommem(Data: PByte; Size: NativeUInt; &Destructor: TZframeDestructorFn; Hint: Pointer);
6848 begin
6849 Create(zframe_frommem(Data, Size, &Destructor, Hint), True);
6850 end;
6851
6852 constructor TZframe.Recv(const Source: IZSock);
6853 begin
6854 Create(zframe_recv(TZsock.UnWrap(Source)), True);
6855 end;
6856
6857 constructor TZframe.Create(handle: PZframe; owned: Boolean);
6858 begin
6859 FHandle := handle;
6860 FOwned := owned;
6861 end;
6862
6863 class function TZframe.Wrap(handle: PZframe; owned: Boolean): IZframe;
6864 begin
6865 if handle <> nil then Result := TZframe.Create(handle, owned) else Result := nil;
6866 end;
6867
6868 class function TZframe.UnWrap(const value: IZframe): PZframe;
6869 begin
6870 if value <> nil then Result := TZframe(value).FHandle else Result := nil;
6871 end;
6872
6873 destructor TZframe.Destroy;
6874 begin
6875 if FOwned and (FHandle <> nil) then
6876 zframe_destroy(FHandle);
6877 end;
6878
6879 class function TZframe.Send(var SelfP: IZframe; const Dest: IZSock; Flags: Integer): Integer;
6880 begin
6881 Result := zframe_send(TZframe(SelfP).FHandle, TZsock.UnWrap(Dest), Flags);
6882 if TZframe(SelfP).FHandle = nil then
6883 SelfP := nil;
6884 end;
6885
6886 class function TZframe.&Is(This: Pointer): Boolean;
6887 begin
6888 Result := zframe_is(This);
6889 end;
6890
6891 class procedure TZframe.Test(Verbose: Boolean);
6892 begin
6893 zframe_test(Verbose);
6894 end;
6895
6896 function TZframe.Size: NativeUInt;
6897 begin
6898 Result := zframe_size(FHandle);
6899 end;
6900
6901 function TZframe.Data: PByte;
6902 begin
6903 Result := zframe_data(FHandle);
6904 end;
6905
6906 function TZframe.Meta(const &Property: string): string;
6907 var
6908 __Property__: UTF8String;
6909 begin
6910 __Property__ := UTF8String(&Property);
6911 Result := string(UTF8String(zframe_meta(FHandle, PAnsiChar(__Property__))));
6912 end;
6913
6914 function TZframe.Dup: IZframe;
6915 begin
6916 Result := TZframe.Wrap(zframe_dup(FHandle), true);
6917 end;
6918
6919 function TZframe.Strhex: string;
6920 begin
6921 Result := ZFreeString(zframe_strhex(FHandle));
6922 end;
6923
6924 function TZframe.Strdup: string;
6925 begin
6926 Result := ZFreeString(zframe_strdup(FHandle));
6927 end;
6928
6929 function TZframe.Streq(const &String: string): Boolean;
6930 var
6931 __String__: UTF8String;
6932 begin
6933 __String__ := UTF8String(&String);
6934 Result := zframe_streq(FHandle, PAnsiChar(__String__));
6935 end;
6936
6937 function TZframe.More: Integer;
6938 begin
6939 Result := zframe_more(FHandle);
6940 end;
6941
6942 procedure TZframe.SetMore(More: Integer);
6943 begin
6944 zframe_set_more(FHandle, More);
6945 end;
6946
6947 function TZframe.RoutingId: Cardinal;
6948 begin
6949 Result := zframe_routing_id(FHandle);
6950 end;
6951
6952 procedure TZframe.SetRoutingId(RoutingId: Cardinal);
6953 begin
6954 zframe_set_routing_id(FHandle, RoutingId);
6955 end;
6956
6957 function TZframe.Group: string;
6958 begin
6959 Result := string(UTF8String(zframe_group(FHandle)));
6960 end;
6961
6962 function TZframe.SetGroup(const Group: string): Integer;
6963 var
6964 __Group__: UTF8String;
6965 begin
6966 __Group__ := UTF8String(Group);
6967 Result := zframe_set_group(FHandle, PAnsiChar(__Group__));
6968 end;
6969
6970 function TZframe.Eq(const Other: IZframe): Boolean;
6971 begin
6972 Result := zframe_eq(FHandle, TZframe.UnWrap(Other));
6973 end;
6974
6975 procedure TZframe.Reset(Data: PByte; Size: NativeUInt);
6976 begin
6977 zframe_reset(FHandle, Data, Size);
6978 end;
6979
6980 procedure TZframe.Print(const Prefix: string);
6981 var
6982 __Prefix__: UTF8String;
6983 begin
6984 __Prefix__ := UTF8String(Prefix);
6985 zframe_print(FHandle, PAnsiChar(__Prefix__));
6986 end;
6987
6988 (* TZhash *)
6989
6990 constructor TZhash.New;
6991 begin
6992 Create(zhash_new, True);
6993 end;
6994
6995 constructor TZhash.Unpack(const Frame: IZframe);
6996 begin
6997 Create(zhash_unpack(TZframe.UnWrap(Frame)), True);
6998 end;
6999
7000 constructor TZhash.Create(handle: PZhash; owned: Boolean);
7001 begin
7002 FHandle := handle;
7003 FOwned := owned;
7004 end;
7005
7006 class function TZhash.Wrap(handle: PZhash; owned: Boolean): IZhash;
7007 begin
7008 if handle <> nil then Result := TZhash.Create(handle, owned) else Result := nil;
7009 end;
7010
7011 class function TZhash.UnWrap(const value: IZhash): PZhash;
7012 begin
7013 if value <> nil then Result := TZhash(value).FHandle else Result := nil;
7014 end;
7015
7016 destructor TZhash.Destroy;
7017 begin
7018 if FOwned and (FHandle <> nil) then
7019 zhash_destroy(FHandle);
7020 end;
7021
7022 class procedure TZhash.Test(Verbose: Boolean);
7023 begin
7024 zhash_test(Verbose);
7025 end;
7026
7027 function TZhash.Insert(const Key: string; Item: Pointer): Integer;
7028 var
7029 __Key__: UTF8String;
7030 begin
7031 __Key__ := UTF8String(Key);
7032 Result := zhash_insert(FHandle, PAnsiChar(__Key__), Item);
7033 end;
7034
7035 procedure TZhash.Update(const Key: string; Item: Pointer);
7036 var
7037 __Key__: UTF8String;
7038 begin
7039 __Key__ := UTF8String(Key);
7040 zhash_update(FHandle, PAnsiChar(__Key__), Item);
7041 end;
7042
7043 procedure TZhash.Delete(const Key: string);
7044 var
7045 __Key__: UTF8String;
7046 begin
7047 __Key__ := UTF8String(Key);
7048 zhash_delete(FHandle, PAnsiChar(__Key__));
7049 end;
7050
7051 function TZhash.Lookup(const Key: string): Pointer;
7052 var
7053 __Key__: UTF8String;
7054 begin
7055 __Key__ := UTF8String(Key);
7056 Result := zhash_lookup(FHandle, PAnsiChar(__Key__));
7057 end;
7058
7059 function TZhash.Rename(const OldKey: string; const NewKey: string): Integer;
7060 var
7061 __OldKey__: UTF8String;
7062 __NewKey__: UTF8String;
7063 begin
7064 __OldKey__ := UTF8String(OldKey);
7065 __NewKey__ := UTF8String(NewKey);
7066 Result := zhash_rename(FHandle, PAnsiChar(__OldKey__), PAnsiChar(__NewKey__));
7067 end;
7068
7069 function TZhash.Freefn(const Key: string; FreeFn: TZhashFreeFn): Pointer;
7070 var
7071 __Key__: UTF8String;
7072 begin
7073 __Key__ := UTF8String(Key);
7074 Result := zhash_freefn(FHandle, PAnsiChar(__Key__), FreeFn);
7075 end;
7076
7077 function TZhash.Size: NativeUInt;
7078 begin
7079 Result := zhash_size(FHandle);
7080 end;
7081
7082 function TZhash.Dup: IZhash;
7083 begin
7084 Result := TZhash.Wrap(zhash_dup(FHandle), true);
7085 end;
7086
7087 function TZhash.Keys: IZlist;
7088 begin
7089 Result := TZlist.Wrap(zhash_keys(FHandle), true);
7090 end;
7091
7092 function TZhash.First: Pointer;
7093 begin
7094 Result := zhash_first(FHandle);
7095 end;
7096
7097 function TZhash.Next: Pointer;
7098 begin
7099 Result := zhash_next(FHandle);
7100 end;
7101
7102 function TZhash.Cursor: string;
7103 begin
7104 Result := string(UTF8String(zhash_cursor(FHandle)));
7105 end;
7106
7107 procedure TZhash.Comment(const Format: string);
7108 var
7109 __Format__: UTF8String;
7110 begin
7111 __Format__ := UTF8String(Format);
7112 zhash_comment(FHandle, PAnsiChar(__Format__));
7113 end;
7114
7115 function TZhash.Pack: IZframe;
7116 begin
7117 Result := TZframe.Wrap(zhash_pack(FHandle), true);
7118 end;
7119
7120 function TZhash.Save(const Filename: string): Integer;
7121 var
7122 __Filename__: UTF8String;
7123 begin
7124 __Filename__ := UTF8String(Filename);
7125 Result := zhash_save(FHandle, PAnsiChar(__Filename__));
7126 end;
7127
7128 function TZhash.Load(const Filename: string): Integer;
7129 var
7130 __Filename__: UTF8String;
7131 begin
7132 __Filename__ := UTF8String(Filename);
7133 Result := zhash_load(FHandle, PAnsiChar(__Filename__));
7134 end;
7135
7136 function TZhash.Refresh: Integer;
7137 begin
7138 Result := zhash_refresh(FHandle);
7139 end;
7140
7141 procedure TZhash.Autofree;
7142 begin
7143 zhash_autofree(FHandle);
7144 end;
7145
7146 (* TZhashx *)
7147
7148 constructor TZhashx.New;
7149 begin
7150 Create(zhashx_new, True);
7151 end;
7152
7153 constructor TZhashx.Unpack(const Frame: IZframe);
7154 begin
7155 Create(zhashx_unpack(TZframe.UnWrap(Frame)), True);
7156 end;
7157
7158 constructor TZhashx.UnpackOwn(const Frame: IZframe; Deserializer: TZhashxDeserializerFn);
7159 begin
7160 Create(zhashx_unpack_own(TZframe.UnWrap(Frame), Deserializer), True);
7161 end;
7162
7163 constructor TZhashx.Create(handle: PZhashx; owned: Boolean);
7164 begin
7165 FHandle := handle;
7166 FOwned := owned;
7167 end;
7168
7169 class function TZhashx.Wrap(handle: PZhashx; owned: Boolean): IZhashx;
7170 begin
7171 if handle <> nil then Result := TZhashx.Create(handle, owned) else Result := nil;
7172 end;
7173
7174 class function TZhashx.UnWrap(const value: IZhashx): PZhashx;
7175 begin
7176 if value <> nil then Result := TZhashx(value).FHandle else Result := nil;
7177 end;
7178
7179 destructor TZhashx.Destroy;
7180 begin
7181 if FOwned and (FHandle <> nil) then
7182 zhashx_destroy(FHandle);
7183 end;
7184
7185 class procedure TZhashx.Test(Verbose: Boolean);
7186 begin
7187 zhashx_test(Verbose);
7188 end;
7189
7190 function TZhashx.Insert(Key: Pointer; Item: Pointer): Integer;
7191 begin
7192 Result := zhashx_insert(FHandle, Key, Item);
7193 end;
7194
7195 procedure TZhashx.Update(Key: Pointer; Item: Pointer);
7196 begin
7197 zhashx_update(FHandle, Key, Item);
7198 end;
7199
7200 procedure TZhashx.Delete(Key: Pointer);
7201 begin
7202 zhashx_delete(FHandle, Key);
7203 end;
7204
7205 procedure TZhashx.Purge;
7206 begin
7207 zhashx_purge(FHandle);
7208 end;
7209
7210 function TZhashx.Lookup(Key: Pointer): Pointer;
7211 begin
7212 Result := zhashx_lookup(FHandle, Key);
7213 end;
7214
7215 function TZhashx.Rename(OldKey: Pointer; NewKey: Pointer): Integer;
7216 begin
7217 Result := zhashx_rename(FHandle, OldKey, NewKey);
7218 end;
7219
7220 function TZhashx.Freefn(Key: Pointer; FreeFn: TZhashxFreeFn): Pointer;
7221 begin
7222 Result := zhashx_freefn(FHandle, Key, FreeFn);
7223 end;
7224
7225 function TZhashx.Size: NativeUInt;
7226 begin
7227 Result := zhashx_size(FHandle);
7228 end;
7229
7230 function TZhashx.Keys: IZlistx;
7231 begin
7232 Result := TZlistx.Wrap(zhashx_keys(FHandle), true);
7233 end;
7234
7235 function TZhashx.Values: IZlistx;
7236 begin
7237 Result := TZlistx.Wrap(zhashx_values(FHandle), true);
7238 end;
7239
7240 function TZhashx.First: Pointer;
7241 begin
7242 Result := zhashx_first(FHandle);
7243 end;
7244
7245 function TZhashx.Next: Pointer;
7246 begin
7247 Result := zhashx_next(FHandle);
7248 end;
7249
7250 function TZhashx.Cursor: Pointer;
7251 begin
7252 Result := zhashx_cursor(FHandle);
7253 end;
7254
7255 procedure TZhashx.Comment(const Format: string);
7256 var
7257 __Format__: UTF8String;
7258 begin
7259 __Format__ := UTF8String(Format);
7260 zhashx_comment(FHandle, PAnsiChar(__Format__));
7261 end;
7262
7263 function TZhashx.Save(const Filename: string): Integer;
7264 var
7265 __Filename__: UTF8String;
7266 begin
7267 __Filename__ := UTF8String(Filename);
7268 Result := zhashx_save(FHandle, PAnsiChar(__Filename__));
7269 end;
7270
7271 function TZhashx.Load(const Filename: string): Integer;
7272 var
7273 __Filename__: UTF8String;
7274 begin
7275 __Filename__ := UTF8String(Filename);
7276 Result := zhashx_load(FHandle, PAnsiChar(__Filename__));
7277 end;
7278
7279 function TZhashx.Refresh: Integer;
7280 begin
7281 Result := zhashx_refresh(FHandle);
7282 end;
7283
7284 function TZhashx.Pack: IZframe;
7285 begin
7286 Result := TZframe.Wrap(zhashx_pack(FHandle), true);
7287 end;
7288
7289 function TZhashx.PackOwn(Serializer: TZhashxSerializerFn): IZframe;
7290 begin
7291 Result := TZframe.Wrap(zhashx_pack_own(FHandle, Serializer), true);
7292 end;
7293
7294 function TZhashx.Dup: IZhashx;
7295 begin
7296 Result := TZhashx.Wrap(zhashx_dup(FHandle), true);
7297 end;
7298
7299 procedure TZhashx.SetDestructor(&Destructor: TZhashxDestructorFn);
7300 begin
7301 zhashx_set_destructor(FHandle, &Destructor);
7302 end;
7303
7304 procedure TZhashx.SetDuplicator(Duplicator: TZhashxDuplicatorFn);
7305 begin
7306 zhashx_set_duplicator(FHandle, Duplicator);
7307 end;
7308
7309 procedure TZhashx.SetKeyDestructor(&Destructor: TZhashxDestructorFn);
7310 begin
7311 zhashx_set_key_destructor(FHandle, &Destructor);
7312 end;
7313
7314 procedure TZhashx.SetKeyDuplicator(Duplicator: TZhashxDuplicatorFn);
7315 begin
7316 zhashx_set_key_duplicator(FHandle, Duplicator);
7317 end;
7318
7319 procedure TZhashx.SetKeyComparator(Comparator: TZhashxComparatorFn);
7320 begin
7321 zhashx_set_key_comparator(FHandle, Comparator);
7322 end;
7323
7324 procedure TZhashx.SetKeyHasher(Hasher: TZhashxHashFn);
7325 begin
7326 zhashx_set_key_hasher(FHandle, Hasher);
7327 end;
7328
7329 function TZhashx.DupV2: IZhashx;
7330 begin
7331 Result := TZhashx.Wrap(zhashx_dup_v2(FHandle), false);
7332 end;
7333
7334 (* TZiflist *)
7335
7336 constructor TZiflist.New;
7337 begin
7338 Create(ziflist_new, True);
7339 end;
7340
7341 constructor TZiflist.Create(handle: PZiflist; owned: Boolean);
7342 begin
7343 FHandle := handle;
7344 FOwned := owned;
7345 end;
7346
7347 class function TZiflist.Wrap(handle: PZiflist; owned: Boolean): IZiflist;
7348 begin
7349 if handle <> nil then Result := TZiflist.Create(handle, owned) else Result := nil;
7350 end;
7351
7352 class function TZiflist.UnWrap(const value: IZiflist): PZiflist;
7353 begin
7354 if value <> nil then Result := TZiflist(value).FHandle else Result := nil;
7355 end;
7356
7357 destructor TZiflist.Destroy;
7358 begin
7359 if FOwned and (FHandle <> nil) then
7360 ziflist_destroy(FHandle);
7361 end;
7362
7363 class function TZiflist.NewIpv6: IZiflist;
7364 begin
7365 Result := TZiflist.Wrap(ziflist_new_ipv6, true);
7366 end;
7367
7368 class procedure TZiflist.Test(Verbose: Boolean);
7369 begin
7370 ziflist_test(Verbose);
7371 end;
7372
7373 procedure TZiflist.Reload;
7374 begin
7375 ziflist_reload(FHandle);
7376 end;
7377
7378 function TZiflist.Size: NativeUInt;
7379 begin
7380 Result := ziflist_size(FHandle);
7381 end;
7382
7383 function TZiflist.First: string;
7384 begin
7385 Result := string(UTF8String(ziflist_first(FHandle)));
7386 end;
7387
7388 function TZiflist.Next: string;
7389 begin
7390 Result := string(UTF8String(ziflist_next(FHandle)));
7391 end;
7392
7393 function TZiflist.Address: string;
7394 begin
7395 Result := string(UTF8String(ziflist_address(FHandle)));
7396 end;
7397
7398 function TZiflist.Broadcast: string;
7399 begin
7400 Result := string(UTF8String(ziflist_broadcast(FHandle)));
7401 end;
7402
7403 function TZiflist.Netmask: string;
7404 begin
7405 Result := string(UTF8String(ziflist_netmask(FHandle)));
7406 end;
7407
7408 procedure TZiflist.Print;
7409 begin
7410 ziflist_print(FHandle);
7411 end;
7412
7413 procedure TZiflist.ReloadIpv6;
7414 begin
7415 ziflist_reload_ipv6(FHandle);
7416 end;
7417
7418 function TZiflist.IsIpv6: Boolean;
7419 begin
7420 Result := ziflist_is_ipv6(FHandle);
7421 end;
7422
7423 (* TZlist *)
7424
7425 constructor TZlist.New;
7426 begin
7427 Create(zlist_new, True);
7428 end;
7429
7430 constructor TZlist.Create(handle: PZlist; owned: Boolean);
7431 begin
7432 FHandle := handle;
7433 FOwned := owned;
7434 end;
7435
7436 class function TZlist.Wrap(handle: PZlist; owned: Boolean): IZlist;
7437 begin
7438 if handle <> nil then Result := TZlist.Create(handle, owned) else Result := nil;
7439 end;
7440
7441 class function TZlist.UnWrap(const value: IZlist): PZlist;
7442 begin
7443 if value <> nil then Result := TZlist(value).FHandle else Result := nil;
7444 end;
7445
7446 destructor TZlist.Destroy;
7447 begin
7448 if FOwned and (FHandle <> nil) then
7449 zlist_destroy(FHandle);
7450 end;
7451
7452 class procedure TZlist.Test(Verbose: Boolean);
7453 begin
7454 zlist_test(Verbose);
7455 end;
7456
7457 function TZlist.First: Pointer;
7458 begin
7459 Result := zlist_first(FHandle);
7460 end;
7461
7462 function TZlist.Next: Pointer;
7463 begin
7464 Result := zlist_next(FHandle);
7465 end;
7466
7467 function TZlist.Last: Pointer;
7468 begin
7469 Result := zlist_last(FHandle);
7470 end;
7471
7472 function TZlist.Head: Pointer;
7473 begin
7474 Result := zlist_head(FHandle);
7475 end;
7476
7477 function TZlist.Tail: Pointer;
7478 begin
7479 Result := zlist_tail(FHandle);
7480 end;
7481
7482 function TZlist.Item: Pointer;
7483 begin
7484 Result := zlist_item(FHandle);
7485 end;
7486
7487 function TZlist.Append(Item: Pointer): Integer;
7488 begin
7489 Result := zlist_append(FHandle, Item);
7490 end;
7491
7492 function TZlist.Push(Item: Pointer): Integer;
7493 begin
7494 Result := zlist_push(FHandle, Item);
7495 end;
7496
7497 function TZlist.Pop: Pointer;
7498 begin
7499 Result := zlist_pop(FHandle);
7500 end;
7501
7502 function TZlist.Exists(Item: Pointer): Boolean;
7503 begin
7504 Result := zlist_exists(FHandle, Item);
7505 end;
7506
7507 procedure TZlist.Remove(Item: Pointer);
7508 begin
7509 zlist_remove(FHandle, Item);
7510 end;
7511
7512 function TZlist.Dup: IZlist;
7513 begin
7514 Result := TZlist.Wrap(zlist_dup(FHandle), true);
7515 end;
7516
7517 procedure TZlist.Purge;
7518 begin
7519 zlist_purge(FHandle);
7520 end;
7521
7522 function TZlist.Size: NativeUInt;
7523 begin
7524 Result := zlist_size(FHandle);
7525 end;
7526
7527 procedure TZlist.Sort(Compare: TZlistCompareFn);
7528 begin
7529 zlist_sort(FHandle, Compare);
7530 end;
7531
7532 procedure TZlist.Autofree;
7533 begin
7534 zlist_autofree(FHandle);
7535 end;
7536
7537 procedure TZlist.Comparefn(Fn: TZlistCompareFn);
7538 begin
7539 zlist_comparefn(FHandle, Fn);
7540 end;
7541
7542 function TZlist.Freefn(Item: Pointer; Fn: TZlistFreeFn; AtTail: Boolean): Pointer;
7543 begin
7544 Result := zlist_freefn(FHandle, Item, Fn, AtTail);
7545 end;
7546
7547 (* TZlistx *)
7548
7549 constructor TZlistx.New;
7550 begin
7551 Create(zlistx_new, True);
7552 end;
7553
7554 constructor TZlistx.Unpack(const Frame: IZframe);
7555 begin
7556 Create(zlistx_unpack(TZframe.UnWrap(Frame)), True);
7557 end;
7558
7559 constructor TZlistx.Create(handle: PZlistx; owned: Boolean);
7560 begin
7561 FHandle := handle;
7562 FOwned := owned;
7563 end;
7564
7565 class function TZlistx.Wrap(handle: PZlistx; owned: Boolean): IZlistx;
7566 begin
7567 if handle <> nil then Result := TZlistx.Create(handle, owned) else Result := nil;
7568 end;
7569
7570 class function TZlistx.UnWrap(const value: IZlistx): PZlistx;
7571 begin
7572 if value <> nil then Result := TZlistx(value).FHandle else Result := nil;
7573 end;
7574
7575 destructor TZlistx.Destroy;
7576 begin
7577 if FOwned and (FHandle <> nil) then
7578 zlistx_destroy(FHandle);
7579 end;
7580
7581 class function TZlistx.HandleItem(Handle: Pointer): Pointer;
7582 begin
7583 Result := zlistx_handle_item(Handle);
7584 end;
7585
7586 class procedure TZlistx.Test(Verbose: Boolean);
7587 begin
7588 zlistx_test(Verbose);
7589 end;
7590
7591 function TZlistx.AddStart(Item: Pointer): Pointer;
7592 begin
7593 Result := zlistx_add_start(FHandle, Item);
7594 end;
7595
7596 function TZlistx.AddEnd(Item: Pointer): Pointer;
7597 begin
7598 Result := zlistx_add_end(FHandle, Item);
7599 end;
7600
7601 function TZlistx.Size: NativeUInt;
7602 begin
7603 Result := zlistx_size(FHandle);
7604 end;
7605
7606 function TZlistx.Head: Pointer;
7607 begin
7608 Result := zlistx_head(FHandle);
7609 end;
7610
7611 function TZlistx.Tail: Pointer;
7612 begin
7613 Result := zlistx_tail(FHandle);
7614 end;
7615
7616 function TZlistx.First: Pointer;
7617 begin
7618 Result := zlistx_first(FHandle);
7619 end;
7620
7621 function TZlistx.Next: Pointer;
7622 begin
7623 Result := zlistx_next(FHandle);
7624 end;
7625
7626 function TZlistx.Prev: Pointer;
7627 begin
7628 Result := zlistx_prev(FHandle);
7629 end;
7630
7631 function TZlistx.Last: Pointer;
7632 begin
7633 Result := zlistx_last(FHandle);
7634 end;
7635
7636 function TZlistx.Item: Pointer;
7637 begin
7638 Result := zlistx_item(FHandle);
7639 end;
7640
7641 function TZlistx.Cursor: Pointer;
7642 begin
7643 Result := zlistx_cursor(FHandle);
7644 end;
7645
7646 function TZlistx.Find(Item: Pointer): Pointer;
7647 begin
7648 Result := zlistx_find(FHandle, Item);
7649 end;
7650
7651 function TZlistx.Detach(Handle: Pointer): Pointer;
7652 begin
7653 Result := zlistx_detach(FHandle, Handle);
7654 end;
7655
7656 function TZlistx.DetachCur: Pointer;
7657 begin
7658 Result := zlistx_detach_cur(FHandle);
7659 end;
7660
7661 function TZlistx.Delete(Handle: Pointer): Integer;
7662 begin
7663 Result := zlistx_delete(FHandle, Handle);
7664 end;
7665
7666 procedure TZlistx.MoveStart(Handle: Pointer);
7667 begin
7668 zlistx_move_start(FHandle, Handle);
7669 end;
7670
7671 procedure TZlistx.MoveEnd(Handle: Pointer);
7672 begin
7673 zlistx_move_end(FHandle, Handle);
7674 end;
7675
7676 procedure TZlistx.Purge;
7677 begin
7678 zlistx_purge(FHandle);
7679 end;
7680
7681 procedure TZlistx.Sort;
7682 begin
7683 zlistx_sort(FHandle);
7684 end;
7685
7686 function TZlistx.Insert(Item: Pointer; LowValue: Boolean): Pointer;
7687 begin
7688 Result := zlistx_insert(FHandle, Item, LowValue);
7689 end;
7690
7691 procedure TZlistx.Reorder(Handle: Pointer; LowValue: Boolean);
7692 begin
7693 zlistx_reorder(FHandle, Handle, LowValue);
7694 end;
7695
7696 function TZlistx.Dup: IZlistx;
7697 begin
7698 Result := TZlistx.Wrap(zlistx_dup(FHandle), false);
7699 end;
7700
7701 procedure TZlistx.SetDestructor(&Destructor: TZlistxDestructorFn);
7702 begin
7703 zlistx_set_destructor(FHandle, &Destructor);
7704 end;
7705
7706 procedure TZlistx.SetDuplicator(Duplicator: TZlistxDuplicatorFn);
7707 begin
7708 zlistx_set_duplicator(FHandle, Duplicator);
7709 end;
7710
7711 procedure TZlistx.SetComparator(Comparator: TZlistxComparatorFn);
7712 begin
7713 zlistx_set_comparator(FHandle, Comparator);
7714 end;
7715
7716 function TZlistx.Pack: IZframe;
7717 begin
7718 Result := TZframe.Wrap(zlistx_pack(FHandle), true);
7719 end;
7720
7721 (* TZloop *)
7722
7723 constructor TZloop.New;
7724 begin
7725 Create(zloop_new, True);
7726 end;
7727
7728 constructor TZloop.Create(handle: PZloop; owned: Boolean);
7729 begin
7730 FHandle := handle;
7731 FOwned := owned;
7732 end;
7733
7734 class function TZloop.Wrap(handle: PZloop; owned: Boolean): IZloop;
7735 begin
7736 if handle <> nil then Result := TZloop.Create(handle, owned) else Result := nil;
7737 end;
7738
7739 class function TZloop.UnWrap(const value: IZloop): PZloop;
7740 begin
7741 if value <> nil then Result := TZloop(value).FHandle else Result := nil;
7742 end;
7743
7744 destructor TZloop.Destroy;
7745 begin
7746 if FOwned and (FHandle <> nil) then
7747 zloop_destroy(FHandle);
7748 end;
7749
7750 class procedure TZloop.Test(Verbose: Boolean);
7751 begin
7752 zloop_test(Verbose);
7753 end;
7754
7755 function TZloop.Reader(const Sock: IZsock; Handler: TZloopReaderFn; Arg: Pointer): Integer;
7756 begin
7757 Result := zloop_reader(FHandle, TZsock.UnWrap(Sock), Handler, Arg);
7758 end;
7759
7760 procedure TZloop.ReaderEnd(const Sock: IZsock);
7761 begin
7762 zloop_reader_end(FHandle, TZsock.UnWrap(Sock));
7763 end;
7764
7765 procedure TZloop.ReaderSetTolerant(const Sock: IZsock);
7766 begin
7767 zloop_reader_set_tolerant(FHandle, TZsock.UnWrap(Sock));
7768 end;
7769
7770 function TZloop.Poller(Item: Pointer; Handler: TZloopFn; Arg: Pointer): Integer;
7771 begin
7772 Result := zloop_poller(FHandle, Item, Handler, Arg);
7773 end;
7774
7775 procedure TZloop.PollerEnd(Item: Pointer);
7776 begin
7777 zloop_poller_end(FHandle, Item);
7778 end;
7779
7780 procedure TZloop.PollerSetTolerant(Item: Pointer);
7781 begin
7782 zloop_poller_set_tolerant(FHandle, Item);
7783 end;
7784
7785 function TZloop.Timer(Delay: NativeUInt; Times: NativeUInt; Handler: TZloopTimerFn; Arg: Pointer): Integer;
7786 begin
7787 Result := zloop_timer(FHandle, Delay, Times, Handler, Arg);
7788 end;
7789
7790 function TZloop.TimerEnd(TimerId: Integer): Integer;
7791 begin
7792 Result := zloop_timer_end(FHandle, TimerId);
7793 end;
7794
7795 function TZloop.Ticket(Handler: TZloopTimerFn; Arg: Pointer): Pointer;
7796 begin
7797 Result := zloop_ticket(FHandle, Handler, Arg);
7798 end;
7799
7800 procedure TZloop.TicketReset(Handle: Pointer);
7801 begin
7802 zloop_ticket_reset(FHandle, Handle);
7803 end;
7804
7805 procedure TZloop.TicketDelete(Handle: Pointer);
7806 begin
7807 zloop_ticket_delete(FHandle, Handle);
7808 end;
7809
7810 procedure TZloop.SetTicketDelay(TicketDelay: NativeUInt);
7811 begin
7812 zloop_set_ticket_delay(FHandle, TicketDelay);
7813 end;
7814
7815 procedure TZloop.SetMaxTimers(MaxTimers: NativeUInt);
7816 begin
7817 zloop_set_max_timers(FHandle, MaxTimers);
7818 end;
7819
7820 procedure TZloop.SetVerbose(Verbose: Boolean);
7821 begin
7822 zloop_set_verbose(FHandle, Verbose);
7823 end;
7824
7825 procedure TZloop.SetNonstop(Nonstop: Boolean);
7826 begin
7827 zloop_set_nonstop(FHandle, Nonstop);
7828 end;
7829
7830 function TZloop.Start: Integer;
7831 begin
7832 Result := zloop_start(FHandle);
7833 end;
7834
7835 (* TZmsg *)
7836
7837 constructor TZmsg.New;
7838 begin
7839 Create(zmsg_new, True);
7840 end;
7841
7842 constructor TZmsg.Recv(const Source: IZSock);
7843 begin
7844 Create(zmsg_recv(TZsock.UnWrap(Source)), True);
7845 end;
7846
7847 constructor TZmsg.Load(&File: Pointer);
7848 begin
7849 Create(zmsg_load(&File), True);
7850 end;
7851
7852 constructor TZmsg.Decode(const Frame: IZframe);
7853 begin
7854 Create(zmsg_decode(TZframe.UnWrap(Frame)), True);
7855 end;
7856
7857 constructor TZmsg.NewSignal(Status: Byte);
7858 begin
7859 Create(zmsg_new_signal(Status), True);
7860 end;
7861
7862 constructor TZmsg.Create(handle: PZmsg; owned: Boolean);
7863 begin
7864 FHandle := handle;
7865 FOwned := owned;
7866 end;
7867
7868 class function TZmsg.Wrap(handle: PZmsg; owned: Boolean): IZmsg;
7869 begin
7870 if handle <> nil then Result := TZmsg.Create(handle, owned) else Result := nil;
7871 end;
7872
7873 class function TZmsg.UnWrap(const value: IZmsg): PZmsg;
7874 begin
7875 if value <> nil then Result := TZmsg(value).FHandle else Result := nil;
7876 end;
7877
7878 destructor TZmsg.Destroy;
7879 begin
7880 if FOwned and (FHandle <> nil) then
7881 zmsg_destroy(FHandle);
7882 end;
7883
7884 class function TZmsg.Send(var SelfP: IZmsg; const Dest: IZSock): Integer;
7885 begin
7886 Result := zmsg_send(TZmsg(SelfP).FHandle, TZsock.UnWrap(Dest));
7887 if TZmsg(SelfP).FHandle = nil then
7888 SelfP := nil;
7889 end;
7890
7891 class function TZmsg.Sendm(var SelfP: IZmsg; const Dest: IZSock): Integer;
7892 begin
7893 Result := zmsg_sendm(TZmsg(SelfP).FHandle, TZsock.UnWrap(Dest));
7894 if TZmsg(SelfP).FHandle = nil then
7895 SelfP := nil;
7896 end;
7897
7898 class function TZmsg.&Is(This: Pointer): Boolean;
7899 begin
7900 Result := zmsg_is(This);
7901 end;
7902
7903 class procedure TZmsg.Test(Verbose: Boolean);
7904 begin
7905 zmsg_test(Verbose);
7906 end;
7907
7908 function TZmsg.Size: NativeUInt;
7909 begin
7910 Result := zmsg_size(FHandle);
7911 end;
7912
7913 function TZmsg.ContentSize: NativeUInt;
7914 begin
7915 Result := zmsg_content_size(FHandle);
7916 end;
7917
7918 function TZmsg.RoutingId: Cardinal;
7919 begin
7920 Result := zmsg_routing_id(FHandle);
7921 end;
7922
7923 procedure TZmsg.SetRoutingId(RoutingId: Cardinal);
7924 begin
7925 zmsg_set_routing_id(FHandle, RoutingId);
7926 end;
7927
7928 function TZmsg.Prepend(var FrameP: IZframe): Integer;
7929 begin
7930 Result := zmsg_prepend(FHandle, TZframe(FrameP).FHandle);
7931 if TZframe(FrameP).FHandle = nil then
7932 FrameP := nil;
7933 end;
7934
7935 function TZmsg.Append(var FrameP: IZframe): Integer;
7936 begin
7937 Result := zmsg_append(FHandle, TZframe(FrameP).FHandle);
7938 if TZframe(FrameP).FHandle = nil then
7939 FrameP := nil;
7940 end;
7941
7942 function TZmsg.Pop: IZframe;
7943 begin
7944 Result := TZframe.Wrap(zmsg_pop(FHandle), true);
7945 end;
7946
7947 function TZmsg.Pushmem(Data: PByte; Size: NativeUInt): Integer;
7948 begin
7949 Result := zmsg_pushmem(FHandle, Data, Size);
7950 end;
7951
7952 function TZmsg.Addmem(Data: PByte; Size: NativeUInt): Integer;
7953 begin
7954 Result := zmsg_addmem(FHandle, Data, Size);
7955 end;
7956
7957 function TZmsg.Pushstr(const &String: string): Integer;
7958 var
7959 __String__: UTF8String;
7960 begin
7961 __String__ := UTF8String(&String);
7962 Result := zmsg_pushstr(FHandle, PAnsiChar(__String__));
7963 end;
7964
7965 function TZmsg.Addstr(const &String: string): Integer;
7966 var
7967 __String__: UTF8String;
7968 begin
7969 __String__ := UTF8String(&String);
7970 Result := zmsg_addstr(FHandle, PAnsiChar(__String__));
7971 end;
7972
7973 function TZmsg.Pushstrf(const Format: string): Integer;
7974 var
7975 __Format__: UTF8String;
7976 begin
7977 __Format__ := UTF8String(Format);
7978 Result := zmsg_pushstrf(FHandle, PAnsiChar(__Format__));
7979 end;
7980
7981 function TZmsg.Addstrf(const Format: string): Integer;
7982 var
7983 __Format__: UTF8String;
7984 begin
7985 __Format__ := UTF8String(Format);
7986 Result := zmsg_addstrf(FHandle, PAnsiChar(__Format__));
7987 end;
7988
7989 function TZmsg.Popstr: string;
7990 begin
7991 Result := ZFreeString(zmsg_popstr(FHandle));
7992 end;
7993
7994 function TZmsg.Addmsg(var MsgP: IZmsg): Integer;
7995 begin
7996 Result := zmsg_addmsg(FHandle, TZmsg(MsgP).FHandle);
7997 if TZmsg(MsgP).FHandle = nil then
7998 MsgP := nil;
7999 end;
8000
8001 function TZmsg.Popmsg: IZmsg;
8002 begin
8003 Result := TZmsg.Wrap(zmsg_popmsg(FHandle), true);
8004 end;
8005
8006 procedure TZmsg.Remove(const Frame: IZframe);
8007 begin
8008 zmsg_remove(FHandle, TZframe.UnWrap(Frame));
8009 end;
8010
8011 function TZmsg.First: IZframe;
8012 begin
8013 Result := TZframe.Wrap(zmsg_first(FHandle), false);
8014 end;
8015
8016 function TZmsg.Next: IZframe;
8017 begin
8018 Result := TZframe.Wrap(zmsg_next(FHandle), false);
8019 end;
8020
8021 function TZmsg.Last: IZframe;
8022 begin
8023 Result := TZframe.Wrap(zmsg_last(FHandle), false);
8024 end;
8025
8026 function TZmsg.Save(&File: Pointer): Integer;
8027 begin
8028 Result := zmsg_save(FHandle, &File);
8029 end;
8030
8031 function TZmsg.Encode: IZframe;
8032 begin
8033 Result := TZframe.Wrap(zmsg_encode(FHandle), true);
8034 end;
8035
8036 function TZmsg.Dup: IZmsg;
8037 begin
8038 Result := TZmsg.Wrap(zmsg_dup(FHandle), true);
8039 end;
8040
8041 procedure TZmsg.Print;
8042 begin
8043 zmsg_print(FHandle);
8044 end;
8045
8046 function TZmsg.Eq(const Other: IZmsg): Boolean;
8047 begin
8048 Result := zmsg_eq(FHandle, TZmsg.UnWrap(Other));
8049 end;
8050
8051 function TZmsg.Signal: Integer;
8052 begin
8053 Result := zmsg_signal(FHandle);
8054 end;
8055
8056 (* TZpoller *)
8057
8058 constructor TZpoller.New(const Reader: IZSock);
8059 begin
8060 Create(zpoller_new(TZsock.UnWrap(Reader)), True);
8061 end;
8062
8063 constructor TZpoller.Create(handle: PZpoller; owned: Boolean);
8064 begin
8065 FHandle := handle;
8066 FOwned := owned;
8067 end;
8068
8069 class function TZpoller.Wrap(handle: PZpoller; owned: Boolean): IZpoller;
8070 begin
8071 if handle <> nil then Result := TZpoller.Create(handle, owned) else Result := nil;
8072 end;
8073
8074 class function TZpoller.UnWrap(const value: IZpoller): PZpoller;
8075 begin
8076 if value <> nil then Result := TZpoller(value).FHandle else Result := nil;
8077 end;
8078
8079 destructor TZpoller.Destroy;
8080 begin
8081 if FOwned and (FHandle <> nil) then
8082 zpoller_destroy(FHandle);
8083 end;
8084
8085 class procedure TZpoller.Test(Verbose: Boolean);
8086 begin
8087 zpoller_test(Verbose);
8088 end;
8089
8090 function TZpoller.Add(const Reader: IZSock): Integer;
8091 begin
8092 Result := zpoller_add(FHandle, TZsock.UnWrap(Reader));
8093 end;
8094
8095 function TZpoller.Remove(Reader: Pointer): Integer;
8096 begin
8097 Result := zpoller_remove(FHandle, Reader);
8098 end;
8099
8100 procedure TZpoller.SetNonstop(Nonstop: Boolean);
8101 begin
8102 zpoller_set_nonstop(FHandle, Nonstop);
8103 end;
8104
8105 function TZpoller.Wait(Timeout: Integer): IZSock;
8106 begin
8107 Result := TZsock.Wrap(zpoller_wait(FHandle, Timeout), false);
8108 end;
8109
8110 function TZpoller.Expired: Boolean;
8111 begin
8112 Result := zpoller_expired(FHandle);
8113 end;
8114
8115 function TZpoller.Terminated: Boolean;
8116 begin
8117 Result := zpoller_terminated(FHandle);
8118 end;
8119
8120 (* TZsock *)
8121
8122 constructor TZsock.New(&Type: Integer);
8123 begin
8124 Create(zsock_new(&Type), True);
8125 end;
8126
8127 constructor TZsock.NewPub(const Endpoint: string);
8128 var
8129 __Endpoint__: UTF8String;
8130 begin
8131 __Endpoint__ := UTF8String(Endpoint);
8132 Create(zsock_new_pub(PAnsiChar(__Endpoint__)), True);
8133 end;
8134
8135 constructor TZsock.NewSub(const Endpoint: string; const Subscribe: string);
8136 var
8137 __Endpoint__: UTF8String;
8138 __Subscribe__: UTF8String;
8139 begin
8140 __Endpoint__ := UTF8String(Endpoint);
8141 __Subscribe__ := UTF8String(Subscribe);
8142 Create(zsock_new_sub(PAnsiChar(__Endpoint__), PAnsiChar(__Subscribe__)), True);
8143 end;
8144
8145 constructor TZsock.NewReq(const Endpoint: string);
8146 var
8147 __Endpoint__: UTF8String;
8148 begin
8149 __Endpoint__ := UTF8String(Endpoint);
8150 Create(zsock_new_req(PAnsiChar(__Endpoint__)), True);
8151 end;
8152
8153 constructor TZsock.NewRep(const Endpoint: string);
8154 var
8155 __Endpoint__: UTF8String;
8156 begin
8157 __Endpoint__ := UTF8String(Endpoint);
8158 Create(zsock_new_rep(PAnsiChar(__Endpoint__)), True);
8159 end;
8160
8161 constructor TZsock.NewDealer(const Endpoint: string);
8162 var
8163 __Endpoint__: UTF8String;
8164 begin
8165 __Endpoint__ := UTF8String(Endpoint);
8166 Create(zsock_new_dealer(PAnsiChar(__Endpoint__)), True);
8167 end;
8168
8169 constructor TZsock.NewRouter(const Endpoint: string);
8170 var
8171 __Endpoint__: UTF8String;
8172 begin
8173 __Endpoint__ := UTF8String(Endpoint);
8174 Create(zsock_new_router(PAnsiChar(__Endpoint__)), True);
8175 end;
8176
8177 constructor TZsock.NewPush(const Endpoint: string);
8178 var
8179 __Endpoint__: UTF8String;
8180 begin
8181 __Endpoint__ := UTF8String(Endpoint);
8182 Create(zsock_new_push(PAnsiChar(__Endpoint__)), True);
8183 end;
8184
8185 constructor TZsock.NewPull(const Endpoint: string);
8186 var
8187 __Endpoint__: UTF8String;
8188 begin
8189 __Endpoint__ := UTF8String(Endpoint);
8190 Create(zsock_new_pull(PAnsiChar(__Endpoint__)), True);
8191 end;
8192
8193 constructor TZsock.NewXpub(const Endpoint: string);
8194 var
8195 __Endpoint__: UTF8String;
8196 begin
8197 __Endpoint__ := UTF8String(Endpoint);
8198 Create(zsock_new_xpub(PAnsiChar(__Endpoint__)), True);
8199 end;
8200
8201 constructor TZsock.NewXsub(const Endpoint: string);
8202 var
8203 __Endpoint__: UTF8String;
8204 begin
8205 __Endpoint__ := UTF8String(Endpoint);
8206 Create(zsock_new_xsub(PAnsiChar(__Endpoint__)), True);
8207 end;
8208
8209 constructor TZsock.NewPair(const Endpoint: string);
8210 var
8211 __Endpoint__: UTF8String;
8212 begin
8213 __Endpoint__ := UTF8String(Endpoint);
8214 Create(zsock_new_pair(PAnsiChar(__Endpoint__)), True);
8215 end;
8216
8217 constructor TZsock.NewStream(const Endpoint: string);
8218 var
8219 __Endpoint__: UTF8String;
8220 begin
8221 __Endpoint__ := UTF8String(Endpoint);
8222 Create(zsock_new_stream(PAnsiChar(__Endpoint__)), True);
8223 end;
8224
8225 constructor TZsock.NewServer(const Endpoint: string);
8226 var
8227 __Endpoint__: UTF8String;
8228 begin
8229 __Endpoint__ := UTF8String(Endpoint);
8230 Create(zsock_new_server(PAnsiChar(__Endpoint__)), True);
8231 end;
8232
8233 constructor TZsock.NewClient(const Endpoint: string);
8234 var
8235 __Endpoint__: UTF8String;
8236 begin
8237 __Endpoint__ := UTF8String(Endpoint);
8238 Create(zsock_new_client(PAnsiChar(__Endpoint__)), True);
8239 end;
8240
8241 constructor TZsock.NewRadio(const Endpoint: string);
8242 var
8243 __Endpoint__: UTF8String;
8244 begin
8245 __Endpoint__ := UTF8String(Endpoint);
8246 Create(zsock_new_radio(PAnsiChar(__Endpoint__)), True);
8247 end;
8248
8249 constructor TZsock.NewDish(const Endpoint: string);
8250 var
8251 __Endpoint__: UTF8String;
8252 begin
8253 __Endpoint__ := UTF8String(Endpoint);
8254 Create(zsock_new_dish(PAnsiChar(__Endpoint__)), True);
8255 end;
8256
8257 constructor TZsock.NewGather(const Endpoint: string);
8258 var
8259 __Endpoint__: UTF8String;
8260 begin
8261 __Endpoint__ := UTF8String(Endpoint);
8262 Create(zsock_new_gather(PAnsiChar(__Endpoint__)), True);
8263 end;
8264
8265 constructor TZsock.NewScatter(const Endpoint: string);
8266 var
8267 __Endpoint__: UTF8String;
8268 begin
8269 __Endpoint__ := UTF8String(Endpoint);
8270 Create(zsock_new_scatter(PAnsiChar(__Endpoint__)), True);
8271 end;
8272
8273 constructor TZsock.Create(handle: PZsock; owned: Boolean);
8274 begin
8275 FHandle := handle;
8276 FOwned := owned;
8277 end;
8278
8279 class function TZsock.Wrap(handle: PZsock; owned: Boolean): IZsock;
8280 begin
8281 if handle <> nil then Result := TZsock.Create(handle, owned) else Result := nil;
8282 end;
8283
8284 class function TZsock.UnWrap(const value: IZsock): PZsock;
8285 begin
8286 if value <> nil then Result := TZsock(value).FHandle else Result := nil;
8287 end;
8288
8289 destructor TZsock.Destroy;
8290 begin
8291 if FOwned and (FHandle <> nil) then
8292 zsock_destroy(FHandle);
8293 end;
8294
8295 class function TZsock.&Is(This: Pointer): Boolean;
8296 begin
8297 Result := zsock_is(This);
8298 end;
8299
8300 class function TZsock.Resolve(This: Pointer): Pointer;
8301 begin
8302 Result := zsock_resolve(This);
8303 end;
8304
8305 class procedure TZsock.Test(Verbose: Boolean);
8306 begin
8307 zsock_test(Verbose);
8308 end;
8309
8310 function TZsock.Bind(const Format: string): Integer;
8311 var
8312 __Format__: UTF8String;
8313 begin
8314 __Format__ := UTF8String(Format);
8315 Result := zsock_bind(FHandle, PAnsiChar(__Format__));
8316 end;
8317
8318 function TZsock.Endpoint: string;
8319 begin
8320 Result := string(UTF8String(zsock_endpoint(FHandle)));
8321 end;
8322
8323 function TZsock.Unbind(const Format: string): Integer;
8324 var
8325 __Format__: UTF8String;
8326 begin
8327 __Format__ := UTF8String(Format);
8328 Result := zsock_unbind(FHandle, PAnsiChar(__Format__));
8329 end;
8330
8331 function TZsock.Connect(const Format: string): Integer;
8332 var
8333 __Format__: UTF8String;
8334 begin
8335 __Format__ := UTF8String(Format);
8336 Result := zsock_connect(FHandle, PAnsiChar(__Format__));
8337 end;
8338
8339 function TZsock.Disconnect(const Format: string): Integer;
8340 var
8341 __Format__: UTF8String;
8342 begin
8343 __Format__ := UTF8String(Format);
8344 Result := zsock_disconnect(FHandle, PAnsiChar(__Format__));
8345 end;
8346
8347 function TZsock.Attach(const Endpoints: string; Serverish: Boolean): Integer;
8348 var
8349 __Endpoints__: UTF8String;
8350 begin
8351 __Endpoints__ := UTF8String(Endpoints);
8352 Result := zsock_attach(FHandle, PAnsiChar(__Endpoints__), Serverish);
8353 end;
8354
8355 function TZsock.TypeStr: string;
8356 begin
8357 Result := string(UTF8String(zsock_type_str(FHandle)));
8358 end;
8359
8360 function TZsock.Send(const Picture: string): Integer;
8361 var
8362 __Picture__: UTF8String;
8363 begin
8364 __Picture__ := UTF8String(Picture);
8365 Result := zsock_send(FHandle, PAnsiChar(__Picture__));
8366 end;
8367
8368 function TZsock.Vsend(const Picture: string; Argptr: va_list): Integer;
8369 var
8370 __Picture__: UTF8String;
8371 begin
8372 __Picture__ := UTF8String(Picture);
8373 Result := zsock_vsend(FHandle, PAnsiChar(__Picture__), Argptr);
8374 end;
8375
8376 function TZsock.Recv(const Picture: string): Integer;
8377 var
8378 __Picture__: UTF8String;
8379 begin
8380 __Picture__ := UTF8String(Picture);
8381 Result := zsock_recv(FHandle, PAnsiChar(__Picture__));
8382 end;
8383
8384 function TZsock.Vrecv(const Picture: string; Argptr: va_list): Integer;
8385 var
8386 __Picture__: UTF8String;
8387 begin
8388 __Picture__ := UTF8String(Picture);
8389 Result := zsock_vrecv(FHandle, PAnsiChar(__Picture__), Argptr);
8390 end;
8391
8392 function TZsock.Bsend(const Picture: string): Integer;
8393 var
8394 __Picture__: UTF8String;
8395 begin
8396 __Picture__ := UTF8String(Picture);
8397 Result := zsock_bsend(FHandle, PAnsiChar(__Picture__));
8398 end;
8399
8400 function TZsock.Brecv(const Picture: string): Integer;
8401 var
8402 __Picture__: UTF8String;
8403 begin
8404 __Picture__ := UTF8String(Picture);
8405 Result := zsock_brecv(FHandle, PAnsiChar(__Picture__));
8406 end;
8407
8408 function TZsock.RoutingId: Cardinal;
8409 begin
8410 Result := zsock_routing_id(FHandle);
8411 end;
8412
8413 procedure TZsock.SetRoutingId(RoutingId: Cardinal);
8414 begin
8415 zsock_set_routing_id(FHandle, RoutingId);
8416 end;
8417
8418 procedure TZsock.SetUnbounded;
8419 begin
8420 zsock_set_unbounded(FHandle);
8421 end;
8422
8423 function TZsock.Signal(Status: Byte): Integer;
8424 begin
8425 Result := zsock_signal(FHandle, Status);
8426 end;
8427
8428 function TZsock.Wait: Integer;
8429 begin
8430 Result := zsock_wait(FHandle);
8431 end;
8432
8433 procedure TZsock.Flush;
8434 begin
8435 zsock_flush(FHandle);
8436 end;
8437
8438 function TZsock.Join(const Group: string): Integer;
8439 var
8440 __Group__: UTF8String;
8441 begin
8442 __Group__ := UTF8String(Group);
8443 Result := zsock_join(FHandle, PAnsiChar(__Group__));
8444 end;
8445
8446 function TZsock.Leave(const Group: string): Integer;
8447 var
8448 __Group__: UTF8String;
8449 begin
8450 __Group__ := UTF8String(Group);
8451 Result := zsock_leave(FHandle, PAnsiChar(__Group__));
8452 end;
8453
8454 function TZsock.HasIn: Boolean;
8455 begin
8456 Result := zsock_has_in(FHandle);
8457 end;
8458
8459 function TZsock.RouterNotify: Integer;
8460 begin
8461 Result := zsock_router_notify(FHandle);
8462 end;
8463
8464 procedure TZsock.SetRouterNotify(RouterNotify: Integer);
8465 begin
8466 zsock_set_router_notify(FHandle, RouterNotify);
8467 end;
8468
8469 function TZsock.MulticastLoop: Integer;
8470 begin
8471 Result := zsock_multicast_loop(FHandle);
8472 end;
8473
8474 procedure TZsock.SetMulticastLoop(MulticastLoop: Integer);
8475 begin
8476 zsock_set_multicast_loop(FHandle, MulticastLoop);
8477 end;
8478
8479 function TZsock.Metadata: string;
8480 begin
8481 Result := ZFreeString(zsock_metadata(FHandle));
8482 end;
8483
8484 procedure TZsock.SetMetadata(const Metadata: string);
8485 var
8486 __Metadata__: UTF8String;
8487 begin
8488 __Metadata__ := UTF8String(Metadata);
8489 zsock_set_metadata(FHandle, PAnsiChar(__Metadata__));
8490 end;
8491
8492 function TZsock.LoopbackFastpath: Integer;
8493 begin
8494 Result := zsock_loopback_fastpath(FHandle);
8495 end;
8496
8497 procedure TZsock.SetLoopbackFastpath(LoopbackFastpath: Integer);
8498 begin
8499 zsock_set_loopback_fastpath(FHandle, LoopbackFastpath);
8500 end;
8501
8502 function TZsock.ZapEnforceDomain: Integer;
8503 begin
8504 Result := zsock_zap_enforce_domain(FHandle);
8505 end;
8506
8507 procedure TZsock.SetZapEnforceDomain(ZapEnforceDomain: Integer);
8508 begin
8509 zsock_set_zap_enforce_domain(FHandle, ZapEnforceDomain);
8510 end;
8511
8512 function TZsock.GssapiPrincipalNametype: Integer;
8513 begin
8514 Result := zsock_gssapi_principal_nametype(FHandle);
8515 end;
8516
8517 procedure TZsock.SetGssapiPrincipalNametype(GssapiPrincipalNametype: Integer);
8518 begin
8519 zsock_set_gssapi_principal_nametype(FHandle, GssapiPrincipalNametype);
8520 end;
8521
8522 function TZsock.GssapiServicePrincipalNametype: Integer;
8523 begin
8524 Result := zsock_gssapi_service_principal_nametype(FHandle);
8525 end;
8526
8527 procedure TZsock.SetGssapiServicePrincipalNametype(GssapiServicePrincipalNametype: Integer);
8528 begin
8529 zsock_set_gssapi_service_principal_nametype(FHandle, GssapiServicePrincipalNametype);
8530 end;
8531
8532 function TZsock.Bindtodevice: string;
8533 begin
8534 Result := ZFreeString(zsock_bindtodevice(FHandle));
8535 end;
8536
8537 procedure TZsock.SetBindtodevice(const Bindtodevice: string);
8538 var
8539 __Bindtodevice__: UTF8String;
8540 begin
8541 __Bindtodevice__ := UTF8String(Bindtodevice);
8542 zsock_set_bindtodevice(FHandle, PAnsiChar(__Bindtodevice__));
8543 end;
8544
8545 function TZsock.HeartbeatIvl: Integer;
8546 begin
8547 Result := zsock_heartbeat_ivl(FHandle);
8548 end;
8549
8550 procedure TZsock.SetHeartbeatIvl(HeartbeatIvl: Integer);
8551 begin
8552 zsock_set_heartbeat_ivl(FHandle, HeartbeatIvl);
8553 end;
8554
8555 function TZsock.HeartbeatTtl: Integer;
8556 begin
8557 Result := zsock_heartbeat_ttl(FHandle);
8558 end;
8559
8560 procedure TZsock.SetHeartbeatTtl(HeartbeatTtl: Integer);
8561 begin
8562 zsock_set_heartbeat_ttl(FHandle, HeartbeatTtl);
8563 end;
8564
8565 function TZsock.HeartbeatTimeout: Integer;
8566 begin
8567 Result := zsock_heartbeat_timeout(FHandle);
8568 end;
8569
8570 procedure TZsock.SetHeartbeatTimeout(HeartbeatTimeout: Integer);
8571 begin
8572 zsock_set_heartbeat_timeout(FHandle, HeartbeatTimeout);
8573 end;
8574
8575 function TZsock.UseFd: Integer;
8576 begin
8577 Result := zsock_use_fd(FHandle);
8578 end;
8579
8580 procedure TZsock.SetUseFd(UseFd: Integer);
8581 begin
8582 zsock_set_use_fd(FHandle, UseFd);
8583 end;
8584
8585 procedure TZsock.SetXpubManual(XpubManual: Integer);
8586 begin
8587 zsock_set_xpub_manual(FHandle, XpubManual);
8588 end;
8589
8590 procedure TZsock.SetXpubWelcomeMsg(const XpubWelcomeMsg: string);
8591 var
8592 __XpubWelcomeMsg__: UTF8String;
8593 begin
8594 __XpubWelcomeMsg__ := UTF8String(XpubWelcomeMsg);
8595 zsock_set_xpub_welcome_msg(FHandle, PAnsiChar(__XpubWelcomeMsg__));
8596 end;
8597
8598 procedure TZsock.SetStreamNotify(StreamNotify: Integer);
8599 begin
8600 zsock_set_stream_notify(FHandle, StreamNotify);
8601 end;
8602
8603 function TZsock.InvertMatching: Integer;
8604 begin
8605 Result := zsock_invert_matching(FHandle);
8606 end;
8607
8608 procedure TZsock.SetInvertMatching(InvertMatching: Integer);
8609 begin
8610 zsock_set_invert_matching(FHandle, InvertMatching);
8611 end;
8612
8613 procedure TZsock.SetXpubVerboser(XpubVerboser: Integer);
8614 begin
8615 zsock_set_xpub_verboser(FHandle, XpubVerboser);
8616 end;
8617
8618 function TZsock.ConnectTimeout: Integer;
8619 begin
8620 Result := zsock_connect_timeout(FHandle);
8621 end;
8622
8623 procedure TZsock.SetConnectTimeout(ConnectTimeout: Integer);
8624 begin
8625 zsock_set_connect_timeout(FHandle, ConnectTimeout);
8626 end;
8627
8628 function TZsock.TcpMaxrt: Integer;
8629 begin
8630 Result := zsock_tcp_maxrt(FHandle);
8631 end;
8632
8633 procedure TZsock.SetTcpMaxrt(TcpMaxrt: Integer);
8634 begin
8635 zsock_set_tcp_maxrt(FHandle, TcpMaxrt);
8636 end;
8637
8638 function TZsock.ThreadSafe: Integer;
8639 begin
8640 Result := zsock_thread_safe(FHandle);
8641 end;
8642
8643 function TZsock.MulticastMaxtpdu: Integer;
8644 begin
8645 Result := zsock_multicast_maxtpdu(FHandle);
8646 end;
8647
8648 procedure TZsock.SetMulticastMaxtpdu(MulticastMaxtpdu: Integer);
8649 begin
8650 zsock_set_multicast_maxtpdu(FHandle, MulticastMaxtpdu);
8651 end;
8652
8653 function TZsock.VmciBufferSize: Integer;
8654 begin
8655 Result := zsock_vmci_buffer_size(FHandle);
8656 end;
8657
8658 procedure TZsock.SetVmciBufferSize(VmciBufferSize: Integer);
8659 begin
8660 zsock_set_vmci_buffer_size(FHandle, VmciBufferSize);
8661 end;
8662
8663 function TZsock.VmciBufferMinSize: Integer;
8664 begin
8665 Result := zsock_vmci_buffer_min_size(FHandle);
8666 end;
8667
8668 procedure TZsock.SetVmciBufferMinSize(VmciBufferMinSize: Integer);
8669 begin
8670 zsock_set_vmci_buffer_min_size(FHandle, VmciBufferMinSize);
8671 end;
8672
8673 function TZsock.VmciBufferMaxSize: Integer;
8674 begin
8675 Result := zsock_vmci_buffer_max_size(FHandle);
8676 end;
8677
8678 procedure TZsock.SetVmciBufferMaxSize(VmciBufferMaxSize: Integer);
8679 begin
8680 zsock_set_vmci_buffer_max_size(FHandle, VmciBufferMaxSize);
8681 end;
8682
8683 function TZsock.VmciConnectTimeout: Integer;
8684 begin
8685 Result := zsock_vmci_connect_timeout(FHandle);
8686 end;
8687
8688 procedure TZsock.SetVmciConnectTimeout(VmciConnectTimeout: Integer);
8689 begin
8690 zsock_set_vmci_connect_timeout(FHandle, VmciConnectTimeout);
8691 end;
8692
8693 function TZsock.Tos: Integer;
8694 begin
8695 Result := zsock_tos(FHandle);
8696 end;
8697
8698 procedure TZsock.SetTos(Tos: Integer);
8699 begin
8700 zsock_set_tos(FHandle, Tos);
8701 end;
8702
8703 procedure TZsock.SetRouterHandover(RouterHandover: Integer);
8704 begin
8705 zsock_set_router_handover(FHandle, RouterHandover);
8706 end;
8707
8708 procedure TZsock.SetConnectRid(const ConnectRid: string);
8709 var
8710 __ConnectRid__: UTF8String;
8711 begin
8712 __ConnectRid__ := UTF8String(ConnectRid);
8713 zsock_set_connect_rid(FHandle, PAnsiChar(__ConnectRid__));
8714 end;
8715
8716 procedure TZsock.SetConnectRidBin(ConnectRid: PByte);
8717 begin
8718 zsock_set_connect_rid_bin(FHandle, ConnectRid);
8719 end;
8720
8721 function TZsock.HandshakeIvl: Integer;
8722 begin
8723 Result := zsock_handshake_ivl(FHandle);
8724 end;
8725
8726 procedure TZsock.SetHandshakeIvl(HandshakeIvl: Integer);
8727 begin
8728 zsock_set_handshake_ivl(FHandle, HandshakeIvl);
8729 end;
8730
8731 function TZsock.SocksProxy: string;
8732 begin
8733 Result := ZFreeString(zsock_socks_proxy(FHandle));
8734 end;
8735
8736 procedure TZsock.SetSocksProxy(const SocksProxy: string);
8737 var
8738 __SocksProxy__: UTF8String;
8739 begin
8740 __SocksProxy__ := UTF8String(SocksProxy);
8741 zsock_set_socks_proxy(FHandle, PAnsiChar(__SocksProxy__));
8742 end;
8743
8744 procedure TZsock.SetXpubNodrop(XpubNodrop: Integer);
8745 begin
8746 zsock_set_xpub_nodrop(FHandle, XpubNodrop);
8747 end;
8748
8749 procedure TZsock.SetRouterMandatory(RouterMandatory: Integer);
8750 begin
8751 zsock_set_router_mandatory(FHandle, RouterMandatory);
8752 end;
8753
8754 procedure TZsock.SetProbeRouter(ProbeRouter: Integer);
8755 begin
8756 zsock_set_probe_router(FHandle, ProbeRouter);
8757 end;
8758
8759 procedure TZsock.SetReqRelaxed(ReqRelaxed: Integer);
8760 begin
8761 zsock_set_req_relaxed(FHandle, ReqRelaxed);
8762 end;
8763
8764 procedure TZsock.SetReqCorrelate(ReqCorrelate: Integer);
8765 begin
8766 zsock_set_req_correlate(FHandle, ReqCorrelate);
8767 end;
8768
8769 procedure TZsock.SetConflate(Conflate: Integer);
8770 begin
8771 zsock_set_conflate(FHandle, Conflate);
8772 end;
8773
8774 function TZsock.ZapDomain: string;
8775 begin
8776 Result := ZFreeString(zsock_zap_domain(FHandle));
8777 end;
8778
8779 procedure TZsock.SetZapDomain(const ZapDomain: string);
8780 var
8781 __ZapDomain__: UTF8String;
8782 begin
8783 __ZapDomain__ := UTF8String(ZapDomain);
8784 zsock_set_zap_domain(FHandle, PAnsiChar(__ZapDomain__));
8785 end;
8786
8787 function TZsock.Mechanism: Integer;
8788 begin
8789 Result := zsock_mechanism(FHandle);
8790 end;
8791
8792 function TZsock.PlainServer: Integer;
8793 begin
8794 Result := zsock_plain_server(FHandle);
8795 end;
8796
8797 procedure TZsock.SetPlainServer(PlainServer: Integer);
8798 begin
8799 zsock_set_plain_server(FHandle, PlainServer);
8800 end;
8801
8802 function TZsock.PlainUsername: string;
8803 begin
8804 Result := ZFreeString(zsock_plain_username(FHandle));
8805 end;
8806
8807 procedure TZsock.SetPlainUsername(const PlainUsername: string);
8808 var
8809 __PlainUsername__: UTF8String;
8810 begin
8811 __PlainUsername__ := UTF8String(PlainUsername);
8812 zsock_set_plain_username(FHandle, PAnsiChar(__PlainUsername__));
8813 end;
8814
8815 function TZsock.PlainPassword: string;
8816 begin
8817 Result := ZFreeString(zsock_plain_password(FHandle));
8818 end;
8819
8820 procedure TZsock.SetPlainPassword(const PlainPassword: string);
8821 var
8822 __PlainPassword__: UTF8String;
8823 begin
8824 __PlainPassword__ := UTF8String(PlainPassword);
8825 zsock_set_plain_password(FHandle, PAnsiChar(__PlainPassword__));
8826 end;
8827
8828 function TZsock.CurveServer: Integer;
8829 begin
8830 Result := zsock_curve_server(FHandle);
8831 end;
8832
8833 procedure TZsock.SetCurveServer(CurveServer: Integer);
8834 begin
8835 zsock_set_curve_server(FHandle, CurveServer);
8836 end;
8837
8838 function TZsock.CurvePublickey: string;
8839 begin
8840 Result := ZFreeString(zsock_curve_publickey(FHandle));
8841 end;
8842
8843 procedure TZsock.SetCurvePublickey(const CurvePublickey: string);
8844 var
8845 __CurvePublickey__: UTF8String;
8846 begin
8847 __CurvePublickey__ := UTF8String(CurvePublickey);
8848 zsock_set_curve_publickey(FHandle, PAnsiChar(__CurvePublickey__));
8849 end;
8850
8851 procedure TZsock.SetCurvePublickeyBin(CurvePublickey: PByte);
8852 begin
8853 zsock_set_curve_publickey_bin(FHandle, CurvePublickey);
8854 end;
8855
8856 function TZsock.CurveSecretkey: string;
8857 begin
8858 Result := ZFreeString(zsock_curve_secretkey(FHandle));
8859 end;
8860
8861 procedure TZsock.SetCurveSecretkey(const CurveSecretkey: string);
8862 var
8863 __CurveSecretkey__: UTF8String;
8864 begin
8865 __CurveSecretkey__ := UTF8String(CurveSecretkey);
8866 zsock_set_curve_secretkey(FHandle, PAnsiChar(__CurveSecretkey__));
8867 end;
8868
8869 procedure TZsock.SetCurveSecretkeyBin(CurveSecretkey: PByte);
8870 begin
8871 zsock_set_curve_secretkey_bin(FHandle, CurveSecretkey);
8872 end;
8873
8874 function TZsock.CurveServerkey: string;
8875 begin
8876 Result := ZFreeString(zsock_curve_serverkey(FHandle));
8877 end;
8878
8879 procedure TZsock.SetCurveServerkey(const CurveServerkey: string);
8880 var
8881 __CurveServerkey__: UTF8String;
8882 begin
8883 __CurveServerkey__ := UTF8String(CurveServerkey);
8884 zsock_set_curve_serverkey(FHandle, PAnsiChar(__CurveServerkey__));
8885 end;
8886
8887 procedure TZsock.SetCurveServerkeyBin(CurveServerkey: PByte);
8888 begin
8889 zsock_set_curve_serverkey_bin(FHandle, CurveServerkey);
8890 end;
8891
8892 function TZsock.GssapiServer: Integer;
8893 begin
8894 Result := zsock_gssapi_server(FHandle);
8895 end;
8896
8897 procedure TZsock.SetGssapiServer(GssapiServer: Integer);
8898 begin
8899 zsock_set_gssapi_server(FHandle, GssapiServer);
8900 end;
8901
8902 function TZsock.GssapiPlaintext: Integer;
8903 begin
8904 Result := zsock_gssapi_plaintext(FHandle);
8905 end;
8906
8907 procedure TZsock.SetGssapiPlaintext(GssapiPlaintext: Integer);
8908 begin
8909 zsock_set_gssapi_plaintext(FHandle, GssapiPlaintext);
8910 end;
8911
8912 function TZsock.GssapiPrincipal: string;
8913 begin
8914 Result := ZFreeString(zsock_gssapi_principal(FHandle));
8915 end;
8916
8917 procedure TZsock.SetGssapiPrincipal(const GssapiPrincipal: string);
8918 var
8919 __GssapiPrincipal__: UTF8String;
8920 begin
8921 __GssapiPrincipal__ := UTF8String(GssapiPrincipal);
8922 zsock_set_gssapi_principal(FHandle, PAnsiChar(__GssapiPrincipal__));
8923 end;
8924
8925 function TZsock.GssapiServicePrincipal: string;
8926 begin
8927 Result := ZFreeString(zsock_gssapi_service_principal(FHandle));
8928 end;
8929
8930 procedure TZsock.SetGssapiServicePrincipal(const GssapiServicePrincipal: string);
8931 var
8932 __GssapiServicePrincipal__: UTF8String;
8933 begin
8934 __GssapiServicePrincipal__ := UTF8String(GssapiServicePrincipal);
8935 zsock_set_gssapi_service_principal(FHandle, PAnsiChar(__GssapiServicePrincipal__));
8936 end;
8937
8938 function TZsock.Ipv6: Integer;
8939 begin
8940 Result := zsock_ipv6(FHandle);
8941 end;
8942
8943 procedure TZsock.SetIpv6(Ipv6: Integer);
8944 begin
8945 zsock_set_ipv6(FHandle, Ipv6);
8946 end;
8947
8948 function TZsock.Immediate: Integer;
8949 begin
8950 Result := zsock_immediate(FHandle);
8951 end;
8952
8953 procedure TZsock.SetImmediate(Immediate: Integer);
8954 begin
8955 zsock_set_immediate(FHandle, Immediate);
8956 end;
8957
8958 function TZsock.Sndhwm: Integer;
8959 begin
8960 Result := zsock_sndhwm(FHandle);
8961 end;
8962
8963 procedure TZsock.SetSndhwm(Sndhwm: Integer);
8964 begin
8965 zsock_set_sndhwm(FHandle, Sndhwm);
8966 end;
8967
8968 function TZsock.Rcvhwm: Integer;
8969 begin
8970 Result := zsock_rcvhwm(FHandle);
8971 end;
8972
8973 procedure TZsock.SetRcvhwm(Rcvhwm: Integer);
8974 begin
8975 zsock_set_rcvhwm(FHandle, Rcvhwm);
8976 end;
8977
8978 function TZsock.Maxmsgsize: Integer;
8979 begin
8980 Result := zsock_maxmsgsize(FHandle);
8981 end;
8982
8983 procedure TZsock.SetMaxmsgsize(Maxmsgsize: Integer);
8984 begin
8985 zsock_set_maxmsgsize(FHandle, Maxmsgsize);
8986 end;
8987
8988 function TZsock.MulticastHops: Integer;
8989 begin
8990 Result := zsock_multicast_hops(FHandle);
8991 end;
8992
8993 procedure TZsock.SetMulticastHops(MulticastHops: Integer);
8994 begin
8995 zsock_set_multicast_hops(FHandle, MulticastHops);
8996 end;
8997
8998 procedure TZsock.SetXpubVerbose(XpubVerbose: Integer);
8999 begin
9000 zsock_set_xpub_verbose(FHandle, XpubVerbose);
9001 end;
9002
9003 function TZsock.TcpKeepalive: Integer;
9004 begin
9005 Result := zsock_tcp_keepalive(FHandle);
9006 end;
9007
9008 procedure TZsock.SetTcpKeepalive(TcpKeepalive: Integer);
9009 begin
9010 zsock_set_tcp_keepalive(FHandle, TcpKeepalive);
9011 end;
9012
9013 function TZsock.TcpKeepaliveIdle: Integer;
9014 begin
9015 Result := zsock_tcp_keepalive_idle(FHandle);
9016 end;
9017
9018 procedure TZsock.SetTcpKeepaliveIdle(TcpKeepaliveIdle: Integer);
9019 begin
9020 zsock_set_tcp_keepalive_idle(FHandle, TcpKeepaliveIdle);
9021 end;
9022
9023 function TZsock.TcpKeepaliveCnt: Integer;
9024 begin
9025 Result := zsock_tcp_keepalive_cnt(FHandle);
9026 end;
9027
9028 procedure TZsock.SetTcpKeepaliveCnt(TcpKeepaliveCnt: Integer);
9029 begin
9030 zsock_set_tcp_keepalive_cnt(FHandle, TcpKeepaliveCnt);
9031 end;
9032
9033 function TZsock.TcpKeepaliveIntvl: Integer;
9034 begin
9035 Result := zsock_tcp_keepalive_intvl(FHandle);
9036 end;
9037
9038 procedure TZsock.SetTcpKeepaliveIntvl(TcpKeepaliveIntvl: Integer);
9039 begin
9040 zsock_set_tcp_keepalive_intvl(FHandle, TcpKeepaliveIntvl);
9041 end;
9042
9043 function TZsock.TcpAcceptFilter: string;
9044 begin
9045 Result := ZFreeString(zsock_tcp_accept_filter(FHandle));
9046 end;
9047
9048 procedure TZsock.SetTcpAcceptFilter(const TcpAcceptFilter: string);
9049 var
9050 __TcpAcceptFilter__: UTF8String;
9051 begin
9052 __TcpAcceptFilter__ := UTF8String(TcpAcceptFilter);
9053 zsock_set_tcp_accept_filter(FHandle, PAnsiChar(__TcpAcceptFilter__));
9054 end;
9055
9056 function TZsock.LastEndpoint: string;
9057 begin
9058 Result := ZFreeString(zsock_last_endpoint(FHandle));
9059 end;
9060
9061 procedure TZsock.SetRouterRaw(RouterRaw: Integer);
9062 begin
9063 zsock_set_router_raw(FHandle, RouterRaw);
9064 end;
9065
9066 function TZsock.Ipv4only: Integer;
9067 begin
9068 Result := zsock_ipv4only(FHandle);
9069 end;
9070
9071 procedure TZsock.SetIpv4only(Ipv4only: Integer);
9072 begin
9073 zsock_set_ipv4only(FHandle, Ipv4only);
9074 end;
9075
9076 procedure TZsock.SetDelayAttachOnConnect(DelayAttachOnConnect: Integer);
9077 begin
9078 zsock_set_delay_attach_on_connect(FHandle, DelayAttachOnConnect);
9079 end;
9080
9081 function TZsock.Hwm: Integer;
9082 begin
9083 Result := zsock_hwm(FHandle);
9084 end;
9085
9086 procedure TZsock.SetHwm(Hwm: Integer);
9087 begin
9088 zsock_set_hwm(FHandle, Hwm);
9089 end;
9090
9091 function TZsock.Swap: Integer;
9092 begin
9093 Result := zsock_swap(FHandle);
9094 end;
9095
9096 procedure TZsock.SetSwap(Swap: Integer);
9097 begin
9098 zsock_set_swap(FHandle, Swap);
9099 end;
9100
9101 function TZsock.Affinity: Integer;
9102 begin
9103 Result := zsock_affinity(FHandle);
9104 end;
9105
9106 procedure TZsock.SetAffinity(Affinity: Integer);
9107 begin
9108 zsock_set_affinity(FHandle, Affinity);
9109 end;
9110
9111 function TZsock.Identity: string;
9112 begin
9113 Result := ZFreeString(zsock_identity(FHandle));
9114 end;
9115
9116 procedure TZsock.SetIdentity(const Identity: string);
9117 var
9118 __Identity__: UTF8String;
9119 begin
9120 __Identity__ := UTF8String(Identity);
9121 zsock_set_identity(FHandle, PAnsiChar(__Identity__));
9122 end;
9123
9124 function TZsock.Rate: Integer;
9125 begin
9126 Result := zsock_rate(FHandle);
9127 end;
9128
9129 procedure TZsock.SetRate(Rate: Integer);
9130 begin
9131 zsock_set_rate(FHandle, Rate);
9132 end;
9133
9134 function TZsock.RecoveryIvl: Integer;
9135 begin
9136 Result := zsock_recovery_ivl(FHandle);
9137 end;
9138
9139 procedure TZsock.SetRecoveryIvl(RecoveryIvl: Integer);
9140 begin
9141 zsock_set_recovery_ivl(FHandle, RecoveryIvl);
9142 end;
9143
9144 function TZsock.RecoveryIvlMsec: Integer;
9145 begin
9146 Result := zsock_recovery_ivl_msec(FHandle);
9147 end;
9148
9149 procedure TZsock.SetRecoveryIvlMsec(RecoveryIvlMsec: Integer);
9150 begin
9151 zsock_set_recovery_ivl_msec(FHandle, RecoveryIvlMsec);
9152 end;
9153
9154 function TZsock.McastLoop: Integer;
9155 begin
9156 Result := zsock_mcast_loop(FHandle);
9157 end;
9158
9159 procedure TZsock.SetMcastLoop(McastLoop: Integer);
9160 begin
9161 zsock_set_mcast_loop(FHandle, McastLoop);
9162 end;
9163
9164 function TZsock.Rcvtimeo: Integer;
9165 begin
9166 Result := zsock_rcvtimeo(FHandle);
9167 end;
9168
9169 procedure TZsock.SetRcvtimeo(Rcvtimeo: Integer);
9170 begin
9171 zsock_set_rcvtimeo(FHandle, Rcvtimeo);
9172 end;
9173
9174 function TZsock.Sndtimeo: Integer;
9175 begin
9176 Result := zsock_sndtimeo(FHandle);
9177 end;
9178
9179 procedure TZsock.SetSndtimeo(Sndtimeo: Integer);
9180 begin
9181 zsock_set_sndtimeo(FHandle, Sndtimeo);
9182 end;
9183
9184 function TZsock.Sndbuf: Integer;
9185 begin
9186 Result := zsock_sndbuf(FHandle);
9187 end;
9188
9189 procedure TZsock.SetSndbuf(Sndbuf: Integer);
9190 begin
9191 zsock_set_sndbuf(FHandle, Sndbuf);
9192 end;
9193
9194 function TZsock.Rcvbuf: Integer;
9195 begin
9196 Result := zsock_rcvbuf(FHandle);
9197 end;
9198
9199 procedure TZsock.SetRcvbuf(Rcvbuf: Integer);
9200 begin
9201 zsock_set_rcvbuf(FHandle, Rcvbuf);
9202 end;
9203
9204 function TZsock.Linger: Integer;
9205 begin
9206 Result := zsock_linger(FHandle);
9207 end;
9208
9209 procedure TZsock.SetLinger(Linger: Integer);
9210 begin
9211 zsock_set_linger(FHandle, Linger);
9212 end;
9213
9214 function TZsock.ReconnectIvl: Integer;
9215 begin
9216 Result := zsock_reconnect_ivl(FHandle);
9217 end;
9218
9219 procedure TZsock.SetReconnectIvl(ReconnectIvl: Integer);
9220 begin
9221 zsock_set_reconnect_ivl(FHandle, ReconnectIvl);
9222 end;
9223
9224 function TZsock.ReconnectIvlMax: Integer;
9225 begin
9226 Result := zsock_reconnect_ivl_max(FHandle);
9227 end;
9228
9229 procedure TZsock.SetReconnectIvlMax(ReconnectIvlMax: Integer);
9230 begin
9231 zsock_set_reconnect_ivl_max(FHandle, ReconnectIvlMax);
9232 end;
9233
9234 function TZsock.Backlog: Integer;
9235 begin
9236 Result := zsock_backlog(FHandle);
9237 end;
9238
9239 procedure TZsock.SetBacklog(Backlog: Integer);
9240 begin
9241 zsock_set_backlog(FHandle, Backlog);
9242 end;
9243
9244 procedure TZsock.SetSubscribe(const Subscribe: string);
9245 var
9246 __Subscribe__: UTF8String;
9247 begin
9248 __Subscribe__ := UTF8String(Subscribe);
9249 zsock_set_subscribe(FHandle, PAnsiChar(__Subscribe__));
9250 end;
9251
9252 procedure TZsock.SetUnsubscribe(const Unsubscribe: string);
9253 var
9254 __Unsubscribe__: UTF8String;
9255 begin
9256 __Unsubscribe__ := UTF8String(Unsubscribe);
9257 zsock_set_unsubscribe(FHandle, PAnsiChar(__Unsubscribe__));
9258 end;
9259
9260 function TZsock.&Type: Integer;
9261 begin
9262 Result := zsock_type(FHandle);
9263 end;
9264
9265 function TZsock.Rcvmore: Integer;
9266 begin
9267 Result := zsock_rcvmore(FHandle);
9268 end;
9269
9270 function TZsock.Fd: TSocket;
9271 begin
9272 Result := zsock_fd(FHandle);
9273 end;
9274
9275 function TZsock.Events: Integer;
9276 begin
9277 Result := zsock_events(FHandle);
9278 end;
9279
9280 (* TZstr *)
9281
9282 class function TZstr.Recv(const Source: IZSock): string;
9283 begin
9284 Result := ZFreeString(zstr_recv(TZsock.UnWrap(Source)));
9285 end;
9286
9287 class function TZstr.RecvCompress(const Source: IZSock): string;
9288 begin
9289 Result := ZFreeString(zstr_recv_compress(TZsock.UnWrap(Source)));
9290 end;
9291
9292 class function TZstr.Send(const Dest: IZSock; const &String: string): Integer;
9293 var
9294 __String__: UTF8String;
9295 begin
9296 __String__ := UTF8String(&String);
9297 Result := zstr_send(TZsock.UnWrap(Dest), PAnsiChar(__String__));
9298 end;
9299
9300 class function TZstr.Sendm(const Dest: IZSock; const &String: string): Integer;
9301 var
9302 __String__: UTF8String;
9303 begin
9304 __String__ := UTF8String(&String);
9305 Result := zstr_sendm(TZsock.UnWrap(Dest), PAnsiChar(__String__));
9306 end;
9307
9308 class function TZstr.Sendf(const Dest: IZSock; const Format: string): Integer;
9309 var
9310 __Format__: UTF8String;
9311 begin
9312 __Format__ := UTF8String(Format);
9313 Result := zstr_sendf(TZsock.UnWrap(Dest), PAnsiChar(__Format__));
9314 end;
9315
9316 class function TZstr.Sendfm(const Dest: IZSock; const Format: string): Integer;
9317 var
9318 __Format__: UTF8String;
9319 begin
9320 __Format__ := UTF8String(Format);
9321 Result := zstr_sendfm(TZsock.UnWrap(Dest), PAnsiChar(__Format__));
9322 end;
9323
9324 class function TZstr.Sendx(const Dest: IZSock; const &String: string): Integer;
9325 var
9326 __String__: UTF8String;
9327 begin
9328 __String__ := UTF8String(&String);
9329 Result := zstr_sendx(TZsock.UnWrap(Dest), PAnsiChar(__String__));
9330 end;
9331
9332 class function TZstr.SendCompress(const Dest: IZSock; const &String: string): Integer;
9333 var
9334 __String__: UTF8String;
9335 begin
9336 __String__ := UTF8String(&String);
9337 Result := zstr_send_compress(TZsock.UnWrap(Dest), PAnsiChar(__String__));
9338 end;
9339
9340 class function TZstr.SendmCompress(const Dest: IZSock; const &String: string): Integer;
9341 var
9342 __String__: UTF8String;
9343 begin
9344 __String__ := UTF8String(&String);
9345 Result := zstr_sendm_compress(TZsock.UnWrap(Dest), PAnsiChar(__String__));
9346 end;
9347
9348 class function TZstr.Str(const Source: IZSock): string;
9349 begin
9350 Result := ZFreeString(zstr_str(TZsock.UnWrap(Source)));
9351 end;
9352
9353 class procedure TZstr.Test(Verbose: Boolean);
9354 begin
9355 zstr_test(Verbose);
9356 end;
9357
9358 (* TZsys *)
9359
9360 class function TZsys.Init: Pointer;
9361 begin
9362 Result := zsys_init;
9363 end;
9364
9365 class procedure TZsys.Shutdown;
9366 begin
9367 zsys_shutdown;
9368 end;
9369
9370 class function TZsys.Socket(&Type: Integer; const Filename: string; LineNbr: NativeUInt): Pointer;
9371 var
9372 __Filename__: UTF8String;
9373 begin
9374 __Filename__ := UTF8String(Filename);
9375 Result := zsys_socket(&Type, PAnsiChar(__Filename__), LineNbr);
9376 end;
9377
9378 class function TZsys.Close(Handle: Pointer; const Filename: string; LineNbr: NativeUInt): Integer;
9379 var
9380 __Filename__: UTF8String;
9381 begin
9382 __Filename__ := UTF8String(Filename);
9383 Result := zsys_close(Handle, PAnsiChar(__Filename__), LineNbr);
9384 end;
9385
9386 class function TZsys.Sockname(Socktype: Integer): string;
9387 begin
9388 Result := string(UTF8String(zsys_sockname(Socktype)));
9389 end;
9390
9391 class function TZsys.CreatePipe(var BackendP: IZsock): IZsock;
9392 begin
9393 Result := TZsock.Wrap(zsys_create_pipe(TZsock(BackendP).FHandle), false);
9394 if TZsock(BackendP).FHandle = nil then
9395 BackendP := nil;
9396 end;
9397
9398 class procedure TZsys.HandlerSet(HandlerFn: PZsysHandlerFn);
9399 begin
9400 zsys_handler_set(HandlerFn);
9401 end;
9402
9403 class procedure TZsys.HandlerReset;
9404 begin
9405 zsys_handler_reset;
9406 end;
9407
9408 class procedure TZsys.CatchInterrupts;
9409 begin
9410 zsys_catch_interrupts;
9411 end;
9412
9413 class function TZsys.IsInterrupted: Boolean;
9414 begin
9415 Result := zsys_is_interrupted;
9416 end;
9417
9418 class procedure TZsys.SetInterrupted;
9419 begin
9420 zsys_set_interrupted;
9421 end;
9422
9423 class function TZsys.FileExists(const Filename: string): Boolean;
9424 var
9425 __Filename__: UTF8String;
9426 begin
9427 __Filename__ := UTF8String(Filename);
9428 Result := zsys_file_exists(PAnsiChar(__Filename__));
9429 end;
9430
9431 class function TZsys.FileModified(const Filename: string): Int64;
9432 var
9433 __Filename__: UTF8String;
9434 begin
9435 __Filename__ := UTF8String(Filename);
9436 Result := zsys_file_modified(PAnsiChar(__Filename__));
9437 end;
9438
9439 class function TZsys.FileMode(const Filename: string): Integer;
9440 var
9441 __Filename__: UTF8String;
9442 begin
9443 __Filename__ := UTF8String(Filename);
9444 Result := zsys_file_mode(PAnsiChar(__Filename__));
9445 end;
9446
9447 class function TZsys.FileDelete(const Filename: string): Integer;
9448 var
9449 __Filename__: UTF8String;
9450 begin
9451 __Filename__ := UTF8String(Filename);
9452 Result := zsys_file_delete(PAnsiChar(__Filename__));
9453 end;
9454
9455 class function TZsys.FileStable(const Filename: string): Boolean;
9456 var
9457 __Filename__: UTF8String;
9458 begin
9459 __Filename__ := UTF8String(Filename);
9460 Result := zsys_file_stable(PAnsiChar(__Filename__));
9461 end;
9462
9463 class function TZsys.DirCreate(const Pathname: string): Integer;
9464 var
9465 __Pathname__: UTF8String;
9466 begin
9467 __Pathname__ := UTF8String(Pathname);
9468 Result := zsys_dir_create(PAnsiChar(__Pathname__));
9469 end;
9470
9471 class function TZsys.DirDelete(const Pathname: string): Integer;
9472 var
9473 __Pathname__: UTF8String;
9474 begin
9475 __Pathname__ := UTF8String(Pathname);
9476 Result := zsys_dir_delete(PAnsiChar(__Pathname__));
9477 end;
9478
9479 class function TZsys.DirChange(const Pathname: string): Integer;
9480 var
9481 __Pathname__: UTF8String;
9482 begin
9483 __Pathname__ := UTF8String(Pathname);
9484 Result := zsys_dir_change(PAnsiChar(__Pathname__));
9485 end;
9486
9487 class procedure TZsys.FileModePrivate;
9488 begin
9489 zsys_file_mode_private;
9490 end;
9491
9492 class procedure TZsys.FileModeDefault;
9493 begin
9494 zsys_file_mode_default;
9495 end;
9496
9497 class procedure TZsys.Version(var Major: Integer; var Minor: Integer; var Patch: Integer);
9498 begin
9499 zsys_version(Major, Minor, Patch);
9500 end;
9501
9502 class function TZsys.SprintfHint(Hint: Integer; const Format: string): string;
9503 var
9504 __Format__: UTF8String;
9505 begin
9506 __Format__ := UTF8String(Format);
9507 Result := string(UTF8String(zsys_sprintf_hint(Hint, PAnsiChar(__Format__))));
9508 end;
9509
9510 class function TZsys.Sprintf(const Format: string): string;
9511 var
9512 __Format__: UTF8String;
9513 begin
9514 __Format__ := UTF8String(Format);
9515 Result := string(UTF8String(zsys_sprintf(PAnsiChar(__Format__))));
9516 end;
9517
9518 class function TZsys.Vprintf(const Format: string; Argptr: va_list): string;
9519 var
9520 __Format__: UTF8String;
9521 begin
9522 __Format__ := UTF8String(Format);
9523 Result := string(UTF8String(zsys_vprintf(PAnsiChar(__Format__), Argptr)));
9524 end;
9525
9526 class function TZsys.UdpNew(Routable: Boolean): TSocket;
9527 begin
9528 Result := zsys_udp_new(Routable);
9529 end;
9530
9531 class function TZsys.UdpClose(Handle: TSocket): Integer;
9532 begin
9533 Result := zsys_udp_close(Handle);
9534 end;
9535
9536 class function TZsys.UdpSend(Udpsock: TSocket; const Frame: IZframe; Address: Pointer; Addrlen: Integer): Integer;
9537 begin
9538 Result := zsys_udp_send(Udpsock, TZframe.UnWrap(Frame), Address, Addrlen);
9539 end;
9540
9541 class function TZsys.UdpRecv(Udpsock: TSocket; const Peername: string; Peerlen: Integer): IZframe;
9542 var
9543 __Peername__: UTF8String;
9544 begin
9545 __Peername__ := UTF8String(Peername);
9546 Result := TZframe.Wrap(zsys_udp_recv(Udpsock, PAnsiChar(__Peername__), Peerlen), false);
9547 end;
9548
9549 class procedure TZsys.SocketError(const Reason: string);
9550 var
9551 __Reason__: UTF8String;
9552 begin
9553 __Reason__ := UTF8String(Reason);
9554 zsys_socket_error(PAnsiChar(__Reason__));
9555 end;
9556
9557 class function TZsys.Hostname: string;
9558 begin
9559 Result := string(UTF8String(zsys_hostname));
9560 end;
9561
9562 class function TZsys.Daemonize(const Workdir: string): Integer;
9563 var
9564 __Workdir__: UTF8String;
9565 begin
9566 __Workdir__ := UTF8String(Workdir);
9567 Result := zsys_daemonize(PAnsiChar(__Workdir__));
9568 end;
9569
9570 class function TZsys.RunAs(const Lockfile: string; const Group: string; const User: string): Integer;
9571 var
9572 __Lockfile__: UTF8String;
9573 __Group__: UTF8String;
9574 __User__: UTF8String;
9575 begin
9576 __Lockfile__ := UTF8String(Lockfile);
9577 __Group__ := UTF8String(Group);
9578 __User__ := UTF8String(User);
9579 Result := zsys_run_as(PAnsiChar(__Lockfile__), PAnsiChar(__Group__), PAnsiChar(__User__));
9580 end;
9581
9582 class function TZsys.HasCurve: Boolean;
9583 begin
9584 Result := zsys_has_curve;
9585 end;
9586
9587 class procedure TZsys.SetIoThreads(IoThreads: NativeUInt);
9588 begin
9589 zsys_set_io_threads(IoThreads);
9590 end;
9591
9592 class procedure TZsys.SetThreadSchedPolicy(Policy: Integer);
9593 begin
9594 zsys_set_thread_sched_policy(Policy);
9595 end;
9596
9597 class procedure TZsys.SetThreadPriority(Priority: Integer);
9598 begin
9599 zsys_set_thread_priority(Priority);
9600 end;
9601
9602 class procedure TZsys.SetThreadNamePrefix(Prefix: Integer);
9603 begin
9604 zsys_set_thread_name_prefix(Prefix);
9605 end;
9606
9607 class function TZsys.ThreadNamePrefix: Integer;
9608 begin
9609 Result := zsys_thread_name_prefix;
9610 end;
9611
9612 class procedure TZsys.ThreadAffinityCpuAdd(Cpu: Integer);
9613 begin
9614 zsys_thread_affinity_cpu_add(Cpu);
9615 end;
9616
9617 class procedure TZsys.ThreadAffinityCpuRemove(Cpu: Integer);
9618 begin
9619 zsys_thread_affinity_cpu_remove(Cpu);
9620 end;
9621
9622 class procedure TZsys.SetMaxSockets(MaxSockets: NativeUInt);
9623 begin
9624 zsys_set_max_sockets(MaxSockets);
9625 end;
9626
9627 class function TZsys.SocketLimit: NativeUInt;
9628 begin
9629 Result := zsys_socket_limit;
9630 end;
9631
9632 class procedure TZsys.SetMaxMsgsz(MaxMsgsz: Integer);
9633 begin
9634 zsys_set_max_msgsz(MaxMsgsz);
9635 end;
9636
9637 class function TZsys.MaxMsgsz: Integer;
9638 begin
9639 Result := zsys_max_msgsz;
9640 end;
9641
9642 class procedure TZsys.SetZeroCopyRecv(ZeroCopy: Integer);
9643 begin
9644 zsys_set_zero_copy_recv(ZeroCopy);
9645 end;
9646
9647 class function TZsys.ZeroCopyRecv: Integer;
9648 begin
9649 Result := zsys_zero_copy_recv;
9650 end;
9651
9652 class procedure TZsys.SetFileStableAgeMsec(FileStableAgeMsec: Int64);
9653 begin
9654 zsys_set_file_stable_age_msec(FileStableAgeMsec);
9655 end;
9656
9657 class function TZsys.FileStableAgeMsec: Int64;
9658 begin
9659 Result := zsys_file_stable_age_msec;
9660 end;
9661
9662 class procedure TZsys.SetLinger(Linger: NativeUInt);
9663 begin
9664 zsys_set_linger(Linger);
9665 end;
9666
9667 class procedure TZsys.SetSndhwm(Sndhwm: NativeUInt);
9668 begin
9669 zsys_set_sndhwm(Sndhwm);
9670 end;
9671
9672 class procedure TZsys.SetRcvhwm(Rcvhwm: NativeUInt);
9673 begin
9674 zsys_set_rcvhwm(Rcvhwm);
9675 end;
9676
9677 class procedure TZsys.SetPipehwm(Pipehwm: NativeUInt);
9678 begin
9679 zsys_set_pipehwm(Pipehwm);
9680 end;
9681
9682 class function TZsys.Pipehwm: NativeUInt;
9683 begin
9684 Result := zsys_pipehwm;
9685 end;
9686
9687 class procedure TZsys.SetIpv6(Ipv6: Integer);
9688 begin
9689 zsys_set_ipv6(Ipv6);
9690 end;
9691
9692 class function TZsys.Ipv6: Integer;
9693 begin
9694 Result := zsys_ipv6;
9695 end;
9696
9697 class procedure TZsys.SetInterface(const Value: string);
9698 var
9699 __Value__: UTF8String;
9700 begin
9701 __Value__ := UTF8String(Value);
9702 zsys_set_interface(PAnsiChar(__Value__));
9703 end;
9704
9705 class function TZsys.&Interface: string;
9706 begin
9707 Result := string(UTF8String(zsys_interface));
9708 end;
9709
9710 class procedure TZsys.SetIpv6Address(const Value: string);
9711 var
9712 __Value__: UTF8String;
9713 begin
9714 __Value__ := UTF8String(Value);
9715 zsys_set_ipv6_address(PAnsiChar(__Value__));
9716 end;
9717
9718 class function TZsys.Ipv6Address: string;
9719 begin
9720 Result := string(UTF8String(zsys_ipv6_address));
9721 end;
9722
9723 class procedure TZsys.SetIpv6McastAddress(const Value: string);
9724 var
9725 __Value__: UTF8String;
9726 begin
9727 __Value__ := UTF8String(Value);
9728 zsys_set_ipv6_mcast_address(PAnsiChar(__Value__));
9729 end;
9730
9731 class function TZsys.Ipv6McastAddress: string;
9732 begin
9733 Result := string(UTF8String(zsys_ipv6_mcast_address));
9734 end;
9735
9736 class procedure TZsys.SetAutoUseFd(AutoUseFd: Integer);
9737 begin
9738 zsys_set_auto_use_fd(AutoUseFd);
9739 end;
9740
9741 class function TZsys.AutoUseFd: Integer;
9742 begin
9743 Result := zsys_auto_use_fd;
9744 end;
9745
9746 class function TZsys.Zprintf(const Format: string; const Args: IZhash): string;
9747 var
9748 __Format__: UTF8String;
9749 begin
9750 __Format__ := UTF8String(Format);
9751 Result := ZFreeString(zsys_zprintf(PAnsiChar(__Format__), TZhash.UnWrap(Args)));
9752 end;
9753
9754 class function TZsys.ZprintfError(const Format: string; const Args: IZhash): string;
9755 var
9756 __Format__: UTF8String;
9757 begin
9758 __Format__ := UTF8String(Format);
9759 Result := ZFreeString(zsys_zprintf_error(PAnsiChar(__Format__), TZhash.UnWrap(Args)));
9760 end;
9761
9762 class function TZsys.Zplprintf(const Format: string; const Args: IZconfig): string;
9763 var
9764 __Format__: UTF8String;
9765 begin
9766 __Format__ := UTF8String(Format);
9767 Result := ZFreeString(zsys_zplprintf(PAnsiChar(__Format__), TZconfig.UnWrap(Args)));
9768 end;
9769
9770 class function TZsys.ZplprintfError(const Format: string; const Args: IZconfig): string;
9771 var
9772 __Format__: UTF8String;
9773 begin
9774 __Format__ := UTF8String(Format);
9775 Result := ZFreeString(zsys_zplprintf_error(PAnsiChar(__Format__), TZconfig.UnWrap(Args)));
9776 end;
9777
9778 class procedure TZsys.SetLogident(const Value: string);
9779 var
9780 __Value__: UTF8String;
9781 begin
9782 __Value__ := UTF8String(Value);
9783 zsys_set_logident(PAnsiChar(__Value__));
9784 end;
9785
9786 class procedure TZsys.SetLogstream(Stream: Pointer);
9787 begin
9788 zsys_set_logstream(Stream);
9789 end;
9790
9791 class procedure TZsys.SetLogsender(const Endpoint: string);
9792 var
9793 __Endpoint__: UTF8String;
9794 begin
9795 __Endpoint__ := UTF8String(Endpoint);
9796 zsys_set_logsender(PAnsiChar(__Endpoint__));
9797 end;
9798
9799 class procedure TZsys.SetLogsystem(Logsystem: Boolean);
9800 begin
9801 zsys_set_logsystem(Logsystem);
9802 end;
9803
9804 class procedure TZsys.Error(const Format: string);
9805 var
9806 __Format__: UTF8String;
9807 begin
9808 __Format__ := UTF8String(Format);
9809 zsys_error(PAnsiChar(__Format__));
9810 end;
9811
9812 class procedure TZsys.Warning(const Format: string);
9813 var
9814 __Format__: UTF8String;
9815 begin
9816 __Format__ := UTF8String(Format);
9817 zsys_warning(PAnsiChar(__Format__));
9818 end;
9819
9820 class procedure TZsys.Notice(const Format: string);
9821 var
9822 __Format__: UTF8String;
9823 begin
9824 __Format__ := UTF8String(Format);
9825 zsys_notice(PAnsiChar(__Format__));
9826 end;
9827
9828 class procedure TZsys.Info(const Format: string);
9829 var
9830 __Format__: UTF8String;
9831 begin
9832 __Format__ := UTF8String(Format);
9833 zsys_info(PAnsiChar(__Format__));
9834 end;
9835
9836 class procedure TZsys.Debug(const Format: string);
9837 var
9838 __Format__: UTF8String;
9839 begin
9840 __Format__ := UTF8String(Format);
9841 zsys_debug(PAnsiChar(__Format__));
9842 end;
9843
9844 class procedure TZsys.Test(Verbose: Boolean);
9845 begin
9846 zsys_test(Verbose);
9847 end;
9848
9849 (* TZuuid *)
9850
9851 constructor TZuuid.New;
9852 begin
9853 Create(zuuid_new, True);
9854 end;
9855
9856 constructor TZuuid.NewFrom(Source: PByte);
9857 begin
9858 Create(zuuid_new_from(Source), True);
9859 end;
9860
9861 constructor TZuuid.Create(handle: PZuuid; owned: Boolean);
9862 begin
9863 FHandle := handle;
9864 FOwned := owned;
9865 end;
9866
9867 class function TZuuid.Wrap(handle: PZuuid; owned: Boolean): IZuuid;
9868 begin
9869 if handle <> nil then Result := TZuuid.Create(handle, owned) else Result := nil;
9870 end;
9871
9872 class function TZuuid.UnWrap(const value: IZuuid): PZuuid;
9873 begin
9874 if value <> nil then Result := TZuuid(value).FHandle else Result := nil;
9875 end;
9876
9877 destructor TZuuid.Destroy;
9878 begin
9879 if FOwned and (FHandle <> nil) then
9880 zuuid_destroy(FHandle);
9881 end;
9882
9883 class procedure TZuuid.Test(Verbose: Boolean);
9884 begin
9885 zuuid_test(Verbose);
9886 end;
9887
9888 procedure TZuuid.&Set(Source: PByte);
9889 begin
9890 zuuid_set(FHandle, Source);
9891 end;
9892
9893 function TZuuid.SetStr(const Source: string): Integer;
9894 var
9895 __Source__: UTF8String;
9896 begin
9897 __Source__ := UTF8String(Source);
9898 Result := zuuid_set_str(FHandle, PAnsiChar(__Source__));
9899 end;
9900
9901 function TZuuid.Data: PByte;
9902 begin
9903 Result := zuuid_data(FHandle);
9904 end;
9905
9906 function TZuuid.Size: NativeUInt;
9907 begin
9908 Result := zuuid_size(FHandle);
9909 end;
9910
9911 function TZuuid.Str: string;
9912 begin
9913 Result := string(UTF8String(zuuid_str(FHandle)));
9914 end;
9915
9916 function TZuuid.StrCanonical: string;
9917 begin
9918 Result := string(UTF8String(zuuid_str_canonical(FHandle)));
9919 end;
9920
9921 procedure TZuuid.Export(Target: PByte);
9922 begin
9923 zuuid_export(FHandle, Target);
9924 end;
9925
9926 function TZuuid.Eq(Compare: PByte): Boolean;
9927 begin
9928 Result := zuuid_eq(FHandle, Compare);
9929 end;
9930
9931 function TZuuid.Neq(Compare: PByte): Boolean;
9932 begin
9933 Result := zuuid_neq(FHandle, Compare);
9934 end;
9935
9936 function TZuuid.Dup: IZuuid;
9937 begin
9938 Result := TZuuid.Wrap(zuuid_dup(FHandle), false);
9939 end;
9940
9941 (* TZauth *)
9942
9943 class procedure TZauth.Test(Verbose: Boolean);
9944 begin
9945 zauth_test(Verbose);
9946 end;
9947
9948 (* TZbeacon *)
9949
9950 class procedure TZbeacon.Test(Verbose: Boolean);
9951 begin
9952 zbeacon_test(Verbose);
9953 end;
9954
9955 (* TZgossip *)
9956
9957 class procedure TZgossip.Test(Verbose: Boolean);
9958 begin
9959 zgossip_test(Verbose);
9960 end;
9961
9962 (* TZmonitor *)
9963
9964 class procedure TZmonitor.Test(Verbose: Boolean);
9965 begin
9966 zmonitor_test(Verbose);
9967 end;
9968
9969 (* TZproxy *)
9970
9971 class procedure TZproxy.Test(Verbose: Boolean);
9972 begin
9973 zproxy_test(Verbose);
9974 end;
9975
9976 (* TZrex *)
9977
9978 class procedure TZrex.Test(Verbose: Boolean);
9979 begin
9980 zrex_test(Verbose);
9981 end;
9982 end.
0 (*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5
6 The high-level C binding for 0MQ
7 *)
8
9 unit libczmq;
10
11 {$if defined(MSWINDOWS)}
12 {$warn SYMBOL_PLATFORM off}
13 {$ifend}
14
15 interface
16
17 uses
18 Winapi.Windows, Winapi.Winsock2;
19
20 const
21 CZMQ_VERSION_MAJOR = 4;
22 CZMQ_VERSION_MINOR = 2;
23 CZMQ_VERSION_PATCH = 0;
24
25 const
26 lib_czmq = 'libczmq.dll';
27
28 // Standard base 64
29 CZMQ_ZARMOUR_MODE_BASE64_STD = 0;
30 // URL and filename friendly base 64
31 CZMQ_ZARMOUR_MODE_BASE64_URL = 1;
32 // Standard base 32
33 CZMQ_ZARMOUR_MODE_BASE32_STD = 2;
34 // Extended hex base 32
35 CZMQ_ZARMOUR_MODE_BASE32_HEX = 3;
36 // Standard base 16
37 CZMQ_ZARMOUR_MODE_BASE16 = 4;
38 // Z85 from ZeroMQ RFC 32
39 CZMQ_ZARMOUR_MODE_Z85 = 5;
40
41 // Creates a new file
42 CZMQ_ZDIR_PATCH_CREATE = 1;
43 // Delete a file
44 CZMQ_ZDIR_PATCH_DELETE = 2;
45
46 //
47 CZMQ_ZFRAME_MORE = 1;
48 //
49 CZMQ_ZFRAME_REUSE = 2;
50 //
51 CZMQ_ZFRAME_DONTWAIT = 4;
52
53 type
54 PZactor = Pointer;
55 PZarmour = Pointer;
56 PZcert = Pointer;
57 PZcertstore = Pointer;
58 PZchunk = Pointer;
59 PZclock = Pointer;
60 PZconfig = Pointer;
61 PZdigest = Pointer;
62 PZdir = Pointer;
63 PZdirPatch = Pointer;
64 PZfile = Pointer;
65 PZframe = Pointer;
66 PZhash = Pointer;
67 PZhashx = Pointer;
68 PZiflist = Pointer;
69 PZlist = Pointer;
70 PZlistx = Pointer;
71 PZloop = Pointer;
72 PZmsg = Pointer;
73 PZpoller = Pointer;
74 PZsock = Pointer;
75 PZstr = Pointer;
76 PZsys = Pointer;
77 PZuuid = Pointer;
78 PZauth = Pointer;
79 PZbeacon = Pointer;
80 PZgossip = Pointer;
81 PZmonitor = Pointer;
82 PZproxy = Pointer;
83 PZrex = Pointer;
84
85 (* Zactor *)
86 (* provides a simple actor framework *)
87
88 type
89
90 // Actors get a pipe and arguments from caller
91 TZactorFn = procedure(Pipe: PZsock; Args: Pointer); stdcall;
92 PZactorFn = ^TZactorFn;
93
94 // Function to be called on zactor_destroy. Default behavior is to send zmsg_t with string "$TERM" in a first frame.
95 //
96 // An example - to send $KTHXBAI string
97 //
98 // if (zstr_send (self, "$KTHXBAI") == 0)
99 // zsock_wait (self);
100 TZactorDestructorFn = procedure(This: PZactor); stdcall;
101 PZactorDestructorFn = ^TZactorDestructorFn;
102
103 // Create a new actor passing arbitrary arguments reference.
104 function zactor_new(Task: TZactorFn; Args: Pointer): PZactor; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
105
106 // Destroy an actor.
107 procedure zactor_destroy(var self: PZactor); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
108
109 // Send a zmsg message to the actor, take ownership of the message
110 // and destroy when it has been sent.
111 function zactor_send(self: PZactor; var MsgP: PZmsg): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
112
113 // Receive a zmsg message from the actor. Returns NULL if the actor
114 // was interrupted before the message could be received, or if there
115 // was a timeout on the actor.
116 function zactor_recv(self: PZactor): PZmsg; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
117
118 // Probe the supplied object, and report if it looks like a zactor_t.
119 function zactor_is(This: Pointer): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
120
121 // Probe the supplied reference. If it looks like a zactor_t instance,
122 // return the underlying libzmq actor handle; else if it looks like
123 // a libzmq actor handle, return the supplied value.
124 function zactor_resolve(This: Pointer): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
125
126 // Return the actor's zsock handle. Use this when you absolutely need
127 // to work with the zsock instance rather than the actor.
128 function zactor_sock(self: PZactor): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
129
130 // Change default destructor by custom function. Actor MUST be able to handle new message instead of default $TERM.
131 procedure zactor_set_destructor(self: PZactor; &Destructor: TZactorDestructorFn); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
132
133 // Self test of this class.
134 procedure zactor_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
135
136 (* Zarmour *)
137 (* armoured text encoding and decoding *)
138
139 // Create a new zarmour
140 function zarmour_new: PZarmour; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
141
142 // Destroy the zarmour
143 procedure zarmour_destroy(var self: PZarmour); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
144
145 // Encode a stream of bytes into an armoured string. Returns the armoured
146 // string, or NULL if there was insufficient memory available to allocate
147 // a new string.
148 function zarmour_encode(self: PZarmour; Data: PByte; Size: NativeUInt): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
149
150 // Decode an armoured string into a chunk. The decoded output is
151 // null-terminated, so it may be treated as a string, if that's what
152 // it was prior to encoding.
153 function zarmour_decode(self: PZarmour; Data: PAnsiChar): PZchunk; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
154
155 // Get the mode property.
156 function zarmour_mode(self: PZarmour): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
157
158 // Get printable string for mode.
159 function zarmour_mode_str(self: PZarmour): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
160
161 // Set the mode property.
162 procedure zarmour_set_mode(self: PZarmour; Mode: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
163
164 // Return true if padding is turned on.
165 function zarmour_pad(self: PZarmour): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
166
167 // Turn padding on or off. Default is on.
168 procedure zarmour_set_pad(self: PZarmour; Pad: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
169
170 // Get the padding character.
171 function zarmour_pad_char(self: PZarmour): AnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
172
173 // Set the padding character.
174 procedure zarmour_set_pad_char(self: PZarmour; PadChar: AnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
175
176 // Return if splitting output into lines is turned on. Default is off.
177 function zarmour_line_breaks(self: PZarmour): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
178
179 // Turn splitting output into lines on or off.
180 procedure zarmour_set_line_breaks(self: PZarmour; LineBreaks: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
181
182 // Get the line length used for splitting lines.
183 function zarmour_line_length(self: PZarmour): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
184
185 // Set the line length used for splitting lines.
186 procedure zarmour_set_line_length(self: PZarmour; LineLength: NativeUInt); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
187
188 // Print properties of object
189 procedure zarmour_print(self: PZarmour); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
190
191 // Self test of this class.
192 procedure zarmour_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
193
194 (* Zcert *)
195 (* work with CURVE security certificates *)
196
197 // Create and initialize a new certificate in memory
198 function zcert_new: PZcert; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
199
200 // Accepts public/secret key pair from caller
201 function zcert_new_from(PublicKey: PByte; SecretKey: PByte): PZcert; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
202
203 // Accepts public/secret key text pair from caller
204 function zcert_new_from_txt(PublicTxt: PAnsiChar; SecretTxt: PAnsiChar): PZcert; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
205
206 // Load certificate from file
207 function zcert_load(Filename: PAnsiChar): PZcert; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
208
209 // Destroy a certificate in memory
210 procedure zcert_destroy(var self: PZcert); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
211
212 // Return public part of key pair as 32-byte binary string
213 function zcert_public_key(self: PZcert): PByte; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
214
215 // Return secret part of key pair as 32-byte binary string
216 function zcert_secret_key(self: PZcert): PByte; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
217
218 // Return public part of key pair as Z85 armored string
219 function zcert_public_txt(self: PZcert): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
220
221 // Return secret part of key pair as Z85 armored string
222 function zcert_secret_txt(self: PZcert): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
223
224 // Set certificate metadata from formatted string.
225 procedure zcert_set_meta(self: PZcert; Name: PAnsiChar; Format: PAnsiChar); cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
226
227 // Unset certificate metadata.
228 procedure zcert_unset_meta(self: PZcert; Name: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
229
230 // Get metadata value from certificate; if the metadata value doesn't
231 // exist, returns NULL.
232 function zcert_meta(self: PZcert; Name: PAnsiChar): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
233
234 // Get list of metadata fields from certificate. Caller is responsible for
235 // destroying list. Caller should not modify the values of list items.
236 function zcert_meta_keys(self: PZcert): PZlist; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
237
238 // Save full certificate (public + secret) to file for persistent storage
239 // This creates one public file and one secret file (filename + "_secret").
240 function zcert_save(self: PZcert; Filename: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
241
242 // Save public certificate only to file for persistent storage
243 function zcert_save_public(self: PZcert; Filename: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
244
245 // Save secret certificate only to file for persistent storage
246 function zcert_save_secret(self: PZcert; Filename: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
247
248 // Apply certificate to socket, i.e. use for CURVE security on socket.
249 // If certificate was loaded from public file, the secret key will be
250 // undefined, and this certificate will not work successfully.
251 procedure zcert_apply(self: PZcert; Socket: PZSock); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
252
253 // Return copy of certificate; if certificate is NULL or we exhausted
254 // heap memory, returns NULL.
255 function zcert_dup(self: PZcert): PZcert; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
256
257 // Return true if two certificates have the same keys
258 function zcert_eq(self: PZcert; Compare: PZcert): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
259
260 // Print certificate contents to stdout
261 procedure zcert_print(self: PZcert); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
262
263 // Self test of this class
264 procedure zcert_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
265
266 (* Zcertstore *)
267 (* work with CURVE security certificate stores *)
268
269 type
270
271 // Loaders retrieve certificates from an arbitrary source.
272 TZcertstoreLoader = procedure(This: PZcertstore); stdcall;
273 PZcertstoreLoader = ^TZcertstoreLoader;
274
275 // Destructor for loader state.
276 TZcertstoreDestructor = procedure(SelfP: PByte); stdcall;
277 PZcertstoreDestructor = ^TZcertstoreDestructor;
278
279 // Create a new certificate store from a disk directory, loading and
280 // indexing all certificates in that location. The directory itself may be
281 // absent, and created later, or modified at any time. The certificate store
282 // is automatically refreshed on any zcertstore_lookup() call. If the
283 // location is specified as NULL, creates a pure-memory store, which you
284 // can work with by inserting certificates at runtime.
285 function zcertstore_new(Location: PAnsiChar): PZcertstore; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
286
287 // Destroy a certificate store object in memory. Does not affect anything
288 // stored on disk.
289 procedure zcertstore_destroy(var self: PZcertstore); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
290
291 // Override the default disk loader with a custom loader fn.
292 procedure zcertstore_set_loader(self: PZcertstore; Loader: TZcertstoreLoader; &Destructor: TZcertstoreDestructor; State: PByte); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
293
294 // Look up certificate by public key, returns zcert_t object if found,
295 // else returns NULL. The public key is provided in Z85 text format.
296 function zcertstore_lookup(self: PZcertstore; PublicKey: PAnsiChar): PZcert; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
297
298 // Insert certificate into certificate store in memory. Note that this
299 // does not save the certificate to disk. To do that, use zcert_save()
300 // directly on the certificate. Takes ownership of zcert_t object.
301 procedure zcertstore_insert(self: PZcertstore; var CertP: PZcert); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
302
303 // Empty certificate hashtable. This wrapper exists to be friendly to bindings,
304 // which don't usually have access to struct internals.
305 procedure zcertstore_empty(self: PZcertstore); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
306
307 // Print list of certificates in store to logging facility
308 procedure zcertstore_print(self: PZcertstore); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
309
310 // Return a list of all the certificates in the store.
311 // The caller takes ownership of the zlistx_t object and is responsible
312 // for destroying it. The caller does not take ownership of the zcert_t
313 // objects.
314 function zcertstore_certs(self: PZcertstore): PZlistx; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
315
316 // Self test of this class
317 procedure zcertstore_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
318
319 (* Zchunk *)
320 (* work with memory chunks *)
321
322 type
323
324 // Destroy an item
325 TZchunkDestructorFn = procedure(var Hint: Pointer); stdcall;
326 PZchunkDestructorFn = ^TZchunkDestructorFn;
327
328 // Create a new chunk of the specified size. If you specify the data, it
329 // is copied into the chunk. If you do not specify the data, the chunk is
330 // allocated and left empty, and you can then add data using zchunk_append.
331 function zchunk_new(Data: PByte; Size: NativeUInt): PZchunk; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
332
333 // Create a new chunk from memory. Take ownership of the memory and calling the destructor
334 // on destroy.
335 function zchunk_frommem(Data: PByte; Size: NativeUInt; &Destructor: TZchunkDestructorFn; Hint: Pointer): PZchunk; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
336
337 // Destroy a chunk
338 procedure zchunk_destroy(var self: PZchunk); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
339
340 // Resizes chunk max_size as requested; chunk_cur size is set to zero
341 procedure zchunk_resize(self: PZchunk; Size: NativeUInt); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
342
343 // Return chunk cur size
344 function zchunk_size(self: PZchunk): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
345
346 // Return chunk max size
347 function zchunk_max_size(self: PZchunk): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
348
349 // Return chunk data
350 function zchunk_data(self: PZchunk): PByte; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
351
352 // Set chunk data from user-supplied data; truncate if too large. Data may
353 // be null. Returns actual size of chunk
354 function zchunk_set(self: PZchunk; Data: PByte; Size: NativeUInt): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
355
356 // Fill chunk data from user-supplied octet
357 function zchunk_fill(self: PZchunk; Filler: Byte; Size: NativeUInt): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
358
359 // Append user-supplied data to chunk, return resulting chunk size. If the
360 // data would exceeded the available space, it is truncated. If you want to
361 // grow the chunk to accommodate new data, use the zchunk_extend method.
362 function zchunk_append(self: PZchunk; Data: PByte; Size: NativeUInt): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
363
364 // Append user-supplied data to chunk, return resulting chunk size. If the
365 // data would exceeded the available space, the chunk grows in size.
366 function zchunk_extend(self: PZchunk; Data: PByte; Size: NativeUInt): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
367
368 // Copy as much data from 'source' into the chunk as possible; returns the
369 // new size of chunk. If all data from 'source' is used, returns exhausted
370 // on the source chunk. Source can be consumed as many times as needed until
371 // it is exhausted. If source was already exhausted, does not change chunk.
372 function zchunk_consume(self: PZchunk; Source: PZchunk): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
373
374 // Returns true if the chunk was exhausted by consume methods, or if the
375 // chunk has a size of zero.
376 function zchunk_exhausted(self: PZchunk): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
377
378 // Read chunk from an open file descriptor
379 function zchunk_read(Handle: Pointer; Bytes: NativeUInt): PZchunk; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
380
381 // Write chunk to an open file descriptor
382 function zchunk_write(self: PZchunk; Handle: Pointer): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
383
384 // Try to slurp an entire file into a chunk. Will read up to maxsize of
385 // the file. If maxsize is 0, will attempt to read the entire file and
386 // fail with an assertion if that cannot fit into memory. Returns a new
387 // chunk containing the file data, or NULL if the file could not be read.
388 function zchunk_slurp(Filename: PAnsiChar; Maxsize: NativeUInt): PZchunk; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
389
390 // Create copy of chunk, as new chunk object. Returns a fresh zchunk_t
391 // object, or null if there was not enough heap memory. If chunk is null,
392 // returns null.
393 function zchunk_dup(self: PZchunk): PZchunk; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
394
395 // Return chunk data encoded as printable hex string. Caller must free
396 // string when finished with it.
397 function zchunk_strhex(self: PZchunk): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
398
399 // Return chunk data copied into freshly allocated string
400 // Caller must free string when finished with it.
401 function zchunk_strdup(self: PZchunk): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
402
403 // Return TRUE if chunk body is equal to string, excluding terminator
404 function zchunk_streq(self: PZchunk; &String: PAnsiChar): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
405
406 // Transform zchunk into a zframe that can be sent in a message.
407 function zchunk_pack(self: PZchunk): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
408
409 // Transform zchunk into a zframe that can be sent in a message.
410 // Take ownership of the chunk.
411 function zchunk_packx(var SelfP: PZchunk): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
412
413 // Transform a zframe into a zchunk.
414 function zchunk_unpack(Frame: PZframe): PZchunk; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
415
416 // Calculate SHA1 digest for chunk, using zdigest class.
417 function zchunk_digest(self: PZchunk): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
418
419 // Dump chunk to FILE stream, for debugging and tracing.
420 procedure zchunk_fprint(self: PZchunk; &File: Pointer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
421
422 // Dump message to stderr, for debugging and tracing.
423 // See zchunk_fprint for details
424 procedure zchunk_print(self: PZchunk); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
425
426 // Probe the supplied object, and report if it looks like a zchunk_t.
427 function zchunk_is(This: Pointer): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
428
429 // Self test of this class.
430 procedure zchunk_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
431
432 (* Zclock *)
433 (* millisecond clocks and delays *)
434
435 // Sleep for a number of milliseconds
436 procedure zclock_sleep(Msecs: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
437
438 // Return current system clock as milliseconds. Note that this clock can
439 // jump backwards (if the system clock is changed) so is unsafe to use for
440 // timers and time offsets. Use zclock_mono for that instead.
441 function zclock_time: Int64; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
442
443 // Return current monotonic clock in milliseconds. Use this when you compute
444 // time offsets. The monotonic clock is not affected by system changes and
445 // so will never be reset backwards, unlike a system clock.
446 function zclock_mono: Int64; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
447
448 // Return current monotonic clock in microseconds. Use this when you compute
449 // time offsets. The monotonic clock is not affected by system changes and
450 // so will never be reset backwards, unlike a system clock.
451 function zclock_usecs: Int64; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
452
453 // Return formatted date/time as fresh string. Free using zstr_free().
454 function zclock_timestr: PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
455
456 // Self test of this class.
457 procedure zclock_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
458
459 (* Zconfig *)
460 (* work with config files written in rfc.zeromq.org/spec:4/ZPL. *)
461
462 type
463
464 //
465 TZconfigFct = function(This: PZconfig; Arg: Pointer; Level: Integer): Integer; stdcall;
466 PZconfigFct = ^TZconfigFct;
467
468 // Create new config item
469 function zconfig_new(Name: PAnsiChar; Parent: PZconfig): PZconfig; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
470
471 // Load a config tree from a specified ZPL text file; returns a zconfig_t
472 // reference for the root, if the file exists and is readable. Returns NULL
473 // if the file does not exist.
474 function zconfig_load(Filename: PAnsiChar): PZconfig; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
475
476 // Equivalent to zconfig_load, taking a format string instead of a fixed
477 // filename.
478 function zconfig_loadf(Format: PAnsiChar): PZconfig; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
479
480 // Destroy a config item and all its children
481 procedure zconfig_destroy(var self: PZconfig); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
482
483 // Create copy of zconfig, caller MUST free the value
484 // Create copy of config, as new zconfig object. Returns a fresh zconfig_t
485 // object. If config is null, or memory was exhausted, returns null.
486 function zconfig_dup(self: PZconfig): PZconfig; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
487
488 // Return name of config item
489 function zconfig_name(self: PZconfig): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
490
491 // Return value of config item
492 function zconfig_value(self: PZconfig): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
493
494 // Insert or update configuration key with value
495 procedure zconfig_put(self: PZconfig; Path: PAnsiChar; Value: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
496
497 // Equivalent to zconfig_put, accepting a format specifier and variable
498 // argument list, instead of a single string value.
499 procedure zconfig_putf(self: PZconfig; Path: PAnsiChar; Format: PAnsiChar); cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
500
501 // Get value for config item into a string value; leading slash is optional
502 // and ignored.
503 function zconfig_get(self: PZconfig; Path: PAnsiChar; DefaultValue: PAnsiChar): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
504
505 // Set config item name, name may be NULL
506 procedure zconfig_set_name(self: PZconfig; Name: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
507
508 // Set new value for config item. The new value may be a string, a printf
509 // format, or NULL. Note that if string may possibly contain '%', or if it
510 // comes from an insecure source, you must use '%s' as the format, followed
511 // by the string.
512 procedure zconfig_set_value(self: PZconfig; Format: PAnsiChar); cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
513
514 // Find our first child, if any
515 function zconfig_child(self: PZconfig): PZconfig; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
516
517 // Find our first sibling, if any
518 function zconfig_next(self: PZconfig): PZconfig; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
519
520 // Find a config item along a path; leading slash is optional and ignored.
521 function zconfig_locate(self: PZconfig; Path: PAnsiChar): PZconfig; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
522
523 // Locate the last config item at a specified depth
524 function zconfig_at_depth(self: PZconfig; Level: Integer): PZconfig; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
525
526 // Execute a callback for each config item in the tree; returns zero if
527 // successful, else -1.
528 function zconfig_execute(self: PZconfig; Handler: TZconfigFct; Arg: Pointer): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
529
530 // Add comment to config item before saving to disk. You can add as many
531 // comment lines as you like. If you use a null format, all comments are
532 // deleted.
533 procedure zconfig_set_comment(self: PZconfig; Format: PAnsiChar); cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
534
535 // Return comments of config item, as zlist.
536 function zconfig_comments(self: PZconfig): PZlist; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
537
538 // Save a config tree to a specified ZPL text file, where a filename
539 // "-" means dump to standard output.
540 function zconfig_save(self: PZconfig; Filename: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
541
542 // Equivalent to zconfig_save, taking a format string instead of a fixed
543 // filename.
544 function zconfig_savef(self: PZconfig; Format: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
545
546 // Report filename used during zconfig_load, or NULL if none
547 function zconfig_filename(self: PZconfig): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
548
549 // Reload config tree from same file that it was previously loaded from.
550 // Returns 0 if OK, -1 if there was an error (and then does not change
551 // existing data).
552 function zconfig_reload(var SelfP: PZconfig): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
553
554 // Load a config tree from a memory chunk
555 function zconfig_chunk_load(Chunk: PZchunk): PZconfig; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
556
557 // Save a config tree to a new memory chunk
558 function zconfig_chunk_save(self: PZconfig): PZchunk; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
559
560 // Load a config tree from a null-terminated string
561 function zconfig_str_load(&String: PAnsiChar): PZconfig; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
562
563 // Save a config tree to a new null terminated string
564 function zconfig_str_save(self: PZconfig): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
565
566 // Return true if a configuration tree was loaded from a file and that
567 // file has changed in since the tree was loaded.
568 function zconfig_has_changed(self: PZconfig): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
569
570 // Destroy subtree (all children)
571 procedure zconfig_remove_subtree(self: PZconfig); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
572
573 // Destroy node and subtree (all children)
574 procedure zconfig_remove(var SelfP: PZconfig); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
575
576 // Print the config file to open stream
577 procedure zconfig_fprint(self: PZconfig; &File: Pointer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
578
579 // Print properties of object
580 procedure zconfig_print(self: PZconfig); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
581
582 // Self test of this class
583 procedure zconfig_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
584
585 (* Zdigest *)
586 (* provides hashing functions (SHA-1 at present) *)
587
588 // Constructor - creates new digest object, which you use to build up a
589 // digest by repeatedly calling zdigest_update() on chunks of data.
590 function zdigest_new: PZdigest; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
591
592 // Destroy a digest object
593 procedure zdigest_destroy(var self: PZdigest); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
594
595 // Add buffer into digest calculation
596 procedure zdigest_update(self: PZdigest; Buffer: PByte; Length: NativeUInt); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
597
598 // Return final digest hash data. If built without crypto support,
599 // returns NULL.
600 function zdigest_data(self: PZdigest): PByte; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
601
602 // Return final digest hash size
603 function zdigest_size(self: PZdigest): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
604
605 // Return digest as printable hex string; caller should not modify nor
606 // free this string. After calling this, you may not use zdigest_update()
607 // on the same digest. If built without crypto support, returns NULL.
608 function zdigest_string(self: PZdigest): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
609
610 // Self test of this class.
611 procedure zdigest_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
612
613 (* Zdir *)
614 (* work with file-system directories *)
615
616 // Create a new directory item that loads in the full tree of the specified
617 // path, optionally located under some parent path. If parent is "-", then
618 // loads only the top-level directory, and does not use parent as a path.
619 function zdir_new(Path: PAnsiChar; Parent: PAnsiChar): PZdir; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
620
621 // Destroy a directory tree and all children it contains.
622 procedure zdir_destroy(var self: PZdir); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
623
624 // Return directory path
625 function zdir_path(self: PZdir): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
626
627 // Return last modification time for directory.
628 function zdir_modified(self: PZdir): Int64; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
629
630 // Return total hierarchy size, in bytes of data contained in all files
631 // in the directory tree.
632 function zdir_cursize(self: PZdir): Longint; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
633
634 // Return directory count
635 function zdir_count(self: PZdir): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
636
637 // Returns a sorted list of zfile objects; Each entry in the list is a pointer
638 // to a zfile_t item already allocated in the zdir tree. Do not destroy the
639 // original zdir tree until you are done with this list.
640 function zdir_list(self: PZdir): PZlist; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
641
642 // Remove directory, optionally including all files that it contains, at
643 // all levels. If force is false, will only remove the directory if empty.
644 // If force is true, will remove all files and all subdirectories.
645 procedure zdir_remove(self: PZdir; Force: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
646
647 // Calculate differences between two versions of a directory tree.
648 // Returns a list of zdir_patch_t patches. Either older or newer may
649 // be null, indicating the directory is empty/absent. If alias is set,
650 // generates virtual filename (minus path, plus alias).
651 function zdir_diff(Older: PZdir; Newer: PZdir; Alias: PAnsiChar): PZlist; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
652
653 // Return full contents of directory as a zdir_patch list.
654 function zdir_resync(self: PZdir; Alias: PAnsiChar): PZlist; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
655
656 // Load directory cache; returns a hash table containing the SHA-1 digests
657 // of every file in the tree. The cache is saved between runs in .cache.
658 function zdir_cache(self: PZdir): PZhash; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
659
660 // Print contents of directory to open stream
661 procedure zdir_fprint(self: PZdir; &File: Pointer; Indent: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
662
663 // Print contents of directory to stdout
664 procedure zdir_print(self: PZdir; Indent: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
665
666 // Create a new zdir_watch actor instance:
667 //
668 // zactor_t *watch = zactor_new (zdir_watch, NULL);
669 //
670 // Destroy zdir_watch instance:
671 //
672 // zactor_destroy (&watch);
673 //
674 // Enable verbose logging of commands and activity:
675 //
676 // zstr_send (watch, "VERBOSE");
677 //
678 // Subscribe to changes to a directory path:
679 //
680 // zsock_send (watch, "ss", "SUBSCRIBE", "directory_path");
681 //
682 // Unsubscribe from changes to a directory path:
683 //
684 // zsock_send (watch, "ss", "UNSUBSCRIBE", "directory_path");
685 //
686 // Receive directory changes:
687 // zsock_recv (watch, "sp", &path, &patches);
688 //
689 // // Delete the received data.
690 // free (path);
691 // zlist_destroy (&patches);
692 procedure zdir_watch(Pipe: PZsock; Unused: Pointer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
693
694 // Self test of this class.
695 procedure zdir_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
696
697 (* ZdirPatch *)
698 (* work with directory patches *)
699
700 // Create new patch
701 function zdir_patch_new(Path: PAnsiChar; &File: PZfile; Op: Integer; Alias: PAnsiChar): PZdirPatch; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
702
703 // Destroy a patch
704 procedure zdir_patch_destroy(var self: PZdirPatch); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
705
706 // Create copy of a patch. If the patch is null, or memory was exhausted,
707 // returns null.
708 function zdir_patch_dup(self: PZdirPatch): PZdirPatch; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
709
710 // Return patch file directory path
711 function zdir_patch_path(self: PZdirPatch): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
712
713 // Return patch file item
714 function zdir_patch_file(self: PZdirPatch): PZfile; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
715
716 // Return operation
717 function zdir_patch_op(self: PZdirPatch): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
718
719 // Return patch virtual file path
720 function zdir_patch_vpath(self: PZdirPatch): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
721
722 // Calculate hash digest for file (create only)
723 procedure zdir_patch_digest_set(self: PZdirPatch); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
724
725 // Return hash digest for patch file
726 function zdir_patch_digest(self: PZdirPatch): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
727
728 // Self test of this class.
729 procedure zdir_patch_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
730
731 (* Zfile *)
732 (* helper functions for working with files. *)
733
734 // If file exists, populates properties. CZMQ supports portable symbolic
735 // links, which are files with the extension ".ln". A symbolic link is a
736 // text file containing one line, the filename of a target file. Reading
737 // data from the symbolic link actually reads from the target file. Path
738 // may be NULL, in which case it is not used.
739 function zfile_new(Path: PAnsiChar; Name: PAnsiChar): PZfile; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
740
741 // Create new temporary file for writing via tmpfile. File is automatically
742 // deleted on destroy
743 function zfile_tmp: PZfile; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
744
745 // Destroy a file item
746 procedure zfile_destroy(var self: PZfile); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
747
748 // Duplicate a file item, returns a newly constructed item. If the file
749 // is null, or memory was exhausted, returns null.
750 function zfile_dup(self: PZfile): PZfile; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
751
752 // Return file name, remove path if provided
753 function zfile_filename(self: PZfile; Path: PAnsiChar): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
754
755 // Refresh file properties from disk; this is not done automatically
756 // on access methods, otherwise it is not possible to compare directory
757 // snapshots.
758 procedure zfile_restat(self: PZfile); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
759
760 // Return when the file was last modified. If you want this to reflect the
761 // current situation, call zfile_restat before checking this property.
762 function zfile_modified(self: PZfile): Int64; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
763
764 // Return the last-known size of the file. If you want this to reflect the
765 // current situation, call zfile_restat before checking this property.
766 function zfile_cursize(self: PZfile): Longint; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
767
768 // Return true if the file is a directory. If you want this to reflect
769 // any external changes, call zfile_restat before checking this property.
770 function zfile_is_directory(self: PZfile): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
771
772 // Return true if the file is a regular file. If you want this to reflect
773 // any external changes, call zfile_restat before checking this property.
774 function zfile_is_regular(self: PZfile): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
775
776 // Return true if the file is readable by this process. If you want this to
777 // reflect any external changes, call zfile_restat before checking this
778 // property.
779 function zfile_is_readable(self: PZfile): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
780
781 // Return true if the file is writeable by this process. If you want this
782 // to reflect any external changes, call zfile_restat before checking this
783 // property.
784 function zfile_is_writeable(self: PZfile): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
785
786 // Check if file has stopped changing and can be safely processed.
787 // Updates the file statistics from disk at every call.
788 function zfile_is_stable(self: PZfile): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
789
790 // Return true if the file was changed on disk since the zfile_t object
791 // was created, or the last zfile_restat() call made on it.
792 function zfile_has_changed(self: PZfile): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
793
794 // Remove the file from disk
795 procedure zfile_remove(self: PZfile); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
796
797 // Open file for reading
798 // Returns 0 if OK, -1 if not found or not accessible
799 function zfile_input(self: PZfile): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
800
801 // Open file for writing, creating directory if needed
802 // File is created if necessary; chunks can be written to file at any
803 // location. Returns 0 if OK, -1 if error.
804 function zfile_output(self: PZfile): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
805
806 // Read chunk from file at specified position. If this was the last chunk,
807 // sets the eof property. Returns a null chunk in case of error.
808 function zfile_read(self: PZfile; Bytes: NativeUInt; Offset: Longint): PZchunk; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
809
810 // Returns true if zfile_read() just read the last chunk in the file.
811 function zfile_eof(self: PZfile): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
812
813 // Write chunk to file at specified position
814 // Return 0 if OK, else -1
815 function zfile_write(self: PZfile; Chunk: PZchunk; Offset: Longint): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
816
817 // Read next line of text from file. Returns a pointer to the text line,
818 // or NULL if there was nothing more to read from the file.
819 function zfile_readln(self: PZfile): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
820
821 // Close file, if open
822 procedure zfile_close(self: PZfile); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
823
824 // Return file handle, if opened
825 function zfile_handle(self: PZfile): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
826
827 // Calculate SHA1 digest for file, using zdigest class.
828 function zfile_digest(self: PZfile): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
829
830 // Self test of this class.
831 procedure zfile_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
832
833 (* Zframe *)
834 (* working with single message frames *)
835
836 type
837
838 // Destroy an item
839 TZframeDestructorFn = procedure(var Hint: Pointer); stdcall;
840 PZframeDestructorFn = ^TZframeDestructorFn;
841
842 // Create a new frame. If size is not null, allocates the frame data
843 // to the specified size. If additionally, data is not null, copies
844 // size octets from the specified data into the frame body.
845 function zframe_new(Data: PByte; Size: NativeUInt): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
846
847 // Create an empty (zero-sized) frame
848 function zframe_new_empty: PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
849
850 // Create a frame with a specified string content.
851 function zframe_from(&String: PAnsiChar): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
852
853 // Create a new frame from memory. Take ownership of the memory and calling the destructor
854 // on destroy.
855 function zframe_frommem(Data: PByte; Size: NativeUInt; &Destructor: TZframeDestructorFn; Hint: Pointer): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
856
857 // Receive frame from socket, returns zframe_t object or NULL if the recv
858 // was interrupted. Does a blocking recv, if you want to not block then use
859 // zpoller or zloop.
860 function zframe_recv(Source: PZSock): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
861
862 // Destroy a frame
863 procedure zframe_destroy(var self: PZframe); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
864
865 // Send a frame to a socket, destroy frame after sending.
866 // Return -1 on error, 0 on success.
867 function zframe_send(var SelfP: PZframe; Dest: PZSock; Flags: Integer): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
868
869 // Return number of bytes in frame data
870 function zframe_size(self: PZframe): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
871
872 // Return address of frame data
873 function zframe_data(self: PZframe): PByte; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
874
875 // Return meta data property for frame
876 // The caller shall not modify or free the returned value, which shall be
877 // owned by the message.
878 function zframe_meta(self: PZframe; &Property: PAnsiChar): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
879
880 // Create a new frame that duplicates an existing frame. If frame is null,
881 // or memory was exhausted, returns null.
882 function zframe_dup(self: PZframe): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
883
884 // Return frame data encoded as printable hex string, useful for 0MQ UUIDs.
885 // Caller must free string when finished with it.
886 function zframe_strhex(self: PZframe): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
887
888 // Return frame data copied into freshly allocated string
889 // Caller must free string when finished with it.
890 function zframe_strdup(self: PZframe): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
891
892 // Return TRUE if frame body is equal to string, excluding terminator
893 function zframe_streq(self: PZframe; &String: PAnsiChar): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
894
895 // Return frame MORE indicator (1 or 0), set when reading frame from socket
896 // or by the zframe_set_more() method
897 function zframe_more(self: PZframe): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
898
899 // Set frame MORE indicator (1 or 0). Note this is NOT used when sending
900 // frame to socket, you have to specify flag explicitly.
901 procedure zframe_set_more(self: PZframe; More: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
902
903 // Return frame routing ID, if the frame came from a ZMQ_SERVER socket.
904 // Else returns zero.
905 function zframe_routing_id(self: PZframe): Cardinal; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
906
907 // Set routing ID on frame. This is used if/when the frame is sent to a
908 // ZMQ_SERVER socket.
909 procedure zframe_set_routing_id(self: PZframe; RoutingId: Cardinal); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
910
911 // Return frame group of radio-dish pattern.
912 function zframe_group(self: PZframe): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
913
914 // Set group on frame. This is used if/when the frame is sent to a
915 // ZMQ_RADIO socket.
916 // Return -1 on error, 0 on success.
917 function zframe_set_group(self: PZframe; Group: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
918
919 // Return TRUE if two frames have identical size and data
920 // If either frame is NULL, equality is always false.
921 function zframe_eq(self: PZframe; Other: PZframe): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
922
923 // Set new contents for frame
924 procedure zframe_reset(self: PZframe; Data: PByte; Size: NativeUInt); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
925
926 // Send message to zsys log sink (may be stdout, or system facility as
927 // configured by zsys_set_logstream). Prefix shows before frame, if not null.
928 procedure zframe_print(self: PZframe; Prefix: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
929
930 // Probe the supplied object, and report if it looks like a zframe_t.
931 function zframe_is(This: Pointer): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
932
933 // Self test of this class.
934 procedure zframe_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
935
936 (* Zhash *)
937 (* generic type-free hash container (simple) *)
938
939 type
940
941 // Callback function for zhash_freefn method
942 TZhashFreeFn = procedure(Data: Pointer); stdcall;
943 PZhashFreeFn = ^TZhashFreeFn;
944
945 // Create a new, empty hash container
946 function zhash_new: PZhash; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
947
948 // Unpack binary frame into a new hash table. Packed data must follow format
949 // defined by zhash_pack. Hash table is set to autofree. An empty frame
950 // unpacks to an empty hash table.
951 function zhash_unpack(Frame: PZframe): PZhash; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
952
953 // Destroy a hash container and all items in it
954 procedure zhash_destroy(var self: PZhash); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
955
956 // Insert item into hash table with specified key and item.
957 // If key is already present returns -1 and leaves existing item unchanged
958 // Returns 0 on success.
959 function zhash_insert(self: PZhash; Key: PAnsiChar; Item: Pointer): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
960
961 // Update item into hash table with specified key and item.
962 // If key is already present, destroys old item and inserts new one.
963 // Use free_fn method to ensure deallocator is properly called on item.
964 procedure zhash_update(self: PZhash; Key: PAnsiChar; Item: Pointer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
965
966 // Remove an item specified by key from the hash table. If there was no such
967 // item, this function does nothing.
968 procedure zhash_delete(self: PZhash; Key: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
969
970 // Return the item at the specified key, or null
971 function zhash_lookup(self: PZhash; Key: PAnsiChar): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
972
973 // Reindexes an item from an old key to a new key. If there was no such
974 // item, does nothing. Returns 0 if successful, else -1.
975 function zhash_rename(self: PZhash; OldKey: PAnsiChar; NewKey: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
976
977 // Set a free function for the specified hash table item. When the item is
978 // destroyed, the free function, if any, is called on that item.
979 // Use this when hash items are dynamically allocated, to ensure that
980 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
981 // Returns the item, or NULL if there is no such item.
982 function zhash_freefn(self: PZhash; Key: PAnsiChar; FreeFn: TZhashFreeFn): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
983
984 // Return the number of keys/items in the hash table
985 function zhash_size(self: PZhash): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
986
987 // Make copy of hash table; if supplied table is null, returns null.
988 // Does not copy items themselves. Rebuilds new table so may be slow on
989 // very large tables. NOTE: only works with item values that are strings
990 // since there's no other way to know how to duplicate the item value.
991 function zhash_dup(self: PZhash): PZhash; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
992
993 // Return keys for items in table
994 function zhash_keys(self: PZhash): PZlist; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
995
996 // Simple iterator; returns first item in hash table, in no given order,
997 // or NULL if the table is empty. This method is simpler to use than the
998 // foreach() method, which is deprecated. To access the key for this item
999 // use zhash_cursor(). NOTE: do NOT modify the table while iterating.
1000 function zhash_first(self: PZhash): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1001
1002 // Simple iterator; returns next item in hash table, in no given order,
1003 // or NULL if the last item was already returned. Use this together with
1004 // zhash_first() to process all items in a hash table. If you need the
1005 // items in sorted order, use zhash_keys() and then zlist_sort(). To
1006 // access the key for this item use zhash_cursor(). NOTE: do NOT modify
1007 // the table while iterating.
1008 function zhash_next(self: PZhash): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1009
1010 // After a successful first/next method, returns the key for the item that
1011 // was returned. This is a constant string that you may not modify or
1012 // deallocate, and which lasts as long as the item in the hash. After an
1013 // unsuccessful first/next, returns NULL.
1014 function zhash_cursor(self: PZhash): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1015
1016 // Add a comment to hash table before saving to disk. You can add as many
1017 // comment lines as you like. These comment lines are discarded when loading
1018 // the file. If you use a null format, all comments are deleted.
1019 procedure zhash_comment(self: PZhash; Format: PAnsiChar); cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1020
1021 // Serialize hash table to a binary frame that can be sent in a message.
1022 // The packed format is compatible with the 'dictionary' type defined in
1023 // http://rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
1024 //
1025 // ; A list of name/value pairs
1026 // dictionary = dict-count *( dict-name dict-value )
1027 // dict-count = number-4
1028 // dict-value = longstr
1029 // dict-name = string
1030 //
1031 // ; Strings are always length + text contents
1032 // longstr = number-4 *VCHAR
1033 // string = number-1 *VCHAR
1034 //
1035 // ; Numbers are unsigned integers in network byte order
1036 // number-1 = 1OCTET
1037 // number-4 = 4OCTET
1038 //
1039 // Comments are not included in the packed data. Item values MUST be
1040 // strings.
1041 function zhash_pack(self: PZhash): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1042
1043 // Save hash table to a text file in name=value format. Hash values must be
1044 // printable strings; keys may not contain '=' character. Returns 0 if OK,
1045 // else -1 if a file error occurred.
1046 function zhash_save(self: PZhash; Filename: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1047
1048 // Load hash table from a text file in name=value format; hash table must
1049 // already exist. Hash values must printable strings; keys may not contain
1050 // '=' character. Returns 0 if OK, else -1 if a file was not readable.
1051 function zhash_load(self: PZhash; Filename: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1052
1053 // When a hash table was loaded from a file by zhash_load, this method will
1054 // reload the file if it has been modified since, and is "stable", i.e. not
1055 // still changing. Returns 0 if OK, -1 if there was an error reloading the
1056 // file.
1057 function zhash_refresh(self: PZhash): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1058
1059 // Set hash for automatic value destruction. Note that this assumes that
1060 // values are NULL-terminated strings. Do not use with different types.
1061 procedure zhash_autofree(self: PZhash); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1062
1063 // Self test of this class.
1064 procedure zhash_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1065
1066 (* Zhashx *)
1067 (* extended generic type-free hash container *)
1068
1069 type
1070
1071 // Destroy an item
1072 TZhashxDestructorFn = procedure(var Item: Pointer); stdcall;
1073 PZhashxDestructorFn = ^TZhashxDestructorFn;
1074
1075 // Duplicate an item
1076 TZhashxDuplicatorFn = function(Item: Pointer): Pointer; stdcall;
1077 PZhashxDuplicatorFn = ^TZhashxDuplicatorFn;
1078
1079 // Compare two items, for sorting
1080 TZhashxComparatorFn = function(Item1: Pointer; Item2: Pointer): Integer; stdcall;
1081 PZhashxComparatorFn = ^TZhashxComparatorFn;
1082
1083 // Destroy an item.
1084 TZhashxFreeFn = procedure(Data: Pointer); stdcall;
1085 PZhashxFreeFn = ^TZhashxFreeFn;
1086
1087 // Hash function for keys.
1088 TZhashxHashFn = function(Key: Pointer): NativeUInt; stdcall;
1089 PZhashxHashFn = ^TZhashxHashFn;
1090
1091 // Serializes an item to a longstr.
1092 // The caller takes ownership of the newly created object.
1093 TZhashxSerializerFn = function(Item: Pointer): PAnsiChar; stdcall;
1094 PZhashxSerializerFn = ^TZhashxSerializerFn;
1095
1096 // Deserializes a longstr into an item.
1097 // The caller takes ownership of the newly created object.
1098 TZhashxDeserializerFn = function(ItemStr: PAnsiChar): Pointer; stdcall;
1099 PZhashxDeserializerFn = ^TZhashxDeserializerFn;
1100
1101 // Create a new, empty hash container
1102 function zhashx_new: PZhashx; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1103
1104 // Unpack binary frame into a new hash table. Packed data must follow format
1105 // defined by zhashx_pack. Hash table is set to autofree. An empty frame
1106 // unpacks to an empty hash table.
1107 function zhashx_unpack(Frame: PZframe): PZhashx; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1108
1109 // Same as unpack but uses a user-defined deserializer function to convert
1110 // a longstr back into item format.
1111 function zhashx_unpack_own(Frame: PZframe; Deserializer: TZhashxDeserializerFn): PZhashx; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1112
1113 // Destroy a hash container and all items in it
1114 procedure zhashx_destroy(var self: PZhashx); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1115
1116 // Insert item into hash table with specified key and item.
1117 // If key is already present returns -1 and leaves existing item unchanged
1118 // Returns 0 on success.
1119 function zhashx_insert(self: PZhashx; Key: Pointer; Item: Pointer): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1120
1121 // Update or insert item into hash table with specified key and item. If the
1122 // key is already present, destroys old item and inserts new one. If you set
1123 // a container item destructor, this is called on the old value. If the key
1124 // was not already present, inserts a new item. Sets the hash cursor to the
1125 // new item.
1126 procedure zhashx_update(self: PZhashx; Key: Pointer; Item: Pointer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1127
1128 // Remove an item specified by key from the hash table. If there was no such
1129 // item, this function does nothing.
1130 procedure zhashx_delete(self: PZhashx; Key: Pointer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1131
1132 // Delete all items from the hash table. If the key destructor is
1133 // set, calls it on every key. If the item destructor is set, calls
1134 // it on every item.
1135 procedure zhashx_purge(self: PZhashx); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1136
1137 // Return the item at the specified key, or null
1138 function zhashx_lookup(self: PZhashx; Key: Pointer): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1139
1140 // Reindexes an item from an old key to a new key. If there was no such
1141 // item, does nothing. Returns 0 if successful, else -1.
1142 function zhashx_rename(self: PZhashx; OldKey: Pointer; NewKey: Pointer): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1143
1144 // Set a free function for the specified hash table item. When the item is
1145 // destroyed, the free function, if any, is called on that item.
1146 // Use this when hash items are dynamically allocated, to ensure that
1147 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
1148 // Returns the item, or NULL if there is no such item.
1149 function zhashx_freefn(self: PZhashx; Key: Pointer; FreeFn: TZhashxFreeFn): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1150
1151 // Return the number of keys/items in the hash table
1152 function zhashx_size(self: PZhashx): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1153
1154 // Return a zlistx_t containing the keys for the items in the
1155 // table. Uses the key_duplicator to duplicate all keys and sets the
1156 // key_destructor as destructor for the list.
1157 function zhashx_keys(self: PZhashx): PZlistx; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1158
1159 // Return a zlistx_t containing the values for the items in the
1160 // table. Uses the duplicator to duplicate all items and sets the
1161 // destructor as destructor for the list.
1162 function zhashx_values(self: PZhashx): PZlistx; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1163
1164 // Simple iterator; returns first item in hash table, in no given order,
1165 // or NULL if the table is empty. This method is simpler to use than the
1166 // foreach() method, which is deprecated. To access the key for this item
1167 // use zhashx_cursor(). NOTE: do NOT modify the table while iterating.
1168 function zhashx_first(self: PZhashx): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1169
1170 // Simple iterator; returns next item in hash table, in no given order,
1171 // or NULL if the last item was already returned. Use this together with
1172 // zhashx_first() to process all items in a hash table. If you need the
1173 // items in sorted order, use zhashx_keys() and then zlistx_sort(). To
1174 // access the key for this item use zhashx_cursor(). NOTE: do NOT modify
1175 // the table while iterating.
1176 function zhashx_next(self: PZhashx): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1177
1178 // After a successful first/next method, returns the key for the item that
1179 // was returned. This is a constant string that you may not modify or
1180 // deallocate, and which lasts as long as the item in the hash. After an
1181 // unsuccessful first/next, returns NULL.
1182 function zhashx_cursor(self: PZhashx): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1183
1184 // Add a comment to hash table before saving to disk. You can add as many
1185 // comment lines as you like. These comment lines are discarded when loading
1186 // the file. If you use a null format, all comments are deleted.
1187 procedure zhashx_comment(self: PZhashx; Format: PAnsiChar); cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1188
1189 // Save hash table to a text file in name=value format. Hash values must be
1190 // printable strings; keys may not contain '=' character. Returns 0 if OK,
1191 // else -1 if a file error occurred.
1192 function zhashx_save(self: PZhashx; Filename: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1193
1194 // Load hash table from a text file in name=value format; hash table must
1195 // already exist. Hash values must printable strings; keys may not contain
1196 // '=' character. Returns 0 if OK, else -1 if a file was not readable.
1197 function zhashx_load(self: PZhashx; Filename: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1198
1199 // When a hash table was loaded from a file by zhashx_load, this method will
1200 // reload the file if it has been modified since, and is "stable", i.e. not
1201 // still changing. Returns 0 if OK, -1 if there was an error reloading the
1202 // file.
1203 function zhashx_refresh(self: PZhashx): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1204
1205 // Serialize hash table to a binary frame that can be sent in a message.
1206 // The packed format is compatible with the 'dictionary' type defined in
1207 // http://rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
1208 //
1209 // ; A list of name/value pairs
1210 // dictionary = dict-count *( dict-name dict-value )
1211 // dict-count = number-4
1212 // dict-value = longstr
1213 // dict-name = string
1214 //
1215 // ; Strings are always length + text contents
1216 // longstr = number-4 *VCHAR
1217 // string = number-1 *VCHAR
1218 //
1219 // ; Numbers are unsigned integers in network byte order
1220 // number-1 = 1OCTET
1221 // number-4 = 4OCTET
1222 //
1223 // Comments are not included in the packed data. Item values MUST be
1224 // strings.
1225 function zhashx_pack(self: PZhashx): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1226
1227 // Same as pack but uses a user-defined serializer function to convert items
1228 // into longstr.
1229 function zhashx_pack_own(self: PZhashx; Serializer: TZhashxSerializerFn): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1230
1231 // Make a copy of the list; items are duplicated if you set a duplicator
1232 // for the list, otherwise not. Copying a null reference returns a null
1233 // reference. Note that this method's behavior changed slightly for CZMQ
1234 // v3.x, as it does not set nor respect autofree. It does however let you
1235 // duplicate any hash table safely. The old behavior is in zhashx_dup_v2.
1236 function zhashx_dup(self: PZhashx): PZhashx; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1237
1238 // Set a user-defined deallocator for hash items; by default items are not
1239 // freed when the hash is destroyed.
1240 procedure zhashx_set_destructor(self: PZhashx; &Destructor: TZhashxDestructorFn); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1241
1242 // Set a user-defined duplicator for hash items; by default items are not
1243 // copied when the hash is duplicated.
1244 procedure zhashx_set_duplicator(self: PZhashx; Duplicator: TZhashxDuplicatorFn); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1245
1246 // Set a user-defined deallocator for keys; by default keys are freed
1247 // when the hash is destroyed using free().
1248 procedure zhashx_set_key_destructor(self: PZhashx; &Destructor: TZhashxDestructorFn); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1249
1250 // Set a user-defined duplicator for keys; by default keys are duplicated
1251 // using strdup.
1252 procedure zhashx_set_key_duplicator(self: PZhashx; Duplicator: TZhashxDuplicatorFn); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1253
1254 // Set a user-defined comparator for keys; by default keys are
1255 // compared using strcmp.
1256 // The callback function should return zero (0) on matching
1257 // items.
1258 procedure zhashx_set_key_comparator(self: PZhashx; Comparator: TZhashxComparatorFn); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1259
1260 // Set a user-defined hash function for keys; by default keys are
1261 // hashed by a modified Bernstein hashing function.
1262 procedure zhashx_set_key_hasher(self: PZhashx; Hasher: TZhashxHashFn); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1263
1264 // Make copy of hash table; if supplied table is null, returns null.
1265 // Does not copy items themselves. Rebuilds new table so may be slow on
1266 // very large tables. NOTE: only works with item values that are strings
1267 // since there's no other way to know how to duplicate the item value.
1268 function zhashx_dup_v2(self: PZhashx): PZhashx; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1269
1270 // Self test of this class.
1271 procedure zhashx_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1272
1273 (* Ziflist *)
1274 (* List of network interfaces available on system *)
1275
1276 // Get a list of network interfaces currently defined on the system
1277 function ziflist_new: PZiflist; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1278
1279 // Destroy a ziflist instance
1280 procedure ziflist_destroy(var self: PZiflist); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1281
1282 // Reload network interfaces from system
1283 procedure ziflist_reload(self: PZiflist); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1284
1285 // Return the number of network interfaces on system
1286 function ziflist_size(self: PZiflist): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1287
1288 // Get first network interface, return NULL if there are none
1289 function ziflist_first(self: PZiflist): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1290
1291 // Get next network interface, return NULL if we hit the last one
1292 function ziflist_next(self: PZiflist): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1293
1294 // Return the current interface IP address as a printable string
1295 function ziflist_address(self: PZiflist): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1296
1297 // Return the current interface broadcast address as a printable string
1298 function ziflist_broadcast(self: PZiflist): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1299
1300 // Return the current interface network mask as a printable string
1301 function ziflist_netmask(self: PZiflist): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1302
1303 // Return the list of interfaces.
1304 procedure ziflist_print(self: PZiflist); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1305
1306 // Get a list of network interfaces currently defined on the system
1307 // Includes IPv6 interfaces
1308 function ziflist_new_ipv6: PZiflist; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1309
1310 // Reload network interfaces from system, including IPv6
1311 procedure ziflist_reload_ipv6(self: PZiflist); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1312
1313 // Return true if the current interface uses IPv6
1314 function ziflist_is_ipv6(self: PZiflist): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1315
1316 // Self test of this class.
1317 procedure ziflist_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1318
1319 (* Zlist *)
1320 (* simple generic list container *)
1321
1322 type
1323
1324 // Comparison function e.g. for sorting and removing.
1325 TZlistCompareFn = function(Item1: Pointer; Item2: Pointer): Integer; stdcall;
1326 PZlistCompareFn = ^TZlistCompareFn;
1327
1328 // Callback function for zlist_freefn method
1329 TZlistFreeFn = procedure(Data: Pointer); stdcall;
1330 PZlistFreeFn = ^TZlistFreeFn;
1331
1332 // Create a new list container
1333 function zlist_new: PZlist; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1334
1335 // Destroy a list container
1336 procedure zlist_destroy(var self: PZlist); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1337
1338 // Return the item at the head of list. If the list is empty, returns NULL.
1339 // Leaves cursor pointing at the head item, or NULL if the list is empty.
1340 function zlist_first(self: PZlist): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1341
1342 // Return the next item. If the list is empty, returns NULL. To move to
1343 // the start of the list call zlist_first (). Advances the cursor.
1344 function zlist_next(self: PZlist): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1345
1346 // Return the item at the tail of list. If the list is empty, returns NULL.
1347 // Leaves cursor pointing at the tail item, or NULL if the list is empty.
1348 function zlist_last(self: PZlist): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1349
1350 // Return first item in the list, or null, leaves the cursor
1351 function zlist_head(self: PZlist): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1352
1353 // Return last item in the list, or null, leaves the cursor
1354 function zlist_tail(self: PZlist): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1355
1356 // Return the current item of list. If the list is empty, returns NULL.
1357 // Leaves cursor pointing at the current item, or NULL if the list is empty.
1358 function zlist_item(self: PZlist): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1359
1360 // Append an item to the end of the list, return 0 if OK or -1 if this
1361 // failed for some reason (out of memory). Note that if a duplicator has
1362 // been set, this method will also duplicate the item.
1363 function zlist_append(self: PZlist; Item: Pointer): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1364
1365 // Push an item to the start of the list, return 0 if OK or -1 if this
1366 // failed for some reason (out of memory). Note that if a duplicator has
1367 // been set, this method will also duplicate the item.
1368 function zlist_push(self: PZlist; Item: Pointer): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1369
1370 // Pop the item off the start of the list, if any
1371 function zlist_pop(self: PZlist): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1372
1373 // Checks if an item already is present. Uses compare method to determine if
1374 // items are equal. If the compare method is NULL the check will only compare
1375 // pointers. Returns true if item is present else false.
1376 function zlist_exists(self: PZlist; Item: Pointer): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1377
1378 // Remove the specified item from the list if present
1379 procedure zlist_remove(self: PZlist; Item: Pointer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1380
1381 // Make a copy of list. If the list has autofree set, the copied list will
1382 // duplicate all items, which must be strings. Otherwise, the list will hold
1383 // pointers back to the items in the original list. If list is null, returns
1384 // NULL.
1385 function zlist_dup(self: PZlist): PZlist; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1386
1387 // Purge all items from list
1388 procedure zlist_purge(self: PZlist); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1389
1390 // Return number of items in the list
1391 function zlist_size(self: PZlist): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1392
1393 // Sort the list. If the compare function is null, sorts the list by
1394 // ascending key value using a straight ASCII comparison. If you specify
1395 // a compare function, this decides how items are sorted. The sort is not
1396 // stable, so may reorder items with the same keys. The algorithm used is
1397 // combsort, a compromise between performance and simplicity.
1398 procedure zlist_sort(self: PZlist; Compare: TZlistCompareFn); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1399
1400 // Set list for automatic item destruction; item values MUST be strings.
1401 // By default a list item refers to a value held elsewhere. When you set
1402 // this, each time you append or push a list item, zlist will take a copy
1403 // of the string value. Then, when you destroy the list, it will free all
1404 // item values automatically. If you use any other technique to allocate
1405 // list values, you must free them explicitly before destroying the list.
1406 // The usual technique is to pop list items and destroy them, until the
1407 // list is empty.
1408 procedure zlist_autofree(self: PZlist); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1409
1410 // Sets a compare function for this list. The function compares two items.
1411 // It returns an integer less than, equal to, or greater than zero if the
1412 // first item is found, respectively, to be less than, to match, or be
1413 // greater than the second item.
1414 // This function is used for sorting, removal and exists checking.
1415 procedure zlist_comparefn(self: PZlist; Fn: TZlistCompareFn); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1416
1417 // Set a free function for the specified list item. When the item is
1418 // destroyed, the free function, if any, is called on that item.
1419 // Use this when list items are dynamically allocated, to ensure that
1420 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
1421 // Returns the item, or NULL if there is no such item.
1422 function zlist_freefn(self: PZlist; Item: Pointer; Fn: TZlistFreeFn; AtTail: Boolean): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1423
1424 // Self test of this class.
1425 procedure zlist_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1426
1427 (* Zlistx *)
1428 (* extended generic list container *)
1429
1430 type
1431
1432 // Destroy an item
1433 TZlistxDestructorFn = procedure(var Item: Pointer); stdcall;
1434 PZlistxDestructorFn = ^TZlistxDestructorFn;
1435
1436 // Duplicate an item
1437 TZlistxDuplicatorFn = function(Item: Pointer): Pointer; stdcall;
1438 PZlistxDuplicatorFn = ^TZlistxDuplicatorFn;
1439
1440 // Compare two items, for sorting
1441 TZlistxComparatorFn = function(Item1: Pointer; Item2: Pointer): Integer; stdcall;
1442 PZlistxComparatorFn = ^TZlistxComparatorFn;
1443
1444 // Create a new, empty list.
1445 function zlistx_new: PZlistx; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1446
1447 // Unpack binary frame into a new list. Packed data must follow format
1448 // defined by zlistx_pack. List is set to autofree. An empty frame
1449 // unpacks to an empty list.
1450 function zlistx_unpack(Frame: PZframe): PZlistx; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1451
1452 // Destroy a list. If an item destructor was specified, all items in the
1453 // list are automatically destroyed as well.
1454 procedure zlistx_destroy(var self: PZlistx); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1455
1456 // Add an item to the head of the list. Calls the item duplicator, if any,
1457 // on the item. Resets cursor to list head. Returns an item handle on
1458 // success, NULL if memory was exhausted.
1459 function zlistx_add_start(self: PZlistx; Item: Pointer): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1460
1461 // Add an item to the tail of the list. Calls the item duplicator, if any,
1462 // on the item. Resets cursor to list head. Returns an item handle on
1463 // success, NULL if memory was exhausted.
1464 function zlistx_add_end(self: PZlistx; Item: Pointer): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1465
1466 // Return the number of items in the list
1467 function zlistx_size(self: PZlistx): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1468
1469 // Return first item in the list, or null, leaves the cursor
1470 function zlistx_head(self: PZlistx): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1471
1472 // Return last item in the list, or null, leaves the cursor
1473 function zlistx_tail(self: PZlistx): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1474
1475 // Return the item at the head of list. If the list is empty, returns NULL.
1476 // Leaves cursor pointing at the head item, or NULL if the list is empty.
1477 function zlistx_first(self: PZlistx): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1478
1479 // Return the next item. At the end of the list (or in an empty list),
1480 // returns NULL. Use repeated zlistx_next () calls to work through the list
1481 // from zlistx_first (). First time, acts as zlistx_first().
1482 function zlistx_next(self: PZlistx): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1483
1484 // Return the previous item. At the start of the list (or in an empty list),
1485 // returns NULL. Use repeated zlistx_prev () calls to work through the list
1486 // backwards from zlistx_last (). First time, acts as zlistx_last().
1487 function zlistx_prev(self: PZlistx): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1488
1489 // Return the item at the tail of list. If the list is empty, returns NULL.
1490 // Leaves cursor pointing at the tail item, or NULL if the list is empty.
1491 function zlistx_last(self: PZlistx): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1492
1493 // Returns the value of the item at the cursor, or NULL if the cursor is
1494 // not pointing to an item.
1495 function zlistx_item(self: PZlistx): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1496
1497 // Returns the handle of the item at the cursor, or NULL if the cursor is
1498 // not pointing to an item.
1499 function zlistx_cursor(self: PZlistx): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1500
1501 // Returns the item associated with the given list handle, or NULL if passed
1502 // in handle is NULL. Asserts that the passed in handle points to a list element.
1503 function zlistx_handle_item(Handle: Pointer): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1504
1505 // Find an item in the list, searching from the start. Uses the item
1506 // comparator, if any, else compares item values directly. Returns the
1507 // item handle found, or NULL. Sets the cursor to the found item, if any.
1508 function zlistx_find(self: PZlistx; Item: Pointer): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1509
1510 // Detach an item from the list, using its handle. The item is not modified,
1511 // and the caller is responsible for destroying it if necessary. If handle is
1512 // null, detaches the first item on the list. Returns item that was detached,
1513 // or null if none was. If cursor was at item, moves cursor to previous item,
1514 // so you can detach items while iterating forwards through a list.
1515 function zlistx_detach(self: PZlistx; Handle: Pointer): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1516
1517 // Detach item at the cursor, if any, from the list. The item is not modified,
1518 // and the caller is responsible for destroying it as necessary. Returns item
1519 // that was detached, or null if none was. Moves cursor to previous item, so
1520 // you can detach items while iterating forwards through a list.
1521 function zlistx_detach_cur(self: PZlistx): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1522
1523 // Delete an item, using its handle. Calls the item destructor is any is
1524 // set. If handle is null, deletes the first item on the list. Returns 0
1525 // if an item was deleted, -1 if not. If cursor was at item, moves cursor
1526 // to previous item, so you can delete items while iterating forwards
1527 // through a list.
1528 function zlistx_delete(self: PZlistx; Handle: Pointer): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1529
1530 // Move an item to the start of the list, via its handle.
1531 procedure zlistx_move_start(self: PZlistx; Handle: Pointer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1532
1533 // Move an item to the end of the list, via its handle.
1534 procedure zlistx_move_end(self: PZlistx; Handle: Pointer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1535
1536 // Remove all items from the list, and destroy them if the item destructor
1537 // is set.
1538 procedure zlistx_purge(self: PZlistx); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1539
1540 // Sort the list. If an item comparator was set, calls that to compare
1541 // items, otherwise compares on item value. The sort is not stable, so may
1542 // reorder equal items.
1543 procedure zlistx_sort(self: PZlistx); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1544
1545 // Create a new node and insert it into a sorted list. Calls the item
1546 // duplicator, if any, on the item. If low_value is true, starts searching
1547 // from the start of the list, otherwise searches from the end. Use the item
1548 // comparator, if any, to find where to place the new node. Returns a handle
1549 // to the new node, or NULL if memory was exhausted. Resets the cursor to the
1550 // list head.
1551 function zlistx_insert(self: PZlistx; Item: Pointer; LowValue: Boolean): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1552
1553 // Move an item, specified by handle, into position in a sorted list. Uses
1554 // the item comparator, if any, to determine the new location. If low_value
1555 // is true, starts searching from the start of the list, otherwise searches
1556 // from the end.
1557 procedure zlistx_reorder(self: PZlistx; Handle: Pointer; LowValue: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1558
1559 // Make a copy of the list; items are duplicated if you set a duplicator
1560 // for the list, otherwise not. Copying a null reference returns a null
1561 // reference.
1562 function zlistx_dup(self: PZlistx): PZlistx; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1563
1564 // Set a user-defined deallocator for list items; by default items are not
1565 // freed when the list is destroyed.
1566 procedure zlistx_set_destructor(self: PZlistx; &Destructor: TZlistxDestructorFn); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1567
1568 // Set a user-defined duplicator for list items; by default items are not
1569 // copied when the list is duplicated.
1570 procedure zlistx_set_duplicator(self: PZlistx; Duplicator: TZlistxDuplicatorFn); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1571
1572 // Set a user-defined comparator for zlistx_find and zlistx_sort; the method
1573 // must return -1, 0, or 1 depending on whether item1 is less than, equal to,
1574 // or greater than, item2.
1575 procedure zlistx_set_comparator(self: PZlistx; Comparator: TZlistxComparatorFn); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1576
1577 // Serialize list to a binary frame that can be sent in a message.
1578 // The packed format is compatible with the 'strings' type implemented by zproto:
1579 //
1580 // ; A list of strings
1581 // list = list-count *longstr
1582 // list-count = number-4
1583 //
1584 // ; Strings are always length + text contents
1585 // longstr = number-4 *VCHAR
1586 //
1587 // ; Numbers are unsigned integers in network byte order
1588 // number-4 = 4OCTET
1589 function zlistx_pack(self: PZlistx): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1590
1591 // Self test of this class.
1592 procedure zlistx_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1593
1594 (* Zloop *)
1595 (* event-driven reactor *)
1596
1597 type
1598
1599 // Callback function for reactor socket activity
1600 TZloopReaderFn = function(Loop: PZloop; Reader: PZsock; Arg: Pointer): Integer; stdcall;
1601 PZloopReaderFn = ^TZloopReaderFn;
1602
1603 // Callback function for reactor events (low-level)
1604 TZloopFn = function(Loop: PZloop; Item: Pointer; Arg: Pointer): Integer; stdcall;
1605 PZloopFn = ^TZloopFn;
1606
1607 // Callback for reactor timer events
1608 TZloopTimerFn = function(Loop: PZloop; TimerId: Integer; Arg: Pointer): Integer; stdcall;
1609 PZloopTimerFn = ^TZloopTimerFn;
1610
1611 // Create a new zloop reactor
1612 function zloop_new: PZloop; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1613
1614 // Destroy a reactor
1615 procedure zloop_destroy(var self: PZloop); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1616
1617 // Register socket reader with the reactor. When the reader has messages,
1618 // the reactor will call the handler, passing the arg. Returns 0 if OK, -1
1619 // if there was an error. If you register the same socket more than once,
1620 // each instance will invoke its corresponding handler.
1621 function zloop_reader(self: PZloop; Sock: PZsock; Handler: TZloopReaderFn; Arg: Pointer): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1622
1623 // Cancel a socket reader from the reactor. If multiple readers exist for
1624 // same socket, cancels ALL of them.
1625 procedure zloop_reader_end(self: PZloop; Sock: PZsock); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1626
1627 // Configure a registered reader to ignore errors. If you do not set this,
1628 // then readers that have errors are removed from the reactor silently.
1629 procedure zloop_reader_set_tolerant(self: PZloop; Sock: PZsock); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1630
1631 // Register low-level libzmq pollitem with the reactor. When the pollitem
1632 // is ready, will call the handler, passing the arg. Returns 0 if OK, -1
1633 // if there was an error. If you register the pollitem more than once, each
1634 // instance will invoke its corresponding handler. A pollitem with
1635 // socket=NULL and fd=0 means 'poll on FD zero'.
1636 function zloop_poller(self: PZloop; Item: Pointer; Handler: TZloopFn; Arg: Pointer): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1637
1638 // Cancel a pollitem from the reactor, specified by socket or FD. If both
1639 // are specified, uses only socket. If multiple poll items exist for same
1640 // socket/FD, cancels ALL of them.
1641 procedure zloop_poller_end(self: PZloop; Item: Pointer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1642
1643 // Configure a registered poller to ignore errors. If you do not set this,
1644 // then poller that have errors are removed from the reactor silently.
1645 procedure zloop_poller_set_tolerant(self: PZloop; Item: Pointer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1646
1647 // Register a timer that expires after some delay and repeats some number of
1648 // times. At each expiry, will call the handler, passing the arg. To run a
1649 // timer forever, use 0 times. Returns a timer_id that is used to cancel the
1650 // timer in the future. Returns -1 if there was an error.
1651 function zloop_timer(self: PZloop; Delay: NativeUInt; Times: NativeUInt; Handler: TZloopTimerFn; Arg: Pointer): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1652
1653 // Cancel a specific timer identified by a specific timer_id (as returned by
1654 // zloop_timer).
1655 function zloop_timer_end(self: PZloop; TimerId: Integer): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1656
1657 // Register a ticket timer. Ticket timers are very fast in the case where
1658 // you use a lot of timers (thousands), and frequently remove and add them.
1659 // The main use case is expiry timers for servers that handle many clients,
1660 // and which reset the expiry timer for each message received from a client.
1661 // Whereas normal timers perform poorly as the number of clients grows, the
1662 // cost of ticket timers is constant, no matter the number of clients. You
1663 // must set the ticket delay using zloop_set_ticket_delay before creating a
1664 // ticket. Returns a handle to the timer that you should use in
1665 // zloop_ticket_reset and zloop_ticket_delete.
1666 function zloop_ticket(self: PZloop; Handler: TZloopTimerFn; Arg: Pointer): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1667
1668 // Reset a ticket timer, which moves it to the end of the ticket list and
1669 // resets its execution time. This is a very fast operation.
1670 procedure zloop_ticket_reset(self: PZloop; Handle: Pointer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1671
1672 // Delete a ticket timer. We do not actually delete the ticket here, as
1673 // other code may still refer to the ticket. We mark as deleted, and remove
1674 // later and safely.
1675 procedure zloop_ticket_delete(self: PZloop; Handle: Pointer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1676
1677 // Set the ticket delay, which applies to all tickets. If you lower the
1678 // delay and there are already tickets created, the results are undefined.
1679 procedure zloop_set_ticket_delay(self: PZloop; TicketDelay: NativeUInt); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1680
1681 // Set hard limit on number of timers allowed. Setting more than a small
1682 // number of timers (10-100) can have a dramatic impact on the performance
1683 // of the reactor. For high-volume cases, use ticket timers. If the hard
1684 // limit is reached, the reactor stops creating new timers and logs an
1685 // error.
1686 procedure zloop_set_max_timers(self: PZloop; MaxTimers: NativeUInt); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1687
1688 // Set verbose tracing of reactor on/off. The default verbose setting is
1689 // off (false).
1690 procedure zloop_set_verbose(self: PZloop; Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1691
1692 // By default the reactor stops if the process receives a SIGINT or SIGTERM
1693 // signal. This makes it impossible to shut-down message based architectures
1694 // like zactors. This method lets you switch off break handling. The default
1695 // nonstop setting is off (false).
1696 procedure zloop_set_nonstop(self: PZloop; Nonstop: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1697
1698 // Start the reactor. Takes control of the thread and returns when the 0MQ
1699 // context is terminated or the process is interrupted, or any event handler
1700 // returns -1. Event handlers may register new sockets and timers, and
1701 // cancel sockets. Returns 0 if interrupted, -1 if canceled by a handler.
1702 function zloop_start(self: PZloop): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1703
1704 // Self test of this class.
1705 procedure zloop_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1706
1707 (* Zmsg *)
1708 (* working with multipart messages *)
1709
1710 // Create a new empty message object
1711 function zmsg_new: PZmsg; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1712
1713 // Receive message from socket, returns zmsg_t object or NULL if the recv
1714 // was interrupted. Does a blocking recv. If you want to not block then use
1715 // the zloop class or zmsg_recv_nowait or zmq_poll to check for socket input
1716 // before receiving.
1717 function zmsg_recv(Source: PZSock): PZmsg; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1718
1719 // Load/append an open file into new message, return the message.
1720 // Returns NULL if the message could not be loaded.
1721 function zmsg_load(&File: Pointer): PZmsg; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1722
1723 // Decodes a serialized message frame created by zmsg_encode () and returns
1724 // a new zmsg_t object. Returns NULL if the frame was badly formatted or
1725 // there was insufficient memory to work.
1726 function zmsg_decode(Frame: PZframe): PZmsg; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1727
1728 // Generate a signal message encoding the given status. A signal is a short
1729 // message carrying a 1-byte success/failure code (by convention, 0 means
1730 // OK). Signals are encoded to be distinguishable from "normal" messages.
1731 function zmsg_new_signal(Status: Byte): PZmsg; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1732
1733 // Destroy a message object and all frames it contains
1734 procedure zmsg_destroy(var self: PZmsg); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1735
1736 // Send message to destination socket, and destroy the message after sending
1737 // it successfully. If the message has no frames, sends nothing but destroys
1738 // the message anyhow. Nullifies the caller's reference to the message (as
1739 // it is a destructor).
1740 function zmsg_send(var SelfP: PZmsg; Dest: PZSock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1741
1742 // Send message to destination socket as part of a multipart sequence, and
1743 // destroy the message after sending it successfully. Note that after a
1744 // zmsg_sendm, you must call zmsg_send or another method that sends a final
1745 // message part. If the message has no frames, sends nothing but destroys
1746 // the message anyhow. Nullifies the caller's reference to the message (as
1747 // it is a destructor).
1748 function zmsg_sendm(var SelfP: PZmsg; Dest: PZSock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1749
1750 // Return size of message, i.e. number of frames (0 or more).
1751 function zmsg_size(self: PZmsg): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1752
1753 // Return total size of all frames in message.
1754 function zmsg_content_size(self: PZmsg): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1755
1756 // Return message routing ID, if the message came from a ZMQ_SERVER socket.
1757 // Else returns zero.
1758 function zmsg_routing_id(self: PZmsg): Cardinal; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1759
1760 // Set routing ID on message. This is used if/when the message is sent to a
1761 // ZMQ_SERVER socket.
1762 procedure zmsg_set_routing_id(self: PZmsg; RoutingId: Cardinal); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1763
1764 // Push frame to the front of the message, i.e. before all other frames.
1765 // Message takes ownership of frame, will destroy it when message is sent.
1766 // Returns 0 on success, -1 on error. Deprecates zmsg_push, which did not
1767 // nullify the caller's frame reference.
1768 function zmsg_prepend(self: PZmsg; var FrameP: PZframe): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1769
1770 // Add frame to the end of the message, i.e. after all other frames.
1771 // Message takes ownership of frame, will destroy it when message is sent.
1772 // Returns 0 on success. Deprecates zmsg_add, which did not nullify the
1773 // caller's frame reference.
1774 function zmsg_append(self: PZmsg; var FrameP: PZframe): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1775
1776 // Remove first frame from message, if any. Returns frame, or NULL.
1777 function zmsg_pop(self: PZmsg): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1778
1779 // Push block of memory to front of message, as a new frame.
1780 // Returns 0 on success, -1 on error.
1781 function zmsg_pushmem(self: PZmsg; Data: PByte; Size: NativeUInt): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1782
1783 // Add block of memory to the end of the message, as a new frame.
1784 // Returns 0 on success, -1 on error.
1785 function zmsg_addmem(self: PZmsg; Data: PByte; Size: NativeUInt): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1786
1787 // Push string as new frame to front of message.
1788 // Returns 0 on success, -1 on error.
1789 function zmsg_pushstr(self: PZmsg; &String: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1790
1791 // Push string as new frame to end of message.
1792 // Returns 0 on success, -1 on error.
1793 function zmsg_addstr(self: PZmsg; &String: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1794
1795 // Push formatted string as new frame to front of message.
1796 // Returns 0 on success, -1 on error.
1797 function zmsg_pushstrf(self: PZmsg; Format: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1798
1799 // Push formatted string as new frame to end of message.
1800 // Returns 0 on success, -1 on error.
1801 function zmsg_addstrf(self: PZmsg; Format: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1802
1803 // Pop frame off front of message, return as fresh string. If there were
1804 // no more frames in the message, returns NULL.
1805 function zmsg_popstr(self: PZmsg): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1806
1807 // Push encoded message as a new frame. Message takes ownership of
1808 // submessage, so the original is destroyed in this call. Returns 0 on
1809 // success, -1 on error.
1810 function zmsg_addmsg(self: PZmsg; var MsgP: PZmsg): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1811
1812 // Remove first submessage from message, if any. Returns zmsg_t, or NULL if
1813 // decoding was not successful.
1814 function zmsg_popmsg(self: PZmsg): PZmsg; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1815
1816 // Remove specified frame from list, if present. Does not destroy frame.
1817 procedure zmsg_remove(self: PZmsg; Frame: PZframe); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1818
1819 // Set cursor to first frame in message. Returns frame, or NULL, if the
1820 // message is empty. Use this to navigate the frames as a list.
1821 function zmsg_first(self: PZmsg): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1822
1823 // Return the next frame. If there are no more frames, returns NULL. To move
1824 // to the first frame call zmsg_first(). Advances the cursor.
1825 function zmsg_next(self: PZmsg): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1826
1827 // Return the last frame. If there are no frames, returns NULL.
1828 function zmsg_last(self: PZmsg): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1829
1830 // Save message to an open file, return 0 if OK, else -1. The message is
1831 // saved as a series of frames, each with length and data. Note that the
1832 // file is NOT guaranteed to be portable between operating systems, not
1833 // versions of CZMQ. The file format is at present undocumented and liable
1834 // to arbitrary change.
1835 function zmsg_save(self: PZmsg; &File: Pointer): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1836
1837 // Serialize multipart message to a single message frame. Use this method
1838 // to send structured messages across transports that do not support
1839 // multipart data. Allocates and returns a new frame containing the
1840 // serialized message. To decode a serialized message frame, use
1841 // zmsg_decode ().
1842 function zmsg_encode(self: PZmsg): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1843
1844 // Create copy of message, as new message object. Returns a fresh zmsg_t
1845 // object. If message is null, or memory was exhausted, returns null.
1846 function zmsg_dup(self: PZmsg): PZmsg; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1847
1848 // Send message to zsys log sink (may be stdout, or system facility as
1849 // configured by zsys_set_logstream).
1850 procedure zmsg_print(self: PZmsg); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1851
1852 // Return true if the two messages have the same number of frames and each
1853 // frame in the first message is identical to the corresponding frame in the
1854 // other message. As with zframe_eq, return false if either message is NULL.
1855 function zmsg_eq(self: PZmsg; Other: PZmsg): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1856
1857 // Return signal value, 0 or greater, if message is a signal, -1 if not.
1858 function zmsg_signal(self: PZmsg): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1859
1860 // Probe the supplied object, and report if it looks like a zmsg_t.
1861 function zmsg_is(This: Pointer): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1862
1863 // Self test of this class.
1864 procedure zmsg_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1865
1866 (* Zpoller *)
1867 (* event-driven reactor *)
1868
1869 // Create new poller, specifying zero or more readers. The list of
1870 // readers ends in a NULL. Each reader can be a zsock_t instance, a
1871 // zactor_t instance, a libzmq socket (void *), or a file handle.
1872 function zpoller_new(Reader: PZSock): PZpoller; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1873
1874 // Destroy a poller
1875 procedure zpoller_destroy(var self: PZpoller); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1876
1877 // Add a reader to be polled. Returns 0 if OK, -1 on failure. The reader may
1878 // be a libzmq void * socket, a zsock_t instance, or a zactor_t instance.
1879 function zpoller_add(self: PZpoller; Reader: PZSock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1880
1881 // Remove a reader from the poller; returns 0 if OK, -1 on failure. The reader
1882 // must have been passed during construction, or in an zpoller_add () call.
1883 function zpoller_remove(self: PZpoller; Reader: Pointer): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1884
1885 // By default the poller stops if the process receives a SIGINT or SIGTERM
1886 // signal. This makes it impossible to shut-down message based architectures
1887 // like zactors. This method lets you switch off break handling. The default
1888 // nonstop setting is off (false).
1889 procedure zpoller_set_nonstop(self: PZpoller; Nonstop: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1890
1891 // Poll the registered readers for I/O, return first reader that has input.
1892 // The reader will be a libzmq void * socket, or a zsock_t or zactor_t
1893 // instance as specified in zpoller_new/zpoller_add. The timeout should be
1894 // zero or greater, or -1 to wait indefinitely. Socket priority is defined
1895 // by their order in the poll list. If you need a balanced poll, use the low
1896 // level zmq_poll method directly. If the poll call was interrupted (SIGINT),
1897 // or the ZMQ context was destroyed, or the timeout expired, returns NULL.
1898 // You can test the actual exit condition by calling zpoller_expired () and
1899 // zpoller_terminated (). The timeout is in msec.
1900 function zpoller_wait(self: PZpoller; Timeout: Integer): PZSock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1901
1902 // Return true if the last zpoller_wait () call ended because the timeout
1903 // expired, without any error.
1904 function zpoller_expired(self: PZpoller): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1905
1906 // Return true if the last zpoller_wait () call ended because the process
1907 // was interrupted, or the parent context was destroyed.
1908 function zpoller_terminated(self: PZpoller): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1909
1910 // Self test of this class.
1911 procedure zpoller_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1912
1913 (* Zsock *)
1914 (* high-level socket API that hides libzmq contexts and sockets *)
1915
1916 // Create a new socket. Returns the new socket, or NULL if the new socket
1917 // could not be created. Note that the symbol zsock_new (and other
1918 // constructors/destructors for zsock) are redirected to the *_checked
1919 // variant, enabling intelligent socket leak detection. This can have
1920 // performance implications if you use a LOT of sockets. To turn off this
1921 // redirection behaviour, define ZSOCK_NOCHECK.
1922 function zsock_new(&Type: Integer): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1923
1924 // Create a PUB socket. Default action is bind.
1925 function zsock_new_pub(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1926
1927 // Create a SUB socket, and optionally subscribe to some prefix string. Default
1928 // action is connect.
1929 function zsock_new_sub(Endpoint: PAnsiChar; Subscribe: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1930
1931 // Create a REQ socket. Default action is connect.
1932 function zsock_new_req(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1933
1934 // Create a REP socket. Default action is bind.
1935 function zsock_new_rep(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1936
1937 // Create a DEALER socket. Default action is connect.
1938 function zsock_new_dealer(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1939
1940 // Create a ROUTER socket. Default action is bind.
1941 function zsock_new_router(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1942
1943 // Create a PUSH socket. Default action is connect.
1944 function zsock_new_push(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1945
1946 // Create a PULL socket. Default action is bind.
1947 function zsock_new_pull(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1948
1949 // Create an XPUB socket. Default action is bind.
1950 function zsock_new_xpub(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1951
1952 // Create an XSUB socket. Default action is connect.
1953 function zsock_new_xsub(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1954
1955 // Create a PAIR socket. Default action is connect.
1956 function zsock_new_pair(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1957
1958 // Create a STREAM socket. Default action is connect.
1959 function zsock_new_stream(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1960
1961 // Create a SERVER socket. Default action is bind.
1962 function zsock_new_server(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1963
1964 // Create a CLIENT socket. Default action is connect.
1965 function zsock_new_client(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1966
1967 // Create a RADIO socket. Default action is bind.
1968 function zsock_new_radio(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1969
1970 // Create a DISH socket. Default action is connect.
1971 function zsock_new_dish(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1972
1973 // Create a GATHER socket. Default action is bind.
1974 function zsock_new_gather(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1975
1976 // Create a SCATTER socket. Default action is connect.
1977 function zsock_new_scatter(Endpoint: PAnsiChar): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1978
1979 // Destroy the socket. You must use this for any socket created via the
1980 // zsock_new method.
1981 procedure zsock_destroy(var self: PZsock); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
1982
1983 // Bind a socket to a formatted endpoint. For tcp:// endpoints, supports
1984 // ephemeral ports, if you specify the port number as "*". By default
1985 // zsock uses the IANA designated range from C000 (49152) to FFFF (65535).
1986 // To override this range, follow the "*" with "[first-last]". Either or
1987 // both first and last may be empty. To bind to a random port within the
1988 // range, use "!" in place of "*".
1989 //
1990 // Examples:
1991 // tcp://127.0.0.1:* bind to first free port from C000 up
1992 // tcp://127.0.0.1:! bind to random port from C000 to FFFF
1993 // tcp://127.0.0.1:*[60000-] bind to first free port from 60000 up
1994 // tcp://127.0.0.1:![-60000] bind to random port from C000 to 60000
1995 // tcp://127.0.0.1:![55000-55999]
1996 // bind to random port from 55000 to 55999
1997 //
1998 // On success, returns the actual port number used, for tcp:// endpoints,
1999 // and 0 for other transports. On failure, returns -1. Note that when using
2000 // ephemeral ports, a port may be reused by different services without
2001 // clients being aware. Protocols that run on ephemeral ports should take
2002 // this into account.
2003 function zsock_bind(self: PZsock; Format: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2004
2005 // Returns last bound endpoint, if any.
2006 function zsock_endpoint(self: PZsock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2007
2008 // Unbind a socket from a formatted endpoint.
2009 // Returns 0 if OK, -1 if the endpoint was invalid or the function
2010 // isn't supported.
2011 function zsock_unbind(self: PZsock; Format: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2012
2013 // Connect a socket to a formatted endpoint
2014 // Returns 0 if OK, -1 if the endpoint was invalid.
2015 function zsock_connect(self: PZsock; Format: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2016
2017 // Disconnect a socket from a formatted endpoint
2018 // Returns 0 if OK, -1 if the endpoint was invalid or the function
2019 // isn't supported.
2020 function zsock_disconnect(self: PZsock; Format: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2021
2022 // Attach a socket to zero or more endpoints. If endpoints is not null,
2023 // parses as list of ZeroMQ endpoints, separated by commas, and prefixed by
2024 // '@' (to bind the socket) or '>' (to connect the socket). Returns 0 if all
2025 // endpoints were valid, or -1 if there was a syntax error. If the endpoint
2026 // does not start with '@' or '>', the serverish argument defines whether
2027 // it is used to bind (serverish = true) or connect (serverish = false).
2028 function zsock_attach(self: PZsock; Endpoints: PAnsiChar; Serverish: Boolean): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2029
2030 // Returns socket type as printable constant string.
2031 function zsock_type_str(self: PZsock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2032
2033 // Send a 'picture' message to the socket (or actor). The picture is a
2034 // string that defines the type of each frame. This makes it easy to send
2035 // a complex multiframe message in one call. The picture can contain any
2036 // of these characters, each corresponding to one or two arguments:
2037 //
2038 // i = int (signed)
2039 // 1 = uint8_t
2040 // 2 = uint16_t
2041 // 4 = uint32_t
2042 // 8 = uint64_t
2043 // s = char *
2044 // b = byte *, size_t (2 arguments)
2045 // c = zchunk_t *
2046 // f = zframe_t *
2047 // h = zhashx_t *
2048 // l = zlistx_t * (DRAFT)
2049 // U = zuuid_t *
2050 // p = void * (sends the pointer value, only meaningful over inproc)
2051 // m = zmsg_t * (sends all frames in the zmsg)
2052 // z = sends zero-sized frame (0 arguments)
2053 // u = uint (deprecated)
2054 //
2055 // Note that s, b, c, and f are encoded the same way and the choice is
2056 // offered as a convenience to the sender, which may or may not already
2057 // have data in a zchunk or zframe. Does not change or take ownership of
2058 // any arguments. Returns 0 if successful, -1 if sending failed for any
2059 // reason.
2060 function zsock_send(self: PZsock; Picture: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2061
2062 // Send a 'picture' message to the socket (or actor). This is a va_list
2063 // version of zsock_send (), so please consult its documentation for the
2064 // details.
2065 function zsock_vsend(self: PZsock; Picture: PAnsiChar; Argptr: va_list): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2066
2067 // Receive a 'picture' message to the socket (or actor). See zsock_send for
2068 // the format and meaning of the picture. Returns the picture elements into
2069 // a series of pointers as provided by the caller:
2070 //
2071 // i = int * (stores signed integer)
2072 // 4 = uint32_t * (stores 32-bit unsigned integer)
2073 // 8 = uint64_t * (stores 64-bit unsigned integer)
2074 // s = char ** (allocates new string)
2075 // b = byte **, size_t * (2 arguments) (allocates memory)
2076 // c = zchunk_t ** (creates zchunk)
2077 // f = zframe_t ** (creates zframe)
2078 // U = zuuid_t * (creates a zuuid with the data)
2079 // h = zhashx_t ** (creates zhashx)
2080 // l = zlistx_t ** (creates zlistx) (DRAFT)
2081 // p = void ** (stores pointer)
2082 // m = zmsg_t ** (creates a zmsg with the remaining frames)
2083 // z = null, asserts empty frame (0 arguments)
2084 // u = uint * (stores unsigned integer, deprecated)
2085 //
2086 // Note that zsock_recv creates the returned objects, and the caller must
2087 // destroy them when finished with them. The supplied pointers do not need
2088 // to be initialized. Returns 0 if successful, or -1 if it failed to recv
2089 // a message, in which case the pointers are not modified. When message
2090 // frames are truncated (a short message), sets return values to zero/null.
2091 // If an argument pointer is NULL, does not store any value (skips it).
2092 // An 'n' picture matches an empty frame; if the message does not match,
2093 // the method will return -1.
2094 function zsock_recv(self: PZsock; Picture: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2095
2096 // Receive a 'picture' message from the socket (or actor). This is a
2097 // va_list version of zsock_recv (), so please consult its documentation
2098 // for the details.
2099 function zsock_vrecv(self: PZsock; Picture: PAnsiChar; Argptr: va_list): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2100
2101 // Send a binary encoded 'picture' message to the socket (or actor). This
2102 // method is similar to zsock_send, except the arguments are encoded in a
2103 // binary format that is compatible with zproto, and is designed to reduce
2104 // memory allocations. The pattern argument is a string that defines the
2105 // type of each argument. Supports these argument types:
2106 //
2107 // pattern C type zproto type:
2108 // 1 uint8_t type = "number" size = "1"
2109 // 2 uint16_t type = "number" size = "2"
2110 // 4 uint32_t type = "number" size = "3"
2111 // 8 uint64_t type = "number" size = "4"
2112 // s char *, 0-255 chars type = "string"
2113 // S char *, 0-2^32-1 chars type = "longstr"
2114 // c zchunk_t * type = "chunk"
2115 // f zframe_t * type = "frame"
2116 // u zuuid_t * type = "uuid"
2117 // m zmsg_t * type = "msg"
2118 // p void *, sends pointer value, only over inproc
2119 //
2120 // Does not change or take ownership of any arguments. Returns 0 if
2121 // successful, -1 if sending failed for any reason.
2122 function zsock_bsend(self: PZsock; Picture: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2123
2124 // Receive a binary encoded 'picture' message from the socket (or actor).
2125 // This method is similar to zsock_recv, except the arguments are encoded
2126 // in a binary format that is compatible with zproto, and is designed to
2127 // reduce memory allocations. The pattern argument is a string that defines
2128 // the type of each argument. See zsock_bsend for the supported argument
2129 // types. All arguments must be pointers; this call sets them to point to
2130 // values held on a per-socket basis.
2131 // For types 1, 2, 4 and 8 the caller must allocate the memory itself before
2132 // calling zsock_brecv.
2133 // For types S, the caller must free the value once finished with it, as
2134 // zsock_brecv will allocate the buffer.
2135 // For type s, the caller must not free the value as it is stored in a
2136 // local cache for performance purposes.
2137 // For types c, f, u and m the caller must call the appropriate destructor
2138 // depending on the object as zsock_brecv will create new objects.
2139 // For type p the caller must coordinate with the sender, as it is just a
2140 // pointer value being passed.
2141 function zsock_brecv(self: PZsock; Picture: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2142
2143 // Return socket routing ID if any. This returns 0 if the socket is not
2144 // of type ZMQ_SERVER or if no request was already received on it.
2145 function zsock_routing_id(self: PZsock): Cardinal; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2146
2147 // Set routing ID on socket. The socket MUST be of type ZMQ_SERVER.
2148 // This will be used when sending messages on the socket via the zsock API.
2149 procedure zsock_set_routing_id(self: PZsock; RoutingId: Cardinal); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2150
2151 // Set socket to use unbounded pipes (HWM=0); use this in cases when you are
2152 // totally certain the message volume can fit in memory. This method works
2153 // across all versions of ZeroMQ. Takes a polymorphic socket reference.
2154 procedure zsock_set_unbounded(self: PZsock); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2155
2156 // Send a signal over a socket. A signal is a short message carrying a
2157 // success/failure code (by convention, 0 means OK). Signals are encoded
2158 // to be distinguishable from "normal" messages. Accepts a zsock_t or a
2159 // zactor_t argument, and returns 0 if successful, -1 if the signal could
2160 // not be sent. Takes a polymorphic socket reference.
2161 function zsock_signal(self: PZsock; Status: Byte): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2162
2163 // Wait on a signal. Use this to coordinate between threads, over pipe
2164 // pairs. Blocks until the signal is received. Returns -1 on error, 0 or
2165 // greater on success. Accepts a zsock_t or a zactor_t as argument.
2166 // Takes a polymorphic socket reference.
2167 function zsock_wait(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2168
2169 // If there is a partial message still waiting on the socket, remove and
2170 // discard it. This is useful when reading partial messages, to get specific
2171 // message types.
2172 procedure zsock_flush(self: PZsock); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2173
2174 // Join a group for the RADIO-DISH pattern. Call only on ZMQ_DISH.
2175 // Returns 0 if OK, -1 if failed.
2176 function zsock_join(self: PZsock; Group: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2177
2178 // Leave a group for the RADIO-DISH pattern. Call only on ZMQ_DISH.
2179 // Returns 0 if OK, -1 if failed.
2180 function zsock_leave(self: PZsock; Group: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2181
2182 // Probe the supplied object, and report if it looks like a zsock_t.
2183 // Takes a polymorphic socket reference.
2184 function zsock_is(This: Pointer): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2185
2186 // Probe the supplied reference. If it looks like a zsock_t instance, return
2187 // the underlying libzmq socket handle; else if it looks like a file
2188 // descriptor, return NULL; else if it looks like a libzmq socket handle,
2189 // return the supplied value. Takes a polymorphic socket reference.
2190 function zsock_resolve(This: Pointer): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2191
2192 // Check whether the socket has available message to read.
2193 function zsock_has_in(self: PZsock): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2194
2195 // Get socket option `router_notify`.
2196 // Available from libzmq 4.3.0.
2197 function zsock_router_notify(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2198
2199 // Set socket option `router_notify`.
2200 // Available from libzmq 4.3.0.
2201 procedure zsock_set_router_notify(self: PZsock; RouterNotify: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2202
2203 // Get socket option `multicast_loop`.
2204 // Available from libzmq 4.3.0.
2205 function zsock_multicast_loop(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2206
2207 // Set socket option `multicast_loop`.
2208 // Available from libzmq 4.3.0.
2209 procedure zsock_set_multicast_loop(self: PZsock; MulticastLoop: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2210
2211 // Get socket option `metadata`.
2212 // Available from libzmq 4.3.0.
2213 function zsock_metadata(self: PZsock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2214
2215 // Set socket option `metadata`.
2216 // Available from libzmq 4.3.0.
2217 procedure zsock_set_metadata(self: PZsock; Metadata: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2218
2219 // Get socket option `loopback_fastpath`.
2220 // Available from libzmq 4.3.0.
2221 function zsock_loopback_fastpath(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2222
2223 // Set socket option `loopback_fastpath`.
2224 // Available from libzmq 4.3.0.
2225 procedure zsock_set_loopback_fastpath(self: PZsock; LoopbackFastpath: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2226
2227 // Get socket option `zap_enforce_domain`.
2228 // Available from libzmq 4.3.0.
2229 function zsock_zap_enforce_domain(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2230
2231 // Set socket option `zap_enforce_domain`.
2232 // Available from libzmq 4.3.0.
2233 procedure zsock_set_zap_enforce_domain(self: PZsock; ZapEnforceDomain: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2234
2235 // Get socket option `gssapi_principal_nametype`.
2236 // Available from libzmq 4.3.0.
2237 function zsock_gssapi_principal_nametype(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2238
2239 // Set socket option `gssapi_principal_nametype`.
2240 // Available from libzmq 4.3.0.
2241 procedure zsock_set_gssapi_principal_nametype(self: PZsock; GssapiPrincipalNametype: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2242
2243 // Get socket option `gssapi_service_principal_nametype`.
2244 // Available from libzmq 4.3.0.
2245 function zsock_gssapi_service_principal_nametype(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2246
2247 // Set socket option `gssapi_service_principal_nametype`.
2248 // Available from libzmq 4.3.0.
2249 procedure zsock_set_gssapi_service_principal_nametype(self: PZsock; GssapiServicePrincipalNametype: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2250
2251 // Get socket option `bindtodevice`.
2252 // Available from libzmq 4.3.0.
2253 function zsock_bindtodevice(self: PZsock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2254
2255 // Set socket option `bindtodevice`.
2256 // Available from libzmq 4.3.0.
2257 procedure zsock_set_bindtodevice(self: PZsock; Bindtodevice: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2258
2259 // Get socket option `heartbeat_ivl`.
2260 // Available from libzmq 4.2.0.
2261 function zsock_heartbeat_ivl(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2262
2263 // Set socket option `heartbeat_ivl`.
2264 // Available from libzmq 4.2.0.
2265 procedure zsock_set_heartbeat_ivl(self: PZsock; HeartbeatIvl: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2266
2267 // Get socket option `heartbeat_ttl`.
2268 // Available from libzmq 4.2.0.
2269 function zsock_heartbeat_ttl(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2270
2271 // Set socket option `heartbeat_ttl`.
2272 // Available from libzmq 4.2.0.
2273 procedure zsock_set_heartbeat_ttl(self: PZsock; HeartbeatTtl: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2274
2275 // Get socket option `heartbeat_timeout`.
2276 // Available from libzmq 4.2.0.
2277 function zsock_heartbeat_timeout(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2278
2279 // Set socket option `heartbeat_timeout`.
2280 // Available from libzmq 4.2.0.
2281 procedure zsock_set_heartbeat_timeout(self: PZsock; HeartbeatTimeout: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2282
2283 // Get socket option `use_fd`.
2284 // Available from libzmq 4.2.0.
2285 function zsock_use_fd(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2286
2287 // Set socket option `use_fd`.
2288 // Available from libzmq 4.2.0.
2289 procedure zsock_set_use_fd(self: PZsock; UseFd: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2290
2291 // Set socket option `xpub_manual`.
2292 // Available from libzmq 4.2.0.
2293 procedure zsock_set_xpub_manual(self: PZsock; XpubManual: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2294
2295 // Set socket option `xpub_welcome_msg`.
2296 // Available from libzmq 4.2.0.
2297 procedure zsock_set_xpub_welcome_msg(self: PZsock; XpubWelcomeMsg: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2298
2299 // Set socket option `stream_notify`.
2300 // Available from libzmq 4.2.0.
2301 procedure zsock_set_stream_notify(self: PZsock; StreamNotify: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2302
2303 // Get socket option `invert_matching`.
2304 // Available from libzmq 4.2.0.
2305 function zsock_invert_matching(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2306
2307 // Set socket option `invert_matching`.
2308 // Available from libzmq 4.2.0.
2309 procedure zsock_set_invert_matching(self: PZsock; InvertMatching: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2310
2311 // Set socket option `xpub_verboser`.
2312 // Available from libzmq 4.2.0.
2313 procedure zsock_set_xpub_verboser(self: PZsock; XpubVerboser: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2314
2315 // Get socket option `connect_timeout`.
2316 // Available from libzmq 4.2.0.
2317 function zsock_connect_timeout(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2318
2319 // Set socket option `connect_timeout`.
2320 // Available from libzmq 4.2.0.
2321 procedure zsock_set_connect_timeout(self: PZsock; ConnectTimeout: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2322
2323 // Get socket option `tcp_maxrt`.
2324 // Available from libzmq 4.2.0.
2325 function zsock_tcp_maxrt(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2326
2327 // Set socket option `tcp_maxrt`.
2328 // Available from libzmq 4.2.0.
2329 procedure zsock_set_tcp_maxrt(self: PZsock; TcpMaxrt: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2330
2331 // Get socket option `thread_safe`.
2332 // Available from libzmq 4.2.0.
2333 function zsock_thread_safe(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2334
2335 // Get socket option `multicast_maxtpdu`.
2336 // Available from libzmq 4.2.0.
2337 function zsock_multicast_maxtpdu(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2338
2339 // Set socket option `multicast_maxtpdu`.
2340 // Available from libzmq 4.2.0.
2341 procedure zsock_set_multicast_maxtpdu(self: PZsock; MulticastMaxtpdu: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2342
2343 // Get socket option `vmci_buffer_size`.
2344 // Available from libzmq 4.2.0.
2345 function zsock_vmci_buffer_size(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2346
2347 // Set socket option `vmci_buffer_size`.
2348 // Available from libzmq 4.2.0.
2349 procedure zsock_set_vmci_buffer_size(self: PZsock; VmciBufferSize: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2350
2351 // Get socket option `vmci_buffer_min_size`.
2352 // Available from libzmq 4.2.0.
2353 function zsock_vmci_buffer_min_size(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2354
2355 // Set socket option `vmci_buffer_min_size`.
2356 // Available from libzmq 4.2.0.
2357 procedure zsock_set_vmci_buffer_min_size(self: PZsock; VmciBufferMinSize: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2358
2359 // Get socket option `vmci_buffer_max_size`.
2360 // Available from libzmq 4.2.0.
2361 function zsock_vmci_buffer_max_size(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2362
2363 // Set socket option `vmci_buffer_max_size`.
2364 // Available from libzmq 4.2.0.
2365 procedure zsock_set_vmci_buffer_max_size(self: PZsock; VmciBufferMaxSize: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2366
2367 // Get socket option `vmci_connect_timeout`.
2368 // Available from libzmq 4.2.0.
2369 function zsock_vmci_connect_timeout(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2370
2371 // Set socket option `vmci_connect_timeout`.
2372 // Available from libzmq 4.2.0.
2373 procedure zsock_set_vmci_connect_timeout(self: PZsock; VmciConnectTimeout: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2374
2375 // Get socket option `tos`.
2376 // Available from libzmq 4.1.0.
2377 function zsock_tos(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2378
2379 // Set socket option `tos`.
2380 // Available from libzmq 4.1.0.
2381 procedure zsock_set_tos(self: PZsock; Tos: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2382
2383 // Set socket option `router_handover`.
2384 // Available from libzmq 4.1.0.
2385 procedure zsock_set_router_handover(self: PZsock; RouterHandover: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2386
2387 // Set socket option `connect_rid`.
2388 // Available from libzmq 4.1.0.
2389 procedure zsock_set_connect_rid(self: PZsock; ConnectRid: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2390
2391 // Set socket option `connect_rid` from 32-octet binary
2392 // Available from libzmq 4.1.0.
2393 procedure zsock_set_connect_rid_bin(self: PZsock; ConnectRid: PByte); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2394
2395 // Get socket option `handshake_ivl`.
2396 // Available from libzmq 4.1.0.
2397 function zsock_handshake_ivl(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2398
2399 // Set socket option `handshake_ivl`.
2400 // Available from libzmq 4.1.0.
2401 procedure zsock_set_handshake_ivl(self: PZsock; HandshakeIvl: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2402
2403 // Get socket option `socks_proxy`.
2404 // Available from libzmq 4.1.0.
2405 function zsock_socks_proxy(self: PZsock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2406
2407 // Set socket option `socks_proxy`.
2408 // Available from libzmq 4.1.0.
2409 procedure zsock_set_socks_proxy(self: PZsock; SocksProxy: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2410
2411 // Set socket option `xpub_nodrop`.
2412 // Available from libzmq 4.1.0.
2413 procedure zsock_set_xpub_nodrop(self: PZsock; XpubNodrop: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2414
2415 // Set socket option `router_mandatory`.
2416 // Available from libzmq 4.0.0.
2417 procedure zsock_set_router_mandatory(self: PZsock; RouterMandatory: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2418
2419 // Set socket option `probe_router`.
2420 // Available from libzmq 4.0.0.
2421 procedure zsock_set_probe_router(self: PZsock; ProbeRouter: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2422
2423 // Set socket option `req_relaxed`.
2424 // Available from libzmq 4.0.0.
2425 procedure zsock_set_req_relaxed(self: PZsock; ReqRelaxed: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2426
2427 // Set socket option `req_correlate`.
2428 // Available from libzmq 4.0.0.
2429 procedure zsock_set_req_correlate(self: PZsock; ReqCorrelate: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2430
2431 // Set socket option `conflate`.
2432 // Available from libzmq 4.0.0.
2433 procedure zsock_set_conflate(self: PZsock; Conflate: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2434
2435 // Get socket option `zap_domain`.
2436 // Available from libzmq 4.0.0.
2437 function zsock_zap_domain(self: PZsock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2438
2439 // Set socket option `zap_domain`.
2440 // Available from libzmq 4.0.0.
2441 procedure zsock_set_zap_domain(self: PZsock; ZapDomain: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2442
2443 // Get socket option `mechanism`.
2444 // Available from libzmq 4.0.0.
2445 function zsock_mechanism(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2446
2447 // Get socket option `plain_server`.
2448 // Available from libzmq 4.0.0.
2449 function zsock_plain_server(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2450
2451 // Set socket option `plain_server`.
2452 // Available from libzmq 4.0.0.
2453 procedure zsock_set_plain_server(self: PZsock; PlainServer: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2454
2455 // Get socket option `plain_username`.
2456 // Available from libzmq 4.0.0.
2457 function zsock_plain_username(self: PZsock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2458
2459 // Set socket option `plain_username`.
2460 // Available from libzmq 4.0.0.
2461 procedure zsock_set_plain_username(self: PZsock; PlainUsername: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2462
2463 // Get socket option `plain_password`.
2464 // Available from libzmq 4.0.0.
2465 function zsock_plain_password(self: PZsock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2466
2467 // Set socket option `plain_password`.
2468 // Available from libzmq 4.0.0.
2469 procedure zsock_set_plain_password(self: PZsock; PlainPassword: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2470
2471 // Get socket option `curve_server`.
2472 // Available from libzmq 4.0.0.
2473 function zsock_curve_server(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2474
2475 // Set socket option `curve_server`.
2476 // Available from libzmq 4.0.0.
2477 procedure zsock_set_curve_server(self: PZsock; CurveServer: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2478
2479 // Get socket option `curve_publickey`.
2480 // Available from libzmq 4.0.0.
2481 function zsock_curve_publickey(self: PZsock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2482
2483 // Set socket option `curve_publickey`.
2484 // Available from libzmq 4.0.0.
2485 procedure zsock_set_curve_publickey(self: PZsock; CurvePublickey: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2486
2487 // Set socket option `curve_publickey` from 32-octet binary
2488 // Available from libzmq 4.0.0.
2489 procedure zsock_set_curve_publickey_bin(self: PZsock; CurvePublickey: PByte); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2490
2491 // Get socket option `curve_secretkey`.
2492 // Available from libzmq 4.0.0.
2493 function zsock_curve_secretkey(self: PZsock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2494
2495 // Set socket option `curve_secretkey`.
2496 // Available from libzmq 4.0.0.
2497 procedure zsock_set_curve_secretkey(self: PZsock; CurveSecretkey: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2498
2499 // Set socket option `curve_secretkey` from 32-octet binary
2500 // Available from libzmq 4.0.0.
2501 procedure zsock_set_curve_secretkey_bin(self: PZsock; CurveSecretkey: PByte); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2502
2503 // Get socket option `curve_serverkey`.
2504 // Available from libzmq 4.0.0.
2505 function zsock_curve_serverkey(self: PZsock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2506
2507 // Set socket option `curve_serverkey`.
2508 // Available from libzmq 4.0.0.
2509 procedure zsock_set_curve_serverkey(self: PZsock; CurveServerkey: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2510
2511 // Set socket option `curve_serverkey` from 32-octet binary
2512 // Available from libzmq 4.0.0.
2513 procedure zsock_set_curve_serverkey_bin(self: PZsock; CurveServerkey: PByte); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2514
2515 // Get socket option `gssapi_server`.
2516 // Available from libzmq 4.0.0.
2517 function zsock_gssapi_server(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2518
2519 // Set socket option `gssapi_server`.
2520 // Available from libzmq 4.0.0.
2521 procedure zsock_set_gssapi_server(self: PZsock; GssapiServer: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2522
2523 // Get socket option `gssapi_plaintext`.
2524 // Available from libzmq 4.0.0.
2525 function zsock_gssapi_plaintext(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2526
2527 // Set socket option `gssapi_plaintext`.
2528 // Available from libzmq 4.0.0.
2529 procedure zsock_set_gssapi_plaintext(self: PZsock; GssapiPlaintext: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2530
2531 // Get socket option `gssapi_principal`.
2532 // Available from libzmq 4.0.0.
2533 function zsock_gssapi_principal(self: PZsock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2534
2535 // Set socket option `gssapi_principal`.
2536 // Available from libzmq 4.0.0.
2537 procedure zsock_set_gssapi_principal(self: PZsock; GssapiPrincipal: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2538
2539 // Get socket option `gssapi_service_principal`.
2540 // Available from libzmq 4.0.0.
2541 function zsock_gssapi_service_principal(self: PZsock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2542
2543 // Set socket option `gssapi_service_principal`.
2544 // Available from libzmq 4.0.0.
2545 procedure zsock_set_gssapi_service_principal(self: PZsock; GssapiServicePrincipal: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2546
2547 // Get socket option `ipv6`.
2548 // Available from libzmq 4.0.0.
2549 function zsock_ipv6(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2550
2551 // Set socket option `ipv6`.
2552 // Available from libzmq 4.0.0.
2553 procedure zsock_set_ipv6(self: PZsock; Ipv6: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2554
2555 // Get socket option `immediate`.
2556 // Available from libzmq 4.0.0.
2557 function zsock_immediate(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2558
2559 // Set socket option `immediate`.
2560 // Available from libzmq 4.0.0.
2561 procedure zsock_set_immediate(self: PZsock; Immediate: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2562
2563 // Get socket option `sndhwm`.
2564 // Available from libzmq 3.0.0.
2565 function zsock_sndhwm(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2566
2567 // Set socket option `sndhwm`.
2568 // Available from libzmq 3.0.0.
2569 procedure zsock_set_sndhwm(self: PZsock; Sndhwm: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2570
2571 // Get socket option `rcvhwm`.
2572 // Available from libzmq 3.0.0.
2573 function zsock_rcvhwm(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2574
2575 // Set socket option `rcvhwm`.
2576 // Available from libzmq 3.0.0.
2577 procedure zsock_set_rcvhwm(self: PZsock; Rcvhwm: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2578
2579 // Get socket option `maxmsgsize`.
2580 // Available from libzmq 3.0.0.
2581 function zsock_maxmsgsize(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2582
2583 // Set socket option `maxmsgsize`.
2584 // Available from libzmq 3.0.0.
2585 procedure zsock_set_maxmsgsize(self: PZsock; Maxmsgsize: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2586
2587 // Get socket option `multicast_hops`.
2588 // Available from libzmq 3.0.0.
2589 function zsock_multicast_hops(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2590
2591 // Set socket option `multicast_hops`.
2592 // Available from libzmq 3.0.0.
2593 procedure zsock_set_multicast_hops(self: PZsock; MulticastHops: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2594
2595 // Set socket option `xpub_verbose`.
2596 // Available from libzmq 3.0.0.
2597 procedure zsock_set_xpub_verbose(self: PZsock; XpubVerbose: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2598
2599 // Get socket option `tcp_keepalive`.
2600 // Available from libzmq 3.0.0.
2601 function zsock_tcp_keepalive(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2602
2603 // Set socket option `tcp_keepalive`.
2604 // Available from libzmq 3.0.0.
2605 procedure zsock_set_tcp_keepalive(self: PZsock; TcpKeepalive: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2606
2607 // Get socket option `tcp_keepalive_idle`.
2608 // Available from libzmq 3.0.0.
2609 function zsock_tcp_keepalive_idle(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2610
2611 // Set socket option `tcp_keepalive_idle`.
2612 // Available from libzmq 3.0.0.
2613 procedure zsock_set_tcp_keepalive_idle(self: PZsock; TcpKeepaliveIdle: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2614
2615 // Get socket option `tcp_keepalive_cnt`.
2616 // Available from libzmq 3.0.0.
2617 function zsock_tcp_keepalive_cnt(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2618
2619 // Set socket option `tcp_keepalive_cnt`.
2620 // Available from libzmq 3.0.0.
2621 procedure zsock_set_tcp_keepalive_cnt(self: PZsock; TcpKeepaliveCnt: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2622
2623 // Get socket option `tcp_keepalive_intvl`.
2624 // Available from libzmq 3.0.0.
2625 function zsock_tcp_keepalive_intvl(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2626
2627 // Set socket option `tcp_keepalive_intvl`.
2628 // Available from libzmq 3.0.0.
2629 procedure zsock_set_tcp_keepalive_intvl(self: PZsock; TcpKeepaliveIntvl: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2630
2631 // Get socket option `tcp_accept_filter`.
2632 // Available from libzmq 3.0.0.
2633 function zsock_tcp_accept_filter(self: PZsock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2634
2635 // Set socket option `tcp_accept_filter`.
2636 // Available from libzmq 3.0.0.
2637 procedure zsock_set_tcp_accept_filter(self: PZsock; TcpAcceptFilter: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2638
2639 // Get socket option `last_endpoint`.
2640 // Available from libzmq 3.0.0.
2641 function zsock_last_endpoint(self: PZsock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2642
2643 // Set socket option `router_raw`.
2644 // Available from libzmq 3.0.0.
2645 procedure zsock_set_router_raw(self: PZsock; RouterRaw: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2646
2647 // Get socket option `ipv4only`.
2648 // Available from libzmq 3.0.0.
2649 function zsock_ipv4only(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2650
2651 // Set socket option `ipv4only`.
2652 // Available from libzmq 3.0.0.
2653 procedure zsock_set_ipv4only(self: PZsock; Ipv4only: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2654
2655 // Set socket option `delay_attach_on_connect`.
2656 // Available from libzmq 3.0.0.
2657 procedure zsock_set_delay_attach_on_connect(self: PZsock; DelayAttachOnConnect: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2658
2659 // Get socket option `hwm`.
2660 // Available from libzmq 2.0.0 to 3.0.0.
2661 function zsock_hwm(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2662
2663 // Set socket option `hwm`.
2664 // Available from libzmq 2.0.0 to 3.0.0.
2665 procedure zsock_set_hwm(self: PZsock; Hwm: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2666
2667 // Get socket option `swap`.
2668 // Available from libzmq 2.0.0 to 3.0.0.
2669 function zsock_swap(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2670
2671 // Set socket option `swap`.
2672 // Available from libzmq 2.0.0 to 3.0.0.
2673 procedure zsock_set_swap(self: PZsock; Swap: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2674
2675 // Get socket option `affinity`.
2676 // Available from libzmq 2.0.0.
2677 function zsock_affinity(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2678
2679 // Set socket option `affinity`.
2680 // Available from libzmq 2.0.0.
2681 procedure zsock_set_affinity(self: PZsock; Affinity: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2682
2683 // Get socket option `identity`.
2684 // Available from libzmq 2.0.0.
2685 function zsock_identity(self: PZsock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2686
2687 // Set socket option `identity`.
2688 // Available from libzmq 2.0.0.
2689 procedure zsock_set_identity(self: PZsock; Identity: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2690
2691 // Get socket option `rate`.
2692 // Available from libzmq 2.0.0.
2693 function zsock_rate(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2694
2695 // Set socket option `rate`.
2696 // Available from libzmq 2.0.0.
2697 procedure zsock_set_rate(self: PZsock; Rate: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2698
2699 // Get socket option `recovery_ivl`.
2700 // Available from libzmq 2.0.0.
2701 function zsock_recovery_ivl(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2702
2703 // Set socket option `recovery_ivl`.
2704 // Available from libzmq 2.0.0.
2705 procedure zsock_set_recovery_ivl(self: PZsock; RecoveryIvl: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2706
2707 // Get socket option `recovery_ivl_msec`.
2708 // Available from libzmq 2.0.0 to 3.0.0.
2709 function zsock_recovery_ivl_msec(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2710
2711 // Set socket option `recovery_ivl_msec`.
2712 // Available from libzmq 2.0.0 to 3.0.0.
2713 procedure zsock_set_recovery_ivl_msec(self: PZsock; RecoveryIvlMsec: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2714
2715 // Get socket option `mcast_loop`.
2716 // Available from libzmq 2.0.0 to 3.0.0.
2717 function zsock_mcast_loop(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2718
2719 // Set socket option `mcast_loop`.
2720 // Available from libzmq 2.0.0 to 3.0.0.
2721 procedure zsock_set_mcast_loop(self: PZsock; McastLoop: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2722
2723 // Get socket option `rcvtimeo`.
2724 // Available from libzmq 2.2.0.
2725 function zsock_rcvtimeo(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2726
2727 // Set socket option `rcvtimeo`.
2728 // Available from libzmq 2.2.0.
2729 procedure zsock_set_rcvtimeo(self: PZsock; Rcvtimeo: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2730
2731 // Get socket option `sndtimeo`.
2732 // Available from libzmq 2.2.0.
2733 function zsock_sndtimeo(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2734
2735 // Set socket option `sndtimeo`.
2736 // Available from libzmq 2.2.0.
2737 procedure zsock_set_sndtimeo(self: PZsock; Sndtimeo: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2738
2739 // Get socket option `sndbuf`.
2740 // Available from libzmq 2.0.0.
2741 function zsock_sndbuf(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2742
2743 // Set socket option `sndbuf`.
2744 // Available from libzmq 2.0.0.
2745 procedure zsock_set_sndbuf(self: PZsock; Sndbuf: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2746
2747 // Get socket option `rcvbuf`.
2748 // Available from libzmq 2.0.0.
2749 function zsock_rcvbuf(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2750
2751 // Set socket option `rcvbuf`.
2752 // Available from libzmq 2.0.0.
2753 procedure zsock_set_rcvbuf(self: PZsock; Rcvbuf: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2754
2755 // Get socket option `linger`.
2756 // Available from libzmq 2.0.0.
2757 function zsock_linger(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2758
2759 // Set socket option `linger`.
2760 // Available from libzmq 2.0.0.
2761 procedure zsock_set_linger(self: PZsock; Linger: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2762
2763 // Get socket option `reconnect_ivl`.
2764 // Available from libzmq 2.0.0.
2765 function zsock_reconnect_ivl(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2766
2767 // Set socket option `reconnect_ivl`.
2768 // Available from libzmq 2.0.0.
2769 procedure zsock_set_reconnect_ivl(self: PZsock; ReconnectIvl: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2770
2771 // Get socket option `reconnect_ivl_max`.
2772 // Available from libzmq 2.0.0.
2773 function zsock_reconnect_ivl_max(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2774
2775 // Set socket option `reconnect_ivl_max`.
2776 // Available from libzmq 2.0.0.
2777 procedure zsock_set_reconnect_ivl_max(self: PZsock; ReconnectIvlMax: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2778
2779 // Get socket option `backlog`.
2780 // Available from libzmq 2.0.0.
2781 function zsock_backlog(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2782
2783 // Set socket option `backlog`.
2784 // Available from libzmq 2.0.0.
2785 procedure zsock_set_backlog(self: PZsock; Backlog: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2786
2787 // Set socket option `subscribe`.
2788 // Available from libzmq 2.0.0.
2789 procedure zsock_set_subscribe(self: PZsock; Subscribe: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2790
2791 // Set socket option `unsubscribe`.
2792 // Available from libzmq 2.0.0.
2793 procedure zsock_set_unsubscribe(self: PZsock; Unsubscribe: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2794
2795 // Get socket option `type`.
2796 // Available from libzmq 2.0.0.
2797 function zsock_type(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2798
2799 // Get socket option `rcvmore`.
2800 // Available from libzmq 2.0.0.
2801 function zsock_rcvmore(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2802
2803 // Get socket option `fd`.
2804 // Available from libzmq 2.0.0.
2805 function zsock_fd(self: PZsock): TSocket; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2806
2807 // Get socket option `events`.
2808 // Available from libzmq 2.0.0.
2809 function zsock_events(self: PZsock): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2810
2811 // Self test of this class.
2812 procedure zsock_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2813
2814 (* Zstr *)
2815 (* sending and receiving strings *)
2816
2817 // Receive C string from socket. Caller must free returned string using
2818 // zstr_free(). Returns NULL if the context is being terminated or the
2819 // process was interrupted.
2820 function zstr_recv(Source: PZSock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2821
2822 // Receive a series of strings (until NULL) from multipart data.
2823 // Each string is allocated and filled with string data; if there
2824 // are not enough frames, unallocated strings are set to NULL.
2825 // Returns -1 if the message could not be read, else returns the
2826 // number of strings filled, zero or more. Free each returned string
2827 // using zstr_free(). If not enough strings are provided, remaining
2828 // multipart frames in the message are dropped.
2829 function zstr_recvx(Source: PZSock; var StringP: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2830
2831 // De-compress and receive C string from socket, received as a message
2832 // with two frames: size of the uncompressed string, and the string itself.
2833 // Caller must free returned string using zstr_free(). Returns NULL if the
2834 // context is being terminated or the process was interrupted.
2835 function zstr_recv_compress(Source: PZSock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2836
2837 // Send a C string to a socket, as a frame. The string is sent without
2838 // trailing null byte; to read this you can use zstr_recv, or a similar
2839 // method that adds a null terminator on the received string. String
2840 // may be NULL, which is sent as "".
2841 function zstr_send(Dest: PZSock; &String: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2842
2843 // Send a C string to a socket, as zstr_send(), with a MORE flag, so that
2844 // you can send further strings in the same multi-part message.
2845 function zstr_sendm(Dest: PZSock; &String: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2846
2847 // Send a formatted string to a socket. Note that you should NOT use
2848 // user-supplied strings in the format (they may contain '%' which
2849 // will create security holes).
2850 function zstr_sendf(Dest: PZSock; Format: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2851
2852 // Send a formatted string to a socket, as for zstr_sendf(), with a
2853 // MORE flag, so that you can send further strings in the same multi-part
2854 // message.
2855 function zstr_sendfm(Dest: PZSock; Format: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2856
2857 // Send a series of strings (until NULL) as multipart data
2858 // Returns 0 if the strings could be sent OK, or -1 on error.
2859 function zstr_sendx(Dest: PZSock; &String: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2860
2861 // Compress and send a C string to a socket, as a message with two frames:
2862 // size of the uncompressed string, and the string itself. The string is
2863 // sent without trailing null byte; to read this you can use
2864 // zstr_recv_compress, or a similar method that de-compresses and adds a
2865 // null terminator on the received string.
2866 function zstr_send_compress(Dest: PZSock; &String: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2867
2868 // Compress and send a C string to a socket, as zstr_send_compress(),
2869 // with a MORE flag, so that you can send further strings in the same
2870 // multi-part message.
2871 function zstr_sendm_compress(Dest: PZSock; &String: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2872
2873 // Accepts a void pointer and returns a fresh character string. If source
2874 // is null, returns an empty string.
2875 function zstr_str(Source: PZSock): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2876
2877 // Free a provided string, and nullify the parent pointer. Safe to call on
2878 // a null pointer.
2879 procedure zstr_free(var StringP: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2880
2881 // Self test of this class.
2882 procedure zstr_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2883
2884 (* Zsys *)
2885 (* *)
2886
2887 type
2888
2889 // Callback for interrupt signal handler
2890 TZsysHandlerFn = procedure(SignalValue: Integer); stdcall;
2891 PZsysHandlerFn = ^TZsysHandlerFn;
2892
2893 // Initialize CZMQ zsys layer; this happens automatically when you create
2894 // a socket or an actor; however this call lets you force initialization
2895 // earlier, so e.g. logging is properly set-up before you start working.
2896 // Not threadsafe, so call only from main thread. Safe to call multiple
2897 // times. Returns global CZMQ context.
2898 function zsys_init: Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2899
2900 // Optionally shut down the CZMQ zsys layer; this normally happens automatically
2901 // when the process exits; however this call lets you force a shutdown
2902 // earlier, avoiding any potential problems with atexit() ordering, especially
2903 // with Windows dlls.
2904 procedure zsys_shutdown; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2905
2906 // Get a new ZMQ socket, automagically creating a ZMQ context if this is
2907 // the first time. Caller is responsible for destroying the ZMQ socket
2908 // before process exits, to avoid a ZMQ deadlock. Note: you should not use
2909 // this method in CZMQ apps, use zsock_new() instead.
2910 // *** This is for CZMQ internal use only and may change arbitrarily ***
2911 function zsys_socket(&Type: Integer; Filename: PAnsiChar; LineNbr: NativeUInt): Pointer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2912
2913 // Destroy/close a ZMQ socket. You should call this for every socket you
2914 // create using zsys_socket().
2915 // *** This is for CZMQ internal use only and may change arbitrarily ***
2916 function zsys_close(Handle: Pointer; Filename: PAnsiChar; LineNbr: NativeUInt): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2917
2918 // Return ZMQ socket name for socket type
2919 // *** This is for CZMQ internal use only and may change arbitrarily ***
2920 function zsys_sockname(Socktype: Integer): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2921
2922 // Create a pipe, which consists of two PAIR sockets connected over inproc.
2923 // The pipe is configured to use the zsys_pipehwm setting. Returns the
2924 // frontend socket successful, NULL if failed.
2925 function zsys_create_pipe(var BackendP: PZsock): PZsock; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2926
2927 // Set interrupt handler; this saves the default handlers so that a
2928 // zsys_handler_reset () can restore them. If you call this multiple times
2929 // then the last handler will take affect. If handler_fn is NULL, disables
2930 // default SIGINT/SIGTERM handling in CZMQ.
2931 procedure zsys_handler_set(HandlerFn: PZsysHandlerFn); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2932
2933 // Reset interrupt handler, call this at exit if needed
2934 procedure zsys_handler_reset; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2935
2936 // Set default interrupt handler, so Ctrl-C or SIGTERM will set
2937 // zsys_interrupted. Idempotent; safe to call multiple times.
2938 // Can be suppressed by ZSYS_SIGHANDLER=false
2939 // *** This is for CZMQ internal use only and may change arbitrarily ***
2940 procedure zsys_catch_interrupts; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2941
2942 // Check if default interrupt handler of Ctrl-C or SIGTERM was called.
2943 // Does not work if ZSYS_SIGHANDLER is false and code does not call
2944 // set interrupted on signal.
2945 function zsys_is_interrupted: Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2946
2947 // Set interrupted flag. This is done by default signal handler, however
2948 // this can be handy for language bindings or cases without default
2949 // signal handler.
2950 procedure zsys_set_interrupted; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2951
2952 // Return 1 if file exists, else zero
2953 function zsys_file_exists(Filename: PAnsiChar): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2954
2955 // Return file modification time. Returns 0 if the file does not exist.
2956 function zsys_file_modified(Filename: PAnsiChar): Int64; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2957
2958 // Return file mode; provides at least support for the POSIX S_ISREG(m)
2959 // and S_ISDIR(m) macros and the S_IRUSR and S_IWUSR bits, on all boxes.
2960 // Returns a mode_t cast to int, or -1 in case of error.
2961 function zsys_file_mode(Filename: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2962
2963 // Delete file. Does not complain if the file is absent
2964 function zsys_file_delete(Filename: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2965
2966 // Check if file is 'stable'
2967 function zsys_file_stable(Filename: PAnsiChar): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2968
2969 // Create a file path if it doesn't exist. The file path is treated as
2970 // printf format.
2971 function zsys_dir_create(Pathname: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2972
2973 // Remove a file path if empty; the pathname is treated as printf format.
2974 function zsys_dir_delete(Pathname: PAnsiChar): Integer; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2975
2976 // Move to a specified working directory. Returns 0 if OK, -1 if this failed.
2977 function zsys_dir_change(Pathname: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2978
2979 // Set private file creation mode; all files created from here will be
2980 // readable/writable by the owner only.
2981 procedure zsys_file_mode_private; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2982
2983 // Reset default file creation mode; all files created from here will use
2984 // process file mode defaults.
2985 procedure zsys_file_mode_default; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2986
2987 // Return the CZMQ version for run-time API detection; returns version
2988 // number into provided fields, providing reference isn't null in each case.
2989 procedure zsys_version(var Major: Integer; var Minor: Integer; var Patch: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2990
2991 // Format a string using printf formatting, returning a freshly allocated
2992 // buffer. If there was insufficient memory, returns NULL. Free the returned
2993 // string using zstr_free(). The hinted version allows to optimize by using
2994 // a larger starting buffer size (known to/assumed by the developer) and so
2995 // avoid reallocations.
2996 function zsys_sprintf_hint(Hint: Integer; Format: PAnsiChar): PAnsiChar; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
2997
2998 // Format a string using printf formatting, returning a freshly allocated
2999 // buffer. If there was insufficient memory, returns NULL. Free the returned
3000 // string using zstr_free().
3001 function zsys_sprintf(Format: PAnsiChar): PAnsiChar; cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3002
3003 // Format a string with a va_list argument, returning a freshly allocated
3004 // buffer. If there was insufficient memory, returns NULL. Free the returned
3005 // string using zstr_free().
3006 function zsys_vprintf(Format: PAnsiChar; Argptr: va_list): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3007
3008 // Create UDP beacon socket; if the routable option is true, uses
3009 // multicast (not yet implemented), else uses broadcast. This method
3010 // and related ones might _eventually_ be moved to a zudp class.
3011 // *** This is for CZMQ internal use only and may change arbitrarily ***
3012 function zsys_udp_new(Routable: Boolean): TSocket; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3013
3014 // Close a UDP socket
3015 // *** This is for CZMQ internal use only and may change arbitrarily ***
3016 function zsys_udp_close(Handle: TSocket): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3017
3018 // Send zframe to UDP socket, return -1 if sending failed due to
3019 // interface having disappeared (happens easily with WiFi)
3020 // *** This is for CZMQ internal use only and may change arbitrarily ***
3021 function zsys_udp_send(Udpsock: TSocket; Frame: PZframe; Address: Pointer; Addrlen: Integer): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3022
3023 // Receive zframe from UDP socket, and set address of peer that sent it
3024 // The peername must be a char [INET_ADDRSTRLEN] array if IPv6 is disabled or
3025 // NI_MAXHOST if it's enabled. Returns NULL when failing to get peer address.
3026 // *** This is for CZMQ internal use only and may change arbitrarily ***
3027 function zsys_udp_recv(Udpsock: TSocket; Peername: PAnsiChar; Peerlen: Integer): PZframe; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3028
3029 // Handle an I/O error on some socket operation; will report and die on
3030 // fatal errors, and continue silently on "try again" errors.
3031 // *** This is for CZMQ internal use only and may change arbitrarily ***
3032 procedure zsys_socket_error(Reason: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3033
3034 // Return current host name, for use in public tcp:// endpoints. Caller gets
3035 // a freshly allocated string, should free it using zstr_free(). If the host
3036 // name is not resolvable, returns NULL.
3037 function zsys_hostname: PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3038
3039 // Move the current process into the background. The precise effect depends
3040 // on the operating system. On POSIX boxes, moves to a specified working
3041 // directory (if specified), closes all file handles, reopens stdin, stdout,
3042 // and stderr to the null device, and sets the process to ignore SIGHUP. On
3043 // Windows, does nothing. Returns 0 if OK, -1 if there was an error.
3044 function zsys_daemonize(Workdir: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3045
3046 // Drop the process ID into the lockfile, with exclusive lock, and switch
3047 // the process to the specified group and/or user. Any of the arguments
3048 // may be null, indicating a no-op. Returns 0 on success, -1 on failure.
3049 // Note if you combine this with zsys_daemonize, run after, not before
3050 // that method, or the lockfile will hold the wrong process ID.
3051 function zsys_run_as(Lockfile: PAnsiChar; Group: PAnsiChar; User: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3052
3053 // Returns true if the underlying libzmq supports CURVE security.
3054 // Uses a heuristic probe according to the version of libzmq being used.
3055 function zsys_has_curve: Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3056
3057 // Configure the number of I/O threads that ZeroMQ will use. A good
3058 // rule of thumb is one thread per gigabit of traffic in or out. The
3059 // default is 1, sufficient for most applications. If the environment
3060 // variable ZSYS_IO_THREADS is defined, that provides the default.
3061 // Note that this method is valid only before any socket is created.
3062 procedure zsys_set_io_threads(IoThreads: NativeUInt); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3063
3064 // Configure the scheduling policy of the ZMQ context thread pool.
3065 // Not available on Windows. See the sched_setscheduler man page or sched.h
3066 // for more information. If the environment variable ZSYS_THREAD_SCHED_POLICY
3067 // is defined, that provides the default.
3068 // Note that this method is valid only before any socket is created.
3069 procedure zsys_set_thread_sched_policy(Policy: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3070
3071 // Configure the scheduling priority of the ZMQ context thread pool.
3072 // Not available on Windows. See the sched_setscheduler man page or sched.h
3073 // for more information. If the environment variable ZSYS_THREAD_PRIORITY is
3074 // defined, that provides the default.
3075 // Note that this method is valid only before any socket is created.
3076 procedure zsys_set_thread_priority(Priority: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3077
3078 // Configure the numeric prefix to each thread created for the internal
3079 // context's thread pool. This option is only supported on Linux.
3080 // If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
3081 // provides the default.
3082 // Note that this method is valid only before any socket is created.
3083 procedure zsys_set_thread_name_prefix(Prefix: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3084
3085 // Return thread name prefix.
3086 function zsys_thread_name_prefix: Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3087
3088 // Adds a specific CPU to the affinity list of the ZMQ context thread pool.
3089 // This option is only supported on Linux.
3090 // Note that this method is valid only before any socket is created.
3091 procedure zsys_thread_affinity_cpu_add(Cpu: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3092
3093 // Removes a specific CPU to the affinity list of the ZMQ context thread pool.
3094 // This option is only supported on Linux.
3095 // Note that this method is valid only before any socket is created.
3096 procedure zsys_thread_affinity_cpu_remove(Cpu: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3097
3098 // Configure the number of sockets that ZeroMQ will allow. The default
3099 // is 1024. The actual limit depends on the system, and you can query it
3100 // by using zsys_socket_limit (). A value of zero means "maximum".
3101 // Note that this method is valid only before any socket is created.
3102 procedure zsys_set_max_sockets(MaxSockets: NativeUInt); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3103
3104 // Return maximum number of ZeroMQ sockets that the system will support.
3105 function zsys_socket_limit: NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3106
3107 // Configure the maximum allowed size of a message sent.
3108 // The default is INT_MAX.
3109 procedure zsys_set_max_msgsz(MaxMsgsz: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3110
3111 // Return maximum message size.
3112 function zsys_max_msgsz: Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3113
3114 // Configure whether to use zero copy strategy in libzmq. If the environment
3115 // variable ZSYS_ZERO_COPY_RECV is defined, that provides the default.
3116 // Otherwise the default is 1.
3117 procedure zsys_set_zero_copy_recv(ZeroCopy: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3118
3119 // Return ZMQ_ZERO_COPY_RECV option.
3120 function zsys_zero_copy_recv: Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3121
3122 // Configure the threshold value of filesystem object age per st_mtime
3123 // that should elapse until we consider that object "stable" at the
3124 // current zclock_time() moment.
3125 // The default is S_DEFAULT_ZSYS_FILE_STABLE_AGE_MSEC defined in zsys.c
3126 // which generally depends on host OS, with fallback value of 5000.
3127 procedure zsys_set_file_stable_age_msec(FileStableAgeMsec: Int64); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3128
3129 // Return current threshold value of file stable age in msec.
3130 // This can be used in code that chooses to wait for this timeout
3131 // before testing if a filesystem object is "stable" or not.
3132 function zsys_file_stable_age_msec: Int64; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3133
3134 // Configure the default linger timeout in msecs for new zsock instances.
3135 // You can also set this separately on each zsock_t instance. The default
3136 // linger time is zero, i.e. any pending messages will be dropped. If the
3137 // environment variable ZSYS_LINGER is defined, that provides the default.
3138 // Note that process exit will typically be delayed by the linger time.
3139 procedure zsys_set_linger(Linger: NativeUInt); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3140
3141 // Configure the default outgoing pipe limit (HWM) for new zsock instances.
3142 // You can also set this separately on each zsock_t instance. The default
3143 // HWM is 1,000, on all versions of ZeroMQ. If the environment variable
3144 // ZSYS_SNDHWM is defined, that provides the default. Note that a value of
3145 // zero means no limit, i.e. infinite memory consumption.
3146 procedure zsys_set_sndhwm(Sndhwm: NativeUInt); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3147
3148 // Configure the default incoming pipe limit (HWM) for new zsock instances.
3149 // You can also set this separately on each zsock_t instance. The default
3150 // HWM is 1,000, on all versions of ZeroMQ. If the environment variable
3151 // ZSYS_RCVHWM is defined, that provides the default. Note that a value of
3152 // zero means no limit, i.e. infinite memory consumption.
3153 procedure zsys_set_rcvhwm(Rcvhwm: NativeUInt); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3154
3155 // Configure the default HWM for zactor internal pipes; this is set on both
3156 // ends of the pipe, for outgoing messages only (sndhwm). The default HWM is
3157 // 1,000, on all versions of ZeroMQ. If the environment var ZSYS_ACTORHWM is
3158 // defined, that provides the default. Note that a value of zero means no
3159 // limit, i.e. infinite memory consumption.
3160 procedure zsys_set_pipehwm(Pipehwm: NativeUInt); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3161
3162 // Return the HWM for zactor internal pipes.
3163 function zsys_pipehwm: NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3164
3165 // Configure use of IPv6 for new zsock instances. By default sockets accept
3166 // and make only IPv4 connections. When you enable IPv6, sockets will accept
3167 // and connect to both IPv4 and IPv6 peers. You can override the setting on
3168 // each zsock_t instance. The default is IPv4 only (ipv6 set to 0). If the
3169 // environment variable ZSYS_IPV6 is defined (as 1 or 0), this provides the
3170 // default. Note: has no effect on ZMQ v2.
3171 procedure zsys_set_ipv6(Ipv6: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3172
3173 // Return use of IPv6 for zsock instances.
3174 function zsys_ipv6: Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3175
3176 // Set network interface name to use for broadcasts, particularly zbeacon.
3177 // This lets the interface be configured for test environments where required.
3178 // For example, on Mac OS X, zbeacon cannot bind to 255.255.255.255 which is
3179 // the default when there is no specified interface. If the environment
3180 // variable ZSYS_INTERFACE is set, use that as the default interface name.
3181 // Setting the interface to "*" means "use all available interfaces".
3182 procedure zsys_set_interface(Value: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3183
3184 // Return network interface to use for broadcasts, or "" if none was set.
3185 function zsys_interface: PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3186
3187 // Set IPv6 address to use zbeacon socket, particularly for receiving zbeacon.
3188 // This needs to be set IPv6 is enabled as IPv6 can have multiple addresses
3189 // on a given interface. If the environment variable ZSYS_IPV6_ADDRESS is set,
3190 // use that as the default IPv6 address.
3191 procedure zsys_set_ipv6_address(Value: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3192
3193 // Return IPv6 address to use for zbeacon reception, or "" if none was set.
3194 function zsys_ipv6_address: PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3195
3196 // Set IPv6 milticast address to use for sending zbeacon messages. This needs
3197 // to be set if IPv6 is enabled. If the environment variable
3198 // ZSYS_IPV6_MCAST_ADDRESS is set, use that as the default IPv6 multicast
3199 // address.
3200 procedure zsys_set_ipv6_mcast_address(Value: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3201
3202 // Return IPv6 multicast address to use for sending zbeacon, or "" if none was
3203 // set.
3204 function zsys_ipv6_mcast_address: PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3205
3206 // Configure the automatic use of pre-allocated FDs when creating new sockets.
3207 // If 0 (default), nothing will happen. Else, when a new socket is bound, the
3208 // system API will be used to check if an existing pre-allocated FD with a
3209 // matching port (if TCP) or path (if IPC) exists, and if it does it will be
3210 // set via the ZMQ_USE_FD socket option so that the library will use it
3211 // instead of creating a new socket.
3212 procedure zsys_set_auto_use_fd(AutoUseFd: Integer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3213
3214 // Return use of automatic pre-allocated FDs for zsock instances.
3215 function zsys_auto_use_fd: Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3216
3217 // Print formatted string. Format is specified by variable names
3218 // in Python-like format style
3219 //
3220 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
3221 // become
3222 // "key=value"
3223 //
3224 // Returns freshly allocated string or NULL in a case of error.
3225 // Not enough memory, invalid format specifier, name not in args
3226 function zsys_zprintf(Format: PAnsiChar; Args: PZhash): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3227
3228 // Return error string for given format/args combination.
3229 function zsys_zprintf_error(Format: PAnsiChar; Args: PZhash): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3230
3231 // Print formatted string. Format is specified by variable names
3232 // in Python-like format style
3233 //
3234 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
3235 // become
3236 // "key=value"
3237 //
3238 // Returns freshly allocated string or NULL in a case of error.
3239 // Not enough memory, invalid format specifier, name not in args
3240 function zsys_zplprintf(Format: PAnsiChar; Args: PZconfig): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3241
3242 // Return error string for given format/args combination.
3243 function zsys_zplprintf_error(Format: PAnsiChar; Args: PZconfig): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3244
3245 // Set log identity, which is a string that prefixes all log messages sent
3246 // by this process. The log identity defaults to the environment variable
3247 // ZSYS_LOGIDENT, if that is set.
3248 procedure zsys_set_logident(Value: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3249
3250 // Set stream to receive log traffic. By default, log traffic is sent to
3251 // stdout. If you set the stream to NULL, no stream will receive the log
3252 // traffic (it may still be sent to the system facility).
3253 procedure zsys_set_logstream(Stream: Pointer); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3254
3255 // Sends log output to a PUB socket bound to the specified endpoint. To
3256 // collect such log output, create a SUB socket, subscribe to the traffic
3257 // you care about, and connect to the endpoint. Log traffic is sent as a
3258 // single string frame, in the same format as when sent to stdout. The
3259 // log system supports a single sender; multiple calls to this method will
3260 // bind the same sender to multiple endpoints. To disable the sender, call
3261 // this method with a null argument.
3262 procedure zsys_set_logsender(Endpoint: PAnsiChar); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3263
3264 // Enable or disable logging to the system facility (syslog on POSIX boxes,
3265 // event log on Windows). By default this is disabled.
3266 procedure zsys_set_logsystem(Logsystem: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3267
3268 // Log error condition - highest priority
3269 procedure zsys_error(Format: PAnsiChar); cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3270
3271 // Log warning condition - high priority
3272 procedure zsys_warning(Format: PAnsiChar); cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3273
3274 // Log normal, but significant, condition - normal priority
3275 procedure zsys_notice(Format: PAnsiChar); cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3276
3277 // Log informational message - low priority
3278 procedure zsys_info(Format: PAnsiChar); cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3279
3280 // Log debug-level message - lowest priority
3281 procedure zsys_debug(Format: PAnsiChar); cdecl; varargs; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3282
3283 // Self test of this class.
3284 procedure zsys_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3285
3286 (* Zuuid *)
3287 (* UUID support class *)
3288
3289 // Create a new UUID object.
3290 function zuuid_new: PZuuid; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3291
3292 // Create UUID object from supplied ZUUID_LEN-octet value.
3293 function zuuid_new_from(Source: PByte): PZuuid; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3294
3295 // Destroy a specified UUID object.
3296 procedure zuuid_destroy(var self: PZuuid); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3297
3298 // Set UUID to new supplied ZUUID_LEN-octet value.
3299 procedure zuuid_set(self: PZuuid; Source: PByte); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3300
3301 // Set UUID to new supplied string value skipping '-' and '{' '}'
3302 // optional delimiters. Return 0 if OK, else returns -1.
3303 function zuuid_set_str(self: PZuuid; Source: PAnsiChar): Integer; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3304
3305 // Return UUID binary data.
3306 function zuuid_data(self: PZuuid): PByte; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3307
3308 // Return UUID binary size
3309 function zuuid_size(self: PZuuid): NativeUInt; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3310
3311 // Returns UUID as string
3312 function zuuid_str(self: PZuuid): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3313
3314 // Return UUID in the canonical string format: 8-4-4-4-12, in lower
3315 // case. Caller does not modify or free returned value. See
3316 // http://en.wikipedia.org/wiki/Universally_unique_identifier
3317 function zuuid_str_canonical(self: PZuuid): PAnsiChar; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3318
3319 // Store UUID blob in target array
3320 procedure zuuid_export(self: PZuuid; Target: PByte); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3321
3322 // Check if UUID is same as supplied value
3323 function zuuid_eq(self: PZuuid; Compare: PByte): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3324
3325 // Check if UUID is different from supplied value
3326 function zuuid_neq(self: PZuuid; Compare: PByte): Boolean; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3327
3328 // Make copy of UUID object; if uuid is null, or memory was exhausted,
3329 // returns null.
3330 function zuuid_dup(self: PZuuid): PZuuid; cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3331
3332 // Self test of this class.
3333 procedure zuuid_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3334
3335 (* Zauth *)
3336 (* *)
3337
3338 // Self test of this class.
3339 procedure zauth_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3340
3341 (* Zbeacon *)
3342 (* *)
3343
3344 // Self test of this class.
3345 procedure zbeacon_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3346
3347 (* Zgossip *)
3348 (* *)
3349
3350 // Self test of this class.
3351 procedure zgossip_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3352
3353 (* Zmonitor *)
3354 (* *)
3355
3356 // Self test of this class.
3357 procedure zmonitor_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3358
3359 (* Zproxy *)
3360 (* *)
3361
3362 // Self test of this class.
3363 procedure zproxy_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3364
3365 (* Zrex *)
3366 (* *)
3367
3368 // Self test of this class.
3369 procedure zrex_test(Verbose: Boolean); cdecl; external lib_czmq {$IFDEF MSWINDOWS}delayed{$ENDIF};
3370 implementation
3371 end.
6565 src/main/c/org_zeromq_czmq_Ztimerset.c
6666 src/main/c/org_zeromq_czmq_Ztrie.c
6767 src/main/c/org_zeromq_czmq_Zuuid.c
68 src/main/c/org_zeromq_czmq_ZhttpClient.c
69 src/main/c/org_zeromq_czmq_ZhttpServer.c
70 src/main/c/org_zeromq_czmq_ZhttpServerOptions.c
71 src/main/c/org_zeromq_czmq_ZhttpRequest.c
72 src/main/c/org_zeromq_czmq_ZhttpResponse.c
6873 )
6974
7075 add_library (czmqjni SHARED ${czmqjni_sources})
4848 This does the following:
4949
5050 * It compiles the CZMQ C sources for Android, into a native library libczmq.so in builds/android/
51 * It compiles the JNI Java classes into a jar file czmq-jni-4.1.1.jar in bindings/jni/build/libs
51 * It compiles the JNI Java classes into a jar file czmq-jni-4.2.0.jar in bindings/jni/build/libs
5252 * It compiles the JNI C sources for Android, into a native library libczmqjni.so.
5353 * It combines all these into czmq-android.jar, which you can use in your Android projects.
5454
6565 ../src/main/c/org_zeromq_czmq_Ztimerset.c
6666 ../src/main/c/org_zeromq_czmq_Ztrie.c
6767 ../src/main/c/org_zeromq_czmq_Zuuid.c
68 ../src/main/c/org_zeromq_czmq_ZhttpClient.c
69 ../src/main/c/org_zeromq_czmq_ZhttpServer.c
70 ../src/main/c/org_zeromq_czmq_ZhttpServerOptions.c
71 ../src/main/c/org_zeromq_czmq_ZhttpRequest.c
72 ../src/main/c/org_zeromq_czmq_ZhttpResponse.c
6873 )
6974
7075 add_library (czmqjni SHARED ${czmqjni_sources})
5151
5252 echo "******** Building czmq.jar for Android"
5353 # Copy class files into org/zeromq/etc.
54 unzip -q ../../build/libs/czmq-jni-4.1.1.jar
54 unzip -q ../../build/libs/czmq-jni-4.2.0.jar
5555
5656 # Copy native libraries into lib/armeabi
5757 mkdir -p lib/armeabi
33 # Read the zproject/README.md for information about making permanent changes. #
44 ################################################################################
55 */
6 import static org.apache.tools.ant.taskdefs.condition.Os.*
67
78 plugins {
89 id 'java'
1112 }
1213
1314 group = "org.zeromq"
14 version = "4.1.1"
15 version = "4.2.0"
1516
1617 repositories {
1718 mavenLocal()
1920 jcenter()
2021 }
2122
22 sourceCompatibility = 1.7
23 targetCompatibility = 1.7
23 sourceCompatibility = 1.8
24 targetCompatibility = 1.8
2425
2526 dependencies {
27 compile 'org.scijava:native-lib-loader:2.3.2'
2628 testCompile 'junit:junit:4.12'
2729 testCompile 'org.hamcrest:hamcrest-all:1.3'
2830 }
2931
30 task wrapper(type: Wrapper) {
31 gradleVersion = '2.13'
32 }
32 wrapper.gradleVersion = '5.0'
3333
3434 // ------------------------------------------------------------------
3535 // Build section
3636
3737 task generateJniHeaders(type: Exec, dependsOn: 'classes') {
38 def classpath = sourceSets.main.output.classesDir
38 def classpath = sourceSets.main.output.classesDirs
3939 def appclasspath = configurations.runtime.files*.getAbsolutePath().join(":")
4040 def nativeIncludes = "src/native/include"
4141 def jniClasses = [
42 'org.zeromq.czmq.Zarmour',
43 'org.zeromq.czmq.Zcert',
44 'org.zeromq.czmq.Zcertstore',
45 'org.zeromq.czmq.Zchunk',
46 'org.zeromq.czmq.Zclock',
47 'org.zeromq.czmq.Zconfig',
48 'org.zeromq.czmq.Zdigest',
49 'org.zeromq.czmq.Zdir',
50 'org.zeromq.czmq.ZdirPatch',
51 'org.zeromq.czmq.Zfile',
52 'org.zeromq.czmq.Zframe',
53 'org.zeromq.czmq.Zhash',
54 'org.zeromq.czmq.Zhashx',
55 'org.zeromq.czmq.Ziflist',
56 'org.zeromq.czmq.Zlist',
57 'org.zeromq.czmq.Zlistx',
58 'org.zeromq.czmq.Zloop',
59 'org.zeromq.czmq.Zmsg',
60 'org.zeromq.czmq.Zpoller',
61 'org.zeromq.czmq.Zproc',
62 'org.zeromq.czmq.Zsock',
63 'org.zeromq.czmq.Zstr',
64 'org.zeromq.czmq.Zsys',
65 'org.zeromq.czmq.Ztimerset',
66 'org.zeromq.czmq.Ztrie',
67 'org.zeromq.czmq.Zuuid'
42 'src/main/java/org/zeromq/czmq/Zarmour.java',
43 'src/main/java/org/zeromq/czmq/Zcert.java',
44 'src/main/java/org/zeromq/czmq/Zcertstore.java',
45 'src/main/java/org/zeromq/czmq/Zchunk.java',
46 'src/main/java/org/zeromq/czmq/Zclock.java',
47 'src/main/java/org/zeromq/czmq/Zconfig.java',
48 'src/main/java/org/zeromq/czmq/Zdigest.java',
49 'src/main/java/org/zeromq/czmq/Zdir.java',
50 'src/main/java/org/zeromq/czmq/ZdirPatch.java',
51 'src/main/java/org/zeromq/czmq/Zfile.java',
52 'src/main/java/org/zeromq/czmq/Zframe.java',
53 'src/main/java/org/zeromq/czmq/Zhash.java',
54 'src/main/java/org/zeromq/czmq/Zhashx.java',
55 'src/main/java/org/zeromq/czmq/Ziflist.java',
56 'src/main/java/org/zeromq/czmq/Zlist.java',
57 'src/main/java/org/zeromq/czmq/Zlistx.java',
58 'src/main/java/org/zeromq/czmq/Zloop.java',
59 'src/main/java/org/zeromq/czmq/Zmsg.java',
60 'src/main/java/org/zeromq/czmq/Zpoller.java',
61 'src/main/java/org/zeromq/czmq/Zproc.java',
62 'src/main/java/org/zeromq/czmq/Zsock.java',
63 'src/main/java/org/zeromq/czmq/Zstr.java',
64 'src/main/java/org/zeromq/czmq/Zsys.java',
65 'src/main/java/org/zeromq/czmq/Ztimerset.java',
66 'src/main/java/org/zeromq/czmq/Ztrie.java',
67 'src/main/java/org/zeromq/czmq/Zuuid.java',
68 'src/main/java/org/zeromq/czmq/ZhttpClient.java',
69 'src/main/java/org/zeromq/czmq/ZhttpServer.java',
70 'src/main/java/org/zeromq/czmq/ZhttpServerOptions.java',
71 'src/main/java/org/zeromq/czmq/ZhttpRequest.java',
72 'src/main/java/org/zeromq/czmq/ZhttpResponse.java'
6873 ]
69 commandLine("javah", "-d", "$nativeIncludes", "-classpath", "$classpath:$appclasspath", *jniClasses)
74 commandLine("javac", "-h", "$nativeIncludes", "-classpath", "$classpath:$appclasspath", *jniClasses)
7075 }
7176 tasks.withType(Test) {
7277 systemProperty "java.library.path", "/usr/lib:/usr/local/lib:$projectDir"
7984 }
8085 jar.dependsOn buildNative
8186 test.dependsOn buildNative
87
88 jar {
89 String arch = "${OS_ARCH}".contains("64") ? "64" : "32"
90 String os = "${OS_NAME}".equals("mac") ? "osx" : "${OS_NAME}"
91 from(".") {
92 include("*.so")
93 into("/natives/${os}_${arch}")
94 }
95 }
8296
8397 // ------------------------------------------------------------------
8498 // Install and Publish section
135149 vcsUrl = 'https://github.com/zeromq/czmq.git'
136150 githubRepo = System.getenv('BINTRAY_USER_ORG') + '/czmq'
137151 version {
138 name = '4.1.1'
139 vcsTag= '4.1.1'
152 name = '4.2.0'
153 vcsTag= '4.2.0'
140154 }
141155 }
142156 }
3838 fi
3939
4040 pushd ../../..
41 rm -rf tmp-deps
42 mkdir -p tmp-deps
4143
4244 # Clone and build dependencies
4345 [ -z "$CI_TIME" ] || echo "`date`: Starting build of dependencies (if any)..."
46 BASE_PWD=${PWD}
47 cd tmp-deps
48 wget http://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.44.tar.gz
49 tar -xzf $(basename "http://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.44.tar.gz")
50 cd $(basename "http://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.44.tar.gz" .tar.gz)
51 $CI_TIME ./configure "${CONFIG_OPTS[@]}"
52 $CI_TIME make -j4
53 $CI_TIME make install
54 cd ${BASE_PWD}
55 BASE_PWD=${PWD}
56 cd tmp-deps
4457 $CI_TIME git clone --quiet --depth 1 https://github.com/zeromq/libzmq.git libzmq
4558 cd libzmq
4659 git --no-pager log --oneline -n1
6174 $CI_TIME ./configure "${CONFIG_OPTS[@]}"
6275 $CI_TIME make -j4
6376 $CI_TIME make install
64 cd ..
77 cd ${BASE_PWD}
78
79 BASE_PWD=${PWD}
80 cd tmp-deps
81 $CI_TIME git clone --quiet --depth 1 https://github.com/curl/curl.git libcurl
82 cd libcurl
83 git --no-pager log --oneline -n1
84 if [ -e autogen.sh ]; then
85 $CI_TIME ./autogen.sh 2> /dev/null
86 fi
87 if [ -e buildconf ]; then
88 $CI_TIME ./buildconf 2> /dev/null
89 fi
90 if [ ! -e autogen.sh ] && [ ! -e buildconf ] && [ ! -e ./configure ] && [ -s ./configure.ac ]; then
91 $CI_TIME libtoolize --copy --force && \
92 $CI_TIME aclocal -I . && \
93 $CI_TIME autoheader && \
94 $CI_TIME automake --add-missing --copy && \
95 $CI_TIME autoconf || \
96 $CI_TIME autoreconf -fiv
97 fi
98 $CI_TIME ./configure "${CONFIG_OPTS[@]}"
99 $CI_TIME make -j4
100 $CI_TIME make install
101 cd ${BASE_PWD}
65102
66103 popd
67104 pushd ../..
0 #Tue May 31 16:38:50 CEST 2016
0 #Sun Dec 16 19:15:46 CET 2018
11 distributionBase=GRADLE_USER_HOME
22 distributionPath=wrapper/dists
33 zipStoreBase=GRADLE_USER_HOME
44 zipStorePath=wrapper/dists
5 distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
5 distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip
6161 ECHO Building without lz4
6262 ECHO #undef HAVE_LZ4>> platform.h
6363 )
64 IF EXIST "..\..\..\libcurl" (
65 ECHO Building with libcurl
66 ECHO #define HAVE_LIBCURL 1>> platform.h
67 ) ELSE (
68 ECHO Building without libcurl
69 ECHO #undef HAVE_LIBCURL>> platform.h
70 )
71 IF EXIST "..\..\..\libmicrohttpd" (
72 ECHO Building with libmicrohttpd
73 ECHO #define HAVE_LIBMICROHTTPD 1>> platform.h
74 ) ELSE (
75 ECHO Building without libmicrohttpd
76 ECHO #undef HAVE_LIBMICROHTTPD>> platform.h
77 )
6478
6579 :- Check if we want to build the draft API
6680 if "%1" == "--enable-drafts" goto :with_draft
4848 //
4949
5050 VS_VERSION_INFO VERSIONINFO
51 FILEVERSION 4,1,1,0
52 PRODUCTVERSION 4,1,1,0
51 FILEVERSION 4,2,0,0
52 PRODUCTVERSION 4,2,0,0
5353 FILEFLAGSMASK 0x3fL
5454 #ifdef _DEBUG
5555 FILEFLAGS 0x1L
6666 BEGIN
6767 VALUE "CompanyName", "The AUTHORS"
6868 VALUE "FileDescription", "The high-level C binding for 0MQ"
69 VALUE "FileVersion", "4.1.1.0"
69 VALUE "FileVersion", "4.2.0.0"
7070 VALUE "InternalName", "CZMQ"
7171 VALUE "LegalCopyright", "Copyright (c) the Authors"
7272 VALUE "OriginalFilename", "libczmq.dll"
7373 VALUE "ProductName", "CZMQ"
74 VALUE "ProductVersion", "4.1.1.0"
74 VALUE "ProductVersion", "4.2.0.0"
7575 END
7676 END
7777 BLOCK "VarFileInfo"
8181 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_Zuuid.h GOTO HAVE_Zuuid
8282 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.Zuuid
8383 :HAVE_Zuuid
84 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpClient.h GOTO HAVE_ZhttpClient
85 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpClient
86 :HAVE_ZhttpClient
87 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpServer.h GOTO HAVE_ZhttpServer
88 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpServer
89 :HAVE_ZhttpServer
90 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpServerOptions.h GOTO HAVE_ZhttpServerOptions
91 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpServerOptions
92 :HAVE_ZhttpServerOptions
93 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpRequest.h GOTO HAVE_ZhttpRequest
94 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpRequest
95 :HAVE_ZhttpRequest
96 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpResponse.h GOTO HAVE_ZhttpResponse
97 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpResponse
98 :HAVE_ZhttpResponse
7070 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_Ztimerset.h" />
7171 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_Ztrie.h" />
7272 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_Zuuid.h" />
73 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpClient.h" />
74 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpServer.h" />
75 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpServerOptions.h" />
76 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpRequest.h" />
77 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpResponse.h" />
7378 </ItemGroup>
7479 <ItemGroup>
7580 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_Zarmour.c">
150155 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_Zuuid.c">
151156 <CompileAs>CompileAsC</CompileAs>
152157 </ClCompile>
158 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpClient.c">
159 <CompileAs>CompileAsC</CompileAs>
160 </ClCompile>
161 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpServer.c">
162 <CompileAs>CompileAsC</CompileAs>
163 </ClCompile>
164 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpServerOptions.c">
165 <CompileAs>CompileAsC</CompileAs>
166 </ClCompile>
167 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpRequest.c">
168 <CompileAs>CompileAsC</CompileAs>
169 </ClCompile>
170 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpResponse.c">
171 <CompileAs>CompileAsC</CompileAs>
172 </ClCompile>
153173 </ItemGroup>
154174 <ItemGroup>
155175 <ResourceCompile Include="..\..\resource.rc" />
8484 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_Zuuid.c">
8585 <Filter>src</Filter>
8686 </ClCompile>
87 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpClient.c">
88 <Filter>src</Filter>
89 </ClCompile>
90 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpServer.c">
91 <Filter>src</Filter>
92 </ClCompile>
93 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpServerOptions.c">
94 <Filter>src</Filter>
95 </ClCompile>
96 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpRequest.c">
97 <Filter>src</Filter>
98 </ClCompile>
99 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpResponse.c">
100 <Filter>src</Filter>
101 </ClCompile>
87102 </ItemGroup>
88103 <ItemGroup>
89104 <ClInclude Include="..\..\..\..\..\include\czmq.h">
165180 <Filter>include</Filter>
166181 </ClInclude>
167182 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_Zuuid.h">
183 <Filter>include</Filter>
184 </ClInclude>
185 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpClient.h">
186 <Filter>include</Filter>
187 </ClInclude>
188 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpServer.h">
189 <Filter>include</Filter>
190 </ClInclude>
191 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpServerOptions.h">
192 <Filter>include</Filter>
193 </ClInclude>
194 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpRequest.h">
195 <Filter>include</Filter>
196 </ClInclude>
197 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpResponse.h">
168198 <Filter>include</Filter>
169199 </ClInclude>
170200 </ItemGroup>
8181 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_Zuuid.h GOTO HAVE_Zuuid
8282 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.Zuuid
8383 :HAVE_Zuuid
84 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpClient.h GOTO HAVE_ZhttpClient
85 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpClient
86 :HAVE_ZhttpClient
87 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpServer.h GOTO HAVE_ZhttpServer
88 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpServer
89 :HAVE_ZhttpServer
90 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpServerOptions.h GOTO HAVE_ZhttpServerOptions
91 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpServerOptions
92 :HAVE_ZhttpServerOptions
93 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpRequest.h GOTO HAVE_ZhttpRequest
94 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpRequest
95 :HAVE_ZhttpRequest
96 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpResponse.h GOTO HAVE_ZhttpResponse
97 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpResponse
98 :HAVE_ZhttpResponse
7070 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_Ztimerset.h" />
7171 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_Ztrie.h" />
7272 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_Zuuid.h" />
73 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpClient.h" />
74 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpServer.h" />
75 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpServerOptions.h" />
76 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpRequest.h" />
77 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpResponse.h" />
7378 </ItemGroup>
7479 <ItemGroup>
7580 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_Zarmour.c">
150155 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_Zuuid.c">
151156 <CompileAs>CompileAsC</CompileAs>
152157 </ClCompile>
158 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpClient.c">
159 <CompileAs>CompileAsC</CompileAs>
160 </ClCompile>
161 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpServer.c">
162 <CompileAs>CompileAsC</CompileAs>
163 </ClCompile>
164 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpServerOptions.c">
165 <CompileAs>CompileAsC</CompileAs>
166 </ClCompile>
167 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpRequest.c">
168 <CompileAs>CompileAsC</CompileAs>
169 </ClCompile>
170 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpResponse.c">
171 <CompileAs>CompileAsC</CompileAs>
172 </ClCompile>
153173 </ItemGroup>
154174 <ItemGroup>
155175 <ResourceCompile Include="..\..\resource.rc" />
8484 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_Zuuid.c">
8585 <Filter>src</Filter>
8686 </ClCompile>
87 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpClient.c">
88 <Filter>src</Filter>
89 </ClCompile>
90 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpServer.c">
91 <Filter>src</Filter>
92 </ClCompile>
93 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpServerOptions.c">
94 <Filter>src</Filter>
95 </ClCompile>
96 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpRequest.c">
97 <Filter>src</Filter>
98 </ClCompile>
99 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpResponse.c">
100 <Filter>src</Filter>
101 </ClCompile>
87102 </ItemGroup>
88103 <ItemGroup>
89104 <ClInclude Include="..\..\..\..\..\include\czmq.h">
165180 <Filter>include</Filter>
166181 </ClInclude>
167182 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_Zuuid.h">
183 <Filter>include</Filter>
184 </ClInclude>
185 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpClient.h">
186 <Filter>include</Filter>
187 </ClInclude>
188 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpServer.h">
189 <Filter>include</Filter>
190 </ClInclude>
191 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpServerOptions.h">
192 <Filter>include</Filter>
193 </ClInclude>
194 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpRequest.h">
195 <Filter>include</Filter>
196 </ClInclude>
197 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpResponse.h">
168198 <Filter>include</Filter>
169199 </ClInclude>
170200 </ItemGroup>
8181 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_Zuuid.h GOTO HAVE_Zuuid
8282 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.Zuuid
8383 :HAVE_Zuuid
84 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpClient.h GOTO HAVE_ZhttpClient
85 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpClient
86 :HAVE_ZhttpClient
87 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpServer.h GOTO HAVE_ZhttpServer
88 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpServer
89 :HAVE_ZhttpServer
90 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpServerOptions.h GOTO HAVE_ZhttpServerOptions
91 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpServerOptions
92 :HAVE_ZhttpServerOptions
93 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpRequest.h GOTO HAVE_ZhttpRequest
94 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpRequest
95 :HAVE_ZhttpRequest
96 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpResponse.h GOTO HAVE_ZhttpResponse
97 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpResponse
98 :HAVE_ZhttpResponse
7070 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_Ztimerset.h" />
7171 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_Ztrie.h" />
7272 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_Zuuid.h" />
73 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpClient.h" />
74 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpServer.h" />
75 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpServerOptions.h" />
76 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpRequest.h" />
77 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpResponse.h" />
7378 </ItemGroup>
7479 <ItemGroup>
7580 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_Zarmour.c">
150155 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_Zuuid.c">
151156 <CompileAs>CompileAsC</CompileAs>
152157 </ClCompile>
158 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpClient.c">
159 <CompileAs>CompileAsC</CompileAs>
160 </ClCompile>
161 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpServer.c">
162 <CompileAs>CompileAsC</CompileAs>
163 </ClCompile>
164 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpServerOptions.c">
165 <CompileAs>CompileAsC</CompileAs>
166 </ClCompile>
167 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpRequest.c">
168 <CompileAs>CompileAsC</CompileAs>
169 </ClCompile>
170 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpResponse.c">
171 <CompileAs>CompileAsC</CompileAs>
172 </ClCompile>
153173 </ItemGroup>
154174 <ItemGroup>
155175 <ResourceCompile Include="..\..\resource.rc" />
8484 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_Zuuid.c">
8585 <Filter>src</Filter>
8686 </ClCompile>
87 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpClient.c">
88 <Filter>src</Filter>
89 </ClCompile>
90 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpServer.c">
91 <Filter>src</Filter>
92 </ClCompile>
93 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpServerOptions.c">
94 <Filter>src</Filter>
95 </ClCompile>
96 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpRequest.c">
97 <Filter>src</Filter>
98 </ClCompile>
99 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpResponse.c">
100 <Filter>src</Filter>
101 </ClCompile>
87102 </ItemGroup>
88103 <ItemGroup>
89104 <ClInclude Include="..\..\..\..\..\include\czmq.h">
165180 <Filter>include</Filter>
166181 </ClInclude>
167182 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_Zuuid.h">
183 <Filter>include</Filter>
184 </ClInclude>
185 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpClient.h">
186 <Filter>include</Filter>
187 </ClInclude>
188 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpServer.h">
189 <Filter>include</Filter>
190 </ClInclude>
191 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpServerOptions.h">
192 <Filter>include</Filter>
193 </ClInclude>
194 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpRequest.h">
195 <Filter>include</Filter>
196 </ClInclude>
197 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpResponse.h">
168198 <Filter>include</Filter>
169199 </ClInclude>
170200 </ItemGroup>
8181 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_Zuuid.h GOTO HAVE_Zuuid
8282 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.Zuuid
8383 :HAVE_Zuuid
84 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpClient.h GOTO HAVE_ZhttpClient
85 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpClient
86 :HAVE_ZhttpClient
87 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpServer.h GOTO HAVE_ZhttpServer
88 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpServer
89 :HAVE_ZhttpServer
90 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpServerOptions.h GOTO HAVE_ZhttpServerOptions
91 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpServerOptions
92 :HAVE_ZhttpServerOptions
93 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpRequest.h GOTO HAVE_ZhttpRequest
94 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpRequest
95 :HAVE_ZhttpRequest
96 IF EXIST ..\..\..\src\native\include\org_zeromq_czmq_ZhttpResponse.h GOTO HAVE_ZhttpResponse
97 "%JAVA_HOME%\bin\javah.exe" -d ..\..\..\src\native\include -classpath ..\..\..\src\main\java org.zeromq.czmq.ZhttpResponse
98 :HAVE_ZhttpResponse
7070 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_Ztimerset.h" />
7171 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_Ztrie.h" />
7272 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_Zuuid.h" />
73 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpClient.h" />
74 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpServer.h" />
75 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpServerOptions.h" />
76 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpRequest.h" />
77 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpResponse.h" />
7378 </ItemGroup>
7479 <ItemGroup>
7580 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_Zarmour.c">
150155 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_Zuuid.c">
151156 <CompileAs>CompileAsC</CompileAs>
152157 </ClCompile>
158 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpClient.c">
159 <CompileAs>CompileAsC</CompileAs>
160 </ClCompile>
161 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpServer.c">
162 <CompileAs>CompileAsC</CompileAs>
163 </ClCompile>
164 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpServerOptions.c">
165 <CompileAs>CompileAsC</CompileAs>
166 </ClCompile>
167 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpRequest.c">
168 <CompileAs>CompileAsC</CompileAs>
169 </ClCompile>
170 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpResponse.c">
171 <CompileAs>CompileAsC</CompileAs>
172 </ClCompile>
153173 </ItemGroup>
154174 <ItemGroup>
155175 <ResourceCompile Include="..\..\resource.rc" />
8484 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_Zuuid.c">
8585 <Filter>src</Filter>
8686 </ClCompile>
87 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpClient.c">
88 <Filter>src</Filter>
89 </ClCompile>
90 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpServer.c">
91 <Filter>src</Filter>
92 </ClCompile>
93 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpServerOptions.c">
94 <Filter>src</Filter>
95 </ClCompile>
96 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpRequest.c">
97 <Filter>src</Filter>
98 </ClCompile>
99 <ClCompile Include="..\..\..\src\main\c\org_zeromq_czmq_ZhttpResponse.c">
100 <Filter>src</Filter>
101 </ClCompile>
87102 </ItemGroup>
88103 <ItemGroup>
89104 <ClInclude Include="..\..\..\..\..\include\czmq.h">
165180 <Filter>include</Filter>
166181 </ClInclude>
167182 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_Zuuid.h">
183 <Filter>include</Filter>
184 </ClInclude>
185 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpClient.h">
186 <Filter>include</Filter>
187 </ClInclude>
188 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpServer.h">
189 <Filter>include</Filter>
190 </ClInclude>
191 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpServerOptions.h">
192 <Filter>include</Filter>
193 </ClInclude>
194 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpRequest.h">
195 <Filter>include</Filter>
196 </ClInclude>
197 <ClInclude Include="..\..\..\src\native\include\org_zeromq_czmq_ZhttpResponse.h">
168198 <Filter>include</Filter>
169199 </ClInclude>
170200 </ItemGroup>
155155 }
156156
157157 JNIEXPORT jlong JNICALL
158 Java_org_zeromq_czmq_Zchunk__1_1packx (JNIEnv *env, jclass c, jlong self)
159 {
160 jlong packx_ = (jlong) (intptr_t) zchunk_packx ((zchunk_t **) &self);
161 return packx_;
162 }
163
164 JNIEXPORT jlong JNICALL
158165 Java_org_zeromq_czmq_Zchunk__1_1unpack (JNIEnv *env, jclass c, jlong frame)
159166 {
160167 jlong unpack_ = (jlong) (intptr_t) zchunk_unpack ((zframe_t *) (intptr_t) frame);
4444 zconfig_destroy ((zconfig_t **) &self);
4545 }
4646
47 JNIEXPORT jlong JNICALL
48 Java_org_zeromq_czmq_Zconfig__1_1dup (JNIEnv *env, jclass c, jlong self)
49 {
50 jlong dup_ = (jlong) (intptr_t) zconfig_dup ((zconfig_t *) (intptr_t) self);
51 return dup_;
52 }
53
4754 JNIEXPORT jstring JNICALL
4855 Java_org_zeromq_czmq_Zconfig__1_1name (JNIEnv *env, jclass c, jlong self)
4956 {
235242 Java_org_zeromq_czmq_Zconfig__1_1remove (JNIEnv *env, jclass c, jlong self)
236243 {
237244 zconfig_remove ((zconfig_t **) &self);
245 return self;
238246 }
239247
240248 JNIEXPORT void JNICALL
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <jni.h>
9 #include "czmq.h"
10 #include "org_zeromq_czmq_ZhttpClient.h"
11
12 JNIEXPORT jlong JNICALL
13 Java_org_zeromq_czmq_ZhttpClient__1_1new (JNIEnv *env, jclass c, jboolean verbose)
14 {
15 // Disable CZMQ signal handling; allow Java to deal with it
16 zsys_handler_set (NULL);
17 jlong new_ = (jlong) (intptr_t) zhttp_client_new ((bool) verbose);
18 return new_;
19 }
20
21 JNIEXPORT void JNICALL
22 Java_org_zeromq_czmq_ZhttpClient__1_1destroy (JNIEnv *env, jclass c, jlong self)
23 {
24 zhttp_client_destroy ((zhttp_client_t **) &self);
25 }
26
27 JNIEXPORT void JNICALL
28 Java_org_zeromq_czmq_ZhttpClient__1_1test (JNIEnv *env, jclass c, jboolean verbose)
29 {
30 zhttp_client_test ((bool) verbose);
31 }
32
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <jni.h>
9 #include "czmq.h"
10 #include "org_zeromq_czmq_ZhttpRequest.h"
11
12 JNIEXPORT jlong JNICALL
13 Java_org_zeromq_czmq_ZhttpRequest__1_1new (JNIEnv *env, jclass c)
14 {
15 // Disable CZMQ signal handling; allow Java to deal with it
16 zsys_handler_set (NULL);
17 jlong new_ = (jlong) (intptr_t) zhttp_request_new ();
18 return new_;
19 }
20
21 JNIEXPORT void JNICALL
22 Java_org_zeromq_czmq_ZhttpRequest__1_1destroy (JNIEnv *env, jclass c, jlong self)
23 {
24 zhttp_request_destroy ((zhttp_request_t **) &self);
25 }
26
27 JNIEXPORT jlong JNICALL
28 Java_org_zeromq_czmq_ZhttpRequest__1_1recv (JNIEnv *env, jclass c, jlong self, jlong sock)
29 {
30 jlong recv_ = (jlong) (intptr_t) zhttp_request_recv ((zhttp_request_t *) (intptr_t) self, (zsock_t *) (intptr_t) sock);
31 return recv_;
32 }
33
34 JNIEXPORT jint JNICALL
35 Java_org_zeromq_czmq_ZhttpRequest__1_1send (JNIEnv *env, jclass c, jlong self, jlong client, jint timeout, jlong arg, jlong arg2)
36 {
37 jint send_ = (jint) zhttp_request_send ((zhttp_request_t *) (intptr_t) self, (zhttp_client_t *) (intptr_t) client, (int) timeout, (void *) (intptr_t) arg, (void *) (intptr_t) arg2);
38 return send_;
39 }
40
41 JNIEXPORT jstring JNICALL
42 Java_org_zeromq_czmq_ZhttpRequest__1_1method (JNIEnv *env, jclass c, jlong self)
43 {
44 char *method_ = (char *) zhttp_request_method ((zhttp_request_t *) (intptr_t) self);
45 jstring return_string_ = (*env)->NewStringUTF (env, method_);
46 return return_string_;
47 }
48
49 JNIEXPORT void JNICALL
50 Java_org_zeromq_czmq_ZhttpRequest__1_1setMethod (JNIEnv *env, jclass c, jlong self, jstring method)
51 {
52 char *method_ = (char *) (*env)->GetStringUTFChars (env, method, NULL);
53 zhttp_request_set_method ((zhttp_request_t *) (intptr_t) self, method_);
54 (*env)->ReleaseStringUTFChars (env, method, method_);
55 }
56
57 JNIEXPORT jstring JNICALL
58 Java_org_zeromq_czmq_ZhttpRequest__1_1url (JNIEnv *env, jclass c, jlong self)
59 {
60 char *url_ = (char *) zhttp_request_url ((zhttp_request_t *) (intptr_t) self);
61 jstring return_string_ = (*env)->NewStringUTF (env, url_);
62 return return_string_;
63 }
64
65 JNIEXPORT void JNICALL
66 Java_org_zeromq_czmq_ZhttpRequest__1_1setUrl (JNIEnv *env, jclass c, jlong self, jstring url)
67 {
68 char *url_ = (char *) (*env)->GetStringUTFChars (env, url, NULL);
69 zhttp_request_set_url ((zhttp_request_t *) (intptr_t) self, url_);
70 (*env)->ReleaseStringUTFChars (env, url, url_);
71 }
72
73 JNIEXPORT jstring JNICALL
74 Java_org_zeromq_czmq_ZhttpRequest__1_1contentType (JNIEnv *env, jclass c, jlong self)
75 {
76 char *content_type_ = (char *) zhttp_request_content_type ((zhttp_request_t *) (intptr_t) self);
77 jstring return_string_ = (*env)->NewStringUTF (env, content_type_);
78 return return_string_;
79 }
80
81 JNIEXPORT void JNICALL
82 Java_org_zeromq_czmq_ZhttpRequest__1_1setContentType (JNIEnv *env, jclass c, jlong self, jstring content_type)
83 {
84 char *content_type_ = (char *) (*env)->GetStringUTFChars (env, content_type, NULL);
85 zhttp_request_set_content_type ((zhttp_request_t *) (intptr_t) self, content_type_);
86 (*env)->ReleaseStringUTFChars (env, content_type, content_type_);
87 }
88
89 JNIEXPORT jlong JNICALL
90 Java_org_zeromq_czmq_ZhttpRequest__1_1contentLength (JNIEnv *env, jclass c, jlong self)
91 {
92 jlong content_length_ = (jlong) zhttp_request_content_length ((zhttp_request_t *) (intptr_t) self);
93 return content_length_;
94 }
95
96 JNIEXPORT jlong JNICALL
97 Java_org_zeromq_czmq_ZhttpRequest__1_1headers (JNIEnv *env, jclass c, jlong self)
98 {
99 jlong headers_ = (jlong) (intptr_t) zhttp_request_headers ((zhttp_request_t *) (intptr_t) self);
100 return headers_;
101 }
102
103 JNIEXPORT jstring JNICALL
104 Java_org_zeromq_czmq_ZhttpRequest__1_1content (JNIEnv *env, jclass c, jlong self)
105 {
106 char *content_ = (char *) zhttp_request_content ((zhttp_request_t *) (intptr_t) self);
107 jstring return_string_ = (*env)->NewStringUTF (env, content_);
108 return return_string_;
109 }
110
111 JNIEXPORT jstring JNICALL
112 Java_org_zeromq_czmq_ZhttpRequest__1_1getContent (JNIEnv *env, jclass c, jlong self)
113 {
114 char *get_content_ = (char *) zhttp_request_get_content ((zhttp_request_t *) (intptr_t) self);
115 jstring return_string_ = (*env)->NewStringUTF (env, get_content_);
116 zstr_free (&get_content_);
117 return return_string_;
118 }
119
120 JNIEXPORT void JNICALL
121 Java_org_zeromq_czmq_ZhttpRequest__1_1setContentConst (JNIEnv *env, jclass c, jlong self, jstring content)
122 {
123 char *content_ = (char *) (*env)->GetStringUTFChars (env, content, NULL);
124 zhttp_request_set_content_const ((zhttp_request_t *) (intptr_t) self, content_);
125 (*env)->ReleaseStringUTFChars (env, content, content_);
126 }
127
128 JNIEXPORT void JNICALL
129 Java_org_zeromq_czmq_ZhttpRequest__1_1resetContent (JNIEnv *env, jclass c, jlong self)
130 {
131 zhttp_request_reset_content ((zhttp_request_t *) (intptr_t) self);
132 }
133
134 JNIEXPORT jboolean JNICALL
135 Java_org_zeromq_czmq_ZhttpRequest__1_1match (JNIEnv *env, jclass c, jlong self, jstring method, jstring path)
136 {
137 char *method_ = (char *) (*env)->GetStringUTFChars (env, method, NULL);
138 char *path_ = (char *) (*env)->GetStringUTFChars (env, path, NULL);
139 jboolean match_ = (jboolean) zhttp_request_match ((zhttp_request_t *) (intptr_t) self, method_, path_);
140 (*env)->ReleaseStringUTFChars (env, method, method_);
141 (*env)->ReleaseStringUTFChars (env, path, path_);
142 return match_;
143 }
144
145 JNIEXPORT void JNICALL
146 Java_org_zeromq_czmq_ZhttpRequest__1_1test (JNIEnv *env, jclass c, jboolean verbose)
147 {
148 zhttp_request_test ((bool) verbose);
149 }
150
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <jni.h>
9 #include "czmq.h"
10 #include "org_zeromq_czmq_ZhttpResponse.h"
11
12 JNIEXPORT jlong JNICALL
13 Java_org_zeromq_czmq_ZhttpResponse__1_1new (JNIEnv *env, jclass c)
14 {
15 // Disable CZMQ signal handling; allow Java to deal with it
16 zsys_handler_set (NULL);
17 jlong new_ = (jlong) (intptr_t) zhttp_response_new ();
18 return new_;
19 }
20
21 JNIEXPORT void JNICALL
22 Java_org_zeromq_czmq_ZhttpResponse__1_1destroy (JNIEnv *env, jclass c, jlong self)
23 {
24 zhttp_response_destroy ((zhttp_response_t **) &self);
25 }
26
27 JNIEXPORT jint JNICALL
28 Java_org_zeromq_czmq_ZhttpResponse__1_1send (JNIEnv *env, jclass c, jlong self, jlong sock, jlong connection)
29 {
30 jint send_ = (jint) zhttp_response_send ((zhttp_response_t *) (intptr_t) self, (zsock_t *) (intptr_t) sock, (void **) (intptr_t) &connection);
31 return send_;
32 }
33
34 JNIEXPORT jint JNICALL
35 Java_org_zeromq_czmq_ZhttpResponse__1_1recv (JNIEnv *env, jclass c, jlong self, jlong client, jlong arg, jlong arg2)
36 {
37 jint recv_ = (jint) zhttp_response_recv ((zhttp_response_t *) (intptr_t) self, (zhttp_client_t *) (intptr_t) client, (void **) (intptr_t) &arg, (void **) (intptr_t) &arg2);
38 return recv_;
39 }
40
41 JNIEXPORT jstring JNICALL
42 Java_org_zeromq_czmq_ZhttpResponse__1_1contentType (JNIEnv *env, jclass c, jlong self)
43 {
44 char *content_type_ = (char *) zhttp_response_content_type ((zhttp_response_t *) (intptr_t) self);
45 jstring return_string_ = (*env)->NewStringUTF (env, content_type_);
46 return return_string_;
47 }
48
49 JNIEXPORT void JNICALL
50 Java_org_zeromq_czmq_ZhttpResponse__1_1setContentType (JNIEnv *env, jclass c, jlong self, jstring value)
51 {
52 char *value_ = (char *) (*env)->GetStringUTFChars (env, value, NULL);
53 zhttp_response_set_content_type ((zhttp_response_t *) (intptr_t) self, value_);
54 (*env)->ReleaseStringUTFChars (env, value, value_);
55 }
56
57 JNIEXPORT jint JNICALL
58 Java_org_zeromq_czmq_ZhttpResponse__1_1statusCode (JNIEnv *env, jclass c, jlong self)
59 {
60 jint status_code_ = (jint) zhttp_response_status_code ((zhttp_response_t *) (intptr_t) self);
61 return status_code_;
62 }
63
64 JNIEXPORT void JNICALL
65 Java_org_zeromq_czmq_ZhttpResponse__1_1setStatusCode (JNIEnv *env, jclass c, jlong self, jint status_code)
66 {
67 zhttp_response_set_status_code ((zhttp_response_t *) (intptr_t) self, (uint32_t) status_code);
68 }
69
70 JNIEXPORT jlong JNICALL
71 Java_org_zeromq_czmq_ZhttpResponse__1_1headers (JNIEnv *env, jclass c, jlong self)
72 {
73 jlong headers_ = (jlong) (intptr_t) zhttp_response_headers ((zhttp_response_t *) (intptr_t) self);
74 return headers_;
75 }
76
77 JNIEXPORT jlong JNICALL
78 Java_org_zeromq_czmq_ZhttpResponse__1_1contentLength (JNIEnv *env, jclass c, jlong self)
79 {
80 jlong content_length_ = (jlong) zhttp_response_content_length ((zhttp_response_t *) (intptr_t) self);
81 return content_length_;
82 }
83
84 JNIEXPORT jstring JNICALL
85 Java_org_zeromq_czmq_ZhttpResponse__1_1content (JNIEnv *env, jclass c, jlong self)
86 {
87 char *content_ = (char *) zhttp_response_content ((zhttp_response_t *) (intptr_t) self);
88 jstring return_string_ = (*env)->NewStringUTF (env, content_);
89 return return_string_;
90 }
91
92 JNIEXPORT jstring JNICALL
93 Java_org_zeromq_czmq_ZhttpResponse__1_1getContent (JNIEnv *env, jclass c, jlong self)
94 {
95 char *get_content_ = (char *) zhttp_response_get_content ((zhttp_response_t *) (intptr_t) self);
96 jstring return_string_ = (*env)->NewStringUTF (env, get_content_);
97 zstr_free (&get_content_);
98 return return_string_;
99 }
100
101 JNIEXPORT void JNICALL
102 Java_org_zeromq_czmq_ZhttpResponse__1_1setContentConst (JNIEnv *env, jclass c, jlong self, jstring content)
103 {
104 char *content_ = (char *) (*env)->GetStringUTFChars (env, content, NULL);
105 zhttp_response_set_content_const ((zhttp_response_t *) (intptr_t) self, content_);
106 (*env)->ReleaseStringUTFChars (env, content, content_);
107 }
108
109 JNIEXPORT void JNICALL
110 Java_org_zeromq_czmq_ZhttpResponse__1_1resetContent (JNIEnv *env, jclass c, jlong self)
111 {
112 zhttp_response_reset_content ((zhttp_response_t *) (intptr_t) self);
113 }
114
115 JNIEXPORT void JNICALL
116 Java_org_zeromq_czmq_ZhttpResponse__1_1test (JNIEnv *env, jclass c, jboolean verbose)
117 {
118 zhttp_response_test ((bool) verbose);
119 }
120
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <jni.h>
9 #include "czmq.h"
10 #include "org_zeromq_czmq_ZhttpServer.h"
11
12 JNIEXPORT jlong JNICALL
13 Java_org_zeromq_czmq_ZhttpServer__1_1new (JNIEnv *env, jclass c, jlong options)
14 {
15 // Disable CZMQ signal handling; allow Java to deal with it
16 zsys_handler_set (NULL);
17 jlong new_ = (jlong) (intptr_t) zhttp_server_new ((zhttp_server_options_t *) (intptr_t) options);
18 return new_;
19 }
20
21 JNIEXPORT void JNICALL
22 Java_org_zeromq_czmq_ZhttpServer__1_1destroy (JNIEnv *env, jclass c, jlong self)
23 {
24 zhttp_server_destroy ((zhttp_server_t **) &self);
25 }
26
27 JNIEXPORT jint JNICALL
28 Java_org_zeromq_czmq_ZhttpServer__1_1port (JNIEnv *env, jclass c, jlong self)
29 {
30 jint port_ = (jint) zhttp_server_port ((zhttp_server_t *) (intptr_t) self);
31 return port_;
32 }
33
34 JNIEXPORT void JNICALL
35 Java_org_zeromq_czmq_ZhttpServer__1_1test (JNIEnv *env, jclass c, jboolean verbose)
36 {
37 zhttp_server_test ((bool) verbose);
38 }
39
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <jni.h>
9 #include "czmq.h"
10 #include "org_zeromq_czmq_ZhttpServerOptions.h"
11
12 JNIEXPORT jlong JNICALL
13 Java_org_zeromq_czmq_ZhttpServerOptions__1_1new (JNIEnv *env, jclass c)
14 {
15 // Disable CZMQ signal handling; allow Java to deal with it
16 zsys_handler_set (NULL);
17 jlong new_ = (jlong) (intptr_t) zhttp_server_options_new ();
18 return new_;
19 }
20
21 JNIEXPORT jlong JNICALL
22 Java_org_zeromq_czmq_ZhttpServerOptions__1_1fromConfig (JNIEnv *env, jclass c, jlong config)
23 {
24 jlong from_config_ = (jlong) (intptr_t) zhttp_server_options_from_config ((zconfig_t *) (intptr_t) config);
25 return from_config_;
26 }
27
28 JNIEXPORT void JNICALL
29 Java_org_zeromq_czmq_ZhttpServerOptions__1_1destroy (JNIEnv *env, jclass c, jlong self)
30 {
31 zhttp_server_options_destroy ((zhttp_server_options_t **) &self);
32 }
33
34 JNIEXPORT jint JNICALL
35 Java_org_zeromq_czmq_ZhttpServerOptions__1_1port (JNIEnv *env, jclass c, jlong self)
36 {
37 jint port_ = (jint) zhttp_server_options_port ((zhttp_server_options_t *) (intptr_t) self);
38 return port_;
39 }
40
41 JNIEXPORT void JNICALL
42 Java_org_zeromq_czmq_ZhttpServerOptions__1_1setPort (JNIEnv *env, jclass c, jlong self, jint port)
43 {
44 zhttp_server_options_set_port ((zhttp_server_options_t *) (intptr_t) self, (int) port);
45 }
46
47 JNIEXPORT jstring JNICALL
48 Java_org_zeromq_czmq_ZhttpServerOptions__1_1backendAddress (JNIEnv *env, jclass c, jlong self)
49 {
50 char *backend_address_ = (char *) zhttp_server_options_backend_address ((zhttp_server_options_t *) (intptr_t) self);
51 jstring return_string_ = (*env)->NewStringUTF (env, backend_address_);
52 return return_string_;
53 }
54
55 JNIEXPORT void JNICALL
56 Java_org_zeromq_czmq_ZhttpServerOptions__1_1setBackendAddress (JNIEnv *env, jclass c, jlong self, jstring address)
57 {
58 char *address_ = (char *) (*env)->GetStringUTFChars (env, address, NULL);
59 zhttp_server_options_set_backend_address ((zhttp_server_options_t *) (intptr_t) self, address_);
60 (*env)->ReleaseStringUTFChars (env, address, address_);
61 }
62
63 JNIEXPORT void JNICALL
64 Java_org_zeromq_czmq_ZhttpServerOptions__1_1test (JNIEnv *env, jclass c, jboolean verbose)
65 {
66 zhttp_server_options_test ((bool) verbose);
67 }
68
1818 return new_;
1919 }
2020
21 JNIEXPORT jlong JNICALL
22 Java_org_zeromq_czmq_Zlistx__1_1unpack (JNIEnv *env, jclass c, jlong frame)
23 {
24 jlong unpack_ = (jlong) (intptr_t) zlistx_unpack ((zframe_t *) (intptr_t) frame);
25 return unpack_;
26 }
27
2128 JNIEXPORT void JNICALL
2229 Java_org_zeromq_czmq_Zlistx__1_1destroy (JNIEnv *env, jclass c, jlong self)
2330 {
180187 return dup_;
181188 }
182189
190 JNIEXPORT jlong JNICALL
191 Java_org_zeromq_czmq_Zlistx__1_1pack (JNIEnv *env, jclass c, jlong self)
192 {
193 jlong pack_ = (jlong) (intptr_t) zlistx_pack ((zlistx_t *) (intptr_t) self);
194 return pack_;
195 }
196
183197 JNIEXPORT void JNICALL
184198 Java_org_zeromq_czmq_Zlistx__1_1test (JNIEnv *env, jclass c, jboolean verbose)
185199 {
4747 JNIEXPORT jlong JNICALL
4848 Java_org_zeromq_czmq_Zpoller__1_1wait (JNIEnv *env, jclass c, jlong self, jint timeout)
4949 {
50 jlong wait_ = (jlong) zpoller_wait ((zpoller_t *) (intptr_t) self, (int) timeout);
50 jlong wait_ = (jlong) (intptr_t) zpoller_wait ((zpoller_t *) (intptr_t) self, (int) timeout);
5151 return wait_;
5252 }
5353
119119 }
120120
121121 JNIEXPORT jint JNICALL
122 Java_org_zeromq_czmq_Zproc__1_1wait (JNIEnv *env, jclass c, jlong self, jboolean hang)
122 Java_org_zeromq_czmq_Zproc__1_1wait (JNIEnv *env, jclass c, jlong self, jint timeout)
123123 {
124 jint wait_ = (jint) zproc_wait ((zproc_t *) (intptr_t) self, (bool) hang);
124 jint wait_ = (jint) zproc_wait ((zproc_t *) (intptr_t) self, (int) timeout);
125125 return wait_;
126 }
127
128 JNIEXPORT void JNICALL
129 Java_org_zeromq_czmq_Zproc__1_1shutdown (JNIEnv *env, jclass c, jlong self, jint timeout)
130 {
131 zproc_shutdown ((zproc_t *) (intptr_t) self, (int) timeout);
126132 }
127133
128134 JNIEXPORT jlong JNICALL
356356 return resolve_;
357357 }
358358
359 JNIEXPORT jboolean JNICALL
360 Java_org_zeromq_czmq_Zsock__1_1hasIn (JNIEnv *env, jclass c, jlong self)
361 {
362 jboolean has_in_ = (jboolean) zsock_has_in ((zsock_t *) (intptr_t) self);
363 return has_in_;
364 }
365
366 JNIEXPORT jint JNICALL
367 Java_org_zeromq_czmq_Zsock__1_1routerNotify (JNIEnv *env, jclass c, jlong self)
368 {
369 jint router_notify_ = (jint) zsock_router_notify ((zsock_t *) (intptr_t) self);
370 return router_notify_;
371 }
372
373 JNIEXPORT void JNICALL
374 Java_org_zeromq_czmq_Zsock__1_1setRouterNotify (JNIEnv *env, jclass c, jlong self, jint router_notify)
375 {
376 zsock_set_router_notify ((zsock_t *) (intptr_t) self, (int) router_notify);
377 }
378
379 JNIEXPORT jint JNICALL
380 Java_org_zeromq_czmq_Zsock__1_1multicastLoop (JNIEnv *env, jclass c, jlong self)
381 {
382 jint multicast_loop_ = (jint) zsock_multicast_loop ((zsock_t *) (intptr_t) self);
383 return multicast_loop_;
384 }
385
386 JNIEXPORT void JNICALL
387 Java_org_zeromq_czmq_Zsock__1_1setMulticastLoop (JNIEnv *env, jclass c, jlong self, jint multicast_loop)
388 {
389 zsock_set_multicast_loop ((zsock_t *) (intptr_t) self, (int) multicast_loop);
390 }
391
392 JNIEXPORT jstring JNICALL
393 Java_org_zeromq_czmq_Zsock__1_1metadata (JNIEnv *env, jclass c, jlong self)
394 {
395 char *metadata_ = (char *) zsock_metadata ((zsock_t *) (intptr_t) self);
396 jstring return_string_ = (*env)->NewStringUTF (env, metadata_);
397 zstr_free (&metadata_);
398 return return_string_;
399 }
400
401 JNIEXPORT void JNICALL
402 Java_org_zeromq_czmq_Zsock__1_1setMetadata (JNIEnv *env, jclass c, jlong self, jstring metadata)
403 {
404 char *metadata_ = (char *) (*env)->GetStringUTFChars (env, metadata, NULL);
405 zsock_set_metadata ((zsock_t *) (intptr_t) self, metadata_);
406 (*env)->ReleaseStringUTFChars (env, metadata, metadata_);
407 }
408
409 JNIEXPORT jint JNICALL
410 Java_org_zeromq_czmq_Zsock__1_1loopbackFastpath (JNIEnv *env, jclass c, jlong self)
411 {
412 jint loopback_fastpath_ = (jint) zsock_loopback_fastpath ((zsock_t *) (intptr_t) self);
413 return loopback_fastpath_;
414 }
415
416 JNIEXPORT void JNICALL
417 Java_org_zeromq_czmq_Zsock__1_1setLoopbackFastpath (JNIEnv *env, jclass c, jlong self, jint loopback_fastpath)
418 {
419 zsock_set_loopback_fastpath ((zsock_t *) (intptr_t) self, (int) loopback_fastpath);
420 }
421
422 JNIEXPORT jint JNICALL
423 Java_org_zeromq_czmq_Zsock__1_1zapEnforceDomain (JNIEnv *env, jclass c, jlong self)
424 {
425 jint zap_enforce_domain_ = (jint) zsock_zap_enforce_domain ((zsock_t *) (intptr_t) self);
426 return zap_enforce_domain_;
427 }
428
429 JNIEXPORT void JNICALL
430 Java_org_zeromq_czmq_Zsock__1_1setZapEnforceDomain (JNIEnv *env, jclass c, jlong self, jint zap_enforce_domain)
431 {
432 zsock_set_zap_enforce_domain ((zsock_t *) (intptr_t) self, (int) zap_enforce_domain);
433 }
434
435 JNIEXPORT jint JNICALL
436 Java_org_zeromq_czmq_Zsock__1_1gssapiPrincipalNametype (JNIEnv *env, jclass c, jlong self)
437 {
438 jint gssapi_principal_nametype_ = (jint) zsock_gssapi_principal_nametype ((zsock_t *) (intptr_t) self);
439 return gssapi_principal_nametype_;
440 }
441
442 JNIEXPORT void JNICALL
443 Java_org_zeromq_czmq_Zsock__1_1setGssapiPrincipalNametype (JNIEnv *env, jclass c, jlong self, jint gssapi_principal_nametype)
444 {
445 zsock_set_gssapi_principal_nametype ((zsock_t *) (intptr_t) self, (int) gssapi_principal_nametype);
446 }
447
448 JNIEXPORT jint JNICALL
449 Java_org_zeromq_czmq_Zsock__1_1gssapiServicePrincipalNametype (JNIEnv *env, jclass c, jlong self)
450 {
451 jint gssapi_service_principal_nametype_ = (jint) zsock_gssapi_service_principal_nametype ((zsock_t *) (intptr_t) self);
452 return gssapi_service_principal_nametype_;
453 }
454
455 JNIEXPORT void JNICALL
456 Java_org_zeromq_czmq_Zsock__1_1setGssapiServicePrincipalNametype (JNIEnv *env, jclass c, jlong self, jint gssapi_service_principal_nametype)
457 {
458 zsock_set_gssapi_service_principal_nametype ((zsock_t *) (intptr_t) self, (int) gssapi_service_principal_nametype);
459 }
460
461 JNIEXPORT jstring JNICALL
462 Java_org_zeromq_czmq_Zsock__1_1bindtodevice (JNIEnv *env, jclass c, jlong self)
463 {
464 char *bindtodevice_ = (char *) zsock_bindtodevice ((zsock_t *) (intptr_t) self);
465 jstring return_string_ = (*env)->NewStringUTF (env, bindtodevice_);
466 zstr_free (&bindtodevice_);
467 return return_string_;
468 }
469
470 JNIEXPORT void JNICALL
471 Java_org_zeromq_czmq_Zsock__1_1setBindtodevice (JNIEnv *env, jclass c, jlong self, jstring bindtodevice)
472 {
473 char *bindtodevice_ = (char *) (*env)->GetStringUTFChars (env, bindtodevice, NULL);
474 zsock_set_bindtodevice ((zsock_t *) (intptr_t) self, bindtodevice_);
475 (*env)->ReleaseStringUTFChars (env, bindtodevice, bindtodevice_);
476 }
477
359478 JNIEXPORT jint JNICALL
360479 Java_org_zeromq_czmq_Zsock__1_1heartbeatIvl (JNIEnv *env, jclass c, jlong self)
361480 {
171171 }
172172
173173 JNIEXPORT jstring JNICALL
174 Java_org_zeromq_czmq_Zsys__1_1sprintfHint (JNIEnv *env, jclass c, jint hint, jstring format)
175 {
176 char *format_ = (char *) (*env)->GetStringUTFChars (env, format, NULL);
177 char *sprintf_hint_ = (char *) zsys_sprintf_hint ((int) hint, format_);
178 jstring return_string_ = (*env)->NewStringUTF (env, sprintf_hint_);
179 (*env)->ReleaseStringUTFChars (env, format, format_);
180 return return_string_;
181 }
182
183 JNIEXPORT jstring JNICALL
174184 Java_org_zeromq_czmq_Zsys__1_1sprintf (JNIEnv *env, jclass c, jstring format)
175185 {
176186 char *format_ = (char *) (*env)->GetStringUTFChars (env, format, NULL);
244254 }
245255
246256 JNIEXPORT void JNICALL
257 Java_org_zeromq_czmq_Zsys__1_1setThreadNamePrefix (JNIEnv *env, jclass c, jint prefix)
258 {
259 zsys_set_thread_name_prefix ((int) prefix);
260 }
261
262 JNIEXPORT jint JNICALL
263 Java_org_zeromq_czmq_Zsys__1_1threadNamePrefix (JNIEnv *env, jclass c)
264 {
265 jint thread_name_prefix_ = (jint) zsys_thread_name_prefix ();
266 return thread_name_prefix_;
267 }
268
269 JNIEXPORT void JNICALL
270 Java_org_zeromq_czmq_Zsys__1_1threadAffinityCpuAdd (JNIEnv *env, jclass c, jint cpu)
271 {
272 zsys_thread_affinity_cpu_add ((int) cpu);
273 }
274
275 JNIEXPORT void JNICALL
276 Java_org_zeromq_czmq_Zsys__1_1threadAffinityCpuRemove (JNIEnv *env, jclass c, jint cpu)
277 {
278 zsys_thread_affinity_cpu_remove ((int) cpu);
279 }
280
281 JNIEXPORT void JNICALL
247282 Java_org_zeromq_czmq_Zsys__1_1setMaxSockets (JNIEnv *env, jclass c, jlong max_sockets)
248283 {
249284 zsys_set_max_sockets ((size_t) max_sockets);
400435 return auto_use_fd_;
401436 }
402437
438 JNIEXPORT jstring JNICALL
439 Java_org_zeromq_czmq_Zsys__1_1zprintf (JNIEnv *env, jclass c, jstring format, jlong args)
440 {
441 char *format_ = (char *) (*env)->GetStringUTFChars (env, format, NULL);
442 char *zprintf_ = (char *) zsys_zprintf (format_, (zhash_t *) (intptr_t) args);
443 jstring return_string_ = (*env)->NewStringUTF (env, zprintf_);
444 zstr_free (&zprintf_);
445 (*env)->ReleaseStringUTFChars (env, format, format_);
446 return return_string_;
447 }
448
449 JNIEXPORT jstring JNICALL
450 Java_org_zeromq_czmq_Zsys__1_1zprintfError (JNIEnv *env, jclass c, jstring format, jlong args)
451 {
452 char *format_ = (char *) (*env)->GetStringUTFChars (env, format, NULL);
453 char *zprintf_error_ = (char *) zsys_zprintf_error (format_, (zhash_t *) (intptr_t) args);
454 jstring return_string_ = (*env)->NewStringUTF (env, zprintf_error_);
455 zstr_free (&zprintf_error_);
456 (*env)->ReleaseStringUTFChars (env, format, format_);
457 return return_string_;
458 }
459
460 JNIEXPORT jstring JNICALL
461 Java_org_zeromq_czmq_Zsys__1_1zplprintf (JNIEnv *env, jclass c, jstring format, jlong args)
462 {
463 char *format_ = (char *) (*env)->GetStringUTFChars (env, format, NULL);
464 char *zplprintf_ = (char *) zsys_zplprintf (format_, (zconfig_t *) (intptr_t) args);
465 jstring return_string_ = (*env)->NewStringUTF (env, zplprintf_);
466 zstr_free (&zplprintf_);
467 (*env)->ReleaseStringUTFChars (env, format, format_);
468 return return_string_;
469 }
470
471 JNIEXPORT jstring JNICALL
472 Java_org_zeromq_czmq_Zsys__1_1zplprintfError (JNIEnv *env, jclass c, jstring format, jlong args)
473 {
474 char *format_ = (char *) (*env)->GetStringUTFChars (env, format, NULL);
475 char *zplprintf_error_ = (char *) zsys_zplprintf_error (format_, (zconfig_t *) (intptr_t) args);
476 jstring return_string_ = (*env)->NewStringUTF (env, zplprintf_error_);
477 zstr_free (&zplprintf_error_);
478 (*env)->ReleaseStringUTFChars (env, format, format_);
479 return return_string_;
480 }
481
403482 JNIEXPORT void JNICALL
404483 Java_org_zeromq_czmq_Zsys__1_1setLogident (JNIEnv *env, jclass c, jstring value)
405484 {
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zarmour implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zcert implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zcertstore implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zchunk implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
122127 chunk containing the file data, or NULL if the file could not be read.
123128 */
124129 native static long __slurp (String filename, long maxsize);
125 public Zchunk slurp (String filename, long maxsize) {
130 public static Zchunk slurp (String filename, long maxsize) {
126131 return new Zchunk (__slurp (filename, maxsize));
127132 }
128133 /*
165170 return new Zframe (__pack (self));
166171 }
167172 /*
173 Transform zchunk into a zframe that can be sent in a message.
174 Take ownership of the chunk.
175 */
176 native static long __packx (long self);
177 public void packx () {
178 self = __packx (self);
179 }
180 /*
168181 Transform a zframe into a zchunk.
169182 */
170183 native static long __unpack (long frame);
171 public Zchunk unpack (Zframe frame) {
184 public static Zchunk unpack (Zframe frame) {
172185 return new Zchunk (__unpack (frame.self));
173186 }
174187 /*
190203 Probe the supplied object, and report if it looks like a zchunk_t.
191204 */
192205 native static boolean __is (long self);
193 public boolean is (long self) {
206 public static boolean is (long self) {
194207 return __is (self);
195208 }
196209 /*
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zclock {
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
1924 Sleep for a number of milliseconds
2025 */
2126 native static void __sleep (int msecs);
22 public void sleep (int msecs) {
27 public static void sleep (int msecs) {
2328 __sleep (msecs);
2429 }
2530 /*
2833 timers and time offsets. Use zclock_mono for that instead.
2934 */
3035 native static long __time ();
31 public long time () {
36 public static long time () {
3237 return __time ();
3338 }
3439 /*
3742 so will never be reset backwards, unlike a system clock.
3843 */
3944 native static long __mono ();
40 public long mono () {
45 public static long mono () {
4146 return __mono ();
4247 }
4348 /*
4651 so will never be reset backwards, unlike a system clock.
4752 */
4853 native static long __usecs ();
49 public long usecs () {
54 public static long usecs () {
5055 return __usecs ();
5156 }
5257 /*
5358 Return formatted date/time as fresh string. Free using zstr_free().
5459 */
5560 native static String __timestr ();
56 public String timestr () {
61 public static String timestr () {
5762 return __timestr ();
5863 }
5964 /*
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zconfig implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
5358 self = 0;
5459 }
5560 /*
61 Create copy of zconfig, caller MUST free the value
62 Create copy of config, as new zconfig object. Returns a fresh zconfig_t
63 object. If config is null, or memory was exhausted, returns null.
64 */
65 native static long __dup (long self);
66 public Zconfig dup () {
67 return new Zconfig (__dup (self));
68 }
69 /*
5670 Return name of config item
5771 */
5872 native static String __name (long self);
179193 existing data).
180194 */
181195 native static long __reload (long self);
182 public int reload () {
196 public void reload () {
183197 self = __reload (self);
184 return 0;
185198 }
186199 /*
187200 Load a config tree from a memory chunk
188201 */
189202 native static long __chunkLoad (long chunk);
190 public Zconfig chunkLoad (Zchunk chunk) {
203 public static Zconfig chunkLoad (Zchunk chunk) {
191204 return new Zconfig (__chunkLoad (chunk.self));
192205 }
193206 /*
201214 Load a config tree from a null-terminated string
202215 */
203216 native static long __strLoad (String string);
204 public Zconfig strLoad (String string) {
217 public static Zconfig strLoad (String string) {
205218 return new Zconfig (__strLoad (string));
206219 }
207220 /*
228241 }
229242 /*
230243 Destroy node and subtree (all children)
231 WARNING: manually fixed void -> long
232244 */
233245 native static long __remove (long self);
234 public long remove () {
246 public void remove () {
235247 self = __remove (self);
236 return 0;
237248 }
238249 /*
239250 Print properties of object
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zdigest implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zdir implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
9196 generates virtual filename (minus path, plus alias).
9297 */
9398 native static long __diff (long older, long newer, String alias);
94 public Zlist diff (Zdir older, Zdir newer, String alias) {
99 public static Zlist diff (Zdir older, Zdir newer, String alias) {
95100 return new Zlist (__diff (older.self, newer.self, alias));
96101 }
97102 /*
145150 zlist_destroy (&patches);
146151 */
147152 native static void __watch (long pipe, long unused);
148 public void watch (Zsock pipe, long unused) {
153 public static void watch (Zsock pipe, long unused) {
149154 __watch (pipe.self, unused);
150155 }
151156 /*
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class ZdirPatch implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zfile implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
3136 self = pointer;
3237 }
3338 /*
34 Create new temporary file for writing via tmpfile. File is automaticaly
39 Create new temporary file for writing via tmpfile. File is automatically
3540 deleted on destroy
3641 */
3742 native static long __tmp ();
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zframe implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
6570 Return -1 on error, 0 on success.
6671 */
6772 native static long __send (long self, long dest, int flags);
68 public int send (long dest, int flags) {
73 public void send (long dest, int flags) {
6974 self = __send (self, dest, flags);
70 return 0;
7175 }
7276 /*
7377 Return number of bytes in frame data
198202 Probe the supplied object, and report if it looks like a zframe_t.
199203 */
200204 native static boolean __is (long self);
201 public boolean is (long self) {
205 public static boolean is (long self) {
202206 return __is (self);
203207 }
204208 /*
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zhash implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zhashx implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 package org.zeromq.czmq;
7
8 import org.scijava.nativelib.NativeLoader;
9
10 public class ZhttpClient implements AutoCloseable{
11 static {
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
20 }
21 }
22 public long self;
23 /*
24 Create a new http client
25 */
26 native static long __new (boolean verbose);
27 public ZhttpClient (boolean verbose) {
28 /* TODO: if __new fails, self is null... */
29 self = __new (verbose);
30 }
31 public ZhttpClient (long pointer) {
32 self = pointer;
33 }
34 /*
35 Destroy an http client
36 */
37 native static void __destroy (long self);
38 @Override
39 public void close () {
40 __destroy (self);
41 self = 0;
42 }
43 /*
44 Self test of this class.
45 */
46 native static void __test (boolean verbose);
47 public static void test (boolean verbose) {
48 __test (verbose);
49 }
50 }
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 package org.zeromq.czmq;
7
8 import org.scijava.nativelib.NativeLoader;
9
10 public class ZhttpRequest implements AutoCloseable{
11 static {
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
20 }
21 }
22 public long self;
23 /*
24 Create a new http request.
25 */
26 native static long __new ();
27 public ZhttpRequest () {
28 /* TODO: if __new fails, self is null... */
29 self = __new ();
30 }
31 public ZhttpRequest (long pointer) {
32 self = pointer;
33 }
34 /*
35 Destroy an http request.
36 */
37 native static void __destroy (long self);
38 @Override
39 public void close () {
40 __destroy (self);
41 self = 0;
42 }
43 /*
44 Receive a new request from zhttp_server.
45 Return the underlying connection if successful, to be used when calling zhttp_response_send.
46 */
47 native static long __recv (long self, long sock);
48 public long recv (Zsock sock) {
49 return __recv (self, sock.self);
50 }
51 /*
52 Send a request to zhttp_client.
53 Url and the request path will be concatenated.
54 This behavior is useful for url rewrite and reverse proxy.
55
56 Send also allow two user provided arguments which will be returned with the response.
57 The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an arg.
58 */
59 native static int __send (long self, long client, int timeout, long arg, long arg2);
60 public int send (ZhttpClient client, int timeout, long arg, long arg2) {
61 return __send (self, client.self, timeout, arg, arg2);
62 }
63 /*
64 Get the request method
65 */
66 native static String __method (long self);
67 public String method () {
68 return __method (self);
69 }
70 /*
71 Set the request method
72 */
73 native static void __setMethod (long self, String method);
74 public void setMethod (String method) {
75 __setMethod (self, method);
76 }
77 /*
78 Get the request url.
79 When receiving a request from http server this is only the path part of the url.
80 */
81 native static String __url (long self);
82 public String url () {
83 return __url (self);
84 }
85 /*
86 Set the request url
87 When sending a request to http client this should be full url.
88 */
89 native static void __setUrl (long self, String url);
90 public void setUrl (String url) {
91 __setUrl (self, url);
92 }
93 /*
94 Get the request content type
95 */
96 native static String __contentType (long self);
97 public String contentType () {
98 return __contentType (self);
99 }
100 /*
101 Set the request content type
102 */
103 native static void __setContentType (long self, String contentType);
104 public void setContentType (String contentType) {
105 __setContentType (self, contentType);
106 }
107 /*
108 Get the content length of the request
109 */
110 native static long __contentLength (long self);
111 public long contentLength () {
112 return __contentLength (self);
113 }
114 /*
115 Get the headers of the request
116 */
117 native static long __headers (long self);
118 public Zhash headers () {
119 return new Zhash (__headers (self));
120 }
121 /*
122 Get the content of the request.
123 */
124 native static String __content (long self);
125 public String content () {
126 return __content (self);
127 }
128 /*
129 Get the content of the request.
130 */
131 native static String __getContent (long self);
132 public String getContent () {
133 return __getContent (self);
134 }
135 /*
136 Set the content of the request..
137 The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
138 */
139 native static void __setContentConst (long self, String content);
140 public void setContentConst (String content) {
141 __setContentConst (self, content);
142 }
143 /*
144 Set the content to NULL
145 */
146 native static void __resetContent (long self);
147 public void resetContent () {
148 __resetContent (self);
149 }
150 /*
151 Match the path of the request.
152 Support wildcards with '%s' symbol inside the match string.
153 Matching wildcards until the next '/', '?' or '\0'.
154 On successful match the variadic arguments will be filled with the matching strings.
155 On successful match the method is modifying the url field and break it into substrings.
156 If you need to use the url, do it before matching or take a copy.
157
158 User must not free the variadic arguments as they are part of the url.
159
160 To use the percent symbol, just double it, e.g "%%something".
161
162 Example:
163 if (zhttp_request_match (request, "POST", "/send/%s/%s", &name, &id))
164 */
165 native static boolean __match (long self, String method, String path);
166 public boolean match (String method, String path []) {
167 return __match (self, method, path [0]);
168 }
169 /*
170 Self test of this class.
171 */
172 native static void __test (boolean verbose);
173 public static void test (boolean verbose) {
174 __test (verbose);
175 }
176 }
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 package org.zeromq.czmq;
7
8 import org.scijava.nativelib.NativeLoader;
9
10 public class ZhttpResponse implements AutoCloseable{
11 static {
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
20 }
21 }
22 public long self;
23 /*
24 Create a new zhttp_response.
25 */
26 native static long __new ();
27 public ZhttpResponse () {
28 /* TODO: if __new fails, self is null... */
29 self = __new ();
30 }
31 public ZhttpResponse (long pointer) {
32 self = pointer;
33 }
34 /*
35 Destroy the zhttp_response.
36 */
37 native static void __destroy (long self);
38 @Override
39 public void close () {
40 __destroy (self);
41 self = 0;
42 }
43 /*
44 Send a response to a request.
45 Returns 0 if successful and -1 otherwise.
46 */
47 native static int __send (long self, long sock, long connection);
48 public int send (Zsock sock, long connection) {
49 return __send (self, sock.self, connection);
50 }
51 /*
52 Receive a response from zhttp_client.
53 On success return 0, -1 otherwise.
54
55 Recv returns the two user arguments which was provided with the request.
56 The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an argument.
57 */
58 native static int __recv (long self, long client, long arg, long arg2);
59 public int recv (ZhttpClient client, long arg, long arg2) {
60 return __recv (self, client.self, arg, arg2);
61 }
62 /*
63 Get the response content type
64 */
65 native static String __contentType (long self);
66 public String contentType () {
67 return __contentType (self);
68 }
69 /*
70 Set the content type of the response.
71 */
72 native static void __setContentType (long self, String value);
73 public void setContentType (String value) {
74 __setContentType (self, value);
75 }
76 /*
77 Get the status code of the response.
78 */
79 native static int __statusCode (long self);
80 public int statusCode () {
81 return __statusCode (self);
82 }
83 /*
84 Set the status code of the response.
85 */
86 native static void __setStatusCode (long self, int statusCode);
87 public void setStatusCode (int statusCode) {
88 __setStatusCode (self, statusCode);
89 }
90 /*
91 Get the headers of the response.
92 */
93 native static long __headers (long self);
94 public Zhash headers () {
95 return new Zhash (__headers (self));
96 }
97 /*
98 Get the content length of the response
99 */
100 native static long __contentLength (long self);
101 public long contentLength () {
102 return __contentLength (self);
103 }
104 /*
105 Get the content of the response.
106 */
107 native static String __content (long self);
108 public String content () {
109 return __content (self);
110 }
111 /*
112 Get the content of the response.
113 */
114 native static String __getContent (long self);
115 public String getContent () {
116 return __getContent (self);
117 }
118 /*
119 Set the content of the response.
120 The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
121 */
122 native static void __setContentConst (long self, String content);
123 public void setContentConst (String content) {
124 __setContentConst (self, content);
125 }
126 /*
127 Set the content to NULL
128 */
129 native static void __resetContent (long self);
130 public void resetContent () {
131 __resetContent (self);
132 }
133 /*
134 Self test of this class.
135 */
136 native static void __test (boolean verbose);
137 public static void test (boolean verbose) {
138 __test (verbose);
139 }
140 }
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 package org.zeromq.czmq;
7
8 import org.scijava.nativelib.NativeLoader;
9
10 public class ZhttpServer implements AutoCloseable{
11 static {
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
20 }
21 }
22 public long self;
23 /*
24 Create a new http server
25 */
26 native static long __new (long options);
27 public ZhttpServer (ZhttpServerOptions options) {
28 /* TODO: if __new fails, self is null... */
29 self = __new (options.self);
30 }
31 public ZhttpServer (long pointer) {
32 self = pointer;
33 }
34 /*
35 Destroy an http server
36 */
37 native static void __destroy (long self);
38 @Override
39 public void close () {
40 __destroy (self);
41 self = 0;
42 }
43 /*
44 Return the port the server is listening on.
45 */
46 native static int __port (long self);
47 public int port () {
48 return __port (self);
49 }
50 /*
51 Self test of this class.
52 */
53 native static void __test (boolean verbose);
54 public static void test (boolean verbose) {
55 __test (verbose);
56 }
57 }
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 package org.zeromq.czmq;
7
8 import org.scijava.nativelib.NativeLoader;
9
10 public class ZhttpServerOptions implements AutoCloseable{
11 static {
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
20 }
21 }
22 public long self;
23 /*
24 Create a new zhttp_server_options.
25 */
26 native static long __new ();
27 public ZhttpServerOptions () {
28 /* TODO: if __new fails, self is null... */
29 self = __new ();
30 }
31 public ZhttpServerOptions (long pointer) {
32 self = pointer;
33 }
34 /*
35 Create options from config tree.
36 */
37 native static long __fromConfig (long config);
38 public static ZhttpServerOptions fromConfig (Zconfig config) {
39 return new ZhttpServerOptions (__fromConfig (config.self));
40 }
41 /*
42 Destroy the zhttp_server_options.
43 */
44 native static void __destroy (long self);
45 @Override
46 public void close () {
47 __destroy (self);
48 self = 0;
49 }
50 /*
51 Get the server listening port.
52 */
53 native static int __port (long self);
54 public int port () {
55 return __port (self);
56 }
57 /*
58 Set the server listening port
59 */
60 native static void __setPort (long self, int port);
61 public void setPort (int port) {
62 __setPort (self, port);
63 }
64 /*
65 Get the address sockets should connect to in order to receive requests.
66 */
67 native static String __backendAddress (long self);
68 public String backendAddress () {
69 return __backendAddress (self);
70 }
71 /*
72 Set the address sockets should connect to in order to receive requests.
73 */
74 native static void __setBackendAddress (long self, String address);
75 public void setBackendAddress (String address) {
76 __setBackendAddress (self, address);
77 }
78 /*
79 Self test of this class.
80 */
81 native static void __test (boolean verbose);
82 public static void test (boolean verbose) {
83 __test (verbose);
84 }
85 }
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Ziflist implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
96101 Includes IPv6 interfaces
97102 */
98103 native static long __newIpv6 ();
99 public Ziflist newIpv6 () {
104 public static Ziflist newIpv6 () {
100105 return new Ziflist (__newIpv6 ());
101106 }
102107 /*
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zlist implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zlistx implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
2530 }
2631 public Zlistx (long pointer) {
2732 self = pointer;
33 }
34 /*
35 Unpack binary frame into a new list. Packed data must follow format
36 defined by zlistx_pack. List is set to autofree. An empty frame
37 unpacks to an empty list.
38 */
39 native static long __unpack (long frame);
40 public static Zlistx unpack (Zframe frame) {
41 return new Zlistx (__unpack (frame.self));
2842 }
2943 /*
3044 Destroy a list. If an item destructor was specified, all items in the
130144 in handle is NULL. Asserts that the passed in handle points to a list element.
131145 */
132146 native static long __handleItem (long handle);
133 public long handleItem (long handle) {
147 public static long handleItem (long handle) {
134148 return __handleItem (handle);
135149 }
136150 /*
237251 return new Zlistx (__dup (self));
238252 }
239253 /*
254 Serialize list to a binary frame that can be sent in a message.
255 The packed format is compatible with the 'strings' type implemented by zproto:
256
257 ; A list of strings
258 list = list-count *longstr
259 list-count = number-4
260
261 ; Strings are always length + text contents
262 longstr = number-4 *VCHAR
263
264 ; Numbers are unsigned integers in network byte order
265 number-4 = 4OCTET
266 */
267 native static long __pack (long self);
268 public Zframe pack () {
269 return new Zframe (__pack (self));
270 }
271 /*
240272 Self test of this class.
241273 */
242274 native static void __test (boolean verbose);
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zloop implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zmsg implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
7075 it is a destructor).
7176 */
7277 native static long __send (long self, long dest);
73 public int send (long dest) {
78 public void send (long dest) {
7479 self = __send (self, dest);
75 return 0;
7680 }
7781 /*
7882 Send message to destination socket as part of a multipart sequence, and
8387 it is a destructor).
8488 */
8589 native static long __sendm (long self, long dest);
86 public int sendm (long dest) {
90 public void sendm (long dest) {
8791 self = __sendm (self, dest);
88 return 0;
8992 }
9093 /*
9194 Return size of message, i.e. number of frames (0 or more).
294297 Probe the supplied object, and report if it looks like a zmsg_t.
295298 */
296299 native static boolean __is (long self);
297 public boolean is (long self) {
300 public static boolean is (long self) {
298301 return __is (self);
299302 }
300303 /*
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zpoller implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zproc implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
148153 return __running (self);
149154 }
150155 /*
156 The timeout should be zero or greater, or -1 to wait indefinitely.
151157 wait or poll process status, return return code
152158 */
153 native static int __wait (long self, boolean hang);
154 public int Wait (boolean hang) {
155 return __wait (self, hang);
156 }
157 /*
158 return internal actor, usefull for the polling if process died
159 native static int __wait (long self, int timeout);
160 public int Wait (int timeout) {
161 return __wait (self, timeout);
162 }
163 /*
164 send SIGTERM signal to the subprocess, wait for grace period and
165 eventually send SIGKILL
166 */
167 native static void __shutdown (long self, int timeout);
168 public void shutdown (int timeout) {
169 __shutdown (self, timeout);
170 }
171 /*
172 return internal actor, useful for the polling if process died
159173 */
160174 native static long __actor (long self);
161175 public long actor () {
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zsock implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
262267 c = zchunk_t *
263268 f = zframe_t *
264269 h = zhashx_t *
270 l = zlistx_t * (DRAFT)
265271 U = zuuid_t *
266272 p = void * (sends the pointer value, only meaningful over inproc)
267273 m = zmsg_t * (sends all frames in the zmsg)
292298 f = zframe_t ** (creates zframe)
293299 U = zuuid_t * (creates a zuuid with the data)
294300 h = zhashx_t ** (creates zhashx)
301 l = zlistx_t ** (creates zlistx) (DRAFT)
295302 p = void ** (stores pointer)
296 m = zmsg_t ** (creates a zmsg with the remaing frames)
303 m = zmsg_t ** (creates a zmsg with the remaining frames)
297304 z = null, asserts empty frame (0 arguments)
298305 u = uint * (stores unsigned integer, deprecated)
299306
436443 Takes a polymorphic socket reference.
437444 */
438445 native static boolean __is (long self);
439 public boolean is (long self) {
446 public static boolean is (long self) {
440447 return __is (self);
441448 }
442449 /*
446453 return the supplied value. Takes a polymorphic socket reference.
447454 */
448455 native static long __resolve (long self);
449 public long resolve (long self) {
456 public static long resolve (long self) {
450457 return __resolve (self);
458 }
459 /*
460 Check whether the socket has available message to read.
461 */
462 native static boolean __hasIn (long self);
463 public boolean hasIn () {
464 return __hasIn (self);
465 }
466 /*
467 Get socket option `router_notify`.
468 Available from libzmq 4.3.0.
469 */
470 native static int __routerNotify (long self);
471 public int routerNotify () {
472 return __routerNotify (self);
473 }
474 /*
475 Set socket option `router_notify`.
476 Available from libzmq 4.3.0.
477 */
478 native static void __setRouterNotify (long self, int routerNotify);
479 public void setRouterNotify (int routerNotify) {
480 __setRouterNotify (self, routerNotify);
481 }
482 /*
483 Get socket option `multicast_loop`.
484 Available from libzmq 4.3.0.
485 */
486 native static int __multicastLoop (long self);
487 public int multicastLoop () {
488 return __multicastLoop (self);
489 }
490 /*
491 Set socket option `multicast_loop`.
492 Available from libzmq 4.3.0.
493 */
494 native static void __setMulticastLoop (long self, int multicastLoop);
495 public void setMulticastLoop (int multicastLoop) {
496 __setMulticastLoop (self, multicastLoop);
497 }
498 /*
499 Get socket option `metadata`.
500 Available from libzmq 4.3.0.
501 */
502 native static String __metadata (long self);
503 public String metadata () {
504 return __metadata (self);
505 }
506 /*
507 Set socket option `metadata`.
508 Available from libzmq 4.3.0.
509 */
510 native static void __setMetadata (long self, String metadata);
511 public void setMetadata (String metadata) {
512 __setMetadata (self, metadata);
513 }
514 /*
515 Get socket option `loopback_fastpath`.
516 Available from libzmq 4.3.0.
517 */
518 native static int __loopbackFastpath (long self);
519 public int loopbackFastpath () {
520 return __loopbackFastpath (self);
521 }
522 /*
523 Set socket option `loopback_fastpath`.
524 Available from libzmq 4.3.0.
525 */
526 native static void __setLoopbackFastpath (long self, int loopbackFastpath);
527 public void setLoopbackFastpath (int loopbackFastpath) {
528 __setLoopbackFastpath (self, loopbackFastpath);
529 }
530 /*
531 Get socket option `zap_enforce_domain`.
532 Available from libzmq 4.3.0.
533 */
534 native static int __zapEnforceDomain (long self);
535 public int zapEnforceDomain () {
536 return __zapEnforceDomain (self);
537 }
538 /*
539 Set socket option `zap_enforce_domain`.
540 Available from libzmq 4.3.0.
541 */
542 native static void __setZapEnforceDomain (long self, int zapEnforceDomain);
543 public void setZapEnforceDomain (int zapEnforceDomain) {
544 __setZapEnforceDomain (self, zapEnforceDomain);
545 }
546 /*
547 Get socket option `gssapi_principal_nametype`.
548 Available from libzmq 4.3.0.
549 */
550 native static int __gssapiPrincipalNametype (long self);
551 public int gssapiPrincipalNametype () {
552 return __gssapiPrincipalNametype (self);
553 }
554 /*
555 Set socket option `gssapi_principal_nametype`.
556 Available from libzmq 4.3.0.
557 */
558 native static void __setGssapiPrincipalNametype (long self, int gssapiPrincipalNametype);
559 public void setGssapiPrincipalNametype (int gssapiPrincipalNametype) {
560 __setGssapiPrincipalNametype (self, gssapiPrincipalNametype);
561 }
562 /*
563 Get socket option `gssapi_service_principal_nametype`.
564 Available from libzmq 4.3.0.
565 */
566 native static int __gssapiServicePrincipalNametype (long self);
567 public int gssapiServicePrincipalNametype () {
568 return __gssapiServicePrincipalNametype (self);
569 }
570 /*
571 Set socket option `gssapi_service_principal_nametype`.
572 Available from libzmq 4.3.0.
573 */
574 native static void __setGssapiServicePrincipalNametype (long self, int gssapiServicePrincipalNametype);
575 public void setGssapiServicePrincipalNametype (int gssapiServicePrincipalNametype) {
576 __setGssapiServicePrincipalNametype (self, gssapiServicePrincipalNametype);
577 }
578 /*
579 Get socket option `bindtodevice`.
580 Available from libzmq 4.3.0.
581 */
582 native static String __bindtodevice (long self);
583 public String bindtodevice () {
584 return __bindtodevice (self);
585 }
586 /*
587 Set socket option `bindtodevice`.
588 Available from libzmq 4.3.0.
589 */
590 native static void __setBindtodevice (long self, String bindtodevice);
591 public void setBindtodevice (String bindtodevice) {
592 __setBindtodevice (self, bindtodevice);
451593 }
452594 /*
453595 Get socket option `heartbeat_ivl`.
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zstr {
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
2126 process was interrupted.
2227 */
2328 native static String __recv (long source);
24 public String recv (long source) {
29 public static String recv (long source) {
2530 return __recv (source);
2631 }
2732 /*
3136 context is being terminated or the process was interrupted.
3237 */
3338 native static String __recvCompress (long source);
34 public String recvCompress (long source) {
39 public static String recvCompress (long source) {
3540 return __recvCompress (source);
3641 }
3742 /*
4146 may be NULL, which is sent as "".
4247 */
4348 native static int __send (long dest, String string);
44 public int send (long dest, String string) {
49 public static int send (long dest, String string) {
4550 return __send (dest, string);
4651 }
4752 /*
4954 you can send further strings in the same multi-part message.
5055 */
5156 native static int __sendm (long dest, String string);
52 public int sendm (long dest, String string) {
57 public static int sendm (long dest, String string) {
5358 return __sendm (dest, string);
5459 }
5560 /*
5863 will create security holes).
5964 */
6065 native static int __sendf (long dest, String format);
61 public int sendf (long dest, String format) {
66 public static int sendf (long dest, String format) {
6267 return __sendf (dest, format);
6368 }
6469 /*
6772 message.
6873 */
6974 native static int __sendfm (long dest, String format);
70 public int sendfm (long dest, String format) {
75 public static int sendfm (long dest, String format) {
7176 return __sendfm (dest, format);
7277 }
7378 /*
7580 Returns 0 if the strings could be sent OK, or -1 on error.
7681 */
7782 native static int __sendx (long dest, String string);
78 public int sendx (long dest, String string []) {
83 public static int sendx (long dest, String string []) {
7984 return __sendx (dest, string [0]);
8085 }
8186 /*
8691 null terminator on the received string.
8792 */
8893 native static int __sendCompress (long dest, String string);
89 public int sendCompress (long dest, String string) {
94 public static int sendCompress (long dest, String string) {
9095 return __sendCompress (dest, string);
9196 }
9297 /*
95100 multi-part message.
96101 */
97102 native static int __sendmCompress (long dest, String string);
98 public int sendmCompress (long dest, String string) {
103 public static int sendmCompress (long dest, String string) {
99104 return __sendmCompress (dest, string);
100105 }
101106 /*
103108 is null, returns an empty string.
104109 */
105110 native static String __str (long source);
106 public String str (long source) {
111 public static String str (long source) {
107112 return __str (source);
108113 }
109114 /*
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zsys {
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
2328 times. Returns global CZMQ context.
2429 */
2530 native static long __init ();
26 public long init () {
31 public static long init () {
2732 return __init ();
2833 }
2934 /*
3338 with Windows dlls.
3439 */
3540 native static void __shutdown ();
36 public void shutdown () {
41 public static void shutdown () {
3742 __shutdown ();
3843 }
3944 /*
4449 *** This is for CZMQ internal use only and may change arbitrarily ***
4550 */
4651 native static long __socket (int type, String filename, long lineNbr);
47 public long socket (int type, String filename, long lineNbr) {
52 public static long socket (int type, String filename, long lineNbr) {
4853 return __socket (type, filename, lineNbr);
4954 }
5055 /*
5358 *** This is for CZMQ internal use only and may change arbitrarily ***
5459 */
5560 native static int __close (long handle, String filename, long lineNbr);
56 public int Close (long handle, String filename, long lineNbr) {
61 public static int Close (long handle, String filename, long lineNbr) {
5762 return __close (handle, filename, lineNbr);
5863 }
5964 /*
6166 *** This is for CZMQ internal use only and may change arbitrarily ***
6267 */
6368 native static String __sockname (int socktype);
64 public String sockname (int socktype) {
69 public static String sockname (int socktype) {
6570 return __sockname (socktype);
6671 }
6772 /*
7075 frontend socket successful, NULL if failed.
7176 */
7277 native static long __createPipe (long backendP);
73 public Zsock createPipe (Zsock backendP) {
78 public static Zsock createPipe (Zsock backendP) {
7479 return new Zsock (__createPipe (backendP.self));
7580 }
7681 /*
7782 Reset interrupt handler, call this at exit if needed
7883 */
7984 native static void __handlerReset ();
80 public void handlerReset () {
85 public static void handlerReset () {
8186 __handlerReset ();
8287 }
8388 /*
8489 Set default interrupt handler, so Ctrl-C or SIGTERM will set
8590 zsys_interrupted. Idempotent; safe to call multiple times.
86 Can be supressed by ZSYS_SIGHANDLER=false
91 Can be suppressed by ZSYS_SIGHANDLER=false
8792 *** This is for CZMQ internal use only and may change arbitrarily ***
8893 */
8994 native static void __catchInterrupts ();
90 public void catchInterrupts () {
95 public static void catchInterrupts () {
9196 __catchInterrupts ();
9297 }
9398 /*
96101 set interrupted on signal.
97102 */
98103 native static boolean __isInterrupted ();
99 public boolean isInterrupted () {
104 public static boolean isInterrupted () {
100105 return __isInterrupted ();
101106 }
102107 /*
105110 signal handler.
106111 */
107112 native static void __setInterrupted ();
108 public void setInterrupted () {
113 public static void setInterrupted () {
109114 __setInterrupted ();
110115 }
111116 /*
112117 Return 1 if file exists, else zero
113118 */
114119 native static boolean __fileExists (String filename);
115 public boolean fileExists (String filename) {
120 public static boolean fileExists (String filename) {
116121 return __fileExists (filename);
117122 }
118123 /*
119124 Return file modification time. Returns 0 if the file does not exist.
120125 */
121126 native static long __fileModified (String filename);
122 public long fileModified (String filename) {
127 public static long fileModified (String filename) {
123128 return __fileModified (filename);
124129 }
125130 /*
128133 Returns a mode_t cast to int, or -1 in case of error.
129134 */
130135 native static int __fileMode (String filename);
131 public int fileMode (String filename) {
136 public static int fileMode (String filename) {
132137 return __fileMode (filename);
133138 }
134139 /*
135140 Delete file. Does not complain if the file is absent
136141 */
137142 native static int __fileDelete (String filename);
138 public int fileDelete (String filename) {
143 public static int fileDelete (String filename) {
139144 return __fileDelete (filename);
140145 }
141146 /*
142147 Check if file is 'stable'
143148 */
144149 native static boolean __fileStable (String filename);
145 public boolean fileStable (String filename) {
150 public static boolean fileStable (String filename) {
146151 return __fileStable (filename);
147152 }
148153 /*
150155 printf format.
151156 */
152157 native static int __dirCreate (String pathname);
153 public int dirCreate (String pathname []) {
158 public static int dirCreate (String pathname []) {
154159 return __dirCreate (pathname [0]);
155160 }
156161 /*
157162 Remove a file path if empty; the pathname is treated as printf format.
158163 */
159164 native static int __dirDelete (String pathname);
160 public int dirDelete (String pathname []) {
165 public static int dirDelete (String pathname []) {
161166 return __dirDelete (pathname [0]);
162167 }
163168 /*
164169 Move to a specified working directory. Returns 0 if OK, -1 if this failed.
165170 */
166171 native static int __dirChange (String pathname);
167 public int dirChange (String pathname) {
172 public static int dirChange (String pathname) {
168173 return __dirChange (pathname);
169174 }
170175 /*
172177 readable/writable by the owner only.
173178 */
174179 native static void __fileModePrivate ();
175 public void fileModePrivate () {
180 public static void fileModePrivate () {
176181 __fileModePrivate ();
177182 }
178183 /*
180185 process file mode defaults.
181186 */
182187 native static void __fileModeDefault ();
183 public void fileModeDefault () {
188 public static void fileModeDefault () {
184189 __fileModeDefault ();
185190 }
186191 /*
188193 number into provided fields, providing reference isn't null in each case.
189194 */
190195 native static void __version (int major, int minor, int patch);
191 public void version (int major, int minor, int patch) {
196 public static void version (int major, int minor, int patch) {
192197 __version (major, minor, patch);
198 }
199 /*
200 Format a string using printf formatting, returning a freshly allocated
201 buffer. If there was insufficient memory, returns NULL. Free the returned
202 string using zstr_free(). The hinted version allows to optimize by using
203 a larger starting buffer size (known to/assumed by the developer) and so
204 avoid reallocations.
205 */
206 native static String __sprintfHint (int hint, String format);
207 public static String sprintfHint (int hint, String format) {
208 return __sprintfHint (hint, format);
193209 }
194210 /*
195211 Format a string using printf formatting, returning a freshly allocated
197213 string using zstr_free().
198214 */
199215 native static String __sprintf (String format);
200 public String sprintf (String format) {
216 public static String sprintf (String format) {
201217 return __sprintf (format);
202218 }
203219 /*
206222 *** This is for CZMQ internal use only and may change arbitrarily ***
207223 */
208224 native static void __socketError (String reason);
209 public void socketError (String reason) {
225 public static void socketError (String reason) {
210226 __socketError (reason);
211227 }
212228 /*
215231 name is not resolvable, returns NULL.
216232 */
217233 native static String __hostname ();
218 public String hostname () {
234 public static String hostname () {
219235 return __hostname ();
220236 }
221237 /*
226242 Windows, does nothing. Returns 0 if OK, -1 if there was an error.
227243 */
228244 native static int __daemonize (String workdir);
229 public int daemonize (String workdir) {
245 public static int daemonize (String workdir) {
230246 return __daemonize (workdir);
231247 }
232248 /*
237253 that method, or the lockfile will hold the wrong process ID.
238254 */
239255 native static int __runAs (String lockfile, String group, String user);
240 public int runAs (String lockfile, String group, String user) {
256 public static int runAs (String lockfile, String group, String user) {
241257 return __runAs (lockfile, group, user);
242258 }
243259 /*
245261 Uses a heuristic probe according to the version of libzmq being used.
246262 */
247263 native static boolean __hasCurve ();
248 public boolean hasCurve () {
264 public static boolean hasCurve () {
249265 return __hasCurve ();
250266 }
251267 /*
256272 Note that this method is valid only before any socket is created.
257273 */
258274 native static void __setIoThreads (long ioThreads);
259 public void setIoThreads (long ioThreads) {
275 public static void setIoThreads (long ioThreads) {
260276 __setIoThreads (ioThreads);
261277 }
262278 /*
267283 Note that this method is valid only before any socket is created.
268284 */
269285 native static void __setThreadSchedPolicy (int policy);
270 public void setThreadSchedPolicy (int policy) {
286 public static void setThreadSchedPolicy (int policy) {
271287 __setThreadSchedPolicy (policy);
272288 }
273289 /*
278294 Note that this method is valid only before any socket is created.
279295 */
280296 native static void __setThreadPriority (int priority);
281 public void setThreadPriority (int priority) {
297 public static void setThreadPriority (int priority) {
282298 __setThreadPriority (priority);
299 }
300 /*
301 Configure the numeric prefix to each thread created for the internal
302 context's thread pool. This option is only supported on Linux.
303 If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
304 provides the default.
305 Note that this method is valid only before any socket is created.
306 */
307 native static void __setThreadNamePrefix (int prefix);
308 public static void setThreadNamePrefix (int prefix) {
309 __setThreadNamePrefix (prefix);
310 }
311 /*
312 Return thread name prefix.
313 */
314 native static int __threadNamePrefix ();
315 public static int threadNamePrefix () {
316 return __threadNamePrefix ();
317 }
318 /*
319 Adds a specific CPU to the affinity list of the ZMQ context thread pool.
320 This option is only supported on Linux.
321 Note that this method is valid only before any socket is created.
322 */
323 native static void __threadAffinityCpuAdd (int cpu);
324 public static void threadAffinityCpuAdd (int cpu) {
325 __threadAffinityCpuAdd (cpu);
326 }
327 /*
328 Removes a specific CPU to the affinity list of the ZMQ context thread pool.
329 This option is only supported on Linux.
330 Note that this method is valid only before any socket is created.
331 */
332 native static void __threadAffinityCpuRemove (int cpu);
333 public static void threadAffinityCpuRemove (int cpu) {
334 __threadAffinityCpuRemove (cpu);
283335 }
284336 /*
285337 Configure the number of sockets that ZeroMQ will allow. The default
288340 Note that this method is valid only before any socket is created.
289341 */
290342 native static void __setMaxSockets (long maxSockets);
291 public void setMaxSockets (long maxSockets) {
343 public static void setMaxSockets (long maxSockets) {
292344 __setMaxSockets (maxSockets);
293345 }
294346 /*
295347 Return maximum number of ZeroMQ sockets that the system will support.
296348 */
297349 native static long __socketLimit ();
298 public long socketLimit () {
350 public static long socketLimit () {
299351 return __socketLimit ();
300352 }
301353 /*
303355 The default is INT_MAX.
304356 */
305357 native static void __setMaxMsgsz (int maxMsgsz);
306 public void setMaxMsgsz (int maxMsgsz) {
358 public static void setMaxMsgsz (int maxMsgsz) {
307359 __setMaxMsgsz (maxMsgsz);
308360 }
309361 /*
310362 Return maximum message size.
311363 */
312364 native static int __maxMsgsz ();
313 public int maxMsgsz () {
365 public static int maxMsgsz () {
314366 return __maxMsgsz ();
315367 }
316368 /*
319371 Otherwise the default is 1.
320372 */
321373 native static void __setZeroCopyRecv (int zeroCopy);
322 public void setZeroCopyRecv (int zeroCopy) {
374 public static void setZeroCopyRecv (int zeroCopy) {
323375 __setZeroCopyRecv (zeroCopy);
324376 }
325377 /*
326378 Return ZMQ_ZERO_COPY_RECV option.
327379 */
328380 native static int __zeroCopyRecv ();
329 public int zeroCopyRecv () {
381 public static int zeroCopyRecv () {
330382 return __zeroCopyRecv ();
331383 }
332384 /*
337389 which generally depends on host OS, with fallback value of 5000.
338390 */
339391 native static void __setFileStableAgeMsec (long fileStableAgeMsec);
340 public void setFileStableAgeMsec (long fileStableAgeMsec) {
392 public static void setFileStableAgeMsec (long fileStableAgeMsec) {
341393 __setFileStableAgeMsec (fileStableAgeMsec);
342394 }
343395 /*
346398 before testing if a filesystem object is "stable" or not.
347399 */
348400 native static long __fileStableAgeMsec ();
349 public long fileStableAgeMsec () {
401 public static long fileStableAgeMsec () {
350402 return __fileStableAgeMsec ();
351403 }
352404 /*
357409 Note that process exit will typically be delayed by the linger time.
358410 */
359411 native static void __setLinger (long linger);
360 public void setLinger (long linger) {
412 public static void setLinger (long linger) {
361413 __setLinger (linger);
362414 }
363415 /*
368420 zero means no limit, i.e. infinite memory consumption.
369421 */
370422 native static void __setSndhwm (long sndhwm);
371 public void setSndhwm (long sndhwm) {
423 public static void setSndhwm (long sndhwm) {
372424 __setSndhwm (sndhwm);
373425 }
374426 /*
379431 zero means no limit, i.e. infinite memory consumption.
380432 */
381433 native static void __setRcvhwm (long rcvhwm);
382 public void setRcvhwm (long rcvhwm) {
434 public static void setRcvhwm (long rcvhwm) {
383435 __setRcvhwm (rcvhwm);
384436 }
385437 /*
390442 limit, i.e. infinite memory consumption.
391443 */
392444 native static void __setPipehwm (long pipehwm);
393 public void setPipehwm (long pipehwm) {
445 public static void setPipehwm (long pipehwm) {
394446 __setPipehwm (pipehwm);
395447 }
396448 /*
397449 Return the HWM for zactor internal pipes.
398450 */
399451 native static long __pipehwm ();
400 public long pipehwm () {
452 public static long pipehwm () {
401453 return __pipehwm ();
402454 }
403455 /*
409461 default. Note: has no effect on ZMQ v2.
410462 */
411463 native static void __setIpv6 (int ipv6);
412 public void setIpv6 (int ipv6) {
464 public static void setIpv6 (int ipv6) {
413465 __setIpv6 (ipv6);
414466 }
415467 /*
416468 Return use of IPv6 for zsock instances.
417469 */
418470 native static int __ipv6 ();
419 public int ipv6 () {
471 public static int ipv6 () {
420472 return __ipv6 ();
421473 }
422474 /*
428480 Setting the interface to "*" means "use all available interfaces".
429481 */
430482 native static void __setInterface (String value);
431 public void setInterface (String value) {
483 public static void setInterface (String value) {
432484 __setInterface (value);
433485 }
434486 /*
435487 Return network interface to use for broadcasts, or "" if none was set.
436488 */
437489 native static String __interface ();
438 public String Interface () {
490 public static String Interface () {
439491 return __interface ();
440492 }
441493 /*
445497 use that as the default IPv6 address.
446498 */
447499 native static void __setIpv6Address (String value);
448 public void setIpv6Address (String value) {
500 public static void setIpv6Address (String value) {
449501 __setIpv6Address (value);
450502 }
451503 /*
452504 Return IPv6 address to use for zbeacon reception, or "" if none was set.
453505 */
454506 native static String __ipv6Address ();
455 public String ipv6Address () {
507 public static String ipv6Address () {
456508 return __ipv6Address ();
457509 }
458510 /*
462514 address.
463515 */
464516 native static void __setIpv6McastAddress (String value);
465 public void setIpv6McastAddress (String value) {
517 public static void setIpv6McastAddress (String value) {
466518 __setIpv6McastAddress (value);
467519 }
468520 /*
470522 set.
471523 */
472524 native static String __ipv6McastAddress ();
473 public String ipv6McastAddress () {
525 public static String ipv6McastAddress () {
474526 return __ipv6McastAddress ();
475527 }
476528 /*
482534 instead of creating a new socket.
483535 */
484536 native static void __setAutoUseFd (int autoUseFd);
485 public void setAutoUseFd (int autoUseFd) {
537 public static void setAutoUseFd (int autoUseFd) {
486538 __setAutoUseFd (autoUseFd);
487539 }
488540 /*
489541 Return use of automatic pre-allocated FDs for zsock instances.
490542 */
491543 native static int __autoUseFd ();
492 public int autoUseFd () {
544 public static int autoUseFd () {
493545 return __autoUseFd ();
546 }
547 /*
548 Print formatted string. Format is specified by variable names
549 in Python-like format style
550
551 "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
552 become
553 "key=value"
554
555 Returns freshly allocated string or NULL in a case of error.
556 Not enough memory, invalid format specifier, name not in args
557 */
558 native static String __zprintf (String format, long args);
559 public static String zprintf (String format, Zhash args) {
560 return __zprintf (format, args.self);
561 }
562 /*
563 Return error string for given format/args combination.
564 */
565 native static String __zprintfError (String format, long args);
566 public static String zprintfError (String format, Zhash args) {
567 return __zprintfError (format, args.self);
568 }
569 /*
570 Print formatted string. Format is specified by variable names
571 in Python-like format style
572
573 "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
574 become
575 "key=value"
576
577 Returns freshly allocated string or NULL in a case of error.
578 Not enough memory, invalid format specifier, name not in args
579 */
580 native static String __zplprintf (String format, long args);
581 public static String zplprintf (String format, Zconfig args) {
582 return __zplprintf (format, args.self);
583 }
584 /*
585 Return error string for given format/args combination.
586 */
587 native static String __zplprintfError (String format, long args);
588 public static String zplprintfError (String format, Zconfig args) {
589 return __zplprintfError (format, args.self);
494590 }
495591 /*
496592 Set log identity, which is a string that prefixes all log messages sent
498594 ZSYS_LOGIDENT, if that is set.
499595 */
500596 native static void __setLogident (String value);
501 public void setLogident (String value) {
597 public static void setLogident (String value) {
502598 __setLogident (value);
503599 }
504600 /*
511607 this method with a null argument.
512608 */
513609 native static void __setLogsender (String endpoint);
514 public void setLogsender (String endpoint) {
610 public static void setLogsender (String endpoint) {
515611 __setLogsender (endpoint);
516612 }
517613 /*
519615 event log on Windows). By default this is disabled.
520616 */
521617 native static void __setLogsystem (boolean logsystem);
522 public void setLogsystem (boolean logsystem) {
618 public static void setLogsystem (boolean logsystem) {
523619 __setLogsystem (logsystem);
524620 }
525621 /*
526622 Log error condition - highest priority
527623 */
528624 native static void __error (String format);
529 public void error (String format) {
625 public static void error (String format) {
530626 __error (format);
531627 }
532628 /*
533629 Log warning condition - high priority
534630 */
535631 native static void __warning (String format);
536 public void warning (String format) {
632 public static void warning (String format) {
537633 __warning (format);
538634 }
539635 /*
540636 Log normal, but significant, condition - normal priority
541637 */
542638 native static void __notice (String format);
543 public void notice (String format) {
639 public static void notice (String format) {
544640 __notice (format);
545641 }
546642 /*
547643 Log informational message - low priority
548644 */
549645 native static void __info (String format);
550 public void info (String format) {
646 public static void info (String format) {
551647 __info (format);
552648 }
553649 /*
554650 Log debug-level message - lowest priority
555651 */
556652 native static void __debug (String format);
557 public void debug (String format) {
653 public static void debug (String format) {
558654 __debug (format);
559655 }
560656 /*
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Ztimerset implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Ztrie implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
55 */
66 package org.zeromq.czmq;
77
8 import org.scijava.nativelib.NativeLoader;
9
810 public class Zuuid implements AutoCloseable{
911 static {
10 try {
11 System.loadLibrary ("czmqjni");
12 }
13 catch (Exception e) {
14 System.exit (-1);
12 if (System.getProperty("java.vm.vendor").contains("Android")) {
13 System.loadLibrary("czmqjni");
14 } else {
15 try {
16 NativeLoader.loadLibrary("czmqjni");
17 } catch (Exception e) {
18 System.exit (-1);
19 }
1520 }
1621 }
1722 public long self;
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZarmourTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZcertTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZcertstoreTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZchunkTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZclockTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZconfigTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZdigestTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZdirPatchTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZdirTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZfileTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZframeTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZhashTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZhashxTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 package org.zeromq.czmq;
7
8 import org.junit.Assert;
9 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
11
12 public class ZhttpClientTest {
13 static {
14 try {
15 NativeLoader.loadLibrary("czmqjni");
16 }
17 catch (Exception e) {
18 System.exit (-1);
19 }
20 }
21 @Test
22 public void test () {
23 ZhttpClient.test (false);
24 }
25 }
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 package org.zeromq.czmq;
7
8 import org.junit.Assert;
9 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
11
12 public class ZhttpRequestTest {
13 static {
14 try {
15 NativeLoader.loadLibrary("czmqjni");
16 }
17 catch (Exception e) {
18 System.exit (-1);
19 }
20 }
21 @Test
22 public void test () {
23 ZhttpRequest.test (false);
24 }
25 }
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 package org.zeromq.czmq;
7
8 import org.junit.Assert;
9 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
11
12 public class ZhttpResponseTest {
13 static {
14 try {
15 NativeLoader.loadLibrary("czmqjni");
16 }
17 catch (Exception e) {
18 System.exit (-1);
19 }
20 }
21 @Test
22 public void test () {
23 ZhttpResponse.test (false);
24 }
25 }
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 package org.zeromq.czmq;
7
8 import org.junit.Assert;
9 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
11
12 public class ZhttpServerOptionsTest {
13 static {
14 try {
15 NativeLoader.loadLibrary("czmqjni");
16 }
17 catch (Exception e) {
18 System.exit (-1);
19 }
20 }
21 @Test
22 public void test () {
23 ZhttpServerOptions.test (false);
24 }
25 }
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 package org.zeromq.czmq;
7
8 import org.junit.Assert;
9 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
11
12 public class ZhttpServerTest {
13 static {
14 try {
15 NativeLoader.loadLibrary("czmqjni");
16 }
17 catch (Exception e) {
18 System.exit (-1);
19 }
20 }
21 @Test
22 public void test () {
23 ZhttpServer.test (false);
24 }
25 }
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZiflistTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZlistTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZlistxTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZloopTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZmsgTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZpollerTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZprocTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZsockTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZstrTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZsysTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZtimersetTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZtrieTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
77
88 import org.junit.Assert;
99 import org.junit.Test;
10 import org.scijava.nativelib.NativeLoader;
1011
1112 public class ZuuidTest {
1213 static {
1314 try {
14 System.loadLibrary ("czmqjni");
15 NativeLoader.loadLibrary("czmqjni");
1516 }
1617 catch (Exception e) {
1718 System.exit (-1);
5252 typedef struct _ztimerset_t ztimerset_t;
5353 typedef struct _ztrie_t ztrie_t;
5454 typedef struct _zuuid_t zuuid_t;
55 typedef struct _zhttp_client_t zhttp_client_t;
56 typedef struct _zhttp_server_t zhttp_server_t;
57 typedef struct _zhttp_server_options_t zhttp_server_options_t;
58 typedef struct _zhttp_request_t zhttp_request_t;
59 typedef struct _zhttp_response_t zhttp_response_t;
5560 // Actors get a pipe and arguments from caller
5661 typedef void (zactor_fn) (
5762 zsock_t *pipe, void *args);
7378 typedef void (zcertstore_destructor) (
7479 void **self_p);
7580
81 // Destroy an item
82 typedef void (zchunk_destructor_fn) (
83 void **hint);
84
7685 //
7786 typedef int (zconfig_fct) (
7887 zconfig_t *self, void *arg, int level);
88
89 // Destroy an item
90 typedef void (zframe_destructor_fn) (
91 void **hint);
7992
8093 // Callback function for zhash_freefn method
8194 typedef void (zhash_free_fn) (
233246 const char *
234247 zargs_param_next (zargs_t *self);
235248
236 // Return current parameter name, or NULL if there are no named
237 // parameters.
249 // Return current parameter name, or NULL if there are no named parameters.
238250 const char *
239251 zargs_param_name (zargs_t *self);
240252
241 // Return value of named parameter, NULL if no given parameter has
242 // been specified, or special value for wich zargs_param_empty ()
243 // returns true.
253 // Return value of named parameter or NULL is it has no value (or was not specified)
244254 const char *
245 zargs_param_lookup (zargs_t *self, const char *keys);
246
247 // Return value of named parameter(s), NULL if no given parameter has
248 // been specified, or special value for wich zargs_param_empty ()
249 // returns true.
255 zargs_get (zargs_t *self, const char *name);
256
257 // Return value of one of parameter(s) or NULL is it has no value (or was not specified)
250258 const char *
251 zargs_param_lookupx (zargs_t *self, const char *keys, ...);
252
253 // Returns true if there are --help -h arguments
259 zargs_getx (zargs_t *self, const char *name, ...);
260
261 // Returns true if named parameter was specified on command line
254262 bool
255 zargs_has_help (zargs_t *self);
256
257 // Returns true if parameter did not have a value
263 zargs_has (zargs_t *self, const char *name);
264
265 // Returns true if named parameter(s) was specified on command line
258266 bool
259 zargs_param_empty (const char *arg);
267 zargs_hasx (zargs_t *self, const char *name, ...);
260268
261269 // Print an instance of zargs.
262270 void
487495 zchunk_t *
488496 zchunk_new (const void *data, size_t size);
489497
498 // Create a new chunk from memory. Take ownership of the memory and calling the destructor
499 // on destroy.
500 zchunk_t *
501 zchunk_frommem (void *data, size_t size, zchunk_destructor_fn destructor, void *hint);
502
490503 // Destroy a chunk
491504 void
492505 zchunk_destroy (zchunk_t **self_p);
578591 zframe_t *
579592 zchunk_pack (zchunk_t *self);
580593
594 // Transform zchunk into a zframe that can be sent in a message.
595 // Take ownership of the chunk.
596 zframe_t *
597 zchunk_packx (zchunk_t **self_p);
598
581599 // Transform a zframe into a zchunk.
582600 zchunk_t *
583601 zchunk_unpack (zframe_t *frame);
653671 // filename.
654672 zconfig_t *
655673 zconfig_loadf (const char *format, ...);
674
675 // Create copy of zconfig, caller MUST free the value
676 // Create copy of config, as new zconfig object. Returns a fresh zconfig_t
677 // object. If config is null, or memory was exhausted, returns null.
678 zconfig_t *
679 zconfig_dup (zconfig_t *self);
656680
657681 // Return name of config item
658682 char *
960984 zfile_t *
961985 zfile_new (const char *path, const char *name);
962986
963 // Create new temporary file for writing via tmpfile. File is automaticaly
987 // Create new temporary file for writing via tmpfile. File is automatically
964988 // deleted on destroy
965989 zfile_t *
966990 zfile_tmp (void);
10941118 // Create a frame with a specified string content.
10951119 zframe_t *
10961120 zframe_from (const char *string);
1121
1122 // Create a new frame from memory. Take ownership of the memory and calling the destructor
1123 // on destroy.
1124 zframe_t *
1125 zframe_frommem (void *data, size_t size, zframe_destructor_fn destructor, void *hint);
10971126
10981127 // Receive frame from socket, returns zframe_t object or NULL if the recv
10991128 // was interrupted. Does a blocking recv, if you want to not block then use
17251754 void
17261755 zlistx_destroy (zlistx_t **self_p);
17271756
1757 // Unpack binary frame into a new list. Packed data must follow format
1758 // defined by zlistx_pack. List is set to autofree. An empty frame
1759 // unpacks to an empty list.
1760 zlistx_t *
1761 zlistx_unpack (zframe_t *frame);
1762
17281763 // Add an item to the head of the list. Calls the item duplicator, if any,
17291764 // on the item. Resets cursor to list head. Returns an item handle on
17301765 // success, NULL if memory was exhausted.
18711906 // or greater than, item2.
18721907 void
18731908 zlistx_set_comparator (zlistx_t *self, zlistx_comparator_fn comparator);
1909
1910 // Serialize list to a binary frame that can be sent in a message.
1911 // The packed format is compatible with the 'strings' type implemented by zproto:
1912 //
1913 // ; A list of strings
1914 // list = list-count *longstr
1915 // list-count = number-4
1916 //
1917 // ; Strings are always length + text contents
1918 // longstr = number-4 *VCHAR
1919 //
1920 // ; Numbers are unsigned integers in network byte order
1921 // number-4 = 4OCTET
1922 zframe_t *
1923 zlistx_pack (zlistx_t *self);
18741924
18751925 // Self test of this class.
18761926 void
23182368 bool
23192369 zproc_running (zproc_t *self);
23202370
2371 // The timeout should be zero or greater, or -1 to wait indefinitely.
23212372 // wait or poll process status, return return code
23222373 int
2323 zproc_wait (zproc_t *self, bool hang);
2324
2325 // return internal actor, usefull for the polling if process died
2374 zproc_wait (zproc_t *self, int timeout);
2375
2376 // send SIGTERM signal to the subprocess, wait for grace period and
2377 // eventually send SIGKILL
2378 void
2379 zproc_shutdown (zproc_t *self, int timeout);
2380
2381 // return internal actor, useful for the polling if process died
23262382 void *
23272383 zproc_actor (zproc_t *self);
23282384
24982554 // c = zchunk_t *
24992555 // f = zframe_t *
25002556 // h = zhashx_t *
2557 // l = zlistx_t * (DRAFT)
25012558 // U = zuuid_t *
25022559 // p = void * (sends the pointer value, only meaningful over inproc)
25032560 // m = zmsg_t * (sends all frames in the zmsg)
25312588 // f = zframe_t ** (creates zframe)
25322589 // U = zuuid_t * (creates a zuuid with the data)
25332590 // h = zhashx_t ** (creates zhashx)
2591 // l = zlistx_t ** (creates zlistx) (DRAFT)
25342592 // p = void ** (stores pointer)
2535 // m = zmsg_t ** (creates a zmsg with the remaing frames)
2593 // m = zmsg_t ** (creates a zmsg with the remaining frames)
25362594 // z = null, asserts empty frame (0 arguments)
25372595 // u = uint * (stores unsigned integer, deprecated)
25382596 //
26562714 void *
26572715 zsock_resolve (void *self);
26582716
2717 // Check whether the socket has available message to read.
2718 bool
2719 zsock_has_in (void *self);
2720
2721 // Get socket option `router_notify`.
2722 // Available from libzmq 4.3.0.
2723 int
2724 zsock_router_notify (void *self);
2725
2726 // Set socket option `router_notify`.
2727 // Available from libzmq 4.3.0.
2728 void
2729 zsock_set_router_notify (void *self, int router_notify);
2730
2731 // Get socket option `multicast_loop`.
2732 // Available from libzmq 4.3.0.
2733 int
2734 zsock_multicast_loop (void *self);
2735
2736 // Set socket option `multicast_loop`.
2737 // Available from libzmq 4.3.0.
2738 void
2739 zsock_set_multicast_loop (void *self, int multicast_loop);
2740
2741 // Get socket option `metadata`.
2742 // Available from libzmq 4.3.0.
2743 char *
2744 zsock_metadata (void *self);
2745
2746 // Set socket option `metadata`.
2747 // Available from libzmq 4.3.0.
2748 void
2749 zsock_set_metadata (void *self, const char *metadata);
2750
2751 // Get socket option `loopback_fastpath`.
2752 // Available from libzmq 4.3.0.
2753 int
2754 zsock_loopback_fastpath (void *self);
2755
2756 // Set socket option `loopback_fastpath`.
2757 // Available from libzmq 4.3.0.
2758 void
2759 zsock_set_loopback_fastpath (void *self, int loopback_fastpath);
2760
2761 // Get socket option `zap_enforce_domain`.
2762 // Available from libzmq 4.3.0.
2763 int
2764 zsock_zap_enforce_domain (void *self);
2765
2766 // Set socket option `zap_enforce_domain`.
2767 // Available from libzmq 4.3.0.
2768 void
2769 zsock_set_zap_enforce_domain (void *self, int zap_enforce_domain);
2770
2771 // Get socket option `gssapi_principal_nametype`.
2772 // Available from libzmq 4.3.0.
2773 int
2774 zsock_gssapi_principal_nametype (void *self);
2775
2776 // Set socket option `gssapi_principal_nametype`.
2777 // Available from libzmq 4.3.0.
2778 void
2779 zsock_set_gssapi_principal_nametype (void *self, int gssapi_principal_nametype);
2780
2781 // Get socket option `gssapi_service_principal_nametype`.
2782 // Available from libzmq 4.3.0.
2783 int
2784 zsock_gssapi_service_principal_nametype (void *self);
2785
2786 // Set socket option `gssapi_service_principal_nametype`.
2787 // Available from libzmq 4.3.0.
2788 void
2789 zsock_set_gssapi_service_principal_nametype (void *self, int gssapi_service_principal_nametype);
2790
2791 // Get socket option `bindtodevice`.
2792 // Available from libzmq 4.3.0.
2793 char *
2794 zsock_bindtodevice (void *self);
2795
2796 // Set socket option `bindtodevice`.
2797 // Available from libzmq 4.3.0.
2798 void
2799 zsock_set_bindtodevice (void *self, const char *bindtodevice);
2800
26592801 // Get socket option `heartbeat_ivl`.
26602802 // Available from libzmq 4.2.0.
26612803 int
34853627
34863628 // Set default interrupt handler, so Ctrl-C or SIGTERM will set
34873629 // zsys_interrupted. Idempotent; safe to call multiple times.
3488 // Can be supressed by ZSYS_SIGHANDLER=false
3630 // Can be suppressed by ZSYS_SIGHANDLER=false
34893631 // *** This is for CZMQ internal use only and may change arbitrarily ***
34903632 void
34913633 zsys_catch_interrupts (void);
35513693 // number into provided fields, providing reference isn't null in each case.
35523694 void
35533695 zsys_version (int *major, int *minor, int *patch);
3696
3697 // Format a string using printf formatting, returning a freshly allocated
3698 // buffer. If there was insufficient memory, returns NULL. Free the returned
3699 // string using zstr_free(). The hinted version allows to optimize by using
3700 // a larger starting buffer size (known to/assumed by the developer) and so
3701 // avoid reallocations.
3702 char *
3703 zsys_sprintf_hint (int hint, const char *format, ...);
35543704
35553705 // Format a string using printf formatting, returning a freshly allocated
35563706 // buffer. If there was insufficient memory, returns NULL. Free the returned
36463796 void
36473797 zsys_set_thread_priority (int priority);
36483798
3799 // Configure the numeric prefix to each thread created for the internal
3800 // context's thread pool. This option is only supported on Linux.
3801 // If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
3802 // provides the default.
3803 // Note that this method is valid only before any socket is created.
3804 void
3805 zsys_set_thread_name_prefix (int prefix);
3806
3807 // Return thread name prefix.
3808 int
3809 zsys_thread_name_prefix (void);
3810
3811 // Adds a specific CPU to the affinity list of the ZMQ context thread pool.
3812 // This option is only supported on Linux.
3813 // Note that this method is valid only before any socket is created.
3814 void
3815 zsys_thread_affinity_cpu_add (int cpu);
3816
3817 // Removes a specific CPU to the affinity list of the ZMQ context thread pool.
3818 // This option is only supported on Linux.
3819 // Note that this method is valid only before any socket is created.
3820 void
3821 zsys_thread_affinity_cpu_remove (int cpu);
3822
36493823 // Configure the number of sockets that ZeroMQ will allow. The default
36503824 // is 1024. The actual limit depends on the system, and you can query it
36513825 // by using zsys_socket_limit (). A value of zero means "maximum".
37873961 // Return use of automatic pre-allocated FDs for zsock instances.
37883962 int
37893963 zsys_auto_use_fd (void);
3964
3965 // Print formatted string. Format is specified by variable names
3966 // in Python-like format style
3967 //
3968 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
3969 // become
3970 // "key=value"
3971 //
3972 // Returns freshly allocated string or NULL in a case of error.
3973 // Not enough memory, invalid format specifier, name not in args
3974 char *
3975 zsys_zprintf (const char *format, zhash_t *args);
3976
3977 // Return error string for given format/args combination.
3978 char *
3979 zsys_zprintf_error (const char *format, zhash_t *args);
3980
3981 // Print formatted string. Format is specified by variable names
3982 // in Python-like format style
3983 //
3984 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
3985 // become
3986 // "key=value"
3987 //
3988 // Returns freshly allocated string or NULL in a case of error.
3989 // Not enough memory, invalid format specifier, name not in args
3990 char *
3991 zsys_zplprintf (const char *format, zconfig_t *args);
3992
3993 // Return error string for given format/args combination.
3994 char *
3995 zsys_zplprintf_error (const char *format, zconfig_t *args);
37903996
37913997 // Set log identity, which is a string that prefixes all log messages sent
37923998 // by this process. The log identity defaults to the environment variable
39974203 void
39984204 zuuid_test (bool verbose);
39994205
4206 // CLASS: zhttp_client
4207 // Create a new http client
4208 zhttp_client_t *
4209 zhttp_client_new (bool verbose);
4210
4211 // Destroy an http client
4212 void
4213 zhttp_client_destroy (zhttp_client_t **self_p);
4214
4215 // Self test of this class.
4216 void
4217 zhttp_client_test (bool verbose);
4218
4219 // CLASS: zhttp_server
4220 // Create a new http server
4221 zhttp_server_t *
4222 zhttp_server_new (zhttp_server_options_t *options);
4223
4224 // Destroy an http server
4225 void
4226 zhttp_server_destroy (zhttp_server_t **self_p);
4227
4228 // Return the port the server is listening on.
4229 int
4230 zhttp_server_port (zhttp_server_t *self);
4231
4232 // Self test of this class.
4233 void
4234 zhttp_server_test (bool verbose);
4235
4236 // CLASS: zhttp_server_options
4237 // Create a new zhttp_server_options.
4238 zhttp_server_options_t *
4239 zhttp_server_options_new (void);
4240
4241 // Create options from config tree.
4242 zhttp_server_options_t *
4243 zhttp_server_options_from_config (zconfig_t *config);
4244
4245 // Destroy the zhttp_server_options.
4246 void
4247 zhttp_server_options_destroy (zhttp_server_options_t **self_p);
4248
4249 // Get the server listening port.
4250 int
4251 zhttp_server_options_port (zhttp_server_options_t *self);
4252
4253 // Set the server listening port
4254 void
4255 zhttp_server_options_set_port (zhttp_server_options_t *self, int port);
4256
4257 // Get the address sockets should connect to in order to receive requests.
4258 const char *
4259 zhttp_server_options_backend_address (zhttp_server_options_t *self);
4260
4261 // Set the address sockets should connect to in order to receive requests.
4262 void
4263 zhttp_server_options_set_backend_address (zhttp_server_options_t *self, const char *address);
4264
4265 // Self test of this class.
4266 void
4267 zhttp_server_options_test (bool verbose);
4268
4269 // CLASS: zhttp_request
4270 // Create a new http request.
4271 zhttp_request_t *
4272 zhttp_request_new (void);
4273
4274 // Destroy an http request.
4275 void
4276 zhttp_request_destroy (zhttp_request_t **self_p);
4277
4278 // Receive a new request from zhttp_server.
4279 // Return the underlying connection if successful, to be used when calling zhttp_response_send.
4280 void *
4281 zhttp_request_recv (zhttp_request_t *self, zsock_t *sock);
4282
4283 // Send a request to zhttp_client.
4284 // Url and the request path will be concatenated.
4285 // This behavior is useful for url rewrite and reverse proxy.
4286 //
4287 // Send also allow two user provided arguments which will be returned with the response.
4288 // The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an arg.
4289 int
4290 zhttp_request_send (zhttp_request_t *self, zhttp_client_t *client, int timeout, void *arg, void *arg2);
4291
4292 // Get the request method
4293 const char *
4294 zhttp_request_method (zhttp_request_t *self);
4295
4296 // Set the request method
4297 void
4298 zhttp_request_set_method (zhttp_request_t *self, const char *method);
4299
4300 // Get the request url.
4301 // When receiving a request from http server this is only the path part of the url.
4302 const char *
4303 zhttp_request_url (zhttp_request_t *self);
4304
4305 // Set the request url
4306 // When sending a request to http client this should be full url.
4307 void
4308 zhttp_request_set_url (zhttp_request_t *self, const char *url);
4309
4310 // Get the request content type
4311 const char *
4312 zhttp_request_content_type (zhttp_request_t *self);
4313
4314 // Set the request content type
4315 void
4316 zhttp_request_set_content_type (zhttp_request_t *self, const char *content_type);
4317
4318 // Get the content length of the request
4319 size_t
4320 zhttp_request_content_length (zhttp_request_t *self);
4321
4322 // Get the headers of the request
4323 zhash_t *
4324 zhttp_request_headers (zhttp_request_t *self);
4325
4326 // Get the content of the request.
4327 const char *
4328 zhttp_request_content (zhttp_request_t *self);
4329
4330 // Get the content of the request.
4331 char *
4332 zhttp_request_get_content (zhttp_request_t *self);
4333
4334 // Set the content of the request.
4335 // Content must by dynamically allocated string.
4336 // Takes ownership of the content.
4337 void
4338 zhttp_request_set_content (zhttp_request_t *self, char **content);
4339
4340 // Set the content of the request..
4341 // The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
4342 void
4343 zhttp_request_set_content_const (zhttp_request_t *self, const char *content);
4344
4345 // Set the content to NULL
4346 void
4347 zhttp_request_reset_content (zhttp_request_t *self);
4348
4349 // Match the path of the request.
4350 // Support wildcards with '%s' symbol inside the match string.
4351 // Matching wildcards until the next '/', '?' or '\0'.
4352 // On successful match the variadic arguments will be filled with the matching strings.
4353 // On successful match the method is modifying the url field and break it into substrings.
4354 // If you need to use the url, do it before matching or take a copy.
4355 //
4356 // User must not free the variadic arguments as they are part of the url.
4357 //
4358 // To use the percent symbol, just double it, e.g "%%something".
4359 //
4360 // Example:
4361 // if (zhttp_request_match (request, "POST", "/send/%s/%s", &name, &id))
4362 bool
4363 zhttp_request_match (zhttp_request_t *self, const char *method, const char *path, ...);
4364
4365 // Self test of this class.
4366 void
4367 zhttp_request_test (bool verbose);
4368
4369 // CLASS: zhttp_response
4370 // Create a new zhttp_response.
4371 zhttp_response_t *
4372 zhttp_response_new (void);
4373
4374 // Destroy the zhttp_response.
4375 void
4376 zhttp_response_destroy (zhttp_response_t **self_p);
4377
4378 // Send a response to a request.
4379 // Returns 0 if successful and -1 otherwise.
4380 int
4381 zhttp_response_send (zhttp_response_t *self, zsock_t *sock, void **connection);
4382
4383 // Receive a response from zhttp_client.
4384 // On success return 0, -1 otherwise.
4385 //
4386 // Recv returns the two user arguments which was provided with the request.
4387 // The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an argument.
4388 int
4389 zhttp_response_recv (zhttp_response_t *self, zhttp_client_t *client, void **arg, void **arg2);
4390
4391 // Get the response content type
4392 const char *
4393 zhttp_response_content_type (zhttp_response_t *self);
4394
4395 // Set the content type of the response.
4396 void
4397 zhttp_response_set_content_type (zhttp_response_t *self, const char *value);
4398
4399 // Get the status code of the response.
4400 uint32_t
4401 zhttp_response_status_code (zhttp_response_t *self);
4402
4403 // Set the status code of the response.
4404 void
4405 zhttp_response_set_status_code (zhttp_response_t *self, uint32_t status_code);
4406
4407 // Get the headers of the response.
4408 zhash_t *
4409 zhttp_response_headers (zhttp_response_t *self);
4410
4411 // Get the content length of the response
4412 size_t
4413 zhttp_response_content_length (zhttp_response_t *self);
4414
4415 // Get the content of the response.
4416 const char *
4417 zhttp_response_content (zhttp_response_t *self);
4418
4419 // Get the content of the response.
4420 char *
4421 zhttp_response_get_content (zhttp_response_t *self);
4422
4423 // Set the content of the response.
4424 // Content must by dynamically allocated string.
4425 // Takes ownership of the content.
4426 void
4427 zhttp_response_set_content (zhttp_response_t *self, char **content);
4428
4429 // Set the content of the response.
4430 // The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
4431 void
4432 zhttp_response_set_content_const (zhttp_response_t *self, const char *content);
4433
4434 // Set the content to NULL
4435 void
4436 zhttp_response_reset_content (zhttp_response_t *self);
4437
4438 // Self test of this class.
4439 void
4440 zhttp_response_test (bool verbose);
4441
40004442 ]]
40014443
40024444 czmq_ffi.czmq = czmq_ffi.ffi.load ("libczmq")
4545 ### The Zargs class - Platform independent command line argument parsing helpers
4646
4747 There are two kind of elements provided by this class
48 foo --named-parameter --parameter with_value positional arguments -a gain-parameter
49 zargs keeps poision only for arguments, parameters are to be accessed like hash.
48 Named parameters, accessed by param_get and param_has methods
49 * --named-parameter
50 * --parameter with_value
51 * -a val
52 Positional arguments, accessed by zargs_first, zargs_next
5053
5154 It DOES:
5255 * provide easy to use CLASS compatible API for accessing argv
5356 * is platform independent
5457 * provide getopt_long style -- argument, which delimits parameters from arguments
55 * makes parameters positon independent
58 * makes parameters position independent
5659
5760 It does NOT
5861 * change argv
119122 string my_zargs.paramName ()
120123 ```
121124
122 Return current parameter name, or NULL if there are no named
123 parameters.
124
125 ```
126 string my_zargs.paramLookup (String)
127 ```
128
129 Return value of named parameter, NULL if no given parameter has
130 been specified, or special value for wich zargs_param_empty ()
131 returns true.
132
133 ```
134 string my_zargs.paramLookupx (String)
135 ```
136
137 Return value of named parameter(s), NULL if no given parameter has
138 been specified, or special value for wich zargs_param_empty ()
139 returns true.
140
141 ```
142 boolean my_zargs.hasHelp ()
143 ```
144
145 Returns true if there are --help -h arguments
146
147 ```
148 boolean my_zargs.paramEmpty (String)
149 ```
150
151 Returns true if parameter did not have a value
125 Return current parameter name, or NULL if there are no named parameters.
126
127 ```
128 string my_zargs.get (String)
129 ```
130
131 Return value of named parameter or NULL is it has no value (or was not specified)
132
133 ```
134 string my_zargs.getx (String)
135 ```
136
137 Return value of one of parameter(s) or NULL is it has no value (or was not specified)
138
139 ```
140 boolean my_zargs.has (String)
141 ```
142
143 Returns true if named parameter was specified on command line
144
145 ```
146 boolean my_zargs.hasx (String)
147 ```
148
149 Returns true if named parameter(s) was specified on command line
152150
153151 ```
154152 nothing my_zargs.print ()
575573 Transform zchunk into a zframe that can be sent in a message.
576574
577575 ```
576 zframe my_zchunk.packx (Zchunk)
577 ```
578
579 Transform zchunk into a zframe that can be sent in a message.
580 Take ownership of the chunk.
581
582 ```
578583 zchunk my_zchunk.unpack (Zframe)
579584 ```
580585
668673 ```
669674
670675 Methods:
676
677 ```
678 zconfig my_zconfig.dup ()
679 ```
680
681 Create copy of zconfig, caller MUST free the value
682 Create copy of config, as new zconfig object. Returns a fresh zconfig_t
683 object. If config is null, or memory was exhausted, returns null.
671684
672685 ```
673686 string my_zconfig.name ()
18021815 reference.
18031816
18041817 ```
1818 zframe my_zlistx.pack ()
1819 ```
1820
1821 Serialize list to a binary frame that can be sent in a message.
1822 The packed format is compatible with the 'strings' type implemented by zproto:
1823
1824 ; A list of strings
1825 list = list-count *longstr
1826 list-count = number-4
1827
1828 ; Strings are always length + text contents
1829 longstr = number-4 *VCHAR
1830
1831 ; Numbers are unsigned integers in network byte order
1832 number-4 = 4OCTET
1833
1834 ```
18051835 nothing my_zlistx.test (Boolean)
18061836 ```
18071837
22362266 return true if process is running, false if not yet started or finished
22372267
22382268 ```
2239 integer my_zproc.wait (Boolean)
2240 ```
2241
2269 integer my_zproc.wait (Number)
2270 ```
2271
2272 The timeout should be zero or greater, or -1 to wait indefinitely.
22422273 wait or poll process status, return return code
2274
2275 ```
2276 nothing my_zproc.shutdown (Number)
2277 ```
2278
2279 send SIGTERM signal to the subprocess, wait for grace period and
2280 eventually send SIGKILL
22432281
22442282 ```
22452283 nothing my_zproc.kill (Number)
23662404 c = zchunk_t *
23672405 f = zframe_t *
23682406 h = zhashx_t *
2407 l = zlistx_t * (DRAFT)
23692408 U = zuuid_t *
23702409 p = void * (sends the pointer value, only meaningful over inproc)
23712410 m = zmsg_t * (sends all frames in the zmsg)
23952434 f = zframe_t ** (creates zframe)
23962435 U = zuuid_t * (creates a zuuid with the data)
23972436 h = zhashx_t ** (creates zhashx)
2437 l = zlistx_t ** (creates zlistx) (DRAFT)
23982438 p = void ** (stores pointer)
2399 m = zmsg_t ** (creates a zmsg with the remaing frames)
2439 m = zmsg_t ** (creates a zmsg with the remaining frames)
24002440 z = null, asserts empty frame (0 arguments)
24012441 u = uint * (stores unsigned integer, deprecated)
24022442
25112551 Returns 0 if OK, -1 if failed.
25122552
25132553 ```
2554 boolean my_zsock.hasIn ()
2555 ```
2556
2557 Check whether the socket has available message to read.
2558
2559 ```
2560 integer my_zsock.routerNotify ()
2561 ```
2562
2563 Get socket option `router_notify`.
2564 Available from libzmq 4.3.0.
2565
2566 ```
2567 nothing my_zsock.setRouterNotify (Number)
2568 ```
2569
2570 Set socket option `router_notify`.
2571 Available from libzmq 4.3.0.
2572
2573 ```
2574 integer my_zsock.multicastLoop ()
2575 ```
2576
2577 Get socket option `multicast_loop`.
2578 Available from libzmq 4.3.0.
2579
2580 ```
2581 nothing my_zsock.setMulticastLoop (Number)
2582 ```
2583
2584 Set socket option `multicast_loop`.
2585 Available from libzmq 4.3.0.
2586
2587 ```
2588 string my_zsock.metadata ()
2589 ```
2590
2591 Get socket option `metadata`.
2592 Available from libzmq 4.3.0.
2593
2594 ```
2595 nothing my_zsock.setMetadata (String)
2596 ```
2597
2598 Set socket option `metadata`.
2599 Available from libzmq 4.3.0.
2600
2601 ```
2602 integer my_zsock.loopbackFastpath ()
2603 ```
2604
2605 Get socket option `loopback_fastpath`.
2606 Available from libzmq 4.3.0.
2607
2608 ```
2609 nothing my_zsock.setLoopbackFastpath (Number)
2610 ```
2611
2612 Set socket option `loopback_fastpath`.
2613 Available from libzmq 4.3.0.
2614
2615 ```
2616 integer my_zsock.zapEnforceDomain ()
2617 ```
2618
2619 Get socket option `zap_enforce_domain`.
2620 Available from libzmq 4.3.0.
2621
2622 ```
2623 nothing my_zsock.setZapEnforceDomain (Number)
2624 ```
2625
2626 Set socket option `zap_enforce_domain`.
2627 Available from libzmq 4.3.0.
2628
2629 ```
2630 integer my_zsock.gssapiPrincipalNametype ()
2631 ```
2632
2633 Get socket option `gssapi_principal_nametype`.
2634 Available from libzmq 4.3.0.
2635
2636 ```
2637 nothing my_zsock.setGssapiPrincipalNametype (Number)
2638 ```
2639
2640 Set socket option `gssapi_principal_nametype`.
2641 Available from libzmq 4.3.0.
2642
2643 ```
2644 integer my_zsock.gssapiServicePrincipalNametype ()
2645 ```
2646
2647 Get socket option `gssapi_service_principal_nametype`.
2648 Available from libzmq 4.3.0.
2649
2650 ```
2651 nothing my_zsock.setGssapiServicePrincipalNametype (Number)
2652 ```
2653
2654 Set socket option `gssapi_service_principal_nametype`.
2655 Available from libzmq 4.3.0.
2656
2657 ```
2658 string my_zsock.bindtodevice ()
2659 ```
2660
2661 Get socket option `bindtodevice`.
2662 Available from libzmq 4.3.0.
2663
2664 ```
2665 nothing my_zsock.setBindtodevice (String)
2666 ```
2667
2668 Set socket option `bindtodevice`.
2669 Available from libzmq 4.3.0.
2670
2671 ```
25142672 integer my_zsock.heartbeatIvl ()
25152673 ```
25162674
36393797
36403798 Set default interrupt handler, so Ctrl-C or SIGTERM will set
36413799 zsys_interrupted. Idempotent; safe to call multiple times.
3642 Can be supressed by ZSYS_SIGHANDLER=false
3800 Can be suppressed by ZSYS_SIGHANDLER=false
36433801 *** This is for CZMQ internal use only and may change arbitrarily ***
36443802
36453803 ```
37293887
37303888 Return the CZMQ version for run-time API detection; returns version
37313889 number into provided fields, providing reference isn't null in each case.
3890
3891 ```
3892 string my_zsys.sprintfHint (Number, String)
3893 ```
3894
3895 Format a string using printf formatting, returning a freshly allocated
3896 buffer. If there was insufficient memory, returns NULL. Free the returned
3897 string using zstr_free(). The hinted version allows to optimize by using
3898 a larger starting buffer size (known to/assumed by the developer) and so
3899 avoid reallocations.
37323900
37333901 ```
37343902 string my_zsys.sprintf (String)
38093977 Not available on Windows. See the sched_setscheduler man page or sched.h
38103978 for more information. If the environment variable ZSYS_THREAD_PRIORITY is
38113979 defined, that provides the default.
3980 Note that this method is valid only before any socket is created.
3981
3982 ```
3983 nothing my_zsys.setThreadNamePrefix (Number)
3984 ```
3985
3986 Configure the numeric prefix to each thread created for the internal
3987 context's thread pool. This option is only supported on Linux.
3988 If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
3989 provides the default.
3990 Note that this method is valid only before any socket is created.
3991
3992 ```
3993 integer my_zsys.threadNamePrefix ()
3994 ```
3995
3996 Return thread name prefix.
3997
3998 ```
3999 nothing my_zsys.threadAffinityCpuAdd (Number)
4000 ```
4001
4002 Adds a specific CPU to the affinity list of the ZMQ context thread pool.
4003 This option is only supported on Linux.
4004 Note that this method is valid only before any socket is created.
4005
4006 ```
4007 nothing my_zsys.threadAffinityCpuRemove (Number)
4008 ```
4009
4010 Removes a specific CPU to the affinity list of the ZMQ context thread pool.
4011 This option is only supported on Linux.
38124012 Note that this method is valid only before any socket is created.
38134013
38144014 ```
39984198 ```
39994199
40004200 Return use of automatic pre-allocated FDs for zsock instances.
4201
4202 ```
4203 string my_zsys.zprintf (String, Zhash)
4204 ```
4205
4206 Print formatted string. Format is specified by variable names
4207 in Python-like format style
4208
4209 "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
4210 become
4211 "key=value"
4212
4213 Returns freshly allocated string or NULL in a case of error.
4214 Not enough memory, invalid format specifier, name not in args
4215
4216 ```
4217 string my_zsys.zprintfError (String, Zhash)
4218 ```
4219
4220 Return error string for given format/args combination.
4221
4222 ```
4223 string my_zsys.zplprintf (String, Zconfig)
4224 ```
4225
4226 Print formatted string. Format is specified by variable names
4227 in Python-like format style
4228
4229 "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
4230 become
4231 "key=value"
4232
4233 Returns freshly allocated string or NULL in a case of error.
4234 Not enough memory, invalid format specifier, name not in args
4235
4236 ```
4237 string my_zsys.zplprintfError (String, Zconfig)
4238 ```
4239
4240 Return error string for given format/args combination.
40014241
40024242 ```
40034243 nothing my_zsys.setLogident (String)
42714511 ```
42724512
42734513 Self test of this class.
4514
4515 ### The ZhttpClient class - Http client, allowing multiple requests simultaneously and integrate easily with zpoller.
4516 Use zhttp_request class to create and send the request.
4517 Use zhttp_response class to receive the response.
4518
4519 Constructor:
4520
4521 ```
4522 var czmq = require ('bindings')('czmq')
4523 var my_zhttp_client = new czmq.ZhttpClient (Boolean)
4524 ```
4525
4526 You *must* call the destructor on every ZhttpClient instance:
4527
4528 ```
4529 my_zhttp_client.destroy ()
4530 ```
4531
4532 Methods:
4533
4534 ```
4535 nothing my_zhttp_client.test (Boolean)
4536 ```
4537
4538 Self test of this class.
4539
4540 ### The ZhttpServer class - Simple http server.
4541 To start handling requests:
4542 1. Create a dealer socket
4543 2. Connect the socket to the server backend address provided in the options.
4544 3. Create a zhttp_request.
4545 4. Call zhttp_request_recv to accept a new request.
4546 5. Call zhttp_response_send to send a response.
4547
4548 You can connect as many dealers as you want.
4549 The Server is using simple dealer socket to route the requests.
4550
4551 NOTE: when using libmicrohttpd << 0.9.34 the application might experience
4552 high CPU usage due to the lack of MHD_suspend_connection and
4553 MHD_resume_connection APIs. It is recommended to use this class only with
4554 libmicrohttpd at least 0.9.34 in production.
4555
4556 Constructor:
4557
4558 ```
4559 var czmq = require ('bindings')('czmq')
4560 var my_zhttp_server = new czmq.ZhttpServer (ZhttpServerOptions)
4561 ```
4562
4563 You *must* call the destructor on every ZhttpServer instance:
4564
4565 ```
4566 my_zhttp_server.destroy ()
4567 ```
4568
4569 Methods:
4570
4571 ```
4572 integer my_zhttp_server.port ()
4573 ```
4574
4575 Return the port the server is listening on.
4576
4577 ```
4578 nothing my_zhttp_server.test (Boolean)
4579 ```
4580
4581 Self test of this class.
4582
4583 ### The ZhttpServerOptions class - zhttp server.
4584
4585 Constructor:
4586
4587 ```
4588 var czmq = require ('bindings')('czmq')
4589 var my_zhttp_server_options = new czmq.ZhttpServerOptions ()
4590 ```
4591
4592 You *must* call the destructor on every ZhttpServerOptions instance:
4593
4594 ```
4595 my_zhttp_server_options.destroy ()
4596 ```
4597
4598 Methods:
4599
4600 ```
4601 integer my_zhttp_server_options.port ()
4602 ```
4603
4604 Get the server listening port.
4605
4606 ```
4607 nothing my_zhttp_server_options.setPort (Number)
4608 ```
4609
4610 Set the server listening port
4611
4612 ```
4613 string my_zhttp_server_options.backendAddress ()
4614 ```
4615
4616 Get the address sockets should connect to in order to receive requests.
4617
4618 ```
4619 nothing my_zhttp_server_options.setBackendAddress (String)
4620 ```
4621
4622 Set the address sockets should connect to in order to receive requests.
4623
4624 ```
4625 nothing my_zhttp_server_options.test (Boolean)
4626 ```
4627
4628 Self test of this class.
4629
4630 ### The ZhttpRequest class - Http request that can be received from zhttp_server or sent to zhttp_client.
4631 Class can be reused between send & recv calls.
4632 Headers and Content is being destroyed after every send call.
4633
4634 Constructor:
4635
4636 ```
4637 var czmq = require ('bindings')('czmq')
4638 var my_zhttp_request = new czmq.ZhttpRequest ()
4639 ```
4640
4641 You *must* call the destructor on every ZhttpRequest instance:
4642
4643 ```
4644 my_zhttp_request.destroy ()
4645 ```
4646
4647 Methods:
4648
4649 ```
4650 string my_zhttp_request.method ()
4651 ```
4652
4653 Get the request method
4654
4655 ```
4656 nothing my_zhttp_request.setMethod (String)
4657 ```
4658
4659 Set the request method
4660
4661 ```
4662 string my_zhttp_request.url ()
4663 ```
4664
4665 Get the request url.
4666 When receiving a request from http server this is only the path part of the url.
4667
4668 ```
4669 nothing my_zhttp_request.setUrl (String)
4670 ```
4671
4672 Set the request url
4673 When sending a request to http client this should be full url.
4674
4675 ```
4676 string my_zhttp_request.contentType ()
4677 ```
4678
4679 Get the request content type
4680
4681 ```
4682 nothing my_zhttp_request.setContentType (String)
4683 ```
4684
4685 Set the request content type
4686
4687 ```
4688 size my_zhttp_request.contentLength ()
4689 ```
4690
4691 Get the content length of the request
4692
4693 ```
4694 zhash my_zhttp_request.headers ()
4695 ```
4696
4697 Get the headers of the request
4698
4699 ```
4700 string my_zhttp_request.content ()
4701 ```
4702
4703 Get the content of the request.
4704
4705 ```
4706 string my_zhttp_request.getContent ()
4707 ```
4708
4709 Get the content of the request.
4710
4711 ```
4712 nothing my_zhttp_request.setContent (String)
4713 ```
4714
4715 Set the content of the request.
4716 Content must by dynamically allocated string.
4717 Takes ownership of the content.
4718
4719 ```
4720 nothing my_zhttp_request.setContentConst (String)
4721 ```
4722
4723 Set the content of the request..
4724 The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
4725
4726 ```
4727 nothing my_zhttp_request.resetContent ()
4728 ```
4729
4730 Set the content to NULL
4731
4732 ```
4733 boolean my_zhttp_request.match (String, String)
4734 ```
4735
4736 Match the path of the request.
4737 Support wildcards with '%s' symbol inside the match string.
4738 Matching wildcards until the next '/', '?' or '\0'.
4739 On successful match the variadic arguments will be filled with the matching strings.
4740 On successful match the method is modifying the url field and break it into substrings.
4741 If you need to use the url, do it before matching or take a copy.
4742
4743 User must not free the variadic arguments as they are part of the url.
4744
4745 To use the percent symbol, just double it, e.g "%%something".
4746
4747 Example:
4748 if (zhttp_request_match (request, "POST", "/send/%s/%s", &name, &id))
4749
4750 ```
4751 nothing my_zhttp_request.test (Boolean)
4752 ```
4753
4754 Self test of this class.
4755
4756 ### The ZhttpResponse class - Http response that can be received from zhttp_client or sent to zhttp_server.
4757 Class can be reused between send & recv calls.
4758 Headers and Content is being destroyed after every send call.
4759
4760 Constructor:
4761
4762 ```
4763 var czmq = require ('bindings')('czmq')
4764 var my_zhttp_response = new czmq.ZhttpResponse ()
4765 ```
4766
4767 You *must* call the destructor on every ZhttpResponse instance:
4768
4769 ```
4770 my_zhttp_response.destroy ()
4771 ```
4772
4773 Methods:
4774
4775 ```
4776 string my_zhttp_response.contentType ()
4777 ```
4778
4779 Get the response content type
4780
4781 ```
4782 nothing my_zhttp_response.setContentType (String)
4783 ```
4784
4785 Set the content type of the response.
4786
4787 ```
4788 number my_zhttp_response.statusCode ()
4789 ```
4790
4791 Get the status code of the response.
4792
4793 ```
4794 nothing my_zhttp_response.setStatusCode (Number)
4795 ```
4796
4797 Set the status code of the response.
4798
4799 ```
4800 zhash my_zhttp_response.headers ()
4801 ```
4802
4803 Get the headers of the response.
4804
4805 ```
4806 size my_zhttp_response.contentLength ()
4807 ```
4808
4809 Get the content length of the response
4810
4811 ```
4812 string my_zhttp_response.content ()
4813 ```
4814
4815 Get the content of the response.
4816
4817 ```
4818 string my_zhttp_response.getContent ()
4819 ```
4820
4821 Get the content of the response.
4822
4823 ```
4824 nothing my_zhttp_response.setContent (String)
4825 ```
4826
4827 Set the content of the response.
4828 Content must by dynamically allocated string.
4829 Takes ownership of the content.
4830
4831 ```
4832 nothing my_zhttp_response.setContentConst (String)
4833 ```
4834
4835 Set the content of the response.
4836 The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
4837
4838 ```
4839 nothing my_zhttp_response.resetContent ()
4840 ```
4841
4842 Set the content to NULL
4843
4844 ```
4845 nothing my_zhttp_response.test (Boolean)
4846 ```
4847
4848 Self test of this class.
3838 Nan::SetPrototypeMethod (tpl, "paramFirst", _param_first);
3939 Nan::SetPrototypeMethod (tpl, "paramNext", _param_next);
4040 Nan::SetPrototypeMethod (tpl, "paramName", _param_name);
41 Nan::SetPrototypeMethod (tpl, "paramLookup", _param_lookup);
42 Nan::SetPrototypeMethod (tpl, "paramLookupx", _param_lookupx);
43 Nan::SetPrototypeMethod (tpl, "hasHelp", _has_help);
44 Nan::SetPrototypeMethod (tpl, "paramEmpty", _param_empty);
41 Nan::SetPrototypeMethod (tpl, "get", _get);
42 Nan::SetPrototypeMethod (tpl, "getx", _getx);
43 Nan::SetPrototypeMethod (tpl, "has", _has);
44 Nan::SetPrototypeMethod (tpl, "hasx", _hasx);
4545 Nan::SetPrototypeMethod (tpl, "print", _print);
4646 Nan::SetPrototypeMethod (tpl, "test", _test);
4747
146146 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
147147 }
148148
149 NAN_METHOD (Zargs::_param_lookup) {
149 NAN_METHOD (Zargs::_get) {
150150 Zargs *zargs = Nan::ObjectWrap::Unwrap <Zargs> (info.Holder ());
151 char *keys;
152 if (info [0]->IsUndefined ())
153 return Nan::ThrowTypeError ("method requires a `keys`");
154 else
155 if (!info [0]->IsString ())
156 return Nan::ThrowTypeError ("`keys` must be a string");
157 //else { // bjornw: remove brackets to keep scope
158 Nan::Utf8String keys_utf8 (info [0].As<String>());
159 keys = *keys_utf8;
160 //} //bjornw end
161 char *result = (char *) zargs_param_lookup (zargs->self, (const char *)keys);
151 char *name;
152 if (info [0]->IsUndefined ())
153 return Nan::ThrowTypeError ("method requires a `name`");
154 else
155 if (!info [0]->IsString ())
156 return Nan::ThrowTypeError ("`name` must be a string");
157 //else { // bjornw: remove brackets to keep scope
158 Nan::Utf8String name_utf8 (info [0].As<String>());
159 name = *name_utf8;
160 //} //bjornw end
161 char *result = (char *) zargs_get (zargs->self, (const char *)name);
162162 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
163163 }
164164
165 NAN_METHOD (Zargs::_param_lookupx) {
165 NAN_METHOD (Zargs::_getx) {
166166 Zargs *zargs = Nan::ObjectWrap::Unwrap <Zargs> (info.Holder ());
167 char *keys;
168 if (info [0]->IsUndefined ())
169 return Nan::ThrowTypeError ("method requires a `keys`");
170 else
171 if (!info [0]->IsString ())
172 return Nan::ThrowTypeError ("`keys` must be a string");
173 //else { // bjornw: remove brackets to keep scope
174 Nan::Utf8String keys_utf8 (info [0].As<String>());
175 keys = *keys_utf8;
176 //} //bjornw end
177 char *result = (char *) zargs_param_lookupx (zargs->self, (const char *)keys);
167 char *name;
168 if (info [0]->IsUndefined ())
169 return Nan::ThrowTypeError ("method requires a `name`");
170 else
171 if (!info [0]->IsString ())
172 return Nan::ThrowTypeError ("`name` must be a string");
173 //else { // bjornw: remove brackets to keep scope
174 Nan::Utf8String name_utf8 (info [0].As<String>());
175 name = *name_utf8;
176 //} //bjornw end
177 char *result = (char *) zargs_getx (zargs->self, (const char *)name);
178178 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
179179 }
180180
181 NAN_METHOD (Zargs::_has_help) {
181 NAN_METHOD (Zargs::_has) {
182182 Zargs *zargs = Nan::ObjectWrap::Unwrap <Zargs> (info.Holder ());
183 bool result = zargs_has_help (zargs->self);
183 char *name;
184 if (info [0]->IsUndefined ())
185 return Nan::ThrowTypeError ("method requires a `name`");
186 else
187 if (!info [0]->IsString ())
188 return Nan::ThrowTypeError ("`name` must be a string");
189 //else { // bjornw: remove brackets to keep scope
190 Nan::Utf8String name_utf8 (info [0].As<String>());
191 name = *name_utf8;
192 //} //bjornw end
193 bool result = zargs_has (zargs->self, (const char *)name);
184194 info.GetReturnValue ().Set (Nan::New<Boolean>(result));
185195 }
186196
187 NAN_METHOD (Zargs::_param_empty) {
188 char *arg;
189 if (info [0]->IsUndefined ())
190 return Nan::ThrowTypeError ("method requires a `arg`");
191 else
192 if (!info [0]->IsString ())
193 return Nan::ThrowTypeError ("`arg` must be a string");
194 //else { // bjornw: remove brackets to keep scope
195 Nan::Utf8String arg_utf8 (info [0].As<String>());
196 arg = *arg_utf8;
197 //} //bjornw end
198 bool result = zargs_param_empty ((const char *)arg);
197 NAN_METHOD (Zargs::_hasx) {
198 Zargs *zargs = Nan::ObjectWrap::Unwrap <Zargs> (info.Holder ());
199 char *name;
200 if (info [0]->IsUndefined ())
201 return Nan::ThrowTypeError ("method requires a `name`");
202 else
203 if (!info [0]->IsString ())
204 return Nan::ThrowTypeError ("`name` must be a string");
205 //else { // bjornw: remove brackets to keep scope
206 Nan::Utf8String name_utf8 (info [0].As<String>());
207 name = *name_utf8;
208 //} //bjornw end
209 bool result = zargs_hasx (zargs->self, (const char *)name);
199210 info.GetReturnValue ().Set (Nan::New<Boolean>(result));
200211 }
201212
894905 Nan::SetPrototypeMethod (tpl, "strdup", _strdup);
895906 Nan::SetPrototypeMethod (tpl, "streq", _streq);
896907 Nan::SetPrototypeMethod (tpl, "pack", _pack);
908 Nan::SetPrototypeMethod (tpl, "packx", _packx);
897909 Nan::SetPrototypeMethod (tpl, "unpack", _unpack);
898910 Nan::SetPrototypeMethod (tpl, "digest", _digest);
899911 Nan::SetPrototypeMethod (tpl, "print", _print);
10941106 }
10951107 }
10961108
1109 NAN_METHOD (Zchunk::_packx) {
1110 Zchunk *self_p = Nan::ObjectWrap::Unwrap<Zchunk>(info [0].As<Object>());
1111 zframe_t *result = zchunk_packx (&self_p->self);
1112 Zframe *zframe_result = new Zframe (result);
1113 if (zframe_result) {
1114 // Don't yet know how to return a new object
1115 // zframe->Wrap (info.This ());
1116 // info.GetReturnValue ().Set (info.This ());
1117 info.GetReturnValue ().Set (Nan::New<Boolean>(true));
1118 }
1119 }
1120
10971121 NAN_METHOD (Zchunk::_unpack) {
10981122 Zframe *frame = Nan::ObjectWrap::Unwrap<Zframe>(info [0].As<Object>());
10991123 zchunk_t *result = zchunk_unpack (frame->self);
12471271 // Prototypes
12481272 Nan::SetPrototypeMethod (tpl, "destroy", destroy);
12491273 Nan::SetPrototypeMethod (tpl, "defined", defined);
1274 Nan::SetPrototypeMethod (tpl, "dup", _dup);
12501275 Nan::SetPrototypeMethod (tpl, "name", _name);
12511276 Nan::SetPrototypeMethod (tpl, "value", _value);
12521277 Nan::SetPrototypeMethod (tpl, "put", _put);
13211346 info.GetReturnValue ().Set (Nan::New (zconfig->self != NULL));
13221347 }
13231348
1349 NAN_METHOD (Zconfig::_dup) {
1350 Zconfig *zconfig = Nan::ObjectWrap::Unwrap <Zconfig> (info.Holder ());
1351 zconfig_t *result = zconfig_dup (zconfig->self);
1352 Zconfig *zconfig_result = new Zconfig (result);
1353 if (zconfig_result) {
1354 // Don't yet know how to return a new object
1355 // zconfig->Wrap (info.This ());
1356 // info.GetReturnValue ().Set (info.This ());
1357 info.GetReturnValue ().Set (Nan::New<Boolean>(true));
1358 }
1359 }
1360
13241361 NAN_METHOD (Zconfig::_name) {
13251362 Zconfig *zconfig = Nan::ObjectWrap::Unwrap <Zconfig> (info.Holder ());
13261363 char *result = (char *) zconfig_name (zconfig->self);
34533490 Nan::SetPrototypeMethod (tpl, "purge", _purge);
34543491 Nan::SetPrototypeMethod (tpl, "sort", _sort);
34553492 Nan::SetPrototypeMethod (tpl, "dup", _dup);
3493 Nan::SetPrototypeMethod (tpl, "pack", _pack);
34563494 Nan::SetPrototypeMethod (tpl, "test", _test);
34573495
34583496 constructor ().Reset (Nan::GetFunction (tpl).ToLocalChecked ());
35143552 if (zlistx_result) {
35153553 // Don't yet know how to return a new object
35163554 // zlistx->Wrap (info.This ());
3555 // info.GetReturnValue ().Set (info.This ());
3556 info.GetReturnValue ().Set (Nan::New<Boolean>(true));
3557 }
3558 }
3559
3560 NAN_METHOD (Zlistx::_pack) {
3561 Zlistx *zlistx = Nan::ObjectWrap::Unwrap <Zlistx> (info.Holder ());
3562 zframe_t *result = zlistx_pack (zlistx->self);
3563 Zframe *zframe_result = new Zframe (result);
3564 if (zframe_result) {
3565 // Don't yet know how to return a new object
3566 // zframe->Wrap (info.This ());
35173567 // info.GetReturnValue ().Set (info.This ());
35183568 info.GetReturnValue ().Set (Nan::New<Boolean>(true));
35193569 }
42214271 Nan::SetPrototypeMethod (tpl, "pid", _pid);
42224272 Nan::SetPrototypeMethod (tpl, "running", _running);
42234273 Nan::SetPrototypeMethod (tpl, "wait", _wait);
4274 Nan::SetPrototypeMethod (tpl, "shutdown", _shutdown);
42244275 Nan::SetPrototypeMethod (tpl, "kill", _kill);
42254276 Nan::SetPrototypeMethod (tpl, "setVerbose", _set_verbose);
42264277 Nan::SetPrototypeMethod (tpl, "test", _test);
43274378 NAN_METHOD (Zproc::_wait) {
43284379 Zproc *zproc = Nan::ObjectWrap::Unwrap <Zproc> (info.Holder ());
43294380 if (info [0]->IsUndefined ())
4330 return Nan::ThrowTypeError ("method requires a `hang`");
4331
4332 //bool hang; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
4333 bool hang;
4334
4335
4336 if (info [0]->IsBoolean ())
4337 {
4338 hang = Nan::To<bool>(info [0]).FromJust ();
4339 }
4340 else
4341 return Nan::ThrowTypeError ("`hang` must be a Boolean");
4342 int result = zproc_wait (zproc->self, (bool) hang);
4343 info.GetReturnValue ().Set (Nan::New<Number>(result));
4381 return Nan::ThrowTypeError ("method requires a `timeout`");
4382
4383 //int timeout; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
4384 int timeout;
4385
4386
4387 if (info [0]->IsNumber ())
4388 {
4389 timeout = Nan::To<int>(info [0]).FromJust ();
4390 }
4391 else
4392 return Nan::ThrowTypeError ("`timeout` must be a number");
4393 int result = zproc_wait (zproc->self, (int) timeout);
4394 info.GetReturnValue ().Set (Nan::New<Number>(result));
4395 }
4396
4397 NAN_METHOD (Zproc::_shutdown) {
4398 Zproc *zproc = Nan::ObjectWrap::Unwrap <Zproc> (info.Holder ());
4399 if (info [0]->IsUndefined ())
4400 return Nan::ThrowTypeError ("method requires a `timeout`");
4401
4402 //int timeout; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
4403 int timeout;
4404
4405
4406 if (info [0]->IsNumber ())
4407 {
4408 timeout = Nan::To<int>(info [0]).FromJust ();
4409 }
4410 else
4411 return Nan::ThrowTypeError ("`timeout` must be a number");
4412 zproc_shutdown (zproc->self, (int) timeout);
43444413 }
43454414
43464415 NAN_METHOD (Zproc::_kill) {
44314500 Nan::SetPrototypeMethod (tpl, "flush", _flush);
44324501 Nan::SetPrototypeMethod (tpl, "join", _join);
44334502 Nan::SetPrototypeMethod (tpl, "leave", _leave);
4503 Nan::SetPrototypeMethod (tpl, "hasIn", _has_in);
4504 Nan::SetPrototypeMethod (tpl, "routerNotify", _router_notify);
4505 Nan::SetPrototypeMethod (tpl, "setRouterNotify", _set_router_notify);
4506 Nan::SetPrototypeMethod (tpl, "multicastLoop", _multicast_loop);
4507 Nan::SetPrototypeMethod (tpl, "setMulticastLoop", _set_multicast_loop);
4508 Nan::SetPrototypeMethod (tpl, "metadata", _metadata);
4509 Nan::SetPrototypeMethod (tpl, "setMetadata", _set_metadata);
4510 Nan::SetPrototypeMethod (tpl, "loopbackFastpath", _loopback_fastpath);
4511 Nan::SetPrototypeMethod (tpl, "setLoopbackFastpath", _set_loopback_fastpath);
4512 Nan::SetPrototypeMethod (tpl, "zapEnforceDomain", _zap_enforce_domain);
4513 Nan::SetPrototypeMethod (tpl, "setZapEnforceDomain", _set_zap_enforce_domain);
4514 Nan::SetPrototypeMethod (tpl, "gssapiPrincipalNametype", _gssapi_principal_nametype);
4515 Nan::SetPrototypeMethod (tpl, "setGssapiPrincipalNametype", _set_gssapi_principal_nametype);
4516 Nan::SetPrototypeMethod (tpl, "gssapiServicePrincipalNametype", _gssapi_service_principal_nametype);
4517 Nan::SetPrototypeMethod (tpl, "setGssapiServicePrincipalNametype", _set_gssapi_service_principal_nametype);
4518 Nan::SetPrototypeMethod (tpl, "bindtodevice", _bindtodevice);
4519 Nan::SetPrototypeMethod (tpl, "setBindtodevice", _set_bindtodevice);
44344520 Nan::SetPrototypeMethod (tpl, "heartbeatIvl", _heartbeat_ivl);
44354521 Nan::SetPrototypeMethod (tpl, "setHeartbeatIvl", _set_heartbeat_ivl);
44364522 Nan::SetPrototypeMethod (tpl, "heartbeatTtl", _heartbeat_ttl);
49235009 info.GetReturnValue ().Set (Nan::New<Number>(result));
49245010 }
49255011
5012 NAN_METHOD (Zsock::_has_in) {
5013 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5014 bool result = zsock_has_in (zsock->self);
5015 info.GetReturnValue ().Set (Nan::New<Boolean>(result));
5016 }
5017
5018 NAN_METHOD (Zsock::_router_notify) {
5019 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5020 int result = zsock_router_notify (zsock->self);
5021 info.GetReturnValue ().Set (Nan::New<Number>(result));
5022 }
5023
5024 NAN_METHOD (Zsock::_set_router_notify) {
5025 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5026 if (info [0]->IsUndefined ())
5027 return Nan::ThrowTypeError ("method requires a `router notify`");
5028
5029 //int router_notify; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
5030 int router_notify;
5031
5032
5033 if (info [0]->IsNumber ())
5034 {
5035 router_notify = Nan::To<int>(info [0]).FromJust ();
5036 }
5037 else
5038 return Nan::ThrowTypeError ("`router notify` must be a number");
5039 zsock_set_router_notify (zsock->self, (int) router_notify);
5040 }
5041
5042 NAN_METHOD (Zsock::_multicast_loop) {
5043 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5044 int result = zsock_multicast_loop (zsock->self);
5045 info.GetReturnValue ().Set (Nan::New<Number>(result));
5046 }
5047
5048 NAN_METHOD (Zsock::_set_multicast_loop) {
5049 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5050 if (info [0]->IsUndefined ())
5051 return Nan::ThrowTypeError ("method requires a `multicast loop`");
5052
5053 //int multicast_loop; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
5054 int multicast_loop;
5055
5056
5057 if (info [0]->IsNumber ())
5058 {
5059 multicast_loop = Nan::To<int>(info [0]).FromJust ();
5060 }
5061 else
5062 return Nan::ThrowTypeError ("`multicast loop` must be a number");
5063 zsock_set_multicast_loop (zsock->self, (int) multicast_loop);
5064 }
5065
5066 NAN_METHOD (Zsock::_metadata) {
5067 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5068 char *result = (char *) zsock_metadata (zsock->self);
5069 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
5070 }
5071
5072 NAN_METHOD (Zsock::_set_metadata) {
5073 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5074 char *metadata;
5075 if (info [0]->IsUndefined ())
5076 return Nan::ThrowTypeError ("method requires a `metadata`");
5077 else
5078 if (!info [0]->IsString ())
5079 return Nan::ThrowTypeError ("`metadata` must be a string");
5080 //else { // bjornw: remove brackets to keep scope
5081 Nan::Utf8String metadata_utf8 (info [0].As<String>());
5082 metadata = *metadata_utf8;
5083 //} //bjornw end
5084 zsock_set_metadata (zsock->self, (const char *)metadata);
5085 }
5086
5087 NAN_METHOD (Zsock::_loopback_fastpath) {
5088 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5089 int result = zsock_loopback_fastpath (zsock->self);
5090 info.GetReturnValue ().Set (Nan::New<Number>(result));
5091 }
5092
5093 NAN_METHOD (Zsock::_set_loopback_fastpath) {
5094 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5095 if (info [0]->IsUndefined ())
5096 return Nan::ThrowTypeError ("method requires a `loopback fastpath`");
5097
5098 //int loopback_fastpath; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
5099 int loopback_fastpath;
5100
5101
5102 if (info [0]->IsNumber ())
5103 {
5104 loopback_fastpath = Nan::To<int>(info [0]).FromJust ();
5105 }
5106 else
5107 return Nan::ThrowTypeError ("`loopback fastpath` must be a number");
5108 zsock_set_loopback_fastpath (zsock->self, (int) loopback_fastpath);
5109 }
5110
5111 NAN_METHOD (Zsock::_zap_enforce_domain) {
5112 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5113 int result = zsock_zap_enforce_domain (zsock->self);
5114 info.GetReturnValue ().Set (Nan::New<Number>(result));
5115 }
5116
5117 NAN_METHOD (Zsock::_set_zap_enforce_domain) {
5118 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5119 if (info [0]->IsUndefined ())
5120 return Nan::ThrowTypeError ("method requires a `zap enforce domain`");
5121
5122 //int zap_enforce_domain; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
5123 int zap_enforce_domain;
5124
5125
5126 if (info [0]->IsNumber ())
5127 {
5128 zap_enforce_domain = Nan::To<int>(info [0]).FromJust ();
5129 }
5130 else
5131 return Nan::ThrowTypeError ("`zap enforce domain` must be a number");
5132 zsock_set_zap_enforce_domain (zsock->self, (int) zap_enforce_domain);
5133 }
5134
5135 NAN_METHOD (Zsock::_gssapi_principal_nametype) {
5136 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5137 int result = zsock_gssapi_principal_nametype (zsock->self);
5138 info.GetReturnValue ().Set (Nan::New<Number>(result));
5139 }
5140
5141 NAN_METHOD (Zsock::_set_gssapi_principal_nametype) {
5142 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5143 if (info [0]->IsUndefined ())
5144 return Nan::ThrowTypeError ("method requires a `gssapi principal nametype`");
5145
5146 //int gssapi_principal_nametype; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
5147 int gssapi_principal_nametype;
5148
5149
5150 if (info [0]->IsNumber ())
5151 {
5152 gssapi_principal_nametype = Nan::To<int>(info [0]).FromJust ();
5153 }
5154 else
5155 return Nan::ThrowTypeError ("`gssapi principal nametype` must be a number");
5156 zsock_set_gssapi_principal_nametype (zsock->self, (int) gssapi_principal_nametype);
5157 }
5158
5159 NAN_METHOD (Zsock::_gssapi_service_principal_nametype) {
5160 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5161 int result = zsock_gssapi_service_principal_nametype (zsock->self);
5162 info.GetReturnValue ().Set (Nan::New<Number>(result));
5163 }
5164
5165 NAN_METHOD (Zsock::_set_gssapi_service_principal_nametype) {
5166 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5167 if (info [0]->IsUndefined ())
5168 return Nan::ThrowTypeError ("method requires a `gssapi service principal nametype`");
5169
5170 //int gssapi_service_principal_nametype; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
5171 int gssapi_service_principal_nametype;
5172
5173
5174 if (info [0]->IsNumber ())
5175 {
5176 gssapi_service_principal_nametype = Nan::To<int>(info [0]).FromJust ();
5177 }
5178 else
5179 return Nan::ThrowTypeError ("`gssapi service principal nametype` must be a number");
5180 zsock_set_gssapi_service_principal_nametype (zsock->self, (int) gssapi_service_principal_nametype);
5181 }
5182
5183 NAN_METHOD (Zsock::_bindtodevice) {
5184 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5185 char *result = (char *) zsock_bindtodevice (zsock->self);
5186 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
5187 }
5188
5189 NAN_METHOD (Zsock::_set_bindtodevice) {
5190 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
5191 char *bindtodevice;
5192 if (info [0]->IsUndefined ())
5193 return Nan::ThrowTypeError ("method requires a `bindtodevice`");
5194 else
5195 if (!info [0]->IsString ())
5196 return Nan::ThrowTypeError ("`bindtodevice` must be a string");
5197 //else { // bjornw: remove brackets to keep scope
5198 Nan::Utf8String bindtodevice_utf8 (info [0].As<String>());
5199 bindtodevice = *bindtodevice_utf8;
5200 //} //bjornw end
5201 zsock_set_bindtodevice (zsock->self, (const char *)bindtodevice);
5202 }
5203
49265204 NAN_METHOD (Zsock::_heartbeat_ivl) {
49275205 Zsock *zsock = Nan::ObjectWrap::Unwrap <Zsock> (info.Holder ());
49285206 int result = zsock_heartbeat_ivl (zsock->self);
68527130 Nan::SetPrototypeMethod (tpl, "fileModePrivate", _file_mode_private);
68537131 Nan::SetPrototypeMethod (tpl, "fileModeDefault", _file_mode_default);
68547132 Nan::SetPrototypeMethod (tpl, "version", _version);
7133 Nan::SetPrototypeMethod (tpl, "sprintfHint", _sprintf_hint);
68557134 Nan::SetPrototypeMethod (tpl, "sprintf", _sprintf);
68567135 Nan::SetPrototypeMethod (tpl, "socketError", _socket_error);
68577136 Nan::SetPrototypeMethod (tpl, "hostname", _hostname);
68617140 Nan::SetPrototypeMethod (tpl, "setIoThreads", _set_io_threads);
68627141 Nan::SetPrototypeMethod (tpl, "setThreadSchedPolicy", _set_thread_sched_policy);
68637142 Nan::SetPrototypeMethod (tpl, "setThreadPriority", _set_thread_priority);
7143 Nan::SetPrototypeMethod (tpl, "setThreadNamePrefix", _set_thread_name_prefix);
7144 Nan::SetPrototypeMethod (tpl, "threadNamePrefix", _thread_name_prefix);
7145 Nan::SetPrototypeMethod (tpl, "threadAffinityCpuAdd", _thread_affinity_cpu_add);
7146 Nan::SetPrototypeMethod (tpl, "threadAffinityCpuRemove", _thread_affinity_cpu_remove);
68647147 Nan::SetPrototypeMethod (tpl, "setMaxSockets", _set_max_sockets);
68657148 Nan::SetPrototypeMethod (tpl, "socketLimit", _socket_limit);
68667149 Nan::SetPrototypeMethod (tpl, "setMaxMsgsz", _set_max_msgsz);
68847167 Nan::SetPrototypeMethod (tpl, "ipv6McastAddress", _ipv6_mcast_address);
68857168 Nan::SetPrototypeMethod (tpl, "setAutoUseFd", _set_auto_use_fd);
68867169 Nan::SetPrototypeMethod (tpl, "autoUseFd", _auto_use_fd);
7170 Nan::SetPrototypeMethod (tpl, "zprintf", _zprintf);
7171 Nan::SetPrototypeMethod (tpl, "zprintfError", _zprintf_error);
7172 Nan::SetPrototypeMethod (tpl, "zplprintf", _zplprintf);
7173 Nan::SetPrototypeMethod (tpl, "zplprintfError", _zplprintf_error);
68877174 Nan::SetPrototypeMethod (tpl, "setLogident", _set_logident);
68887175 Nan::SetPrototypeMethod (tpl, "setLogsender", _set_logsender);
68897176 Nan::SetPrototypeMethod (tpl, "setLogsystem", _set_logsystem);
71367423 zsys_version ((int *) &major, (int *) &minor, (int *) &patch);
71377424 }
71387425
7426 NAN_METHOD (Zsys::_sprintf_hint) {
7427 if (info [0]->IsUndefined ())
7428 return Nan::ThrowTypeError ("method requires a `hint`");
7429
7430 //int hint; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
7431 int hint;
7432
7433
7434 if (info [0]->IsNumber ())
7435 {
7436 hint = Nan::To<int>(info [0]).FromJust ();
7437 }
7438 else
7439 return Nan::ThrowTypeError ("`hint` must be a number");
7440 char *format;
7441 if (info [1]->IsUndefined ())
7442 return Nan::ThrowTypeError ("method requires a `format`");
7443 else
7444 if (!info [1]->IsString ())
7445 return Nan::ThrowTypeError ("`format` must be a string");
7446 //else { // bjornw: remove brackets to keep scope
7447 Nan::Utf8String format_utf8 (info [1].As<String>());
7448 format = *format_utf8;
7449 //} //bjornw end
7450 char *result = (char *) zsys_sprintf_hint ((int) hint, (const char *)format);
7451 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
7452 }
7453
71397454 NAN_METHOD (Zsys::_sprintf) {
71407455 char *format;
71417456 if (info [0]->IsUndefined ())
72697584 zsys_set_thread_priority ((int) priority);
72707585 }
72717586
7587 NAN_METHOD (Zsys::_set_thread_name_prefix) {
7588 if (info [0]->IsUndefined ())
7589 return Nan::ThrowTypeError ("method requires a `prefix`");
7590
7591 //int prefix; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
7592 int prefix;
7593
7594
7595 if (info [0]->IsNumber ())
7596 {
7597 prefix = Nan::To<int>(info [0]).FromJust ();
7598 }
7599 else
7600 return Nan::ThrowTypeError ("`prefix` must be a number");
7601 zsys_set_thread_name_prefix ((int) prefix);
7602 }
7603
7604 NAN_METHOD (Zsys::_thread_name_prefix) {
7605 int result = zsys_thread_name_prefix ();
7606 info.GetReturnValue ().Set (Nan::New<Number>(result));
7607 }
7608
7609 NAN_METHOD (Zsys::_thread_affinity_cpu_add) {
7610 if (info [0]->IsUndefined ())
7611 return Nan::ThrowTypeError ("method requires a `cpu`");
7612
7613 //int cpu; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
7614 int cpu;
7615
7616
7617 if (info [0]->IsNumber ())
7618 {
7619 cpu = Nan::To<int>(info [0]).FromJust ();
7620 }
7621 else
7622 return Nan::ThrowTypeError ("`cpu` must be a number");
7623 zsys_thread_affinity_cpu_add ((int) cpu);
7624 }
7625
7626 NAN_METHOD (Zsys::_thread_affinity_cpu_remove) {
7627 if (info [0]->IsUndefined ())
7628 return Nan::ThrowTypeError ("method requires a `cpu`");
7629
7630 //int cpu; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
7631 int cpu;
7632
7633
7634 if (info [0]->IsNumber ())
7635 {
7636 cpu = Nan::To<int>(info [0]).FromJust ();
7637 }
7638 else
7639 return Nan::ThrowTypeError ("`cpu` must be a number");
7640 zsys_thread_affinity_cpu_remove ((int) cpu);
7641 }
7642
72727643 NAN_METHOD (Zsys::_set_max_sockets) {
72737644 if (info [0]->IsUndefined ())
72747645 return Nan::ThrowTypeError ("method requires a `max sockets`");
74947865 NAN_METHOD (Zsys::_auto_use_fd) {
74957866 int result = zsys_auto_use_fd ();
74967867 info.GetReturnValue ().Set (Nan::New<Number>(result));
7868 }
7869
7870 NAN_METHOD (Zsys::_zprintf) {
7871 char *format;
7872 if (info [0]->IsUndefined ())
7873 return Nan::ThrowTypeError ("method requires a `format`");
7874 else
7875 if (!info [0]->IsString ())
7876 return Nan::ThrowTypeError ("`format` must be a string");
7877 //else { // bjornw: remove brackets to keep scope
7878 Nan::Utf8String format_utf8 (info [0].As<String>());
7879 format = *format_utf8;
7880 //} //bjornw end
7881 Zhash *args = Nan::ObjectWrap::Unwrap<Zhash>(info [1].As<Object>());
7882 char *result = (char *) zsys_zprintf ((const char *)format, args->self);
7883 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
7884 }
7885
7886 NAN_METHOD (Zsys::_zprintf_error) {
7887 char *format;
7888 if (info [0]->IsUndefined ())
7889 return Nan::ThrowTypeError ("method requires a `format`");
7890 else
7891 if (!info [0]->IsString ())
7892 return Nan::ThrowTypeError ("`format` must be a string");
7893 //else { // bjornw: remove brackets to keep scope
7894 Nan::Utf8String format_utf8 (info [0].As<String>());
7895 format = *format_utf8;
7896 //} //bjornw end
7897 Zhash *args = Nan::ObjectWrap::Unwrap<Zhash>(info [1].As<Object>());
7898 char *result = (char *) zsys_zprintf_error ((const char *)format, args->self);
7899 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
7900 }
7901
7902 NAN_METHOD (Zsys::_zplprintf) {
7903 char *format;
7904 if (info [0]->IsUndefined ())
7905 return Nan::ThrowTypeError ("method requires a `format`");
7906 else
7907 if (!info [0]->IsString ())
7908 return Nan::ThrowTypeError ("`format` must be a string");
7909 //else { // bjornw: remove brackets to keep scope
7910 Nan::Utf8String format_utf8 (info [0].As<String>());
7911 format = *format_utf8;
7912 //} //bjornw end
7913 Zconfig *args = Nan::ObjectWrap::Unwrap<Zconfig>(info [1].As<Object>());
7914 char *result = (char *) zsys_zplprintf ((const char *)format, args->self);
7915 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
7916 }
7917
7918 NAN_METHOD (Zsys::_zplprintf_error) {
7919 char *format;
7920 if (info [0]->IsUndefined ())
7921 return Nan::ThrowTypeError ("method requires a `format`");
7922 else
7923 if (!info [0]->IsString ())
7924 return Nan::ThrowTypeError ("`format` must be a string");
7925 //else { // bjornw: remove brackets to keep scope
7926 Nan::Utf8String format_utf8 (info [0].As<String>());
7927 format = *format_utf8;
7928 //} //bjornw end
7929 Zconfig *args = Nan::ObjectWrap::Unwrap<Zconfig>(info [1].As<Object>());
7930 char *result = (char *) zsys_zplprintf_error ((const char *)format, args->self);
7931 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
74977932 }
74987933
74997934 NAN_METHOD (Zsys::_set_logident) {
81088543 }
81098544
81108545 Nan::Persistent <Function> &Zuuid::constructor () {
8546 static Nan::Persistent <Function> my_constructor;
8547 return my_constructor;
8548 }
8549
8550
8551 NAN_MODULE_INIT (ZhttpClient::Init) {
8552 Nan::HandleScope scope;
8553
8554 // Prepare constructor template
8555 Local <FunctionTemplate> tpl = Nan::New <FunctionTemplate> (New);
8556 tpl->SetClassName (Nan::New ("ZhttpClient").ToLocalChecked ());
8557 tpl->InstanceTemplate ()->SetInternalFieldCount (1);
8558
8559 // Prototypes
8560 Nan::SetPrototypeMethod (tpl, "destroy", destroy);
8561 Nan::SetPrototypeMethod (tpl, "defined", defined);
8562 Nan::SetPrototypeMethod (tpl, "test", _test);
8563
8564 constructor ().Reset (Nan::GetFunction (tpl).ToLocalChecked ());
8565 Nan::Set (target, Nan::New ("ZhttpClient").ToLocalChecked (),
8566 Nan::GetFunction (tpl).ToLocalChecked ());
8567 }
8568
8569 ZhttpClient::ZhttpClient (bool verbose) {
8570 self = zhttp_client_new ((bool) verbose);
8571 }
8572
8573 ZhttpClient::ZhttpClient (zhttp_client_t *self_) {
8574 self = self_;
8575 }
8576
8577 ZhttpClient::~ZhttpClient () {
8578 }
8579
8580 NAN_METHOD (ZhttpClient::New) {
8581 assert (info.IsConstructCall ());
8582 if (info [0]->IsUndefined ())
8583 return Nan::ThrowTypeError ("method requires a `verbose`");
8584
8585 //bool verbose; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
8586 bool verbose;
8587
8588
8589 if (info [0]->IsBoolean ())
8590 {
8591 verbose = Nan::To<bool>(info [0]).FromJust ();
8592 }
8593 else
8594 return Nan::ThrowTypeError ("`verbose` must be a Boolean");
8595 ZhttpClient *zhttp_client = new ZhttpClient ((bool) verbose);
8596 if (zhttp_client) {
8597 zhttp_client->Wrap (info.This ());
8598 info.GetReturnValue ().Set (info.This ());
8599 }
8600 }
8601
8602 NAN_METHOD (ZhttpClient::destroy) {
8603 ZhttpClient *zhttp_client = Nan::ObjectWrap::Unwrap <ZhttpClient> (info.Holder ());
8604 zhttp_client_destroy (&zhttp_client->self);
8605 }
8606
8607
8608 NAN_METHOD (ZhttpClient::defined) {
8609 ZhttpClient *zhttp_client = Nan::ObjectWrap::Unwrap <ZhttpClient> (info.Holder ());
8610 info.GetReturnValue ().Set (Nan::New (zhttp_client->self != NULL));
8611 }
8612
8613 NAN_METHOD (ZhttpClient::_test) {
8614 if (info [0]->IsUndefined ())
8615 return Nan::ThrowTypeError ("method requires a `verbose`");
8616
8617 //bool verbose; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
8618 bool verbose;
8619
8620
8621 if (info [0]->IsBoolean ())
8622 {
8623 verbose = Nan::To<bool>(info [0]).FromJust ();
8624 }
8625 else
8626 return Nan::ThrowTypeError ("`verbose` must be a Boolean");
8627 zhttp_client_test ((bool) verbose);
8628 }
8629
8630 Nan::Persistent <Function> &ZhttpClient::constructor () {
8631 static Nan::Persistent <Function> my_constructor;
8632 return my_constructor;
8633 }
8634
8635
8636 NAN_MODULE_INIT (ZhttpServer::Init) {
8637 Nan::HandleScope scope;
8638
8639 // Prepare constructor template
8640 Local <FunctionTemplate> tpl = Nan::New <FunctionTemplate> (New);
8641 tpl->SetClassName (Nan::New ("ZhttpServer").ToLocalChecked ());
8642 tpl->InstanceTemplate ()->SetInternalFieldCount (1);
8643
8644 // Prototypes
8645 Nan::SetPrototypeMethod (tpl, "destroy", destroy);
8646 Nan::SetPrototypeMethod (tpl, "defined", defined);
8647 Nan::SetPrototypeMethod (tpl, "port", _port);
8648 Nan::SetPrototypeMethod (tpl, "test", _test);
8649
8650 constructor ().Reset (Nan::GetFunction (tpl).ToLocalChecked ());
8651 Nan::Set (target, Nan::New ("ZhttpServer").ToLocalChecked (),
8652 Nan::GetFunction (tpl).ToLocalChecked ());
8653 }
8654
8655 ZhttpServer::ZhttpServer (zhttp_server_options_t *options) {
8656 self = zhttp_server_new (options);
8657 }
8658
8659 ZhttpServer::ZhttpServer (zhttp_server_t *self_) {
8660 self = self_;
8661 }
8662
8663 ZhttpServer::~ZhttpServer () {
8664 }
8665
8666 NAN_METHOD (ZhttpServer::New) {
8667 assert (info.IsConstructCall ());
8668 ZhttpServerOptions *options = Nan::ObjectWrap::Unwrap<ZhttpServerOptions>(info [0].As<Object>());
8669 ZhttpServer *zhttp_server = new ZhttpServer (options->self);
8670 if (zhttp_server) {
8671 zhttp_server->Wrap (info.This ());
8672 info.GetReturnValue ().Set (info.This ());
8673 }
8674 }
8675
8676 NAN_METHOD (ZhttpServer::destroy) {
8677 ZhttpServer *zhttp_server = Nan::ObjectWrap::Unwrap <ZhttpServer> (info.Holder ());
8678 zhttp_server_destroy (&zhttp_server->self);
8679 }
8680
8681
8682 NAN_METHOD (ZhttpServer::defined) {
8683 ZhttpServer *zhttp_server = Nan::ObjectWrap::Unwrap <ZhttpServer> (info.Holder ());
8684 info.GetReturnValue ().Set (Nan::New (zhttp_server->self != NULL));
8685 }
8686
8687 NAN_METHOD (ZhttpServer::_port) {
8688 ZhttpServer *zhttp_server = Nan::ObjectWrap::Unwrap <ZhttpServer> (info.Holder ());
8689 int result = zhttp_server_port (zhttp_server->self);
8690 info.GetReturnValue ().Set (Nan::New<Number>(result));
8691 }
8692
8693 NAN_METHOD (ZhttpServer::_test) {
8694 if (info [0]->IsUndefined ())
8695 return Nan::ThrowTypeError ("method requires a `verbose`");
8696
8697 //bool verbose; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
8698 bool verbose;
8699
8700
8701 if (info [0]->IsBoolean ())
8702 {
8703 verbose = Nan::To<bool>(info [0]).FromJust ();
8704 }
8705 else
8706 return Nan::ThrowTypeError ("`verbose` must be a Boolean");
8707 zhttp_server_test ((bool) verbose);
8708 }
8709
8710 Nan::Persistent <Function> &ZhttpServer::constructor () {
8711 static Nan::Persistent <Function> my_constructor;
8712 return my_constructor;
8713 }
8714
8715
8716 NAN_MODULE_INIT (ZhttpServerOptions::Init) {
8717 Nan::HandleScope scope;
8718
8719 // Prepare constructor template
8720 Local <FunctionTemplate> tpl = Nan::New <FunctionTemplate> (New);
8721 tpl->SetClassName (Nan::New ("ZhttpServerOptions").ToLocalChecked ());
8722 tpl->InstanceTemplate ()->SetInternalFieldCount (1);
8723
8724 // Prototypes
8725 Nan::SetPrototypeMethod (tpl, "destroy", destroy);
8726 Nan::SetPrototypeMethod (tpl, "defined", defined);
8727 Nan::SetPrototypeMethod (tpl, "port", _port);
8728 Nan::SetPrototypeMethod (tpl, "setPort", _set_port);
8729 Nan::SetPrototypeMethod (tpl, "backendAddress", _backend_address);
8730 Nan::SetPrototypeMethod (tpl, "setBackendAddress", _set_backend_address);
8731 Nan::SetPrototypeMethod (tpl, "test", _test);
8732
8733 constructor ().Reset (Nan::GetFunction (tpl).ToLocalChecked ());
8734 Nan::Set (target, Nan::New ("ZhttpServerOptions").ToLocalChecked (),
8735 Nan::GetFunction (tpl).ToLocalChecked ());
8736 }
8737
8738 ZhttpServerOptions::ZhttpServerOptions (void) {
8739 self = zhttp_server_options_new ();
8740 }
8741
8742 ZhttpServerOptions::ZhttpServerOptions (zhttp_server_options_t *self_) {
8743 self = self_;
8744 }
8745
8746 ZhttpServerOptions::~ZhttpServerOptions () {
8747 }
8748
8749 NAN_METHOD (ZhttpServerOptions::New) {
8750 assert (info.IsConstructCall ());
8751 ZhttpServerOptions *zhttp_server_options = new ZhttpServerOptions ();
8752 if (zhttp_server_options) {
8753 zhttp_server_options->Wrap (info.This ());
8754 info.GetReturnValue ().Set (info.This ());
8755 }
8756 }
8757
8758 NAN_METHOD (ZhttpServerOptions::destroy) {
8759 ZhttpServerOptions *zhttp_server_options = Nan::ObjectWrap::Unwrap <ZhttpServerOptions> (info.Holder ());
8760 zhttp_server_options_destroy (&zhttp_server_options->self);
8761 }
8762
8763
8764 NAN_METHOD (ZhttpServerOptions::defined) {
8765 ZhttpServerOptions *zhttp_server_options = Nan::ObjectWrap::Unwrap <ZhttpServerOptions> (info.Holder ());
8766 info.GetReturnValue ().Set (Nan::New (zhttp_server_options->self != NULL));
8767 }
8768
8769 NAN_METHOD (ZhttpServerOptions::_port) {
8770 ZhttpServerOptions *zhttp_server_options = Nan::ObjectWrap::Unwrap <ZhttpServerOptions> (info.Holder ());
8771 int result = zhttp_server_options_port (zhttp_server_options->self);
8772 info.GetReturnValue ().Set (Nan::New<Number>(result));
8773 }
8774
8775 NAN_METHOD (ZhttpServerOptions::_set_port) {
8776 ZhttpServerOptions *zhttp_server_options = Nan::ObjectWrap::Unwrap <ZhttpServerOptions> (info.Holder ());
8777 if (info [0]->IsUndefined ())
8778 return Nan::ThrowTypeError ("method requires a `port`");
8779
8780 //int port; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
8781 int port;
8782
8783
8784 if (info [0]->IsNumber ())
8785 {
8786 port = Nan::To<int>(info [0]).FromJust ();
8787 }
8788 else
8789 return Nan::ThrowTypeError ("`port` must be a number");
8790 zhttp_server_options_set_port (zhttp_server_options->self, (int) port);
8791 }
8792
8793 NAN_METHOD (ZhttpServerOptions::_backend_address) {
8794 ZhttpServerOptions *zhttp_server_options = Nan::ObjectWrap::Unwrap <ZhttpServerOptions> (info.Holder ());
8795 char *result = (char *) zhttp_server_options_backend_address (zhttp_server_options->self);
8796 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
8797 }
8798
8799 NAN_METHOD (ZhttpServerOptions::_set_backend_address) {
8800 ZhttpServerOptions *zhttp_server_options = Nan::ObjectWrap::Unwrap <ZhttpServerOptions> (info.Holder ());
8801 char *address;
8802 if (info [0]->IsUndefined ())
8803 return Nan::ThrowTypeError ("method requires a `address`");
8804 else
8805 if (!info [0]->IsString ())
8806 return Nan::ThrowTypeError ("`address` must be a string");
8807 //else { // bjornw: remove brackets to keep scope
8808 Nan::Utf8String address_utf8 (info [0].As<String>());
8809 address = *address_utf8;
8810 //} //bjornw end
8811 zhttp_server_options_set_backend_address (zhttp_server_options->self, (const char *)address);
8812 }
8813
8814 NAN_METHOD (ZhttpServerOptions::_test) {
8815 if (info [0]->IsUndefined ())
8816 return Nan::ThrowTypeError ("method requires a `verbose`");
8817
8818 //bool verbose; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
8819 bool verbose;
8820
8821
8822 if (info [0]->IsBoolean ())
8823 {
8824 verbose = Nan::To<bool>(info [0]).FromJust ();
8825 }
8826 else
8827 return Nan::ThrowTypeError ("`verbose` must be a Boolean");
8828 zhttp_server_options_test ((bool) verbose);
8829 }
8830
8831 Nan::Persistent <Function> &ZhttpServerOptions::constructor () {
8832 static Nan::Persistent <Function> my_constructor;
8833 return my_constructor;
8834 }
8835
8836
8837 NAN_MODULE_INIT (ZhttpRequest::Init) {
8838 Nan::HandleScope scope;
8839
8840 // Prepare constructor template
8841 Local <FunctionTemplate> tpl = Nan::New <FunctionTemplate> (New);
8842 tpl->SetClassName (Nan::New ("ZhttpRequest").ToLocalChecked ());
8843 tpl->InstanceTemplate ()->SetInternalFieldCount (1);
8844
8845 // Prototypes
8846 Nan::SetPrototypeMethod (tpl, "destroy", destroy);
8847 Nan::SetPrototypeMethod (tpl, "defined", defined);
8848 Nan::SetPrototypeMethod (tpl, "method", _method);
8849 Nan::SetPrototypeMethod (tpl, "setMethod", _set_method);
8850 Nan::SetPrototypeMethod (tpl, "url", _url);
8851 Nan::SetPrototypeMethod (tpl, "setUrl", _set_url);
8852 Nan::SetPrototypeMethod (tpl, "contentType", _content_type);
8853 Nan::SetPrototypeMethod (tpl, "setContentType", _set_content_type);
8854 Nan::SetPrototypeMethod (tpl, "contentLength", _content_length);
8855 Nan::SetPrototypeMethod (tpl, "headers", _headers);
8856 Nan::SetPrototypeMethod (tpl, "content", _content);
8857 Nan::SetPrototypeMethod (tpl, "getContent", _get_content);
8858 Nan::SetPrototypeMethod (tpl, "setContent", _set_content);
8859 Nan::SetPrototypeMethod (tpl, "setContentConst", _set_content_const);
8860 Nan::SetPrototypeMethod (tpl, "resetContent", _reset_content);
8861 Nan::SetPrototypeMethod (tpl, "match", _match);
8862 Nan::SetPrototypeMethod (tpl, "test", _test);
8863
8864 constructor ().Reset (Nan::GetFunction (tpl).ToLocalChecked ());
8865 Nan::Set (target, Nan::New ("ZhttpRequest").ToLocalChecked (),
8866 Nan::GetFunction (tpl).ToLocalChecked ());
8867 }
8868
8869 ZhttpRequest::ZhttpRequest (void) {
8870 self = zhttp_request_new ();
8871 }
8872
8873 ZhttpRequest::ZhttpRequest (zhttp_request_t *self_) {
8874 self = self_;
8875 }
8876
8877 ZhttpRequest::~ZhttpRequest () {
8878 }
8879
8880 NAN_METHOD (ZhttpRequest::New) {
8881 assert (info.IsConstructCall ());
8882 ZhttpRequest *zhttp_request = new ZhttpRequest ();
8883 if (zhttp_request) {
8884 zhttp_request->Wrap (info.This ());
8885 info.GetReturnValue ().Set (info.This ());
8886 }
8887 }
8888
8889 NAN_METHOD (ZhttpRequest::destroy) {
8890 ZhttpRequest *zhttp_request = Nan::ObjectWrap::Unwrap <ZhttpRequest> (info.Holder ());
8891 zhttp_request_destroy (&zhttp_request->self);
8892 }
8893
8894
8895 NAN_METHOD (ZhttpRequest::defined) {
8896 ZhttpRequest *zhttp_request = Nan::ObjectWrap::Unwrap <ZhttpRequest> (info.Holder ());
8897 info.GetReturnValue ().Set (Nan::New (zhttp_request->self != NULL));
8898 }
8899
8900 NAN_METHOD (ZhttpRequest::_method) {
8901 ZhttpRequest *zhttp_request = Nan::ObjectWrap::Unwrap <ZhttpRequest> (info.Holder ());
8902 char *result = (char *) zhttp_request_method (zhttp_request->self);
8903 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
8904 }
8905
8906 NAN_METHOD (ZhttpRequest::_set_method) {
8907 ZhttpRequest *zhttp_request = Nan::ObjectWrap::Unwrap <ZhttpRequest> (info.Holder ());
8908 char *method;
8909 if (info [0]->IsUndefined ())
8910 return Nan::ThrowTypeError ("method requires a `method`");
8911 else
8912 if (!info [0]->IsString ())
8913 return Nan::ThrowTypeError ("`method` must be a string");
8914 //else { // bjornw: remove brackets to keep scope
8915 Nan::Utf8String method_utf8 (info [0].As<String>());
8916 method = *method_utf8;
8917 //} //bjornw end
8918 zhttp_request_set_method (zhttp_request->self, (const char *)method);
8919 }
8920
8921 NAN_METHOD (ZhttpRequest::_url) {
8922 ZhttpRequest *zhttp_request = Nan::ObjectWrap::Unwrap <ZhttpRequest> (info.Holder ());
8923 char *result = (char *) zhttp_request_url (zhttp_request->self);
8924 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
8925 }
8926
8927 NAN_METHOD (ZhttpRequest::_set_url) {
8928 ZhttpRequest *zhttp_request = Nan::ObjectWrap::Unwrap <ZhttpRequest> (info.Holder ());
8929 char *url;
8930 if (info [0]->IsUndefined ())
8931 return Nan::ThrowTypeError ("method requires a `url`");
8932 else
8933 if (!info [0]->IsString ())
8934 return Nan::ThrowTypeError ("`url` must be a string");
8935 //else { // bjornw: remove brackets to keep scope
8936 Nan::Utf8String url_utf8 (info [0].As<String>());
8937 url = *url_utf8;
8938 //} //bjornw end
8939 zhttp_request_set_url (zhttp_request->self, (const char *)url);
8940 }
8941
8942 NAN_METHOD (ZhttpRequest::_content_type) {
8943 ZhttpRequest *zhttp_request = Nan::ObjectWrap::Unwrap <ZhttpRequest> (info.Holder ());
8944 char *result = (char *) zhttp_request_content_type (zhttp_request->self);
8945 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
8946 }
8947
8948 NAN_METHOD (ZhttpRequest::_set_content_type) {
8949 ZhttpRequest *zhttp_request = Nan::ObjectWrap::Unwrap <ZhttpRequest> (info.Holder ());
8950 char *content_type;
8951 if (info [0]->IsUndefined ())
8952 return Nan::ThrowTypeError ("method requires a `content type`");
8953 else
8954 if (!info [0]->IsString ())
8955 return Nan::ThrowTypeError ("`content type` must be a string");
8956 //else { // bjornw: remove brackets to keep scope
8957 Nan::Utf8String content_type_utf8 (info [0].As<String>());
8958 content_type = *content_type_utf8;
8959 //} //bjornw end
8960 zhttp_request_set_content_type (zhttp_request->self, (const char *)content_type);
8961 }
8962
8963 NAN_METHOD (ZhttpRequest::_content_length) {
8964 ZhttpRequest *zhttp_request = Nan::ObjectWrap::Unwrap <ZhttpRequest> (info.Holder ());
8965 size_t result = zhttp_request_content_length (zhttp_request->self);
8966 info.GetReturnValue ().Set (Nan::New<Number>(result));
8967 }
8968
8969 NAN_METHOD (ZhttpRequest::_headers) {
8970 ZhttpRequest *zhttp_request = Nan::ObjectWrap::Unwrap <ZhttpRequest> (info.Holder ());
8971 zhash_t *result = zhttp_request_headers (zhttp_request->self);
8972 Zhash *zhash_result = new Zhash (result);
8973 if (zhash_result) {
8974 // Don't yet know how to return a new object
8975 // zhash->Wrap (info.This ());
8976 // info.GetReturnValue ().Set (info.This ());
8977 info.GetReturnValue ().Set (Nan::New<Boolean>(true));
8978 }
8979 }
8980
8981 NAN_METHOD (ZhttpRequest::_content) {
8982 ZhttpRequest *zhttp_request = Nan::ObjectWrap::Unwrap <ZhttpRequest> (info.Holder ());
8983 char *result = (char *) zhttp_request_content (zhttp_request->self);
8984 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
8985 }
8986
8987 NAN_METHOD (ZhttpRequest::_get_content) {
8988 ZhttpRequest *zhttp_request = Nan::ObjectWrap::Unwrap <ZhttpRequest> (info.Holder ());
8989 char *result = (char *) zhttp_request_get_content (zhttp_request->self);
8990 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
8991 }
8992
8993 NAN_METHOD (ZhttpRequest::_set_content) {
8994 ZhttpRequest *zhttp_request = Nan::ObjectWrap::Unwrap <ZhttpRequest> (info.Holder ());
8995 char *content;
8996 if (info [0]->IsUndefined ())
8997 return Nan::ThrowTypeError ("method requires a `content`");
8998 else
8999 if (!info [0]->IsString ())
9000 return Nan::ThrowTypeError ("`content` must be a string");
9001 //else { // bjornw: remove brackets to keep scope
9002 Nan::Utf8String content_utf8 (info [0].As<String>());
9003 content = *content_utf8;
9004 //} //bjornw end
9005 zhttp_request_set_content (zhttp_request->self, (char **)&content);
9006 }
9007
9008 NAN_METHOD (ZhttpRequest::_set_content_const) {
9009 ZhttpRequest *zhttp_request = Nan::ObjectWrap::Unwrap <ZhttpRequest> (info.Holder ());
9010 char *content;
9011 if (info [0]->IsUndefined ())
9012 return Nan::ThrowTypeError ("method requires a `content`");
9013 else
9014 if (!info [0]->IsString ())
9015 return Nan::ThrowTypeError ("`content` must be a string");
9016 //else { // bjornw: remove brackets to keep scope
9017 Nan::Utf8String content_utf8 (info [0].As<String>());
9018 content = *content_utf8;
9019 //} //bjornw end
9020 zhttp_request_set_content_const (zhttp_request->self, (const char *)content);
9021 }
9022
9023 NAN_METHOD (ZhttpRequest::_reset_content) {
9024 ZhttpRequest *zhttp_request = Nan::ObjectWrap::Unwrap <ZhttpRequest> (info.Holder ());
9025 zhttp_request_reset_content (zhttp_request->self);
9026 }
9027
9028 NAN_METHOD (ZhttpRequest::_match) {
9029 ZhttpRequest *zhttp_request = Nan::ObjectWrap::Unwrap <ZhttpRequest> (info.Holder ());
9030 char *method;
9031 if (info [0]->IsUndefined ())
9032 return Nan::ThrowTypeError ("method requires a `method`");
9033 else
9034 if (!info [0]->IsString ())
9035 return Nan::ThrowTypeError ("`method` must be a string");
9036 //else { // bjornw: remove brackets to keep scope
9037 Nan::Utf8String method_utf8 (info [0].As<String>());
9038 method = *method_utf8;
9039 //} //bjornw end
9040 char *path;
9041 if (info [1]->IsUndefined ())
9042 return Nan::ThrowTypeError ("method requires a `path`");
9043 else
9044 if (!info [1]->IsString ())
9045 return Nan::ThrowTypeError ("`path` must be a string");
9046 //else { // bjornw: remove brackets to keep scope
9047 Nan::Utf8String path_utf8 (info [1].As<String>());
9048 path = *path_utf8;
9049 //} //bjornw end
9050 bool result = zhttp_request_match (zhttp_request->self, (const char *)method, (const char *)path);
9051 info.GetReturnValue ().Set (Nan::New<Boolean>(result));
9052 }
9053
9054 NAN_METHOD (ZhttpRequest::_test) {
9055 if (info [0]->IsUndefined ())
9056 return Nan::ThrowTypeError ("method requires a `verbose`");
9057
9058 //bool verbose; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
9059 bool verbose;
9060
9061
9062 if (info [0]->IsBoolean ())
9063 {
9064 verbose = Nan::To<bool>(info [0]).FromJust ();
9065 }
9066 else
9067 return Nan::ThrowTypeError ("`verbose` must be a Boolean");
9068 zhttp_request_test ((bool) verbose);
9069 }
9070
9071 Nan::Persistent <Function> &ZhttpRequest::constructor () {
9072 static Nan::Persistent <Function> my_constructor;
9073 return my_constructor;
9074 }
9075
9076
9077 NAN_MODULE_INIT (ZhttpResponse::Init) {
9078 Nan::HandleScope scope;
9079
9080 // Prepare constructor template
9081 Local <FunctionTemplate> tpl = Nan::New <FunctionTemplate> (New);
9082 tpl->SetClassName (Nan::New ("ZhttpResponse").ToLocalChecked ());
9083 tpl->InstanceTemplate ()->SetInternalFieldCount (1);
9084
9085 // Prototypes
9086 Nan::SetPrototypeMethod (tpl, "destroy", destroy);
9087 Nan::SetPrototypeMethod (tpl, "defined", defined);
9088 Nan::SetPrototypeMethod (tpl, "contentType", _content_type);
9089 Nan::SetPrototypeMethod (tpl, "setContentType", _set_content_type);
9090 Nan::SetPrototypeMethod (tpl, "statusCode", _status_code);
9091 Nan::SetPrototypeMethod (tpl, "setStatusCode", _set_status_code);
9092 Nan::SetPrototypeMethod (tpl, "headers", _headers);
9093 Nan::SetPrototypeMethod (tpl, "contentLength", _content_length);
9094 Nan::SetPrototypeMethod (tpl, "content", _content);
9095 Nan::SetPrototypeMethod (tpl, "getContent", _get_content);
9096 Nan::SetPrototypeMethod (tpl, "setContent", _set_content);
9097 Nan::SetPrototypeMethod (tpl, "setContentConst", _set_content_const);
9098 Nan::SetPrototypeMethod (tpl, "resetContent", _reset_content);
9099 Nan::SetPrototypeMethod (tpl, "test", _test);
9100
9101 constructor ().Reset (Nan::GetFunction (tpl).ToLocalChecked ());
9102 Nan::Set (target, Nan::New ("ZhttpResponse").ToLocalChecked (),
9103 Nan::GetFunction (tpl).ToLocalChecked ());
9104 }
9105
9106 ZhttpResponse::ZhttpResponse (void) {
9107 self = zhttp_response_new ();
9108 }
9109
9110 ZhttpResponse::ZhttpResponse (zhttp_response_t *self_) {
9111 self = self_;
9112 }
9113
9114 ZhttpResponse::~ZhttpResponse () {
9115 }
9116
9117 NAN_METHOD (ZhttpResponse::New) {
9118 assert (info.IsConstructCall ());
9119 ZhttpResponse *zhttp_response = new ZhttpResponse ();
9120 if (zhttp_response) {
9121 zhttp_response->Wrap (info.This ());
9122 info.GetReturnValue ().Set (info.This ());
9123 }
9124 }
9125
9126 NAN_METHOD (ZhttpResponse::destroy) {
9127 ZhttpResponse *zhttp_response = Nan::ObjectWrap::Unwrap <ZhttpResponse> (info.Holder ());
9128 zhttp_response_destroy (&zhttp_response->self);
9129 }
9130
9131
9132 NAN_METHOD (ZhttpResponse::defined) {
9133 ZhttpResponse *zhttp_response = Nan::ObjectWrap::Unwrap <ZhttpResponse> (info.Holder ());
9134 info.GetReturnValue ().Set (Nan::New (zhttp_response->self != NULL));
9135 }
9136
9137 NAN_METHOD (ZhttpResponse::_content_type) {
9138 ZhttpResponse *zhttp_response = Nan::ObjectWrap::Unwrap <ZhttpResponse> (info.Holder ());
9139 char *result = (char *) zhttp_response_content_type (zhttp_response->self);
9140 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
9141 }
9142
9143 NAN_METHOD (ZhttpResponse::_set_content_type) {
9144 ZhttpResponse *zhttp_response = Nan::ObjectWrap::Unwrap <ZhttpResponse> (info.Holder ());
9145 char *value;
9146 if (info [0]->IsUndefined ())
9147 return Nan::ThrowTypeError ("method requires a `value`");
9148 else
9149 if (!info [0]->IsString ())
9150 return Nan::ThrowTypeError ("`value` must be a string");
9151 //else { // bjornw: remove brackets to keep scope
9152 Nan::Utf8String value_utf8 (info [0].As<String>());
9153 value = *value_utf8;
9154 //} //bjornw end
9155 zhttp_response_set_content_type (zhttp_response->self, (const char *)value);
9156 }
9157
9158 NAN_METHOD (ZhttpResponse::_status_code) {
9159 ZhttpResponse *zhttp_response = Nan::ObjectWrap::Unwrap <ZhttpResponse> (info.Holder ());
9160 uint32_t result = zhttp_response_status_code (zhttp_response->self);
9161 info.GetReturnValue ().Set (Nan::New<Number>(result));
9162 }
9163
9164 NAN_METHOD (ZhttpResponse::_set_status_code) {
9165 ZhttpResponse *zhttp_response = Nan::ObjectWrap::Unwrap <ZhttpResponse> (info.Holder ());
9166 if (info [0]->IsUndefined ())
9167 return Nan::ThrowTypeError ("method requires a `status_code`");
9168
9169 //uint32_t status_code; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
9170 uint32_t status_code;
9171
9172
9173 if (info [0]->IsNumber ())
9174 {
9175 status_code = Nan::To<uint32_t>(info [0]).FromJust ();
9176 }
9177 else
9178 return Nan::ThrowTypeError ("`status_code` must be a number");
9179 zhttp_response_set_status_code (zhttp_response->self, (uint32_t) status_code);
9180 }
9181
9182 NAN_METHOD (ZhttpResponse::_headers) {
9183 ZhttpResponse *zhttp_response = Nan::ObjectWrap::Unwrap <ZhttpResponse> (info.Holder ());
9184 zhash_t *result = zhttp_response_headers (zhttp_response->self);
9185 Zhash *zhash_result = new Zhash (result);
9186 if (zhash_result) {
9187 // Don't yet know how to return a new object
9188 // zhash->Wrap (info.This ());
9189 // info.GetReturnValue ().Set (info.This ());
9190 info.GetReturnValue ().Set (Nan::New<Boolean>(true));
9191 }
9192 }
9193
9194 NAN_METHOD (ZhttpResponse::_content_length) {
9195 ZhttpResponse *zhttp_response = Nan::ObjectWrap::Unwrap <ZhttpResponse> (info.Holder ());
9196 size_t result = zhttp_response_content_length (zhttp_response->self);
9197 info.GetReturnValue ().Set (Nan::New<Number>(result));
9198 }
9199
9200 NAN_METHOD (ZhttpResponse::_content) {
9201 ZhttpResponse *zhttp_response = Nan::ObjectWrap::Unwrap <ZhttpResponse> (info.Holder ());
9202 char *result = (char *) zhttp_response_content (zhttp_response->self);
9203 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
9204 }
9205
9206 NAN_METHOD (ZhttpResponse::_get_content) {
9207 ZhttpResponse *zhttp_response = Nan::ObjectWrap::Unwrap <ZhttpResponse> (info.Holder ());
9208 char *result = (char *) zhttp_response_get_content (zhttp_response->self);
9209 info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
9210 }
9211
9212 NAN_METHOD (ZhttpResponse::_set_content) {
9213 ZhttpResponse *zhttp_response = Nan::ObjectWrap::Unwrap <ZhttpResponse> (info.Holder ());
9214 char *content;
9215 if (info [0]->IsUndefined ())
9216 return Nan::ThrowTypeError ("method requires a `content`");
9217 else
9218 if (!info [0]->IsString ())
9219 return Nan::ThrowTypeError ("`content` must be a string");
9220 //else { // bjornw: remove brackets to keep scope
9221 Nan::Utf8String content_utf8 (info [0].As<String>());
9222 content = *content_utf8;
9223 //} //bjornw end
9224 zhttp_response_set_content (zhttp_response->self, (char **)&content);
9225 }
9226
9227 NAN_METHOD (ZhttpResponse::_set_content_const) {
9228 ZhttpResponse *zhttp_response = Nan::ObjectWrap::Unwrap <ZhttpResponse> (info.Holder ());
9229 char *content;
9230 if (info [0]->IsUndefined ())
9231 return Nan::ThrowTypeError ("method requires a `content`");
9232 else
9233 if (!info [0]->IsString ())
9234 return Nan::ThrowTypeError ("`content` must be a string");
9235 //else { // bjornw: remove brackets to keep scope
9236 Nan::Utf8String content_utf8 (info [0].As<String>());
9237 content = *content_utf8;
9238 //} //bjornw end
9239 zhttp_response_set_content_const (zhttp_response->self, (const char *)content);
9240 }
9241
9242 NAN_METHOD (ZhttpResponse::_reset_content) {
9243 ZhttpResponse *zhttp_response = Nan::ObjectWrap::Unwrap <ZhttpResponse> (info.Holder ());
9244 zhttp_response_reset_content (zhttp_response->self);
9245 }
9246
9247 NAN_METHOD (ZhttpResponse::_test) {
9248 if (info [0]->IsUndefined ())
9249 return Nan::ThrowTypeError ("method requires a `verbose`");
9250
9251 //bool verbose; // bjornw typedef - if using c_type, then you get 'int * major' but it needs to be 'int major'. later using the FromJust() returns an int
9252 bool verbose;
9253
9254
9255 if (info [0]->IsBoolean ())
9256 {
9257 verbose = Nan::To<bool>(info [0]).FromJust ();
9258 }
9259 else
9260 return Nan::ThrowTypeError ("`verbose` must be a Boolean");
9261 zhttp_response_test ((bool) verbose);
9262 }
9263
9264 Nan::Persistent <Function> &ZhttpResponse::constructor () {
81119265 static Nan::Persistent <Function> my_constructor;
81129266 return my_constructor;
81139267 }
81429296 Ztimerset::Init (target);
81439297 Ztrie::Init (target);
81449298 Zuuid::Init (target);
9299 ZhttpClient::Init (target);
9300 ZhttpServer::Init (target);
9301 ZhttpServerOptions::Init (target);
9302 ZhttpRequest::Init (target);
9303 ZhttpResponse::Init (target);
81459304 }
81469305
81479306 NODE_MODULE (czmq, czmq_initialize)
4646 static NAN_METHOD (_param_first);
4747 static NAN_METHOD (_param_next);
4848 static NAN_METHOD (_param_name);
49 static NAN_METHOD (_param_lookup);
50 static NAN_METHOD (_param_lookupx);
51 static NAN_METHOD (_has_help);
52 static NAN_METHOD (_param_empty);
49 static NAN_METHOD (_get);
50 static NAN_METHOD (_getx);
51 static NAN_METHOD (_has);
52 static NAN_METHOD (_hasx);
5353 static NAN_METHOD (_print);
5454 static NAN_METHOD (_test);
5555 };
164164 static NAN_METHOD (_strdup);
165165 static NAN_METHOD (_streq);
166166 static NAN_METHOD (_pack);
167 static NAN_METHOD (_packx);
167168 static NAN_METHOD (_unpack);
168169 static NAN_METHOD (_digest);
169170 static NAN_METHOD (_print);
200201 static NAN_METHOD (New);
201202 static NAN_METHOD (destroy);
202203 static NAN_METHOD (defined);
204 static NAN_METHOD (_dup);
203205 static NAN_METHOD (_name);
204206 static NAN_METHOD (_value);
205207 static NAN_METHOD (_put);
485487 static NAN_METHOD (_purge);
486488 static NAN_METHOD (_sort);
487489 static NAN_METHOD (_dup);
490 static NAN_METHOD (_pack);
488491 static NAN_METHOD (_test);
489492 };
490493
597600 static NAN_METHOD (_pid);
598601 static NAN_METHOD (_running);
599602 static NAN_METHOD (_wait);
603 static NAN_METHOD (_shutdown);
600604 static NAN_METHOD (_kill);
601605 static NAN_METHOD (_set_verbose);
602606 static NAN_METHOD (_test);
633637 static NAN_METHOD (_flush);
634638 static NAN_METHOD (_join);
635639 static NAN_METHOD (_leave);
640 static NAN_METHOD (_has_in);
641 static NAN_METHOD (_router_notify);
642 static NAN_METHOD (_set_router_notify);
643 static NAN_METHOD (_multicast_loop);
644 static NAN_METHOD (_set_multicast_loop);
645 static NAN_METHOD (_metadata);
646 static NAN_METHOD (_set_metadata);
647 static NAN_METHOD (_loopback_fastpath);
648 static NAN_METHOD (_set_loopback_fastpath);
649 static NAN_METHOD (_zap_enforce_domain);
650 static NAN_METHOD (_set_zap_enforce_domain);
651 static NAN_METHOD (_gssapi_principal_nametype);
652 static NAN_METHOD (_set_gssapi_principal_nametype);
653 static NAN_METHOD (_gssapi_service_principal_nametype);
654 static NAN_METHOD (_set_gssapi_service_principal_nametype);
655 static NAN_METHOD (_bindtodevice);
656 static NAN_METHOD (_set_bindtodevice);
636657 static NAN_METHOD (_heartbeat_ivl);
637658 static NAN_METHOD (_set_heartbeat_ivl);
638659 static NAN_METHOD (_heartbeat_ttl);
824845 static NAN_METHOD (_file_mode_private);
825846 static NAN_METHOD (_file_mode_default);
826847 static NAN_METHOD (_version);
848 static NAN_METHOD (_sprintf_hint);
827849 static NAN_METHOD (_sprintf);
828850 static NAN_METHOD (_socket_error);
829851 static NAN_METHOD (_hostname);
833855 static NAN_METHOD (_set_io_threads);
834856 static NAN_METHOD (_set_thread_sched_policy);
835857 static NAN_METHOD (_set_thread_priority);
858 static NAN_METHOD (_set_thread_name_prefix);
859 static NAN_METHOD (_thread_name_prefix);
860 static NAN_METHOD (_thread_affinity_cpu_add);
861 static NAN_METHOD (_thread_affinity_cpu_remove);
836862 static NAN_METHOD (_set_max_sockets);
837863 static NAN_METHOD (_socket_limit);
838864 static NAN_METHOD (_set_max_msgsz);
856882 static NAN_METHOD (_ipv6_mcast_address);
857883 static NAN_METHOD (_set_auto_use_fd);
858884 static NAN_METHOD (_auto_use_fd);
885 static NAN_METHOD (_zprintf);
886 static NAN_METHOD (_zprintf_error);
887 static NAN_METHOD (_zplprintf);
888 static NAN_METHOD (_zplprintf_error);
859889 static NAN_METHOD (_set_logident);
860890 static NAN_METHOD (_set_logsender);
861891 static NAN_METHOD (_set_logsystem);
936966 static NAN_METHOD (_test);
937967 };
938968
969 class ZhttpClient: public Nan::ObjectWrap {
970 public:
971 static NAN_MODULE_INIT (Init);
972 explicit ZhttpClient (bool verbose);
973 explicit ZhttpClient (zhttp_client_t *self);
974 zhttp_client_t *self;
975 private:
976 ~ZhttpClient ();
977 static Nan::Persistent <Function> &constructor ();
978
979 static NAN_METHOD (New);
980 static NAN_METHOD (destroy);
981 static NAN_METHOD (defined);
982 static NAN_METHOD (_test);
983 };
984
985 class ZhttpServer: public Nan::ObjectWrap {
986 public:
987 static NAN_MODULE_INIT (Init);
988 explicit ZhttpServer (zhttp_server_options_t *options);
989 explicit ZhttpServer (zhttp_server_t *self);
990 zhttp_server_t *self;
991 private:
992 ~ZhttpServer ();
993 static Nan::Persistent <Function> &constructor ();
994
995 static NAN_METHOD (New);
996 static NAN_METHOD (destroy);
997 static NAN_METHOD (defined);
998 static NAN_METHOD (_port);
999 static NAN_METHOD (_test);
1000 };
1001
1002 class ZhttpServerOptions: public Nan::ObjectWrap {
1003 public:
1004 static NAN_MODULE_INIT (Init);
1005 explicit ZhttpServerOptions (void);
1006 explicit ZhttpServerOptions (zhttp_server_options_t *self);
1007 zhttp_server_options_t *self;
1008 private:
1009 ~ZhttpServerOptions ();
1010 static Nan::Persistent <Function> &constructor ();
1011
1012 static NAN_METHOD (New);
1013 static NAN_METHOD (destroy);
1014 static NAN_METHOD (defined);
1015 static NAN_METHOD (_port);
1016 static NAN_METHOD (_set_port);
1017 static NAN_METHOD (_backend_address);
1018 static NAN_METHOD (_set_backend_address);
1019 static NAN_METHOD (_test);
1020 };
1021
1022 class ZhttpRequest: public Nan::ObjectWrap {
1023 public:
1024 static NAN_MODULE_INIT (Init);
1025 explicit ZhttpRequest (void);
1026 explicit ZhttpRequest (zhttp_request_t *self);
1027 zhttp_request_t *self;
1028 private:
1029 ~ZhttpRequest ();
1030 static Nan::Persistent <Function> &constructor ();
1031
1032 static NAN_METHOD (New);
1033 static NAN_METHOD (destroy);
1034 static NAN_METHOD (defined);
1035 static NAN_METHOD (_method);
1036 static NAN_METHOD (_set_method);
1037 static NAN_METHOD (_url);
1038 static NAN_METHOD (_set_url);
1039 static NAN_METHOD (_content_type);
1040 static NAN_METHOD (_set_content_type);
1041 static NAN_METHOD (_content_length);
1042 static NAN_METHOD (_headers);
1043 static NAN_METHOD (_content);
1044 static NAN_METHOD (_get_content);
1045 static NAN_METHOD (_set_content);
1046 static NAN_METHOD (_set_content_const);
1047 static NAN_METHOD (_reset_content);
1048 static NAN_METHOD (_match);
1049 static NAN_METHOD (_test);
1050 };
1051
1052 class ZhttpResponse: public Nan::ObjectWrap {
1053 public:
1054 static NAN_MODULE_INIT (Init);
1055 explicit ZhttpResponse (void);
1056 explicit ZhttpResponse (zhttp_response_t *self);
1057 zhttp_response_t *self;
1058 private:
1059 ~ZhttpResponse ();
1060 static Nan::Persistent <Function> &constructor ();
1061
1062 static NAN_METHOD (New);
1063 static NAN_METHOD (destroy);
1064 static NAN_METHOD (defined);
1065 static NAN_METHOD (_content_type);
1066 static NAN_METHOD (_set_content_type);
1067 static NAN_METHOD (_status_code);
1068 static NAN_METHOD (_set_status_code);
1069 static NAN_METHOD (_headers);
1070 static NAN_METHOD (_content_length);
1071 static NAN_METHOD (_content);
1072 static NAN_METHOD (_get_content);
1073 static NAN_METHOD (_set_content);
1074 static NAN_METHOD (_set_content_const);
1075 static NAN_METHOD (_reset_content);
1076 static NAN_METHOD (_test);
1077 };
1078
9391079 #endif
3636
3737 BUILD_ROOT=`pwd`
3838 cd ../../..
39 # Note: here we go to parent directory that contains current project,
40 # so the checkout is nearby, same as expected for usual developer work
3941
4042 # Check dependent projects
4143 if [ ! -d libzmq ]; then
4244 echo "I: cloning https://github.com/zeromq/libzmq.git into `pwd`/libzmq..."
43 git clone $QUIET https://github.com/zeromq/libzmq.git
45 git clone $QUIET https://github.com/zeromq/libzmq.git || exit
4446 fi
4547 if [ ! -f libzmq/builds/gyp/project.gyp ]; then
46 echo "E: `pwd`/libzmq out of date (builds/gyp/project.gyp missing)"
47 exit
48 echo "E: `pwd`/libzmq out of date (builds/gyp/project.gyp missing)" >&2
49 exit 1
4850 fi
4951
5052
177177 class zuuid_t(Structure):
178178 pass # Empty - only for type checking
179179 zuuid_p = POINTER(zuuid_t)
180
181 class zhttp_client_t(Structure):
182 pass # Empty - only for type checking
183 zhttp_client_p = POINTER(zhttp_client_t)
184
185 class zhttp_server_options_t(Structure):
186 pass # Empty - only for type checking
187 zhttp_server_options_p = POINTER(zhttp_server_options_t)
188
189 class zhttp_server_t(Structure):
190 pass # Empty - only for type checking
191 zhttp_server_p = POINTER(zhttp_server_t)
192
193 class zhttp_request_t(Structure):
194 pass # Empty - only for type checking
195 zhttp_request_p = POINTER(zhttp_request_t)
196
197 class zhttp_response_t(Structure):
198 pass # Empty - only for type checking
199 zhttp_response_p = POINTER(zhttp_response_t)
180200
181201 def return_py_file(c_file):
182202 if not sys.version_info > (3,):
375395 lib.zargs_param_next.argtypes = [zargs_p]
376396 lib.zargs_param_name.restype = c_char_p
377397 lib.zargs_param_name.argtypes = [zargs_p]
378 lib.zargs_param_lookup.restype = c_char_p
379 lib.zargs_param_lookup.argtypes = [zargs_p, c_char_p]
380 lib.zargs_param_lookupx.restype = c_char_p
381 lib.zargs_param_lookupx.argtypes = [zargs_p, c_char_p]
382 lib.zargs_has_help.restype = c_bool
383 lib.zargs_has_help.argtypes = [zargs_p]
384 lib.zargs_param_empty.restype = c_bool
385 lib.zargs_param_empty.argtypes = [c_char_p]
398 lib.zargs_get.restype = c_char_p
399 lib.zargs_get.argtypes = [zargs_p, c_char_p]
400 lib.zargs_getx.restype = c_char_p
401 lib.zargs_getx.argtypes = [zargs_p, c_char_p]
402 lib.zargs_has.restype = c_bool
403 lib.zargs_has.argtypes = [zargs_p, c_char_p]
404 lib.zargs_hasx.restype = c_bool
405 lib.zargs_hasx.argtypes = [zargs_p, c_char_p]
386406 lib.zargs_print.restype = None
387407 lib.zargs_print.argtypes = [zargs_p]
388408 lib.zargs_test.restype = None
393413 Platform independent command line argument parsing helpers
394414
395415 There are two kind of elements provided by this class
396 foo --named-parameter --parameter with_value positional arguments -a gain-parameter
397 zargs keeps poision only for arguments, parameters are to be accessed like hash.
416 Named parameters, accessed by param_get and param_has methods
417 * --named-parameter
418 * --parameter with_value
419 * -a val
420 Positional arguments, accessed by zargs_first, zargs_next
398421
399422 It DOES:
400423 * provide easy to use CLASS compatible API for accessing argv
401424 * is platform independent
402425 * provide getopt_long style -- argument, which delimits parameters from arguments
403 * makes parameters positon independent
426 * makes parameters position independent
404427
405428 It does NOT
406429 * change argv
494517
495518 def param_name(self):
496519 """
497 Return current parameter name, or NULL if there are no named
498 parameters.
520 Return current parameter name, or NULL if there are no named parameters.
499521 """
500522 return lib.zargs_param_name(self._as_parameter_)
501523
502 def param_lookup(self, keys):
503 """
504 Return value of named parameter, NULL if no given parameter has
505 been specified, or special value for wich zargs_param_empty ()
506 returns true.
507 """
508 return lib.zargs_param_lookup(self._as_parameter_, keys)
509
510 def param_lookupx(self, keys, *args):
511 """
512 Return value of named parameter(s), NULL if no given parameter has
513 been specified, or special value for wich zargs_param_empty ()
514 returns true.
515 """
516 return lib.zargs_param_lookupx(self._as_parameter_, keys, *args)
517
518 def has_help(self):
519 """
520 Returns true if there are --help -h arguments
521 """
522 return lib.zargs_has_help(self._as_parameter_)
523
524 @staticmethod
525 def param_empty(arg):
526 """
527 Returns true if parameter did not have a value
528 """
529 return lib.zargs_param_empty(arg)
524 def get(self, name):
525 """
526 Return value of named parameter or NULL is it has no value (or was not specified)
527 """
528 return lib.zargs_get(self._as_parameter_, name)
529
530 def getx(self, name, *args):
531 """
532 Return value of one of parameter(s) or NULL is it has no value (or was not specified)
533 """
534 return lib.zargs_getx(self._as_parameter_, name, *args)
535
536 def has(self, name):
537 """
538 Returns true if named parameter was specified on command line
539 """
540 return lib.zargs_has(self._as_parameter_, name)
541
542 def hasx(self, name, *args):
543 """
544 Returns true if named parameter(s) was specified on command line
545 """
546 return lib.zargs_hasx(self._as_parameter_, name, *args)
530547
531548 def print(self):
532549 """
10731090
10741091
10751092 # zchunk
1093 zchunk_destructor_fn = CFUNCTYPE(None, POINTER(c_void_p))
10761094 lib.zchunk_new.restype = zchunk_p
10771095 lib.zchunk_new.argtypes = [c_void_p, c_size_t]
10781096 lib.zchunk_destroy.restype = None
10791097 lib.zchunk_destroy.argtypes = [POINTER(zchunk_p)]
1098 lib.zchunk_frommem.restype = zchunk_p
1099 lib.zchunk_frommem.argtypes = [c_void_p, c_size_t, zchunk_destructor_fn, c_void_p]
10801100 lib.zchunk_resize.restype = None
10811101 lib.zchunk_resize.argtypes = [zchunk_p, c_size_t]
10821102 lib.zchunk_size.restype = c_size_t
11131133 lib.zchunk_streq.argtypes = [zchunk_p, c_char_p]
11141134 lib.zchunk_pack.restype = zframe_p
11151135 lib.zchunk_pack.argtypes = [zchunk_p]
1136 lib.zchunk_packx.restype = zframe_p
1137 lib.zchunk_packx.argtypes = [POINTER(zchunk_p)]
11161138 lib.zchunk_unpack.restype = zchunk_p
11171139 lib.zchunk_unpack.argtypes = [zframe_p]
11181140 lib.zchunk_digest.restype = c_char_p
11761198 "Determine whether the object is valid by converting to boolean" # Python 2
11771199 return self._as_parameter_.__nonzero__()
11781200
1201 @staticmethod
1202 def frommem(data, size, destructor, hint):
1203 """
1204 Create a new chunk from memory. Take ownership of the memory and calling the destructor
1205 on destroy.
1206 """
1207 return Zchunk(lib.zchunk_frommem(data, size, destructor, hint), True)
1208
11791209 def resize(self, size):
11801210 """
11811211 Resizes chunk max_size as requested; chunk_cur size is set to zero
13001330 Transform zchunk into a zframe that can be sent in a message.
13011331 """
13021332 return Zframe(lib.zchunk_pack(self._as_parameter_), True)
1333
1334 @staticmethod
1335 def packx(self_p):
1336 """
1337 Transform zchunk into a zframe that can be sent in a message.
1338 Take ownership of the chunk.
1339 """
1340 return Zframe(lib.zchunk_packx(byref(zchunk_p.from_param(self_p))), True)
13031341
13041342 @staticmethod
13051343 def unpack(frame):
14411479 lib.zconfig_load.argtypes = [c_char_p]
14421480 lib.zconfig_loadf.restype = zconfig_p
14431481 lib.zconfig_loadf.argtypes = [c_char_p]
1482 lib.zconfig_dup.restype = zconfig_p
1483 lib.zconfig_dup.argtypes = [zconfig_p]
14441484 lib.zconfig_name.restype = c_char_p
14451485 lib.zconfig_name.argtypes = [zconfig_p]
14461486 lib.zconfig_value.restype = c_char_p
15631603 """
15641604 return Zconfig(lib.zconfig_loadf(format, *args), True)
15651605
1606 def dup(self):
1607 """
1608 Create copy of zconfig, caller MUST free the value
1609 Create copy of config, as new zconfig object. Returns a fresh zconfig_t
1610 object. If config is null, or memory was exhausted, returns null.
1611 """
1612 return Zconfig(lib.zconfig_dup(self._as_parameter_), True)
1613
15661614 def name(self):
15671615 """
15681616 Return name of config item
22782326 @staticmethod
22792327 def tmp():
22802328 """
2281 Create new temporary file for writing via tmpfile. File is automaticaly
2329 Create new temporary file for writing via tmpfile. File is automatically
22822330 deleted on destroy
22832331 """
22842332 return Zfile(lib.zfile_tmp(), True)
24372485
24382486
24392487 # zframe
2488 zframe_destructor_fn = CFUNCTYPE(None, POINTER(c_void_p))
24402489 lib.zframe_new.restype = zframe_p
24412490 lib.zframe_new.argtypes = [c_void_p, c_size_t]
24422491 lib.zframe_destroy.restype = None
24452494 lib.zframe_new_empty.argtypes = []
24462495 lib.zframe_from.restype = zframe_p
24472496 lib.zframe_from.argtypes = [c_char_p]
2497 lib.zframe_frommem.restype = zframe_p
2498 lib.zframe_frommem.argtypes = [c_void_p, c_size_t, zframe_destructor_fn, c_void_p]
24482499 lib.zframe_recv.restype = zframe_p
24492500 lib.zframe_recv.argtypes = [c_void_p]
24502501 lib.zframe_send.restype = c_int
25522603 Create a frame with a specified string content.
25532604 """
25542605 return Zframe(lib.zframe_from(string), True)
2606
2607 @staticmethod
2608 def frommem(data, size, destructor, hint):
2609 """
2610 Create a new frame from memory. Take ownership of the memory and calling the destructor
2611 on destroy.
2612 """
2613 return Zframe(lib.zframe_frommem(data, size, destructor, hint), True)
25552614
25562615 @staticmethod
25572616 def recv(source):
37523811 lib.zlistx_new.argtypes = []
37533812 lib.zlistx_destroy.restype = None
37543813 lib.zlistx_destroy.argtypes = [POINTER(zlistx_p)]
3814 lib.zlistx_unpack.restype = zlistx_p
3815 lib.zlistx_unpack.argtypes = [zframe_p]
37553816 lib.zlistx_add_start.restype = c_void_p
37563817 lib.zlistx_add_start.argtypes = [zlistx_p, c_void_p]
37573818 lib.zlistx_add_end.restype = c_void_p
38043865 lib.zlistx_set_duplicator.argtypes = [zlistx_p, zlistx_duplicator_fn]
38053866 lib.zlistx_set_comparator.restype = None
38063867 lib.zlistx_set_comparator.argtypes = [zlistx_p, zlistx_comparator_fn]
3868 lib.zlistx_pack.restype = zframe_p
3869 lib.zlistx_pack.argtypes = [zlistx_p]
38073870 lib.zlistx_test.restype = None
38083871 lib.zlistx_test.argtypes = [c_bool]
38093872
38563919 "Determine whether the object is valid by converting to boolean" # Python 2
38573920 return self._as_parameter_.__nonzero__()
38583921
3922 @staticmethod
3923 def unpack(frame):
3924 """
3925 Unpack binary frame into a new list. Packed data must follow format
3926 defined by zlistx_pack. List is set to autofree. An empty frame
3927 unpacks to an empty list.
3928 """
3929 return Zlistx(lib.zlistx_unpack(frame), True)
3930
38593931 def add_start(self, item):
38603932 """
38613933 Add an item to the head of the list. Calls the item duplicator, if any,
40554127 or greater than, item2.
40564128 """
40574129 return lib.zlistx_set_comparator(self._as_parameter_, comparator)
4130
4131 def pack(self):
4132 """
4133 Serialize list to a binary frame that can be sent in a message.
4134 The packed format is compatible with the 'strings' type implemented by zproto:
4135
4136 ; A list of strings
4137 list = list-count *longstr
4138 list-count = number-4
4139
4140 ; Strings are always length + text contents
4141 longstr = number-4 *VCHAR
4142
4143 ; Numbers are unsigned integers in network byte order
4144 number-4 = 4OCTET
4145 """
4146 return Zframe(lib.zlistx_pack(self._as_parameter_), True)
40584147
40594148 @staticmethod
40604149 def test(verbose):
48444933 lib.zproc_running.restype = c_bool
48454934 lib.zproc_running.argtypes = [zproc_p]
48464935 lib.zproc_wait.restype = c_int
4847 lib.zproc_wait.argtypes = [zproc_p, c_bool]
4936 lib.zproc_wait.argtypes = [zproc_p, c_int]
4937 lib.zproc_shutdown.restype = None
4938 lib.zproc_shutdown.argtypes = [zproc_p, c_int]
48484939 lib.zproc_actor.restype = c_void_p
48494940 lib.zproc_actor.argtypes = [zproc_p]
48504941 lib.zproc_kill.restype = None
50005091 """
50015092 return lib.zproc_running(self._as_parameter_)
50025093
5003 def wait(self, hang):
5004 """
5005 wait or poll process status, return return code
5006 """
5007 return lib.zproc_wait(self._as_parameter_, hang)
5094 def wait(self, timeout):
5095 """
5096 The timeout should be zero or greater, or -1 to wait indefinitely.
5097 wait or poll process status, return return code
5098 """
5099 return lib.zproc_wait(self._as_parameter_, timeout)
5100
5101 def shutdown(self, timeout):
5102 """
5103 send SIGTERM signal to the subprocess, wait for grace period and
5104 eventually send SIGKILL
5105 """
5106 return lib.zproc_shutdown(self._as_parameter_, timeout)
50085107
50095108 def actor(self):
50105109 """
5011 return internal actor, usefull for the polling if process died
5110 return internal actor, useful for the polling if process died
50125111 """
50135112 return c_void_p(lib.zproc_actor(self._as_parameter_))
50145113
51195218 lib.zsock_is.argtypes = [c_void_p]
51205219 lib.zsock_resolve.restype = c_void_p
51215220 lib.zsock_resolve.argtypes = [c_void_p]
5221 lib.zsock_has_in.restype = c_bool
5222 lib.zsock_has_in.argtypes = [zsock_p]
5223 lib.zsock_router_notify.restype = c_int
5224 lib.zsock_router_notify.argtypes = [zsock_p]
5225 lib.zsock_set_router_notify.restype = None
5226 lib.zsock_set_router_notify.argtypes = [zsock_p, c_int]
5227 lib.zsock_multicast_loop.restype = c_int
5228 lib.zsock_multicast_loop.argtypes = [zsock_p]
5229 lib.zsock_set_multicast_loop.restype = None
5230 lib.zsock_set_multicast_loop.argtypes = [zsock_p, c_int]
5231 lib.zsock_metadata.restype = POINTER(c_char)
5232 lib.zsock_metadata.argtypes = [zsock_p]
5233 lib.zsock_set_metadata.restype = None
5234 lib.zsock_set_metadata.argtypes = [zsock_p, c_char_p]
5235 lib.zsock_loopback_fastpath.restype = c_int
5236 lib.zsock_loopback_fastpath.argtypes = [zsock_p]
5237 lib.zsock_set_loopback_fastpath.restype = None
5238 lib.zsock_set_loopback_fastpath.argtypes = [zsock_p, c_int]
5239 lib.zsock_zap_enforce_domain.restype = c_int
5240 lib.zsock_zap_enforce_domain.argtypes = [zsock_p]
5241 lib.zsock_set_zap_enforce_domain.restype = None
5242 lib.zsock_set_zap_enforce_domain.argtypes = [zsock_p, c_int]
5243 lib.zsock_gssapi_principal_nametype.restype = c_int
5244 lib.zsock_gssapi_principal_nametype.argtypes = [zsock_p]
5245 lib.zsock_set_gssapi_principal_nametype.restype = None
5246 lib.zsock_set_gssapi_principal_nametype.argtypes = [zsock_p, c_int]
5247 lib.zsock_gssapi_service_principal_nametype.restype = c_int
5248 lib.zsock_gssapi_service_principal_nametype.argtypes = [zsock_p]
5249 lib.zsock_set_gssapi_service_principal_nametype.restype = None
5250 lib.zsock_set_gssapi_service_principal_nametype.argtypes = [zsock_p, c_int]
5251 lib.zsock_bindtodevice.restype = POINTER(c_char)
5252 lib.zsock_bindtodevice.argtypes = [zsock_p]
5253 lib.zsock_set_bindtodevice.restype = None
5254 lib.zsock_set_bindtodevice.argtypes = [zsock_p, c_char_p]
51225255 lib.zsock_heartbeat_ivl.restype = c_int
51235256 lib.zsock_heartbeat_ivl.argtypes = [zsock_p]
51245257 lib.zsock_set_heartbeat_ivl.restype = None
56675800 c = zchunk_t *
56685801 f = zframe_t *
56695802 h = zhashx_t *
5803 l = zlistx_t * (DRAFT)
56705804 U = zuuid_t *
56715805 p = void * (sends the pointer value, only meaningful over inproc)
56725806 m = zmsg_t * (sends all frames in the zmsg)
57045838 f = zframe_t ** (creates zframe)
57055839 U = zuuid_t * (creates a zuuid with the data)
57065840 h = zhashx_t ** (creates zhashx)
5841 l = zlistx_t ** (creates zlistx) (DRAFT)
57075842 p = void ** (stores pointer)
5708 m = zmsg_t ** (creates a zmsg with the remaing frames)
5843 m = zmsg_t ** (creates a zmsg with the remaining frames)
57095844 z = null, asserts empty frame (0 arguments)
57105845 u = uint * (stores unsigned integer, deprecated)
57115846
58565991 return the supplied value. Takes a polymorphic socket reference.
58575992 """
58585993 return c_void_p(lib.zsock_resolve(self))
5994
5995 def has_in(self):
5996 """
5997 Check whether the socket has available message to read.
5998 """
5999 return lib.zsock_has_in(self._as_parameter_)
6000
6001 def router_notify(self):
6002 """
6003 Get socket option `router_notify`.
6004 Available from libzmq 4.3.0.
6005 """
6006 return lib.zsock_router_notify(self._as_parameter_)
6007
6008 def set_router_notify(self, router_notify):
6009 """
6010 Set socket option `router_notify`.
6011 Available from libzmq 4.3.0.
6012 """
6013 return lib.zsock_set_router_notify(self._as_parameter_, router_notify)
6014
6015 def multicast_loop(self):
6016 """
6017 Get socket option `multicast_loop`.
6018 Available from libzmq 4.3.0.
6019 """
6020 return lib.zsock_multicast_loop(self._as_parameter_)
6021
6022 def set_multicast_loop(self, multicast_loop):
6023 """
6024 Set socket option `multicast_loop`.
6025 Available from libzmq 4.3.0.
6026 """
6027 return lib.zsock_set_multicast_loop(self._as_parameter_, multicast_loop)
6028
6029 def metadata(self):
6030 """
6031 Get socket option `metadata`.
6032 Available from libzmq 4.3.0.
6033 """
6034 return return_fresh_string(lib.zsock_metadata(self._as_parameter_))
6035
6036 def set_metadata(self, metadata):
6037 """
6038 Set socket option `metadata`.
6039 Available from libzmq 4.3.0.
6040 """
6041 return lib.zsock_set_metadata(self._as_parameter_, metadata)
6042
6043 def loopback_fastpath(self):
6044 """
6045 Get socket option `loopback_fastpath`.
6046 Available from libzmq 4.3.0.
6047 """
6048 return lib.zsock_loopback_fastpath(self._as_parameter_)
6049
6050 def set_loopback_fastpath(self, loopback_fastpath):
6051 """
6052 Set socket option `loopback_fastpath`.
6053 Available from libzmq 4.3.0.
6054 """
6055 return lib.zsock_set_loopback_fastpath(self._as_parameter_, loopback_fastpath)
6056
6057 def zap_enforce_domain(self):
6058 """
6059 Get socket option `zap_enforce_domain`.
6060 Available from libzmq 4.3.0.
6061 """
6062 return lib.zsock_zap_enforce_domain(self._as_parameter_)
6063
6064 def set_zap_enforce_domain(self, zap_enforce_domain):
6065 """
6066 Set socket option `zap_enforce_domain`.
6067 Available from libzmq 4.3.0.
6068 """
6069 return lib.zsock_set_zap_enforce_domain(self._as_parameter_, zap_enforce_domain)
6070
6071 def gssapi_principal_nametype(self):
6072 """
6073 Get socket option `gssapi_principal_nametype`.
6074 Available from libzmq 4.3.0.
6075 """
6076 return lib.zsock_gssapi_principal_nametype(self._as_parameter_)
6077
6078 def set_gssapi_principal_nametype(self, gssapi_principal_nametype):
6079 """
6080 Set socket option `gssapi_principal_nametype`.
6081 Available from libzmq 4.3.0.
6082 """
6083 return lib.zsock_set_gssapi_principal_nametype(self._as_parameter_, gssapi_principal_nametype)
6084
6085 def gssapi_service_principal_nametype(self):
6086 """
6087 Get socket option `gssapi_service_principal_nametype`.
6088 Available from libzmq 4.3.0.
6089 """
6090 return lib.zsock_gssapi_service_principal_nametype(self._as_parameter_)
6091
6092 def set_gssapi_service_principal_nametype(self, gssapi_service_principal_nametype):
6093 """
6094 Set socket option `gssapi_service_principal_nametype`.
6095 Available from libzmq 4.3.0.
6096 """
6097 return lib.zsock_set_gssapi_service_principal_nametype(self._as_parameter_, gssapi_service_principal_nametype)
6098
6099 def bindtodevice(self):
6100 """
6101 Get socket option `bindtodevice`.
6102 Available from libzmq 4.3.0.
6103 """
6104 return return_fresh_string(lib.zsock_bindtodevice(self._as_parameter_))
6105
6106 def set_bindtodevice(self, bindtodevice):
6107 """
6108 Set socket option `bindtodevice`.
6109 Available from libzmq 4.3.0.
6110 """
6111 return lib.zsock_set_bindtodevice(self._as_parameter_, bindtodevice)
58596112
58606113 def heartbeat_ivl(self):
58616114 """
70517304 lib.zsys_file_mode_default.argtypes = []
70527305 lib.zsys_version.restype = None
70537306 lib.zsys_version.argtypes = [POINTER(c_int), POINTER(c_int), POINTER(c_int)]
7307 lib.zsys_sprintf_hint.restype = c_char_p
7308 lib.zsys_sprintf_hint.argtypes = [c_int, c_char_p]
70547309 lib.zsys_sprintf.restype = c_char_p
70557310 lib.zsys_sprintf.argtypes = [c_char_p]
70567311 lib.zsys_vprintf.restype = c_char_p
70797334 lib.zsys_set_thread_sched_policy.argtypes = [c_int]
70807335 lib.zsys_set_thread_priority.restype = None
70817336 lib.zsys_set_thread_priority.argtypes = [c_int]
7337 lib.zsys_set_thread_name_prefix.restype = None
7338 lib.zsys_set_thread_name_prefix.argtypes = [c_int]
7339 lib.zsys_thread_name_prefix.restype = c_int
7340 lib.zsys_thread_name_prefix.argtypes = []
7341 lib.zsys_thread_affinity_cpu_add.restype = None
7342 lib.zsys_thread_affinity_cpu_add.argtypes = [c_int]
7343 lib.zsys_thread_affinity_cpu_remove.restype = None
7344 lib.zsys_thread_affinity_cpu_remove.argtypes = [c_int]
70827345 lib.zsys_set_max_sockets.restype = None
70837346 lib.zsys_set_max_sockets.argtypes = [c_size_t]
70847347 lib.zsys_socket_limit.restype = c_size_t
71257388 lib.zsys_set_auto_use_fd.argtypes = [c_int]
71267389 lib.zsys_auto_use_fd.restype = c_int
71277390 lib.zsys_auto_use_fd.argtypes = []
7391 lib.zsys_zprintf.restype = POINTER(c_char)
7392 lib.zsys_zprintf.argtypes = [c_char_p, zhash_p]
7393 lib.zsys_zprintf_error.restype = POINTER(c_char)
7394 lib.zsys_zprintf_error.argtypes = [c_char_p, zhash_p]
7395 lib.zsys_zplprintf.restype = POINTER(c_char)
7396 lib.zsys_zplprintf.argtypes = [c_char_p, zconfig_p]
7397 lib.zsys_zplprintf_error.restype = POINTER(c_char)
7398 lib.zsys_zplprintf_error.argtypes = [c_char_p, zconfig_p]
71287399 lib.zsys_set_logident.restype = None
71297400 lib.zsys_set_logident.argtypes = [c_char_p]
71307401 lib.zsys_set_logstream.restype = None
72527523 """
72537524 Set default interrupt handler, so Ctrl-C or SIGTERM will set
72547525 zsys_interrupted. Idempotent; safe to call multiple times.
7255 Can be supressed by ZSYS_SIGHANDLER=false
7526 Can be suppressed by ZSYS_SIGHANDLER=false
72567527 *** This is for CZMQ internal use only and may change arbitrarily ***
72577528 """
72587529 return lib.zsys_catch_interrupts()
73577628 number into provided fields, providing reference isn't null in each case.
73587629 """
73597630 return lib.zsys_version(byref(c_int.from_param(major)), byref(c_int.from_param(minor)), byref(c_int.from_param(patch)))
7631
7632 @staticmethod
7633 def sprintf_hint(hint, format, *args):
7634 """
7635 Format a string using printf formatting, returning a freshly allocated
7636 buffer. If there was insufficient memory, returns NULL. Free the returned
7637 string using zstr_free(). The hinted version allows to optimize by using
7638 a larger starting buffer size (known to/assumed by the developer) and so
7639 avoid reallocations.
7640 """
7641 return lib.zsys_sprintf_hint(hint, format, *args)
73607642
73617643 @staticmethod
73627644 def sprintf(format, *args):
74937775 Note that this method is valid only before any socket is created.
74947776 """
74957777 return lib.zsys_set_thread_priority(priority)
7778
7779 @staticmethod
7780 def set_thread_name_prefix(prefix):
7781 """
7782 Configure the numeric prefix to each thread created for the internal
7783 context's thread pool. This option is only supported on Linux.
7784 If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
7785 provides the default.
7786 Note that this method is valid only before any socket is created.
7787 """
7788 return lib.zsys_set_thread_name_prefix(prefix)
7789
7790 @staticmethod
7791 def thread_name_prefix():
7792 """
7793 Return thread name prefix.
7794 """
7795 return lib.zsys_thread_name_prefix()
7796
7797 @staticmethod
7798 def thread_affinity_cpu_add(cpu):
7799 """
7800 Adds a specific CPU to the affinity list of the ZMQ context thread pool.
7801 This option is only supported on Linux.
7802 Note that this method is valid only before any socket is created.
7803 """
7804 return lib.zsys_thread_affinity_cpu_add(cpu)
7805
7806 @staticmethod
7807 def thread_affinity_cpu_remove(cpu):
7808 """
7809 Removes a specific CPU to the affinity list of the ZMQ context thread pool.
7810 This option is only supported on Linux.
7811 Note that this method is valid only before any socket is created.
7812 """
7813 return lib.zsys_thread_affinity_cpu_remove(cpu)
74967814
74977815 @staticmethod
74987816 def set_max_sockets(max_sockets):
77048022 Return use of automatic pre-allocated FDs for zsock instances.
77058023 """
77068024 return lib.zsys_auto_use_fd()
8025
8026 @staticmethod
8027 def zprintf(format, args):
8028 """
8029 Print formatted string. Format is specified by variable names
8030 in Python-like format style
8031
8032 "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
8033 become
8034 "key=value"
8035
8036 Returns freshly allocated string or NULL in a case of error.
8037 Not enough memory, invalid format specifier, name not in args
8038 """
8039 return return_fresh_string(lib.zsys_zprintf(format, args))
8040
8041 @staticmethod
8042 def zprintf_error(format, args):
8043 """
8044 Return error string for given format/args combination.
8045 """
8046 return return_fresh_string(lib.zsys_zprintf_error(format, args))
8047
8048 @staticmethod
8049 def zplprintf(format, args):
8050 """
8051 Print formatted string. Format is specified by variable names
8052 in Python-like format style
8053
8054 "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
8055 become
8056 "key=value"
8057
8058 Returns freshly allocated string or NULL in a case of error.
8059 Not enough memory, invalid format specifier, name not in args
8060 """
8061 return return_fresh_string(lib.zsys_zplprintf(format, args))
8062
8063 @staticmethod
8064 def zplprintf_error(format, args):
8065 """
8066 Return error string for given format/args combination.
8067 """
8068 return return_fresh_string(lib.zsys_zplprintf_error(format, args))
77078069
77088070 @staticmethod
77098071 def set_logident(value):
82008562 """
82018563 return lib.zuuid_test(verbose)
82028564
8565
8566 # zhttp_client
8567 lib.zhttp_client_new.restype = zhttp_client_p
8568 lib.zhttp_client_new.argtypes = [c_bool]
8569 lib.zhttp_client_destroy.restype = None
8570 lib.zhttp_client_destroy.argtypes = [POINTER(zhttp_client_p)]
8571 lib.zhttp_client_test.restype = None
8572 lib.zhttp_client_test.argtypes = [c_bool]
8573
8574 class ZhttpClient(object):
8575 """
8576 Http client, allowing multiple requests simultaneously and integrate easily with zpoller.
8577 Use zhttp_request class to create and send the request.
8578 Use zhttp_response class to receive the response.
8579 """
8580
8581 allow_destruct = False
8582 def __init__(self, *args):
8583 """
8584 Create a new http client
8585 """
8586 if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
8587 self._as_parameter_ = cast(args[0], zhttp_client_p) # Conversion from raw type to binding
8588 self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
8589 elif len(args) == 2 and type(args[0]) is zhttp_client_p and isinstance(args[1], bool):
8590 self._as_parameter_ = args[0] # Conversion from raw type to binding
8591 self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
8592 else:
8593 assert(len(args) == 1)
8594 self._as_parameter_ = lib.zhttp_client_new(args[0]) # Creation of new raw type
8595 self.allow_destruct = True
8596
8597 def __del__(self):
8598 """
8599 Destroy an http client
8600 """
8601 if self.allow_destruct:
8602 lib.zhttp_client_destroy(byref(self._as_parameter_))
8603
8604 def __eq__(self, other):
8605 if type(other) == type(self):
8606 return other.c_address() == self.c_address()
8607 elif type(other) == c_void_p:
8608 return other.value == self.c_address()
8609
8610 def c_address(self):
8611 """
8612 Return the address of the object pointer in c. Useful for comparison.
8613 """
8614 return addressof(self._as_parameter_.contents)
8615
8616 def __bool__(self):
8617 "Determine whether the object is valid by converting to boolean" # Python 3
8618 return self._as_parameter_.__bool__()
8619
8620 def __nonzero__(self):
8621 "Determine whether the object is valid by converting to boolean" # Python 2
8622 return self._as_parameter_.__nonzero__()
8623
8624 @staticmethod
8625 def test(verbose):
8626 """
8627 Self test of this class.
8628 """
8629 return lib.zhttp_client_test(verbose)
8630
8631
8632 # zhttp_server
8633 lib.zhttp_server_new.restype = zhttp_server_p
8634 lib.zhttp_server_new.argtypes = [zhttp_server_options_p]
8635 lib.zhttp_server_destroy.restype = None
8636 lib.zhttp_server_destroy.argtypes = [POINTER(zhttp_server_p)]
8637 lib.zhttp_server_port.restype = c_int
8638 lib.zhttp_server_port.argtypes = [zhttp_server_p]
8639 lib.zhttp_server_test.restype = None
8640 lib.zhttp_server_test.argtypes = [c_bool]
8641
8642 class ZhttpServer(object):
8643 """
8644 Simple http server.
8645 To start handling requests:
8646 1. Create a dealer socket
8647 2. Connect the socket to the server backend address provided in the options.
8648 3. Create a zhttp_request.
8649 4. Call zhttp_request_recv to accept a new request.
8650 5. Call zhttp_response_send to send a response.
8651
8652 You can connect as many dealers as you want.
8653 The Server is using simple dealer socket to route the requests.
8654
8655 NOTE: when using libmicrohttpd << 0.9.34 the application might experience
8656 high CPU usage due to the lack of MHD_suspend_connection and
8657 MHD_resume_connection APIs. It is recommended to use this class only with
8658 libmicrohttpd at least 0.9.34 in production.
8659 """
8660
8661 allow_destruct = False
8662 def __init__(self, *args):
8663 """
8664 Create a new http server
8665 """
8666 if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
8667 self._as_parameter_ = cast(args[0], zhttp_server_p) # Conversion from raw type to binding
8668 self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
8669 elif len(args) == 2 and type(args[0]) is zhttp_server_p and isinstance(args[1], bool):
8670 self._as_parameter_ = args[0] # Conversion from raw type to binding
8671 self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
8672 else:
8673 assert(len(args) == 1)
8674 self._as_parameter_ = lib.zhttp_server_new(args[0]) # Creation of new raw type
8675 self.allow_destruct = True
8676
8677 def __del__(self):
8678 """
8679 Destroy an http server
8680 """
8681 if self.allow_destruct:
8682 lib.zhttp_server_destroy(byref(self._as_parameter_))
8683
8684 def __eq__(self, other):
8685 if type(other) == type(self):
8686 return other.c_address() == self.c_address()
8687 elif type(other) == c_void_p:
8688 return other.value == self.c_address()
8689
8690 def c_address(self):
8691 """
8692 Return the address of the object pointer in c. Useful for comparison.
8693 """
8694 return addressof(self._as_parameter_.contents)
8695
8696 def __bool__(self):
8697 "Determine whether the object is valid by converting to boolean" # Python 3
8698 return self._as_parameter_.__bool__()
8699
8700 def __nonzero__(self):
8701 "Determine whether the object is valid by converting to boolean" # Python 2
8702 return self._as_parameter_.__nonzero__()
8703
8704 def port(self):
8705 """
8706 Return the port the server is listening on.
8707 """
8708 return lib.zhttp_server_port(self._as_parameter_)
8709
8710 @staticmethod
8711 def test(verbose):
8712 """
8713 Self test of this class.
8714 """
8715 return lib.zhttp_server_test(verbose)
8716
8717
8718 # zhttp_server_options
8719 lib.zhttp_server_options_new.restype = zhttp_server_options_p
8720 lib.zhttp_server_options_new.argtypes = []
8721 lib.zhttp_server_options_destroy.restype = None
8722 lib.zhttp_server_options_destroy.argtypes = [POINTER(zhttp_server_options_p)]
8723 lib.zhttp_server_options_from_config.restype = zhttp_server_options_p
8724 lib.zhttp_server_options_from_config.argtypes = [zconfig_p]
8725 lib.zhttp_server_options_port.restype = c_int
8726 lib.zhttp_server_options_port.argtypes = [zhttp_server_options_p]
8727 lib.zhttp_server_options_set_port.restype = None
8728 lib.zhttp_server_options_set_port.argtypes = [zhttp_server_options_p, c_int]
8729 lib.zhttp_server_options_backend_address.restype = c_char_p
8730 lib.zhttp_server_options_backend_address.argtypes = [zhttp_server_options_p]
8731 lib.zhttp_server_options_set_backend_address.restype = None
8732 lib.zhttp_server_options_set_backend_address.argtypes = [zhttp_server_options_p, c_char_p]
8733 lib.zhttp_server_options_test.restype = None
8734 lib.zhttp_server_options_test.argtypes = [c_bool]
8735
8736 class ZhttpServerOptions(object):
8737 """
8738 zhttp server.
8739 """
8740
8741 allow_destruct = False
8742 def __init__(self, *args):
8743 """
8744 Create a new zhttp_server_options.
8745 """
8746 if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
8747 self._as_parameter_ = cast(args[0], zhttp_server_options_p) # Conversion from raw type to binding
8748 self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
8749 elif len(args) == 2 and type(args[0]) is zhttp_server_options_p and isinstance(args[1], bool):
8750 self._as_parameter_ = args[0] # Conversion from raw type to binding
8751 self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
8752 else:
8753 assert(len(args) == 0)
8754 self._as_parameter_ = lib.zhttp_server_options_new() # Creation of new raw type
8755 self.allow_destruct = True
8756
8757 def __del__(self):
8758 """
8759 Destroy the zhttp_server_options.
8760 """
8761 if self.allow_destruct:
8762 lib.zhttp_server_options_destroy(byref(self._as_parameter_))
8763
8764 def __eq__(self, other):
8765 if type(other) == type(self):
8766 return other.c_address() == self.c_address()
8767 elif type(other) == c_void_p:
8768 return other.value == self.c_address()
8769
8770 def c_address(self):
8771 """
8772 Return the address of the object pointer in c. Useful for comparison.
8773 """
8774 return addressof(self._as_parameter_.contents)
8775
8776 def __bool__(self):
8777 "Determine whether the object is valid by converting to boolean" # Python 3
8778 return self._as_parameter_.__bool__()
8779
8780 def __nonzero__(self):
8781 "Determine whether the object is valid by converting to boolean" # Python 2
8782 return self._as_parameter_.__nonzero__()
8783
8784 @staticmethod
8785 def from_config(config):
8786 """
8787 Create options from config tree.
8788 """
8789 return ZhttpServerOptions(lib.zhttp_server_options_from_config(config), True)
8790
8791 def port(self):
8792 """
8793 Get the server listening port.
8794 """
8795 return lib.zhttp_server_options_port(self._as_parameter_)
8796
8797 def set_port(self, port):
8798 """
8799 Set the server listening port
8800 """
8801 return lib.zhttp_server_options_set_port(self._as_parameter_, port)
8802
8803 def backend_address(self):
8804 """
8805 Get the address sockets should connect to in order to receive requests.
8806 """
8807 return lib.zhttp_server_options_backend_address(self._as_parameter_)
8808
8809 def set_backend_address(self, address):
8810 """
8811 Set the address sockets should connect to in order to receive requests.
8812 """
8813 return lib.zhttp_server_options_set_backend_address(self._as_parameter_, address)
8814
8815 @staticmethod
8816 def test(verbose):
8817 """
8818 Self test of this class.
8819 """
8820 return lib.zhttp_server_options_test(verbose)
8821
8822
8823 # zhttp_request
8824 lib.zhttp_request_new.restype = zhttp_request_p
8825 lib.zhttp_request_new.argtypes = []
8826 lib.zhttp_request_destroy.restype = None
8827 lib.zhttp_request_destroy.argtypes = [POINTER(zhttp_request_p)]
8828 lib.zhttp_request_recv.restype = c_void_p
8829 lib.zhttp_request_recv.argtypes = [zhttp_request_p, zsock_p]
8830 lib.zhttp_request_send.restype = c_int
8831 lib.zhttp_request_send.argtypes = [zhttp_request_p, zhttp_client_p, c_int, c_void_p, c_void_p]
8832 lib.zhttp_request_method.restype = c_char_p
8833 lib.zhttp_request_method.argtypes = [zhttp_request_p]
8834 lib.zhttp_request_set_method.restype = None
8835 lib.zhttp_request_set_method.argtypes = [zhttp_request_p, c_char_p]
8836 lib.zhttp_request_url.restype = c_char_p
8837 lib.zhttp_request_url.argtypes = [zhttp_request_p]
8838 lib.zhttp_request_set_url.restype = None
8839 lib.zhttp_request_set_url.argtypes = [zhttp_request_p, c_char_p]
8840 lib.zhttp_request_content_type.restype = c_char_p
8841 lib.zhttp_request_content_type.argtypes = [zhttp_request_p]
8842 lib.zhttp_request_set_content_type.restype = None
8843 lib.zhttp_request_set_content_type.argtypes = [zhttp_request_p, c_char_p]
8844 lib.zhttp_request_content_length.restype = c_size_t
8845 lib.zhttp_request_content_length.argtypes = [zhttp_request_p]
8846 lib.zhttp_request_headers.restype = zhash_p
8847 lib.zhttp_request_headers.argtypes = [zhttp_request_p]
8848 lib.zhttp_request_content.restype = c_char_p
8849 lib.zhttp_request_content.argtypes = [zhttp_request_p]
8850 lib.zhttp_request_get_content.restype = POINTER(c_char)
8851 lib.zhttp_request_get_content.argtypes = [zhttp_request_p]
8852 lib.zhttp_request_set_content.restype = None
8853 lib.zhttp_request_set_content.argtypes = [zhttp_request_p, POINTER(c_char_p)]
8854 lib.zhttp_request_set_content_const.restype = None
8855 lib.zhttp_request_set_content_const.argtypes = [zhttp_request_p, c_char_p]
8856 lib.zhttp_request_reset_content.restype = None
8857 lib.zhttp_request_reset_content.argtypes = [zhttp_request_p]
8858 lib.zhttp_request_match.restype = c_bool
8859 lib.zhttp_request_match.argtypes = [zhttp_request_p, c_char_p, c_char_p]
8860 lib.zhttp_request_test.restype = None
8861 lib.zhttp_request_test.argtypes = [c_bool]
8862
8863 class ZhttpRequest(object):
8864 """
8865 Http request that can be received from zhttp_server or sent to zhttp_client.
8866 Class can be reused between send & recv calls.
8867 Headers and Content is being destroyed after every send call.
8868 """
8869
8870 allow_destruct = False
8871 def __init__(self, *args):
8872 """
8873 Create a new http request.
8874 """
8875 if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
8876 self._as_parameter_ = cast(args[0], zhttp_request_p) # Conversion from raw type to binding
8877 self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
8878 elif len(args) == 2 and type(args[0]) is zhttp_request_p and isinstance(args[1], bool):
8879 self._as_parameter_ = args[0] # Conversion from raw type to binding
8880 self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
8881 else:
8882 assert(len(args) == 0)
8883 self._as_parameter_ = lib.zhttp_request_new() # Creation of new raw type
8884 self.allow_destruct = True
8885
8886 def __del__(self):
8887 """
8888 Destroy an http request.
8889 """
8890 if self.allow_destruct:
8891 lib.zhttp_request_destroy(byref(self._as_parameter_))
8892
8893 def __eq__(self, other):
8894 if type(other) == type(self):
8895 return other.c_address() == self.c_address()
8896 elif type(other) == c_void_p:
8897 return other.value == self.c_address()
8898
8899 def c_address(self):
8900 """
8901 Return the address of the object pointer in c. Useful for comparison.
8902 """
8903 return addressof(self._as_parameter_.contents)
8904
8905 def __bool__(self):
8906 "Determine whether the object is valid by converting to boolean" # Python 3
8907 return self._as_parameter_.__bool__()
8908
8909 def __nonzero__(self):
8910 "Determine whether the object is valid by converting to boolean" # Python 2
8911 return self._as_parameter_.__nonzero__()
8912
8913 def recv(self, sock):
8914 """
8915 Receive a new request from zhttp_server.
8916 Return the underlying connection if successful, to be used when calling zhttp_response_send.
8917 """
8918 return c_void_p(lib.zhttp_request_recv(self._as_parameter_, sock))
8919
8920 def send(self, client, timeout, arg, arg2):
8921 """
8922 Send a request to zhttp_client.
8923 Url and the request path will be concatenated.
8924 This behavior is useful for url rewrite and reverse proxy.
8925
8926 Send also allow two user provided arguments which will be returned with the response.
8927 The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an arg.
8928 """
8929 return lib.zhttp_request_send(self._as_parameter_, client, timeout, arg, arg2)
8930
8931 def method(self):
8932 """
8933 Get the request method
8934 """
8935 return lib.zhttp_request_method(self._as_parameter_)
8936
8937 def set_method(self, method):
8938 """
8939 Set the request method
8940 """
8941 return lib.zhttp_request_set_method(self._as_parameter_, method)
8942
8943 def url(self):
8944 """
8945 Get the request url.
8946 When receiving a request from http server this is only the path part of the url.
8947 """
8948 return lib.zhttp_request_url(self._as_parameter_)
8949
8950 def set_url(self, url):
8951 """
8952 Set the request url
8953 When sending a request to http client this should be full url.
8954 """
8955 return lib.zhttp_request_set_url(self._as_parameter_, url)
8956
8957 def content_type(self):
8958 """
8959 Get the request content type
8960 """
8961 return lib.zhttp_request_content_type(self._as_parameter_)
8962
8963 def set_content_type(self, content_type):
8964 """
8965 Set the request content type
8966 """
8967 return lib.zhttp_request_set_content_type(self._as_parameter_, content_type)
8968
8969 def content_length(self):
8970 """
8971 Get the content length of the request
8972 """
8973 return lib.zhttp_request_content_length(self._as_parameter_)
8974
8975 def headers(self):
8976 """
8977 Get the headers of the request
8978 """
8979 return Zhash(lib.zhttp_request_headers(self._as_parameter_), False)
8980
8981 def content(self):
8982 """
8983 Get the content of the request.
8984 """
8985 return lib.zhttp_request_content(self._as_parameter_)
8986
8987 def get_content(self):
8988 """
8989 Get the content of the request.
8990 """
8991 return return_fresh_string(lib.zhttp_request_get_content(self._as_parameter_))
8992
8993 def set_content(self, content):
8994 """
8995 Set the content of the request.
8996 Content must by dynamically allocated string.
8997 Takes ownership of the content.
8998 """
8999 return lib.zhttp_request_set_content(self._as_parameter_, byref(c_char_p.from_param(content)))
9000
9001 def set_content_const(self, content):
9002 """
9003 Set the content of the request..
9004 The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
9005 """
9006 return lib.zhttp_request_set_content_const(self._as_parameter_, content)
9007
9008 def reset_content(self):
9009 """
9010 Set the content to NULL
9011 """
9012 return lib.zhttp_request_reset_content(self._as_parameter_)
9013
9014 def match(self, method, path, *args):
9015 """
9016 Match the path of the request.
9017 Support wildcards with '%s' symbol inside the match string.
9018 Matching wildcards until the next '/', '?' or '\0'.
9019 On successful match the variadic arguments will be filled with the matching strings.
9020 On successful match the method is modifying the url field and break it into substrings.
9021 If you need to use the url, do it before matching or take a copy.
9022
9023 User must not free the variadic arguments as they are part of the url.
9024
9025 To use the percent symbol, just double it, e.g "%%something".
9026
9027 Example:
9028 if (zhttp_request_match (request, "POST", "/send/%s/%s", &name, &id))
9029 """
9030 return lib.zhttp_request_match(self._as_parameter_, method, path, *args)
9031
9032 @staticmethod
9033 def test(verbose):
9034 """
9035 Self test of this class.
9036 """
9037 return lib.zhttp_request_test(verbose)
9038
9039
9040 # zhttp_response
9041 lib.zhttp_response_new.restype = zhttp_response_p
9042 lib.zhttp_response_new.argtypes = []
9043 lib.zhttp_response_destroy.restype = None
9044 lib.zhttp_response_destroy.argtypes = [POINTER(zhttp_response_p)]
9045 lib.zhttp_response_send.restype = c_int
9046 lib.zhttp_response_send.argtypes = [zhttp_response_p, zsock_p, POINTER(c_void_p)]
9047 lib.zhttp_response_recv.restype = c_int
9048 lib.zhttp_response_recv.argtypes = [zhttp_response_p, zhttp_client_p, POINTER(c_void_p), POINTER(c_void_p)]
9049 lib.zhttp_response_content_type.restype = c_char_p
9050 lib.zhttp_response_content_type.argtypes = [zhttp_response_p]
9051 lib.zhttp_response_set_content_type.restype = None
9052 lib.zhttp_response_set_content_type.argtypes = [zhttp_response_p, c_char_p]
9053 lib.zhttp_response_status_code.restype = c_int
9054 lib.zhttp_response_status_code.argtypes = [zhttp_response_p]
9055 lib.zhttp_response_set_status_code.restype = None
9056 lib.zhttp_response_set_status_code.argtypes = [zhttp_response_p, c_int]
9057 lib.zhttp_response_headers.restype = zhash_p
9058 lib.zhttp_response_headers.argtypes = [zhttp_response_p]
9059 lib.zhttp_response_content_length.restype = c_size_t
9060 lib.zhttp_response_content_length.argtypes = [zhttp_response_p]
9061 lib.zhttp_response_content.restype = c_char_p
9062 lib.zhttp_response_content.argtypes = [zhttp_response_p]
9063 lib.zhttp_response_get_content.restype = POINTER(c_char)
9064 lib.zhttp_response_get_content.argtypes = [zhttp_response_p]
9065 lib.zhttp_response_set_content.restype = None
9066 lib.zhttp_response_set_content.argtypes = [zhttp_response_p, POINTER(c_char_p)]
9067 lib.zhttp_response_set_content_const.restype = None
9068 lib.zhttp_response_set_content_const.argtypes = [zhttp_response_p, c_char_p]
9069 lib.zhttp_response_reset_content.restype = None
9070 lib.zhttp_response_reset_content.argtypes = [zhttp_response_p]
9071 lib.zhttp_response_test.restype = None
9072 lib.zhttp_response_test.argtypes = [c_bool]
9073
9074 class ZhttpResponse(object):
9075 """
9076 Http response that can be received from zhttp_client or sent to zhttp_server.
9077 Class can be reused between send & recv calls.
9078 Headers and Content is being destroyed after every send call.
9079 """
9080
9081 allow_destruct = False
9082 def __init__(self, *args):
9083 """
9084 Create a new zhttp_response.
9085 """
9086 if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
9087 self._as_parameter_ = cast(args[0], zhttp_response_p) # Conversion from raw type to binding
9088 self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
9089 elif len(args) == 2 and type(args[0]) is zhttp_response_p and isinstance(args[1], bool):
9090 self._as_parameter_ = args[0] # Conversion from raw type to binding
9091 self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
9092 else:
9093 assert(len(args) == 0)
9094 self._as_parameter_ = lib.zhttp_response_new() # Creation of new raw type
9095 self.allow_destruct = True
9096
9097 def __del__(self):
9098 """
9099 Destroy the zhttp_response.
9100 """
9101 if self.allow_destruct:
9102 lib.zhttp_response_destroy(byref(self._as_parameter_))
9103
9104 def __eq__(self, other):
9105 if type(other) == type(self):
9106 return other.c_address() == self.c_address()
9107 elif type(other) == c_void_p:
9108 return other.value == self.c_address()
9109
9110 def c_address(self):
9111 """
9112 Return the address of the object pointer in c. Useful for comparison.
9113 """
9114 return addressof(self._as_parameter_.contents)
9115
9116 def __bool__(self):
9117 "Determine whether the object is valid by converting to boolean" # Python 3
9118 return self._as_parameter_.__bool__()
9119
9120 def __nonzero__(self):
9121 "Determine whether the object is valid by converting to boolean" # Python 2
9122 return self._as_parameter_.__nonzero__()
9123
9124 def send(self, sock, connection):
9125 """
9126 Send a response to a request.
9127 Returns 0 if successful and -1 otherwise.
9128 """
9129 return lib.zhttp_response_send(self._as_parameter_, sock, byref(c_void_p.from_param(connection)))
9130
9131 def recv(self, client, arg, arg2):
9132 """
9133 Receive a response from zhttp_client.
9134 On success return 0, -1 otherwise.
9135
9136 Recv returns the two user arguments which was provided with the request.
9137 The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an argument.
9138 """
9139 return lib.zhttp_response_recv(self._as_parameter_, client, byref(c_void_p.from_param(arg)), byref(c_void_p.from_param(arg2)))
9140
9141 def content_type(self):
9142 """
9143 Get the response content type
9144 """
9145 return lib.zhttp_response_content_type(self._as_parameter_)
9146
9147 def set_content_type(self, value):
9148 """
9149 Set the content type of the response.
9150 """
9151 return lib.zhttp_response_set_content_type(self._as_parameter_, value)
9152
9153 def status_code(self):
9154 """
9155 Get the status code of the response.
9156 """
9157 return lib.zhttp_response_status_code(self._as_parameter_)
9158
9159 def set_status_code(self, status_code):
9160 """
9161 Set the status code of the response.
9162 """
9163 return lib.zhttp_response_set_status_code(self._as_parameter_, status_code)
9164
9165 def headers(self):
9166 """
9167 Get the headers of the response.
9168 """
9169 return Zhash(lib.zhttp_response_headers(self._as_parameter_), False)
9170
9171 def content_length(self):
9172 """
9173 Get the content length of the response
9174 """
9175 return lib.zhttp_response_content_length(self._as_parameter_)
9176
9177 def content(self):
9178 """
9179 Get the content of the response.
9180 """
9181 return lib.zhttp_response_content(self._as_parameter_)
9182
9183 def get_content(self):
9184 """
9185 Get the content of the response.
9186 """
9187 return return_fresh_string(lib.zhttp_response_get_content(self._as_parameter_))
9188
9189 def set_content(self, content):
9190 """
9191 Set the content of the response.
9192 Content must by dynamically allocated string.
9193 Takes ownership of the content.
9194 """
9195 return lib.zhttp_response_set_content(self._as_parameter_, byref(c_char_p.from_param(content)))
9196
9197 def set_content_const(self, content):
9198 """
9199 Set the content of the response.
9200 The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
9201 """
9202 return lib.zhttp_response_set_content_const(self._as_parameter_, content)
9203
9204 def reset_content(self):
9205 """
9206 Set the content to NULL
9207 """
9208 return lib.zhttp_response_reset_content(self._as_parameter_)
9209
9210 @staticmethod
9211 def test(verbose):
9212 """
9213 Self test of this class.
9214 """
9215 return lib.zhttp_response_test(verbose)
9216
82039217 ################################################################################
82049218 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
82059219 # Read the zproject/README.md for information about making permanent changes. #
55
66 setup(
77 name = "czmq",
8 version = "4.1.1",
8 version = "4.2.0",
99 license = "mplv2",
1010 description = """Python bindings of: the high-level c binding for 0mq""",
1111 url = "https://github.com/zeromq/czmq",
4141
4242 if self.verbose:
4343 watch.sock().send(b"s", b"VERBOSE")
44 self.assertEqual(watch.wait(), 0)
44 self.assertEqual(watch.sock().wait(), 0)
4545
4646 # need to create a file in the test directory we're watching
4747 # in order to ensure the directory exists
527527 def test_zloop(self):
528528 def _cancel_timer_event(loop, timer_id, arg):
529529 # We are handling timer 2, and will cancel timer 1
530 cancel_timer_id = POINTER(c_int)(c_int(arg)).contents
531 return Zloop(loop, False).timer_end(cancel_timer_id)
530 self.assertIsInstance(arg, int)
531 return Zloop(loop, False).timer_end(arg)
532532 cancel_timer_event = zloop_timer_fn(_cancel_timer_event)
533533
534534 def _timer_event(loop, timer_id, arg):
558558 loop.set_verbose(self.verbose)
559559
560560 # Create a timer that will be cancelled
561 timer_id = c_int(loop.timer(1000, 1, timer_event, None))
562 loop.timer(5, 1, cancel_timer_event, byref(timer_id))
561 timer_id = loop.timer(1000, 1, timer_event, None)
562 loop.timer(5, 1, cancel_timer_event, timer_id)
563563
564564 # After 20 msecs, send a ping message to output3
565565 loop.timer(20, 1, timer_event, output)
1010 Platform independent command line argument parsing helpers
1111
1212 There are two kind of elements provided by this class
13 foo --named-parameter --parameter with_value positional arguments -a gain-parameter
14 zargs keeps poision only for arguments, parameters are to be accessed like hash.
13 Named parameters, accessed by param_get and param_has methods
14 * --named-parameter
15 * --parameter with_value
16 * -a val
17 Positional arguments, accessed by zargs_first, zargs_next
1518
1619 It DOES:
1720 * provide easy to use CLASS compatible API for accessing argv
1821 * is platform independent
1922 * provide getopt_long style -- argument, which delimits parameters from arguments
20 * makes parameters positon independent
23 * makes parameters position independent
2124
2225 It does NOT
2326 * change argv
8184
8285 def param_name(self):
8386 """
84 Return current parameter name, or NULL if there are no named
85 parameters.
87 Return current parameter name, or NULL if there are no named parameters.
8688 """
8789 return utils.lib.zargs_param_name(self._p)
8890
89 def param_lookup(self, keys):
91 def get(self, name):
9092 """
91 Return value of named parameter, NULL if no given parameter has
92 been specified, or special value for wich zargs_param_empty ()
93 returns true.
93 Return value of named parameter or NULL is it has no value (or was not specified)
9494 """
95 return utils.lib.zargs_param_lookup(self._p, utils.to_bytes(keys))
95 return utils.lib.zargs_get(self._p, utils.to_bytes(name))
9696
97 def param_lookupx(self, keys, ):
97 def getx(self, name, ):
9898 """
99 Return value of named parameter(s), NULL if no given parameter has
100 been specified, or special value for wich zargs_param_empty ()
101 returns true.
99 Return value of one of parameter(s) or NULL is it has no value (or was not specified)
102100 """
103 return utils.lib.zargs_param_lookupx(self._p, utils.to_bytes(keys), )
101 return utils.lib.zargs_getx(self._p, utils.to_bytes(name), )
104102
105 def has_help(self):
103 def has(self, name):
106104 """
107 Returns true if there are --help -h arguments
105 Returns true if named parameter was specified on command line
108106 """
109 return utils.lib.zargs_has_help(self._p)
107 return utils.lib.zargs_has(self._p, utils.to_bytes(name))
110108
111 def param_empty(arg):
109 def hasx(self, name, ):
112110 """
113 Returns true if parameter did not have a value
111 Returns true if named parameter(s) was specified on command line
114112 """
115 return utils.lib.zargs_param_empty(utils.to_bytes(arg))
113 return utils.lib.zargs_hasx(self._p, utils.to_bytes(name), )
116114
117115 def print_py(self):
118116 """
148148 """
149149 return utils.lib.zchunk_pack(self._p)
150150
151 def packx(self_p):
152 """
153 Transform zchunk into a zframe that can be sent in a message.
154 Take ownership of the chunk.
155 """
156 return utils.lib.zchunk_packx(self_p._p)
157
151158 def unpack(frame):
152159 """
153160 Transform a zframe into a zchunk.
2323 # https://cffi.readthedocs.org/en/latest/using.html#ffi-interface
2424 self._p = utils.ffi.gc(p, libczmq_destructors.zconfig_destroy_py)
2525
26 def dup(self):
27 """
28 Create copy of zconfig, caller MUST free the value
29 Create copy of config, as new zconfig object. Returns a fresh zconfig_t
30 object. If config is null, or memory was exhausted, returns null.
31 """
32 return utils.lib.zconfig_dup(self._p)
33
2634 def name(self):
2735 """
2836 Return name of config item
0 ################################################################################
1 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
2 # Read the zproject/README.md for information about making permanent changes. #
3 ################################################################################
4 from . import utils
5 from . import destructors
6 libczmq_destructors = destructors.lib
7
8 class ZhttpClient(object):
9 """
10 Http client, allowing multiple requests simultaneously and integrate easily with zpoller.
11 Use zhttp_request class to create and send the request.
12 Use zhttp_response class to receive the response.
13 """
14
15 def __init__(self, verbose):
16 """
17 Create a new http client
18 """
19 p = utils.lib.zhttp_client_new(verbose)
20 if p == utils.ffi.NULL:
21 raise MemoryError("Could not allocate person")
22
23 # ffi.gc returns a copy of the cdata object which will have the
24 # destructor called when the Python object is GC'd:
25 # https://cffi.readthedocs.org/en/latest/using.html#ffi-interface
26 self._p = utils.ffi.gc(p, libczmq_destructors.zhttp_client_destroy_py)
27
28 def test(verbose):
29 """
30 Self test of this class.
31 """
32 utils.lib.zhttp_client_test(verbose)
33
34 ################################################################################
35 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
36 # Read the zproject/README.md for information about making permanent changes. #
37 ################################################################################
0 ################################################################################
1 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
2 # Read the zproject/README.md for information about making permanent changes. #
3 ################################################################################
4 from . import utils
5 from . import destructors
6 libczmq_destructors = destructors.lib
7
8 class ZhttpRequest(object):
9 """
10 Http request that can be received from zhttp_server or sent to zhttp_client.
11 Class can be reused between send & recv calls.
12 Headers and Content is being destroyed after every send call.
13 """
14
15 def __init__(self):
16 """
17 Create a new http request.
18 """
19 p = utils.lib.zhttp_request_new()
20 if p == utils.ffi.NULL:
21 raise MemoryError("Could not allocate person")
22
23 # ffi.gc returns a copy of the cdata object which will have the
24 # destructor called when the Python object is GC'd:
25 # https://cffi.readthedocs.org/en/latest/using.html#ffi-interface
26 self._p = utils.ffi.gc(p, libczmq_destructors.zhttp_request_destroy_py)
27
28 def recv(self, sock):
29 """
30 Receive a new request from zhttp_server.
31 Return the underlying connection if successful, to be used when calling zhttp_response_send.
32 """
33 return utils.lib.zhttp_request_recv(self._p, sock._p)
34
35 def send(self, client, timeout, arg, arg2):
36 """
37 Send a request to zhttp_client.
38 Url and the request path will be concatenated.
39 This behavior is useful for url rewrite and reverse proxy.
40
41 Send also allow two user provided arguments which will be returned with the response.
42 The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an arg.
43 """
44 return utils.lib.zhttp_request_send(self._p, client._p, timeout, arg._p, arg2._p)
45
46 def method(self):
47 """
48 Get the request method
49 """
50 return utils.lib.zhttp_request_method(self._p)
51
52 def set_method(self, method):
53 """
54 Set the request method
55 """
56 utils.lib.zhttp_request_set_method(self._p, utils.to_bytes(method))
57
58 def url(self):
59 """
60 Get the request url.
61 When receiving a request from http server this is only the path part of the url.
62 """
63 return utils.lib.zhttp_request_url(self._p)
64
65 def set_url(self, url):
66 """
67 Set the request url
68 When sending a request to http client this should be full url.
69 """
70 utils.lib.zhttp_request_set_url(self._p, utils.to_bytes(url))
71
72 def content_type(self):
73 """
74 Get the request content type
75 """
76 return utils.lib.zhttp_request_content_type(self._p)
77
78 def set_content_type(self, content_type):
79 """
80 Set the request content type
81 """
82 utils.lib.zhttp_request_set_content_type(self._p, utils.to_bytes(content_type))
83
84 def content_length(self):
85 """
86 Get the content length of the request
87 """
88 return utils.lib.zhttp_request_content_length(self._p)
89
90 def headers(self):
91 """
92 Get the headers of the request
93 """
94 return utils.lib.zhttp_request_headers(self._p)
95
96 def content(self):
97 """
98 Get the content of the request.
99 """
100 return utils.lib.zhttp_request_content(self._p)
101
102 def get_content(self):
103 """
104 Get the content of the request.
105 """
106 return utils.lib.zhttp_request_get_content(self._p)
107
108 def set_content(self, content):
109 """
110 Set the content of the request.
111 Content must by dynamically allocated string.
112 Takes ownership of the content.
113 """
114 utils.lib.zhttp_request_set_content(self._p, utils.to_bytes(content))
115
116 def set_content_const(self, content):
117 """
118 Set the content of the request..
119 The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
120 """
121 utils.lib.zhttp_request_set_content_const(self._p, utils.to_bytes(content))
122
123 def reset_content(self):
124 """
125 Set the content to NULL
126 """
127 utils.lib.zhttp_request_reset_content(self._p)
128
129 def match(self, method, path, ):
130 """
131 Match the path of the request.
132 Support wildcards with '%s' symbol inside the match string.
133 Matching wildcards until the next '/', '?' or '\0'.
134 On successful match the variadic arguments will be filled with the matching strings.
135 On successful match the method is modifying the url field and break it into substrings.
136 If you need to use the url, do it before matching or take a copy.
137
138 User must not free the variadic arguments as they are part of the url.
139
140 To use the percent symbol, just double it, e.g "%%something".
141
142 Example:
143 if (zhttp_request_match (request, "POST", "/send/%s/%s", &name, &id))
144 """
145 return utils.lib.zhttp_request_match(self._p, utils.to_bytes(method), utils.to_bytes(path), )
146
147 def test(verbose):
148 """
149 Self test of this class.
150 """
151 utils.lib.zhttp_request_test(verbose)
152
153 ################################################################################
154 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
155 # Read the zproject/README.md for information about making permanent changes. #
156 ################################################################################
0 ################################################################################
1 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
2 # Read the zproject/README.md for information about making permanent changes. #
3 ################################################################################
4 from . import utils
5 from . import destructors
6 libczmq_destructors = destructors.lib
7
8 class ZhttpResponse(object):
9 """
10 Http response that can be received from zhttp_client or sent to zhttp_server.
11 Class can be reused between send & recv calls.
12 Headers and Content is being destroyed after every send call.
13 """
14
15 def __init__(self):
16 """
17 Create a new zhttp_response.
18 """
19 p = utils.lib.zhttp_response_new()
20 if p == utils.ffi.NULL:
21 raise MemoryError("Could not allocate person")
22
23 # ffi.gc returns a copy of the cdata object which will have the
24 # destructor called when the Python object is GC'd:
25 # https://cffi.readthedocs.org/en/latest/using.html#ffi-interface
26 self._p = utils.ffi.gc(p, libczmq_destructors.zhttp_response_destroy_py)
27
28 def send(self, sock, connection):
29 """
30 Send a response to a request.
31 Returns 0 if successful and -1 otherwise.
32 """
33 return utils.lib.zhttp_response_send(self._p, sock._p, connection._p)
34
35 def recv(self, client, arg, arg2):
36 """
37 Receive a response from zhttp_client.
38 On success return 0, -1 otherwise.
39
40 Recv returns the two user arguments which was provided with the request.
41 The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an argument.
42 """
43 return utils.lib.zhttp_response_recv(self._p, client._p, arg._p, arg2._p)
44
45 def content_type(self):
46 """
47 Get the response content type
48 """
49 return utils.lib.zhttp_response_content_type(self._p)
50
51 def set_content_type(self, value):
52 """
53 Set the content type of the response.
54 """
55 utils.lib.zhttp_response_set_content_type(self._p, utils.to_bytes(value))
56
57 def status_code(self):
58 """
59 Get the status code of the response.
60 """
61 return utils.lib.zhttp_response_status_code(self._p)
62
63 def set_status_code(self, status_code):
64 """
65 Set the status code of the response.
66 """
67 utils.lib.zhttp_response_set_status_code(self._p, status_code)
68
69 def headers(self):
70 """
71 Get the headers of the response.
72 """
73 return utils.lib.zhttp_response_headers(self._p)
74
75 def content_length(self):
76 """
77 Get the content length of the response
78 """
79 return utils.lib.zhttp_response_content_length(self._p)
80
81 def content(self):
82 """
83 Get the content of the response.
84 """
85 return utils.lib.zhttp_response_content(self._p)
86
87 def get_content(self):
88 """
89 Get the content of the response.
90 """
91 return utils.lib.zhttp_response_get_content(self._p)
92
93 def set_content(self, content):
94 """
95 Set the content of the response.
96 Content must by dynamically allocated string.
97 Takes ownership of the content.
98 """
99 utils.lib.zhttp_response_set_content(self._p, utils.to_bytes(content))
100
101 def set_content_const(self, content):
102 """
103 Set the content of the response.
104 The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
105 """
106 utils.lib.zhttp_response_set_content_const(self._p, utils.to_bytes(content))
107
108 def reset_content(self):
109 """
110 Set the content to NULL
111 """
112 utils.lib.zhttp_response_reset_content(self._p)
113
114 def test(verbose):
115 """
116 Self test of this class.
117 """
118 utils.lib.zhttp_response_test(verbose)
119
120 ################################################################################
121 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
122 # Read the zproject/README.md for information about making permanent changes. #
123 ################################################################################
0 ################################################################################
1 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
2 # Read the zproject/README.md for information about making permanent changes. #
3 ################################################################################
4 from . import utils
5 from . import destructors
6 libczmq_destructors = destructors.lib
7
8 class ZhttpServer(object):
9 """
10 Simple http server.
11 To start handling requests:
12 1. Create a dealer socket
13 2. Connect the socket to the server backend address provided in the options.
14 3. Create a zhttp_request.
15 4. Call zhttp_request_recv to accept a new request.
16 5. Call zhttp_response_send to send a response.
17
18 You can connect as many dealers as you want.
19 The Server is using simple dealer socket to route the requests.
20
21 NOTE: when using libmicrohttpd << 0.9.34 the application might experience
22 high CPU usage due to the lack of MHD_suspend_connection and
23 MHD_resume_connection APIs. It is recommended to use this class only with
24 libmicrohttpd at least 0.9.34 in production.
25 """
26
27 def __init__(self, options):
28 """
29 Create a new http server
30 """
31 p = utils.lib.zhttp_server_new(options._p)
32 if p == utils.ffi.NULL:
33 raise MemoryError("Could not allocate person")
34
35 # ffi.gc returns a copy of the cdata object which will have the
36 # destructor called when the Python object is GC'd:
37 # https://cffi.readthedocs.org/en/latest/using.html#ffi-interface
38 self._p = utils.ffi.gc(p, libczmq_destructors.zhttp_server_destroy_py)
39
40 def port(self):
41 """
42 Return the port the server is listening on.
43 """
44 return utils.lib.zhttp_server_port(self._p)
45
46 def test(verbose):
47 """
48 Self test of this class.
49 """
50 utils.lib.zhttp_server_test(verbose)
51
52 ################################################################################
53 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
54 # Read the zproject/README.md for information about making permanent changes. #
55 ################################################################################
0 ################################################################################
1 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
2 # Read the zproject/README.md for information about making permanent changes. #
3 ################################################################################
4 from . import utils
5 from . import destructors
6 libczmq_destructors = destructors.lib
7
8 class ZhttpServerConnection(object):
9 """
10
11 """
12
13 def test(verbose):
14 """
15 Self test of this class.
16 """
17 utils.lib.zhttp_server_connection_test(verbose)
18
19 ################################################################################
20 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
21 # Read the zproject/README.md for information about making permanent changes. #
22 ################################################################################
0 ################################################################################
1 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
2 # Read the zproject/README.md for information about making permanent changes. #
3 ################################################################################
4 from . import utils
5 from . import destructors
6 libczmq_destructors = destructors.lib
7
8 class ZhttpServerOptions(object):
9 """
10 zhttp server.
11 """
12
13 def __init__(self):
14 """
15 Create a new zhttp_server_options.
16 """
17 p = utils.lib.zhttp_server_options_new()
18 if p == utils.ffi.NULL:
19 raise MemoryError("Could not allocate person")
20
21 # ffi.gc returns a copy of the cdata object which will have the
22 # destructor called when the Python object is GC'd:
23 # https://cffi.readthedocs.org/en/latest/using.html#ffi-interface
24 self._p = utils.ffi.gc(p, libczmq_destructors.zhttp_server_options_destroy_py)
25
26 def port(self):
27 """
28 Get the server listening port.
29 """
30 return utils.lib.zhttp_server_options_port(self._p)
31
32 def set_port(self, port):
33 """
34 Set the server listening port
35 """
36 utils.lib.zhttp_server_options_set_port(self._p, port)
37
38 def backend_address(self):
39 """
40 Get the address sockets should connect to in order to receive requests.
41 """
42 return utils.lib.zhttp_server_options_backend_address(self._p)
43
44 def set_backend_address(self, address):
45 """
46 Set the address sockets should connect to in order to receive requests.
47 """
48 utils.lib.zhttp_server_options_set_backend_address(self._p, utils.to_bytes(address))
49
50 def test(verbose):
51 """
52 Self test of this class.
53 """
54 utils.lib.zhttp_server_options_test(verbose)
55
56 ################################################################################
57 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
58 # Read the zproject/README.md for information about making permanent changes. #
59 ################################################################################
222222 """
223223 utils.lib.zlistx_set_comparator(self._p, comparator)
224224
225 def pack(self):
226 """
227 Serialize list to a binary frame that can be sent in a message.
228 The packed format is compatible with the 'strings' type implemented by zproto:
229
230 ; A list of strings
231 list = list-count *longstr
232 list-count = number-4
233
234 ; Strings are always length + text contents
235 longstr = number-4 *VCHAR
236
237 ; Numbers are unsigned integers in network byte order
238 number-4 = 4OCTET
239 """
240 return utils.lib.zlistx_pack(self._p)
241
225242 def test(verbose):
226243 """
227244 Self test of this class.
128128 """
129129 return utils.lib.zproc_running(self._p)
130130
131 def wait(self, hang):
131 def wait(self, timeout):
132132 """
133 The timeout should be zero or greater, or -1 to wait indefinitely.
133134 wait or poll process status, return return code
134135 """
135 return utils.lib.zproc_wait(self._p, hang)
136 return utils.lib.zproc_wait(self._p, timeout)
137
138 def shutdown(self, timeout):
139 """
140 send SIGTERM signal to the subprocess, wait for grace period and
141 eventually send SIGKILL
142 """
143 utils.lib.zproc_shutdown(self._p, timeout)
136144
137145 def actor(self):
138146 """
139 return internal actor, usefull for the polling if process died
147 return internal actor, useful for the polling if process died
140148 """
141149 return utils.lib.zproc_actor(self._p)
142150
116116 c = zchunk_t *
117117 f = zframe_t *
118118 h = zhashx_t *
119 l = zlistx_t * (DRAFT)
119120 U = zuuid_t *
120121 p = void * (sends the pointer value, only meaningful over inproc)
121122 m = zmsg_t * (sends all frames in the zmsg)
153154 f = zframe_t ** (creates zframe)
154155 U = zuuid_t * (creates a zuuid with the data)
155156 h = zhashx_t ** (creates zhashx)
157 l = zlistx_t ** (creates zlistx) (DRAFT)
156158 p = void ** (stores pointer)
157 m = zmsg_t ** (creates a zmsg with the remaing frames)
159 m = zmsg_t ** (creates a zmsg with the remaining frames)
158160 z = null, asserts empty frame (0 arguments)
159161 u = uint * (stores unsigned integer, deprecated)
160162
304306 """
305307 return utils.lib.zsock_resolve(self._p)
306308
309 def has_in(self):
310 """
311 Check whether the socket has available message to read.
312 """
313 return utils.lib.zsock_has_in(self._p)
314
315 def router_notify(self):
316 """
317 Get socket option `router_notify`.
318 Available from libzmq 4.3.0.
319 """
320 return utils.lib.zsock_router_notify(self._p)
321
322 def set_router_notify(self, router_notify):
323 """
324 Set socket option `router_notify`.
325 Available from libzmq 4.3.0.
326 """
327 utils.lib.zsock_set_router_notify(self._p, router_notify)
328
329 def multicast_loop(self):
330 """
331 Get socket option `multicast_loop`.
332 Available from libzmq 4.3.0.
333 """
334 return utils.lib.zsock_multicast_loop(self._p)
335
336 def set_multicast_loop(self, multicast_loop):
337 """
338 Set socket option `multicast_loop`.
339 Available from libzmq 4.3.0.
340 """
341 utils.lib.zsock_set_multicast_loop(self._p, multicast_loop)
342
343 def metadata(self):
344 """
345 Get socket option `metadata`.
346 Available from libzmq 4.3.0.
347 """
348 return utils.lib.zsock_metadata(self._p)
349
350 def set_metadata(self, metadata):
351 """
352 Set socket option `metadata`.
353 Available from libzmq 4.3.0.
354 """
355 utils.lib.zsock_set_metadata(self._p, utils.to_bytes(metadata))
356
357 def loopback_fastpath(self):
358 """
359 Get socket option `loopback_fastpath`.
360 Available from libzmq 4.3.0.
361 """
362 return utils.lib.zsock_loopback_fastpath(self._p)
363
364 def set_loopback_fastpath(self, loopback_fastpath):
365 """
366 Set socket option `loopback_fastpath`.
367 Available from libzmq 4.3.0.
368 """
369 utils.lib.zsock_set_loopback_fastpath(self._p, loopback_fastpath)
370
371 def zap_enforce_domain(self):
372 """
373 Get socket option `zap_enforce_domain`.
374 Available from libzmq 4.3.0.
375 """
376 return utils.lib.zsock_zap_enforce_domain(self._p)
377
378 def set_zap_enforce_domain(self, zap_enforce_domain):
379 """
380 Set socket option `zap_enforce_domain`.
381 Available from libzmq 4.3.0.
382 """
383 utils.lib.zsock_set_zap_enforce_domain(self._p, zap_enforce_domain)
384
385 def gssapi_principal_nametype(self):
386 """
387 Get socket option `gssapi_principal_nametype`.
388 Available from libzmq 4.3.0.
389 """
390 return utils.lib.zsock_gssapi_principal_nametype(self._p)
391
392 def set_gssapi_principal_nametype(self, gssapi_principal_nametype):
393 """
394 Set socket option `gssapi_principal_nametype`.
395 Available from libzmq 4.3.0.
396 """
397 utils.lib.zsock_set_gssapi_principal_nametype(self._p, gssapi_principal_nametype)
398
399 def gssapi_service_principal_nametype(self):
400 """
401 Get socket option `gssapi_service_principal_nametype`.
402 Available from libzmq 4.3.0.
403 """
404 return utils.lib.zsock_gssapi_service_principal_nametype(self._p)
405
406 def set_gssapi_service_principal_nametype(self, gssapi_service_principal_nametype):
407 """
408 Set socket option `gssapi_service_principal_nametype`.
409 Available from libzmq 4.3.0.
410 """
411 utils.lib.zsock_set_gssapi_service_principal_nametype(self._p, gssapi_service_principal_nametype)
412
413 def bindtodevice(self):
414 """
415 Get socket option `bindtodevice`.
416 Available from libzmq 4.3.0.
417 """
418 return utils.lib.zsock_bindtodevice(self._p)
419
420 def set_bindtodevice(self, bindtodevice):
421 """
422 Set socket option `bindtodevice`.
423 Available from libzmq 4.3.0.
424 """
425 utils.lib.zsock_set_bindtodevice(self._p, utils.to_bytes(bindtodevice))
426
307427 def heartbeat_ivl(self):
308428 """
309429 Get socket option `heartbeat_ivl`.
8181 """
8282 Set default interrupt handler, so Ctrl-C or SIGTERM will set
8383 zsys_interrupted. Idempotent; safe to call multiple times.
84 Can be supressed by ZSYS_SIGHANDLER=false
84 Can be suppressed by ZSYS_SIGHANDLER=false
8585 *** This is for CZMQ internal use only and may change arbitrarily ***
8686 """
8787 utils.lib.zsys_catch_interrupts()
173173 number into provided fields, providing reference isn't null in each case.
174174 """
175175 utils.lib.zsys_version(major, minor, patch)
176
177 def sprintf_hint(hint, format, ):
178 """
179 Format a string using printf formatting, returning a freshly allocated
180 buffer. If there was insufficient memory, returns NULL. Free the returned
181 string using zstr_free(). The hinted version allows to optimize by using
182 a larger starting buffer size (known to/assumed by the developer) and so
183 avoid reallocations.
184 """
185 return utils.lib.zsys_sprintf_hint(hint, utils.to_bytes(format), )
176186
177187 def sprintf(format, ):
178188 """
295305 Note that this method is valid only before any socket is created.
296306 """
297307 utils.lib.zsys_set_thread_priority(priority)
308
309 def set_thread_name_prefix(prefix):
310 """
311 Configure the numeric prefix to each thread created for the internal
312 context's thread pool. This option is only supported on Linux.
313 If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
314 provides the default.
315 Note that this method is valid only before any socket is created.
316 """
317 utils.lib.zsys_set_thread_name_prefix(prefix)
318
319 def thread_name_prefix():
320 """
321 Return thread name prefix.
322 """
323 return utils.lib.zsys_thread_name_prefix()
324
325 def thread_affinity_cpu_add(cpu):
326 """
327 Adds a specific CPU to the affinity list of the ZMQ context thread pool.
328 This option is only supported on Linux.
329 Note that this method is valid only before any socket is created.
330 """
331 utils.lib.zsys_thread_affinity_cpu_add(cpu)
332
333 def thread_affinity_cpu_remove(cpu):
334 """
335 Removes a specific CPU to the affinity list of the ZMQ context thread pool.
336 This option is only supported on Linux.
337 Note that this method is valid only before any socket is created.
338 """
339 utils.lib.zsys_thread_affinity_cpu_remove(cpu)
298340
299341 def set_max_sockets(max_sockets):
300342 """
483525 Return use of automatic pre-allocated FDs for zsock instances.
484526 """
485527 return utils.lib.zsys_auto_use_fd()
528
529 def zprintf(format, args):
530 """
531 Print formatted string. Format is specified by variable names
532 in Python-like format style
533
534 "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
535 become
536 "key=value"
537
538 Returns freshly allocated string or NULL in a case of error.
539 Not enough memory, invalid format specifier, name not in args
540 """
541 return utils.lib.zsys_zprintf(utils.to_bytes(format), args._p)
542
543 def zprintf_error(format, args):
544 """
545 Return error string for given format/args combination.
546 """
547 return utils.lib.zsys_zprintf_error(utils.to_bytes(format), args._p)
548
549 def zplprintf(format, args):
550 """
551 Print formatted string. Format is specified by variable names
552 in Python-like format style
553
554 "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
555 become
556 "key=value"
557
558 Returns freshly allocated string or NULL in a case of error.
559 Not enough memory, invalid format specifier, name not in args
560 """
561 return utils.lib.zsys_zplprintf(utils.to_bytes(format), args._p)
562
563 def zplprintf_error(format, args):
564 """
565 Return error string for given format/args combination.
566 """
567 return utils.lib.zsys_zplprintf_error(utils.to_bytes(format), args._p)
486568
487569 def set_logident(value):
488570 """
44 from . import utils
55 from .Zactor import *
66 from .Zargs import *
7 MODE_BASE64_STD = 0 # Standard base 64
8 MODE_BASE64_URL = 1 # URL and filename friendly base 64
9 MODE_BASE32_STD = 2 # Standard base 32
10 MODE_BASE32_HEX = 3 # Extended hex base 32
11 MODE_BASE16 = 4 # Standard base 16
12 MODE_Z85 = 5 # Z85 from ZeroMQ RFC 32
7 MODE_BASE64_STD = 0 # standard base 64
8 MODE_BASE64_URL = 1 # url and filename friendly base 64
9 MODE_BASE32_STD = 2 # standard base 32
10 MODE_BASE32_HEX = 3 # extended hex base 32
11 MODE_BASE16 = 4 # standard base 16
12 MODE_Z85 = 5 # z85 from zeromq rfc 32
1313 from .Zarmour import *
1414 from .Zcert import *
1515 from .Zcertstore import *
1818 from .Zconfig import *
1919 from .Zdigest import *
2020 from .Zdir import *
21 CREATE = 1 # Creates a new file
22 DELETE = 2 # Delete a file
21 CREATE = 1 # creates a new file
22 DELETE = 2 # delete a file
2323 from .ZdirPatch import *
2424 from .Zfile import *
2525 MORE = 1 #
4141 from .Ztimerset import *
4242 from .Ztrie import *
4343 from .Zuuid import *
44 from .ZhttpClient import *
45 from .ZhttpServer import *
46 from .ZhttpServerOptions import *
47 from .ZhttpRequest import *
48 from .ZhttpResponse import *
+0
-4081
bindings/python_cffi/czmq_cffi/_cdefs.inc less more
0 ################################################################################
1 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
2 # Read the zproject/README.md for information about making permanent changes. #
3 ################################################################################
4 # This file is intended to be included while generating cffi binding for top level library
5
6 czmq_cdefs = list ()
7 # Custom setup for czmq
8 czmq_cdefs.append ('''
9 typedef int time_t;
10 typedef int off_t;
11
12 typedef unsigned char byte; // Single unsigned byte = 8 bits
13 typedef unsigned short dbyte; // Double byte = 16 bits
14 typedef unsigned int qbyte; // Quad byte = 32 bits
15 typedef int SOCKET;
16 typedef struct sockaddr_in inaddr_t;
17
18 // -- destroy an item
19 typedef void (czmq_destructor) (void **item);
20 // -- duplicate an item
21 typedef void *(czmq_duplicator) (const void *item);
22 // - compare two items, for sorting
23 typedef int (czmq_comparator) (const void *item1, const void *item2);
24 ''')
25
26 czmq_cdefs.append ('''
27 typedef struct _zsock_t zsock_t;
28 typedef struct _zactor_t zactor_t;
29 typedef struct _zmsg_t zmsg_t;
30 typedef struct _zargs_t zargs_t;
31 typedef struct _zarmour_t zarmour_t;
32 typedef struct _zchunk_t zchunk_t;
33 typedef struct _char_t char_t;
34 typedef struct _zcert_t zcert_t;
35 typedef struct _zlist_t zlist_t;
36 typedef struct _zcertstore_t zcertstore_t;
37 typedef struct _zlistx_t zlistx_t;
38 typedef struct _zframe_t zframe_t;
39 typedef struct _msecs_t msecs_t;
40 typedef struct _zclock_t zclock_t;
41 typedef struct _zconfig_t zconfig_t;
42 typedef struct _zdigest_t zdigest_t;
43 typedef struct _zdir_t zdir_t;
44 typedef struct _zhash_t zhash_t;
45 typedef struct _zfile_t zfile_t;
46 typedef struct _zdir_patch_t zdir_patch_t;
47 typedef struct _zhashx_t zhashx_t;
48 typedef struct _ziflist_t ziflist_t;
49 typedef struct _zloop_t zloop_t;
50 typedef struct _zmq_pollitem_t zmq_pollitem_t;
51 typedef struct _zpoller_t zpoller_t;
52 typedef struct _zproc_t zproc_t;
53 typedef struct _va_list_t va_list_t;
54 typedef struct _socket_t socket_t;
55 typedef struct _zstr_t zstr_t;
56 typedef struct _zsys_t zsys_t;
57 typedef struct _ztimerset_t ztimerset_t;
58 typedef struct _ztrie_t ztrie_t;
59 typedef struct _zuuid_t zuuid_t;
60 // Actors get a pipe and arguments from caller
61 typedef void (zactor_fn) (
62 zsock_t *pipe, void *args);
63
64 // Function to be called on zactor_destroy. Default behavior is to send zmsg_t with string "$TERM" in a first frame.
65 //
66 // An example - to send $KTHXBAI string
67 //
68 // if (zstr_send (self->pipe, "$KTHXBAI") == 0)
69 // zsock_wait (self->pipe);
70 typedef void (zactor_destructor_fn) (
71 zactor_t *self);
72
73 // Loaders retrieve certificates from an arbitrary source.
74 typedef void (zcertstore_loader) (
75 zcertstore_t *self);
76
77 // Destructor for loader state.
78 typedef void (zcertstore_destructor) (
79 void **self_p);
80
81 //
82 typedef int (zconfig_fct) (
83 zconfig_t *self, void *arg, int level);
84
85 // Callback function for zhash_freefn method
86 typedef void (zhash_free_fn) (
87 void *data);
88
89 // Destroy an item
90 typedef void (zhashx_destructor_fn) (
91 void **item);
92
93 // Duplicate an item
94 typedef void * (zhashx_duplicator_fn) (
95 const void *item);
96
97 // Compare two items, for sorting
98 typedef int (zhashx_comparator_fn) (
99 const void *item1, const void *item2);
100
101 // Destroy an item.
102 typedef void (zhashx_free_fn) (
103 void *data);
104
105 // Hash function for keys.
106 typedef size_t (zhashx_hash_fn) (
107 const void *key);
108
109 // Serializes an item to a longstr.
110 // The caller takes ownership of the newly created object.
111 typedef char * (zhashx_serializer_fn) (
112 const void *item);
113
114 // Deserializes a longstr into an item.
115 // The caller takes ownership of the newly created object.
116 typedef void * (zhashx_deserializer_fn) (
117 const char *item_str);
118
119 // Comparison function e.g. for sorting and removing.
120 typedef int (zlist_compare_fn) (
121 void *item1, void *item2);
122
123 // Callback function for zlist_freefn method
124 typedef void (zlist_free_fn) (
125 void *data);
126
127 // Destroy an item
128 typedef void (zlistx_destructor_fn) (
129 void **item);
130
131 // Duplicate an item
132 typedef void * (zlistx_duplicator_fn) (
133 const void *item);
134
135 // Compare two items, for sorting
136 typedef int (zlistx_comparator_fn) (
137 const void *item1, const void *item2);
138
139 // Callback function for reactor socket activity
140 typedef int (zloop_reader_fn) (
141 zloop_t *loop, zsock_t *reader, void *arg);
142
143 // Callback function for reactor events (low-level)
144 typedef int (zloop_fn) (
145 zloop_t *loop, zmq_pollitem_t *item, void *arg);
146
147 // Callback for reactor timer events
148 typedef int (zloop_timer_fn) (
149 zloop_t *loop, int timer_id, void *arg);
150
151 // Callback for interrupt signal handler
152 typedef void (zsys_handler_fn) (
153 int signal_value);
154
155 // Callback function for timer event.
156 typedef void (ztimerset_fn) (
157 int timer_id, void *arg);
158
159 // Callback function for ztrie_node to destroy node data.
160 typedef void (ztrie_destroy_data_fn) (
161 void **data);
162
163 // CLASS: zactor
164 // Create a new actor passing arbitrary arguments reference.
165 zactor_t *
166 zactor_new (zactor_fn task, void *args);
167
168 // Destroy an actor.
169 void
170 zactor_destroy (zactor_t **self_p);
171
172 // Send a zmsg message to the actor, take ownership of the message
173 // and destroy when it has been sent.
174 int
175 zactor_send (zactor_t *self, zmsg_t **msg_p);
176
177 // Receive a zmsg message from the actor. Returns NULL if the actor
178 // was interrupted before the message could be received, or if there
179 // was a timeout on the actor.
180 zmsg_t *
181 zactor_recv (zactor_t *self);
182
183 // Probe the supplied object, and report if it looks like a zactor_t.
184 bool
185 zactor_is (void *self);
186
187 // Probe the supplied reference. If it looks like a zactor_t instance,
188 // return the underlying libzmq actor handle; else if it looks like
189 // a libzmq actor handle, return the supplied value.
190 void *
191 zactor_resolve (void *self);
192
193 // Return the actor's zsock handle. Use this when you absolutely need
194 // to work with the zsock instance rather than the actor.
195 zsock_t *
196 zactor_sock (zactor_t *self);
197
198 // Change default destructor by custom function. Actor MUST be able to handle new message instead of default $TERM.
199 void
200 zactor_set_destructor (zactor_t *self, zactor_destructor_fn destructor);
201
202 // Self test of this class.
203 void
204 zactor_test (bool verbose);
205
206 // CLASS: zargs
207 // Create a new zargs from command line arguments.
208 zargs_t *
209 zargs_new (int argc, char **argv);
210
211 // Destroy zargs instance.
212 void
213 zargs_destroy (zargs_t **self_p);
214
215 // Return program name (argv[0])
216 const char *
217 zargs_progname (zargs_t *self);
218
219 // Return number of positional arguments
220 size_t
221 zargs_arguments (zargs_t *self);
222
223 // Return first positional argument or NULL
224 const char *
225 zargs_first (zargs_t *self);
226
227 // Return next positional argument or NULL
228 const char *
229 zargs_next (zargs_t *self);
230
231 // Return first named parameter value, or NULL if there are no named
232 // parameters, or value for which zargs_param_empty (arg) returns true.
233 const char *
234 zargs_param_first (zargs_t *self);
235
236 // Return next named parameter value, or NULL if there are no named
237 // parameters, or value for which zargs_param_empty (arg) returns true.
238 const char *
239 zargs_param_next (zargs_t *self);
240
241 // Return current parameter name, or NULL if there are no named
242 // parameters.
243 const char *
244 zargs_param_name (zargs_t *self);
245
246 // Return value of named parameter, NULL if no given parameter has
247 // been specified, or special value for wich zargs_param_empty ()
248 // returns true.
249 const char *
250 zargs_param_lookup (zargs_t *self, const char *keys);
251
252 // Return value of named parameter(s), NULL if no given parameter has
253 // been specified, or special value for wich zargs_param_empty ()
254 // returns true.
255 const char *
256 zargs_param_lookupx (zargs_t *self, const char *keys, ...);
257
258 // Returns true if there are --help -h arguments
259 bool
260 zargs_has_help (zargs_t *self);
261
262 // Returns true if parameter did not have a value
263 bool
264 zargs_param_empty (const char *arg);
265
266 // Print an instance of zargs.
267 void
268 zargs_print (zargs_t *self);
269
270 // Self test of this class.
271 void
272 zargs_test (bool verbose);
273
274 // CLASS: zarmour
275 // Create a new zarmour
276 zarmour_t *
277 zarmour_new (void);
278
279 // Destroy the zarmour
280 void
281 zarmour_destroy (zarmour_t **self_p);
282
283 // Encode a stream of bytes into an armoured string. Returns the armoured
284 // string, or NULL if there was insufficient memory available to allocate
285 // a new string.
286 char *
287 zarmour_encode (zarmour_t *self, const byte *data, size_t size);
288
289 // Decode an armoured string into a chunk. The decoded output is
290 // null-terminated, so it may be treated as a string, if that's what
291 // it was prior to encoding.
292 zchunk_t *
293 zarmour_decode (zarmour_t *self, const char *data);
294
295 // Get the mode property.
296 int
297 zarmour_mode (zarmour_t *self);
298
299 // Get printable string for mode.
300 const char *
301 zarmour_mode_str (zarmour_t *self);
302
303 // Set the mode property.
304 void
305 zarmour_set_mode (zarmour_t *self, int mode);
306
307 // Return true if padding is turned on.
308 bool
309 zarmour_pad (zarmour_t *self);
310
311 // Turn padding on or off. Default is on.
312 void
313 zarmour_set_pad (zarmour_t *self, bool pad);
314
315 // Get the padding character.
316 char
317 zarmour_pad_char (zarmour_t *self);
318
319 // Set the padding character.
320 void
321 zarmour_set_pad_char (zarmour_t *self, char pad_char);
322
323 // Return if splitting output into lines is turned on. Default is off.
324 bool
325 zarmour_line_breaks (zarmour_t *self);
326
327 // Turn splitting output into lines on or off.
328 void
329 zarmour_set_line_breaks (zarmour_t *self, bool line_breaks);
330
331 // Get the line length used for splitting lines.
332 size_t
333 zarmour_line_length (zarmour_t *self);
334
335 // Set the line length used for splitting lines.
336 void
337 zarmour_set_line_length (zarmour_t *self, size_t line_length);
338
339 // Print properties of object
340 void
341 zarmour_print (zarmour_t *self);
342
343 // Self test of this class.
344 void
345 zarmour_test (bool verbose);
346
347 // CLASS: zcert
348 // Create and initialize a new certificate in memory
349 zcert_t *
350 zcert_new (void);
351
352 // Accepts public/secret key pair from caller
353 zcert_t *
354 zcert_new_from (const byte *public_key, const byte *secret_key);
355
356 // Accepts public/secret key text pair from caller
357 zcert_t *
358 zcert_new_from_txt (const char *public_txt, const char *secret_txt);
359
360 // Load certificate from file
361 zcert_t *
362 zcert_load (const char *filename);
363
364 // Destroy a certificate in memory
365 void
366 zcert_destroy (zcert_t **self_p);
367
368 // Return public part of key pair as 32-byte binary string
369 const byte *
370 zcert_public_key (zcert_t *self);
371
372 // Return secret part of key pair as 32-byte binary string
373 const byte *
374 zcert_secret_key (zcert_t *self);
375
376 // Return public part of key pair as Z85 armored string
377 const char *
378 zcert_public_txt (zcert_t *self);
379
380 // Return secret part of key pair as Z85 armored string
381 const char *
382 zcert_secret_txt (zcert_t *self);
383
384 // Set certificate metadata from formatted string.
385 void
386 zcert_set_meta (zcert_t *self, const char *name, const char *format, ...);
387
388 // Unset certificate metadata.
389 void
390 zcert_unset_meta (zcert_t *self, const char *name);
391
392 // Get metadata value from certificate; if the metadata value doesn't
393 // exist, returns NULL.
394 const char *
395 zcert_meta (zcert_t *self, const char *name);
396
397 // Get list of metadata fields from certificate. Caller is responsible for
398 // destroying list. Caller should not modify the values of list items.
399 zlist_t *
400 zcert_meta_keys (zcert_t *self);
401
402 // Save full certificate (public + secret) to file for persistent storage
403 // This creates one public file and one secret file (filename + "_secret").
404 int
405 zcert_save (zcert_t *self, const char *filename);
406
407 // Save public certificate only to file for persistent storage
408 int
409 zcert_save_public (zcert_t *self, const char *filename);
410
411 // Save secret certificate only to file for persistent storage
412 int
413 zcert_save_secret (zcert_t *self, const char *filename);
414
415 // Apply certificate to socket, i.e. use for CURVE security on socket.
416 // If certificate was loaded from public file, the secret key will be
417 // undefined, and this certificate will not work successfully.
418 void
419 zcert_apply (zcert_t *self, void *socket);
420
421 // Return copy of certificate; if certificate is NULL or we exhausted
422 // heap memory, returns NULL.
423 zcert_t *
424 zcert_dup (zcert_t *self);
425
426 // Return true if two certificates have the same keys
427 bool
428 zcert_eq (zcert_t *self, zcert_t *compare);
429
430 // Print certificate contents to stdout
431 void
432 zcert_print (zcert_t *self);
433
434 // Self test of this class
435 void
436 zcert_test (bool verbose);
437
438 // CLASS: zcertstore
439 // Create a new certificate store from a disk directory, loading and
440 // indexing all certificates in that location. The directory itself may be
441 // absent, and created later, or modified at any time. The certificate store
442 // is automatically refreshed on any zcertstore_lookup() call. If the
443 // location is specified as NULL, creates a pure-memory store, which you
444 // can work with by inserting certificates at runtime.
445 zcertstore_t *
446 zcertstore_new (const char *location);
447
448 // Destroy a certificate store object in memory. Does not affect anything
449 // stored on disk.
450 void
451 zcertstore_destroy (zcertstore_t **self_p);
452
453 // Override the default disk loader with a custom loader fn.
454 void
455 zcertstore_set_loader (zcertstore_t *self, zcertstore_loader loader, zcertstore_destructor destructor, void *state);
456
457 // Look up certificate by public key, returns zcert_t object if found,
458 // else returns NULL. The public key is provided in Z85 text format.
459 zcert_t *
460 zcertstore_lookup (zcertstore_t *self, const char *public_key);
461
462 // Insert certificate into certificate store in memory. Note that this
463 // does not save the certificate to disk. To do that, use zcert_save()
464 // directly on the certificate. Takes ownership of zcert_t object.
465 void
466 zcertstore_insert (zcertstore_t *self, zcert_t **cert_p);
467
468 // Empty certificate hashtable. This wrapper exists to be friendly to bindings,
469 // which don't usually have access to struct internals.
470 void
471 zcertstore_empty (zcertstore_t *self);
472
473 // Print list of certificates in store to logging facility
474 void
475 zcertstore_print (zcertstore_t *self);
476
477 // Return a list of all the certificates in the store.
478 // The caller takes ownership of the zlistx_t object and is responsible
479 // for destroying it. The caller does not take ownership of the zcert_t
480 // objects.
481 zlistx_t *
482 zcertstore_certs (zcertstore_t *self);
483
484 // Self test of this class
485 void
486 zcertstore_test (bool verbose);
487
488 // CLASS: zchunk
489 // Create a new chunk of the specified size. If you specify the data, it
490 // is copied into the chunk. If you do not specify the data, the chunk is
491 // allocated and left empty, and you can then add data using zchunk_append.
492 zchunk_t *
493 zchunk_new (const void *data, size_t size);
494
495 // Destroy a chunk
496 void
497 zchunk_destroy (zchunk_t **self_p);
498
499 // Resizes chunk max_size as requested; chunk_cur size is set to zero
500 void
501 zchunk_resize (zchunk_t *self, size_t size);
502
503 // Return chunk cur size
504 size_t
505 zchunk_size (zchunk_t *self);
506
507 // Return chunk max size
508 size_t
509 zchunk_max_size (zchunk_t *self);
510
511 // Return chunk data
512 byte *
513 zchunk_data (zchunk_t *self);
514
515 // Set chunk data from user-supplied data; truncate if too large. Data may
516 // be null. Returns actual size of chunk
517 size_t
518 zchunk_set (zchunk_t *self, const void *data, size_t size);
519
520 // Fill chunk data from user-supplied octet
521 size_t
522 zchunk_fill (zchunk_t *self, byte filler, size_t size);
523
524 // Append user-supplied data to chunk, return resulting chunk size. If the
525 // data would exceeded the available space, it is truncated. If you want to
526 // grow the chunk to accommodate new data, use the zchunk_extend method.
527 size_t
528 zchunk_append (zchunk_t *self, const void *data, size_t size);
529
530 // Append user-supplied data to chunk, return resulting chunk size. If the
531 // data would exceeded the available space, the chunk grows in size.
532 size_t
533 zchunk_extend (zchunk_t *self, const void *data, size_t size);
534
535 // Copy as much data from 'source' into the chunk as possible; returns the
536 // new size of chunk. If all data from 'source' is used, returns exhausted
537 // on the source chunk. Source can be consumed as many times as needed until
538 // it is exhausted. If source was already exhausted, does not change chunk.
539 size_t
540 zchunk_consume (zchunk_t *self, zchunk_t *source);
541
542 // Returns true if the chunk was exhausted by consume methods, or if the
543 // chunk has a size of zero.
544 bool
545 zchunk_exhausted (zchunk_t *self);
546
547 // Read chunk from an open file descriptor
548 zchunk_t *
549 zchunk_read (FILE *handle, size_t bytes);
550
551 // Write chunk to an open file descriptor
552 int
553 zchunk_write (zchunk_t *self, FILE *handle);
554
555 // Try to slurp an entire file into a chunk. Will read up to maxsize of
556 // the file. If maxsize is 0, will attempt to read the entire file and
557 // fail with an assertion if that cannot fit into memory. Returns a new
558 // chunk containing the file data, or NULL if the file could not be read.
559 zchunk_t *
560 zchunk_slurp (const char *filename, size_t maxsize);
561
562 // Create copy of chunk, as new chunk object. Returns a fresh zchunk_t
563 // object, or null if there was not enough heap memory. If chunk is null,
564 // returns null.
565 zchunk_t *
566 zchunk_dup (zchunk_t *self);
567
568 // Return chunk data encoded as printable hex string. Caller must free
569 // string when finished with it.
570 char *
571 zchunk_strhex (zchunk_t *self);
572
573 // Return chunk data copied into freshly allocated string
574 // Caller must free string when finished with it.
575 char *
576 zchunk_strdup (zchunk_t *self);
577
578 // Return TRUE if chunk body is equal to string, excluding terminator
579 bool
580 zchunk_streq (zchunk_t *self, const char *string);
581
582 // Transform zchunk into a zframe that can be sent in a message.
583 zframe_t *
584 zchunk_pack (zchunk_t *self);
585
586 // Transform a zframe into a zchunk.
587 zchunk_t *
588 zchunk_unpack (zframe_t *frame);
589
590 // Calculate SHA1 digest for chunk, using zdigest class.
591 const char *
592 zchunk_digest (zchunk_t *self);
593
594 // Dump chunk to FILE stream, for debugging and tracing.
595 void
596 zchunk_fprint (zchunk_t *self, FILE *file);
597
598 // Dump message to stderr, for debugging and tracing.
599 // See zchunk_fprint for details
600 void
601 zchunk_print (zchunk_t *self);
602
603 // Probe the supplied object, and report if it looks like a zchunk_t.
604 bool
605 zchunk_is (void *self);
606
607 // Self test of this class.
608 void
609 zchunk_test (bool verbose);
610
611 // CLASS: zclock
612 // Sleep for a number of milliseconds
613 void
614 zclock_sleep (int msecs);
615
616 // Return current system clock as milliseconds. Note that this clock can
617 // jump backwards (if the system clock is changed) so is unsafe to use for
618 // timers and time offsets. Use zclock_mono for that instead.
619 int64_t
620 zclock_time (void);
621
622 // Return current monotonic clock in milliseconds. Use this when you compute
623 // time offsets. The monotonic clock is not affected by system changes and
624 // so will never be reset backwards, unlike a system clock.
625 int64_t
626 zclock_mono (void);
627
628 // Return current monotonic clock in microseconds. Use this when you compute
629 // time offsets. The monotonic clock is not affected by system changes and
630 // so will never be reset backwards, unlike a system clock.
631 int64_t
632 zclock_usecs (void);
633
634 // Return formatted date/time as fresh string. Free using zstr_free().
635 char *
636 zclock_timestr (void);
637
638 // Self test of this class.
639 void
640 zclock_test (bool verbose);
641
642 // CLASS: zconfig
643 // Create new config item
644 zconfig_t *
645 zconfig_new (const char *name, zconfig_t *parent);
646
647 // Destroy a config item and all its children
648 void
649 zconfig_destroy (zconfig_t **self_p);
650
651 // Load a config tree from a specified ZPL text file; returns a zconfig_t
652 // reference for the root, if the file exists and is readable. Returns NULL
653 // if the file does not exist.
654 zconfig_t *
655 zconfig_load (const char *filename);
656
657 // Equivalent to zconfig_load, taking a format string instead of a fixed
658 // filename.
659 zconfig_t *
660 zconfig_loadf (const char *format, ...);
661
662 // Return name of config item
663 char *
664 zconfig_name (zconfig_t *self);
665
666 // Return value of config item
667 char *
668 zconfig_value (zconfig_t *self);
669
670 // Insert or update configuration key with value
671 void
672 zconfig_put (zconfig_t *self, const char *path, const char *value);
673
674 // Equivalent to zconfig_put, accepting a format specifier and variable
675 // argument list, instead of a single string value.
676 void
677 zconfig_putf (zconfig_t *self, const char *path, const char *format, ...);
678
679 // Get value for config item into a string value; leading slash is optional
680 // and ignored.
681 char *
682 zconfig_get (zconfig_t *self, const char *path, const char *default_value);
683
684 // Set config item name, name may be NULL
685 void
686 zconfig_set_name (zconfig_t *self, const char *name);
687
688 // Set new value for config item. The new value may be a string, a printf
689 // format, or NULL. Note that if string may possibly contain '%', or if it
690 // comes from an insecure source, you must use '%s' as the format, followed
691 // by the string.
692 void
693 zconfig_set_value (zconfig_t *self, const char *format, ...);
694
695 // Find our first child, if any
696 zconfig_t *
697 zconfig_child (zconfig_t *self);
698
699 // Find our first sibling, if any
700 zconfig_t *
701 zconfig_next (zconfig_t *self);
702
703 // Find a config item along a path; leading slash is optional and ignored.
704 zconfig_t *
705 zconfig_locate (zconfig_t *self, const char *path);
706
707 // Locate the last config item at a specified depth
708 zconfig_t *
709 zconfig_at_depth (zconfig_t *self, int level);
710
711 // Execute a callback for each config item in the tree; returns zero if
712 // successful, else -1.
713 int
714 zconfig_execute (zconfig_t *self, zconfig_fct handler, void *arg);
715
716 // Add comment to config item before saving to disk. You can add as many
717 // comment lines as you like. If you use a null format, all comments are
718 // deleted.
719 void
720 zconfig_set_comment (zconfig_t *self, const char *format, ...);
721
722 // Return comments of config item, as zlist.
723 zlist_t *
724 zconfig_comments (zconfig_t *self);
725
726 // Save a config tree to a specified ZPL text file, where a filename
727 // "-" means dump to standard output.
728 int
729 zconfig_save (zconfig_t *self, const char *filename);
730
731 // Equivalent to zconfig_save, taking a format string instead of a fixed
732 // filename.
733 int
734 zconfig_savef (zconfig_t *self, const char *format, ...);
735
736 // Report filename used during zconfig_load, or NULL if none
737 const char *
738 zconfig_filename (zconfig_t *self);
739
740 // Reload config tree from same file that it was previously loaded from.
741 // Returns 0 if OK, -1 if there was an error (and then does not change
742 // existing data).
743 int
744 zconfig_reload (zconfig_t **self_p);
745
746 // Load a config tree from a memory chunk
747 zconfig_t *
748 zconfig_chunk_load (zchunk_t *chunk);
749
750 // Save a config tree to a new memory chunk
751 zchunk_t *
752 zconfig_chunk_save (zconfig_t *self);
753
754 // Load a config tree from a null-terminated string
755 zconfig_t *
756 zconfig_str_load (const char *string);
757
758 // Save a config tree to a new null terminated string
759 char *
760 zconfig_str_save (zconfig_t *self);
761
762 // Return true if a configuration tree was loaded from a file and that
763 // file has changed in since the tree was loaded.
764 bool
765 zconfig_has_changed (zconfig_t *self);
766
767 // Destroy subtree (all children)
768 void
769 zconfig_remove_subtree (zconfig_t *self);
770
771 // Destroy node and subtree (all children)
772 void
773 zconfig_remove (zconfig_t **self_p);
774
775 // Print the config file to open stream
776 void
777 zconfig_fprint (zconfig_t *self, FILE *file);
778
779 // Print properties of object
780 void
781 zconfig_print (zconfig_t *self);
782
783 // Self test of this class
784 void
785 zconfig_test (bool verbose);
786
787 // CLASS: zdigest
788 // Constructor - creates new digest object, which you use to build up a
789 // digest by repeatedly calling zdigest_update() on chunks of data.
790 zdigest_t *
791 zdigest_new (void);
792
793 // Destroy a digest object
794 void
795 zdigest_destroy (zdigest_t **self_p);
796
797 // Add buffer into digest calculation
798 void
799 zdigest_update (zdigest_t *self, const byte *buffer, size_t length);
800
801 // Return final digest hash data. If built without crypto support,
802 // returns NULL.
803 const byte *
804 zdigest_data (zdigest_t *self);
805
806 // Return final digest hash size
807 size_t
808 zdigest_size (zdigest_t *self);
809
810 // Return digest as printable hex string; caller should not modify nor
811 // free this string. After calling this, you may not use zdigest_update()
812 // on the same digest. If built without crypto support, returns NULL.
813 char *
814 zdigest_string (zdigest_t *self);
815
816 // Self test of this class.
817 void
818 zdigest_test (bool verbose);
819
820 // CLASS: zdir
821 // Create a new directory item that loads in the full tree of the specified
822 // path, optionally located under some parent path. If parent is "-", then
823 // loads only the top-level directory, and does not use parent as a path.
824 zdir_t *
825 zdir_new (const char *path, const char *parent);
826
827 // Destroy a directory tree and all children it contains.
828 void
829 zdir_destroy (zdir_t **self_p);
830
831 // Return directory path
832 const char *
833 zdir_path (zdir_t *self);
834
835 // Return last modification time for directory.
836 time_t
837 zdir_modified (zdir_t *self);
838
839 // Return total hierarchy size, in bytes of data contained in all files
840 // in the directory tree.
841 off_t
842 zdir_cursize (zdir_t *self);
843
844 // Return directory count
845 size_t
846 zdir_count (zdir_t *self);
847
848 // Returns a sorted list of zfile objects; Each entry in the list is a pointer
849 // to a zfile_t item already allocated in the zdir tree. Do not destroy the
850 // original zdir tree until you are done with this list.
851 zlist_t *
852 zdir_list (zdir_t *self);
853
854 // Remove directory, optionally including all files that it contains, at
855 // all levels. If force is false, will only remove the directory if empty.
856 // If force is true, will remove all files and all subdirectories.
857 void
858 zdir_remove (zdir_t *self, bool force);
859
860 // Calculate differences between two versions of a directory tree.
861 // Returns a list of zdir_patch_t patches. Either older or newer may
862 // be null, indicating the directory is empty/absent. If alias is set,
863 // generates virtual filename (minus path, plus alias).
864 zlist_t *
865 zdir_diff (zdir_t *older, zdir_t *newer, const char *alias);
866
867 // Return full contents of directory as a zdir_patch list.
868 zlist_t *
869 zdir_resync (zdir_t *self, const char *alias);
870
871 // Load directory cache; returns a hash table containing the SHA-1 digests
872 // of every file in the tree. The cache is saved between runs in .cache.
873 zhash_t *
874 zdir_cache (zdir_t *self);
875
876 // Print contents of directory to open stream
877 void
878 zdir_fprint (zdir_t *self, FILE *file, int indent);
879
880 // Print contents of directory to stdout
881 void
882 zdir_print (zdir_t *self, int indent);
883
884 // Create a new zdir_watch actor instance:
885 //
886 // zactor_t *watch = zactor_new (zdir_watch, NULL);
887 //
888 // Destroy zdir_watch instance:
889 //
890 // zactor_destroy (&watch);
891 //
892 // Enable verbose logging of commands and activity:
893 //
894 // zstr_send (watch, "VERBOSE");
895 //
896 // Subscribe to changes to a directory path:
897 //
898 // zsock_send (watch, "ss", "SUBSCRIBE", "directory_path");
899 //
900 // Unsubscribe from changes to a directory path:
901 //
902 // zsock_send (watch, "ss", "UNSUBSCRIBE", "directory_path");
903 //
904 // Receive directory changes:
905 // zsock_recv (watch, "sp", &path, &patches);
906 //
907 // // Delete the received data.
908 // free (path);
909 // zlist_destroy (&patches);
910 void
911 zdir_watch (zsock_t *pipe, void *unused);
912
913 // Self test of this class.
914 void
915 zdir_test (bool verbose);
916
917 // CLASS: zdir_patch
918 // Create new patch
919 zdir_patch_t *
920 zdir_patch_new (const char *path, zfile_t *file, int op, const char *alias);
921
922 // Destroy a patch
923 void
924 zdir_patch_destroy (zdir_patch_t **self_p);
925
926 // Create copy of a patch. If the patch is null, or memory was exhausted,
927 // returns null.
928 zdir_patch_t *
929 zdir_patch_dup (zdir_patch_t *self);
930
931 // Return patch file directory path
932 const char *
933 zdir_patch_path (zdir_patch_t *self);
934
935 // Return patch file item
936 zfile_t *
937 zdir_patch_file (zdir_patch_t *self);
938
939 // Return operation
940 int
941 zdir_patch_op (zdir_patch_t *self);
942
943 // Return patch virtual file path
944 const char *
945 zdir_patch_vpath (zdir_patch_t *self);
946
947 // Calculate hash digest for file (create only)
948 void
949 zdir_patch_digest_set (zdir_patch_t *self);
950
951 // Return hash digest for patch file
952 const char *
953 zdir_patch_digest (zdir_patch_t *self);
954
955 // Self test of this class.
956 void
957 zdir_patch_test (bool verbose);
958
959 // CLASS: zfile
960 // If file exists, populates properties. CZMQ supports portable symbolic
961 // links, which are files with the extension ".ln". A symbolic link is a
962 // text file containing one line, the filename of a target file. Reading
963 // data from the symbolic link actually reads from the target file. Path
964 // may be NULL, in which case it is not used.
965 zfile_t *
966 zfile_new (const char *path, const char *name);
967
968 // Create new temporary file for writing via tmpfile. File is automaticaly
969 // deleted on destroy
970 zfile_t *
971 zfile_tmp (void);
972
973 // Destroy a file item
974 void
975 zfile_destroy (zfile_t **self_p);
976
977 // Duplicate a file item, returns a newly constructed item. If the file
978 // is null, or memory was exhausted, returns null.
979 zfile_t *
980 zfile_dup (zfile_t *self);
981
982 // Return file name, remove path if provided
983 const char *
984 zfile_filename (zfile_t *self, const char *path);
985
986 // Refresh file properties from disk; this is not done automatically
987 // on access methods, otherwise it is not possible to compare directory
988 // snapshots.
989 void
990 zfile_restat (zfile_t *self);
991
992 // Return when the file was last modified. If you want this to reflect the
993 // current situation, call zfile_restat before checking this property.
994 time_t
995 zfile_modified (zfile_t *self);
996
997 // Return the last-known size of the file. If you want this to reflect the
998 // current situation, call zfile_restat before checking this property.
999 off_t
1000 zfile_cursize (zfile_t *self);
1001
1002 // Return true if the file is a directory. If you want this to reflect
1003 // any external changes, call zfile_restat before checking this property.
1004 bool
1005 zfile_is_directory (zfile_t *self);
1006
1007 // Return true if the file is a regular file. If you want this to reflect
1008 // any external changes, call zfile_restat before checking this property.
1009 bool
1010 zfile_is_regular (zfile_t *self);
1011
1012 // Return true if the file is readable by this process. If you want this to
1013 // reflect any external changes, call zfile_restat before checking this
1014 // property.
1015 bool
1016 zfile_is_readable (zfile_t *self);
1017
1018 // Return true if the file is writeable by this process. If you want this
1019 // to reflect any external changes, call zfile_restat before checking this
1020 // property.
1021 bool
1022 zfile_is_writeable (zfile_t *self);
1023
1024 // Check if file has stopped changing and can be safely processed.
1025 // Updates the file statistics from disk at every call.
1026 bool
1027 zfile_is_stable (zfile_t *self);
1028
1029 // Return true if the file was changed on disk since the zfile_t object
1030 // was created, or the last zfile_restat() call made on it.
1031 bool
1032 zfile_has_changed (zfile_t *self);
1033
1034 // Remove the file from disk
1035 void
1036 zfile_remove (zfile_t *self);
1037
1038 // Open file for reading
1039 // Returns 0 if OK, -1 if not found or not accessible
1040 int
1041 zfile_input (zfile_t *self);
1042
1043 // Open file for writing, creating directory if needed
1044 // File is created if necessary; chunks can be written to file at any
1045 // location. Returns 0 if OK, -1 if error.
1046 int
1047 zfile_output (zfile_t *self);
1048
1049 // Read chunk from file at specified position. If this was the last chunk,
1050 // sets the eof property. Returns a null chunk in case of error.
1051 zchunk_t *
1052 zfile_read (zfile_t *self, size_t bytes, off_t offset);
1053
1054 // Returns true if zfile_read() just read the last chunk in the file.
1055 bool
1056 zfile_eof (zfile_t *self);
1057
1058 // Write chunk to file at specified position
1059 // Return 0 if OK, else -1
1060 int
1061 zfile_write (zfile_t *self, zchunk_t *chunk, off_t offset);
1062
1063 // Read next line of text from file. Returns a pointer to the text line,
1064 // or NULL if there was nothing more to read from the file.
1065 const char *
1066 zfile_readln (zfile_t *self);
1067
1068 // Close file, if open
1069 void
1070 zfile_close (zfile_t *self);
1071
1072 // Return file handle, if opened
1073 FILE *
1074 zfile_handle (zfile_t *self);
1075
1076 // Calculate SHA1 digest for file, using zdigest class.
1077 const char *
1078 zfile_digest (zfile_t *self);
1079
1080 // Self test of this class.
1081 void
1082 zfile_test (bool verbose);
1083
1084 // CLASS: zframe
1085 // Create a new frame. If size is not null, allocates the frame data
1086 // to the specified size. If additionally, data is not null, copies
1087 // size octets from the specified data into the frame body.
1088 zframe_t *
1089 zframe_new (const void *data, size_t size);
1090
1091 // Destroy a frame
1092 void
1093 zframe_destroy (zframe_t **self_p);
1094
1095 // Create an empty (zero-sized) frame
1096 zframe_t *
1097 zframe_new_empty (void);
1098
1099 // Create a frame with a specified string content.
1100 zframe_t *
1101 zframe_from (const char *string);
1102
1103 // Receive frame from socket, returns zframe_t object or NULL if the recv
1104 // was interrupted. Does a blocking recv, if you want to not block then use
1105 // zpoller or zloop.
1106 zframe_t *
1107 zframe_recv (void *source);
1108
1109 // Send a frame to a socket, destroy frame after sending.
1110 // Return -1 on error, 0 on success.
1111 int
1112 zframe_send (zframe_t **self_p, void *dest, int flags);
1113
1114 // Return number of bytes in frame data
1115 size_t
1116 zframe_size (zframe_t *self);
1117
1118 // Return address of frame data
1119 byte *
1120 zframe_data (zframe_t *self);
1121
1122 // Return meta data property for frame
1123 // The caller shall not modify or free the returned value, which shall be
1124 // owned by the message.
1125 const char *
1126 zframe_meta (zframe_t *self, const char *property);
1127
1128 // Create a new frame that duplicates an existing frame. If frame is null,
1129 // or memory was exhausted, returns null.
1130 zframe_t *
1131 zframe_dup (zframe_t *self);
1132
1133 // Return frame data encoded as printable hex string, useful for 0MQ UUIDs.
1134 // Caller must free string when finished with it.
1135 char *
1136 zframe_strhex (zframe_t *self);
1137
1138 // Return frame data copied into freshly allocated string
1139 // Caller must free string when finished with it.
1140 char *
1141 zframe_strdup (zframe_t *self);
1142
1143 // Return TRUE if frame body is equal to string, excluding terminator
1144 bool
1145 zframe_streq (zframe_t *self, const char *string);
1146
1147 // Return frame MORE indicator (1 or 0), set when reading frame from socket
1148 // or by the zframe_set_more() method
1149 int
1150 zframe_more (zframe_t *self);
1151
1152 // Set frame MORE indicator (1 or 0). Note this is NOT used when sending
1153 // frame to socket, you have to specify flag explicitly.
1154 void
1155 zframe_set_more (zframe_t *self, int more);
1156
1157 // Return frame routing ID, if the frame came from a ZMQ_SERVER socket.
1158 // Else returns zero.
1159 uint32_t
1160 zframe_routing_id (zframe_t *self);
1161
1162 // Set routing ID on frame. This is used if/when the frame is sent to a
1163 // ZMQ_SERVER socket.
1164 void
1165 zframe_set_routing_id (zframe_t *self, uint32_t routing_id);
1166
1167 // Return frame group of radio-dish pattern.
1168 const char *
1169 zframe_group (zframe_t *self);
1170
1171 // Set group on frame. This is used if/when the frame is sent to a
1172 // ZMQ_RADIO socket.
1173 // Return -1 on error, 0 on success.
1174 int
1175 zframe_set_group (zframe_t *self, const char *group);
1176
1177 // Return TRUE if two frames have identical size and data
1178 // If either frame is NULL, equality is always false.
1179 bool
1180 zframe_eq (zframe_t *self, zframe_t *other);
1181
1182 // Set new contents for frame
1183 void
1184 zframe_reset (zframe_t *self, const void *data, size_t size);
1185
1186 // Send message to zsys log sink (may be stdout, or system facility as
1187 // configured by zsys_set_logstream). Prefix shows before frame, if not null.
1188 void
1189 zframe_print (zframe_t *self, const char *prefix);
1190
1191 // Probe the supplied object, and report if it looks like a zframe_t.
1192 bool
1193 zframe_is (void *self);
1194
1195 // Self test of this class.
1196 void
1197 zframe_test (bool verbose);
1198
1199 // CLASS: zhash
1200 // Create a new, empty hash container
1201 zhash_t *
1202 zhash_new (void);
1203
1204 // Destroy a hash container and all items in it
1205 void
1206 zhash_destroy (zhash_t **self_p);
1207
1208 // Unpack binary frame into a new hash table. Packed data must follow format
1209 // defined by zhash_pack. Hash table is set to autofree. An empty frame
1210 // unpacks to an empty hash table.
1211 zhash_t *
1212 zhash_unpack (zframe_t *frame);
1213
1214 // Insert item into hash table with specified key and item.
1215 // If key is already present returns -1 and leaves existing item unchanged
1216 // Returns 0 on success.
1217 int
1218 zhash_insert (zhash_t *self, const char *key, void *item);
1219
1220 // Update item into hash table with specified key and item.
1221 // If key is already present, destroys old item and inserts new one.
1222 // Use free_fn method to ensure deallocator is properly called on item.
1223 void
1224 zhash_update (zhash_t *self, const char *key, void *item);
1225
1226 // Remove an item specified by key from the hash table. If there was no such
1227 // item, this function does nothing.
1228 void
1229 zhash_delete (zhash_t *self, const char *key);
1230
1231 // Return the item at the specified key, or null
1232 void *
1233 zhash_lookup (zhash_t *self, const char *key);
1234
1235 // Reindexes an item from an old key to a new key. If there was no such
1236 // item, does nothing. Returns 0 if successful, else -1.
1237 int
1238 zhash_rename (zhash_t *self, const char *old_key, const char *new_key);
1239
1240 // Set a free function for the specified hash table item. When the item is
1241 // destroyed, the free function, if any, is called on that item.
1242 // Use this when hash items are dynamically allocated, to ensure that
1243 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
1244 // Returns the item, or NULL if there is no such item.
1245 void *
1246 zhash_freefn (zhash_t *self, const char *key, zhash_free_fn free_fn);
1247
1248 // Return the number of keys/items in the hash table
1249 size_t
1250 zhash_size (zhash_t *self);
1251
1252 // Make copy of hash table; if supplied table is null, returns null.
1253 // Does not copy items themselves. Rebuilds new table so may be slow on
1254 // very large tables. NOTE: only works with item values that are strings
1255 // since there's no other way to know how to duplicate the item value.
1256 zhash_t *
1257 zhash_dup (zhash_t *self);
1258
1259 // Return keys for items in table
1260 zlist_t *
1261 zhash_keys (zhash_t *self);
1262
1263 // Simple iterator; returns first item in hash table, in no given order,
1264 // or NULL if the table is empty. This method is simpler to use than the
1265 // foreach() method, which is deprecated. To access the key for this item
1266 // use zhash_cursor(). NOTE: do NOT modify the table while iterating.
1267 void *
1268 zhash_first (zhash_t *self);
1269
1270 // Simple iterator; returns next item in hash table, in no given order,
1271 // or NULL if the last item was already returned. Use this together with
1272 // zhash_first() to process all items in a hash table. If you need the
1273 // items in sorted order, use zhash_keys() and then zlist_sort(). To
1274 // access the key for this item use zhash_cursor(). NOTE: do NOT modify
1275 // the table while iterating.
1276 void *
1277 zhash_next (zhash_t *self);
1278
1279 // After a successful first/next method, returns the key for the item that
1280 // was returned. This is a constant string that you may not modify or
1281 // deallocate, and which lasts as long as the item in the hash. After an
1282 // unsuccessful first/next, returns NULL.
1283 const char *
1284 zhash_cursor (zhash_t *self);
1285
1286 // Add a comment to hash table before saving to disk. You can add as many
1287 // comment lines as you like. These comment lines are discarded when loading
1288 // the file. If you use a null format, all comments are deleted.
1289 void
1290 zhash_comment (zhash_t *self, const char *format, ...);
1291
1292 // Serialize hash table to a binary frame that can be sent in a message.
1293 // The packed format is compatible with the 'dictionary' type defined in
1294 // http://rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
1295 //
1296 // ; A list of name/value pairs
1297 // dictionary = dict-count *( dict-name dict-value )
1298 // dict-count = number-4
1299 // dict-value = longstr
1300 // dict-name = string
1301 //
1302 // ; Strings are always length + text contents
1303 // longstr = number-4 *VCHAR
1304 // string = number-1 *VCHAR
1305 //
1306 // ; Numbers are unsigned integers in network byte order
1307 // number-1 = 1OCTET
1308 // number-4 = 4OCTET
1309 //
1310 // Comments are not included in the packed data. Item values MUST be
1311 // strings.
1312 zframe_t *
1313 zhash_pack (zhash_t *self);
1314
1315 // Save hash table to a text file in name=value format. Hash values must be
1316 // printable strings; keys may not contain '=' character. Returns 0 if OK,
1317 // else -1 if a file error occurred.
1318 int
1319 zhash_save (zhash_t *self, const char *filename);
1320
1321 // Load hash table from a text file in name=value format; hash table must
1322 // already exist. Hash values must printable strings; keys may not contain
1323 // '=' character. Returns 0 if OK, else -1 if a file was not readable.
1324 int
1325 zhash_load (zhash_t *self, const char *filename);
1326
1327 // When a hash table was loaded from a file by zhash_load, this method will
1328 // reload the file if it has been modified since, and is "stable", i.e. not
1329 // still changing. Returns 0 if OK, -1 if there was an error reloading the
1330 // file.
1331 int
1332 zhash_refresh (zhash_t *self);
1333
1334 // Set hash for automatic value destruction. Note that this assumes that
1335 // values are NULL-terminated strings. Do not use with different types.
1336 void
1337 zhash_autofree (zhash_t *self);
1338
1339 // Self test of this class.
1340 void
1341 zhash_test (bool verbose);
1342
1343 // CLASS: zhashx
1344 // Create a new, empty hash container
1345 zhashx_t *
1346 zhashx_new (void);
1347
1348 // Destroy a hash container and all items in it
1349 void
1350 zhashx_destroy (zhashx_t **self_p);
1351
1352 // Unpack binary frame into a new hash table. Packed data must follow format
1353 // defined by zhashx_pack. Hash table is set to autofree. An empty frame
1354 // unpacks to an empty hash table.
1355 zhashx_t *
1356 zhashx_unpack (zframe_t *frame);
1357
1358 // Same as unpack but uses a user-defined deserializer function to convert
1359 // a longstr back into item format.
1360 zhashx_t *
1361 zhashx_unpack_own (zframe_t *frame, zhashx_deserializer_fn deserializer);
1362
1363 // Insert item into hash table with specified key and item.
1364 // If key is already present returns -1 and leaves existing item unchanged
1365 // Returns 0 on success.
1366 int
1367 zhashx_insert (zhashx_t *self, const void *key, void *item);
1368
1369 // Update or insert item into hash table with specified key and item. If the
1370 // key is already present, destroys old item and inserts new one. If you set
1371 // a container item destructor, this is called on the old value. If the key
1372 // was not already present, inserts a new item. Sets the hash cursor to the
1373 // new item.
1374 void
1375 zhashx_update (zhashx_t *self, const void *key, void *item);
1376
1377 // Remove an item specified by key from the hash table. If there was no such
1378 // item, this function does nothing.
1379 void
1380 zhashx_delete (zhashx_t *self, const void *key);
1381
1382 // Delete all items from the hash table. If the key destructor is
1383 // set, calls it on every key. If the item destructor is set, calls
1384 // it on every item.
1385 void
1386 zhashx_purge (zhashx_t *self);
1387
1388 // Return the item at the specified key, or null
1389 void *
1390 zhashx_lookup (zhashx_t *self, const void *key);
1391
1392 // Reindexes an item from an old key to a new key. If there was no such
1393 // item, does nothing. Returns 0 if successful, else -1.
1394 int
1395 zhashx_rename (zhashx_t *self, const void *old_key, const void *new_key);
1396
1397 // Set a free function for the specified hash table item. When the item is
1398 // destroyed, the free function, if any, is called on that item.
1399 // Use this when hash items are dynamically allocated, to ensure that
1400 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
1401 // Returns the item, or NULL if there is no such item.
1402 void *
1403 zhashx_freefn (zhashx_t *self, const void *key, zhashx_free_fn free_fn);
1404
1405 // Return the number of keys/items in the hash table
1406 size_t
1407 zhashx_size (zhashx_t *self);
1408
1409 // Return a zlistx_t containing the keys for the items in the
1410 // table. Uses the key_duplicator to duplicate all keys and sets the
1411 // key_destructor as destructor for the list.
1412 zlistx_t *
1413 zhashx_keys (zhashx_t *self);
1414
1415 // Return a zlistx_t containing the values for the items in the
1416 // table. Uses the duplicator to duplicate all items and sets the
1417 // destructor as destructor for the list.
1418 zlistx_t *
1419 zhashx_values (zhashx_t *self);
1420
1421 // Simple iterator; returns first item in hash table, in no given order,
1422 // or NULL if the table is empty. This method is simpler to use than the
1423 // foreach() method, which is deprecated. To access the key for this item
1424 // use zhashx_cursor(). NOTE: do NOT modify the table while iterating.
1425 void *
1426 zhashx_first (zhashx_t *self);
1427
1428 // Simple iterator; returns next item in hash table, in no given order,
1429 // or NULL if the last item was already returned. Use this together with
1430 // zhashx_first() to process all items in a hash table. If you need the
1431 // items in sorted order, use zhashx_keys() and then zlistx_sort(). To
1432 // access the key for this item use zhashx_cursor(). NOTE: do NOT modify
1433 // the table while iterating.
1434 void *
1435 zhashx_next (zhashx_t *self);
1436
1437 // After a successful first/next method, returns the key for the item that
1438 // was returned. This is a constant string that you may not modify or
1439 // deallocate, and which lasts as long as the item in the hash. After an
1440 // unsuccessful first/next, returns NULL.
1441 const void *
1442 zhashx_cursor (zhashx_t *self);
1443
1444 // Add a comment to hash table before saving to disk. You can add as many
1445 // comment lines as you like. These comment lines are discarded when loading
1446 // the file. If you use a null format, all comments are deleted.
1447 void
1448 zhashx_comment (zhashx_t *self, const char *format, ...);
1449
1450 // Save hash table to a text file in name=value format. Hash values must be
1451 // printable strings; keys may not contain '=' character. Returns 0 if OK,
1452 // else -1 if a file error occurred.
1453 int
1454 zhashx_save (zhashx_t *self, const char *filename);
1455
1456 // Load hash table from a text file in name=value format; hash table must
1457 // already exist. Hash values must printable strings; keys may not contain
1458 // '=' character. Returns 0 if OK, else -1 if a file was not readable.
1459 int
1460 zhashx_load (zhashx_t *self, const char *filename);
1461
1462 // When a hash table was loaded from a file by zhashx_load, this method will
1463 // reload the file if it has been modified since, and is "stable", i.e. not
1464 // still changing. Returns 0 if OK, -1 if there was an error reloading the
1465 // file.
1466 int
1467 zhashx_refresh (zhashx_t *self);
1468
1469 // Serialize hash table to a binary frame that can be sent in a message.
1470 // The packed format is compatible with the 'dictionary' type defined in
1471 // http://rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
1472 //
1473 // ; A list of name/value pairs
1474 // dictionary = dict-count *( dict-name dict-value )
1475 // dict-count = number-4
1476 // dict-value = longstr
1477 // dict-name = string
1478 //
1479 // ; Strings are always length + text contents
1480 // longstr = number-4 *VCHAR
1481 // string = number-1 *VCHAR
1482 //
1483 // ; Numbers are unsigned integers in network byte order
1484 // number-1 = 1OCTET
1485 // number-4 = 4OCTET
1486 //
1487 // Comments are not included in the packed data. Item values MUST be
1488 // strings.
1489 zframe_t *
1490 zhashx_pack (zhashx_t *self);
1491
1492 // Same as pack but uses a user-defined serializer function to convert items
1493 // into longstr.
1494 zframe_t *
1495 zhashx_pack_own (zhashx_t *self, zhashx_serializer_fn serializer);
1496
1497 // Make a copy of the list; items are duplicated if you set a duplicator
1498 // for the list, otherwise not. Copying a null reference returns a null
1499 // reference. Note that this method's behavior changed slightly for CZMQ
1500 // v3.x, as it does not set nor respect autofree. It does however let you
1501 // duplicate any hash table safely. The old behavior is in zhashx_dup_v2.
1502 zhashx_t *
1503 zhashx_dup (zhashx_t *self);
1504
1505 // Set a user-defined deallocator for hash items; by default items are not
1506 // freed when the hash is destroyed.
1507 void
1508 zhashx_set_destructor (zhashx_t *self, zhashx_destructor_fn destructor);
1509
1510 // Set a user-defined duplicator for hash items; by default items are not
1511 // copied when the hash is duplicated.
1512 void
1513 zhashx_set_duplicator (zhashx_t *self, zhashx_duplicator_fn duplicator);
1514
1515 // Set a user-defined deallocator for keys; by default keys are freed
1516 // when the hash is destroyed using free().
1517 void
1518 zhashx_set_key_destructor (zhashx_t *self, zhashx_destructor_fn destructor);
1519
1520 // Set a user-defined duplicator for keys; by default keys are duplicated
1521 // using strdup.
1522 void
1523 zhashx_set_key_duplicator (zhashx_t *self, zhashx_duplicator_fn duplicator);
1524
1525 // Set a user-defined comparator for keys; by default keys are
1526 // compared using strcmp.
1527 // The callback function should return zero (0) on matching
1528 // items.
1529 void
1530 zhashx_set_key_comparator (zhashx_t *self, zhashx_comparator_fn comparator);
1531
1532 // Set a user-defined hash function for keys; by default keys are
1533 // hashed by a modified Bernstein hashing function.
1534 void
1535 zhashx_set_key_hasher (zhashx_t *self, zhashx_hash_fn hasher);
1536
1537 // Make copy of hash table; if supplied table is null, returns null.
1538 // Does not copy items themselves. Rebuilds new table so may be slow on
1539 // very large tables. NOTE: only works with item values that are strings
1540 // since there's no other way to know how to duplicate the item value.
1541 zhashx_t *
1542 zhashx_dup_v2 (zhashx_t *self);
1543
1544 // Self test of this class.
1545 void
1546 zhashx_test (bool verbose);
1547
1548 // CLASS: ziflist
1549 // Get a list of network interfaces currently defined on the system
1550 ziflist_t *
1551 ziflist_new (void);
1552
1553 // Destroy a ziflist instance
1554 void
1555 ziflist_destroy (ziflist_t **self_p);
1556
1557 // Reload network interfaces from system
1558 void
1559 ziflist_reload (ziflist_t *self);
1560
1561 // Return the number of network interfaces on system
1562 size_t
1563 ziflist_size (ziflist_t *self);
1564
1565 // Get first network interface, return NULL if there are none
1566 const char *
1567 ziflist_first (ziflist_t *self);
1568
1569 // Get next network interface, return NULL if we hit the last one
1570 const char *
1571 ziflist_next (ziflist_t *self);
1572
1573 // Return the current interface IP address as a printable string
1574 const char *
1575 ziflist_address (ziflist_t *self);
1576
1577 // Return the current interface broadcast address as a printable string
1578 const char *
1579 ziflist_broadcast (ziflist_t *self);
1580
1581 // Return the current interface network mask as a printable string
1582 const char *
1583 ziflist_netmask (ziflist_t *self);
1584
1585 // Return the list of interfaces.
1586 void
1587 ziflist_print (ziflist_t *self);
1588
1589 // Get a list of network interfaces currently defined on the system
1590 // Includes IPv6 interfaces
1591 ziflist_t *
1592 ziflist_new_ipv6 (void);
1593
1594 // Reload network interfaces from system, including IPv6
1595 void
1596 ziflist_reload_ipv6 (ziflist_t *self);
1597
1598 // Return true if the current interface uses IPv6
1599 bool
1600 ziflist_is_ipv6 (ziflist_t *self);
1601
1602 // Self test of this class.
1603 void
1604 ziflist_test (bool verbose);
1605
1606 // CLASS: zlist
1607 // Create a new list container
1608 zlist_t *
1609 zlist_new (void);
1610
1611 // Destroy a list container
1612 void
1613 zlist_destroy (zlist_t **self_p);
1614
1615 // Return the item at the head of list. If the list is empty, returns NULL.
1616 // Leaves cursor pointing at the head item, or NULL if the list is empty.
1617 void *
1618 zlist_first (zlist_t *self);
1619
1620 // Return the next item. If the list is empty, returns NULL. To move to
1621 // the start of the list call zlist_first (). Advances the cursor.
1622 void *
1623 zlist_next (zlist_t *self);
1624
1625 // Return the item at the tail of list. If the list is empty, returns NULL.
1626 // Leaves cursor pointing at the tail item, or NULL if the list is empty.
1627 void *
1628 zlist_last (zlist_t *self);
1629
1630 // Return first item in the list, or null, leaves the cursor
1631 void *
1632 zlist_head (zlist_t *self);
1633
1634 // Return last item in the list, or null, leaves the cursor
1635 void *
1636 zlist_tail (zlist_t *self);
1637
1638 // Return the current item of list. If the list is empty, returns NULL.
1639 // Leaves cursor pointing at the current item, or NULL if the list is empty.
1640 void *
1641 zlist_item (zlist_t *self);
1642
1643 // Append an item to the end of the list, return 0 if OK or -1 if this
1644 // failed for some reason (out of memory). Note that if a duplicator has
1645 // been set, this method will also duplicate the item.
1646 int
1647 zlist_append (zlist_t *self, void *item);
1648
1649 // Push an item to the start of the list, return 0 if OK or -1 if this
1650 // failed for some reason (out of memory). Note that if a duplicator has
1651 // been set, this method will also duplicate the item.
1652 int
1653 zlist_push (zlist_t *self, void *item);
1654
1655 // Pop the item off the start of the list, if any
1656 void *
1657 zlist_pop (zlist_t *self);
1658
1659 // Checks if an item already is present. Uses compare method to determine if
1660 // items are equal. If the compare method is NULL the check will only compare
1661 // pointers. Returns true if item is present else false.
1662 bool
1663 zlist_exists (zlist_t *self, void *item);
1664
1665 // Remove the specified item from the list if present
1666 void
1667 zlist_remove (zlist_t *self, void *item);
1668
1669 // Make a copy of list. If the list has autofree set, the copied list will
1670 // duplicate all items, which must be strings. Otherwise, the list will hold
1671 // pointers back to the items in the original list. If list is null, returns
1672 // NULL.
1673 zlist_t *
1674 zlist_dup (zlist_t *self);
1675
1676 // Purge all items from list
1677 void
1678 zlist_purge (zlist_t *self);
1679
1680 // Return number of items in the list
1681 size_t
1682 zlist_size (zlist_t *self);
1683
1684 // Sort the list. If the compare function is null, sorts the list by
1685 // ascending key value using a straight ASCII comparison. If you specify
1686 // a compare function, this decides how items are sorted. The sort is not
1687 // stable, so may reorder items with the same keys. The algorithm used is
1688 // combsort, a compromise between performance and simplicity.
1689 void
1690 zlist_sort (zlist_t *self, zlist_compare_fn compare);
1691
1692 // Set list for automatic item destruction; item values MUST be strings.
1693 // By default a list item refers to a value held elsewhere. When you set
1694 // this, each time you append or push a list item, zlist will take a copy
1695 // of the string value. Then, when you destroy the list, it will free all
1696 // item values automatically. If you use any other technique to allocate
1697 // list values, you must free them explicitly before destroying the list.
1698 // The usual technique is to pop list items and destroy them, until the
1699 // list is empty.
1700 void
1701 zlist_autofree (zlist_t *self);
1702
1703 // Sets a compare function for this list. The function compares two items.
1704 // It returns an integer less than, equal to, or greater than zero if the
1705 // first item is found, respectively, to be less than, to match, or be
1706 // greater than the second item.
1707 // This function is used for sorting, removal and exists checking.
1708 void
1709 zlist_comparefn (zlist_t *self, zlist_compare_fn fn);
1710
1711 // Set a free function for the specified list item. When the item is
1712 // destroyed, the free function, if any, is called on that item.
1713 // Use this when list items are dynamically allocated, to ensure that
1714 // you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
1715 // Returns the item, or NULL if there is no such item.
1716 void *
1717 zlist_freefn (zlist_t *self, void *item, zlist_free_fn fn, bool at_tail);
1718
1719 // Self test of this class.
1720 void
1721 zlist_test (bool verbose);
1722
1723 // CLASS: zlistx
1724 // Create a new, empty list.
1725 zlistx_t *
1726 zlistx_new (void);
1727
1728 // Destroy a list. If an item destructor was specified, all items in the
1729 // list are automatically destroyed as well.
1730 void
1731 zlistx_destroy (zlistx_t **self_p);
1732
1733 // Add an item to the head of the list. Calls the item duplicator, if any,
1734 // on the item. Resets cursor to list head. Returns an item handle on
1735 // success, NULL if memory was exhausted.
1736 void *
1737 zlistx_add_start (zlistx_t *self, void *item);
1738
1739 // Add an item to the tail of the list. Calls the item duplicator, if any,
1740 // on the item. Resets cursor to list head. Returns an item handle on
1741 // success, NULL if memory was exhausted.
1742 void *
1743 zlistx_add_end (zlistx_t *self, void *item);
1744
1745 // Return the number of items in the list
1746 size_t
1747 zlistx_size (zlistx_t *self);
1748
1749 // Return first item in the list, or null, leaves the cursor
1750 void *
1751 zlistx_head (zlistx_t *self);
1752
1753 // Return last item in the list, or null, leaves the cursor
1754 void *
1755 zlistx_tail (zlistx_t *self);
1756
1757 // Return the item at the head of list. If the list is empty, returns NULL.
1758 // Leaves cursor pointing at the head item, or NULL if the list is empty.
1759 void *
1760 zlistx_first (zlistx_t *self);
1761
1762 // Return the next item. At the end of the list (or in an empty list),
1763 // returns NULL. Use repeated zlistx_next () calls to work through the list
1764 // from zlistx_first (). First time, acts as zlistx_first().
1765 void *
1766 zlistx_next (zlistx_t *self);
1767
1768 // Return the previous item. At the start of the list (or in an empty list),
1769 // returns NULL. Use repeated zlistx_prev () calls to work through the list
1770 // backwards from zlistx_last (). First time, acts as zlistx_last().
1771 void *
1772 zlistx_prev (zlistx_t *self);
1773
1774 // Return the item at the tail of list. If the list is empty, returns NULL.
1775 // Leaves cursor pointing at the tail item, or NULL if the list is empty.
1776 void *
1777 zlistx_last (zlistx_t *self);
1778
1779 // Returns the value of the item at the cursor, or NULL if the cursor is
1780 // not pointing to an item.
1781 void *
1782 zlistx_item (zlistx_t *self);
1783
1784 // Returns the handle of the item at the cursor, or NULL if the cursor is
1785 // not pointing to an item.
1786 void *
1787 zlistx_cursor (zlistx_t *self);
1788
1789 // Returns the item associated with the given list handle, or NULL if passed
1790 // in handle is NULL. Asserts that the passed in handle points to a list element.
1791 void *
1792 zlistx_handle_item (void *handle);
1793
1794 // Find an item in the list, searching from the start. Uses the item
1795 // comparator, if any, else compares item values directly. Returns the
1796 // item handle found, or NULL. Sets the cursor to the found item, if any.
1797 void *
1798 zlistx_find (zlistx_t *self, void *item);
1799
1800 // Detach an item from the list, using its handle. The item is not modified,
1801 // and the caller is responsible for destroying it if necessary. If handle is
1802 // null, detaches the first item on the list. Returns item that was detached,
1803 // or null if none was. If cursor was at item, moves cursor to previous item,
1804 // so you can detach items while iterating forwards through a list.
1805 void *
1806 zlistx_detach (zlistx_t *self, void *handle);
1807
1808 // Detach item at the cursor, if any, from the list. The item is not modified,
1809 // and the caller is responsible for destroying it as necessary. Returns item
1810 // that was detached, or null if none was. Moves cursor to previous item, so
1811 // you can detach items while iterating forwards through a list.
1812 void *
1813 zlistx_detach_cur (zlistx_t *self);
1814
1815 // Delete an item, using its handle. Calls the item destructor is any is
1816 // set. If handle is null, deletes the first item on the list. Returns 0
1817 // if an item was deleted, -1 if not. If cursor was at item, moves cursor
1818 // to previous item, so you can delete items while iterating forwards
1819 // through a list.
1820 int
1821 zlistx_delete (zlistx_t *self, void *handle);
1822
1823 // Move an item to the start of the list, via its handle.
1824 void
1825 zlistx_move_start (zlistx_t *self, void *handle);
1826
1827 // Move an item to the end of the list, via its handle.
1828 void
1829 zlistx_move_end (zlistx_t *self, void *handle);
1830
1831 // Remove all items from the list, and destroy them if the item destructor
1832 // is set.
1833 void
1834 zlistx_purge (zlistx_t *self);
1835
1836 // Sort the list. If an item comparator was set, calls that to compare
1837 // items, otherwise compares on item value. The sort is not stable, so may
1838 // reorder equal items.
1839 void
1840 zlistx_sort (zlistx_t *self);
1841
1842 // Create a new node and insert it into a sorted list. Calls the item
1843 // duplicator, if any, on the item. If low_value is true, starts searching
1844 // from the start of the list, otherwise searches from the end. Use the item
1845 // comparator, if any, to find where to place the new node. Returns a handle
1846 // to the new node, or NULL if memory was exhausted. Resets the cursor to the
1847 // list head.
1848 void *
1849 zlistx_insert (zlistx_t *self, void *item, bool low_value);
1850
1851 // Move an item, specified by handle, into position in a sorted list. Uses
1852 // the item comparator, if any, to determine the new location. If low_value
1853 // is true, starts searching from the start of the list, otherwise searches
1854 // from the end.
1855 void
1856 zlistx_reorder (zlistx_t *self, void *handle, bool low_value);
1857
1858 // Make a copy of the list; items are duplicated if you set a duplicator
1859 // for the list, otherwise not. Copying a null reference returns a null
1860 // reference.
1861 zlistx_t *
1862 zlistx_dup (zlistx_t *self);
1863
1864 // Set a user-defined deallocator for list items; by default items are not
1865 // freed when the list is destroyed.
1866 void
1867 zlistx_set_destructor (zlistx_t *self, zlistx_destructor_fn destructor);
1868
1869 // Set a user-defined duplicator for list items; by default items are not
1870 // copied when the list is duplicated.
1871 void
1872 zlistx_set_duplicator (zlistx_t *self, zlistx_duplicator_fn duplicator);
1873
1874 // Set a user-defined comparator for zlistx_find and zlistx_sort; the method
1875 // must return -1, 0, or 1 depending on whether item1 is less than, equal to,
1876 // or greater than, item2.
1877 void
1878 zlistx_set_comparator (zlistx_t *self, zlistx_comparator_fn comparator);
1879
1880 // Self test of this class.
1881 void
1882 zlistx_test (bool verbose);
1883
1884 // CLASS: zloop
1885 // Create a new zloop reactor
1886 zloop_t *
1887 zloop_new (void);
1888
1889 // Destroy a reactor
1890 void
1891 zloop_destroy (zloop_t **self_p);
1892
1893 // Register socket reader with the reactor. When the reader has messages,
1894 // the reactor will call the handler, passing the arg. Returns 0 if OK, -1
1895 // if there was an error. If you register the same socket more than once,
1896 // each instance will invoke its corresponding handler.
1897 int
1898 zloop_reader (zloop_t *self, zsock_t *sock, zloop_reader_fn handler, void *arg);
1899
1900 // Cancel a socket reader from the reactor. If multiple readers exist for
1901 // same socket, cancels ALL of them.
1902 void
1903 zloop_reader_end (zloop_t *self, zsock_t *sock);
1904
1905 // Configure a registered reader to ignore errors. If you do not set this,
1906 // then readers that have errors are removed from the reactor silently.
1907 void
1908 zloop_reader_set_tolerant (zloop_t *self, zsock_t *sock);
1909
1910 // Register low-level libzmq pollitem with the reactor. When the pollitem
1911 // is ready, will call the handler, passing the arg. Returns 0 if OK, -1
1912 // if there was an error. If you register the pollitem more than once, each
1913 // instance will invoke its corresponding handler. A pollitem with
1914 // socket=NULL and fd=0 means 'poll on FD zero'.
1915 int
1916 zloop_poller (zloop_t *self, zmq_pollitem_t *item, zloop_fn handler, void *arg);
1917
1918 // Cancel a pollitem from the reactor, specified by socket or FD. If both
1919 // are specified, uses only socket. If multiple poll items exist for same
1920 // socket/FD, cancels ALL of them.
1921 void
1922 zloop_poller_end (zloop_t *self, zmq_pollitem_t *item);
1923
1924 // Configure a registered poller to ignore errors. If you do not set this,
1925 // then poller that have errors are removed from the reactor silently.
1926 void
1927 zloop_poller_set_tolerant (zloop_t *self, zmq_pollitem_t *item);
1928
1929 // Register a timer that expires after some delay and repeats some number of
1930 // times. At each expiry, will call the handler, passing the arg. To run a
1931 // timer forever, use 0 times. Returns a timer_id that is used to cancel the
1932 // timer in the future. Returns -1 if there was an error.
1933 int
1934 zloop_timer (zloop_t *self, size_t delay, size_t times, zloop_timer_fn handler, void *arg);
1935
1936 // Cancel a specific timer identified by a specific timer_id (as returned by
1937 // zloop_timer).
1938 int
1939 zloop_timer_end (zloop_t *self, int timer_id);
1940
1941 // Register a ticket timer. Ticket timers are very fast in the case where
1942 // you use a lot of timers (thousands), and frequently remove and add them.
1943 // The main use case is expiry timers for servers that handle many clients,
1944 // and which reset the expiry timer for each message received from a client.
1945 // Whereas normal timers perform poorly as the number of clients grows, the
1946 // cost of ticket timers is constant, no matter the number of clients. You
1947 // must set the ticket delay using zloop_set_ticket_delay before creating a
1948 // ticket. Returns a handle to the timer that you should use in
1949 // zloop_ticket_reset and zloop_ticket_delete.
1950 void *
1951 zloop_ticket (zloop_t *self, zloop_timer_fn handler, void *arg);
1952
1953 // Reset a ticket timer, which moves it to the end of the ticket list and
1954 // resets its execution time. This is a very fast operation.
1955 void
1956 zloop_ticket_reset (zloop_t *self, void *handle);
1957
1958 // Delete a ticket timer. We do not actually delete the ticket here, as
1959 // other code may still refer to the ticket. We mark as deleted, and remove
1960 // later and safely.
1961 void
1962 zloop_ticket_delete (zloop_t *self, void *handle);
1963
1964 // Set the ticket delay, which applies to all tickets. If you lower the
1965 // delay and there are already tickets created, the results are undefined.
1966 void
1967 zloop_set_ticket_delay (zloop_t *self, size_t ticket_delay);
1968
1969 // Set hard limit on number of timers allowed. Setting more than a small
1970 // number of timers (10-100) can have a dramatic impact on the performance
1971 // of the reactor. For high-volume cases, use ticket timers. If the hard
1972 // limit is reached, the reactor stops creating new timers and logs an
1973 // error.
1974 void
1975 zloop_set_max_timers (zloop_t *self, size_t max_timers);
1976
1977 // Set verbose tracing of reactor on/off. The default verbose setting is
1978 // off (false).
1979 void
1980 zloop_set_verbose (zloop_t *self, bool verbose);
1981
1982 // By default the reactor stops if the process receives a SIGINT or SIGTERM
1983 // signal. This makes it impossible to shut-down message based architectures
1984 // like zactors. This method lets you switch off break handling. The default
1985 // nonstop setting is off (false).
1986 void
1987 zloop_set_nonstop (zloop_t *self, bool nonstop);
1988
1989 // Start the reactor. Takes control of the thread and returns when the 0MQ
1990 // context is terminated or the process is interrupted, or any event handler
1991 // returns -1. Event handlers may register new sockets and timers, and
1992 // cancel sockets. Returns 0 if interrupted, -1 if canceled by a handler.
1993 int
1994 zloop_start (zloop_t *self);
1995
1996 // Self test of this class.
1997 void
1998 zloop_test (bool verbose);
1999
2000 // CLASS: zmsg
2001 // Create a new empty message object
2002 zmsg_t *
2003 zmsg_new (void);
2004
2005 // Destroy a message object and all frames it contains
2006 void
2007 zmsg_destroy (zmsg_t **self_p);
2008
2009 // Receive message from socket, returns zmsg_t object or NULL if the recv
2010 // was interrupted. Does a blocking recv. If you want to not block then use
2011 // the zloop class or zmsg_recv_nowait or zmq_poll to check for socket input
2012 // before receiving.
2013 zmsg_t *
2014 zmsg_recv (void *source);
2015
2016 // Load/append an open file into new message, return the message.
2017 // Returns NULL if the message could not be loaded.
2018 zmsg_t *
2019 zmsg_load (FILE *file);
2020
2021 // Decodes a serialized message frame created by zmsg_encode () and returns
2022 // a new zmsg_t object. Returns NULL if the frame was badly formatted or
2023 // there was insufficient memory to work.
2024 zmsg_t *
2025 zmsg_decode (zframe_t *frame);
2026
2027 // Generate a signal message encoding the given status. A signal is a short
2028 // message carrying a 1-byte success/failure code (by convention, 0 means
2029 // OK). Signals are encoded to be distinguishable from "normal" messages.
2030 zmsg_t *
2031 zmsg_new_signal (byte status);
2032
2033 // Send message to destination socket, and destroy the message after sending
2034 // it successfully. If the message has no frames, sends nothing but destroys
2035 // the message anyhow. Nullifies the caller's reference to the message (as
2036 // it is a destructor).
2037 int
2038 zmsg_send (zmsg_t **self_p, void *dest);
2039
2040 // Send message to destination socket as part of a multipart sequence, and
2041 // destroy the message after sending it successfully. Note that after a
2042 // zmsg_sendm, you must call zmsg_send or another method that sends a final
2043 // message part. If the message has no frames, sends nothing but destroys
2044 // the message anyhow. Nullifies the caller's reference to the message (as
2045 // it is a destructor).
2046 int
2047 zmsg_sendm (zmsg_t **self_p, void *dest);
2048
2049 // Return size of message, i.e. number of frames (0 or more).
2050 size_t
2051 zmsg_size (zmsg_t *self);
2052
2053 // Return total size of all frames in message.
2054 size_t
2055 zmsg_content_size (zmsg_t *self);
2056
2057 // Return message routing ID, if the message came from a ZMQ_SERVER socket.
2058 // Else returns zero.
2059 uint32_t
2060 zmsg_routing_id (zmsg_t *self);
2061
2062 // Set routing ID on message. This is used if/when the message is sent to a
2063 // ZMQ_SERVER socket.
2064 void
2065 zmsg_set_routing_id (zmsg_t *self, uint32_t routing_id);
2066
2067 // Push frame to the front of the message, i.e. before all other frames.
2068 // Message takes ownership of frame, will destroy it when message is sent.
2069 // Returns 0 on success, -1 on error. Deprecates zmsg_push, which did not
2070 // nullify the caller's frame reference.
2071 int
2072 zmsg_prepend (zmsg_t *self, zframe_t **frame_p);
2073
2074 // Add frame to the end of the message, i.e. after all other frames.
2075 // Message takes ownership of frame, will destroy it when message is sent.
2076 // Returns 0 on success. Deprecates zmsg_add, which did not nullify the
2077 // caller's frame reference.
2078 int
2079 zmsg_append (zmsg_t *self, zframe_t **frame_p);
2080
2081 // Remove first frame from message, if any. Returns frame, or NULL.
2082 zframe_t *
2083 zmsg_pop (zmsg_t *self);
2084
2085 // Push block of memory to front of message, as a new frame.
2086 // Returns 0 on success, -1 on error.
2087 int
2088 zmsg_pushmem (zmsg_t *self, const void *data, size_t size);
2089
2090 // Add block of memory to the end of the message, as a new frame.
2091 // Returns 0 on success, -1 on error.
2092 int
2093 zmsg_addmem (zmsg_t *self, const void *data, size_t size);
2094
2095 // Push string as new frame to front of message.
2096 // Returns 0 on success, -1 on error.
2097 int
2098 zmsg_pushstr (zmsg_t *self, const char *string);
2099
2100 // Push string as new frame to end of message.
2101 // Returns 0 on success, -1 on error.
2102 int
2103 zmsg_addstr (zmsg_t *self, const char *string);
2104
2105 // Push formatted string as new frame to front of message.
2106 // Returns 0 on success, -1 on error.
2107 int
2108 zmsg_pushstrf (zmsg_t *self, const char *format, ...);
2109
2110 // Push formatted string as new frame to end of message.
2111 // Returns 0 on success, -1 on error.
2112 int
2113 zmsg_addstrf (zmsg_t *self, const char *format, ...);
2114
2115 // Pop frame off front of message, return as fresh string. If there were
2116 // no more frames in the message, returns NULL.
2117 char *
2118 zmsg_popstr (zmsg_t *self);
2119
2120 // Push encoded message as a new frame. Message takes ownership of
2121 // submessage, so the original is destroyed in this call. Returns 0 on
2122 // success, -1 on error.
2123 int
2124 zmsg_addmsg (zmsg_t *self, zmsg_t **msg_p);
2125
2126 // Remove first submessage from message, if any. Returns zmsg_t, or NULL if
2127 // decoding was not successful.
2128 zmsg_t *
2129 zmsg_popmsg (zmsg_t *self);
2130
2131 // Remove specified frame from list, if present. Does not destroy frame.
2132 void
2133 zmsg_remove (zmsg_t *self, zframe_t *frame);
2134
2135 // Set cursor to first frame in message. Returns frame, or NULL, if the
2136 // message is empty. Use this to navigate the frames as a list.
2137 zframe_t *
2138 zmsg_first (zmsg_t *self);
2139
2140 // Return the next frame. If there are no more frames, returns NULL. To move
2141 // to the first frame call zmsg_first(). Advances the cursor.
2142 zframe_t *
2143 zmsg_next (zmsg_t *self);
2144
2145 // Return the last frame. If there are no frames, returns NULL.
2146 zframe_t *
2147 zmsg_last (zmsg_t *self);
2148
2149 // Save message to an open file, return 0 if OK, else -1. The message is
2150 // saved as a series of frames, each with length and data. Note that the
2151 // file is NOT guaranteed to be portable between operating systems, not
2152 // versions of CZMQ. The file format is at present undocumented and liable
2153 // to arbitrary change.
2154 int
2155 zmsg_save (zmsg_t *self, FILE *file);
2156
2157 // Serialize multipart message to a single message frame. Use this method
2158 // to send structured messages across transports that do not support
2159 // multipart data. Allocates and returns a new frame containing the
2160 // serialized message. To decode a serialized message frame, use
2161 // zmsg_decode ().
2162 zframe_t *
2163 zmsg_encode (zmsg_t *self);
2164
2165 // Create copy of message, as new message object. Returns a fresh zmsg_t
2166 // object. If message is null, or memory was exhausted, returns null.
2167 zmsg_t *
2168 zmsg_dup (zmsg_t *self);
2169
2170 // Send message to zsys log sink (may be stdout, or system facility as
2171 // configured by zsys_set_logstream).
2172 void
2173 zmsg_print (zmsg_t *self);
2174
2175 // Return true if the two messages have the same number of frames and each
2176 // frame in the first message is identical to the corresponding frame in the
2177 // other message. As with zframe_eq, return false if either message is NULL.
2178 bool
2179 zmsg_eq (zmsg_t *self, zmsg_t *other);
2180
2181 // Return signal value, 0 or greater, if message is a signal, -1 if not.
2182 int
2183 zmsg_signal (zmsg_t *self);
2184
2185 // Probe the supplied object, and report if it looks like a zmsg_t.
2186 bool
2187 zmsg_is (void *self);
2188
2189 // Self test of this class.
2190 void
2191 zmsg_test (bool verbose);
2192
2193 // CLASS: zpoller
2194 // Create new poller, specifying zero or more readers. The list of
2195 // readers ends in a NULL. Each reader can be a zsock_t instance, a
2196 // zactor_t instance, a libzmq socket (void *), or a file handle.
2197 zpoller_t *
2198 zpoller_new (void *reader, ...);
2199
2200 // Destroy a poller
2201 void
2202 zpoller_destroy (zpoller_t **self_p);
2203
2204 // Add a reader to be polled. Returns 0 if OK, -1 on failure. The reader may
2205 // be a libzmq void * socket, a zsock_t instance, or a zactor_t instance.
2206 int
2207 zpoller_add (zpoller_t *self, void *reader);
2208
2209 // Remove a reader from the poller; returns 0 if OK, -1 on failure. The reader
2210 // must have been passed during construction, or in an zpoller_add () call.
2211 int
2212 zpoller_remove (zpoller_t *self, void *reader);
2213
2214 // By default the poller stops if the process receives a SIGINT or SIGTERM
2215 // signal. This makes it impossible to shut-down message based architectures
2216 // like zactors. This method lets you switch off break handling. The default
2217 // nonstop setting is off (false).
2218 void
2219 zpoller_set_nonstop (zpoller_t *self, bool nonstop);
2220
2221 // Poll the registered readers for I/O, return first reader that has input.
2222 // The reader will be a libzmq void * socket, or a zsock_t or zactor_t
2223 // instance as specified in zpoller_new/zpoller_add. The timeout should be
2224 // zero or greater, or -1 to wait indefinitely. Socket priority is defined
2225 // by their order in the poll list. If you need a balanced poll, use the low
2226 // level zmq_poll method directly. If the poll call was interrupted (SIGINT),
2227 // or the ZMQ context was destroyed, or the timeout expired, returns NULL.
2228 // You can test the actual exit condition by calling zpoller_expired () and
2229 // zpoller_terminated (). The timeout is in msec.
2230 void *
2231 zpoller_wait (zpoller_t *self, int timeout);
2232
2233 // Return true if the last zpoller_wait () call ended because the timeout
2234 // expired, without any error.
2235 bool
2236 zpoller_expired (zpoller_t *self);
2237
2238 // Return true if the last zpoller_wait () call ended because the process
2239 // was interrupted, or the parent context was destroyed.
2240 bool
2241 zpoller_terminated (zpoller_t *self);
2242
2243 // Self test of this class.
2244 void
2245 zpoller_test (bool verbose);
2246
2247 // CLASS: zproc
2248 // Create a new zproc.
2249 // NOTE: On Windows and with libzmq3 and libzmq2 this function
2250 // returns NULL. Code needs to be ported there.
2251 zproc_t *
2252 zproc_new (void);
2253
2254 // Destroy zproc, wait until process ends.
2255 void
2256 zproc_destroy (zproc_t **self_p);
2257
2258 // Setup the command line arguments, the first item must be an (absolute) filename
2259 // to run.
2260 void
2261 zproc_set_args (zproc_t *self, zlistx_t *args);
2262
2263 // Setup the environment variables for the process.
2264 void
2265 zproc_set_env (zproc_t *self, zhashx_t *args);
2266
2267 // Connects process stdin with a readable ('>', connect) zeromq socket. If
2268 // socket argument is NULL, zproc creates own managed pair of inproc
2269 // sockets. The writable one is then accessbile via zproc_stdin method.
2270 void
2271 zproc_set_stdin (zproc_t *self, void *socket);
2272
2273 // Connects process stdout with a writable ('@', bind) zeromq socket. If
2274 // socket argument is NULL, zproc creates own managed pair of inproc
2275 // sockets. The readable one is then accessbile via zproc_stdout method.
2276 void
2277 zproc_set_stdout (zproc_t *self, void *socket);
2278
2279 // Connects process stderr with a writable ('@', bind) zeromq socket. If
2280 // socket argument is NULL, zproc creates own managed pair of inproc
2281 // sockets. The readable one is then accessbile via zproc_stderr method.
2282 void
2283 zproc_set_stderr (zproc_t *self, void *socket);
2284
2285 // Return subprocess stdin writable socket. NULL for
2286 // not initialized or external sockets.
2287 void *
2288 zproc_stdin (zproc_t *self);
2289
2290 // Return subprocess stdout readable socket. NULL for
2291 // not initialized or external sockets.
2292 void *
2293 zproc_stdout (zproc_t *self);
2294
2295 // Return subprocess stderr readable socket. NULL for
2296 // not initialized or external sockets.
2297 void *
2298 zproc_stderr (zproc_t *self);
2299
2300 // Starts the process.
2301 int
2302 zproc_run (zproc_t *self);
2303
2304 // process exit code
2305 int
2306 zproc_returncode (zproc_t *self);
2307
2308 // PID of the process
2309 int
2310 zproc_pid (zproc_t *self);
2311
2312 // return true if process is running, false if not yet started or finished
2313 bool
2314 zproc_running (zproc_t *self);
2315
2316 // wait or poll process status, return return code
2317 int
2318 zproc_wait (zproc_t *self, bool hang);
2319
2320 // return internal actor, usefull for the polling if process died
2321 void *
2322 zproc_actor (zproc_t *self);
2323
2324 // send a signal to the subprocess
2325 void
2326 zproc_kill (zproc_t *self, int signal);
2327
2328 // set verbose mode
2329 void
2330 zproc_set_verbose (zproc_t *self, bool verbose);
2331
2332 // Returns CZMQ version as a single 6-digit integer encoding the major
2333 // version (x 10000), the minor version (x 100) and the patch.
2334 int
2335 zproc_czmq_version (void);
2336
2337 // Returns true if the process received a SIGINT or SIGTERM signal.
2338 // It is good practice to use this method to exit any infinite loop
2339 // processing messages.
2340 bool
2341 zproc_interrupted (void);
2342
2343 // Returns true if the underlying libzmq supports CURVE security.
2344 bool
2345 zproc_has_curve (void);
2346
2347 // Return current host name, for use in public tcp:// endpoints.
2348 // If the host name is not resolvable, returns NULL.
2349 char *
2350 zproc_hostname (void);
2351
2352 // Move the current process into the background. The precise effect
2353 // depends on the operating system. On POSIX boxes, moves to a specified
2354 // working directory (if specified), closes all file handles, reopens
2355 // stdin, stdout, and stderr to the null device, and sets the process to
2356 // ignore SIGHUP. On Windows, does nothing. Returns 0 if OK, -1 if there
2357 // was an error.
2358 void
2359 zproc_daemonize (const char *workdir);
2360
2361 // Drop the process ID into the lockfile, with exclusive lock, and
2362 // switch the process to the specified group and/or user. Any of the
2363 // arguments may be null, indicating a no-op. Returns 0 on success,
2364 // -1 on failure. Note if you combine this with zsys_daemonize, run
2365 // after, not before that method, or the lockfile will hold the wrong
2366 // process ID.
2367 void
2368 zproc_run_as (const char *lockfile, const char *group, const char *user);
2369
2370 // Configure the number of I/O threads that ZeroMQ will use. A good
2371 // rule of thumb is one thread per gigabit of traffic in or out. The
2372 // default is 1, sufficient for most applications. If the environment
2373 // variable ZSYS_IO_THREADS is defined, that provides the default.
2374 // Note that this method is valid only before any socket is created.
2375 void
2376 zproc_set_io_threads (size_t io_threads);
2377
2378 // Configure the number of sockets that ZeroMQ will allow. The default
2379 // is 1024. The actual limit depends on the system, and you can query it
2380 // by using zsys_socket_limit (). A value of zero means "maximum".
2381 // Note that this method is valid only before any socket is created.
2382 void
2383 zproc_set_max_sockets (size_t max_sockets);
2384
2385 // Set network interface name to use for broadcasts, particularly zbeacon.
2386 // This lets the interface be configured for test environments where required.
2387 // For example, on Mac OS X, zbeacon cannot bind to 255.255.255.255 which is
2388 // the default when there is no specified interface. If the environment
2389 // variable ZSYS_INTERFACE is set, use that as the default interface name.
2390 // Setting the interface to "*" means "use all available interfaces".
2391 void
2392 zproc_set_biface (const char *value);
2393
2394 // Return network interface to use for broadcasts, or "" if none was set.
2395 const char *
2396 zproc_biface (void);
2397
2398 // Set log identity, which is a string that prefixes all log messages sent
2399 // by this process. The log identity defaults to the environment variable
2400 // ZSYS_LOGIDENT, if that is set.
2401 void
2402 zproc_set_log_ident (const char *value);
2403
2404 // Sends log output to a PUB socket bound to the specified endpoint. To
2405 // collect such log output, create a SUB socket, subscribe to the traffic
2406 // you care about, and connect to the endpoint. Log traffic is sent as a
2407 // single string frame, in the same format as when sent to stdout. The
2408 // log system supports a single sender; multiple calls to this method will
2409 // bind the same sender to multiple endpoints. To disable the sender, call
2410 // this method with a null argument.
2411 void
2412 zproc_set_log_sender (const char *endpoint);
2413
2414 // Enable or disable logging to the system facility (syslog on POSIX boxes,
2415 // event log on Windows). By default this is disabled.
2416 void
2417 zproc_set_log_system (bool logsystem);
2418
2419 // Log error condition - highest priority
2420 void
2421 zproc_log_error (const char *format, ...);
2422
2423 // Log warning condition - high priority
2424 void
2425 zproc_log_warning (const char *format, ...);
2426
2427 // Log normal, but significant, condition - normal priority
2428 void
2429 zproc_log_notice (const char *format, ...);
2430
2431 // Log informational message - low priority
2432 void
2433 zproc_log_info (const char *format, ...);
2434
2435 // Log debug-level message - lowest priority
2436 void
2437 zproc_log_debug (const char *format, ...);
2438
2439 // Self test of this class.
2440 void
2441 zproc_test (bool verbose);
2442
2443 // CLASS: zsock
2444 // Create a new socket. Returns the new socket, or NULL if the new socket
2445 // could not be created. Note that the symbol zsock_new (and other
2446 // constructors/destructors for zsock) are redirected to the *_checked
2447 // variant, enabling intelligent socket leak detection. This can have
2448 // performance implications if you use a LOT of sockets. To turn off this
2449 // redirection behaviour, define ZSOCK_NOCHECK.
2450 zsock_t *
2451 zsock_new (int type);
2452
2453 // Destroy the socket. You must use this for any socket created via the
2454 // zsock_new method.
2455 void
2456 zsock_destroy (zsock_t **self_p);
2457
2458 // Create a PUB socket. Default action is bind.
2459 zsock_t *
2460 zsock_new_pub (const char *endpoint);
2461
2462 // Create a SUB socket, and optionally subscribe to some prefix string. Default
2463 // action is connect.
2464 zsock_t *
2465 zsock_new_sub (const char *endpoint, const char *subscribe);
2466
2467 // Create a REQ socket. Default action is connect.
2468 zsock_t *
2469 zsock_new_req (const char *endpoint);
2470
2471 // Create a REP socket. Default action is bind.
2472 zsock_t *
2473 zsock_new_rep (const char *endpoint);
2474
2475 // Create a DEALER socket. Default action is connect.
2476 zsock_t *
2477 zsock_new_dealer (const char *endpoint);
2478
2479 // Create a ROUTER socket. Default action is bind.
2480 zsock_t *
2481 zsock_new_router (const char *endpoint);
2482
2483 // Create a PUSH socket. Default action is connect.
2484 zsock_t *
2485 zsock_new_push (const char *endpoint);
2486
2487 // Create a PULL socket. Default action is bind.
2488 zsock_t *
2489 zsock_new_pull (const char *endpoint);
2490
2491 // Create an XPUB socket. Default action is bind.
2492 zsock_t *
2493 zsock_new_xpub (const char *endpoint);
2494
2495 // Create an XSUB socket. Default action is connect.
2496 zsock_t *
2497 zsock_new_xsub (const char *endpoint);
2498
2499 // Create a PAIR socket. Default action is connect.
2500 zsock_t *
2501 zsock_new_pair (const char *endpoint);
2502
2503 // Create a STREAM socket. Default action is connect.
2504 zsock_t *
2505 zsock_new_stream (const char *endpoint);
2506
2507 // Create a SERVER socket. Default action is bind.
2508 zsock_t *
2509 zsock_new_server (const char *endpoint);
2510
2511 // Create a CLIENT socket. Default action is connect.
2512 zsock_t *
2513 zsock_new_client (const char *endpoint);
2514
2515 // Create a RADIO socket. Default action is bind.
2516 zsock_t *
2517 zsock_new_radio (const char *endpoint);
2518
2519 // Create a DISH socket. Default action is connect.
2520 zsock_t *
2521 zsock_new_dish (const char *endpoint);
2522
2523 // Create a GATHER socket. Default action is bind.
2524 zsock_t *
2525 zsock_new_gather (const char *endpoint);
2526
2527 // Create a SCATTER socket. Default action is connect.
2528 zsock_t *
2529 zsock_new_scatter (const char *endpoint);
2530
2531 // Bind a socket to a formatted endpoint. For tcp:// endpoints, supports
2532 // ephemeral ports, if you specify the port number as "*". By default
2533 // zsock uses the IANA designated range from C000 (49152) to FFFF (65535).
2534 // To override this range, follow the "*" with "[first-last]". Either or
2535 // both first and last may be empty. To bind to a random port within the
2536 // range, use "!" in place of "*".
2537 //
2538 // Examples:
2539 // tcp://127.0.0.1:* bind to first free port from C000 up
2540 // tcp://127.0.0.1:! bind to random port from C000 to FFFF
2541 // tcp://127.0.0.1:*[60000-] bind to first free port from 60000 up
2542 // tcp://127.0.0.1:![-60000] bind to random port from C000 to 60000
2543 // tcp://127.0.0.1:![55000-55999]
2544 // bind to random port from 55000 to 55999
2545 //
2546 // On success, returns the actual port number used, for tcp:// endpoints,
2547 // and 0 for other transports. On failure, returns -1. Note that when using
2548 // ephemeral ports, a port may be reused by different services without
2549 // clients being aware. Protocols that run on ephemeral ports should take
2550 // this into account.
2551 int
2552 zsock_bind (zsock_t *self, const char *format, ...);
2553
2554 // Returns last bound endpoint, if any.
2555 const char *
2556 zsock_endpoint (zsock_t *self);
2557
2558 // Unbind a socket from a formatted endpoint.
2559 // Returns 0 if OK, -1 if the endpoint was invalid or the function
2560 // isn't supported.
2561 int
2562 zsock_unbind (zsock_t *self, const char *format, ...);
2563
2564 // Connect a socket to a formatted endpoint
2565 // Returns 0 if OK, -1 if the endpoint was invalid.
2566 int
2567 zsock_connect (zsock_t *self, const char *format, ...);
2568
2569 // Disconnect a socket from a formatted endpoint
2570 // Returns 0 if OK, -1 if the endpoint was invalid or the function
2571 // isn't supported.
2572 int
2573 zsock_disconnect (zsock_t *self, const char *format, ...);
2574
2575 // Attach a socket to zero or more endpoints. If endpoints is not null,
2576 // parses as list of ZeroMQ endpoints, separated by commas, and prefixed by
2577 // '@' (to bind the socket) or '>' (to connect the socket). Returns 0 if all
2578 // endpoints were valid, or -1 if there was a syntax error. If the endpoint
2579 // does not start with '@' or '>', the serverish argument defines whether
2580 // it is used to bind (serverish = true) or connect (serverish = false).
2581 int
2582 zsock_attach (zsock_t *self, const char *endpoints, bool serverish);
2583
2584 // Returns socket type as printable constant string.
2585 const char *
2586 zsock_type_str (zsock_t *self);
2587
2588 // Send a 'picture' message to the socket (or actor). The picture is a
2589 // string that defines the type of each frame. This makes it easy to send
2590 // a complex multiframe message in one call. The picture can contain any
2591 // of these characters, each corresponding to one or two arguments:
2592 //
2593 // i = int (signed)
2594 // 1 = uint8_t
2595 // 2 = uint16_t
2596 // 4 = uint32_t
2597 // 8 = uint64_t
2598 // s = char *
2599 // b = byte *, size_t (2 arguments)
2600 // c = zchunk_t *
2601 // f = zframe_t *
2602 // h = zhashx_t *
2603 // U = zuuid_t *
2604 // p = void * (sends the pointer value, only meaningful over inproc)
2605 // m = zmsg_t * (sends all frames in the zmsg)
2606 // z = sends zero-sized frame (0 arguments)
2607 // u = uint (deprecated)
2608 //
2609 // Note that s, b, c, and f are encoded the same way and the choice is
2610 // offered as a convenience to the sender, which may or may not already
2611 // have data in a zchunk or zframe. Does not change or take ownership of
2612 // any arguments. Returns 0 if successful, -1 if sending failed for any
2613 // reason.
2614 int
2615 zsock_send (void *self, const char *picture, ...);
2616
2617 // Send a 'picture' message to the socket (or actor). This is a va_list
2618 // version of zsock_send (), so please consult its documentation for the
2619 // details.
2620 int
2621 zsock_vsend (void *self, const char *picture, va_list argptr);
2622
2623 // Receive a 'picture' message to the socket (or actor). See zsock_send for
2624 // the format and meaning of the picture. Returns the picture elements into
2625 // a series of pointers as provided by the caller:
2626 //
2627 // i = int * (stores signed integer)
2628 // 4 = uint32_t * (stores 32-bit unsigned integer)
2629 // 8 = uint64_t * (stores 64-bit unsigned integer)
2630 // s = char ** (allocates new string)
2631 // b = byte **, size_t * (2 arguments) (allocates memory)
2632 // c = zchunk_t ** (creates zchunk)
2633 // f = zframe_t ** (creates zframe)
2634 // U = zuuid_t * (creates a zuuid with the data)
2635 // h = zhashx_t ** (creates zhashx)
2636 // p = void ** (stores pointer)
2637 // m = zmsg_t ** (creates a zmsg with the remaing frames)
2638 // z = null, asserts empty frame (0 arguments)
2639 // u = uint * (stores unsigned integer, deprecated)
2640 //
2641 // Note that zsock_recv creates the returned objects, and the caller must
2642 // destroy them when finished with them. The supplied pointers do not need
2643 // to be initialized. Returns 0 if successful, or -1 if it failed to recv
2644 // a message, in which case the pointers are not modified. When message
2645 // frames are truncated (a short message), sets return values to zero/null.
2646 // If an argument pointer is NULL, does not store any value (skips it).
2647 // An 'n' picture matches an empty frame; if the message does not match,
2648 // the method will return -1.
2649 int
2650 zsock_recv (void *self, const char *picture, ...);
2651
2652 // Receive a 'picture' message from the socket (or actor). This is a
2653 // va_list version of zsock_recv (), so please consult its documentation
2654 // for the details.
2655 int
2656 zsock_vrecv (void *self, const char *picture, va_list argptr);
2657
2658 // Send a binary encoded 'picture' message to the socket (or actor). This
2659 // method is similar to zsock_send, except the arguments are encoded in a
2660 // binary format that is compatible with zproto, and is designed to reduce
2661 // memory allocations. The pattern argument is a string that defines the
2662 // type of each argument. Supports these argument types:
2663 //
2664 // pattern C type zproto type:
2665 // 1 uint8_t type = "number" size = "1"
2666 // 2 uint16_t type = "number" size = "2"
2667 // 4 uint32_t type = "number" size = "3"
2668 // 8 uint64_t type = "number" size = "4"
2669 // s char *, 0-255 chars type = "string"
2670 // S char *, 0-2^32-1 chars type = "longstr"
2671 // c zchunk_t * type = "chunk"
2672 // f zframe_t * type = "frame"
2673 // u zuuid_t * type = "uuid"
2674 // m zmsg_t * type = "msg"
2675 // p void *, sends pointer value, only over inproc
2676 //
2677 // Does not change or take ownership of any arguments. Returns 0 if
2678 // successful, -1 if sending failed for any reason.
2679 int
2680 zsock_bsend (void *self, const char *picture, ...);
2681
2682 // Receive a binary encoded 'picture' message from the socket (or actor).
2683 // This method is similar to zsock_recv, except the arguments are encoded
2684 // in a binary format that is compatible with zproto, and is designed to
2685 // reduce memory allocations. The pattern argument is a string that defines
2686 // the type of each argument. See zsock_bsend for the supported argument
2687 // types. All arguments must be pointers; this call sets them to point to
2688 // values held on a per-socket basis.
2689 // For types 1, 2, 4 and 8 the caller must allocate the memory itself before
2690 // calling zsock_brecv.
2691 // For types S, the caller must free the value once finished with it, as
2692 // zsock_brecv will allocate the buffer.
2693 // For type s, the caller must not free the value as it is stored in a
2694 // local cache for performance purposes.
2695 // For types c, f, u and m the caller must call the appropriate destructor
2696 // depending on the object as zsock_brecv will create new objects.
2697 // For type p the caller must coordinate with the sender, as it is just a
2698 // pointer value being passed.
2699 int
2700 zsock_brecv (void *self, const char *picture, ...);
2701
2702 // Return socket routing ID if any. This returns 0 if the socket is not
2703 // of type ZMQ_SERVER or if no request was already received on it.
2704 uint32_t
2705 zsock_routing_id (zsock_t *self);
2706
2707 // Set routing ID on socket. The socket MUST be of type ZMQ_SERVER.
2708 // This will be used when sending messages on the socket via the zsock API.
2709 void
2710 zsock_set_routing_id (zsock_t *self, uint32_t routing_id);
2711
2712 // Set socket to use unbounded pipes (HWM=0); use this in cases when you are
2713 // totally certain the message volume can fit in memory. This method works
2714 // across all versions of ZeroMQ. Takes a polymorphic socket reference.
2715 void
2716 zsock_set_unbounded (void *self);
2717
2718 // Send a signal over a socket. A signal is a short message carrying a
2719 // success/failure code (by convention, 0 means OK). Signals are encoded
2720 // to be distinguishable from "normal" messages. Accepts a zsock_t or a
2721 // zactor_t argument, and returns 0 if successful, -1 if the signal could
2722 // not be sent. Takes a polymorphic socket reference.
2723 int
2724 zsock_signal (void *self, byte status);
2725
2726 // Wait on a signal. Use this to coordinate between threads, over pipe
2727 // pairs. Blocks until the signal is received. Returns -1 on error, 0 or
2728 // greater on success. Accepts a zsock_t or a zactor_t as argument.
2729 // Takes a polymorphic socket reference.
2730 int
2731 zsock_wait (void *self);
2732
2733 // If there is a partial message still waiting on the socket, remove and
2734 // discard it. This is useful when reading partial messages, to get specific
2735 // message types.
2736 void
2737 zsock_flush (void *self);
2738
2739 // Join a group for the RADIO-DISH pattern. Call only on ZMQ_DISH.
2740 // Returns 0 if OK, -1 if failed.
2741 int
2742 zsock_join (void *self, const char *group);
2743
2744 // Leave a group for the RADIO-DISH pattern. Call only on ZMQ_DISH.
2745 // Returns 0 if OK, -1 if failed.
2746 int
2747 zsock_leave (void *self, const char *group);
2748
2749 // Probe the supplied object, and report if it looks like a zsock_t.
2750 // Takes a polymorphic socket reference.
2751 bool
2752 zsock_is (void *self);
2753
2754 // Probe the supplied reference. If it looks like a zsock_t instance, return
2755 // the underlying libzmq socket handle; else if it looks like a file
2756 // descriptor, return NULL; else if it looks like a libzmq socket handle,
2757 // return the supplied value. Takes a polymorphic socket reference.
2758 void *
2759 zsock_resolve (void *self);
2760
2761 // Get socket option `heartbeat_ivl`.
2762 // Available from libzmq 4.2.0.
2763 int
2764 zsock_heartbeat_ivl (void *self);
2765
2766 // Set socket option `heartbeat_ivl`.
2767 // Available from libzmq 4.2.0.
2768 void
2769 zsock_set_heartbeat_ivl (void *self, int heartbeat_ivl);
2770
2771 // Get socket option `heartbeat_ttl`.
2772 // Available from libzmq 4.2.0.
2773 int
2774 zsock_heartbeat_ttl (void *self);
2775
2776 // Set socket option `heartbeat_ttl`.
2777 // Available from libzmq 4.2.0.
2778 void
2779 zsock_set_heartbeat_ttl (void *self, int heartbeat_ttl);
2780
2781 // Get socket option `heartbeat_timeout`.
2782 // Available from libzmq 4.2.0.
2783 int
2784 zsock_heartbeat_timeout (void *self);
2785
2786 // Set socket option `heartbeat_timeout`.
2787 // Available from libzmq 4.2.0.
2788 void
2789 zsock_set_heartbeat_timeout (void *self, int heartbeat_timeout);
2790
2791 // Get socket option `use_fd`.
2792 // Available from libzmq 4.2.0.
2793 int
2794 zsock_use_fd (void *self);
2795
2796 // Set socket option `use_fd`.
2797 // Available from libzmq 4.2.0.
2798 void
2799 zsock_set_use_fd (void *self, int use_fd);
2800
2801 // Set socket option `xpub_manual`.
2802 // Available from libzmq 4.2.0.
2803 void
2804 zsock_set_xpub_manual (void *self, int xpub_manual);
2805
2806 // Set socket option `xpub_welcome_msg`.
2807 // Available from libzmq 4.2.0.
2808 void
2809 zsock_set_xpub_welcome_msg (void *self, const char *xpub_welcome_msg);
2810
2811 // Set socket option `stream_notify`.
2812 // Available from libzmq 4.2.0.
2813 void
2814 zsock_set_stream_notify (void *self, int stream_notify);
2815
2816 // Get socket option `invert_matching`.
2817 // Available from libzmq 4.2.0.
2818 int
2819 zsock_invert_matching (void *self);
2820
2821 // Set socket option `invert_matching`.
2822 // Available from libzmq 4.2.0.
2823 void
2824 zsock_set_invert_matching (void *self, int invert_matching);
2825
2826 // Set socket option `xpub_verboser`.
2827 // Available from libzmq 4.2.0.
2828 void
2829 zsock_set_xpub_verboser (void *self, int xpub_verboser);
2830
2831 // Get socket option `connect_timeout`.
2832 // Available from libzmq 4.2.0.
2833 int
2834 zsock_connect_timeout (void *self);
2835
2836 // Set socket option `connect_timeout`.
2837 // Available from libzmq 4.2.0.
2838 void
2839 zsock_set_connect_timeout (void *self, int connect_timeout);
2840
2841 // Get socket option `tcp_maxrt`.
2842 // Available from libzmq 4.2.0.
2843 int
2844 zsock_tcp_maxrt (void *self);
2845
2846 // Set socket option `tcp_maxrt`.
2847 // Available from libzmq 4.2.0.
2848 void
2849 zsock_set_tcp_maxrt (void *self, int tcp_maxrt);
2850
2851 // Get socket option `thread_safe`.
2852 // Available from libzmq 4.2.0.
2853 int
2854 zsock_thread_safe (void *self);
2855
2856 // Get socket option `multicast_maxtpdu`.
2857 // Available from libzmq 4.2.0.
2858 int
2859 zsock_multicast_maxtpdu (void *self);
2860
2861 // Set socket option `multicast_maxtpdu`.
2862 // Available from libzmq 4.2.0.
2863 void
2864 zsock_set_multicast_maxtpdu (void *self, int multicast_maxtpdu);
2865
2866 // Get socket option `vmci_buffer_size`.
2867 // Available from libzmq 4.2.0.
2868 int
2869 zsock_vmci_buffer_size (void *self);
2870
2871 // Set socket option `vmci_buffer_size`.
2872 // Available from libzmq 4.2.0.
2873 void
2874 zsock_set_vmci_buffer_size (void *self, int vmci_buffer_size);
2875
2876 // Get socket option `vmci_buffer_min_size`.
2877 // Available from libzmq 4.2.0.
2878 int
2879 zsock_vmci_buffer_min_size (void *self);
2880
2881 // Set socket option `vmci_buffer_min_size`.
2882 // Available from libzmq 4.2.0.
2883 void
2884 zsock_set_vmci_buffer_min_size (void *self, int vmci_buffer_min_size);
2885
2886 // Get socket option `vmci_buffer_max_size`.
2887 // Available from libzmq 4.2.0.
2888 int
2889 zsock_vmci_buffer_max_size (void *self);
2890
2891 // Set socket option `vmci_buffer_max_size`.
2892 // Available from libzmq 4.2.0.
2893 void
2894 zsock_set_vmci_buffer_max_size (void *self, int vmci_buffer_max_size);
2895
2896 // Get socket option `vmci_connect_timeout`.
2897 // Available from libzmq 4.2.0.
2898 int
2899 zsock_vmci_connect_timeout (void *self);
2900
2901 // Set socket option `vmci_connect_timeout`.
2902 // Available from libzmq 4.2.0.
2903 void
2904 zsock_set_vmci_connect_timeout (void *self, int vmci_connect_timeout);
2905
2906 // Get socket option `tos`.
2907 // Available from libzmq 4.1.0.
2908 int
2909 zsock_tos (void *self);
2910
2911 // Set socket option `tos`.
2912 // Available from libzmq 4.1.0.
2913 void
2914 zsock_set_tos (void *self, int tos);
2915
2916 // Set socket option `router_handover`.
2917 // Available from libzmq 4.1.0.
2918 void
2919 zsock_set_router_handover (void *self, int router_handover);
2920
2921 // Set socket option `connect_rid`.
2922 // Available from libzmq 4.1.0.
2923 void
2924 zsock_set_connect_rid (void *self, const char *connect_rid);
2925
2926 // Set socket option `connect_rid` from 32-octet binary
2927 // Available from libzmq 4.1.0.
2928 void
2929 zsock_set_connect_rid_bin (void *self, const byte *connect_rid);
2930
2931 // Get socket option `handshake_ivl`.
2932 // Available from libzmq 4.1.0.
2933 int
2934 zsock_handshake_ivl (void *self);
2935
2936 // Set socket option `handshake_ivl`.
2937 // Available from libzmq 4.1.0.
2938 void
2939 zsock_set_handshake_ivl (void *self, int handshake_ivl);
2940
2941 // Get socket option `socks_proxy`.
2942 // Available from libzmq 4.1.0.
2943 char *
2944 zsock_socks_proxy (void *self);
2945
2946 // Set socket option `socks_proxy`.
2947 // Available from libzmq 4.1.0.
2948 void
2949 zsock_set_socks_proxy (void *self, const char *socks_proxy);
2950
2951 // Set socket option `xpub_nodrop`.
2952 // Available from libzmq 4.1.0.
2953 void
2954 zsock_set_xpub_nodrop (void *self, int xpub_nodrop);
2955
2956 // Set socket option `router_mandatory`.
2957 // Available from libzmq 4.0.0.
2958 void
2959 zsock_set_router_mandatory (void *self, int router_mandatory);
2960
2961 // Set socket option `probe_router`.
2962 // Available from libzmq 4.0.0.
2963 void
2964 zsock_set_probe_router (void *self, int probe_router);
2965
2966 // Set socket option `req_relaxed`.
2967 // Available from libzmq 4.0.0.
2968 void
2969 zsock_set_req_relaxed (void *self, int req_relaxed);
2970
2971 // Set socket option `req_correlate`.
2972 // Available from libzmq 4.0.0.
2973 void
2974 zsock_set_req_correlate (void *self, int req_correlate);
2975
2976 // Set socket option `conflate`.
2977 // Available from libzmq 4.0.0.
2978 void
2979 zsock_set_conflate (void *self, int conflate);
2980
2981 // Get socket option `zap_domain`.
2982 // Available from libzmq 4.0.0.
2983 char *
2984 zsock_zap_domain (void *self);
2985
2986 // Set socket option `zap_domain`.
2987 // Available from libzmq 4.0.0.
2988 void
2989 zsock_set_zap_domain (void *self, const char *zap_domain);
2990
2991 // Get socket option `mechanism`.
2992 // Available from libzmq 4.0.0.
2993 int
2994 zsock_mechanism (void *self);
2995
2996 // Get socket option `plain_server`.
2997 // Available from libzmq 4.0.0.
2998 int
2999 zsock_plain_server (void *self);
3000
3001 // Set socket option `plain_server`.
3002 // Available from libzmq 4.0.0.
3003 void
3004 zsock_set_plain_server (void *self, int plain_server);
3005
3006 // Get socket option `plain_username`.
3007 // Available from libzmq 4.0.0.
3008 char *
3009 zsock_plain_username (void *self);
3010
3011 // Set socket option `plain_username`.
3012 // Available from libzmq 4.0.0.
3013 void
3014 zsock_set_plain_username (void *self, const char *plain_username);
3015
3016 // Get socket option `plain_password`.
3017 // Available from libzmq 4.0.0.
3018 char *
3019 zsock_plain_password (void *self);
3020
3021 // Set socket option `plain_password`.
3022 // Available from libzmq 4.0.0.
3023 void
3024 zsock_set_plain_password (void *self, const char *plain_password);
3025
3026 // Get socket option `curve_server`.
3027 // Available from libzmq 4.0.0.
3028 int
3029 zsock_curve_server (void *self);
3030
3031 // Set socket option `curve_server`.
3032 // Available from libzmq 4.0.0.
3033 void
3034 zsock_set_curve_server (void *self, int curve_server);
3035
3036 // Get socket option `curve_publickey`.
3037 // Available from libzmq 4.0.0.
3038 char *
3039 zsock_curve_publickey (void *self);
3040
3041 // Set socket option `curve_publickey`.
3042 // Available from libzmq 4.0.0.
3043 void
3044 zsock_set_curve_publickey (void *self, const char *curve_publickey);
3045
3046 // Set socket option `curve_publickey` from 32-octet binary
3047 // Available from libzmq 4.0.0.
3048 void
3049 zsock_set_curve_publickey_bin (void *self, const byte *curve_publickey);
3050
3051 // Get socket option `curve_secretkey`.
3052 // Available from libzmq 4.0.0.
3053 char *
3054 zsock_curve_secretkey (void *self);
3055
3056 // Set socket option `curve_secretkey`.
3057 // Available from libzmq 4.0.0.
3058 void
3059 zsock_set_curve_secretkey (void *self, const char *curve_secretkey);
3060
3061 // Set socket option `curve_secretkey` from 32-octet binary
3062 // Available from libzmq 4.0.0.
3063 void
3064 zsock_set_curve_secretkey_bin (void *self, const byte *curve_secretkey);
3065
3066 // Get socket option `curve_serverkey`.
3067 // Available from libzmq 4.0.0.
3068 char *
3069 zsock_curve_serverkey (void *self);
3070
3071 // Set socket option `curve_serverkey`.
3072 // Available from libzmq 4.0.0.
3073 void
3074 zsock_set_curve_serverkey (void *self, const char *curve_serverkey);
3075
3076 // Set socket option `curve_serverkey` from 32-octet binary
3077 // Available from libzmq 4.0.0.
3078 void
3079 zsock_set_curve_serverkey_bin (void *self, const byte *curve_serverkey);
3080
3081 // Get socket option `gssapi_server`.
3082 // Available from libzmq 4.0.0.
3083 int
3084 zsock_gssapi_server (void *self);
3085
3086 // Set socket option `gssapi_server`.
3087 // Available from libzmq 4.0.0.
3088 void
3089 zsock_set_gssapi_server (void *self, int gssapi_server);
3090
3091 // Get socket option `gssapi_plaintext`.
3092 // Available from libzmq 4.0.0.
3093 int
3094 zsock_gssapi_plaintext (void *self);
3095
3096 // Set socket option `gssapi_plaintext`.
3097 // Available from libzmq 4.0.0.
3098 void
3099 zsock_set_gssapi_plaintext (void *self, int gssapi_plaintext);
3100
3101 // Get socket option `gssapi_principal`.
3102 // Available from libzmq 4.0.0.
3103 char *
3104 zsock_gssapi_principal (void *self);
3105
3106 // Set socket option `gssapi_principal`.
3107 // Available from libzmq 4.0.0.
3108 void
3109 zsock_set_gssapi_principal (void *self, const char *gssapi_principal);
3110
3111 // Get socket option `gssapi_service_principal`.
3112 // Available from libzmq 4.0.0.
3113 char *
3114 zsock_gssapi_service_principal (void *self);
3115
3116 // Set socket option `gssapi_service_principal`.
3117 // Available from libzmq 4.0.0.
3118 void
3119 zsock_set_gssapi_service_principal (void *self, const char *gssapi_service_principal);
3120
3121 // Get socket option `ipv6`.
3122 // Available from libzmq 4.0.0.
3123 int
3124 zsock_ipv6 (void *self);
3125
3126 // Set socket option `ipv6`.
3127 // Available from libzmq 4.0.0.
3128 void
3129 zsock_set_ipv6 (void *self, int ipv6);
3130
3131 // Get socket option `immediate`.
3132 // Available from libzmq 4.0.0.
3133 int
3134 zsock_immediate (void *self);
3135
3136 // Set socket option `immediate`.
3137 // Available from libzmq 4.0.0.
3138 void
3139 zsock_set_immediate (void *self, int immediate);
3140
3141 // Get socket option `sndhwm`.
3142 // Available from libzmq 3.0.0.
3143 int
3144 zsock_sndhwm (void *self);
3145
3146 // Set socket option `sndhwm`.
3147 // Available from libzmq 3.0.0.
3148 void
3149 zsock_set_sndhwm (void *self, int sndhwm);
3150
3151 // Get socket option `rcvhwm`.
3152 // Available from libzmq 3.0.0.
3153 int
3154 zsock_rcvhwm (void *self);
3155
3156 // Set socket option `rcvhwm`.
3157 // Available from libzmq 3.0.0.
3158 void
3159 zsock_set_rcvhwm (void *self, int rcvhwm);
3160
3161 // Get socket option `maxmsgsize`.
3162 // Available from libzmq 3.0.0.
3163 int
3164 zsock_maxmsgsize (void *self);
3165
3166 // Set socket option `maxmsgsize`.
3167 // Available from libzmq 3.0.0.
3168 void
3169 zsock_set_maxmsgsize (void *self, int maxmsgsize);
3170
3171 // Get socket option `multicast_hops`.
3172 // Available from libzmq 3.0.0.
3173 int
3174 zsock_multicast_hops (void *self);
3175
3176 // Set socket option `multicast_hops`.
3177 // Available from libzmq 3.0.0.
3178 void
3179 zsock_set_multicast_hops (void *self, int multicast_hops);
3180
3181 // Set socket option `xpub_verbose`.
3182 // Available from libzmq 3.0.0.
3183 void
3184 zsock_set_xpub_verbose (void *self, int xpub_verbose);
3185
3186 // Get socket option `tcp_keepalive`.
3187 // Available from libzmq 3.0.0.
3188 int
3189 zsock_tcp_keepalive (void *self);
3190
3191 // Set socket option `tcp_keepalive`.
3192 // Available from libzmq 3.0.0.
3193 void
3194 zsock_set_tcp_keepalive (void *self, int tcp_keepalive);
3195
3196 // Get socket option `tcp_keepalive_idle`.
3197 // Available from libzmq 3.0.0.
3198 int
3199 zsock_tcp_keepalive_idle (void *self);
3200
3201 // Set socket option `tcp_keepalive_idle`.
3202 // Available from libzmq 3.0.0.
3203 void
3204 zsock_set_tcp_keepalive_idle (void *self, int tcp_keepalive_idle);
3205
3206 // Get socket option `tcp_keepalive_cnt`.
3207 // Available from libzmq 3.0.0.
3208 int
3209 zsock_tcp_keepalive_cnt (void *self);
3210
3211 // Set socket option `tcp_keepalive_cnt`.
3212 // Available from libzmq 3.0.0.
3213 void
3214 zsock_set_tcp_keepalive_cnt (void *self, int tcp_keepalive_cnt);
3215
3216 // Get socket option `tcp_keepalive_intvl`.
3217 // Available from libzmq 3.0.0.
3218 int
3219 zsock_tcp_keepalive_intvl (void *self);
3220
3221 // Set socket option `tcp_keepalive_intvl`.
3222 // Available from libzmq 3.0.0.
3223 void
3224 zsock_set_tcp_keepalive_intvl (void *self, int tcp_keepalive_intvl);
3225
3226 // Get socket option `tcp_accept_filter`.
3227 // Available from libzmq 3.0.0.
3228 char *
3229 zsock_tcp_accept_filter (void *self);
3230
3231 // Set socket option `tcp_accept_filter`.
3232 // Available from libzmq 3.0.0.
3233 void
3234 zsock_set_tcp_accept_filter (void *self, const char *tcp_accept_filter);
3235
3236 // Get socket option `last_endpoint`.
3237 // Available from libzmq 3.0.0.
3238 char *
3239 zsock_last_endpoint (void *self);
3240
3241 // Set socket option `router_raw`.
3242 // Available from libzmq 3.0.0.
3243 void
3244 zsock_set_router_raw (void *self, int router_raw);
3245
3246 // Get socket option `ipv4only`.
3247 // Available from libzmq 3.0.0.
3248 int
3249 zsock_ipv4only (void *self);
3250
3251 // Set socket option `ipv4only`.
3252 // Available from libzmq 3.0.0.
3253 void
3254 zsock_set_ipv4only (void *self, int ipv4only);
3255
3256 // Set socket option `delay_attach_on_connect`.
3257 // Available from libzmq 3.0.0.
3258 void
3259 zsock_set_delay_attach_on_connect (void *self, int delay_attach_on_connect);
3260
3261 // Get socket option `hwm`.
3262 // Available from libzmq 2.0.0 to 3.0.0.
3263 int
3264 zsock_hwm (void *self);
3265
3266 // Set socket option `hwm`.
3267 // Available from libzmq 2.0.0 to 3.0.0.
3268 void
3269 zsock_set_hwm (void *self, int hwm);
3270
3271 // Get socket option `swap`.
3272 // Available from libzmq 2.0.0 to 3.0.0.
3273 int
3274 zsock_swap (void *self);
3275
3276 // Set socket option `swap`.
3277 // Available from libzmq 2.0.0 to 3.0.0.
3278 void
3279 zsock_set_swap (void *self, int swap);
3280
3281 // Get socket option `affinity`.
3282 // Available from libzmq 2.0.0.
3283 int
3284 zsock_affinity (void *self);
3285
3286 // Set socket option `affinity`.
3287 // Available from libzmq 2.0.0.
3288 void
3289 zsock_set_affinity (void *self, int affinity);
3290
3291 // Get socket option `identity`.
3292 // Available from libzmq 2.0.0.
3293 char *
3294 zsock_identity (void *self);
3295
3296 // Set socket option `identity`.
3297 // Available from libzmq 2.0.0.
3298 void
3299 zsock_set_identity (void *self, const char *identity);
3300
3301 // Get socket option `rate`.
3302 // Available from libzmq 2.0.0.
3303 int
3304 zsock_rate (void *self);
3305
3306 // Set socket option `rate`.
3307 // Available from libzmq 2.0.0.
3308 void
3309 zsock_set_rate (void *self, int rate);
3310
3311 // Get socket option `recovery_ivl`.
3312 // Available from libzmq 2.0.0.
3313 int
3314 zsock_recovery_ivl (void *self);
3315
3316 // Set socket option `recovery_ivl`.
3317 // Available from libzmq 2.0.0.
3318 void
3319 zsock_set_recovery_ivl (void *self, int recovery_ivl);
3320
3321 // Get socket option `recovery_ivl_msec`.
3322 // Available from libzmq 2.0.0 to 3.0.0.
3323 int
3324 zsock_recovery_ivl_msec (void *self);
3325
3326 // Set socket option `recovery_ivl_msec`.
3327 // Available from libzmq 2.0.0 to 3.0.0.
3328 void
3329 zsock_set_recovery_ivl_msec (void *self, int recovery_ivl_msec);
3330
3331 // Get socket option `mcast_loop`.
3332 // Available from libzmq 2.0.0 to 3.0.0.
3333 int
3334 zsock_mcast_loop (void *self);
3335
3336 // Set socket option `mcast_loop`.
3337 // Available from libzmq 2.0.0 to 3.0.0.
3338 void
3339 zsock_set_mcast_loop (void *self, int mcast_loop);
3340
3341 // Get socket option `rcvtimeo`.
3342 // Available from libzmq 2.2.0.
3343 int
3344 zsock_rcvtimeo (void *self);
3345
3346 // Set socket option `rcvtimeo`.
3347 // Available from libzmq 2.2.0.
3348 void
3349 zsock_set_rcvtimeo (void *self, int rcvtimeo);
3350
3351 // Get socket option `sndtimeo`.
3352 // Available from libzmq 2.2.0.
3353 int
3354 zsock_sndtimeo (void *self);
3355
3356 // Set socket option `sndtimeo`.
3357 // Available from libzmq 2.2.0.
3358 void
3359 zsock_set_sndtimeo (void *self, int sndtimeo);
3360
3361 // Get socket option `sndbuf`.
3362 // Available from libzmq 2.0.0.
3363 int
3364 zsock_sndbuf (void *self);
3365
3366 // Set socket option `sndbuf`.
3367 // Available from libzmq 2.0.0.
3368 void
3369 zsock_set_sndbuf (void *self, int sndbuf);
3370
3371 // Get socket option `rcvbuf`.
3372 // Available from libzmq 2.0.0.
3373 int
3374 zsock_rcvbuf (void *self);
3375
3376 // Set socket option `rcvbuf`.
3377 // Available from libzmq 2.0.0.
3378 void
3379 zsock_set_rcvbuf (void *self, int rcvbuf);
3380
3381 // Get socket option `linger`.
3382 // Available from libzmq 2.0.0.
3383 int
3384 zsock_linger (void *self);
3385
3386 // Set socket option `linger`.
3387 // Available from libzmq 2.0.0.
3388 void
3389 zsock_set_linger (void *self, int linger);
3390
3391 // Get socket option `reconnect_ivl`.
3392 // Available from libzmq 2.0.0.
3393 int
3394 zsock_reconnect_ivl (void *self);
3395
3396 // Set socket option `reconnect_ivl`.
3397 // Available from libzmq 2.0.0.
3398 void
3399 zsock_set_reconnect_ivl (void *self, int reconnect_ivl);
3400
3401 // Get socket option `reconnect_ivl_max`.
3402 // Available from libzmq 2.0.0.
3403 int
3404 zsock_reconnect_ivl_max (void *self);
3405
3406 // Set socket option `reconnect_ivl_max`.
3407 // Available from libzmq 2.0.0.
3408 void
3409 zsock_set_reconnect_ivl_max (void *self, int reconnect_ivl_max);
3410
3411 // Get socket option `backlog`.
3412 // Available from libzmq 2.0.0.
3413 int
3414 zsock_backlog (void *self);
3415
3416 // Set socket option `backlog`.
3417 // Available from libzmq 2.0.0.
3418 void
3419 zsock_set_backlog (void *self, int backlog);
3420
3421 // Set socket option `subscribe`.
3422 // Available from libzmq 2.0.0.
3423 void
3424 zsock_set_subscribe (void *self, const char *subscribe);
3425
3426 // Set socket option `unsubscribe`.
3427 // Available from libzmq 2.0.0.
3428 void
3429 zsock_set_unsubscribe (void *self, const char *unsubscribe);
3430
3431 // Get socket option `type`.
3432 // Available from libzmq 2.0.0.
3433 int
3434 zsock_type (void *self);
3435
3436 // Get socket option `rcvmore`.
3437 // Available from libzmq 2.0.0.
3438 int
3439 zsock_rcvmore (void *self);
3440
3441 // Get socket option `fd`.
3442 // Available from libzmq 2.0.0.
3443 SOCKET
3444 zsock_fd (void *self);
3445
3446 // Get socket option `events`.
3447 // Available from libzmq 2.0.0.
3448 int
3449 zsock_events (void *self);
3450
3451 // Self test of this class.
3452 void
3453 zsock_test (bool verbose);
3454
3455 // CLASS: zstr
3456 // Receive C string from socket. Caller must free returned string using
3457 // zstr_free(). Returns NULL if the context is being terminated or the
3458 // process was interrupted.
3459 char *
3460 zstr_recv (void *source);
3461
3462 // Receive a series of strings (until NULL) from multipart data.
3463 // Each string is allocated and filled with string data; if there
3464 // are not enough frames, unallocated strings are set to NULL.
3465 // Returns -1 if the message could not be read, else returns the
3466 // number of strings filled, zero or more. Free each returned string
3467 // using zstr_free(). If not enough strings are provided, remaining
3468 // multipart frames in the message are dropped.
3469 int
3470 zstr_recvx (void *source, char **string_p, ...);
3471
3472 // De-compress and receive C string from socket, received as a message
3473 // with two frames: size of the uncompressed string, and the string itself.
3474 // Caller must free returned string using zstr_free(). Returns NULL if the
3475 // context is being terminated or the process was interrupted.
3476 char *
3477 zstr_recv_compress (void *source);
3478
3479 // Send a C string to a socket, as a frame. The string is sent without
3480 // trailing null byte; to read this you can use zstr_recv, or a similar
3481 // method that adds a null terminator on the received string. String
3482 // may be NULL, which is sent as "".
3483 int
3484 zstr_send (void *dest, const char *string);
3485
3486 // Send a C string to a socket, as zstr_send(), with a MORE flag, so that
3487 // you can send further strings in the same multi-part message.
3488 int
3489 zstr_sendm (void *dest, const char *string);
3490
3491 // Send a formatted string to a socket. Note that you should NOT use
3492 // user-supplied strings in the format (they may contain '%' which
3493 // will create security holes).
3494 int
3495 zstr_sendf (void *dest, const char *format, ...);
3496
3497 // Send a formatted string to a socket, as for zstr_sendf(), with a
3498 // MORE flag, so that you can send further strings in the same multi-part
3499 // message.
3500 int
3501 zstr_sendfm (void *dest, const char *format, ...);
3502
3503 // Send a series of strings (until NULL) as multipart data
3504 // Returns 0 if the strings could be sent OK, or -1 on error.
3505 int
3506 zstr_sendx (void *dest, const char *string, ...);
3507
3508 // Compress and send a C string to a socket, as a message with two frames:
3509 // size of the uncompressed string, and the string itself. The string is
3510 // sent without trailing null byte; to read this you can use
3511 // zstr_recv_compress, or a similar method that de-compresses and adds a
3512 // null terminator on the received string.
3513 int
3514 zstr_send_compress (void *dest, const char *string);
3515
3516 // Compress and send a C string to a socket, as zstr_send_compress(),
3517 // with a MORE flag, so that you can send further strings in the same
3518 // multi-part message.
3519 int
3520 zstr_sendm_compress (void *dest, const char *string);
3521
3522 // Accepts a void pointer and returns a fresh character string. If source
3523 // is null, returns an empty string.
3524 char *
3525 zstr_str (void *source);
3526
3527 // Free a provided string, and nullify the parent pointer. Safe to call on
3528 // a null pointer.
3529 void
3530 zstr_free (char **string_p);
3531
3532 // Self test of this class.
3533 void
3534 zstr_test (bool verbose);
3535
3536 // CLASS: zsys
3537 // Initialize CZMQ zsys layer; this happens automatically when you create
3538 // a socket or an actor; however this call lets you force initialization
3539 // earlier, so e.g. logging is properly set-up before you start working.
3540 // Not threadsafe, so call only from main thread. Safe to call multiple
3541 // times. Returns global CZMQ context.
3542 void *
3543 zsys_init (void);
3544
3545 // Optionally shut down the CZMQ zsys layer; this normally happens automatically
3546 // when the process exits; however this call lets you force a shutdown
3547 // earlier, avoiding any potential problems with atexit() ordering, especially
3548 // with Windows dlls.
3549 void
3550 zsys_shutdown (void);
3551
3552 // Get a new ZMQ socket, automagically creating a ZMQ context if this is
3553 // the first time. Caller is responsible for destroying the ZMQ socket
3554 // before process exits, to avoid a ZMQ deadlock. Note: you should not use
3555 // this method in CZMQ apps, use zsock_new() instead.
3556 // *** This is for CZMQ internal use only and may change arbitrarily ***
3557 void *
3558 zsys_socket (int type, const char *filename, size_t line_nbr);
3559
3560 // Destroy/close a ZMQ socket. You should call this for every socket you
3561 // create using zsys_socket().
3562 // *** This is for CZMQ internal use only and may change arbitrarily ***
3563 int
3564 zsys_close (void *handle, const char *filename, size_t line_nbr);
3565
3566 // Return ZMQ socket name for socket type
3567 // *** This is for CZMQ internal use only and may change arbitrarily ***
3568 char *
3569 zsys_sockname (int socktype);
3570
3571 // Create a pipe, which consists of two PAIR sockets connected over inproc.
3572 // The pipe is configured to use the zsys_pipehwm setting. Returns the
3573 // frontend socket successful, NULL if failed.
3574 zsock_t *
3575 zsys_create_pipe (zsock_t **backend_p);
3576
3577 // Set interrupt handler; this saves the default handlers so that a
3578 // zsys_handler_reset () can restore them. If you call this multiple times
3579 // then the last handler will take affect. If handler_fn is NULL, disables
3580 // default SIGINT/SIGTERM handling in CZMQ.
3581 void
3582 zsys_handler_set (zsys_handler_fn *handler_fn);
3583
3584 // Reset interrupt handler, call this at exit if needed
3585 void
3586 zsys_handler_reset (void);
3587
3588 // Set default interrupt handler, so Ctrl-C or SIGTERM will set
3589 // zsys_interrupted. Idempotent; safe to call multiple times.
3590 // Can be supressed by ZSYS_SIGHANDLER=false
3591 // *** This is for CZMQ internal use only and may change arbitrarily ***
3592 void
3593 zsys_catch_interrupts (void);
3594
3595 // Return 1 if file exists, else zero
3596 bool
3597 zsys_file_exists (const char *filename);
3598
3599 // Return file modification time. Returns 0 if the file does not exist.
3600 time_t
3601 zsys_file_modified (const char *filename);
3602
3603 // Return file mode; provides at least support for the POSIX S_ISREG(m)
3604 // and S_ISDIR(m) macros and the S_IRUSR and S_IWUSR bits, on all boxes.
3605 // Returns a mode_t cast to int, or -1 in case of error.
3606 int
3607 zsys_file_mode (const char *filename);
3608
3609 // Delete file. Does not complain if the file is absent
3610 int
3611 zsys_file_delete (const char *filename);
3612
3613 // Check if file is 'stable'
3614 bool
3615 zsys_file_stable (const char *filename);
3616
3617 // Create a file path if it doesn't exist. The file path is treated as
3618 // printf format.
3619 int
3620 zsys_dir_create (const char *pathname, ...);
3621
3622 // Remove a file path if empty; the pathname is treated as printf format.
3623 int
3624 zsys_dir_delete (const char *pathname, ...);
3625
3626 // Move to a specified working directory. Returns 0 if OK, -1 if this failed.
3627 int
3628 zsys_dir_change (const char *pathname);
3629
3630 // Set private file creation mode; all files created from here will be
3631 // readable/writable by the owner only.
3632 void
3633 zsys_file_mode_private (void);
3634
3635 // Reset default file creation mode; all files created from here will use
3636 // process file mode defaults.
3637 void
3638 zsys_file_mode_default (void);
3639
3640 // Return the CZMQ version for run-time API detection; returns version
3641 // number into provided fields, providing reference isn't null in each case.
3642 void
3643 zsys_version (int *major, int *minor, int *patch);
3644
3645 // Format a string using printf formatting, returning a freshly allocated
3646 // buffer. If there was insufficient memory, returns NULL. Free the returned
3647 // string using zstr_free().
3648 char *
3649 zsys_sprintf (const char *format, ...);
3650
3651 // Format a string with a va_list argument, returning a freshly allocated
3652 // buffer. If there was insufficient memory, returns NULL. Free the returned
3653 // string using zstr_free().
3654 char *
3655 zsys_vprintf (const char *format, va_list argptr);
3656
3657 // Create UDP beacon socket; if the routable option is true, uses
3658 // multicast (not yet implemented), else uses broadcast. This method
3659 // and related ones might _eventually_ be moved to a zudp class.
3660 // *** This is for CZMQ internal use only and may change arbitrarily ***
3661 SOCKET
3662 zsys_udp_new (bool routable);
3663
3664 // Close a UDP socket
3665 // *** This is for CZMQ internal use only and may change arbitrarily ***
3666 int
3667 zsys_udp_close (SOCKET handle);
3668
3669 // Send zframe to UDP socket, return -1 if sending failed due to
3670 // interface having disappeared (happens easily with WiFi)
3671 // *** This is for CZMQ internal use only and may change arbitrarily ***
3672 int
3673 zsys_udp_send (SOCKET udpsock, zframe_t *frame, inaddr_t *address, int addrlen);
3674
3675 // Receive zframe from UDP socket, and set address of peer that sent it
3676 // The peername must be a char [INET_ADDRSTRLEN] array if IPv6 is disabled or
3677 // NI_MAXHOST if it's enabled. Returns NULL when failing to get peer address.
3678 // *** This is for CZMQ internal use only and may change arbitrarily ***
3679 zframe_t *
3680 zsys_udp_recv (SOCKET udpsock, char *peername, int peerlen);
3681
3682 // Handle an I/O error on some socket operation; will report and die on
3683 // fatal errors, and continue silently on "try again" errors.
3684 // *** This is for CZMQ internal use only and may change arbitrarily ***
3685 void
3686 zsys_socket_error (const char *reason);
3687
3688 // Return current host name, for use in public tcp:// endpoints. Caller gets
3689 // a freshly allocated string, should free it using zstr_free(). If the host
3690 // name is not resolvable, returns NULL.
3691 char *
3692 zsys_hostname (void);
3693
3694 // Move the current process into the background. The precise effect depends
3695 // on the operating system. On POSIX boxes, moves to a specified working
3696 // directory (if specified), closes all file handles, reopens stdin, stdout,
3697 // and stderr to the null device, and sets the process to ignore SIGHUP. On
3698 // Windows, does nothing. Returns 0 if OK, -1 if there was an error.
3699 int
3700 zsys_daemonize (const char *workdir);
3701
3702 // Drop the process ID into the lockfile, with exclusive lock, and switch
3703 // the process to the specified group and/or user. Any of the arguments
3704 // may be null, indicating a no-op. Returns 0 on success, -1 on failure.
3705 // Note if you combine this with zsys_daemonize, run after, not before
3706 // that method, or the lockfile will hold the wrong process ID.
3707 int
3708 zsys_run_as (const char *lockfile, const char *group, const char *user);
3709
3710 // Returns true if the underlying libzmq supports CURVE security.
3711 // Uses a heuristic probe according to the version of libzmq being used.
3712 bool
3713 zsys_has_curve (void);
3714
3715 // Configure the number of I/O threads that ZeroMQ will use. A good
3716 // rule of thumb is one thread per gigabit of traffic in or out. The
3717 // default is 1, sufficient for most applications. If the environment
3718 // variable ZSYS_IO_THREADS is defined, that provides the default.
3719 // Note that this method is valid only before any socket is created.
3720 void
3721 zsys_set_io_threads (size_t io_threads);
3722
3723 // Configure the scheduling policy of the ZMQ context thread pool.
3724 // Not available on Windows. See the sched_setscheduler man page or sched.h
3725 // for more information. If the environment variable ZSYS_THREAD_SCHED_POLICY
3726 // is defined, that provides the default.
3727 // Note that this method is valid only before any socket is created.
3728 void
3729 zsys_set_thread_sched_policy (int policy);
3730
3731 // Configure the scheduling priority of the ZMQ context thread pool.
3732 // Not available on Windows. See the sched_setscheduler man page or sched.h
3733 // for more information. If the environment variable ZSYS_THREAD_PRIORITY is
3734 // defined, that provides the default.
3735 // Note that this method is valid only before any socket is created.
3736 void
3737 zsys_set_thread_priority (int priority);
3738
3739 // Configure the number of sockets that ZeroMQ will allow. The default
3740 // is 1024. The actual limit depends on the system, and you can query it
3741 // by using zsys_socket_limit (). A value of zero means "maximum".
3742 // Note that this method is valid only before any socket is created.
3743 void
3744 zsys_set_max_sockets (size_t max_sockets);
3745
3746 // Return maximum number of ZeroMQ sockets that the system will support.
3747 size_t
3748 zsys_socket_limit (void);
3749
3750 // Configure the maximum allowed size of a message sent.
3751 // The default is INT_MAX.
3752 void
3753 zsys_set_max_msgsz (int max_msgsz);
3754
3755 // Return maximum message size.
3756 int
3757 zsys_max_msgsz (void);
3758
3759 // Configure the threshold value of filesystem object age per st_mtime
3760 // that should elapse until we consider that object "stable" at the
3761 // current zclock_time() moment.
3762 // The default is S_DEFAULT_ZSYS_FILE_STABLE_AGE_MSEC defined in zsys.c
3763 // which generally depends on host OS, with fallback value of 5000.
3764 void
3765 zsys_set_file_stable_age_msec (int64_t file_stable_age_msec);
3766
3767 // Return current threshold value of file stable age in msec.
3768 // This can be used in code that chooses to wait for this timeout
3769 // before testing if a filesystem object is "stable" or not.
3770 int64_t
3771 zsys_file_stable_age_msec (void);
3772
3773 // Configure the default linger timeout in msecs for new zsock instances.
3774 // You can also set this separately on each zsock_t instance. The default
3775 // linger time is zero, i.e. any pending messages will be dropped. If the
3776 // environment variable ZSYS_LINGER is defined, that provides the default.
3777 // Note that process exit will typically be delayed by the linger time.
3778 void
3779 zsys_set_linger (size_t linger);
3780
3781 // Configure the default outgoing pipe limit (HWM) for new zsock instances.
3782 // You can also set this separately on each zsock_t instance. The default
3783 // HWM is 1,000, on all versions of ZeroMQ. If the environment variable
3784 // ZSYS_SNDHWM is defined, that provides the default. Note that a value of
3785 // zero means no limit, i.e. infinite memory consumption.
3786 void
3787 zsys_set_sndhwm (size_t sndhwm);
3788
3789 // Configure the default incoming pipe limit (HWM) for new zsock instances.
3790 // You can also set this separately on each zsock_t instance. The default
3791 // HWM is 1,000, on all versions of ZeroMQ. If the environment variable
3792 // ZSYS_RCVHWM is defined, that provides the default. Note that a value of
3793 // zero means no limit, i.e. infinite memory consumption.
3794 void
3795 zsys_set_rcvhwm (size_t rcvhwm);
3796
3797 // Configure the default HWM for zactor internal pipes; this is set on both
3798 // ends of the pipe, for outgoing messages only (sndhwm). The default HWM is
3799 // 1,000, on all versions of ZeroMQ. If the environment var ZSYS_ACTORHWM is
3800 // defined, that provides the default. Note that a value of zero means no
3801 // limit, i.e. infinite memory consumption.
3802 void
3803 zsys_set_pipehwm (size_t pipehwm);
3804
3805 // Return the HWM for zactor internal pipes.
3806 size_t
3807 zsys_pipehwm (void);
3808
3809 // Configure use of IPv6 for new zsock instances. By default sockets accept
3810 // and make only IPv4 connections. When you enable IPv6, sockets will accept
3811 // and connect to both IPv4 and IPv6 peers. You can override the setting on
3812 // each zsock_t instance. The default is IPv4 only (ipv6 set to 0). If the
3813 // environment variable ZSYS_IPV6 is defined (as 1 or 0), this provides the
3814 // default. Note: has no effect on ZMQ v2.
3815 void
3816 zsys_set_ipv6 (int ipv6);
3817
3818 // Return use of IPv6 for zsock instances.
3819 int
3820 zsys_ipv6 (void);
3821
3822 // Set network interface name to use for broadcasts, particularly zbeacon.
3823 // This lets the interface be configured for test environments where required.
3824 // For example, on Mac OS X, zbeacon cannot bind to 255.255.255.255 which is
3825 // the default when there is no specified interface. If the environment
3826 // variable ZSYS_INTERFACE is set, use that as the default interface name.
3827 // Setting the interface to "*" means "use all available interfaces".
3828 void
3829 zsys_set_interface (const char *value);
3830
3831 // Return network interface to use for broadcasts, or "" if none was set.
3832 const char *
3833 zsys_interface (void);
3834
3835 // Set IPv6 address to use zbeacon socket, particularly for receiving zbeacon.
3836 // This needs to be set IPv6 is enabled as IPv6 can have multiple addresses
3837 // on a given interface. If the environment variable ZSYS_IPV6_ADDRESS is set,
3838 // use that as the default IPv6 address.
3839 void
3840 zsys_set_ipv6_address (const char *value);
3841
3842 // Return IPv6 address to use for zbeacon reception, or "" if none was set.
3843 const char *
3844 zsys_ipv6_address (void);
3845
3846 // Set IPv6 milticast address to use for sending zbeacon messages. This needs
3847 // to be set if IPv6 is enabled. If the environment variable
3848 // ZSYS_IPV6_MCAST_ADDRESS is set, use that as the default IPv6 multicast
3849 // address.
3850 void
3851 zsys_set_ipv6_mcast_address (const char *value);
3852
3853 // Return IPv6 multicast address to use for sending zbeacon, or "" if none was
3854 // set.
3855 const char *
3856 zsys_ipv6_mcast_address (void);
3857
3858 // Configure the automatic use of pre-allocated FDs when creating new sockets.
3859 // If 0 (default), nothing will happen. Else, when a new socket is bound, the
3860 // system API will be used to check if an existing pre-allocated FD with a
3861 // matching port (if TCP) or path (if IPC) exists, and if it does it will be
3862 // set via the ZMQ_USE_FD socket option so that the library will use it
3863 // instead of creating a new socket.
3864 void
3865 zsys_set_auto_use_fd (int auto_use_fd);
3866
3867 // Return use of automatic pre-allocated FDs for zsock instances.
3868 int
3869 zsys_auto_use_fd (void);
3870
3871 // Set log identity, which is a string that prefixes all log messages sent
3872 // by this process. The log identity defaults to the environment variable
3873 // ZSYS_LOGIDENT, if that is set.
3874 void
3875 zsys_set_logident (const char *value);
3876
3877 // Set stream to receive log traffic. By default, log traffic is sent to
3878 // stdout. If you set the stream to NULL, no stream will receive the log
3879 // traffic (it may still be sent to the system facility).
3880 void
3881 zsys_set_logstream (FILE *stream);
3882
3883 // Sends log output to a PUB socket bound to the specified endpoint. To
3884 // collect such log output, create a SUB socket, subscribe to the traffic
3885 // you care about, and connect to the endpoint. Log traffic is sent as a
3886 // single string frame, in the same format as when sent to stdout. The
3887 // log system supports a single sender; multiple calls to this method will
3888 // bind the same sender to multiple endpoints. To disable the sender, call
3889 // this method with a null argument.
3890 void
3891 zsys_set_logsender (const char *endpoint);
3892
3893 // Enable or disable logging to the system facility (syslog on POSIX boxes,
3894 // event log on Windows). By default this is disabled.
3895 void
3896 zsys_set_logsystem (bool logsystem);
3897
3898 // Log error condition - highest priority
3899 void
3900 zsys_error (const char *format, ...);
3901
3902 // Log warning condition - high priority
3903 void
3904 zsys_warning (const char *format, ...);
3905
3906 // Log normal, but significant, condition - normal priority
3907 void
3908 zsys_notice (const char *format, ...);
3909
3910 // Log informational message - low priority
3911 void
3912 zsys_info (const char *format, ...);
3913
3914 // Log debug-level message - lowest priority
3915 void
3916 zsys_debug (const char *format, ...);
3917
3918 // Self test of this class.
3919 void
3920 zsys_test (bool verbose);
3921
3922 // CLASS: ztimerset
3923 // Create new timer set.
3924 ztimerset_t *
3925 ztimerset_new (void);
3926
3927 // Destroy a timer set
3928 void
3929 ztimerset_destroy (ztimerset_t **self_p);
3930
3931 // Add a timer to the set. Returns timer id if OK, -1 on failure.
3932 int
3933 ztimerset_add (ztimerset_t *self, size_t interval, ztimerset_fn handler, void *arg);
3934
3935 // Cancel a timer. Returns 0 if OK, -1 on failure.
3936 int
3937 ztimerset_cancel (ztimerset_t *self, int timer_id);
3938
3939 // Set timer interval. Returns 0 if OK, -1 on failure.
3940 // This method is slow, canceling the timer and adding a new one yield better performance.
3941 int
3942 ztimerset_set_interval (ztimerset_t *self, int timer_id, size_t interval);
3943
3944 // Reset timer to start interval counting from current time. Returns 0 if OK, -1 on failure.
3945 // This method is slow, canceling the timer and adding a new one yield better performance.
3946 int
3947 ztimerset_reset (ztimerset_t *self, int timer_id);
3948
3949 // Return the time until the next interval.
3950 // Should be used as timeout parameter for the zpoller wait method.
3951 // The timeout is in msec.
3952 int
3953 ztimerset_timeout (ztimerset_t *self);
3954
3955 // Invoke callback function of all timers which their interval has elapsed.
3956 // Should be call after zpoller wait method.
3957 // Returns 0 if OK, -1 on failure.
3958 int
3959 ztimerset_execute (ztimerset_t *self);
3960
3961 // Self test of this class.
3962 void
3963 ztimerset_test (bool verbose);
3964
3965 // CLASS: ztrie
3966 // Creates a new ztrie.
3967 ztrie_t *
3968 ztrie_new (char delimiter);
3969
3970 // Destroy the ztrie.
3971 void
3972 ztrie_destroy (ztrie_t **self_p);
3973
3974 // Inserts a new route into the tree and attaches the data. Returns -1
3975 // if the route already exists, otherwise 0. This method takes ownership of
3976 // the provided data if a destroy_data_fn is provided.
3977 int
3978 ztrie_insert_route (ztrie_t *self, const char *path, void *data, ztrie_destroy_data_fn destroy_data_fn);
3979
3980 // Removes a route from the trie and destroys its data. Returns -1 if the
3981 // route does not exists, otherwise 0.
3982 // the start of the list call zlist_first (). Advances the cursor.
3983 int
3984 ztrie_remove_route (ztrie_t *self, const char *path);
3985
3986 // Returns true if the path matches a route in the tree, otherwise false.
3987 bool
3988 ztrie_matches (ztrie_t *self, const char *path);
3989
3990 // Returns the data of a matched route from last ztrie_matches. If the path
3991 // did not match, returns NULL. Do not delete the data as it's owned by
3992 // ztrie.
3993 void *
3994 ztrie_hit_data (ztrie_t *self);
3995
3996 // Returns the count of parameters that a matched route has.
3997 size_t
3998 ztrie_hit_parameter_count (ztrie_t *self);
3999
4000 // Returns the parameters of a matched route with named regexes from last
4001 // ztrie_matches. If the path did not match or the route did not contain any
4002 // named regexes, returns NULL.
4003 zhashx_t *
4004 ztrie_hit_parameters (ztrie_t *self);
4005
4006 // Returns the asterisk matched part of a route, if there has been no match
4007 // or no asterisk match, returns NULL.
4008 const char *
4009 ztrie_hit_asterisk_match (ztrie_t *self);
4010
4011 // Print the trie
4012 void
4013 ztrie_print (ztrie_t *self);
4014
4015 // Self test of this class.
4016 void
4017 ztrie_test (bool verbose);
4018
4019 // CLASS: zuuid
4020 // Create a new UUID object.
4021 zuuid_t *
4022 zuuid_new (void);
4023
4024 // Destroy a specified UUID object.
4025 void
4026 zuuid_destroy (zuuid_t **self_p);
4027
4028 // Create UUID object from supplied ZUUID_LEN-octet value.
4029 zuuid_t *
4030 zuuid_new_from (const byte *source);
4031
4032 // Set UUID to new supplied ZUUID_LEN-octet value.
4033 void
4034 zuuid_set (zuuid_t *self, const byte *source);
4035
4036 // Set UUID to new supplied string value skipping '-' and '{' '}'
4037 // optional delimiters. Return 0 if OK, else returns -1.
4038 int
4039 zuuid_set_str (zuuid_t *self, const char *source);
4040
4041 // Return UUID binary data.
4042 const byte *
4043 zuuid_data (zuuid_t *self);
4044
4045 // Return UUID binary size
4046 size_t
4047 zuuid_size (zuuid_t *self);
4048
4049 // Returns UUID as string
4050 const char *
4051 zuuid_str (zuuid_t *self);
4052
4053 // Return UUID in the canonical string format: 8-4-4-4-12, in lower
4054 // case. Caller does not modify or free returned value. See
4055 // http://en.wikipedia.org/wiki/Universally_unique_identifier
4056 const char *
4057 zuuid_str_canonical (zuuid_t *self);
4058
4059 // Store UUID blob in target array
4060 void
4061 zuuid_export (zuuid_t *self, byte *target);
4062
4063 // Check if UUID is same as supplied value
4064 bool
4065 zuuid_eq (zuuid_t *self, const byte *compare);
4066
4067 // Check if UUID is different from supplied value
4068 bool
4069 zuuid_neq (zuuid_t *self, const byte *compare);
4070
4071 // Make copy of UUID object; if uuid is null, or memory was exhausted,
4072 // returns null.
4073 zuuid_t *
4074 zuuid_dup (zuuid_t *self);
4075
4076 // Self test of this class.
4077 void
4078 zuuid_test (bool verbose);
4079
4080 ''')
8787 "uuid",
8888 "libsystemd",
8989 "liblz4",
90 "libcurl",
91 "libmicrohttpd",
9092 "libczmq"
9193 ])
9294 import cffi
183185 void
184186 zuuid_destroy_py (void *self);
185187
188 void
189 zhttp_client_destroy_py (void *self);
190
191 void
192 zhttp_server_destroy_py (void *self);
193
194 void
195 zhttp_server_options_destroy_py (void *self);
196
197 void
198 zhttp_request_destroy_py (void *self);
199
200 void
201 zhttp_response_destroy_py (void *self);
202
186203 ''')
187204
188205 ffidestructorbuilder.set_source ("czmq_cffi.destructors", '''
335352 zuuid_destroy_py (void *self)
336353 {
337354 zuuid_destroy ((zuuid_t **) &self);
355 }
356
357 void
358 zhttp_client_destroy_py (void *self)
359 {
360 zhttp_client_destroy ((zhttp_client_t **) &self);
361 }
362
363 void
364 zhttp_server_destroy_py (void *self)
365 {
366 zhttp_server_destroy ((zhttp_server_t **) &self);
367 }
368
369 void
370 zhttp_server_options_destroy_py (void *self)
371 {
372 zhttp_server_options_destroy ((zhttp_server_options_t **) &self);
373 }
374
375 void
376 zhttp_request_destroy_py (void *self)
377 {
378 zhttp_request_destroy ((zhttp_request_t **) &self);
379 }
380
381 void
382 zhttp_response_destroy_py (void *self)
383 {
384 zhttp_response_destroy ((zhttp_response_t **) &self);
338385 }
339386
340387 ''', **kwargs)
5959 typedef struct _ztimerset_t ztimerset_t;
6060 typedef struct _ztrie_t ztrie_t;
6161 typedef struct _zuuid_t zuuid_t;
62 typedef struct _zhttp_client_t zhttp_client_t;
63 typedef struct _zhttp_server_options_t zhttp_server_options_t;
64 typedef struct _zhttp_server_t zhttp_server_t;
65 typedef struct _zhttp_request_t zhttp_request_t;
66 typedef struct _zhttp_response_t zhttp_response_t;
6267 // Actors get a pipe and arguments from caller
6368 typedef void (zactor_fn) (
6469 zsock_t *pipe, void *args);
8085 typedef void (zcertstore_destructor) (
8186 void **self_p);
8287
88 // Destroy an item
89 typedef void (zchunk_destructor_fn) (
90 void **hint);
91
8392 //
8493 typedef int (zconfig_fct) (
8594 zconfig_t *self, void *arg, int level);
95
96 // Destroy an item
97 typedef void (zframe_destructor_fn) (
98 void **hint);
8699
87100 // Callback function for zhash_freefn method
88101 typedef void (zhash_free_fn) (
240253 const char *
241254 zargs_param_next (zargs_t *self);
242255
243 // Return current parameter name, or NULL if there are no named
244 // parameters.
256 // Return current parameter name, or NULL if there are no named parameters.
245257 const char *
246258 zargs_param_name (zargs_t *self);
247259
248 // Return value of named parameter, NULL if no given parameter has
249 // been specified, or special value for wich zargs_param_empty ()
250 // returns true.
260 // Return value of named parameter or NULL is it has no value (or was not specified)
251261 const char *
252 zargs_param_lookup (zargs_t *self, const char *keys);
253
254 // Return value of named parameter(s), NULL if no given parameter has
255 // been specified, or special value for wich zargs_param_empty ()
256 // returns true.
262 zargs_get (zargs_t *self, const char *name);
263
264 // Return value of one of parameter(s) or NULL is it has no value (or was not specified)
257265 const char *
258 zargs_param_lookupx (zargs_t *self, const char *keys, ...);
259
260 // Returns true if there are --help -h arguments
266 zargs_getx (zargs_t *self, const char *name, ...);
267
268 // Returns true if named parameter was specified on command line
261269 bool
262 zargs_has_help (zargs_t *self);
263
264 // Returns true if parameter did not have a value
270 zargs_has (zargs_t *self, const char *name);
271
272 // Returns true if named parameter(s) was specified on command line
265273 bool
266 zargs_param_empty (const char *arg);
274 zargs_hasx (zargs_t *self, const char *name, ...);
267275
268276 // Print an instance of zargs.
269277 void
494502 zchunk_t *
495503 zchunk_new (const void *data, size_t size);
496504
505 // Create a new chunk from memory. Take ownership of the memory and calling the destructor
506 // on destroy.
507 zchunk_t *
508 zchunk_frommem (void *data, size_t size, zchunk_destructor_fn destructor, void *hint);
509
497510 // Destroy a chunk
498511 void
499512 zchunk_destroy (zchunk_t **self_p);
585598 zframe_t *
586599 zchunk_pack (zchunk_t *self);
587600
601 // Transform zchunk into a zframe that can be sent in a message.
602 // Take ownership of the chunk.
603 zframe_t *
604 zchunk_packx (zchunk_t **self_p);
605
588606 // Transform a zframe into a zchunk.
589607 zchunk_t *
590608 zchunk_unpack (zframe_t *frame);
660678 // filename.
661679 zconfig_t *
662680 zconfig_loadf (const char *format, ...);
681
682 // Create copy of zconfig, caller MUST free the value
683 // Create copy of config, as new zconfig object. Returns a fresh zconfig_t
684 // object. If config is null, or memory was exhausted, returns null.
685 zconfig_t *
686 zconfig_dup (zconfig_t *self);
663687
664688 // Return name of config item
665689 char *
967991 zfile_t *
968992 zfile_new (const char *path, const char *name);
969993
970 // Create new temporary file for writing via tmpfile. File is automaticaly
994 // Create new temporary file for writing via tmpfile. File is automatically
971995 // deleted on destroy
972996 zfile_t *
973997 zfile_tmp (void);
11011125 // Create a frame with a specified string content.
11021126 zframe_t *
11031127 zframe_from (const char *string);
1128
1129 // Create a new frame from memory. Take ownership of the memory and calling the destructor
1130 // on destroy.
1131 zframe_t *
1132 zframe_frommem (void *data, size_t size, zframe_destructor_fn destructor, void *hint);
11041133
11051134 // Receive frame from socket, returns zframe_t object or NULL if the recv
11061135 // was interrupted. Does a blocking recv, if you want to not block then use
17321761 void
17331762 zlistx_destroy (zlistx_t **self_p);
17341763
1764 // Unpack binary frame into a new list. Packed data must follow format
1765 // defined by zlistx_pack. List is set to autofree. An empty frame
1766 // unpacks to an empty list.
1767 zlistx_t *
1768 zlistx_unpack (zframe_t *frame);
1769
17351770 // Add an item to the head of the list. Calls the item duplicator, if any,
17361771 // on the item. Resets cursor to list head. Returns an item handle on
17371772 // success, NULL if memory was exhausted.
18781913 // or greater than, item2.
18791914 void
18801915 zlistx_set_comparator (zlistx_t *self, zlistx_comparator_fn comparator);
1916
1917 // Serialize list to a binary frame that can be sent in a message.
1918 // The packed format is compatible with the 'strings' type implemented by zproto:
1919 //
1920 // ; A list of strings
1921 // list = list-count *longstr
1922 // list-count = number-4
1923 //
1924 // ; Strings are always length + text contents
1925 // longstr = number-4 *VCHAR
1926 //
1927 // ; Numbers are unsigned integers in network byte order
1928 // number-4 = 4OCTET
1929 zframe_t *
1930 zlistx_pack (zlistx_t *self);
18811931
18821932 // Self test of this class.
18831933 void
23252375 bool
23262376 zproc_running (zproc_t *self);
23272377
2378 // The timeout should be zero or greater, or -1 to wait indefinitely.
23282379 // wait or poll process status, return return code
23292380 int
2330 zproc_wait (zproc_t *self, bool hang);
2331
2332 // return internal actor, usefull for the polling if process died
2381 zproc_wait (zproc_t *self, int timeout);
2382
2383 // send SIGTERM signal to the subprocess, wait for grace period and
2384 // eventually send SIGKILL
2385 void
2386 zproc_shutdown (zproc_t *self, int timeout);
2387
2388 // return internal actor, useful for the polling if process died
23332389 void *
23342390 zproc_actor (zproc_t *self);
23352391
25052561 // c = zchunk_t *
25062562 // f = zframe_t *
25072563 // h = zhashx_t *
2564 // l = zlistx_t * (DRAFT)
25082565 // U = zuuid_t *
25092566 // p = void * (sends the pointer value, only meaningful over inproc)
25102567 // m = zmsg_t * (sends all frames in the zmsg)
25382595 // f = zframe_t ** (creates zframe)
25392596 // U = zuuid_t * (creates a zuuid with the data)
25402597 // h = zhashx_t ** (creates zhashx)
2598 // l = zlistx_t ** (creates zlistx) (DRAFT)
25412599 // p = void ** (stores pointer)
2542 // m = zmsg_t ** (creates a zmsg with the remaing frames)
2600 // m = zmsg_t ** (creates a zmsg with the remaining frames)
25432601 // z = null, asserts empty frame (0 arguments)
25442602 // u = uint * (stores unsigned integer, deprecated)
25452603 //
26632721 void *
26642722 zsock_resolve (void *self);
26652723
2724 // Check whether the socket has available message to read.
2725 bool
2726 zsock_has_in (void *self);
2727
2728 // Get socket option `router_notify`.
2729 // Available from libzmq 4.3.0.
2730 int
2731 zsock_router_notify (void *self);
2732
2733 // Set socket option `router_notify`.
2734 // Available from libzmq 4.3.0.
2735 void
2736 zsock_set_router_notify (void *self, int router_notify);
2737
2738 // Get socket option `multicast_loop`.
2739 // Available from libzmq 4.3.0.
2740 int
2741 zsock_multicast_loop (void *self);
2742
2743 // Set socket option `multicast_loop`.
2744 // Available from libzmq 4.3.0.
2745 void
2746 zsock_set_multicast_loop (void *self, int multicast_loop);
2747
2748 // Get socket option `metadata`.
2749 // Available from libzmq 4.3.0.
2750 char *
2751 zsock_metadata (void *self);
2752
2753 // Set socket option `metadata`.
2754 // Available from libzmq 4.3.0.
2755 void
2756 zsock_set_metadata (void *self, const char *metadata);
2757
2758 // Get socket option `loopback_fastpath`.
2759 // Available from libzmq 4.3.0.
2760 int
2761 zsock_loopback_fastpath (void *self);
2762
2763 // Set socket option `loopback_fastpath`.
2764 // Available from libzmq 4.3.0.
2765 void
2766 zsock_set_loopback_fastpath (void *self, int loopback_fastpath);
2767
2768 // Get socket option `zap_enforce_domain`.
2769 // Available from libzmq 4.3.0.
2770 int
2771 zsock_zap_enforce_domain (void *self);
2772
2773 // Set socket option `zap_enforce_domain`.
2774 // Available from libzmq 4.3.0.
2775 void
2776 zsock_set_zap_enforce_domain (void *self, int zap_enforce_domain);
2777
2778 // Get socket option `gssapi_principal_nametype`.
2779 // Available from libzmq 4.3.0.
2780 int
2781 zsock_gssapi_principal_nametype (void *self);
2782
2783 // Set socket option `gssapi_principal_nametype`.
2784 // Available from libzmq 4.3.0.
2785 void
2786 zsock_set_gssapi_principal_nametype (void *self, int gssapi_principal_nametype);
2787
2788 // Get socket option `gssapi_service_principal_nametype`.
2789 // Available from libzmq 4.3.0.
2790 int
2791 zsock_gssapi_service_principal_nametype (void *self);
2792
2793 // Set socket option `gssapi_service_principal_nametype`.
2794 // Available from libzmq 4.3.0.
2795 void
2796 zsock_set_gssapi_service_principal_nametype (void *self, int gssapi_service_principal_nametype);
2797
2798 // Get socket option `bindtodevice`.
2799 // Available from libzmq 4.3.0.
2800 char *
2801 zsock_bindtodevice (void *self);
2802
2803 // Set socket option `bindtodevice`.
2804 // Available from libzmq 4.3.0.
2805 void
2806 zsock_set_bindtodevice (void *self, const char *bindtodevice);
2807
26662808 // Get socket option `heartbeat_ivl`.
26672809 // Available from libzmq 4.2.0.
26682810 int
34923634
34933635 // Set default interrupt handler, so Ctrl-C or SIGTERM will set
34943636 // zsys_interrupted. Idempotent; safe to call multiple times.
3495 // Can be supressed by ZSYS_SIGHANDLER=false
3637 // Can be suppressed by ZSYS_SIGHANDLER=false
34963638 // *** This is for CZMQ internal use only and may change arbitrarily ***
34973639 void
34983640 zsys_catch_interrupts (void);
35583700 // number into provided fields, providing reference isn't null in each case.
35593701 void
35603702 zsys_version (int *major, int *minor, int *patch);
3703
3704 // Format a string using printf formatting, returning a freshly allocated
3705 // buffer. If there was insufficient memory, returns NULL. Free the returned
3706 // string using zstr_free(). The hinted version allows to optimize by using
3707 // a larger starting buffer size (known to/assumed by the developer) and so
3708 // avoid reallocations.
3709 char *
3710 zsys_sprintf_hint (int hint, const char *format, ...);
35613711
35623712 // Format a string using printf formatting, returning a freshly allocated
35633713 // buffer. If there was insufficient memory, returns NULL. Free the returned
36533803 void
36543804 zsys_set_thread_priority (int priority);
36553805
3806 // Configure the numeric prefix to each thread created for the internal
3807 // context's thread pool. This option is only supported on Linux.
3808 // If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
3809 // provides the default.
3810 // Note that this method is valid only before any socket is created.
3811 void
3812 zsys_set_thread_name_prefix (int prefix);
3813
3814 // Return thread name prefix.
3815 int
3816 zsys_thread_name_prefix (void);
3817
3818 // Adds a specific CPU to the affinity list of the ZMQ context thread pool.
3819 // This option is only supported on Linux.
3820 // Note that this method is valid only before any socket is created.
3821 void
3822 zsys_thread_affinity_cpu_add (int cpu);
3823
3824 // Removes a specific CPU to the affinity list of the ZMQ context thread pool.
3825 // This option is only supported on Linux.
3826 // Note that this method is valid only before any socket is created.
3827 void
3828 zsys_thread_affinity_cpu_remove (int cpu);
3829
36563830 // Configure the number of sockets that ZeroMQ will allow. The default
36573831 // is 1024. The actual limit depends on the system, and you can query it
36583832 // by using zsys_socket_limit (). A value of zero means "maximum".
37943968 // Return use of automatic pre-allocated FDs for zsock instances.
37953969 int
37963970 zsys_auto_use_fd (void);
3971
3972 // Print formatted string. Format is specified by variable names
3973 // in Python-like format style
3974 //
3975 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
3976 // become
3977 // "key=value"
3978 //
3979 // Returns freshly allocated string or NULL in a case of error.
3980 // Not enough memory, invalid format specifier, name not in args
3981 char *
3982 zsys_zprintf (const char *format, zhash_t *args);
3983
3984 // Return error string for given format/args combination.
3985 char *
3986 zsys_zprintf_error (const char *format, zhash_t *args);
3987
3988 // Print formatted string. Format is specified by variable names
3989 // in Python-like format style
3990 //
3991 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
3992 // become
3993 // "key=value"
3994 //
3995 // Returns freshly allocated string or NULL in a case of error.
3996 // Not enough memory, invalid format specifier, name not in args
3997 char *
3998 zsys_zplprintf (const char *format, zconfig_t *args);
3999
4000 // Return error string for given format/args combination.
4001 char *
4002 zsys_zplprintf_error (const char *format, zconfig_t *args);
37974003
37984004 // Set log identity, which is a string that prefixes all log messages sent
37994005 // by this process. The log identity defaults to the environment variable
40044210 void
40054211 zuuid_test (bool verbose);
40064212
4213 // CLASS: zhttp_client
4214 // Create a new http client
4215 zhttp_client_t *
4216 zhttp_client_new (bool verbose);
4217
4218 // Destroy an http client
4219 void
4220 zhttp_client_destroy (zhttp_client_t **self_p);
4221
4222 // Self test of this class.
4223 void
4224 zhttp_client_test (bool verbose);
4225
4226 // CLASS: zhttp_server
4227 // Create a new http server
4228 zhttp_server_t *
4229 zhttp_server_new (zhttp_server_options_t *options);
4230
4231 // Destroy an http server
4232 void
4233 zhttp_server_destroy (zhttp_server_t **self_p);
4234
4235 // Return the port the server is listening on.
4236 int
4237 zhttp_server_port (zhttp_server_t *self);
4238
4239 // Self test of this class.
4240 void
4241 zhttp_server_test (bool verbose);
4242
4243 // CLASS: zhttp_server_options
4244 // Create a new zhttp_server_options.
4245 zhttp_server_options_t *
4246 zhttp_server_options_new (void);
4247
4248 // Create options from config tree.
4249 zhttp_server_options_t *
4250 zhttp_server_options_from_config (zconfig_t *config);
4251
4252 // Destroy the zhttp_server_options.
4253 void
4254 zhttp_server_options_destroy (zhttp_server_options_t **self_p);
4255
4256 // Get the server listening port.
4257 int
4258 zhttp_server_options_port (zhttp_server_options_t *self);
4259
4260 // Set the server listening port
4261 void
4262 zhttp_server_options_set_port (zhttp_server_options_t *self, int port);
4263
4264 // Get the address sockets should connect to in order to receive requests.
4265 const char *
4266 zhttp_server_options_backend_address (zhttp_server_options_t *self);
4267
4268 // Set the address sockets should connect to in order to receive requests.
4269 void
4270 zhttp_server_options_set_backend_address (zhttp_server_options_t *self, const char *address);
4271
4272 // Self test of this class.
4273 void
4274 zhttp_server_options_test (bool verbose);
4275
4276 // CLASS: zhttp_request
4277 // Create a new http request.
4278 zhttp_request_t *
4279 zhttp_request_new (void);
4280
4281 // Destroy an http request.
4282 void
4283 zhttp_request_destroy (zhttp_request_t **self_p);
4284
4285 // Receive a new request from zhttp_server.
4286 // Return the underlying connection if successful, to be used when calling zhttp_response_send.
4287 void *
4288 zhttp_request_recv (zhttp_request_t *self, zsock_t *sock);
4289
4290 // Send a request to zhttp_client.
4291 // Url and the request path will be concatenated.
4292 // This behavior is useful for url rewrite and reverse proxy.
4293 //
4294 // Send also allow two user provided arguments which will be returned with the response.
4295 // The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an arg.
4296 int
4297 zhttp_request_send (zhttp_request_t *self, zhttp_client_t *client, int timeout, void *arg, void *arg2);
4298
4299 // Get the request method
4300 const char *
4301 zhttp_request_method (zhttp_request_t *self);
4302
4303 // Set the request method
4304 void
4305 zhttp_request_set_method (zhttp_request_t *self, const char *method);
4306
4307 // Get the request url.
4308 // When receiving a request from http server this is only the path part of the url.
4309 const char *
4310 zhttp_request_url (zhttp_request_t *self);
4311
4312 // Set the request url
4313 // When sending a request to http client this should be full url.
4314 void
4315 zhttp_request_set_url (zhttp_request_t *self, const char *url);
4316
4317 // Get the request content type
4318 const char *
4319 zhttp_request_content_type (zhttp_request_t *self);
4320
4321 // Set the request content type
4322 void
4323 zhttp_request_set_content_type (zhttp_request_t *self, const char *content_type);
4324
4325 // Get the content length of the request
4326 size_t
4327 zhttp_request_content_length (zhttp_request_t *self);
4328
4329 // Get the headers of the request
4330 zhash_t *
4331 zhttp_request_headers (zhttp_request_t *self);
4332
4333 // Get the content of the request.
4334 const char *
4335 zhttp_request_content (zhttp_request_t *self);
4336
4337 // Get the content of the request.
4338 char *
4339 zhttp_request_get_content (zhttp_request_t *self);
4340
4341 // Set the content of the request.
4342 // Content must by dynamically allocated string.
4343 // Takes ownership of the content.
4344 void
4345 zhttp_request_set_content (zhttp_request_t *self, char **content);
4346
4347 // Set the content of the request..
4348 // The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
4349 void
4350 zhttp_request_set_content_const (zhttp_request_t *self, const char *content);
4351
4352 // Set the content to NULL
4353 void
4354 zhttp_request_reset_content (zhttp_request_t *self);
4355
4356 // Match the path of the request.
4357 // Support wildcards with '%s' symbol inside the match string.
4358 // Matching wildcards until the next '/', '?' or '\0'.
4359 // On successful match the variadic arguments will be filled with the matching strings.
4360 // On successful match the method is modifying the url field and break it into substrings.
4361 // If you need to use the url, do it before matching or take a copy.
4362 //
4363 // User must not free the variadic arguments as they are part of the url.
4364 //
4365 // To use the percent symbol, just double it, e.g "%%something".
4366 //
4367 // Example:
4368 // if (zhttp_request_match (request, "POST", "/send/%s/%s", &name, &id))
4369 bool
4370 zhttp_request_match (zhttp_request_t *self, const char *method, const char *path, ...);
4371
4372 // Self test of this class.
4373 void
4374 zhttp_request_test (bool verbose);
4375
4376 // CLASS: zhttp_response
4377 // Create a new zhttp_response.
4378 zhttp_response_t *
4379 zhttp_response_new (void);
4380
4381 // Destroy the zhttp_response.
4382 void
4383 zhttp_response_destroy (zhttp_response_t **self_p);
4384
4385 // Send a response to a request.
4386 // Returns 0 if successful and -1 otherwise.
4387 int
4388 zhttp_response_send (zhttp_response_t *self, zsock_t *sock, void **connection);
4389
4390 // Receive a response from zhttp_client.
4391 // On success return 0, -1 otherwise.
4392 //
4393 // Recv returns the two user arguments which was provided with the request.
4394 // The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an argument.
4395 int
4396 zhttp_response_recv (zhttp_response_t *self, zhttp_client_t *client, void **arg, void **arg2);
4397
4398 // Get the response content type
4399 const char *
4400 zhttp_response_content_type (zhttp_response_t *self);
4401
4402 // Set the content type of the response.
4403 void
4404 zhttp_response_set_content_type (zhttp_response_t *self, const char *value);
4405
4406 // Get the status code of the response.
4407 uint32_t
4408 zhttp_response_status_code (zhttp_response_t *self);
4409
4410 // Set the status code of the response.
4411 void
4412 zhttp_response_set_status_code (zhttp_response_t *self, uint32_t status_code);
4413
4414 // Get the headers of the response.
4415 zhash_t *
4416 zhttp_response_headers (zhttp_response_t *self);
4417
4418 // Get the content length of the response
4419 size_t
4420 zhttp_response_content_length (zhttp_response_t *self);
4421
4422 // Get the content of the response.
4423 const char *
4424 zhttp_response_content (zhttp_response_t *self);
4425
4426 // Get the content of the response.
4427 char *
4428 zhttp_response_get_content (zhttp_response_t *self);
4429
4430 // Set the content of the response.
4431 // Content must by dynamically allocated string.
4432 // Takes ownership of the content.
4433 void
4434 zhttp_response_set_content (zhttp_response_t *self, char **content);
4435
4436 // Set the content of the response.
4437 // The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
4438 void
4439 zhttp_response_set_content_const (zhttp_response_t *self, const char *content);
4440
4441 // Set the content to NULL
4442 void
4443 zhttp_response_reset_content (zhttp_response_t *self);
4444
4445 // Self test of this class.
4446 void
4447 zhttp_response_test (bool verbose);
4448
40074449 ''')
40084450 for i, item in enumerate (czmq_cdefs):
40094451 czmq_cdefs [i] = re.sub(r';[^;]*\bva_list\b[^;]*;', ';', item, flags=re.S) # we don't support anything with a va_list arg
55
66 setup(
77 name = "czmq_cffi",
8 version = "4.1.1",
8 version = "4.2.0",
99 license = "mplv2",
1010 description = """Python cffi bindings of: the high-level c binding for 0mq""",
1111 packages = ["czmq_cffi", ],
6464 $$SRCDIR/QmlZsys.h \
6565 $$SRCDIR/QmlZtimerset.h \
6666 $$SRCDIR/QmlZtrie.h \
67 $$SRCDIR/QmlZuuid.h
67 $$SRCDIR/QmlZuuid.h \
68 $$SRCDIR/QmlZhttpClient.h \
69 $$SRCDIR/QmlZhttpServer.h \
70 $$SRCDIR/QmlZhttpServerOptions.h \
71 $$SRCDIR/QmlZhttpRequest.h \
72 $$SRCDIR/QmlZhttpResponse.h
6873
6974 SOURCES += \
7075 $$SRCDIR/QmlZactor.cpp \
9499 $$SRCDIR/QmlZsys.cpp \
95100 $$SRCDIR/QmlZtimerset.cpp \
96101 $$SRCDIR/QmlZtrie.cpp \
97 $$SRCDIR/QmlZuuid.cpp
102 $$SRCDIR/QmlZuuid.cpp \
103 $$SRCDIR/QmlZhttpClient.cpp \
104 $$SRCDIR/QmlZhttpServer.cpp \
105 $$SRCDIR/QmlZhttpServerOptions.cpp \
106 $$SRCDIR/QmlZhttpRequest.cpp \
107 $$SRCDIR/QmlZhttpResponse.cpp
98108
99109 OBJECTS_DIR = $$BUILDDIR/.obj
100110 MOC_DIR = $$BUILDDIR/.moc
4646 };
4747
4848 ///
49 // Return current parameter name, or NULL if there are no named
50 // parameters.
49 // Return current parameter name, or NULL if there are no named parameters.
5150 const QString QmlZargs::paramName () {
5251 return QString (zargs_param_name (self));
5352 };
5453
5554 ///
56 // Return value of named parameter, NULL if no given parameter has
57 // been specified, or special value for wich zargs_param_empty ()
58 // returns true.
59 const QString QmlZargs::paramLookup (const QString &keys) {
60 return QString (zargs_param_lookup (self, keys.toUtf8().data()));
55 // Return value of named parameter or NULL is it has no value (or was not specified)
56 const QString QmlZargs::get (const QString &name) {
57 return QString (zargs_get (self, name.toUtf8().data()));
6158 };
6259
6360 ///
64 // Return value of named parameter(s), NULL if no given parameter has
65 // been specified, or special value for wich zargs_param_empty ()
66 // returns true.
67 const QString QmlZargs::paramLookupx (const QString &keys) {
68 return QString (zargs_param_lookupx (self, keys.toUtf8().data()));
61 // Return value of one of parameter(s) or NULL is it has no value (or was not specified)
62 const QString QmlZargs::getx (const QString &name) {
63 return QString (zargs_getx (self, name.toUtf8().data()));
6964 };
7065
7166 ///
72 // Returns true if there are --help -h arguments
73 bool QmlZargs::hasHelp () {
74 return zargs_has_help (self);
67 // Returns true if named parameter was specified on command line
68 bool QmlZargs::has (const QString &name) {
69 return zargs_has (self, name.toUtf8().data());
70 };
71
72 ///
73 // Returns true if named parameter(s) was specified on command line
74 bool QmlZargs::hasx (const QString &name) {
75 return zargs_hasx (self, name.toUtf8().data());
7576 };
7677
7778 ///
8586 return new QmlZargsAttached(object);
8687 }
8788
88
89 ///
90 // Returns true if parameter did not have a value
91 bool QmlZargsAttached::paramEmpty (const QString &arg) {
92 return zargs_param_empty (arg.toUtf8().data());
93 };
9489
9590 ///
9691 // Self test of this class.
4747 // parameters, or value for which zargs_param_empty (arg) returns true.
4848 const QString paramNext ();
4949
50 // Return current parameter name, or NULL if there are no named
51 // parameters.
50 // Return current parameter name, or NULL if there are no named parameters.
5251 const QString paramName ();
5352
54 // Return value of named parameter, NULL if no given parameter has
55 // been specified, or special value for wich zargs_param_empty ()
56 // returns true.
57 const QString paramLookup (const QString &keys);
53 // Return value of named parameter or NULL is it has no value (or was not specified)
54 const QString get (const QString &name);
5855
59 // Return value of named parameter(s), NULL if no given parameter has
60 // been specified, or special value for wich zargs_param_empty ()
61 // returns true.
62 const QString paramLookupx (const QString &keys);
56 // Return value of one of parameter(s) or NULL is it has no value (or was not specified)
57 const QString getx (const QString &name);
6358
64 // Returns true if there are --help -h arguments
65 bool hasHelp ();
59 // Returns true if named parameter was specified on command line
60 bool has (const QString &name);
61
62 // Returns true if named parameter(s) was specified on command line
63 bool hasx (const QString &name);
6664
6765 // Print an instance of zargs.
6866 void print ();
7977 };
8078
8179 public slots:
82 // Returns true if parameter did not have a value
83 bool paramEmpty (const QString &arg);
84
8580 // Self test of this class.
8681 void test (bool verbose);
8782
170170 };
171171
172172 ///
173 // Transform zchunk into a zframe that can be sent in a message.
174 // Take ownership of the chunk.
175 QmlZframe *QmlZchunkAttached::packx (QmlZchunk *selfP) {
176 QmlZframe *retQ_ = new QmlZframe ();
177 retQ_->self = zchunk_packx (&selfP->self);
178 return retQ_;
179 };
180
181 ///
173182 // Transform a zframe into a zchunk.
174183 QmlZchunk *QmlZchunkAttached::unpack (QmlZframe *frame) {
175184 QmlZchunk *retQ_ = new QmlZchunk ();
200209 };
201210
202211 ///
212 // Create a new chunk from memory. Take ownership of the memory and calling the destructor
213 // on destroy.
214 QmlZchunk *QmlZchunkAttached::frommem (void *data, size_t size, zchunk_destructor_fn destructor, void *hint) {
215 QmlZchunk *qmlSelf = new QmlZchunk ();
216 qmlSelf->self = zchunk_frommem (data, size, destructor, hint);
217 return qmlSelf;
218 };
219
220 ///
203221 // Destroy a chunk
204222 void QmlZchunkAttached::destruct (QmlZchunk *qmlSelf) {
205223 zchunk_destroy (&qmlSelf->self);
118118 // chunk containing the file data, or NULL if the file could not be read.
119119 QmlZchunk *slurp (const QString &filename, size_t maxsize);
120120
121 // Transform zchunk into a zframe that can be sent in a message.
122 // Take ownership of the chunk.
123 QmlZframe *packx (QmlZchunk *selfP);
124
121125 // Transform a zframe into a zchunk.
122126 QmlZchunk *unpack (QmlZframe *frame);
123127
131135 // is copied into the chunk. If you do not specify the data, the chunk is
132136 // allocated and left empty, and you can then add data using zchunk_append.
133137 QmlZchunk *construct (const void *data, size_t size);
138
139 // Create a new chunk from memory. Take ownership of the memory and calling the destructor
140 // on destroy.
141 QmlZchunk *frommem (void *data, size_t size, zchunk_destructor_fn destructor, void *hint);
134142
135143 // Destroy a chunk
136144 void destruct (QmlZchunk *qmlSelf);
66
77 #include "QmlZconfig.h"
88
9
10 ///
11 // Create copy of zconfig, caller MUST free the value
12 // Create copy of config, as new zconfig object. Returns a fresh zconfig_t
13 // object. If config is null, or memory was exhausted, returns null.
14 QmlZconfig *QmlZconfig::dup () {
15 QmlZconfig *retQ_ = new QmlZconfig ();
16 retQ_->self = zconfig_dup (self);
17 return retQ_;
18 };
919
1020 ///
1121 // Return name of config item
2727 static QObject* qmlAttachedProperties(QObject* object); // defined in QmlZconfig.cpp
2828
2929 public slots:
30 // Create copy of zconfig, caller MUST free the value
31 // Create copy of config, as new zconfig object. Returns a fresh zconfig_t
32 // object. If config is null, or memory was exhausted, returns null.
33 QmlZconfig *dup ();
34
3035 // Return name of config item
3136 const QString name ();
3237
181181 };
182182
183183 ///
184 // Create new temporary file for writing via tmpfile. File is automaticaly
184 // Create new temporary file for writing via tmpfile. File is automatically
185185 // deleted on destroy
186186 QmlZfile *QmlZfileAttached::tmp () {
187187 QmlZfile *qmlSelf = new QmlZfile ();
131131 // may be NULL, in which case it is not used.
132132 QmlZfile *construct (const QString &path, const QString &name);
133133
134 // Create new temporary file for writing via tmpfile. File is automaticaly
134 // Create new temporary file for writing via tmpfile. File is automatically
135135 // deleted on destroy
136136 QmlZfile *tmp ();
137137
176176 };
177177
178178 ///
179 // Create a new frame from memory. Take ownership of the memory and calling the destructor
180 // on destroy.
181 QmlZframe *QmlZframeAttached::frommem (void *data, size_t size, zframe_destructor_fn destructor, void *hint) {
182 QmlZframe *qmlSelf = new QmlZframe ();
183 qmlSelf->self = zframe_frommem (data, size, destructor, hint);
184 return qmlSelf;
185 };
186
187 ///
179188 // Receive frame from socket, returns zframe_t object or NULL if the recv
180189 // was interrupted. Does a blocking recv, if you want to not block then use
181190 // zpoller or zloop.
121121 // Create a frame with a specified string content.
122122 QmlZframe *from (const QString &string);
123123
124 // Create a new frame from memory. Take ownership of the memory and calling the destructor
125 // on destroy.
126 QmlZframe *frommem (void *data, size_t size, zframe_destructor_fn destructor, void *hint);
127
124128 // Receive frame from socket, returns zframe_t object or NULL if the recv
125129 // was interrupted. Does a blocking recv, if you want to not block then use
126130 // zpoller or zloop.
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #include "QmlZhttpClient.h"
8
9
10
11 QObject* QmlZhttpClient::qmlAttachedProperties(QObject* object) {
12 return new QmlZhttpClientAttached(object);
13 }
14
15
16 ///
17 // Self test of this class.
18 void QmlZhttpClientAttached::test (bool verbose) {
19 zhttp_client_test (verbose);
20 };
21
22 ///
23 // Create a new http client
24 QmlZhttpClient *QmlZhttpClientAttached::construct (bool verbose) {
25 QmlZhttpClient *qmlSelf = new QmlZhttpClient ();
26 qmlSelf->self = zhttp_client_new (verbose);
27 return qmlSelf;
28 };
29
30 ///
31 // Destroy an http client
32 void QmlZhttpClientAttached::destruct (QmlZhttpClient *qmlSelf) {
33 zhttp_client_destroy (&qmlSelf->self);
34 };
35
36 /*
37 ################################################################################
38 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
39 # Read the zproject/README.md for information about making permanent changes. #
40 ################################################################################
41 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #ifndef QML_ZHTTP_CLIENT_H
8 #define QML_ZHTTP_CLIENT_H
9
10 #include <QtQml>
11
12 #include <czmq.h>
13 #include "qml_czmq_plugin.h"
14
15
16 class QmlZhttpClient : public QObject
17 {
18 Q_OBJECT
19 Q_PROPERTY(bool isNULL READ isNULL)
20
21 public:
22 zhttp_client_t *self;
23
24 QmlZhttpClient() { self = NULL; }
25 bool isNULL() { return self == NULL; }
26
27 static QObject* qmlAttachedProperties(QObject* object); // defined in QmlZhttpClient.cpp
28
29 public slots:};
30
31 class QmlZhttpClientAttached : public QObject
32 {
33 Q_OBJECT
34 QObject* m_attached;
35
36 public:
37 QmlZhttpClientAttached (QObject* attached) {
38 Q_UNUSED (attached);
39 };
40
41 public slots:
42 // Self test of this class.
43 void test (bool verbose);
44
45 // Create a new http client
46 QmlZhttpClient *construct (bool verbose);
47
48 // Destroy an http client
49 void destruct (QmlZhttpClient *qmlSelf);
50 };
51
52
53 QML_DECLARE_TYPEINFO(QmlZhttpClient, QML_HAS_ATTACHED_PROPERTIES)
54
55 #endif
56 /*
57 ################################################################################
58 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
59 # Read the zproject/README.md for information about making permanent changes. #
60 ################################################################################
61 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #include "QmlZhttpRequest.h"
8
9
10 ///
11 // Receive a new request from zhttp_server.
12 // Return the underlying connection if successful, to be used when calling zhttp_response_send.
13 void *QmlZhttpRequest::recv (QmlZsock *sock) {
14 return zhttp_request_recv (self, sock->self);
15 };
16
17 ///
18 // Send a request to zhttp_client.
19 // Url and the request path will be concatenated.
20 // This behavior is useful for url rewrite and reverse proxy.
21 //
22 // Send also allow two user provided arguments which will be returned with the response.
23 // The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an arg.
24 int QmlZhttpRequest::send (QmlZhttpClient *client, int timeout, void *arg, void *arg2) {
25 return zhttp_request_send (self, client->self, timeout, arg, arg2);
26 };
27
28 ///
29 // Get the request method
30 const QString QmlZhttpRequest::method () {
31 return QString (zhttp_request_method (self));
32 };
33
34 ///
35 // Set the request method
36 void QmlZhttpRequest::setMethod (const QString &method) {
37 zhttp_request_set_method (self, method.toUtf8().data());
38 };
39
40 ///
41 // Get the request url.
42 // When receiving a request from http server this is only the path part of the url.
43 const QString QmlZhttpRequest::url () {
44 return QString (zhttp_request_url (self));
45 };
46
47 ///
48 // Set the request url
49 // When sending a request to http client this should be full url.
50 void QmlZhttpRequest::setUrl (const QString &url) {
51 zhttp_request_set_url (self, url.toUtf8().data());
52 };
53
54 ///
55 // Get the request content type
56 const QString QmlZhttpRequest::contentType () {
57 return QString (zhttp_request_content_type (self));
58 };
59
60 ///
61 // Set the request content type
62 void QmlZhttpRequest::setContentType (const QString &contentType) {
63 zhttp_request_set_content_type (self, contentType.toUtf8().data());
64 };
65
66 ///
67 // Get the content length of the request
68 size_t QmlZhttpRequest::contentLength () {
69 return zhttp_request_content_length (self);
70 };
71
72 ///
73 // Get the headers of the request
74 QmlZhash *QmlZhttpRequest::headers () {
75 QmlZhash *retQ_ = new QmlZhash ();
76 retQ_->self = zhttp_request_headers (self);
77 return retQ_;
78 };
79
80 ///
81 // Get the content of the request.
82 const QString QmlZhttpRequest::content () {
83 return QString (zhttp_request_content (self));
84 };
85
86 ///
87 // Get the content of the request.
88 QString QmlZhttpRequest::getContent () {
89 char *retStr_ = zhttp_request_get_content (self);
90 QString retQStr_ = QString (retStr_);
91 free (retStr_);
92 return retQStr_;
93 };
94
95 ///
96 // Set the content of the request.
97 // Content must by dynamically allocated string.
98 // Takes ownership of the content.
99 void QmlZhttpRequest::setContent (QString content) {
100 zhttp_request_set_content (self, content.toUtf8().data());
101 };
102
103 ///
104 // Set the content of the request..
105 // The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
106 void QmlZhttpRequest::setContentConst (const QString &content) {
107 zhttp_request_set_content_const (self, content.toUtf8().data());
108 };
109
110 ///
111 // Set the content to NULL
112 void QmlZhttpRequest::resetContent () {
113 zhttp_request_reset_content (self);
114 };
115
116 ///
117 // Match the path of the request.
118 // Support wildcards with '%s' symbol inside the match string.
119 // Matching wildcards until the next '/', '?' or '\0'.
120 // On successful match the variadic arguments will be filled with the matching strings.
121 // On successful match the method is modifying the url field and break it into substrings.
122 // If you need to use the url, do it before matching or take a copy.
123 //
124 // User must not free the variadic arguments as they are part of the url.
125 //
126 // To use the percent symbol, just double it, e.g "%%something".
127 //
128 // Example:
129 // if (zhttp_request_match (request, "POST", "/send/%s/%s", &name, &id))
130 bool QmlZhttpRequest::match (const QString &method, const QString &path) {
131 return zhttp_request_match (self, method.toUtf8().data(), path.toUtf8().data());
132 };
133
134
135 QObject* QmlZhttpRequest::qmlAttachedProperties(QObject* object) {
136 return new QmlZhttpRequestAttached(object);
137 }
138
139
140 ///
141 // Self test of this class.
142 void QmlZhttpRequestAttached::test (bool verbose) {
143 zhttp_request_test (verbose);
144 };
145
146 ///
147 // Create a new http request.
148 QmlZhttpRequest *QmlZhttpRequestAttached::construct () {
149 QmlZhttpRequest *qmlSelf = new QmlZhttpRequest ();
150 qmlSelf->self = zhttp_request_new ();
151 return qmlSelf;
152 };
153
154 ///
155 // Destroy an http request.
156 void QmlZhttpRequestAttached::destruct (QmlZhttpRequest *qmlSelf) {
157 zhttp_request_destroy (&qmlSelf->self);
158 };
159
160 /*
161 ################################################################################
162 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
163 # Read the zproject/README.md for information about making permanent changes. #
164 ################################################################################
165 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #ifndef QML_ZHTTP_REQUEST_H
8 #define QML_ZHTTP_REQUEST_H
9
10 #include <QtQml>
11
12 #include <czmq.h>
13 #include "qml_czmq_plugin.h"
14
15
16 class QmlZhttpRequest : public QObject
17 {
18 Q_OBJECT
19 Q_PROPERTY(bool isNULL READ isNULL)
20
21 public:
22 zhttp_request_t *self;
23
24 QmlZhttpRequest() { self = NULL; }
25 bool isNULL() { return self == NULL; }
26
27 static QObject* qmlAttachedProperties(QObject* object); // defined in QmlZhttpRequest.cpp
28
29 public slots:
30 // Receive a new request from zhttp_server.
31 // Return the underlying connection if successful, to be used when calling zhttp_response_send.
32 void *recv (QmlZsock *sock);
33
34 // Send a request to zhttp_client.
35 // Url and the request path will be concatenated.
36 // This behavior is useful for url rewrite and reverse proxy.
37 //
38 // Send also allow two user provided arguments which will be returned with the response.
39 // The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an arg.
40 int send (QmlZhttpClient *client, int timeout, void *arg, void *arg2);
41
42 // Get the request method
43 const QString method ();
44
45 // Set the request method
46 void setMethod (const QString &method);
47
48 // Get the request url.
49 // When receiving a request from http server this is only the path part of the url.
50 const QString url ();
51
52 // Set the request url
53 // When sending a request to http client this should be full url.
54 void setUrl (const QString &url);
55
56 // Get the request content type
57 const QString contentType ();
58
59 // Set the request content type
60 void setContentType (const QString &contentType);
61
62 // Get the content length of the request
63 size_t contentLength ();
64
65 // Get the headers of the request
66 QmlZhash *headers ();
67
68 // Get the content of the request.
69 const QString content ();
70
71 // Get the content of the request.
72 QString getContent ();
73
74 // Set the content of the request.
75 // Content must by dynamically allocated string.
76 // Takes ownership of the content.
77 void setContent (QString content);
78
79 // Set the content of the request..
80 // The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
81 void setContentConst (const QString &content);
82
83 // Set the content to NULL
84 void resetContent ();
85
86 // Match the path of the request.
87 // Support wildcards with '%s' symbol inside the match string.
88 // Matching wildcards until the next '/', '?' or '\0'.
89 // On successful match the variadic arguments will be filled with the matching strings.
90 // On successful match the method is modifying the url field and break it into substrings.
91 // If you need to use the url, do it before matching or take a copy.
92 //
93 // User must not free the variadic arguments as they are part of the url.
94 //
95 // To use the percent symbol, just double it, e.g "%%something".
96 //
97 // Example:
98 // if (zhttp_request_match (request, "POST", "/send/%s/%s", &name, &id))
99 bool match (const QString &method, const QString &path);
100 };
101
102 class QmlZhttpRequestAttached : public QObject
103 {
104 Q_OBJECT
105 QObject* m_attached;
106
107 public:
108 QmlZhttpRequestAttached (QObject* attached) {
109 Q_UNUSED (attached);
110 };
111
112 public slots:
113 // Self test of this class.
114 void test (bool verbose);
115
116 // Create a new http request.
117 QmlZhttpRequest *construct ();
118
119 // Destroy an http request.
120 void destruct (QmlZhttpRequest *qmlSelf);
121 };
122
123
124 QML_DECLARE_TYPEINFO(QmlZhttpRequest, QML_HAS_ATTACHED_PROPERTIES)
125
126 #endif
127 /*
128 ################################################################################
129 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
130 # Read the zproject/README.md for information about making permanent changes. #
131 ################################################################################
132 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #include "QmlZhttpResponse.h"
8
9
10 ///
11 // Send a response to a request.
12 // Returns 0 if successful and -1 otherwise.
13 int QmlZhttpResponse::send (QmlZsock *sock, void **connection) {
14 return zhttp_response_send (self, sock->self, connection);
15 };
16
17 ///
18 // Receive a response from zhttp_client.
19 // On success return 0, -1 otherwise.
20 //
21 // Recv returns the two user arguments which was provided with the request.
22 // The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an argument.
23 int QmlZhttpResponse::recv (QmlZhttpClient *client, void **arg, void **arg2) {
24 return zhttp_response_recv (self, client->self, arg, arg2);
25 };
26
27 ///
28 // Get the response content type
29 const QString QmlZhttpResponse::contentType () {
30 return QString (zhttp_response_content_type (self));
31 };
32
33 ///
34 // Set the content type of the response.
35 void QmlZhttpResponse::setContentType (const QString &value) {
36 zhttp_response_set_content_type (self, value.toUtf8().data());
37 };
38
39 ///
40 // Get the status code of the response.
41 uint32_t QmlZhttpResponse::statusCode () {
42 return zhttp_response_status_code (self);
43 };
44
45 ///
46 // Set the status code of the response.
47 void QmlZhttpResponse::setStatusCode (uint32_t statusCode) {
48 zhttp_response_set_status_code (self, statusCode);
49 };
50
51 ///
52 // Get the headers of the response.
53 QmlZhash *QmlZhttpResponse::headers () {
54 QmlZhash *retQ_ = new QmlZhash ();
55 retQ_->self = zhttp_response_headers (self);
56 return retQ_;
57 };
58
59 ///
60 // Get the content length of the response
61 size_t QmlZhttpResponse::contentLength () {
62 return zhttp_response_content_length (self);
63 };
64
65 ///
66 // Get the content of the response.
67 const QString QmlZhttpResponse::content () {
68 return QString (zhttp_response_content (self));
69 };
70
71 ///
72 // Get the content of the response.
73 QString QmlZhttpResponse::getContent () {
74 char *retStr_ = zhttp_response_get_content (self);
75 QString retQStr_ = QString (retStr_);
76 free (retStr_);
77 return retQStr_;
78 };
79
80 ///
81 // Set the content of the response.
82 // Content must by dynamically allocated string.
83 // Takes ownership of the content.
84 void QmlZhttpResponse::setContent (QString content) {
85 zhttp_response_set_content (self, content.toUtf8().data());
86 };
87
88 ///
89 // Set the content of the response.
90 // The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
91 void QmlZhttpResponse::setContentConst (const QString &content) {
92 zhttp_response_set_content_const (self, content.toUtf8().data());
93 };
94
95 ///
96 // Set the content to NULL
97 void QmlZhttpResponse::resetContent () {
98 zhttp_response_reset_content (self);
99 };
100
101
102 QObject* QmlZhttpResponse::qmlAttachedProperties(QObject* object) {
103 return new QmlZhttpResponseAttached(object);
104 }
105
106
107 ///
108 // Self test of this class.
109 void QmlZhttpResponseAttached::test (bool verbose) {
110 zhttp_response_test (verbose);
111 };
112
113 ///
114 // Create a new zhttp_response.
115 QmlZhttpResponse *QmlZhttpResponseAttached::construct () {
116 QmlZhttpResponse *qmlSelf = new QmlZhttpResponse ();
117 qmlSelf->self = zhttp_response_new ();
118 return qmlSelf;
119 };
120
121 ///
122 // Destroy the zhttp_response.
123 void QmlZhttpResponseAttached::destruct (QmlZhttpResponse *qmlSelf) {
124 zhttp_response_destroy (&qmlSelf->self);
125 };
126
127 /*
128 ################################################################################
129 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
130 # Read the zproject/README.md for information about making permanent changes. #
131 ################################################################################
132 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #ifndef QML_ZHTTP_RESPONSE_H
8 #define QML_ZHTTP_RESPONSE_H
9
10 #include <QtQml>
11
12 #include <czmq.h>
13 #include "qml_czmq_plugin.h"
14
15
16 class QmlZhttpResponse : public QObject
17 {
18 Q_OBJECT
19 Q_PROPERTY(bool isNULL READ isNULL)
20
21 public:
22 zhttp_response_t *self;
23
24 QmlZhttpResponse() { self = NULL; }
25 bool isNULL() { return self == NULL; }
26
27 static QObject* qmlAttachedProperties(QObject* object); // defined in QmlZhttpResponse.cpp
28
29 public slots:
30 // Send a response to a request.
31 // Returns 0 if successful and -1 otherwise.
32 int send (QmlZsock *sock, void **connection);
33
34 // Receive a response from zhttp_client.
35 // On success return 0, -1 otherwise.
36 //
37 // Recv returns the two user arguments which was provided with the request.
38 // The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an argument.
39 int recv (QmlZhttpClient *client, void **arg, void **arg2);
40
41 // Get the response content type
42 const QString contentType ();
43
44 // Set the content type of the response.
45 void setContentType (const QString &value);
46
47 // Get the status code of the response.
48 uint32_t statusCode ();
49
50 // Set the status code of the response.
51 void setStatusCode (uint32_t statusCode);
52
53 // Get the headers of the response.
54 QmlZhash *headers ();
55
56 // Get the content length of the response
57 size_t contentLength ();
58
59 // Get the content of the response.
60 const QString content ();
61
62 // Get the content of the response.
63 QString getContent ();
64
65 // Set the content of the response.
66 // Content must by dynamically allocated string.
67 // Takes ownership of the content.
68 void setContent (QString content);
69
70 // Set the content of the response.
71 // The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
72 void setContentConst (const QString &content);
73
74 // Set the content to NULL
75 void resetContent ();
76 };
77
78 class QmlZhttpResponseAttached : public QObject
79 {
80 Q_OBJECT
81 QObject* m_attached;
82
83 public:
84 QmlZhttpResponseAttached (QObject* attached) {
85 Q_UNUSED (attached);
86 };
87
88 public slots:
89 // Self test of this class.
90 void test (bool verbose);
91
92 // Create a new zhttp_response.
93 QmlZhttpResponse *construct ();
94
95 // Destroy the zhttp_response.
96 void destruct (QmlZhttpResponse *qmlSelf);
97 };
98
99
100 QML_DECLARE_TYPEINFO(QmlZhttpResponse, QML_HAS_ATTACHED_PROPERTIES)
101
102 #endif
103 /*
104 ################################################################################
105 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
106 # Read the zproject/README.md for information about making permanent changes. #
107 ################################################################################
108 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #include "QmlZhttpServer.h"
8
9
10 ///
11 // Return the port the server is listening on.
12 int QmlZhttpServer::port () {
13 return zhttp_server_port (self);
14 };
15
16
17 QObject* QmlZhttpServer::qmlAttachedProperties(QObject* object) {
18 return new QmlZhttpServerAttached(object);
19 }
20
21
22 ///
23 // Self test of this class.
24 void QmlZhttpServerAttached::test (bool verbose) {
25 zhttp_server_test (verbose);
26 };
27
28 ///
29 // Create a new http server
30 QmlZhttpServer *QmlZhttpServerAttached::construct (QmlZhttpServerOptions *options) {
31 QmlZhttpServer *qmlSelf = new QmlZhttpServer ();
32 qmlSelf->self = zhttp_server_new (options->self);
33 return qmlSelf;
34 };
35
36 ///
37 // Destroy an http server
38 void QmlZhttpServerAttached::destruct (QmlZhttpServer *qmlSelf) {
39 zhttp_server_destroy (&qmlSelf->self);
40 };
41
42 /*
43 ################################################################################
44 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
45 # Read the zproject/README.md for information about making permanent changes. #
46 ################################################################################
47 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #ifndef QML_ZHTTP_SERVER_H
8 #define QML_ZHTTP_SERVER_H
9
10 #include <QtQml>
11
12 #include <czmq.h>
13 #include "qml_czmq_plugin.h"
14
15
16 class QmlZhttpServer : public QObject
17 {
18 Q_OBJECT
19 Q_PROPERTY(bool isNULL READ isNULL)
20
21 public:
22 zhttp_server_t *self;
23
24 QmlZhttpServer() { self = NULL; }
25 bool isNULL() { return self == NULL; }
26
27 static QObject* qmlAttachedProperties(QObject* object); // defined in QmlZhttpServer.cpp
28
29 public slots:
30 // Return the port the server is listening on.
31 int port ();
32 };
33
34 class QmlZhttpServerAttached : public QObject
35 {
36 Q_OBJECT
37 QObject* m_attached;
38
39 public:
40 QmlZhttpServerAttached (QObject* attached) {
41 Q_UNUSED (attached);
42 };
43
44 public slots:
45 // Self test of this class.
46 void test (bool verbose);
47
48 // Create a new http server
49 QmlZhttpServer *construct (QmlZhttpServerOptions *options);
50
51 // Destroy an http server
52 void destruct (QmlZhttpServer *qmlSelf);
53 };
54
55
56 QML_DECLARE_TYPEINFO(QmlZhttpServer, QML_HAS_ATTACHED_PROPERTIES)
57
58 #endif
59 /*
60 ################################################################################
61 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
62 # Read the zproject/README.md for information about making permanent changes. #
63 ################################################################################
64 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #include "QmlZhttpServerConnection.h"
8
9
10
11 QObject* QmlZhttpServerConnection::qmlAttachedProperties(QObject* object) {
12 return new QmlZhttpServerConnectionAttached(object);
13 }
14
15
16 ///
17 // Self test of this class.
18 void QmlZhttpServerConnectionAttached::test (bool verbose) {
19 zhttp_server_connection_test (verbose);
20 };
21
22 /*
23 ################################################################################
24 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
25 # Read the zproject/README.md for information about making permanent changes. #
26 ################################################################################
27 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #ifndef QML_ZHTTP_SERVER_CONNECTION_H
8 #define QML_ZHTTP_SERVER_CONNECTION_H
9
10 #include <QtQml>
11
12 #include <czmq.h>
13 #include "qml_czmq_plugin.h"
14
15
16 class QmlZhttpServerConnection : public QObject
17 {
18 Q_OBJECT
19 Q_PROPERTY(bool isNULL READ isNULL)
20
21 public:
22 zhttp_server_connection_t *self;
23
24 QmlZhttpServerConnection() { self = NULL; }
25 bool isNULL() { return self == NULL; }
26
27 static QObject* qmlAttachedProperties(QObject* object); // defined in QmlZhttpServerConnection.cpp
28
29 public slots:};
30
31 class QmlZhttpServerConnectionAttached : public QObject
32 {
33 Q_OBJECT
34 QObject* m_attached;
35
36 public:
37 QmlZhttpServerConnectionAttached (QObject* attached) {
38 Q_UNUSED (attached);
39 };
40
41 public slots:
42 // Self test of this class.
43 void test (bool verbose);
44 };
45
46
47 QML_DECLARE_TYPEINFO(QmlZhttpServerConnection, QML_HAS_ATTACHED_PROPERTIES)
48
49 #endif
50 /*
51 ################################################################################
52 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
53 # Read the zproject/README.md for information about making permanent changes. #
54 ################################################################################
55 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #include "QmlZhttpServerOptions.h"
8
9
10 ///
11 // Get the server listening port.
12 int QmlZhttpServerOptions::port () {
13 return zhttp_server_options_port (self);
14 };
15
16 ///
17 // Set the server listening port
18 void QmlZhttpServerOptions::setPort (int port) {
19 zhttp_server_options_set_port (self, port);
20 };
21
22 ///
23 // Get the address sockets should connect to in order to receive requests.
24 const QString QmlZhttpServerOptions::backendAddress () {
25 return QString (zhttp_server_options_backend_address (self));
26 };
27
28 ///
29 // Set the address sockets should connect to in order to receive requests.
30 void QmlZhttpServerOptions::setBackendAddress (const QString &address) {
31 zhttp_server_options_set_backend_address (self, address.toUtf8().data());
32 };
33
34
35 QObject* QmlZhttpServerOptions::qmlAttachedProperties(QObject* object) {
36 return new QmlZhttpServerOptionsAttached(object);
37 }
38
39
40 ///
41 // Self test of this class.
42 void QmlZhttpServerOptionsAttached::test (bool verbose) {
43 zhttp_server_options_test (verbose);
44 };
45
46 ///
47 // Create a new zhttp_server_options.
48 QmlZhttpServerOptions *QmlZhttpServerOptionsAttached::construct () {
49 QmlZhttpServerOptions *qmlSelf = new QmlZhttpServerOptions ();
50 qmlSelf->self = zhttp_server_options_new ();
51 return qmlSelf;
52 };
53
54 ///
55 // Create options from config tree.
56 QmlZhttpServerOptions *QmlZhttpServerOptionsAttached::fromConfig (QmlZconfig *config) {
57 QmlZhttpServerOptions *qmlSelf = new QmlZhttpServerOptions ();
58 qmlSelf->self = zhttp_server_options_from_config (config->self);
59 return qmlSelf;
60 };
61
62 ///
63 // Destroy the zhttp_server_options.
64 void QmlZhttpServerOptionsAttached::destruct (QmlZhttpServerOptions *qmlSelf) {
65 zhttp_server_options_destroy (&qmlSelf->self);
66 };
67
68 /*
69 ################################################################################
70 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
71 # Read the zproject/README.md for information about making permanent changes. #
72 ################################################################################
73 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #ifndef QML_ZHTTP_SERVER_OPTIONS_H
8 #define QML_ZHTTP_SERVER_OPTIONS_H
9
10 #include <QtQml>
11
12 #include <czmq.h>
13 #include "qml_czmq_plugin.h"
14
15
16 class QmlZhttpServerOptions : public QObject
17 {
18 Q_OBJECT
19 Q_PROPERTY(bool isNULL READ isNULL)
20
21 public:
22 zhttp_server_options_t *self;
23
24 QmlZhttpServerOptions() { self = NULL; }
25 bool isNULL() { return self == NULL; }
26
27 static QObject* qmlAttachedProperties(QObject* object); // defined in QmlZhttpServerOptions.cpp
28
29 public slots:
30 // Get the server listening port.
31 int port ();
32
33 // Set the server listening port
34 void setPort (int port);
35
36 // Get the address sockets should connect to in order to receive requests.
37 const QString backendAddress ();
38
39 // Set the address sockets should connect to in order to receive requests.
40 void setBackendAddress (const QString &address);
41 };
42
43 class QmlZhttpServerOptionsAttached : public QObject
44 {
45 Q_OBJECT
46 QObject* m_attached;
47
48 public:
49 QmlZhttpServerOptionsAttached (QObject* attached) {
50 Q_UNUSED (attached);
51 };
52
53 public slots:
54 // Self test of this class.
55 void test (bool verbose);
56
57 // Create a new zhttp_server_options.
58 QmlZhttpServerOptions *construct ();
59
60 // Create options from config tree.
61 QmlZhttpServerOptions *fromConfig (QmlZconfig *config);
62
63 // Destroy the zhttp_server_options.
64 void destruct (QmlZhttpServerOptions *qmlSelf);
65 };
66
67
68 QML_DECLARE_TYPEINFO(QmlZhttpServerOptions, QML_HAS_ATTACHED_PROPERTIES)
69
70 #endif
71 /*
72 ################################################################################
73 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
74 # Read the zproject/README.md for information about making permanent changes. #
75 ################################################################################
76 */
201201 zlistx_set_comparator (self, comparator);
202202 };
203203
204 ///
205 // Serialize list to a binary frame that can be sent in a message.
206 // The packed format is compatible with the 'strings' type implemented by zproto:
207 //
208 // ; A list of strings
209 // list = list-count *longstr
210 // list-count = number-4
211 //
212 // ; Strings are always length + text contents
213 // longstr = number-4 *VCHAR
214 //
215 // ; Numbers are unsigned integers in network byte order
216 // number-4 = 4OCTET
217 QmlZframe *QmlZlistx::pack () {
218 QmlZframe *retQ_ = new QmlZframe ();
219 retQ_->self = zlistx_pack (self);
220 return retQ_;
221 };
222
204223
205224 QObject* QmlZlistx::qmlAttachedProperties(QObject* object) {
206225 return new QmlZlistxAttached(object);
229248 };
230249
231250 ///
251 // Unpack binary frame into a new list. Packed data must follow format
252 // defined by zlistx_pack. List is set to autofree. An empty frame
253 // unpacks to an empty list.
254 QmlZlistx *QmlZlistxAttached::unpack (QmlZframe *frame) {
255 QmlZlistx *qmlSelf = new QmlZlistx ();
256 qmlSelf->self = zlistx_unpack (frame->self);
257 return qmlSelf;
258 };
259
260 ///
232261 // Destroy a list. If an item destructor was specified, all items in the
233262 // list are automatically destroyed as well.
234263 void QmlZlistxAttached::destruct (QmlZlistx *qmlSelf) {
143143 // must return -1, 0, or 1 depending on whether item1 is less than, equal to,
144144 // or greater than, item2.
145145 void setComparator (zlistx_comparator_fn comparator);
146
147 // Serialize list to a binary frame that can be sent in a message.
148 // The packed format is compatible with the 'strings' type implemented by zproto:
149 //
150 // ; A list of strings
151 // list = list-count *longstr
152 // list-count = number-4
153 //
154 // ; Strings are always length + text contents
155 // longstr = number-4 *VCHAR
156 //
157 // ; Numbers are unsigned integers in network byte order
158 // number-4 = 4OCTET
159 QmlZframe *pack ();
146160 };
147161
148162 class QmlZlistxAttached : public QObject
166180 // Create a new, empty list.
167181 QmlZlistx *construct ();
168182
183 // Unpack binary frame into a new list. Packed data must follow format
184 // defined by zlistx_pack. List is set to autofree. An empty frame
185 // unpacks to an empty list.
186 QmlZlistx *unpack (QmlZframe *frame);
187
169188 // Destroy a list. If an item destructor was specified, all items in the
170189 // list are automatically destroyed as well.
171190 void destruct (QmlZlistx *qmlSelf);
106106 };
107107
108108 ///
109 // The timeout should be zero or greater, or -1 to wait indefinitely.
109110 // wait or poll process status, return return code
110 int QmlZproc::wait (bool hang) {
111 return zproc_wait (self, hang);
111 int QmlZproc::wait (int timeout) {
112 return zproc_wait (self, timeout);
112113 };
113114
114115 ///
115 // return internal actor, usefull for the polling if process died
116 // send SIGTERM signal to the subprocess, wait for grace period and
117 // eventually send SIGKILL
118 void QmlZproc::shutdown (int timeout) {
119 zproc_shutdown (self, timeout);
120 };
121
122 ///
123 // return internal actor, useful for the polling if process died
116124 void *QmlZproc::actor () {
117125 return zproc_actor (self);
118126 };
8181 // return true if process is running, false if not yet started or finished
8282 bool running ();
8383
84 // The timeout should be zero or greater, or -1 to wait indefinitely.
8485 // wait or poll process status, return return code
85 int wait (bool hang);
86 int wait (int timeout);
8687
87 // return internal actor, usefull for the polling if process died
88 // send SIGTERM signal to the subprocess, wait for grace period and
89 // eventually send SIGKILL
90 void shutdown (int timeout);
91
92 // return internal actor, useful for the polling if process died
8893 void *actor ();
8994
9095 // send a signal to the subprocess
9494 // c = zchunk_t *
9595 // f = zframe_t *
9696 // h = zhashx_t *
97 // l = zlistx_t * (DRAFT)
9798 // U = zuuid_t *
9899 // p = void * (sends the pointer value, only meaningful over inproc)
99100 // m = zmsg_t * (sends all frames in the zmsg)
131132 // f = zframe_t ** (creates zframe)
132133 // U = zuuid_t * (creates a zuuid with the data)
133134 // h = zhashx_t ** (creates zhashx)
135 // l = zlistx_t ** (creates zlistx) (DRAFT)
134136 // p = void ** (stores pointer)
135 // m = zmsg_t ** (creates a zmsg with the remaing frames)
137 // m = zmsg_t ** (creates a zmsg with the remaining frames)
136138 // z = null, asserts empty frame (0 arguments)
137139 // u = uint * (stores unsigned integer, deprecated)
138140 //
268270 };
269271
270272 ///
273 // Check whether the socket has available message to read.
274 bool QmlZsock::hasIn () {
275 return zsock_has_in (self);
276 };
277
278 ///
279 // Get socket option `router_notify`.
280 // Available from libzmq 4.3.0.
281 int QmlZsock::routerNotify () {
282 return zsock_router_notify (self);
283 };
284
285 ///
286 // Set socket option `router_notify`.
287 // Available from libzmq 4.3.0.
288 void QmlZsock::setRouterNotify (int routerNotify) {
289 zsock_set_router_notify (self, routerNotify);
290 };
291
292 ///
293 // Get socket option `multicast_loop`.
294 // Available from libzmq 4.3.0.
295 int QmlZsock::multicastLoop () {
296 return zsock_multicast_loop (self);
297 };
298
299 ///
300 // Set socket option `multicast_loop`.
301 // Available from libzmq 4.3.0.
302 void QmlZsock::setMulticastLoop (int multicastLoop) {
303 zsock_set_multicast_loop (self, multicastLoop);
304 };
305
306 ///
307 // Get socket option `metadata`.
308 // Available from libzmq 4.3.0.
309 QString QmlZsock::metadata () {
310 char *retStr_ = zsock_metadata (self);
311 QString retQStr_ = QString (retStr_);
312 free (retStr_);
313 return retQStr_;
314 };
315
316 ///
317 // Set socket option `metadata`.
318 // Available from libzmq 4.3.0.
319 void QmlZsock::setMetadata (const QString &metadata) {
320 zsock_set_metadata (self, metadata.toUtf8().data());
321 };
322
323 ///
324 // Get socket option `loopback_fastpath`.
325 // Available from libzmq 4.3.0.
326 int QmlZsock::loopbackFastpath () {
327 return zsock_loopback_fastpath (self);
328 };
329
330 ///
331 // Set socket option `loopback_fastpath`.
332 // Available from libzmq 4.3.0.
333 void QmlZsock::setLoopbackFastpath (int loopbackFastpath) {
334 zsock_set_loopback_fastpath (self, loopbackFastpath);
335 };
336
337 ///
338 // Get socket option `zap_enforce_domain`.
339 // Available from libzmq 4.3.0.
340 int QmlZsock::zapEnforceDomain () {
341 return zsock_zap_enforce_domain (self);
342 };
343
344 ///
345 // Set socket option `zap_enforce_domain`.
346 // Available from libzmq 4.3.0.
347 void QmlZsock::setZapEnforceDomain (int zapEnforceDomain) {
348 zsock_set_zap_enforce_domain (self, zapEnforceDomain);
349 };
350
351 ///
352 // Get socket option `gssapi_principal_nametype`.
353 // Available from libzmq 4.3.0.
354 int QmlZsock::gssapiPrincipalNametype () {
355 return zsock_gssapi_principal_nametype (self);
356 };
357
358 ///
359 // Set socket option `gssapi_principal_nametype`.
360 // Available from libzmq 4.3.0.
361 void QmlZsock::setGssapiPrincipalNametype (int gssapiPrincipalNametype) {
362 zsock_set_gssapi_principal_nametype (self, gssapiPrincipalNametype);
363 };
364
365 ///
366 // Get socket option `gssapi_service_principal_nametype`.
367 // Available from libzmq 4.3.0.
368 int QmlZsock::gssapiServicePrincipalNametype () {
369 return zsock_gssapi_service_principal_nametype (self);
370 };
371
372 ///
373 // Set socket option `gssapi_service_principal_nametype`.
374 // Available from libzmq 4.3.0.
375 void QmlZsock::setGssapiServicePrincipalNametype (int gssapiServicePrincipalNametype) {
376 zsock_set_gssapi_service_principal_nametype (self, gssapiServicePrincipalNametype);
377 };
378
379 ///
380 // Get socket option `bindtodevice`.
381 // Available from libzmq 4.3.0.
382 QString QmlZsock::bindtodevice () {
383 char *retStr_ = zsock_bindtodevice (self);
384 QString retQStr_ = QString (retStr_);
385 free (retStr_);
386 return retQStr_;
387 };
388
389 ///
390 // Set socket option `bindtodevice`.
391 // Available from libzmq 4.3.0.
392 void QmlZsock::setBindtodevice (const QString &bindtodevice) {
393 zsock_set_bindtodevice (self, bindtodevice.toUtf8().data());
394 };
395
396 ///
271397 // Get socket option `heartbeat_ivl`.
272398 // Available from libzmq 4.2.0.
273399 int QmlZsock::heartbeatIvl () {
9292 // c = zchunk_t *
9393 // f = zframe_t *
9494 // h = zhashx_t *
95 // l = zlistx_t * (DRAFT)
9596 // U = zuuid_t *
9697 // p = void * (sends the pointer value, only meaningful over inproc)
9798 // m = zmsg_t * (sends all frames in the zmsg)
123124 // f = zframe_t ** (creates zframe)
124125 // U = zuuid_t * (creates a zuuid with the data)
125126 // h = zhashx_t ** (creates zhashx)
127 // l = zlistx_t ** (creates zlistx) (DRAFT)
126128 // p = void ** (stores pointer)
127 // m = zmsg_t ** (creates a zmsg with the remaing frames)
129 // m = zmsg_t ** (creates a zmsg with the remaining frames)
128130 // z = null, asserts empty frame (0 arguments)
129131 // u = uint * (stores unsigned integer, deprecated)
130132 //
224226 // Returns 0 if OK, -1 if failed.
225227 int leave (const QString &group);
226228
229 // Check whether the socket has available message to read.
230 bool hasIn ();
231
232 // Get socket option `router_notify`.
233 // Available from libzmq 4.3.0.
234 int routerNotify ();
235
236 // Set socket option `router_notify`.
237 // Available from libzmq 4.3.0.
238 void setRouterNotify (int routerNotify);
239
240 // Get socket option `multicast_loop`.
241 // Available from libzmq 4.3.0.
242 int multicastLoop ();
243
244 // Set socket option `multicast_loop`.
245 // Available from libzmq 4.3.0.
246 void setMulticastLoop (int multicastLoop);
247
248 // Get socket option `metadata`.
249 // Available from libzmq 4.3.0.
250 QString metadata ();
251
252 // Set socket option `metadata`.
253 // Available from libzmq 4.3.0.
254 void setMetadata (const QString &metadata);
255
256 // Get socket option `loopback_fastpath`.
257 // Available from libzmq 4.3.0.
258 int loopbackFastpath ();
259
260 // Set socket option `loopback_fastpath`.
261 // Available from libzmq 4.3.0.
262 void setLoopbackFastpath (int loopbackFastpath);
263
264 // Get socket option `zap_enforce_domain`.
265 // Available from libzmq 4.3.0.
266 int zapEnforceDomain ();
267
268 // Set socket option `zap_enforce_domain`.
269 // Available from libzmq 4.3.0.
270 void setZapEnforceDomain (int zapEnforceDomain);
271
272 // Get socket option `gssapi_principal_nametype`.
273 // Available from libzmq 4.3.0.
274 int gssapiPrincipalNametype ();
275
276 // Set socket option `gssapi_principal_nametype`.
277 // Available from libzmq 4.3.0.
278 void setGssapiPrincipalNametype (int gssapiPrincipalNametype);
279
280 // Get socket option `gssapi_service_principal_nametype`.
281 // Available from libzmq 4.3.0.
282 int gssapiServicePrincipalNametype ();
283
284 // Set socket option `gssapi_service_principal_nametype`.
285 // Available from libzmq 4.3.0.
286 void setGssapiServicePrincipalNametype (int gssapiServicePrincipalNametype);
287
288 // Get socket option `bindtodevice`.
289 // Available from libzmq 4.3.0.
290 QString bindtodevice ();
291
292 // Set socket option `bindtodevice`.
293 // Available from libzmq 4.3.0.
294 void setBindtodevice (const QString &bindtodevice);
295
227296 // Get socket option `heartbeat_ivl`.
228297 // Available from libzmq 4.2.0.
229298 int heartbeatIvl ();
8585 ///
8686 // Set default interrupt handler, so Ctrl-C or SIGTERM will set
8787 // zsys_interrupted. Idempotent; safe to call multiple times.
88 // Can be supressed by ZSYS_SIGHANDLER=false
88 // Can be suppressed by ZSYS_SIGHANDLER=false
8989 // *** This is for CZMQ internal use only and may change arbitrarily ***
9090 void QmlZsysAttached::catchInterrupts () {
9191 zsys_catch_interrupts ();
177177 // number into provided fields, providing reference isn't null in each case.
178178 void QmlZsysAttached::version (int *major, int *minor, int *patch) {
179179 zsys_version (major, minor, patch);
180 };
181
182 ///
183 // Format a string using printf formatting, returning a freshly allocated
184 // buffer. If there was insufficient memory, returns NULL. Free the returned
185 // string using zstr_free(). The hinted version allows to optimize by using
186 // a larger starting buffer size (known to/assumed by the developer) and so
187 // avoid reallocations.
188 const QString QmlZsysAttached::sprintfHint (int hint, const QString &format) {
189 return QString (zsys_sprintf_hint (hint, format.toUtf8().data()));
180190 };
181191
182192 ///
301311 // Note that this method is valid only before any socket is created.
302312 void QmlZsysAttached::setThreadPriority (int priority) {
303313 zsys_set_thread_priority (priority);
314 };
315
316 ///
317 // Configure the numeric prefix to each thread created for the internal
318 // context's thread pool. This option is only supported on Linux.
319 // If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
320 // provides the default.
321 // Note that this method is valid only before any socket is created.
322 void QmlZsysAttached::setThreadNamePrefix (int prefix) {
323 zsys_set_thread_name_prefix (prefix);
324 };
325
326 ///
327 // Return thread name prefix.
328 int QmlZsysAttached::threadNamePrefix () {
329 return zsys_thread_name_prefix ();
330 };
331
332 ///
333 // Adds a specific CPU to the affinity list of the ZMQ context thread pool.
334 // This option is only supported on Linux.
335 // Note that this method is valid only before any socket is created.
336 void QmlZsysAttached::threadAffinityCpuAdd (int cpu) {
337 zsys_thread_affinity_cpu_add (cpu);
338 };
339
340 ///
341 // Removes a specific CPU to the affinity list of the ZMQ context thread pool.
342 // This option is only supported on Linux.
343 // Note that this method is valid only before any socket is created.
344 void QmlZsysAttached::threadAffinityCpuRemove (int cpu) {
345 zsys_thread_affinity_cpu_remove (cpu);
304346 };
305347
306348 ///
489531 // Return use of automatic pre-allocated FDs for zsock instances.
490532 int QmlZsysAttached::autoUseFd () {
491533 return zsys_auto_use_fd ();
534 };
535
536 ///
537 // Print formatted string. Format is specified by variable names
538 // in Python-like format style
539 //
540 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
541 // become
542 // "key=value"
543 //
544 // Returns freshly allocated string or NULL in a case of error.
545 // Not enough memory, invalid format specifier, name not in args
546 QString QmlZsysAttached::zprintf (const QString &format, QmlZhash *args) {
547 char *retStr_ = zsys_zprintf (format.toUtf8().data(), args->self);
548 QString retQStr_ = QString (retStr_);
549 free (retStr_);
550 return retQStr_;
551 };
552
553 ///
554 // Return error string for given format/args combination.
555 QString QmlZsysAttached::zprintfError (const QString &format, QmlZhash *args) {
556 char *retStr_ = zsys_zprintf_error (format.toUtf8().data(), args->self);
557 QString retQStr_ = QString (retStr_);
558 free (retStr_);
559 return retQStr_;
560 };
561
562 ///
563 // Print formatted string. Format is specified by variable names
564 // in Python-like format style
565 //
566 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
567 // become
568 // "key=value"
569 //
570 // Returns freshly allocated string or NULL in a case of error.
571 // Not enough memory, invalid format specifier, name not in args
572 QString QmlZsysAttached::zplprintf (const QString &format, QmlZconfig *args) {
573 char *retStr_ = zsys_zplprintf (format.toUtf8().data(), args->self);
574 QString retQStr_ = QString (retStr_);
575 free (retStr_);
576 return retQStr_;
577 };
578
579 ///
580 // Return error string for given format/args combination.
581 QString QmlZsysAttached::zplprintfError (const QString &format, QmlZconfig *args) {
582 char *retStr_ = zsys_zplprintf_error (format.toUtf8().data(), args->self);
583 QString retQStr_ = QString (retStr_);
584 free (retStr_);
585 return retQStr_;
492586 };
493587
494588 ///
8484
8585 // Set default interrupt handler, so Ctrl-C or SIGTERM will set
8686 // zsys_interrupted. Idempotent; safe to call multiple times.
87 // Can be supressed by ZSYS_SIGHANDLER=false
87 // Can be suppressed by ZSYS_SIGHANDLER=false
8888 // *** This is for CZMQ internal use only and may change arbitrarily ***
8989 void catchInterrupts ();
9090
136136 // Return the CZMQ version for run-time API detection; returns version
137137 // number into provided fields, providing reference isn't null in each case.
138138 void version (int *major, int *minor, int *patch);
139
140 // Format a string using printf formatting, returning a freshly allocated
141 // buffer. If there was insufficient memory, returns NULL. Free the returned
142 // string using zstr_free(). The hinted version allows to optimize by using
143 // a larger starting buffer size (known to/assumed by the developer) and so
144 // avoid reallocations.
145 const QString sprintfHint (int hint, const QString &format);
139146
140147 // Format a string using printf formatting, returning a freshly allocated
141148 // buffer. If there was insufficient memory, returns NULL. Free the returned
216223 // defined, that provides the default.
217224 // Note that this method is valid only before any socket is created.
218225 void setThreadPriority (int priority);
226
227 // Configure the numeric prefix to each thread created for the internal
228 // context's thread pool. This option is only supported on Linux.
229 // If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
230 // provides the default.
231 // Note that this method is valid only before any socket is created.
232 void setThreadNamePrefix (int prefix);
233
234 // Return thread name prefix.
235 int threadNamePrefix ();
236
237 // Adds a specific CPU to the affinity list of the ZMQ context thread pool.
238 // This option is only supported on Linux.
239 // Note that this method is valid only before any socket is created.
240 void threadAffinityCpuAdd (int cpu);
241
242 // Removes a specific CPU to the affinity list of the ZMQ context thread pool.
243 // This option is only supported on Linux.
244 // Note that this method is valid only before any socket is created.
245 void threadAffinityCpuRemove (int cpu);
219246
220247 // Configure the number of sockets that ZeroMQ will allow. The default
221248 // is 1024. The actual limit depends on the system, and you can query it
335362
336363 // Return use of automatic pre-allocated FDs for zsock instances.
337364 int autoUseFd ();
365
366 // Print formatted string. Format is specified by variable names
367 // in Python-like format style
368 //
369 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
370 // become
371 // "key=value"
372 //
373 // Returns freshly allocated string or NULL in a case of error.
374 // Not enough memory, invalid format specifier, name not in args
375 QString zprintf (const QString &format, QmlZhash *args);
376
377 // Return error string for given format/args combination.
378 QString zprintfError (const QString &format, QmlZhash *args);
379
380 // Print formatted string. Format is specified by variable names
381 // in Python-like format style
382 //
383 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
384 // become
385 // "key=value"
386 //
387 // Returns freshly allocated string or NULL in a case of error.
388 // Not enough memory, invalid format specifier, name not in args
389 QString zplprintf (const QString &format, QmlZconfig *args);
390
391 // Return error string for given format/args combination.
392 QString zplprintfError (const QString &format, QmlZconfig *args);
338393
339394 // Set log identity, which is a string that prefixes all log messages sent
340395 // by this process. The log identity defaults to the environment variable
6666 class QmlZtrieAttached;
6767 class QmlZuuid;
6868 class QmlZuuidAttached;
69 class QmlZhttpClient;
70 class QmlZhttpClientAttached;
71 class QmlZhttpServer;
72 class QmlZhttpServerAttached;
73 class QmlZhttpServerOptions;
74 class QmlZhttpServerOptionsAttached;
75 class QmlZhttpRequest;
76 class QmlZhttpRequestAttached;
77 class QmlZhttpResponse;
78 class QmlZhttpResponseAttached;
6979
7080 #include "QmlZactor.h"
7181 #include "QmlZargs.h"
95105 #include "QmlZtimerset.h"
96106 #include "QmlZtrie.h"
97107 #include "QmlZuuid.h"
108 #include "QmlZhttpClient.h"
109 #include "QmlZhttpServer.h"
110 #include "QmlZhttpServerOptions.h"
111 #include "QmlZhttpRequest.h"
112 #include "QmlZhttpResponse.h"
98113
99114 class QmlCZMQPlugin : public QQmlExtensionPlugin
100115 {
160175 qmlRegisterType<QmlZtrieAttached>();
161176 qmlRegisterType<QmlZuuid> (uri, 1, 0, "QmlZuuid");
162177 qmlRegisterType<QmlZuuidAttached>();
178 qmlRegisterType<QmlZhttpClient> (uri, 1, 0, "QmlZhttpClient");
179 qmlRegisterType<QmlZhttpClientAttached>();
180 qmlRegisterType<QmlZhttpServer> (uri, 1, 0, "QmlZhttpServer");
181 qmlRegisterType<QmlZhttpServerAttached>();
182 qmlRegisterType<QmlZhttpServerOptions> (uri, 1, 0, "QmlZhttpServerOptions");
183 qmlRegisterType<QmlZhttpServerOptionsAttached>();
184 qmlRegisterType<QmlZhttpRequest> (uri, 1, 0, "QmlZhttpRequest");
185 qmlRegisterType<QmlZhttpRequestAttached>();
186 qmlRegisterType<QmlZhttpResponse> (uri, 1, 0, "QmlZhttpResponse");
187 qmlRegisterType<QmlZhttpResponseAttached>();
163188 };
164189 };
165190
22 # Read the zproject/README.md for information about making permanent changes. #
33 ################################################################################
44 TEMPLATE = lib
5 VERSION = 4.1.1
5 VERSION = 4.2.0
66 CONFIG += qt dll qczmq-buildlib
77 mac:CONFIG += absolute_library_soname
88 win32|mac:!wince*:!win32-msvc:!macx-xcode:CONFIG += debug_and_release build_all
4444 QZtimerset::test (verbose);
4545 QZtrie::test (verbose);
4646 QZuuid::test (verbose);
47 QZhttpClient::test (verbose);
48 QZhttpServer::test (verbose);
49 QZhttpServerOptions::test (verbose);
50 QZhttpRequest::test (verbose);
51 QZhttpResponse::test (verbose);
4752
4853 qDebug() << "Tests passed OK\n";
4954 return 0;
33 # Read the zproject/README.md for information about making permanent changes. #
44 ################################################################################
55 */
6 #ifndef Q_CZMQ_H
7 #define Q_CZMQ_H
6 #ifndef Q_QCZMQ_H
7 #define Q_QCZMQ_H
88
99 #include <QObject>
1010 #include <QString>
5555 class QZtimerset;
5656 class QZtrie;
5757 class QZuuid;
58 class QZhttpClient;
59 class QZhttpServer;
60 class QZhttpServerOptions;
61 class QZhttpRequest;
62 class QZhttpResponse;
5863
5964 // Public API classes
6065 #include "qzactor.h"
8590 #include "qztimerset.h"
8691 #include "qztrie.h"
8792 #include "qzuuid.h"
93 #include "qzhttpclient.h"
94 #include "qzhttpserver.h"
95 #include "qzhttpserveroptions.h"
96 #include "qzhttprequest.h"
97 #include "qzhttpresponse.h"
8898
8999 #endif // Q_CZMQ_H
90100 /*
3737 $$PWD/qzsys.h \
3838 $$PWD/qztimerset.h \
3939 $$PWD/qztrie.h \
40 $$PWD/qzuuid.h
40 $$PWD/qzuuid.h \
41 $$PWD/qzhttpclient.h \
42 $$PWD/qzhttpserver.h \
43 $$PWD/qzhttpserveroptions.h \
44 $$PWD/qzhttprequest.h \
45 $$PWD/qzhttpresponse.h
4146
4247 SOURCES += \
4348 $$PWD/qzactor.cpp \
6772 $$PWD/qzsys.cpp \
6873 $$PWD/qztimerset.cpp \
6974 $$PWD/qztrie.cpp \
70 $$PWD/qzuuid.cpp
75 $$PWD/qzuuid.cpp \
76 $$PWD/qzhttpclient.cpp \
77 $$PWD/qzhttpserver.cpp \
78 $$PWD/qzhttpserveroptions.cpp \
79 $$PWD/qzhttprequest.cpp \
80 $$PWD/qzhttpresponse.cpp
7181 }
7282
7383 win32 {
7272 }
7373
7474 ///
75 // Return current parameter name, or NULL if there are no named
76 // parameters.
75 // Return current parameter name, or NULL if there are no named parameters.
7776 const QString QZargs::paramName ()
7877 {
7978 const QString rv = QString (zargs_param_name (self));
8180 }
8281
8382 ///
84 // Return value of named parameter, NULL if no given parameter has
85 // been specified, or special value for wich zargs_param_empty ()
86 // returns true.
87 const QString QZargs::paramLookup (const QString &keys)
83 // Return value of named parameter or NULL is it has no value (or was not specified)
84 const QString QZargs::get (const QString &name)
8885 {
89 const QString rv = QString (zargs_param_lookup (self, keys.toUtf8().data()));
86 const QString rv = QString (zargs_get (self, name.toUtf8().data()));
9087 return rv;
9188 }
9289
9390 ///
94 // Returns true if there are --help -h arguments
95 bool QZargs::hasHelp ()
91 // Returns true if named parameter was specified on command line
92 bool QZargs::has (const QString &name)
9693 {
97 bool rv = zargs_has_help (self);
98 return rv;
99 }
100
101 ///
102 // Returns true if parameter did not have a value
103 bool QZargs::paramEmpty (const QString &arg)
104 {
105 bool rv = zargs_param_empty (arg.toUtf8().data());
94 bool rv = zargs_has (self, name.toUtf8().data());
10695 return rv;
10796 }
10897
3939 // parameters, or value for which zargs_param_empty (arg) returns true.
4040 const QString paramNext ();
4141
42 // Return current parameter name, or NULL if there are no named
43 // parameters.
42 // Return current parameter name, or NULL if there are no named parameters.
4443 const QString paramName ();
4544
46 // Return value of named parameter, NULL if no given parameter has
47 // been specified, or special value for wich zargs_param_empty ()
48 // returns true.
49 const QString paramLookup (const QString &keys);
45 // Return value of named parameter or NULL is it has no value (or was not specified)
46 const QString get (const QString &name);
5047
51 // Returns true if there are --help -h arguments
52 bool hasHelp ();
53
54 // Returns true if parameter did not have a value
55 static bool paramEmpty (const QString &arg);
48 // Returns true if named parameter was specified on command line
49 bool has (const QString &name);
5650
5751 // Print an instance of zargs.
5852 void print ();
2121 QZchunk::QZchunk (const void *data, size_t size, QObject *qObjParent) : QObject (qObjParent)
2222 {
2323 this->self = zchunk_new (data, size);
24 }
25
26 ///
27 // Create a new chunk from memory. Take ownership of the memory and calling the destructor
28 // on destroy.
29 QZchunk* QZchunk::frommem (void *data, size_t size, zchunk_destructor_fn destructor, void *hint, QObject *qObjParent)
30 {
31 return new QZchunk (zchunk_frommem (data, size, destructor, hint), qObjParent);
2432 }
2533
2634 ///
194202 }
195203
196204 ///
205 // Transform zchunk into a zframe that can be sent in a message.
206 // Take ownership of the chunk.
207 QZframe * QZchunk::packx ()
208 {
209 QZframe *rv = new QZframe (zchunk_packx (&self));
210 return rv;
211 }
212
213 ///
197214 // Transform a zframe into a zchunk.
198215 QZchunk * QZchunk::unpack (QZframe *frame)
199216 {
2020 // is copied into the chunk. If you do not specify the data, the chunk is
2121 // allocated and left empty, and you can then add data using zchunk_append.
2222 explicit QZchunk (const void *data, size_t size, QObject *qObjParent = 0);
23
24 // Create a new chunk from memory. Take ownership of the memory and calling the destructor
25 // on destroy.
26 static QZchunk* frommem (void *data, size_t size, zchunk_destructor_fn destructor, void *hint, QObject *qObjParent = 0);
2327
2428 // Destroy a chunk
2529 ~QZchunk ();
9397 // Transform zchunk into a zframe that can be sent in a message.
9498 QZframe * pack ();
9599
100 // Transform zchunk into a zframe that can be sent in a message.
101 // Take ownership of the chunk.
102 QZframe * packx ();
103
96104 // Transform a zframe into a zchunk.
97105 static QZchunk * unpack (QZframe *frame);
98106
4646 }
4747
4848 ///
49 // Create copy of zconfig, caller MUST free the value
50 // Create copy of config, as new zconfig object. Returns a fresh zconfig_t
51 // object. If config is null, or memory was exhausted, returns null.
52 QZconfig * QZconfig::dup ()
53 {
54 QZconfig *rv = new QZconfig (zconfig_dup (self));
55 return rv;
56 }
57
58 ///
4959 // Return name of config item
5060 const QString QZconfig::name ()
5161 {
3030
3131 // Destroy a config item and all its children
3232 ~QZconfig ();
33
34 // Create copy of zconfig, caller MUST free the value
35 // Create copy of config, as new zconfig object. Returns a fresh zconfig_t
36 // object. If config is null, or memory was exhausted, returns null.
37 QZconfig * dup ();
3338
3439 // Return name of config item
3540 const QString name ();
2626 }
2727
2828 ///
29 // Create new temporary file for writing via tmpfile. File is automaticaly
29 // Create new temporary file for writing via tmpfile. File is automatically
3030 // deleted on destroy
3131 QZfile* QZfile::tmp (QObject *qObjParent)
3232 {
2323 // may be NULL, in which case it is not used.
2424 explicit QZfile (const QString &path, const QString &name, QObject *qObjParent = 0);
2525
26 // Create new temporary file for writing via tmpfile. File is automaticaly
26 // Create new temporary file for writing via tmpfile. File is automatically
2727 // deleted on destroy
2828 static QZfile* tmp (QObject *qObjParent = 0);
2929
3838 }
3939
4040 ///
41 // Create a new frame from memory. Take ownership of the memory and calling the destructor
42 // on destroy.
43 QZframe* QZframe::frommem (void *data, size_t size, zframe_destructor_fn destructor, void *hint, QObject *qObjParent)
44 {
45 return new QZframe (zframe_frommem (data, size, destructor, hint), qObjParent);
46 }
47
48 ///
4149 // Receive frame from socket, returns zframe_t object or NULL if the recv
4250 // was interrupted. Does a blocking recv, if you want to not block then use
4351 // zpoller or zloop.
2626
2727 // Create a frame with a specified string content.
2828 static QZframe* from (const QString &string, QObject *qObjParent = 0);
29
30 // Create a new frame from memory. Take ownership of the memory and calling the destructor
31 // on destroy.
32 static QZframe* frommem (void *data, size_t size, zframe_destructor_fn destructor, void *hint, QObject *qObjParent = 0);
2933
3034 // Receive frame from socket, returns zframe_t object or NULL if the recv
3135 // was interrupted. Does a blocking recv, if you want to not block then use
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #include "qczmq.h"
8
9 ///
10 // Copy-construct to return the proper wrapped c types
11 QZhttpClient::QZhttpClient (zhttp_client_t *self, QObject *qObjParent) : QObject (qObjParent)
12 {
13 this->self = self;
14 }
15
16
17 ///
18 // Create a new http client
19 QZhttpClient::QZhttpClient (bool verbose, QObject *qObjParent) : QObject (qObjParent)
20 {
21 this->self = zhttp_client_new (verbose);
22 }
23
24 ///
25 // Destroy an http client
26 QZhttpClient::~QZhttpClient ()
27 {
28 zhttp_client_destroy (&self);
29 }
30
31 ///
32 // Self test of this class.
33 void QZhttpClient::test (bool verbose)
34 {
35 zhttp_client_test (verbose);
36
37 }
38 /*
39 ################################################################################
40 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
41 # Read the zproject/README.md for information about making permanent changes. #
42 ################################################################################
43 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 #ifndef Q_ZHTTP_CLIENT_H
7 #define Q_ZHTTP_CLIENT_H
8
9 #include "qczmq.h"
10
11 class QT_CZMQ_EXPORT QZhttpClient : public QObject
12 {
13 Q_OBJECT
14 public:
15
16 // Copy-construct to return the proper wrapped c types
17 QZhttpClient (zhttp_client_t *self, QObject *qObjParent = 0);
18
19 // Create a new http client
20 explicit QZhttpClient (bool verbose, QObject *qObjParent = 0);
21
22 // Destroy an http client
23 ~QZhttpClient ();
24
25 // Self test of this class.
26 static void test (bool verbose);
27
28 zhttp_client_t *self;
29 };
30 #endif // Q_ZHTTP_CLIENT_H
31 /*
32 ################################################################################
33 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
34 # Read the zproject/README.md for information about making permanent changes. #
35 ################################################################################
36 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #include "qczmq.h"
8
9 ///
10 // Copy-construct to return the proper wrapped c types
11 QZhttpRequest::QZhttpRequest (zhttp_request_t *self, QObject *qObjParent) : QObject (qObjParent)
12 {
13 this->self = self;
14 }
15
16
17 ///
18 // Create a new http request.
19 QZhttpRequest::QZhttpRequest (QObject *qObjParent) : QObject (qObjParent)
20 {
21 this->self = zhttp_request_new ();
22 }
23
24 ///
25 // Destroy an http request.
26 QZhttpRequest::~QZhttpRequest ()
27 {
28 zhttp_request_destroy (&self);
29 }
30
31 ///
32 // Receive a new request from zhttp_server.
33 // Return the underlying connection if successful, to be used when calling zhttp_response_send.
34 void * QZhttpRequest::recv (QZsock *sock)
35 {
36 void * rv = zhttp_request_recv (self, sock->self);
37 return rv;
38 }
39
40 ///
41 // Send a request to zhttp_client.
42 // Url and the request path will be concatenated.
43 // This behavior is useful for url rewrite and reverse proxy.
44 //
45 // Send also allow two user provided arguments which will be returned with the response.
46 // The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an arg.
47 int QZhttpRequest::send (QZhttpClient *client, int timeout, void *arg, void *arg2)
48 {
49 int rv = zhttp_request_send (self, client->self, timeout, arg, arg2);
50 return rv;
51 }
52
53 ///
54 // Get the request method
55 const QString QZhttpRequest::method ()
56 {
57 const QString rv = QString (zhttp_request_method (self));
58 return rv;
59 }
60
61 ///
62 // Set the request method
63 void QZhttpRequest::setMethod (const QString &method)
64 {
65 zhttp_request_set_method (self, method.toUtf8().data());
66
67 }
68
69 ///
70 // Get the request url.
71 // When receiving a request from http server this is only the path part of the url.
72 const QString QZhttpRequest::url ()
73 {
74 const QString rv = QString (zhttp_request_url (self));
75 return rv;
76 }
77
78 ///
79 // Set the request url
80 // When sending a request to http client this should be full url.
81 void QZhttpRequest::setUrl (const QString &url)
82 {
83 zhttp_request_set_url (self, url.toUtf8().data());
84
85 }
86
87 ///
88 // Get the request content type
89 const QString QZhttpRequest::contentType ()
90 {
91 const QString rv = QString (zhttp_request_content_type (self));
92 return rv;
93 }
94
95 ///
96 // Set the request content type
97 void QZhttpRequest::setContentType (const QString &contentType)
98 {
99 zhttp_request_set_content_type (self, contentType.toUtf8().data());
100
101 }
102
103 ///
104 // Get the content length of the request
105 size_t QZhttpRequest::contentLength ()
106 {
107 size_t rv = zhttp_request_content_length (self);
108 return rv;
109 }
110
111 ///
112 // Get the headers of the request
113 QZhash * QZhttpRequest::headers ()
114 {
115 QZhash *rv = new QZhash (zhttp_request_headers (self));
116 return rv;
117 }
118
119 ///
120 // Get the content of the request.
121 const QString QZhttpRequest::content ()
122 {
123 const QString rv = QString (zhttp_request_content (self));
124 return rv;
125 }
126
127 ///
128 // Get the content of the request.
129 QString QZhttpRequest::getContent ()
130 {
131 char *retStr_ = zhttp_request_get_content (self);
132 QString rv = QString (retStr_);
133 zstr_free (&retStr_);
134 return rv;
135 }
136
137 ///
138 // Set the content of the request..
139 // The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
140 void QZhttpRequest::setContentConst (const QString &content)
141 {
142 zhttp_request_set_content_const (self, content.toUtf8().data());
143
144 }
145
146 ///
147 // Set the content to NULL
148 void QZhttpRequest::resetContent ()
149 {
150 zhttp_request_reset_content (self);
151
152 }
153
154 ///
155 // Self test of this class.
156 void QZhttpRequest::test (bool verbose)
157 {
158 zhttp_request_test (verbose);
159
160 }
161 /*
162 ################################################################################
163 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
164 # Read the zproject/README.md for information about making permanent changes. #
165 ################################################################################
166 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 #ifndef Q_ZHTTP_REQUEST_H
7 #define Q_ZHTTP_REQUEST_H
8
9 #include "qczmq.h"
10
11 class QT_CZMQ_EXPORT QZhttpRequest : public QObject
12 {
13 Q_OBJECT
14 public:
15
16 // Copy-construct to return the proper wrapped c types
17 QZhttpRequest (zhttp_request_t *self, QObject *qObjParent = 0);
18
19 // Create a new http request.
20 explicit QZhttpRequest (QObject *qObjParent = 0);
21
22 // Destroy an http request.
23 ~QZhttpRequest ();
24
25 // Receive a new request from zhttp_server.
26 // Return the underlying connection if successful, to be used when calling zhttp_response_send.
27 void * recv (QZsock *sock);
28
29 // Send a request to zhttp_client.
30 // Url and the request path will be concatenated.
31 // This behavior is useful for url rewrite and reverse proxy.
32 //
33 // Send also allow two user provided arguments which will be returned with the response.
34 // The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an arg.
35 int send (QZhttpClient *client, int timeout, void *arg, void *arg2);
36
37 // Get the request method
38 const QString method ();
39
40 // Set the request method
41 void setMethod (const QString &method);
42
43 // Get the request url.
44 // When receiving a request from http server this is only the path part of the url.
45 const QString url ();
46
47 // Set the request url
48 // When sending a request to http client this should be full url.
49 void setUrl (const QString &url);
50
51 // Get the request content type
52 const QString contentType ();
53
54 // Set the request content type
55 void setContentType (const QString &contentType);
56
57 // Get the content length of the request
58 size_t contentLength ();
59
60 // Get the headers of the request
61 QZhash * headers ();
62
63 // Get the content of the request.
64 const QString content ();
65
66 // Get the content of the request.
67 QString getContent ();
68
69 // Set the content of the request..
70 // The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
71 void setContentConst (const QString &content);
72
73 // Set the content to NULL
74 void resetContent ();
75
76 // Self test of this class.
77 static void test (bool verbose);
78
79 zhttp_request_t *self;
80 };
81 #endif // Q_ZHTTP_REQUEST_H
82 /*
83 ################################################################################
84 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
85 # Read the zproject/README.md for information about making permanent changes. #
86 ################################################################################
87 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #include "qczmq.h"
8
9 ///
10 // Copy-construct to return the proper wrapped c types
11 QZhttpResponse::QZhttpResponse (zhttp_response_t *self, QObject *qObjParent) : QObject (qObjParent)
12 {
13 this->self = self;
14 }
15
16
17 ///
18 // Create a new zhttp_response.
19 QZhttpResponse::QZhttpResponse (QObject *qObjParent) : QObject (qObjParent)
20 {
21 this->self = zhttp_response_new ();
22 }
23
24 ///
25 // Destroy the zhttp_response.
26 QZhttpResponse::~QZhttpResponse ()
27 {
28 zhttp_response_destroy (&self);
29 }
30
31 ///
32 // Send a response to a request.
33 // Returns 0 if successful and -1 otherwise.
34 int QZhttpResponse::send (QZsock *sock, void **connection)
35 {
36 int rv = zhttp_response_send (self, sock->self, connection);
37 return rv;
38 }
39
40 ///
41 // Receive a response from zhttp_client.
42 // On success return 0, -1 otherwise.
43 //
44 // Recv returns the two user arguments which was provided with the request.
45 // The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an argument.
46 int QZhttpResponse::recv (QZhttpClient *client, void **arg, void **arg2)
47 {
48 int rv = zhttp_response_recv (self, client->self, arg, arg2);
49 return rv;
50 }
51
52 ///
53 // Get the response content type
54 const QString QZhttpResponse::contentType ()
55 {
56 const QString rv = QString (zhttp_response_content_type (self));
57 return rv;
58 }
59
60 ///
61 // Set the content type of the response.
62 void QZhttpResponse::setContentType (const QString &value)
63 {
64 zhttp_response_set_content_type (self, value.toUtf8().data());
65
66 }
67
68 ///
69 // Get the status code of the response.
70 quint32 QZhttpResponse::statusCode ()
71 {
72 uint32_t rv = zhttp_response_status_code (self);
73 return rv;
74 }
75
76 ///
77 // Set the status code of the response.
78 void QZhttpResponse::setStatusCode (quint32 statusCode)
79 {
80 zhttp_response_set_status_code (self, (uint32_t) statusCode);
81
82 }
83
84 ///
85 // Get the headers of the response.
86 QZhash * QZhttpResponse::headers ()
87 {
88 QZhash *rv = new QZhash (zhttp_response_headers (self));
89 return rv;
90 }
91
92 ///
93 // Get the content length of the response
94 size_t QZhttpResponse::contentLength ()
95 {
96 size_t rv = zhttp_response_content_length (self);
97 return rv;
98 }
99
100 ///
101 // Get the content of the response.
102 const QString QZhttpResponse::content ()
103 {
104 const QString rv = QString (zhttp_response_content (self));
105 return rv;
106 }
107
108 ///
109 // Get the content of the response.
110 QString QZhttpResponse::getContent ()
111 {
112 char *retStr_ = zhttp_response_get_content (self);
113 QString rv = QString (retStr_);
114 zstr_free (&retStr_);
115 return rv;
116 }
117
118 ///
119 // Set the content of the response.
120 // The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
121 void QZhttpResponse::setContentConst (const QString &content)
122 {
123 zhttp_response_set_content_const (self, content.toUtf8().data());
124
125 }
126
127 ///
128 // Set the content to NULL
129 void QZhttpResponse::resetContent ()
130 {
131 zhttp_response_reset_content (self);
132
133 }
134
135 ///
136 // Self test of this class.
137 void QZhttpResponse::test (bool verbose)
138 {
139 zhttp_response_test (verbose);
140
141 }
142 /*
143 ################################################################################
144 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
145 # Read the zproject/README.md for information about making permanent changes. #
146 ################################################################################
147 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 #ifndef Q_ZHTTP_RESPONSE_H
7 #define Q_ZHTTP_RESPONSE_H
8
9 #include "qczmq.h"
10
11 class QT_CZMQ_EXPORT QZhttpResponse : public QObject
12 {
13 Q_OBJECT
14 public:
15
16 // Copy-construct to return the proper wrapped c types
17 QZhttpResponse (zhttp_response_t *self, QObject *qObjParent = 0);
18
19 // Create a new zhttp_response.
20 explicit QZhttpResponse (QObject *qObjParent = 0);
21
22 // Destroy the zhttp_response.
23 ~QZhttpResponse ();
24
25 // Send a response to a request.
26 // Returns 0 if successful and -1 otherwise.
27 int send (QZsock *sock, void **connection);
28
29 // Receive a response from zhttp_client.
30 // On success return 0, -1 otherwise.
31 //
32 // Recv returns the two user arguments which was provided with the request.
33 // The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an argument.
34 int recv (QZhttpClient *client, void **arg, void **arg2);
35
36 // Get the response content type
37 const QString contentType ();
38
39 // Set the content type of the response.
40 void setContentType (const QString &value);
41
42 // Get the status code of the response.
43 quint32 statusCode ();
44
45 // Set the status code of the response.
46 void setStatusCode (quint32 statusCode);
47
48 // Get the headers of the response.
49 QZhash * headers ();
50
51 // Get the content length of the response
52 size_t contentLength ();
53
54 // Get the content of the response.
55 const QString content ();
56
57 // Get the content of the response.
58 QString getContent ();
59
60 // Set the content of the response.
61 // The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
62 void setContentConst (const QString &content);
63
64 // Set the content to NULL
65 void resetContent ();
66
67 // Self test of this class.
68 static void test (bool verbose);
69
70 zhttp_response_t *self;
71 };
72 #endif // Q_ZHTTP_RESPONSE_H
73 /*
74 ################################################################################
75 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
76 # Read the zproject/README.md for information about making permanent changes. #
77 ################################################################################
78 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #include "qczmq.h"
8
9 ///
10 // Copy-construct to return the proper wrapped c types
11 QZhttpServer::QZhttpServer (zhttp_server_t *self, QObject *qObjParent) : QObject (qObjParent)
12 {
13 this->self = self;
14 }
15
16
17 ///
18 // Create a new http server
19 QZhttpServer::QZhttpServer (QZhttpServerOptions *options, QObject *qObjParent) : QObject (qObjParent)
20 {
21 this->self = zhttp_server_new (options->self);
22 }
23
24 ///
25 // Destroy an http server
26 QZhttpServer::~QZhttpServer ()
27 {
28 zhttp_server_destroy (&self);
29 }
30
31 ///
32 // Return the port the server is listening on.
33 int QZhttpServer::port ()
34 {
35 int rv = zhttp_server_port (self);
36 return rv;
37 }
38
39 ///
40 // Self test of this class.
41 void QZhttpServer::test (bool verbose)
42 {
43 zhttp_server_test (verbose);
44
45 }
46 /*
47 ################################################################################
48 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
49 # Read the zproject/README.md for information about making permanent changes. #
50 ################################################################################
51 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 #ifndef Q_ZHTTP_SERVER_H
7 #define Q_ZHTTP_SERVER_H
8
9 #include "qczmq.h"
10
11 class QT_CZMQ_EXPORT QZhttpServer : public QObject
12 {
13 Q_OBJECT
14 public:
15
16 // Copy-construct to return the proper wrapped c types
17 QZhttpServer (zhttp_server_t *self, QObject *qObjParent = 0);
18
19 // Create a new http server
20 explicit QZhttpServer (QZhttpServerOptions *options, QObject *qObjParent = 0);
21
22 // Destroy an http server
23 ~QZhttpServer ();
24
25 // Return the port the server is listening on.
26 int port ();
27
28 // Self test of this class.
29 static void test (bool verbose);
30
31 zhttp_server_t *self;
32 };
33 #endif // Q_ZHTTP_SERVER_H
34 /*
35 ################################################################################
36 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
37 # Read the zproject/README.md for information about making permanent changes. #
38 ################################################################################
39 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #include "qczmq.h"
8
9 ///
10 // Copy-construct to return the proper wrapped c types
11 QZhttpServerConnection::QZhttpServerConnection (zhttp_server_connection_t *self, QObject *qObjParent) : QObject (qObjParent)
12 {
13 this->self = self;
14 }
15
16 /*
17 ################################################################################
18 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
19 # Read the zproject/README.md for information about making permanent changes. #
20 ################################################################################
21 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 #ifndef Q_ZHTTP_SERVER_CONNECTION_H
7 #define Q_ZHTTP_SERVER_CONNECTION_H
8
9 #include "qczmq.h"
10
11 class QT_CZMQ_EXPORT QZhttpServerConnection : public QObject
12 {
13 Q_OBJECT
14 public:
15
16 // Copy-construct to return the proper wrapped c types
17 QZhttpServerConnection (zhttp_server_connection_t *self, QObject *qObjParent = 0);
18
19 zhttp_server_connection_t *self;
20 };
21 #endif // Q_ZHTTP_SERVER_CONNECTION_H
22 /*
23 ################################################################################
24 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
25 # Read the zproject/README.md for information about making permanent changes. #
26 ################################################################################
27 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6
7 #include "qczmq.h"
8
9 ///
10 // Copy-construct to return the proper wrapped c types
11 QZhttpServerOptions::QZhttpServerOptions (zhttp_server_options_t *self, QObject *qObjParent) : QObject (qObjParent)
12 {
13 this->self = self;
14 }
15
16
17 ///
18 // Create a new zhttp_server_options.
19 QZhttpServerOptions::QZhttpServerOptions (QObject *qObjParent) : QObject (qObjParent)
20 {
21 this->self = zhttp_server_options_new ();
22 }
23
24 ///
25 // Create options from config tree.
26 QZhttpServerOptions* QZhttpServerOptions::fromConfig (QZconfig *config, QObject *qObjParent)
27 {
28 return new QZhttpServerOptions (zhttp_server_options_from_config (config->self), qObjParent);
29 }
30
31 ///
32 // Destroy the zhttp_server_options.
33 QZhttpServerOptions::~QZhttpServerOptions ()
34 {
35 zhttp_server_options_destroy (&self);
36 }
37
38 ///
39 // Get the server listening port.
40 int QZhttpServerOptions::port ()
41 {
42 int rv = zhttp_server_options_port (self);
43 return rv;
44 }
45
46 ///
47 // Set the server listening port
48 void QZhttpServerOptions::setPort (int port)
49 {
50 zhttp_server_options_set_port (self, port);
51
52 }
53
54 ///
55 // Get the address sockets should connect to in order to receive requests.
56 const QString QZhttpServerOptions::backendAddress ()
57 {
58 const QString rv = QString (zhttp_server_options_backend_address (self));
59 return rv;
60 }
61
62 ///
63 // Set the address sockets should connect to in order to receive requests.
64 void QZhttpServerOptions::setBackendAddress (const QString &address)
65 {
66 zhttp_server_options_set_backend_address (self, address.toUtf8().data());
67
68 }
69
70 ///
71 // Self test of this class.
72 void QZhttpServerOptions::test (bool verbose)
73 {
74 zhttp_server_options_test (verbose);
75
76 }
77 /*
78 ################################################################################
79 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
80 # Read the zproject/README.md for information about making permanent changes. #
81 ################################################################################
82 */
0 /*
1 ################################################################################
2 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3 # Read the zproject/README.md for information about making permanent changes. #
4 ################################################################################
5 */
6 #ifndef Q_ZHTTP_SERVER_OPTIONS_H
7 #define Q_ZHTTP_SERVER_OPTIONS_H
8
9 #include "qczmq.h"
10
11 class QT_CZMQ_EXPORT QZhttpServerOptions : public QObject
12 {
13 Q_OBJECT
14 public:
15
16 // Copy-construct to return the proper wrapped c types
17 QZhttpServerOptions (zhttp_server_options_t *self, QObject *qObjParent = 0);
18
19 // Create a new zhttp_server_options.
20 explicit QZhttpServerOptions (QObject *qObjParent = 0);
21
22 // Create options from config tree.
23 static QZhttpServerOptions* fromConfig (QZconfig *config, QObject *qObjParent = 0);
24
25 // Destroy the zhttp_server_options.
26 ~QZhttpServerOptions ();
27
28 // Get the server listening port.
29 int port ();
30
31 // Set the server listening port
32 void setPort (int port);
33
34 // Get the address sockets should connect to in order to receive requests.
35 const QString backendAddress ();
36
37 // Set the address sockets should connect to in order to receive requests.
38 void setBackendAddress (const QString &address);
39
40 // Self test of this class.
41 static void test (bool verbose);
42
43 zhttp_server_options_t *self;
44 };
45 #endif // Q_ZHTTP_SERVER_OPTIONS_H
46 /*
47 ################################################################################
48 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
49 # Read the zproject/README.md for information about making permanent changes. #
50 ################################################################################
51 */
1919 QZlistx::QZlistx (QObject *qObjParent) : QObject (qObjParent)
2020 {
2121 this->self = zlistx_new ();
22 }
23
24 ///
25 // Unpack binary frame into a new list. Packed data must follow format
26 // defined by zlistx_pack. List is set to autofree. An empty frame
27 // unpacks to an empty list.
28 QZlistx* QZlistx::unpack (QZframe *frame, QObject *qObjParent)
29 {
30 return new QZlistx (zlistx_unpack (frame->self), qObjParent);
2231 }
2332
2433 ///
281290 }
282291
283292 ///
293 // Serialize list to a binary frame that can be sent in a message.
294 // The packed format is compatible with the 'strings' type implemented by zproto:
295 //
296 // ; A list of strings
297 // list = list-count *longstr
298 // list-count = number-4
299 //
300 // ; Strings are always length + text contents
301 // longstr = number-4 *VCHAR
302 //
303 // ; Numbers are unsigned integers in network byte order
304 // number-4 = 4OCTET
305 QZframe * QZlistx::pack ()
306 {
307 QZframe *rv = new QZframe (zlistx_pack (self));
308 return rv;
309 }
310
311 ///
284312 // Self test of this class.
285313 void QZlistx::test (bool verbose)
286314 {
1818
1919 // Create a new, empty list.
2020 explicit QZlistx (QObject *qObjParent = 0);
21
22 // Unpack binary frame into a new list. Packed data must follow format
23 // defined by zlistx_pack. List is set to autofree. An empty frame
24 // unpacks to an empty list.
25 static QZlistx* unpack (QZframe *frame, QObject *qObjParent = 0);
2126
2227 // Destroy a list. If an item destructor was specified, all items in the
2328 // list are automatically destroyed as well.
144149 // or greater than, item2.
145150 void setComparator (zlistx_comparator_fn comparator);
146151
152 // Serialize list to a binary frame that can be sent in a message.
153 // The packed format is compatible with the 'strings' type implemented by zproto:
154 //
155 // ; A list of strings
156 // list = list-count *longstr
157 // list-count = number-4
158 //
159 // ; Strings are always length + text contents
160 // longstr = number-4 *VCHAR
161 //
162 // ; Numbers are unsigned integers in network byte order
163 // number-4 = 4OCTET
164 QZframe * pack ();
165
147166 // Self test of this class.
148167 static void test (bool verbose);
149168
146146 }
147147
148148 ///
149 // The timeout should be zero or greater, or -1 to wait indefinitely.
149150 // wait or poll process status, return return code
150 int QZproc::wait (bool hang)
151 {
152 int rv = zproc_wait (self, hang);
153 return rv;
154 }
155
156 ///
157 // return internal actor, usefull for the polling if process died
151 int QZproc::wait (int timeout)
152 {
153 int rv = zproc_wait (self, timeout);
154 return rv;
155 }
156
157 ///
158 // send SIGTERM signal to the subprocess, wait for grace period and
159 // eventually send SIGKILL
160 void QZproc::shutdown (int timeout)
161 {
162 zproc_shutdown (self, timeout);
163
164 }
165
166 ///
167 // return internal actor, useful for the polling if process died
158168 void * QZproc::actor ()
159169 {
160170 void * rv = zproc_actor (self);
7474 // return true if process is running, false if not yet started or finished
7575 bool running ();
7676
77 // The timeout should be zero or greater, or -1 to wait indefinitely.
7778 // wait or poll process status, return return code
78 int wait (bool hang);
79 int wait (int timeout);
7980
80 // return internal actor, usefull for the polling if process died
81 // send SIGTERM signal to the subprocess, wait for grace period and
82 // eventually send SIGKILL
83 void shutdown (int timeout);
84
85 // return internal actor, useful for the polling if process died
8186 void * actor ();
8287
8388 // send a signal to the subprocess
262262 // c = zchunk_t *
263263 // f = zframe_t *
264264 // h = zhashx_t *
265 // l = zlistx_t * (DRAFT)
265266 // U = zuuid_t *
266267 // p = void * (sends the pointer value, only meaningful over inproc)
267268 // m = zmsg_t * (sends all frames in the zmsg)
306307 // f = zframe_t ** (creates zframe)
307308 // U = zuuid_t * (creates a zuuid with the data)
308309 // h = zhashx_t ** (creates zhashx)
310 // l = zlistx_t ** (creates zlistx) (DRAFT)
309311 // p = void ** (stores pointer)
310 // m = zmsg_t ** (creates a zmsg with the remaing frames)
312 // m = zmsg_t ** (creates a zmsg with the remaining frames)
311313 // z = null, asserts empty frame (0 arguments)
312314 // u = uint * (stores unsigned integer, deprecated)
313315 //
438440 }
439441
440442 ///
443 // Check whether the socket has available message to read.
444 bool QZsock::hasIn ()
445 {
446 bool rv = zsock_has_in (self);
447 return rv;
448 }
449
450 ///
451 // Get socket option `router_notify`.
452 // Available from libzmq 4.3.0.
453 int QZsock::routerNotify ()
454 {
455 int rv = zsock_router_notify (self);
456 return rv;
457 }
458
459 ///
460 // Set socket option `router_notify`.
461 // Available from libzmq 4.3.0.
462 void QZsock::setRouterNotify (int routerNotify)
463 {
464 zsock_set_router_notify (self, routerNotify);
465
466 }
467
468 ///
469 // Get socket option `multicast_loop`.
470 // Available from libzmq 4.3.0.
471 int QZsock::multicastLoop ()
472 {
473 int rv = zsock_multicast_loop (self);
474 return rv;
475 }
476
477 ///
478 // Set socket option `multicast_loop`.
479 // Available from libzmq 4.3.0.
480 void QZsock::setMulticastLoop (int multicastLoop)
481 {
482 zsock_set_multicast_loop (self, multicastLoop);
483
484 }
485
486 ///
487 // Get socket option `metadata`.
488 // Available from libzmq 4.3.0.
489 QString QZsock::metadata ()
490 {
491 char *retStr_ = zsock_metadata (self);
492 QString rv = QString (retStr_);
493 zstr_free (&retStr_);
494 return rv;
495 }
496
497 ///
498 // Set socket option `metadata`.
499 // Available from libzmq 4.3.0.
500 void QZsock::setMetadata (const QString &metadata)
501 {
502 zsock_set_metadata (self, metadata.toUtf8().data());
503
504 }
505
506 ///
507 // Get socket option `loopback_fastpath`.
508 // Available from libzmq 4.3.0.
509 int QZsock::loopbackFastpath ()
510 {
511 int rv = zsock_loopback_fastpath (self);
512 return rv;
513 }
514
515 ///
516 // Set socket option `loopback_fastpath`.
517 // Available from libzmq 4.3.0.
518 void QZsock::setLoopbackFastpath (int loopbackFastpath)
519 {
520 zsock_set_loopback_fastpath (self, loopbackFastpath);
521
522 }
523
524 ///
525 // Get socket option `zap_enforce_domain`.
526 // Available from libzmq 4.3.0.
527 int QZsock::zapEnforceDomain ()
528 {
529 int rv = zsock_zap_enforce_domain (self);
530 return rv;
531 }
532
533 ///
534 // Set socket option `zap_enforce_domain`.
535 // Available from libzmq 4.3.0.
536 void QZsock::setZapEnforceDomain (int zapEnforceDomain)
537 {
538 zsock_set_zap_enforce_domain (self, zapEnforceDomain);
539
540 }
541
542 ///
543 // Get socket option `gssapi_principal_nametype`.
544 // Available from libzmq 4.3.0.
545 int QZsock::gssapiPrincipalNametype ()
546 {
547 int rv = zsock_gssapi_principal_nametype (self);
548 return rv;
549 }
550
551 ///
552 // Set socket option `gssapi_principal_nametype`.
553 // Available from libzmq 4.3.0.
554 void QZsock::setGssapiPrincipalNametype (int gssapiPrincipalNametype)
555 {
556 zsock_set_gssapi_principal_nametype (self, gssapiPrincipalNametype);
557
558 }
559
560 ///
561 // Get socket option `gssapi_service_principal_nametype`.
562 // Available from libzmq 4.3.0.
563 int QZsock::gssapiServicePrincipalNametype ()
564 {
565 int rv = zsock_gssapi_service_principal_nametype (self);
566 return rv;
567 }
568
569 ///
570 // Set socket option `gssapi_service_principal_nametype`.
571 // Available from libzmq 4.3.0.
572 void QZsock::setGssapiServicePrincipalNametype (int gssapiServicePrincipalNametype)
573 {
574 zsock_set_gssapi_service_principal_nametype (self, gssapiServicePrincipalNametype);
575
576 }
577
578 ///
579 // Get socket option `bindtodevice`.
580 // Available from libzmq 4.3.0.
581 QString QZsock::bindtodevice ()
582 {
583 char *retStr_ = zsock_bindtodevice (self);
584 QString rv = QString (retStr_);
585 zstr_free (&retStr_);
586 return rv;
587 }
588
589 ///
590 // Set socket option `bindtodevice`.
591 // Available from libzmq 4.3.0.
592 void QZsock::setBindtodevice (const QString &bindtodevice)
593 {
594 zsock_set_bindtodevice (self, bindtodevice.toUtf8().data());
595
596 }
597
598 ///
441599 // Get socket option `heartbeat_ivl`.
442600 // Available from libzmq 4.2.0.
443601 int QZsock::heartbeatIvl ()
148148 // c = zchunk_t *
149149 // f = zframe_t *
150150 // h = zhashx_t *
151 // l = zlistx_t * (DRAFT)
151152 // U = zuuid_t *
152153 // p = void * (sends the pointer value, only meaningful over inproc)
153154 // m = zmsg_t * (sends all frames in the zmsg)
179180 // f = zframe_t ** (creates zframe)
180181 // U = zuuid_t * (creates a zuuid with the data)
181182 // h = zhashx_t ** (creates zhashx)
183 // l = zlistx_t ** (creates zlistx) (DRAFT)
182184 // p = void ** (stores pointer)
183 // m = zmsg_t ** (creates a zmsg with the remaing frames)
185 // m = zmsg_t ** (creates a zmsg with the remaining frames)
184186 // z = null, asserts empty frame (0 arguments)
185187 // u = uint * (stores unsigned integer, deprecated)
186188 //
248250 // return the supplied value. Takes a polymorphic socket reference.
249251 static void * resolve (void *self);
250252
253 // Check whether the socket has available message to read.
254 bool hasIn ();
255
256 // Get socket option `router_notify`.
257 // Available from libzmq 4.3.0.
258 int routerNotify ();
259
260 // Set socket option `router_notify`.
261 // Available from libzmq 4.3.0.
262 void setRouterNotify (int routerNotify);
263
264 // Get socket option `multicast_loop`.
265 // Available from libzmq 4.3.0.
266 int multicastLoop ();
267
268 // Set socket option `multicast_loop`.
269 // Available from libzmq 4.3.0.
270 void setMulticastLoop (int multicastLoop);
271
272 // Get socket option `metadata`.
273 // Available from libzmq 4.3.0.
274 QString metadata ();
275
276 // Set socket option `metadata`.
277 // Available from libzmq 4.3.0.
278 void setMetadata (const QString &metadata);
279
280 // Get socket option `loopback_fastpath`.
281 // Available from libzmq 4.3.0.
282 int loopbackFastpath ();
283
284 // Set socket option `loopback_fastpath`.
285 // Available from libzmq 4.3.0.
286 void setLoopbackFastpath (int loopbackFastpath);
287
288 // Get socket option `zap_enforce_domain`.
289 // Available from libzmq 4.3.0.
290 int zapEnforceDomain ();
291
292 // Set socket option `zap_enforce_domain`.
293 // Available from libzmq 4.3.0.
294 void setZapEnforceDomain (int zapEnforceDomain);
295
296 // Get socket option `gssapi_principal_nametype`.
297 // Available from libzmq 4.3.0.
298 int gssapiPrincipalNametype ();
299
300 // Set socket option `gssapi_principal_nametype`.
301 // Available from libzmq 4.3.0.
302 void setGssapiPrincipalNametype (int gssapiPrincipalNametype);
303
304 // Get socket option `gssapi_service_principal_nametype`.
305 // Available from libzmq 4.3.0.
306 int gssapiServicePrincipalNametype ();
307
308 // Set socket option `gssapi_service_principal_nametype`.
309 // Available from libzmq 4.3.0.
310 void setGssapiServicePrincipalNametype (int gssapiServicePrincipalNametype);
311
312 // Get socket option `bindtodevice`.
313 // Available from libzmq 4.3.0.
314 QString bindtodevice ();
315
316 // Set socket option `bindtodevice`.
317 // Available from libzmq 4.3.0.
318 void setBindtodevice (const QString &bindtodevice);
319
251320 // Get socket option `heartbeat_ivl`.
252321 // Available from libzmq 4.2.0.
253322 int heartbeatIvl ();
100100 ///
101101 // Set default interrupt handler, so Ctrl-C or SIGTERM will set
102102 // zsys_interrupted. Idempotent; safe to call multiple times.
103 // Can be supressed by ZSYS_SIGHANDLER=false
103 // Can be suppressed by ZSYS_SIGHANDLER=false
104104 // *** This is for CZMQ internal use only and may change arbitrarily ***
105105 void QZsys::catchInterrupts ()
106106 {
342342 void QZsys::setThreadPriority (int priority)
343343 {
344344 zsys_set_thread_priority (priority);
345
346 }
347
348 ///
349 // Configure the numeric prefix to each thread created for the internal
350 // context's thread pool. This option is only supported on Linux.
351 // If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
352 // provides the default.
353 // Note that this method is valid only before any socket is created.
354 void QZsys::setThreadNamePrefix (int prefix)
355 {
356 zsys_set_thread_name_prefix (prefix);
357
358 }
359
360 ///
361 // Return thread name prefix.
362 int QZsys::threadNamePrefix ()
363 {
364 int rv = zsys_thread_name_prefix ();
365 return rv;
366 }
367
368 ///
369 // Adds a specific CPU to the affinity list of the ZMQ context thread pool.
370 // This option is only supported on Linux.
371 // Note that this method is valid only before any socket is created.
372 void QZsys::threadAffinityCpuAdd (int cpu)
373 {
374 zsys_thread_affinity_cpu_add (cpu);
375
376 }
377
378 ///
379 // Removes a specific CPU to the affinity list of the ZMQ context thread pool.
380 // This option is only supported on Linux.
381 // Note that this method is valid only before any socket is created.
382 void QZsys::threadAffinityCpuRemove (int cpu)
383 {
384 zsys_thread_affinity_cpu_remove (cpu);
345385
346386 }
347387
576616 int QZsys::autoUseFd ()
577617 {
578618 int rv = zsys_auto_use_fd ();
619 return rv;
620 }
621
622 ///
623 // Print formatted string. Format is specified by variable names
624 // in Python-like format style
625 //
626 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
627 // become
628 // "key=value"
629 //
630 // Returns freshly allocated string or NULL in a case of error.
631 // Not enough memory, invalid format specifier, name not in args
632 QString QZsys::zprintf (const QString &format, QZhash *args)
633 {
634 char *retStr_ = zsys_zprintf (format.toUtf8().data(), args->self);
635 QString rv = QString (retStr_);
636 zstr_free (&retStr_);
637 return rv;
638 }
639
640 ///
641 // Return error string for given format/args combination.
642 QString QZsys::zprintfError (const QString &format, QZhash *args)
643 {
644 char *retStr_ = zsys_zprintf_error (format.toUtf8().data(), args->self);
645 QString rv = QString (retStr_);
646 zstr_free (&retStr_);
647 return rv;
648 }
649
650 ///
651 // Print formatted string. Format is specified by variable names
652 // in Python-like format style
653 //
654 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
655 // become
656 // "key=value"
657 //
658 // Returns freshly allocated string or NULL in a case of error.
659 // Not enough memory, invalid format specifier, name not in args
660 QString QZsys::zplprintf (const QString &format, QZconfig *args)
661 {
662 char *retStr_ = zsys_zplprintf (format.toUtf8().data(), args->self);
663 QString rv = QString (retStr_);
664 zstr_free (&retStr_);
665 return rv;
666 }
667
668 ///
669 // Return error string for given format/args combination.
670 QString QZsys::zplprintfError (const QString &format, QZconfig *args)
671 {
672 char *retStr_ = zsys_zplprintf_error (format.toUtf8().data(), args->self);
673 QString rv = QString (retStr_);
674 zstr_free (&retStr_);
579675 return rv;
580676 }
581677
6161
6262 // Set default interrupt handler, so Ctrl-C or SIGTERM will set
6363 // zsys_interrupted. Idempotent; safe to call multiple times.
64 // Can be supressed by ZSYS_SIGHANDLER=false
64 // Can be suppressed by ZSYS_SIGHANDLER=false
6565 // *** This is for CZMQ internal use only and may change arbitrarily ***
6666 static void catchInterrupts ();
6767
181181 // defined, that provides the default.
182182 // Note that this method is valid only before any socket is created.
183183 static void setThreadPriority (int priority);
184
185 // Configure the numeric prefix to each thread created for the internal
186 // context's thread pool. This option is only supported on Linux.
187 // If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
188 // provides the default.
189 // Note that this method is valid only before any socket is created.
190 static void setThreadNamePrefix (int prefix);
191
192 // Return thread name prefix.
193 static int threadNamePrefix ();
194
195 // Adds a specific CPU to the affinity list of the ZMQ context thread pool.
196 // This option is only supported on Linux.
197 // Note that this method is valid only before any socket is created.
198 static void threadAffinityCpuAdd (int cpu);
199
200 // Removes a specific CPU to the affinity list of the ZMQ context thread pool.
201 // This option is only supported on Linux.
202 // Note that this method is valid only before any socket is created.
203 static void threadAffinityCpuRemove (int cpu);
184204
185205 // Configure the number of sockets that ZeroMQ will allow. The default
186206 // is 1024. The actual limit depends on the system, and you can query it
300320
301321 // Return use of automatic pre-allocated FDs for zsock instances.
302322 static int autoUseFd ();
323
324 // Print formatted string. Format is specified by variable names
325 // in Python-like format style
326 //
327 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
328 // become
329 // "key=value"
330 //
331 // Returns freshly allocated string or NULL in a case of error.
332 // Not enough memory, invalid format specifier, name not in args
333 static QString zprintf (const QString &format, QZhash *args);
334
335 // Return error string for given format/args combination.
336 static QString zprintfError (const QString &format, QZhash *args);
337
338 // Print formatted string. Format is specified by variable names
339 // in Python-like format style
340 //
341 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
342 // become
343 // "key=value"
344 //
345 // Returns freshly allocated string or NULL in a case of error.
346 // Not enough memory, invalid format specifier, name not in args
347 static QString zplprintf (const QString &format, QZconfig *args);
348
349 // Return error string for given format/args combination.
350 static QString zplprintfError (const QString &format, QZconfig *args);
303351
304352 // Set log identity, which is a string that prefixes all log messages sent
305353 // by this process. The log identity defaults to the environment variable
44
55 module CZMQ
66 module FFI
7 VERSION = '4.1.1'
7 VERSION = '4.2.0'
88 end
99 end
1010
88 # Platform independent command line argument parsing helpers
99 #
1010 # There are two kind of elements provided by this class
11 # foo --named-parameter --parameter with_value positional arguments -a gain-parameter
12 # zargs keeps poision only for arguments, parameters are to be accessed like hash.
11 # Named parameters, accessed by param_get and param_has methods
12 # * --named-parameter
13 # * --parameter with_value
14 # * -a val
15 # Positional arguments, accessed by zargs_first, zargs_next
1316 #
1417 # It DOES:
1518 # * provide easy to use CLASS compatible API for accessing argv
1619 # * is platform independent
1720 # * provide getopt_long style -- argument, which delimits parameters from arguments
18 # * makes parameters positon independent
21 # * makes parameters position independent
1922 #
2023 # It does NOT
2124 # * change argv
172175 result
173176 end
174177
175 # Return current parameter name, or NULL if there are no named
176 # parameters.
178 # Return current parameter name, or NULL if there are no named parameters.
177179 #
178180 # @return [String]
179181 def param_name()
183185 result
184186 end
185187
186 # Return value of named parameter, NULL if no given parameter has
187 # been specified, or special value for wich zargs_param_empty ()
188 # returns true.
189 #
190 # @param keys [String, #to_s, nil]
191 # @return [String]
192 def param_lookup(keys)
193 raise DestroyedError unless @ptr
194 self_p = @ptr
195 result = ::CZMQ::FFI.zargs_param_lookup(self_p, keys)
196 result
197 end
198
199 # Return value of named parameter(s), NULL if no given parameter has
200 # been specified, or special value for wich zargs_param_empty ()
201 # returns true.
202 #
203 # @param keys [String, #to_s, nil]
188 # Return value of named parameter or NULL is it has no value (or was not specified)
189 #
190 # @param name [String, #to_s, nil]
191 # @return [String]
192 def get(name)
193 raise DestroyedError unless @ptr
194 self_p = @ptr
195 result = ::CZMQ::FFI.zargs_get(self_p, name)
196 result
197 end
198
199 # Return value of one of parameter(s) or NULL is it has no value (or was not specified)
200 #
201 # @param name [String, #to_s, nil]
204202 # @param args [Array<Object>] see https://github.com/ffi/ffi/wiki/examples#using-varargs
205203 # @return [String]
206 def param_lookupx(keys, *args)
207 raise DestroyedError unless @ptr
208 self_p = @ptr
209 result = ::CZMQ::FFI.zargs_param_lookupx(self_p, keys, *args)
210 result
211 end
212
213 # Returns true if there are --help -h arguments
214 #
204 def getx(name, *args)
205 raise DestroyedError unless @ptr
206 self_p = @ptr
207 result = ::CZMQ::FFI.zargs_getx(self_p, name, *args)
208 result
209 end
210
211 # Returns true if named parameter was specified on command line
212 #
213 # @param name [String, #to_s, nil]
215214 # @return [Boolean]
216 def has_help()
217 raise DestroyedError unless @ptr
218 self_p = @ptr
219 result = ::CZMQ::FFI.zargs_has_help(self_p)
220 result
221 end
222
223 # Returns true if parameter did not have a value
224 #
225 # @param arg [String, #to_s, nil]
215 def has(name)
216 raise DestroyedError unless @ptr
217 self_p = @ptr
218 result = ::CZMQ::FFI.zargs_has(self_p, name)
219 result
220 end
221
222 # Returns true if named parameter(s) was specified on command line
223 #
224 # @param name [String, #to_s, nil]
225 # @param args [Array<Object>] see https://github.com/ffi/ffi/wiki/examples#using-varargs
226226 # @return [Boolean]
227 def self.param_empty(arg)
228 result = ::CZMQ::FFI.zargs_param_empty(arg)
227 def hasx(name, *args)
228 raise DestroyedError unless @ptr
229 self_p = @ptr
230 result = ::CZMQ::FFI.zargs_hasx(self_p, name, *args)
229231 result
230232 end
231233
7272 @finalizer = nil
7373 end
7474
75 # Create a new callback of the following type:
76 # Destroy an item
77 # typedef void (zchunk_destructor_fn) (
78 # void **hint);
79 #
80 # @note WARNING: If your Ruby code doesn't retain a reference to the
81 # FFI::Function object after passing it to a C function call,
82 # it may be garbage collected while C still holds the pointer,
83 # potentially resulting in a segmentation fault.
84 def self.destructor_fn
85 ::FFI::Function.new :void, [:pointer], blocking: true do |hint|
86 result = yield hint
87 result
88 end
89 end
90
7591 # Create a new chunk of the specified size. If you specify the data, it
7692 # is copied into the chunk. If you do not specify the data, the chunk is
7793 # allocated and left empty, and you can then add data using zchunk_append.
8197 def self.new(data, size)
8298 size = Integer(size)
8399 ptr = ::CZMQ::FFI.zchunk_new(data, size)
100 __new ptr
101 end
102
103 # Create a new chunk from memory. Take ownership of the memory and calling the destructor
104 # on destroy.
105 # @param data [::FFI::Pointer, #to_ptr]
106 # @param size [Integer, #to_int, #to_i]
107 # @param destructor [::FFI::Pointer, #to_ptr]
108 # @param hint [::FFI::Pointer, #to_ptr]
109 # @return [CZMQ::Zchunk]
110 def self.frommem(data, size, destructor, hint)
111 size = Integer(size)
112 ptr = ::CZMQ::FFI.zchunk_frommem(data, size, destructor, hint)
84113 __new ptr
85114 end
86115
316345 result
317346 end
318347
348 # Transform zchunk into a zframe that can be sent in a message.
349 # Take ownership of the chunk.
350 #
351 # @param self_p [#__ptr_give_ref]
352 # @return [Zframe]
353 def self.packx(self_p)
354 self_p = self_p.__ptr_give_ref
355 result = ::CZMQ::FFI.zchunk_packx(self_p)
356 result = Zframe.__new result, true
357 result
358 end
359
319360 # Transform a zframe into a zchunk.
320361 #
321362 # @param frame [Zframe, #__ptr]
130130 result
131131 end
132132
133 # Create copy of zconfig, caller MUST free the value
134 # Create copy of config, as new zconfig object. Returns a fresh zconfig_t
135 # object. If config is null, or memory was exhausted, returns null.
136 #
137 # @return [Zconfig]
138 def dup()
139 raise DestroyedError unless @ptr
140 self_p = @ptr
141 result = ::CZMQ::FFI.zconfig_dup(self_p)
142 result = Zconfig.__new result, true
143 result
144 end
145
133146 # Return name of config item
134147 #
135148 # @return [::FFI::Pointer]
8585 __new ptr
8686 end
8787
88 # Create new temporary file for writing via tmpfile. File is automaticaly
88 # Create new temporary file for writing via tmpfile. File is automatically
8989 # deleted on destroy
9090 # @return [CZMQ::Zfile]
9191 def self.tmp()
8181 @finalizer = nil
8282 end
8383
84 # Create a new callback of the following type:
85 # Destroy an item
86 # typedef void (zframe_destructor_fn) (
87 # void **hint);
88 #
89 # @note WARNING: If your Ruby code doesn't retain a reference to the
90 # FFI::Function object after passing it to a C function call,
91 # it may be garbage collected while C still holds the pointer,
92 # potentially resulting in a segmentation fault.
93 def self.destructor_fn
94 ::FFI::Function.new :void, [:pointer], blocking: true do |hint|
95 result = yield hint
96 result
97 end
98 end
99
84100 # Create a new frame. If size is not null, allocates the frame data
85101 # to the specified size. If additionally, data is not null, copies
86102 # size octets from the specified data into the frame body.
108124 __new ptr
109125 end
110126
127 # Create a new frame from memory. Take ownership of the memory and calling the destructor
128 # on destroy.
129 # @param data [::FFI::Pointer, #to_ptr]
130 # @param size [Integer, #to_int, #to_i]
131 # @param destructor [::FFI::Pointer, #to_ptr]
132 # @param hint [::FFI::Pointer, #to_ptr]
133 # @return [CZMQ::Zframe]
134 def self.frommem(data, size, destructor, hint)
135 size = Integer(size)
136 ptr = ::CZMQ::FFI.zframe_frommem(data, size, destructor, hint)
137 __new ptr
138 end
139
111140 # Receive frame from socket, returns zframe_t object or NULL if the recv
112141 # was interrupted. Does a blocking recv, if you want to not block then use
113142 # zpoller or zloop.
0 ################################################################################
1 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
2 # Read the zproject/README.md for information about making permanent changes. #
3 ################################################################################
4
5 module CZMQ
6 module FFI
7
8 # Http client, allowing multiple requests simultaneously and integrate easily with zpoller.
9 # Use zhttp_request class to create and send the request.
10 # Use zhttp_response class to receive the response.
11 # @note This class is 100% generated using zproject.
12 class ZhttpClient
13 # Raised when one tries to use an instance of {ZhttpClient} after
14 # the internal pointer to the native object has been nullified.
15 class DestroyedError < RuntimeError; end
16
17 # Boilerplate for self pointer, initializer, and finalizer
18 class << self
19 alias :__new :new
20 end
21 # Attaches the pointer _ptr_ to this instance and defines a finalizer for
22 # it if necessary.
23 # @param ptr [::FFI::Pointer]
24 # @param finalize [Boolean]
25 def initialize(ptr, finalize = true)
26 @ptr = ptr
27 if @ptr.null?
28 @ptr = nil # Remove null pointers so we don't have to test for them.
29 elsif finalize
30 @finalizer = self.class.create_finalizer_for @ptr
31 ObjectSpace.define_finalizer self, @finalizer
32 end
33 end
34 # @param ptr [::FFI::Pointer]
35 # @return [Proc]
36 def self.create_finalizer_for(ptr)
37 Proc.new do
38 ptr_ptr = ::FFI::MemoryPointer.new :pointer
39 ptr_ptr.write_pointer ptr
40 ::CZMQ::FFI.zhttp_client_destroy ptr_ptr
41 end
42 end
43 # @return [Boolean]
44 def null?
45 !@ptr or @ptr.null?
46 end
47 # Return internal pointer
48 # @return [::FFI::Pointer]
49 def __ptr
50 raise DestroyedError unless @ptr
51 @ptr
52 end
53 # So external Libraries can just pass the Object to a FFI function which expects a :pointer
54 alias_method :to_ptr, :__ptr
55 # Nullify internal pointer and return pointer pointer.
56 # @note This detaches the current instance from the native object
57 # and thus makes it unusable.
58 # @return [::FFI::MemoryPointer] the pointer pointing to a pointer
59 # pointing to the native object
60 def __ptr_give_ref
61 raise DestroyedError unless @ptr
62 ptr_ptr = ::FFI::MemoryPointer.new :pointer
63 ptr_ptr.write_pointer @ptr
64 __undef_finalizer if @finalizer
65 @ptr = nil
66 ptr_ptr
67 end
68 # Undefines the finalizer for this object.
69 # @note Only use this if you need to and can guarantee that the native
70 # object will be freed by other means.
71 # @return [void]
72 def __undef_finalizer
73 ObjectSpace.undefine_finalizer self
74 @finalizer = nil
75 end
76
77 # Create a new http client
78 # @param verbose [Boolean]
79 # @return [CZMQ::ZhttpClient]
80 def self.new(verbose)
81 verbose = !(0==verbose||!verbose) # boolean
82 ptr = ::CZMQ::FFI.zhttp_client_new(verbose)
83 __new ptr
84 end
85
86 # Destroy an http client
87 #
88 # @return [void]
89 def destroy()
90 return unless @ptr
91 self_p = __ptr_give_ref
92 result = ::CZMQ::FFI.zhttp_client_destroy(self_p)
93 result
94 end
95
96 # Self test of this class.
97 #
98 # @param verbose [Boolean]
99 # @return [void]
100 def self.test(verbose)
101 verbose = !(0==verbose||!verbose) # boolean
102 result = ::CZMQ::FFI.zhttp_client_test(verbose)
103 result
104 end
105 end
106 end
107 end
108
109 ################################################################################
110 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
111 # Read the zproject/README.md for information about making permanent changes. #
112 ################################################################################
0 ################################################################################
1 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
2 # Read the zproject/README.md for information about making permanent changes. #
3 ################################################################################
4
5 module CZMQ
6 module FFI
7
8 # Http request that can be received from zhttp_server or sent to zhttp_client.
9 # Class can be reused between send & recv calls.
10 # Headers and Content is being destroyed after every send call.
11 # @note This class is 100% generated using zproject.
12 class ZhttpRequest
13 # Raised when one tries to use an instance of {ZhttpRequest} after
14 # the internal pointer to the native object has been nullified.
15 class DestroyedError < RuntimeError; end
16
17 # Boilerplate for self pointer, initializer, and finalizer
18 class << self
19 alias :__new :new
20 end
21 # Attaches the pointer _ptr_ to this instance and defines a finalizer for
22 # it if necessary.
23 # @param ptr [::FFI::Pointer]
24 # @param finalize [Boolean]
25 def initialize(ptr, finalize = true)
26 @ptr = ptr
27 if @ptr.null?
28 @ptr = nil # Remove null pointers so we don't have to test for them.
29 elsif finalize
30 @finalizer = self.class.create_finalizer_for @ptr
31 ObjectSpace.define_finalizer self, @finalizer
32 end
33 end
34 # @param ptr [::FFI::Pointer]
35 # @return [Proc]
36 def self.create_finalizer_for(ptr)
37 Proc.new do
38 ptr_ptr = ::FFI::MemoryPointer.new :pointer
39 ptr_ptr.write_pointer ptr
40 ::CZMQ::FFI.zhttp_request_destroy ptr_ptr
41 end
42 end
43 # @return [Boolean]
44 def null?
45 !@ptr or @ptr.null?
46 end
47 # Return internal pointer
48 # @return [::FFI::Pointer]
49 def __ptr
50 raise DestroyedError unless @ptr
51 @ptr
52 end
53 # So external Libraries can just pass the Object to a FFI function which expects a :pointer
54 alias_method :to_ptr, :__ptr
55 # Nullify internal pointer and return pointer pointer.
56 # @note This detaches the current instance from the native object
57 # and thus makes it unusable.
58 # @return [::FFI::MemoryPointer] the pointer pointing to a pointer
59 # pointing to the native object
60 def __ptr_give_ref
61 raise DestroyedError unless @ptr
62 ptr_ptr = ::FFI::MemoryPointer.new :pointer
63 ptr_ptr.write_pointer @ptr
64 __undef_finalizer if @finalizer
65 @ptr = nil
66 ptr_ptr
67 end
68 # Undefines the finalizer for this object.
69 # @note Only use this if you need to and can guarantee that the native
70 # object will be freed by other means.
71 # @return [void]
72 def __undef_finalizer
73 ObjectSpace.undefine_finalizer self
74 @finalizer = nil
75 end
76
77 # Create a new http request.
78 # @return [CZMQ::ZhttpRequest]
79 def self.new()
80 ptr = ::CZMQ::FFI.zhttp_request_new()
81 __new ptr
82 end
83
84 # Destroy an http request.
85 #
86 # @return [void]
87 def destroy()
88 return unless @ptr
89 self_p = __ptr_give_ref
90 result = ::CZMQ::FFI.zhttp_request_destroy(self_p)
91 result
92 end
93
94 # Receive a new request from zhttp_server.
95 # Return the underlying connection if successful, to be used when calling zhttp_response_send.
96 #
97 # @param sock [Zsock, #__ptr]
98 # @return [::FFI::Pointer]
99 def recv(sock)
100 raise DestroyedError unless @ptr
101 self_p = @ptr
102 sock = sock.__ptr if sock
103 result = ::CZMQ::FFI.zhttp_request_recv(self_p, sock)
104 result
105 end
106
107 # Send a request to zhttp_client.
108 # Url and the request path will be concatenated.
109 # This behavior is useful for url rewrite and reverse proxy.
110 #
111 # Send also allow two user provided arguments which will be returned with the response.
112 # The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an arg.
113 #
114 # @param client [ZhttpClient, #__ptr]
115 # @param timeout [Integer, #to_int, #to_i]
116 # @param arg [::FFI::Pointer, #to_ptr]
117 # @param arg2 [::FFI::Pointer, #to_ptr]
118 # @return [Integer]
119 def send(client, timeout, arg, arg2)
120 raise DestroyedError unless @ptr
121 self_p = @ptr
122 client = client.__ptr if client
123 timeout = Integer(timeout)
124 result = ::CZMQ::FFI.zhttp_request_send(self_p, client, timeout, arg, arg2)
125 result
126 end
127
128 # Get the request method
129 #
130 # @return [String]
131 def method()
132 raise DestroyedError unless @ptr
133 self_p = @ptr
134 result = ::CZMQ::FFI.zhttp_request_method(self_p)
135 result
136 end
137
138 # Set the request method
139 #
140 # @param method [String, #to_s, nil]
141 # @return [void]
142 def set_method(method)
143 raise DestroyedError unless @ptr
144 self_p = @ptr
145 result = ::CZMQ::FFI.zhttp_request_set_method(self_p, method)
146 result
147 end
148
149 # Get the request url.
150 # When receiving a request from http server this is only the path part of the url.
151 #
152 # @return [String]
153 def url()
154 raise DestroyedError unless @ptr
155 self_p = @ptr
156 result = ::CZMQ::FFI.zhttp_request_url(self_p)
157 result
158 end
159
160 # Set the request url
161 # When sending a request to http client this should be full url.
162 #
163 # @param url [String, #to_s, nil]
164 # @return [void]
165 def set_url(url)
166 raise DestroyedError unless @ptr
167 self_p = @ptr
168 result = ::CZMQ::FFI.zhttp_request_set_url(self_p, url)
169 result
170 end
171
172 # Get the request content type
173 #
174 # @return [String]
175 def content_type()
176 raise DestroyedError unless @ptr
177 self_p = @ptr
178 result = ::CZMQ::FFI.zhttp_request_content_type(self_p)
179 result
180 end
181
182 # Set the request content type
183 #
184 # @param content_type [String, #to_s, nil]
185 # @return [void]
186 def set_content_type(content_type)
187 raise DestroyedError unless @ptr
188 self_p = @ptr
189 result = ::CZMQ::FFI.zhttp_request_set_content_type(self_p, content_type)
190 result
191 end
192
193 # Get the content length of the request
194 #
195 # @return [Integer]
196 def content_length()
197 raise DestroyedError unless @ptr
198 self_p = @ptr
199 result = ::CZMQ::FFI.zhttp_request_content_length(self_p)
200 result
201 end
202
203 # Get the headers of the request
204 #
205 # @return [Zhash]
206 def headers()
207 raise DestroyedError unless @ptr
208 self_p = @ptr
209 result = ::CZMQ::FFI.zhttp_request_headers(self_p)
210 result = Zhash.__new result, false
211 result
212 end
213
214 # Get the content of the request.
215 #
216 # @return [String]
217 def content()
218 raise DestroyedError unless @ptr
219 self_p = @ptr
220 result = ::CZMQ::FFI.zhttp_request_content(self_p)
221 result
222 end
223
224 # Get the content of the request.
225 #
226 # @return [::FFI::AutoPointer]
227 def get_content()
228 raise DestroyedError unless @ptr
229 self_p = @ptr
230 result = ::CZMQ::FFI.zhttp_request_get_content(self_p)
231 result = ::FFI::AutoPointer.new(result, LibC.method(:free))
232 result
233 end
234
235 # Set the content of the request.
236 # Content must by dynamically allocated string.
237 # Takes ownership of the content.
238 #
239 # @param content [::FFI::Pointer, #to_ptr]
240 # @return [void]
241 def set_content(content)
242 raise DestroyedError unless @ptr
243 self_p = @ptr
244 result = ::CZMQ::FFI.zhttp_request_set_content(self_p, content)
245 result
246 end
247
248 # Set the content of the request..
249 # The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
250 #
251 # @param content [String, #to_s, nil]
252 # @return [void]
253 def set_content_const(content)
254 raise DestroyedError unless @ptr
255 self_p = @ptr
256 result = ::CZMQ::FFI.zhttp_request_set_content_const(self_p, content)
257 result
258 end
259
260 # Set the content to NULL
261 #
262 # @return [void]
263 def reset_content()
264 raise DestroyedError unless @ptr
265 self_p = @ptr
266 result = ::CZMQ::FFI.zhttp_request_reset_content(self_p)
267 result
268 end
269
270 # Match the path of the request.
271 # Support wildcards with '%s' symbol inside the match string.
272 # Matching wildcards until the next '/', '?' or '\0'.
273 # On successful match the variadic arguments will be filled with the matching strings.
274 # On successful match the method is modifying the url field and break it into substrings.
275 # If you need to use the url, do it before matching or take a copy.
276 #
277 # User must not free the variadic arguments as they are part of the url.
278 #
279 # To use the percent symbol, just double it, e.g "%%something".
280 #
281 # Example:
282 # if (zhttp_request_match (request, "POST", "/send/%s/%s", &name, &id))
283 #
284 # @param method [String, #to_s, nil]
285 # @param path [String, #to_s, nil]
286 # @param args [Array<Object>] see https://github.com/ffi/ffi/wiki/examples#using-varargs
287 # @return [Boolean]
288 def match(method, path, *args)
289 raise DestroyedError unless @ptr
290 self_p = @ptr
291 result = ::CZMQ::FFI.zhttp_request_match(self_p, method, path, *args)
292 result
293 end
294
295 # Self test of this class.
296 #
297 # @param verbose [Boolean]
298 # @return [void]
299 def self.test(verbose)
300 verbose = !(0==verbose||!verbose) # boolean
301 result = ::CZMQ::FFI.zhttp_request_test(verbose)
302 result
303 end
304 end
305 end
306 end
307
308 ################################################################################
309 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
310 # Read the zproject/README.md for information about making permanent changes. #
311 ################################################################################
0 ################################################################################
1 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
2 # Read the zproject/README.md for information about making permanent changes. #
3 ################################################################################
4
5 module CZMQ
6 module FFI
7
8 # Http response that can be received from zhttp_client or sent to zhttp_server.
9 # Class can be reused between send & recv calls.
10 # Headers and Content is being destroyed after every send call.
11 # @note This class is 100% generated using zproject.
12 class ZhttpResponse
13 # Raised when one tries to use an instance of {ZhttpResponse} after
14 # the internal pointer to the native object has been nullified.
15 class DestroyedError < RuntimeError; end
16
17 # Boilerplate for self pointer, initializer, and finalizer
18 class << self
19 alias :__new :new
20 end
21 # Attaches the pointer _ptr_ to this instance and defines a finalizer for
22 # it if necessary.
23 # @param ptr [::FFI::Pointer]
24 # @param finalize [Boolean]
25 def initialize(ptr, finalize = true)
26 @ptr = ptr
27 if @ptr.null?
28 @ptr = nil # Remove null pointers so we don't have to test for them.
29 elsif finalize
30 @finalizer = self.class.create_finalizer_for @ptr
31 ObjectSpace.define_finalizer self, @finalizer
32 end
33 end
34 # @param ptr [::FFI::Pointer]
35 # @return [Proc]
36 def self.create_finalizer_for(ptr)
37 Proc.new do
38 ptr_ptr = ::FFI::MemoryPointer.new :pointer
39 ptr_ptr.write_pointer ptr
40 ::CZMQ::FFI.zhttp_response_destroy ptr_ptr
41 end
42 end
43 # @return [Boolean]
44 def null?
45 !@ptr or @ptr.null?
46 end
47 # Return internal pointer
48 # @return [::FFI::Pointer]
49 def __ptr
50 raise DestroyedError unless @ptr
51 @ptr
52 end
53 # So external Libraries can just pass the Object to a FFI function which expects a :pointer
54 alias_method :to_ptr, :__ptr
55 # Nullify internal pointer and return pointer pointer.
56 # @note This detaches the current instance from the native object
57 # and thus makes it unusable.
58 # @return [::FFI::MemoryPointer] the pointer pointing to a pointer
59 # pointing to the native object
60 def __ptr_give_ref
61 raise DestroyedError unless @ptr
62 ptr_ptr = ::FFI::MemoryPointer.new :pointer
63 ptr_ptr.write_pointer @ptr
64 __undef_finalizer if @finalizer
65 @ptr = nil
66 ptr_ptr
67 end
68 # Undefines the finalizer for this object.
69 # @note Only use this if you need to and can guarantee that the native
70 # object will be freed by other means.
71 # @return [void]
72 def __undef_finalizer
73 ObjectSpace.undefine_finalizer self
74 @finalizer = nil
75 end
76
77 # Create a new zhttp_response.
78 # @return [CZMQ::ZhttpResponse]
79 def self.new()
80 ptr = ::CZMQ::FFI.zhttp_response_new()
81 __new ptr
82 end
83
84 # Destroy the zhttp_response.
85 #
86 # @return [void]
87 def destroy()
88 return unless @ptr
89 self_p = __ptr_give_ref
90 result = ::CZMQ::FFI.zhttp_response_destroy(self_p)
91 result
92 end
93
94 # Send a response to a request.
95 # Returns 0 if successful and -1 otherwise.
96 #
97 # @param sock [Zsock, #__ptr]
98 # @param connection [::FFI::Pointer, #to_ptr]
99 # @return [Integer]
100 def send(sock, connection)
101 raise DestroyedError unless @ptr
102 self_p = @ptr
103 sock = sock.__ptr if sock
104 result = ::CZMQ::FFI.zhttp_response_send(self_p, sock, connection)
105 result
106 end
107
108 # Receive a response from zhttp_client.
109 # On success return 0, -1 otherwise.
110 #
111 # Recv returns the two user arguments which was provided with the request.
112 # The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an argument.
113 #
114 # @param client [ZhttpClient, #__ptr]
115 # @param arg [::FFI::Pointer, #to_ptr]
116 # @param arg2 [::FFI::Pointer, #to_ptr]
117 # @return [Integer]
118 def recv(client, arg, arg2)
119 raise DestroyedError unless @ptr
120 self_p = @ptr
121 client = client.__ptr if client
122 result = ::CZMQ::FFI.zhttp_response_recv(self_p, client, arg, arg2)
123 result
124 end
125
126 # Get the response content type
127 #
128 # @return [String]
129 def content_type()
130 raise DestroyedError unless @ptr
131 self_p = @ptr
132 result = ::CZMQ::FFI.zhttp_response_content_type(self_p)
133 result
134 end
135
136 # Set the content type of the response.
137 #
138 # @param value [String, #to_s, nil]
139 # @return [void]
140 def set_content_type(value)
141 raise DestroyedError unless @ptr
142 self_p = @ptr
143 result = ::CZMQ::FFI.zhttp_response_set_content_type(self_p, value)
144 result
145 end
146
147 # Get the status code of the response.
148 #
149 # @return [Integer]
150 def status_code()
151 raise DestroyedError unless @ptr
152 self_p = @ptr
153 result = ::CZMQ::FFI.zhttp_response_status_code(self_p)
154 result
155 end
156
157 # Set the status code of the response.
158 #
159 # @param status_code [Integer, #to_int, #to_i]
160 # @return [void]
161 def set_status_code(status_code)
162 raise DestroyedError unless @ptr
163 self_p = @ptr
164 status_code = Integer(status_code)
165 result = ::CZMQ::FFI.zhttp_response_set_status_code(self_p, status_code)
166 result
167 end
168
169 # Get the headers of the response.
170 #
171 # @return [Zhash]
172 def headers()
173 raise DestroyedError unless @ptr
174 self_p = @ptr
175 result = ::CZMQ::FFI.zhttp_response_headers(self_p)
176 result = Zhash.__new result, false
177 result
178 end
179
180 # Get the content length of the response
181 #
182 # @return [Integer]
183 def content_length()
184 raise DestroyedError unless @ptr
185 self_p = @ptr
186 result = ::CZMQ::FFI.zhttp_response_content_length(self_p)
187 result
188 end
189
190 # Get the content of the response.
191 #
192 # @return [String]
193 def content()
194 raise DestroyedError unless @ptr
195 self_p = @ptr
196 result = ::CZMQ::FFI.zhttp_response_content(self_p)
197 result
198 end
199
200 # Get the content of the response.
201 #
202 # @return [::FFI::AutoPointer]
203 def get_content()
204 raise DestroyedError unless @ptr
205 self_p = @ptr
206 result = ::CZMQ::FFI.zhttp_response_get_content(self_p)
207 result = ::FFI::AutoPointer.new(result, LibC.method(:free))
208 result
209 end
210
211 # Set the content of the response.
212 # Content must by dynamically allocated string.
213 # Takes ownership of the content.
214 #
215 # @param content [::FFI::Pointer, #to_ptr]
216 # @return [void]
217 def set_content(content)
218 raise DestroyedError unless @ptr
219 self_p = @ptr
220 result = ::CZMQ::FFI.zhttp_response_set_content(self_p, content)
221 result
222 end
223
224 # Set the content of the response.
225 # The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
226 #
227 # @param content [String, #to_s, nil]
228 # @return [void]
229 def set_content_const(content)
230 raise DestroyedError unless @ptr
231 self_p = @ptr
232 result = ::CZMQ::FFI.zhttp_response_set_content_const(self_p, content)
233 result
234 end
235
236 # Set the content to NULL
237 #
238 # @return [void]
239 def reset_content()
240 raise DestroyedError unless @ptr
241 self_p = @ptr
242 result = ::CZMQ::FFI.zhttp_response_reset_content(self_p)
243 result
244 end
245
246 # Self test of this class.
247 #
248 # @param verbose [Boolean]
249 # @return [void]
250 def self.test(verbose)
251 verbose = !(0==verbose||!verbose) # boolean
252 result = ::CZMQ::FFI.zhttp_response_test(verbose)
253 result
254 end
255 end
256 end
257 end
258
259 ################################################################################
260 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
261 # Read the zproject/README.md for information about making permanent changes. #
262 ################################################################################
0 ################################################################################
1 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
2 # Read the zproject/README.md for information about making permanent changes. #
3 ################################################################################
4
5 module CZMQ
6 module FFI
7
8 # Simple http server.
9 # To start handling requests:
10 # 1. Create a dealer socket
11 # 2. Connect the socket to the server backend address provided in the options.
12 # 3. Create a zhttp_request.
13 # 4. Call zhttp_request_recv to accept a new request.
14 # 5. Call zhttp_response_send to send a response.
15 #
16 # You can connect as many dealers as you want.
17 # The Server is using simple dealer socket to route the requests.
18 #
19 # NOTE: when using libmicrohttpd << 0.9.34 the application might experience
20 # high CPU usage due to the lack of MHD_suspend_connection and
21 # MHD_resume_connection APIs. It is recommended to use this class only with
22 # libmicrohttpd at least 0.9.34 in production.
23 # @note This class is 100% generated using zproject.
24 class ZhttpServer
25 # Raised when one tries to use an instance of {ZhttpServer} after
26 # the internal pointer to the native object has been nullified.
27 class DestroyedError < RuntimeError; end
28
29 # Boilerplate for self pointer, initializer, and finalizer
30 class << self
31 alias :__new :new
32 end
33 # Attaches the pointer _ptr_ to this instance and defines a finalizer for
34 # it if necessary.
35 # @param ptr [::FFI::Pointer]
36 # @param finalize [Boolean]
37 def initialize(ptr, finalize = true)
38 @ptr = ptr
39 if @ptr.null?
40 @ptr = nil # Remove null pointers so we don't have to test for them.
41 elsif finalize
42 @finalizer = self.class.create_finalizer_for @ptr
43 ObjectSpace.define_finalizer self, @finalizer
44 end
45 end
46 # @param ptr [::FFI::Pointer]
47 # @return [Proc]
48 def self.create_finalizer_for(ptr)
49 Proc.new do
50 ptr_ptr = ::FFI::MemoryPointer.new :pointer
51 ptr_ptr.write_pointer ptr
52 ::CZMQ::FFI.zhttp_server_destroy ptr_ptr
53 end
54 end
55 # @return [Boolean]
56 def null?
57 !@ptr or @ptr.null?
58 end
59 # Return internal pointer
60 # @return [::FFI::Pointer]
61 def __ptr
62 raise DestroyedError unless @ptr
63 @ptr
64 end
65 # So external Libraries can just pass the Object to a FFI function which expects a :pointer
66 alias_method :to_ptr, :__ptr
67 # Nullify internal pointer and return pointer pointer.
68 # @note This detaches the current instance from the native object
69 # and thus makes it unusable.
70 # @return [::FFI::MemoryPointer] the pointer pointing to a pointer
71 # pointing to the native object
72 def __ptr_give_ref
73 raise DestroyedError unless @ptr
74 ptr_ptr = ::FFI::MemoryPointer.new :pointer
75 ptr_ptr.write_pointer @ptr
76 __undef_finalizer if @finalizer
77 @ptr = nil
78 ptr_ptr
79 end
80 # Undefines the finalizer for this object.
81 # @note Only use this if you need to and can guarantee that the native
82 # object will be freed by other means.
83 # @return [void]
84 def __undef_finalizer
85 ObjectSpace.undefine_finalizer self
86 @finalizer = nil
87 end
88
89 # Create a new http server
90 # @param options [ZhttpServerOptions, #__ptr]
91 # @return [CZMQ::ZhttpServer]
92 def self.new(options)
93 options = options.__ptr if options
94 ptr = ::CZMQ::FFI.zhttp_server_new(options)
95 __new ptr
96 end
97
98 # Destroy an http server
99 #
100 # @return [void]
101 def destroy()
102 return unless @ptr
103 self_p = __ptr_give_ref
104 result = ::CZMQ::FFI.zhttp_server_destroy(self_p)
105 result
106 end
107
108 # Return the port the server is listening on.
109 #
110 # @return [Integer]
111 def port()
112 raise DestroyedError unless @ptr
113 self_p = @ptr
114 result = ::CZMQ::FFI.zhttp_server_port(self_p)
115 result
116 end
117
118 # Self test of this class.
119 #
120 # @param verbose [Boolean]
121 # @return [void]
122 def self.test(verbose)
123 verbose = !(0==verbose||!verbose) # boolean
124 result = ::CZMQ::FFI.zhttp_server_test(verbose)
125 result
126 end
127 end
128 end
129 end
130
131 ################################################################################
132 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
133 # Read the zproject/README.md for information about making permanent changes. #
134 ################################################################################
0 ################################################################################
1 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
2 # Read the zproject/README.md for information about making permanent changes. #
3 ################################################################################
4
5 module CZMQ
6 module FFI
7
8 #
9 # @note This class is 100% generated using zproject.
10 class ZhttpServerConnection
11 # Raised when one tries to use an instance of {ZhttpServerConnection} after
12 # the internal pointer to the native object has been nullified.
13 class DestroyedError < RuntimeError; end
14
15 # Boilerplate for self pointer, initializer, and finalizer
16 class << self
17 alias :__new :new
18 end
19 # Attaches the pointer _ptr_ to this instance and defines a finalizer for
20 # it if necessary.
21 # @param ptr [::FFI::Pointer]
22 # @param finalize [Boolean]
23 def initialize(ptr, finalize = true)
24 @ptr = ptr
25 if @ptr.null?
26 @ptr = nil # Remove null pointers so we don't have to test for them.
27 elsif finalize
28 @finalizer = self.class.create_finalizer_for @ptr
29 ObjectSpace.define_finalizer self, @finalizer
30 end
31 end
32 # @return [Proc]
33 def self.create_finalizer_for(ptr)
34 Proc.new do
35 "WARNING: "\
36 "Objects of type #{self} cannot be destroyed implicitly. "\
37 "Please call the correct destroy method with the relevant arguments."
38 end
39 end
40 # @return [Boolean]
41 def null?
42 !@ptr or @ptr.null?
43 end
44 # Return internal pointer
45 # @return [::FFI::Pointer]
46 def __ptr
47 raise DestroyedError unless @ptr
48 @ptr
49 end
50 # So external Libraries can just pass the Object to a FFI function which expects a :pointer
51 alias_method :to_ptr, :__ptr
52 # Nullify internal pointer and return pointer pointer.
53 # @note This detaches the current instance from the native object
54 # and thus makes it unusable.
55 # @return [::FFI::MemoryPointer] the pointer pointing to a pointer
56 # pointing to the native object
57 def __ptr_give_ref
58 raise DestroyedError unless @ptr
59 ptr_ptr = ::FFI::MemoryPointer.new :pointer
60 ptr_ptr.write_pointer @ptr
61 __undef_finalizer if @finalizer
62 @ptr = nil
63 ptr_ptr
64 end
65 # Undefines the finalizer for this object.
66 # @note Only use this if you need to and can guarantee that the native
67 # object will be freed by other means.
68 # @return [void]
69 def __undef_finalizer
70 ObjectSpace.undefine_finalizer self
71 @finalizer = nil
72 end
73
74 # Self test of this class.
75 #
76 # @param verbose [Boolean]
77 # @return [void]
78 def self.test(verbose)
79 verbose = !(0==verbose||!verbose) # boolean
80 result = ::CZMQ::FFI.zhttp_server_connection_test(verbose)
81 result
82 end
83 end
84 end
85 end
86
87 ################################################################################
88 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
89 # Read the zproject/README.md for information about making permanent changes. #
90 ################################################################################
0 ################################################################################
1 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
2 # Read the zproject/README.md for information about making permanent changes. #
3 ################################################################################
4
5 module CZMQ
6 module FFI
7
8 # zhttp server.
9 # @note This class is 100% generated using zproject.
10 class ZhttpServerOptions
11 # Raised when one tries to use an instance of {ZhttpServerOptions} after
12 # the internal pointer to the native object has been nullified.
13 class DestroyedError < RuntimeError; end
14
15 # Boilerplate for self pointer, initializer, and finalizer
16 class << self
17 alias :__new :new
18 end
19 # Attaches the pointer _ptr_ to this instance and defines a finalizer for
20 # it if necessary.
21 # @param ptr [::FFI::Pointer]
22 # @param finalize [Boolean]
23 def initialize(ptr, finalize = true)
24 @ptr = ptr
25 if @ptr.null?
26 @ptr = nil # Remove null pointers so we don't have to test for them.
27 elsif finalize
28 @finalizer = self.class.create_finalizer_for @ptr
29 ObjectSpace.define_finalizer self, @finalizer
30 end
31 end
32 # @param ptr [::FFI::Pointer]
33 # @return [Proc]
34 def self.create_finalizer_for(ptr)
35 Proc.new do
36 ptr_ptr = ::FFI::MemoryPointer.new :pointer
37 ptr_ptr.write_pointer ptr
38 ::CZMQ::FFI.zhttp_server_options_destroy ptr_ptr
39 end
40 end
41 # @return [Boolean]
42 def null?
43 !@ptr or @ptr.null?
44 end
45 # Return internal pointer
46 # @return [::FFI::Pointer]
47 def __ptr
48 raise DestroyedError unless @ptr
49 @ptr
50 end
51 # So external Libraries can just pass the Object to a FFI function which expects a :pointer
52 alias_method :to_ptr, :__ptr
53 # Nullify internal pointer and return pointer pointer.
54 # @note This detaches the current instance from the native object
55 # and thus makes it unusable.
56 # @return [::FFI::MemoryPointer] the pointer pointing to a pointer
57 # pointing to the native object
58 def __ptr_give_ref
59 raise DestroyedError unless @ptr
60 ptr_ptr = ::FFI::MemoryPointer.new :pointer
61 ptr_ptr.write_pointer @ptr
62 __undef_finalizer if @finalizer
63 @ptr = nil
64 ptr_ptr
65 end
66 # Undefines the finalizer for this object.
67 # @note Only use this if you need to and can guarantee that the native
68 # object will be freed by other means.
69 # @return [void]
70 def __undef_finalizer
71 ObjectSpace.undefine_finalizer self
72 @finalizer = nil
73 end
74
75 # Create a new zhttp_server_options.
76 # @return [CZMQ::ZhttpServerOptions]
77 def self.new()
78 ptr = ::CZMQ::FFI.zhttp_server_options_new()
79 __new ptr
80 end
81
82 # Create options from config tree.
83 # @param config [Zconfig, #__ptr]
84 # @return [CZMQ::ZhttpServerOptions]
85 def self.from_config(config)
86 config = config.__ptr if config
87 ptr = ::CZMQ::FFI.zhttp_server_options_from_config(config)
88 __new ptr
89 end
90
91 # Destroy the zhttp_server_options.
92 #
93 # @return [void]
94 def destroy()
95 return unless @ptr
96 self_p = __ptr_give_ref
97 result = ::CZMQ::FFI.zhttp_server_options_destroy(self_p)
98 result
99 end
100
101 # Get the server listening port.
102 #
103 # @return [Integer]
104 def port()
105 raise DestroyedError unless @ptr
106 self_p = @ptr
107 result = ::CZMQ::FFI.zhttp_server_options_port(self_p)
108 result
109 end
110
111 # Set the server listening port
112 #
113 # @param port [Integer, #to_int, #to_i]
114 # @return [void]
115 def set_port(port)
116 raise DestroyedError unless @ptr
117 self_p = @ptr
118 port = Integer(port)
119 result = ::CZMQ::FFI.zhttp_server_options_set_port(self_p, port)
120 result
121 end
122
123 # Get the address sockets should connect to in order to receive requests.
124 #
125 # @return [String]
126 def backend_address()
127 raise DestroyedError unless @ptr
128 self_p = @ptr
129 result = ::CZMQ::FFI.zhttp_server_options_backend_address(self_p)
130 result
131 end
132
133 # Set the address sockets should connect to in order to receive requests.
134 #
135 # @param address [String, #to_s, nil]
136 # @return [void]
137 def set_backend_address(address)
138 raise DestroyedError unless @ptr
139 self_p = @ptr
140 result = ::CZMQ::FFI.zhttp_server_options_set_backend_address(self_p, address)
141 result
142 end
143
144 # Self test of this class.
145 #
146 # @param verbose [Boolean]
147 # @return [void]
148 def self.test(verbose)
149 verbose = !(0==verbose||!verbose) # boolean
150 result = ::CZMQ::FFI.zhttp_server_options_test(verbose)
151 result
152 end
153 end
154 end
155 end
156
157 ################################################################################
158 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
159 # Read the zproject/README.md for information about making permanent changes. #
160 ################################################################################
128128 __new ptr
129129 end
130130
131 # Unpack binary frame into a new list. Packed data must follow format
132 # defined by zlistx_pack. List is set to autofree. An empty frame
133 # unpacks to an empty list.
134 # @param frame [Zframe, #__ptr]
135 # @return [CZMQ::Zlistx]
136 def self.unpack(frame)
137 frame = frame.__ptr if frame
138 ptr = ::CZMQ::FFI.zlistx_unpack(frame)
139 __new ptr
140 end
141
131142 # Destroy a list. If an item destructor was specified, all items in the
132143 # list are automatically destroyed as well.
133144 #
458469 result
459470 end
460471
472 # Serialize list to a binary frame that can be sent in a message.
473 # The packed format is compatible with the 'strings' type implemented by zproto:
474 #
475 # ; A list of strings
476 # list = list-count *longstr
477 # list-count = number-4
478 #
479 # ; Strings are always length + text contents
480 # longstr = number-4 *VCHAR
481 #
482 # ; Numbers are unsigned integers in network byte order
483 # number-4 = 4OCTET
484 #
485 # @return [Zframe]
486 def pack()
487 raise DestroyedError unless @ptr
488 self_p = @ptr
489 result = ::CZMQ::FFI.zlistx_pack(self_p)
490 result = Zframe.__new result, true
491 result
492 end
493
461494 # Self test of this class.
462495 #
463496 # @param verbose [Boolean]
253253 result
254254 end
255255
256 # The timeout should be zero or greater, or -1 to wait indefinitely.
256257 # wait or poll process status, return return code
257258 #
258 # @param hang [Boolean]
259 # @param timeout [Integer, #to_int, #to_i]
259260 # @return [Integer]
260 def wait(hang)
261 raise DestroyedError unless @ptr
262 self_p = @ptr
263 hang = !(0==hang||!hang) # boolean
264 result = ::CZMQ::FFI.zproc_wait(self_p, hang)
265 result
266 end
267
268 # return internal actor, usefull for the polling if process died
261 def wait(timeout)
262 raise DestroyedError unless @ptr
263 self_p = @ptr
264 timeout = Integer(timeout)
265 result = ::CZMQ::FFI.zproc_wait(self_p, timeout)
266 result
267 end
268
269 # send SIGTERM signal to the subprocess, wait for grace period and
270 # eventually send SIGKILL
271 #
272 # @param timeout [Integer, #to_int, #to_i]
273 # @return [void]
274 def shutdown(timeout)
275 raise DestroyedError unless @ptr
276 self_p = @ptr
277 timeout = Integer(timeout)
278 result = ::CZMQ::FFI.zproc_shutdown(self_p, timeout)
279 result
280 end
281
282 # return internal actor, useful for the polling if process died
269283 #
270284 # @return [::FFI::Pointer]
271285 def actor()
368368 # c = zchunk_t *
369369 # f = zframe_t *
370370 # h = zhashx_t *
371 # l = zlistx_t * (DRAFT)
371372 # U = zuuid_t *
372373 # p = void * (sends the pointer value, only meaningful over inproc)
373374 # m = zmsg_t * (sends all frames in the zmsg)
405406 # c = zchunk_t *
406407 # f = zframe_t *
407408 # h = zhashx_t *
409 # l = zlistx_t * (DRAFT)
408410 # U = zuuid_t *
409411 # p = void * (sends the pointer value, only meaningful over inproc)
410412 # m = zmsg_t * (sends all frames in the zmsg)
474476 # f = zframe_t ** (creates zframe)
475477 # U = zuuid_t * (creates a zuuid with the data)
476478 # h = zhashx_t ** (creates zhashx)
479 # l = zlistx_t ** (creates zlistx) (DRAFT)
477480 # p = void ** (stores pointer)
478 # m = zmsg_t ** (creates a zmsg with the remaing frames)
481 # m = zmsg_t ** (creates a zmsg with the remaining frames)
479482 # z = null, asserts empty frame (0 arguments)
480483 # u = uint * (stores unsigned integer, deprecated)
481484 #
511514 # f = zframe_t ** (creates zframe)
512515 # U = zuuid_t * (creates a zuuid with the data)
513516 # h = zhashx_t ** (creates zhashx)
517 # l = zlistx_t ** (creates zlistx) (DRAFT)
514518 # p = void ** (stores pointer)
515 # m = zmsg_t ** (creates a zmsg with the remaing frames)
519 # m = zmsg_t ** (creates a zmsg with the remaining frames)
516520 # z = null, asserts empty frame (0 arguments)
517521 # u = uint * (stores unsigned integer, deprecated)
518522 #
913917 result
914918 end
915919
920 # Check whether the socket has available message to read.
921 #
922 # @return [Boolean]
923 def has_in()
924 raise DestroyedError unless @ptr
925 self_p = @ptr
926 result = ::CZMQ::FFI.zsock_has_in(self_p)
927 result
928 end
929
930 # Check whether the socket has available message to read.
931 #
932 # This is the polymorphic version of #has_in.
933 #
934 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
935 # object reference to use this method on
936 # @return [Boolean]
937 def self.has_in(self_p)
938 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
939 result = ::CZMQ::FFI.zsock_has_in(self_p)
940 result
941 end
942
943 # Get socket option `router_notify`.
944 # Available from libzmq 4.3.0.
945 #
946 # @return [Integer]
947 def router_notify()
948 raise DestroyedError unless @ptr
949 self_p = @ptr
950 result = ::CZMQ::FFI.zsock_router_notify(self_p)
951 result
952 end
953
954 # Get socket option `router_notify`.
955 # Available from libzmq 4.3.0.
956 #
957 # This is the polymorphic version of #router_notify.
958 #
959 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
960 # object reference to use this method on
961 # @return [Integer]
962 def self.router_notify(self_p)
963 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
964 result = ::CZMQ::FFI.zsock_router_notify(self_p)
965 result
966 end
967
968 # Set socket option `router_notify`.
969 # Available from libzmq 4.3.0.
970 #
971 # @param router_notify [Integer, #to_int, #to_i]
972 # @return [void]
973 def set_router_notify(router_notify)
974 raise DestroyedError unless @ptr
975 self_p = @ptr
976 router_notify = Integer(router_notify)
977 result = ::CZMQ::FFI.zsock_set_router_notify(self_p, router_notify)
978 result
979 end
980
981 # Set socket option `router_notify`.
982 # Available from libzmq 4.3.0.
983 #
984 # This is the polymorphic version of #set_router_notify.
985 #
986 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
987 # object reference to use this method on
988 # @param router_notify [Integer, #to_int, #to_i]
989 # @return [void]
990 def self.set_router_notify(self_p, router_notify)
991 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
992 router_notify = Integer(router_notify)
993 result = ::CZMQ::FFI.zsock_set_router_notify(self_p, router_notify)
994 result
995 end
996
997 # Get socket option `multicast_loop`.
998 # Available from libzmq 4.3.0.
999 #
1000 # @return [Integer]
1001 def multicast_loop()
1002 raise DestroyedError unless @ptr
1003 self_p = @ptr
1004 result = ::CZMQ::FFI.zsock_multicast_loop(self_p)
1005 result
1006 end
1007
1008 # Get socket option `multicast_loop`.
1009 # Available from libzmq 4.3.0.
1010 #
1011 # This is the polymorphic version of #multicast_loop.
1012 #
1013 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
1014 # object reference to use this method on
1015 # @return [Integer]
1016 def self.multicast_loop(self_p)
1017 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
1018 result = ::CZMQ::FFI.zsock_multicast_loop(self_p)
1019 result
1020 end
1021
1022 # Set socket option `multicast_loop`.
1023 # Available from libzmq 4.3.0.
1024 #
1025 # @param multicast_loop [Integer, #to_int, #to_i]
1026 # @return [void]
1027 def set_multicast_loop(multicast_loop)
1028 raise DestroyedError unless @ptr
1029 self_p = @ptr
1030 multicast_loop = Integer(multicast_loop)
1031 result = ::CZMQ::FFI.zsock_set_multicast_loop(self_p, multicast_loop)
1032 result
1033 end
1034
1035 # Set socket option `multicast_loop`.
1036 # Available from libzmq 4.3.0.
1037 #
1038 # This is the polymorphic version of #set_multicast_loop.
1039 #
1040 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
1041 # object reference to use this method on
1042 # @param multicast_loop [Integer, #to_int, #to_i]
1043 # @return [void]
1044 def self.set_multicast_loop(self_p, multicast_loop)
1045 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
1046 multicast_loop = Integer(multicast_loop)
1047 result = ::CZMQ::FFI.zsock_set_multicast_loop(self_p, multicast_loop)
1048 result
1049 end
1050
1051 # Get socket option `metadata`.
1052 # Available from libzmq 4.3.0.
1053 #
1054 # @return [::FFI::AutoPointer]
1055 def metadata()
1056 raise DestroyedError unless @ptr
1057 self_p = @ptr
1058 result = ::CZMQ::FFI.zsock_metadata(self_p)
1059 result = ::FFI::AutoPointer.new(result, LibC.method(:free))
1060 result
1061 end
1062
1063 # Get socket option `metadata`.
1064 # Available from libzmq 4.3.0.
1065 #
1066 # This is the polymorphic version of #metadata.
1067 #
1068 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
1069 # object reference to use this method on
1070 # @return [::FFI::AutoPointer]
1071 def self.metadata(self_p)
1072 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
1073 result = ::CZMQ::FFI.zsock_metadata(self_p)
1074 result = ::FFI::AutoPointer.new(result, LibC.method(:free))
1075 result
1076 end
1077
1078 # Set socket option `metadata`.
1079 # Available from libzmq 4.3.0.
1080 #
1081 # @param metadata [String, #to_s, nil]
1082 # @return [void]
1083 def set_metadata(metadata)
1084 raise DestroyedError unless @ptr
1085 self_p = @ptr
1086 result = ::CZMQ::FFI.zsock_set_metadata(self_p, metadata)
1087 result
1088 end
1089
1090 # Set socket option `metadata`.
1091 # Available from libzmq 4.3.0.
1092 #
1093 # This is the polymorphic version of #set_metadata.
1094 #
1095 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
1096 # object reference to use this method on
1097 # @param metadata [String, #to_s, nil]
1098 # @return [void]
1099 def self.set_metadata(self_p, metadata)
1100 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
1101 result = ::CZMQ::FFI.zsock_set_metadata(self_p, metadata)
1102 result
1103 end
1104
1105 # Get socket option `loopback_fastpath`.
1106 # Available from libzmq 4.3.0.
1107 #
1108 # @return [Integer]
1109 def loopback_fastpath()
1110 raise DestroyedError unless @ptr
1111 self_p = @ptr
1112 result = ::CZMQ::FFI.zsock_loopback_fastpath(self_p)
1113 result
1114 end
1115
1116 # Get socket option `loopback_fastpath`.
1117 # Available from libzmq 4.3.0.
1118 #
1119 # This is the polymorphic version of #loopback_fastpath.
1120 #
1121 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
1122 # object reference to use this method on
1123 # @return [Integer]
1124 def self.loopback_fastpath(self_p)
1125 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
1126 result = ::CZMQ::FFI.zsock_loopback_fastpath(self_p)
1127 result
1128 end
1129
1130 # Set socket option `loopback_fastpath`.
1131 # Available from libzmq 4.3.0.
1132 #
1133 # @param loopback_fastpath [Integer, #to_int, #to_i]
1134 # @return [void]
1135 def set_loopback_fastpath(loopback_fastpath)
1136 raise DestroyedError unless @ptr
1137 self_p = @ptr
1138 loopback_fastpath = Integer(loopback_fastpath)
1139 result = ::CZMQ::FFI.zsock_set_loopback_fastpath(self_p, loopback_fastpath)
1140 result
1141 end
1142
1143 # Set socket option `loopback_fastpath`.
1144 # Available from libzmq 4.3.0.
1145 #
1146 # This is the polymorphic version of #set_loopback_fastpath.
1147 #
1148 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
1149 # object reference to use this method on
1150 # @param loopback_fastpath [Integer, #to_int, #to_i]
1151 # @return [void]
1152 def self.set_loopback_fastpath(self_p, loopback_fastpath)
1153 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
1154 loopback_fastpath = Integer(loopback_fastpath)
1155 result = ::CZMQ::FFI.zsock_set_loopback_fastpath(self_p, loopback_fastpath)
1156 result
1157 end
1158
1159 # Get socket option `zap_enforce_domain`.
1160 # Available from libzmq 4.3.0.
1161 #
1162 # @return [Integer]
1163 def zap_enforce_domain()
1164 raise DestroyedError unless @ptr
1165 self_p = @ptr
1166 result = ::CZMQ::FFI.zsock_zap_enforce_domain(self_p)
1167 result
1168 end
1169
1170 # Get socket option `zap_enforce_domain`.
1171 # Available from libzmq 4.3.0.
1172 #
1173 # This is the polymorphic version of #zap_enforce_domain.
1174 #
1175 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
1176 # object reference to use this method on
1177 # @return [Integer]
1178 def self.zap_enforce_domain(self_p)
1179 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
1180 result = ::CZMQ::FFI.zsock_zap_enforce_domain(self_p)
1181 result
1182 end
1183
1184 # Set socket option `zap_enforce_domain`.
1185 # Available from libzmq 4.3.0.
1186 #
1187 # @param zap_enforce_domain [Integer, #to_int, #to_i]
1188 # @return [void]
1189 def set_zap_enforce_domain(zap_enforce_domain)
1190 raise DestroyedError unless @ptr
1191 self_p = @ptr
1192 zap_enforce_domain = Integer(zap_enforce_domain)
1193 result = ::CZMQ::FFI.zsock_set_zap_enforce_domain(self_p, zap_enforce_domain)
1194 result
1195 end
1196
1197 # Set socket option `zap_enforce_domain`.
1198 # Available from libzmq 4.3.0.
1199 #
1200 # This is the polymorphic version of #set_zap_enforce_domain.
1201 #
1202 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
1203 # object reference to use this method on
1204 # @param zap_enforce_domain [Integer, #to_int, #to_i]
1205 # @return [void]
1206 def self.set_zap_enforce_domain(self_p, zap_enforce_domain)
1207 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
1208 zap_enforce_domain = Integer(zap_enforce_domain)
1209 result = ::CZMQ::FFI.zsock_set_zap_enforce_domain(self_p, zap_enforce_domain)
1210 result
1211 end
1212
1213 # Get socket option `gssapi_principal_nametype`.
1214 # Available from libzmq 4.3.0.
1215 #
1216 # @return [Integer]
1217 def gssapi_principal_nametype()
1218 raise DestroyedError unless @ptr
1219 self_p = @ptr
1220 result = ::CZMQ::FFI.zsock_gssapi_principal_nametype(self_p)
1221 result
1222 end
1223
1224 # Get socket option `gssapi_principal_nametype`.
1225 # Available from libzmq 4.3.0.
1226 #
1227 # This is the polymorphic version of #gssapi_principal_nametype.
1228 #
1229 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
1230 # object reference to use this method on
1231 # @return [Integer]
1232 def self.gssapi_principal_nametype(self_p)
1233 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
1234 result = ::CZMQ::FFI.zsock_gssapi_principal_nametype(self_p)
1235 result
1236 end
1237
1238 # Set socket option `gssapi_principal_nametype`.
1239 # Available from libzmq 4.3.0.
1240 #
1241 # @param gssapi_principal_nametype [Integer, #to_int, #to_i]
1242 # @return [void]
1243 def set_gssapi_principal_nametype(gssapi_principal_nametype)
1244 raise DestroyedError unless @ptr
1245 self_p = @ptr
1246 gssapi_principal_nametype = Integer(gssapi_principal_nametype)
1247 result = ::CZMQ::FFI.zsock_set_gssapi_principal_nametype(self_p, gssapi_principal_nametype)
1248 result
1249 end
1250
1251 # Set socket option `gssapi_principal_nametype`.
1252 # Available from libzmq 4.3.0.
1253 #
1254 # This is the polymorphic version of #set_gssapi_principal_nametype.
1255 #
1256 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
1257 # object reference to use this method on
1258 # @param gssapi_principal_nametype [Integer, #to_int, #to_i]
1259 # @return [void]
1260 def self.set_gssapi_principal_nametype(self_p, gssapi_principal_nametype)
1261 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
1262 gssapi_principal_nametype = Integer(gssapi_principal_nametype)
1263 result = ::CZMQ::FFI.zsock_set_gssapi_principal_nametype(self_p, gssapi_principal_nametype)
1264 result
1265 end
1266
1267 # Get socket option `gssapi_service_principal_nametype`.
1268 # Available from libzmq 4.3.0.
1269 #
1270 # @return [Integer]
1271 def gssapi_service_principal_nametype()
1272 raise DestroyedError unless @ptr
1273 self_p = @ptr
1274 result = ::CZMQ::FFI.zsock_gssapi_service_principal_nametype(self_p)
1275 result
1276 end
1277
1278 # Get socket option `gssapi_service_principal_nametype`.
1279 # Available from libzmq 4.3.0.
1280 #
1281 # This is the polymorphic version of #gssapi_service_principal_nametype.
1282 #
1283 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
1284 # object reference to use this method on
1285 # @return [Integer]
1286 def self.gssapi_service_principal_nametype(self_p)
1287 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
1288 result = ::CZMQ::FFI.zsock_gssapi_service_principal_nametype(self_p)
1289 result
1290 end
1291
1292 # Set socket option `gssapi_service_principal_nametype`.
1293 # Available from libzmq 4.3.0.
1294 #
1295 # @param gssapi_service_principal_nametype [Integer, #to_int, #to_i]
1296 # @return [void]
1297 def set_gssapi_service_principal_nametype(gssapi_service_principal_nametype)
1298 raise DestroyedError unless @ptr
1299 self_p = @ptr
1300 gssapi_service_principal_nametype = Integer(gssapi_service_principal_nametype)
1301 result = ::CZMQ::FFI.zsock_set_gssapi_service_principal_nametype(self_p, gssapi_service_principal_nametype)
1302 result
1303 end
1304
1305 # Set socket option `gssapi_service_principal_nametype`.
1306 # Available from libzmq 4.3.0.
1307 #
1308 # This is the polymorphic version of #set_gssapi_service_principal_nametype.
1309 #
1310 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
1311 # object reference to use this method on
1312 # @param gssapi_service_principal_nametype [Integer, #to_int, #to_i]
1313 # @return [void]
1314 def self.set_gssapi_service_principal_nametype(self_p, gssapi_service_principal_nametype)
1315 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
1316 gssapi_service_principal_nametype = Integer(gssapi_service_principal_nametype)
1317 result = ::CZMQ::FFI.zsock_set_gssapi_service_principal_nametype(self_p, gssapi_service_principal_nametype)
1318 result
1319 end
1320
1321 # Get socket option `bindtodevice`.
1322 # Available from libzmq 4.3.0.
1323 #
1324 # @return [::FFI::AutoPointer]
1325 def bindtodevice()
1326 raise DestroyedError unless @ptr
1327 self_p = @ptr
1328 result = ::CZMQ::FFI.zsock_bindtodevice(self_p)
1329 result = ::FFI::AutoPointer.new(result, LibC.method(:free))
1330 result
1331 end
1332
1333 # Get socket option `bindtodevice`.
1334 # Available from libzmq 4.3.0.
1335 #
1336 # This is the polymorphic version of #bindtodevice.
1337 #
1338 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
1339 # object reference to use this method on
1340 # @return [::FFI::AutoPointer]
1341 def self.bindtodevice(self_p)
1342 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
1343 result = ::CZMQ::FFI.zsock_bindtodevice(self_p)
1344 result = ::FFI::AutoPointer.new(result, LibC.method(:free))
1345 result
1346 end
1347
1348 # Set socket option `bindtodevice`.
1349 # Available from libzmq 4.3.0.
1350 #
1351 # @param bindtodevice [String, #to_s, nil]
1352 # @return [void]
1353 def set_bindtodevice(bindtodevice)
1354 raise DestroyedError unless @ptr
1355 self_p = @ptr
1356 result = ::CZMQ::FFI.zsock_set_bindtodevice(self_p, bindtodevice)
1357 result
1358 end
1359
1360 # Set socket option `bindtodevice`.
1361 # Available from libzmq 4.3.0.
1362 #
1363 # This is the polymorphic version of #set_bindtodevice.
1364 #
1365 # @param self_p [CZMQ::Zsock, #__ptr, ::FFI::Pointer, nil]
1366 # object reference to use this method on
1367 # @param bindtodevice [String, #to_s, nil]
1368 # @return [void]
1369 def self.set_bindtodevice(self_p, bindtodevice)
1370 self_p = self_p.__ptr if self_p.respond_to?(:__ptr)
1371 result = ::CZMQ::FFI.zsock_set_bindtodevice(self_p, bindtodevice)
1372 result
1373 end
1374
9161375 # Get socket option `heartbeat_ivl`.
9171376 # Available from libzmq 4.2.0.
9181377 #
187187
188188 # Set default interrupt handler, so Ctrl-C or SIGTERM will set
189189 # zsys_interrupted. Idempotent; safe to call multiple times.
190 # Can be supressed by ZSYS_SIGHANDLER=false
190 # Can be suppressed by ZSYS_SIGHANDLER=false
191191 # *** This is for CZMQ internal use only and may change arbitrarily ***
192192 #
193193 # @return [void]
320320 # @return [void]
321321 def self.version(major, minor, patch)
322322 result = ::CZMQ::FFI.zsys_version(major, minor, patch)
323 result
324 end
325
326 # Format a string using printf formatting, returning a freshly allocated
327 # buffer. If there was insufficient memory, returns NULL. Free the returned
328 # string using zstr_free(). The hinted version allows to optimize by using
329 # a larger starting buffer size (known to/assumed by the developer) and so
330 # avoid reallocations.
331 #
332 # @param hint [Integer, #to_int, #to_i]
333 # @param format [String, #to_s, nil]
334 # @param args [Array<Object>] see https://github.com/ffi/ffi/wiki/examples#using-varargs
335 # @return [::FFI::Pointer]
336 def self.sprintf_hint(hint, format, *args)
337 hint = Integer(hint)
338 result = ::CZMQ::FFI.zsys_sprintf_hint(hint, format, *args)
323339 result
324340 end
325341
502518 result
503519 end
504520
521 # Configure the numeric prefix to each thread created for the internal
522 # context's thread pool. This option is only supported on Linux.
523 # If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
524 # provides the default.
525 # Note that this method is valid only before any socket is created.
526 #
527 # @param prefix [Integer, #to_int, #to_i]
528 # @return [void]
529 def self.set_thread_name_prefix(prefix)
530 prefix = Integer(prefix)
531 result = ::CZMQ::FFI.zsys_set_thread_name_prefix(prefix)
532 result
533 end
534
535 # Return thread name prefix.
536 #
537 # @return [Integer]
538 def self.thread_name_prefix()
539 result = ::CZMQ::FFI.zsys_thread_name_prefix()
540 result
541 end
542
543 # Adds a specific CPU to the affinity list of the ZMQ context thread pool.
544 # This option is only supported on Linux.
545 # Note that this method is valid only before any socket is created.
546 #
547 # @param cpu [Integer, #to_int, #to_i]
548 # @return [void]
549 def self.thread_affinity_cpu_add(cpu)
550 cpu = Integer(cpu)
551 result = ::CZMQ::FFI.zsys_thread_affinity_cpu_add(cpu)
552 result
553 end
554
555 # Removes a specific CPU to the affinity list of the ZMQ context thread pool.
556 # This option is only supported on Linux.
557 # Note that this method is valid only before any socket is created.
558 #
559 # @param cpu [Integer, #to_int, #to_i]
560 # @return [void]
561 def self.thread_affinity_cpu_remove(cpu)
562 cpu = Integer(cpu)
563 result = ::CZMQ::FFI.zsys_thread_affinity_cpu_remove(cpu)
564 result
565 end
566
505567 # Configure the number of sockets that ZeroMQ will allow. The default
506568 # is 1024. The actual limit depends on the system, and you can query it
507569 # by using zsys_socket_limit (). A value of zero means "maximum".
755817 # @return [Integer]
756818 def self.auto_use_fd()
757819 result = ::CZMQ::FFI.zsys_auto_use_fd()
820 result
821 end
822
823 # Print formatted string. Format is specified by variable names
824 # in Python-like format style
825 #
826 # "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
827 # become
828 # "key=value"
829 #
830 # Returns freshly allocated string or NULL in a case of error.
831 # Not enough memory, invalid format specifier, name not in args
832 #
833 # @param format [String, #to_s, nil]
834 # @param args [Zhash, #__ptr]
835 # @return [::FFI::AutoPointer]
836 def self.zprintf(format, args)
837 args = args.__ptr if args
838 result = ::CZMQ::FFI.zsys_zprintf(format, args)
839 result = ::FFI::AutoPointer.new(result, LibC.method(:free))
840 result
841 end
842
843 # Return error string for given format/args combination.
844 #
845 # @param format [String, #to_s, nil]
846 # @param args [Zhash, #__ptr]
847 # @return [::FFI::AutoPointer]
848 def self.zprintf_error(format, args)
849 args = args.__ptr if args
850 result = ::CZMQ::FFI.zsys_zprintf_error(format, args)
851 result = ::FFI::AutoPointer.new(result, LibC.method(:free))
852 result
853 end
854
855 # Print formatted string. Format is specified by variable names
856 # in Python-like format style
857 #
858 # "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
859 # become
860 # "key=value"
861 #
862 # Returns freshly allocated string or NULL in a case of error.
863 # Not enough memory, invalid format specifier, name not in args
864 #
865 # @param format [String, #to_s, nil]
866 # @param args [Zconfig, #__ptr]
867 # @return [::FFI::AutoPointer]
868 def self.zplprintf(format, args)
869 args = args.__ptr if args
870 result = ::CZMQ::FFI.zsys_zplprintf(format, args)
871 result = ::FFI::AutoPointer.new(result, LibC.method(:free))
872 result
873 end
874
875 # Return error string for given format/args combination.
876 #
877 # @param format [String, #to_s, nil]
878 # @param args [Zconfig, #__ptr]
879 # @return [::FFI::AutoPointer]
880 def self.zplprintf_error(format, args)
881 args = args.__ptr if args
882 result = ::CZMQ::FFI.zsys_zplprintf_error(format, args)
883 result = ::FFI::AutoPointer.new(result, LibC.method(:free))
758884 result
759885 end
760886
7373 attach_function :zargs_param_first, [:pointer], :string, **opts
7474 attach_function :zargs_param_next, [:pointer], :string, **opts
7575 attach_function :zargs_param_name, [:pointer], :string, **opts
76 attach_function :zargs_param_lookup, [:pointer, :string], :string, **opts
77 attach_function :zargs_param_lookupx, [:pointer, :string, :varargs], :string, **opts
78 attach_function :zargs_has_help, [:pointer], :bool, **opts
79 attach_function :zargs_param_empty, [:string], :bool, **opts
76 attach_function :zargs_get, [:pointer, :string], :string, **opts
77 attach_function :zargs_getx, [:pointer, :string, :varargs], :string, **opts
78 attach_function :zargs_has, [:pointer, :string], :bool, **opts
79 attach_function :zargs_hasx, [:pointer, :string, :varargs], :bool, **opts
8080 attach_function :zargs_print, [:pointer], :void, **opts
8181 attach_function :zargs_test, [:bool], :void, **opts
8282
139139 require_relative 'ffi/zcertstore'
140140
141141 attach_function :zchunk_new, [:pointer, :size_t], :pointer, **opts
142 attach_function :zchunk_frommem, [:pointer, :size_t, :pointer, :pointer], :pointer, **opts
142143 attach_function :zchunk_destroy, [:pointer], :void, **opts
143144 attach_function :zchunk_resize, [:pointer, :size_t], :void, **opts
144145 attach_function :zchunk_size, [:pointer], :size_t, **opts
158159 attach_function :zchunk_strdup, [:pointer], :pointer, **opts
159160 attach_function :zchunk_streq, [:pointer, :string], :bool, **opts
160161 attach_function :zchunk_pack, [:pointer], :pointer, **opts
162 attach_function :zchunk_packx, [:pointer], :pointer, **opts
161163 attach_function :zchunk_unpack, [:pointer], :pointer, **opts
162164 attach_function :zchunk_digest, [:pointer], :string, **opts
163165 attach_function :zchunk_fprint, [:pointer, :pointer], :void, **opts
180182 attach_function :zconfig_load, [:string], :pointer, **opts
181183 attach_function :zconfig_loadf, [:string, :varargs], :pointer, **opts
182184 attach_function :zconfig_destroy, [:pointer], :void, **opts
185 attach_function :zconfig_dup, [:pointer], :pointer, **opts
183186 attach_function :zconfig_name, [:pointer], :pointer, **opts
184187 attach_function :zconfig_value, [:pointer], :pointer, **opts
185188 attach_function :zconfig_put, [:pointer, :string, :string], :void, **opts
283286 attach_function :zframe_new, [:pointer, :size_t], :pointer, **opts
284287 attach_function :zframe_new_empty, [], :pointer, **opts
285288 attach_function :zframe_from, [:string], :pointer, **opts
289 attach_function :zframe_frommem, [:pointer, :size_t, :pointer, :pointer], :pointer, **opts
286290 attach_function :zframe_recv, [:pointer], :pointer, **opts
287291 attach_function :zframe_destroy, [:pointer], :void, **opts
288292 attach_function :zframe_send, [:pointer, :pointer, :int], :int, **opts
409413 require_relative 'ffi/zlist'
410414
411415 attach_function :zlistx_new, [], :pointer, **opts
416 attach_function :zlistx_unpack, [:pointer], :pointer, **opts
412417 attach_function :zlistx_destroy, [:pointer], :void, **opts
413418 attach_function :zlistx_add_start, [:pointer, :pointer], :pointer, **opts
414419 attach_function :zlistx_add_end, [:pointer, :pointer], :pointer, **opts
436441 attach_function :zlistx_set_destructor, [:pointer, :pointer], :void, **opts
437442 attach_function :zlistx_set_duplicator, [:pointer, :pointer], :void, **opts
438443 attach_function :zlistx_set_comparator, [:pointer, :pointer], :void, **opts
444 attach_function :zlistx_pack, [:pointer], :pointer, **opts
439445 attach_function :zlistx_test, [:bool], :void, **opts
440446
441447 require_relative 'ffi/zlistx'
529535 attach_function :zproc_returncode, [:pointer], :int, **opts
530536 attach_function :zproc_pid, [:pointer], :int, **opts
531537 attach_function :zproc_running, [:pointer], :bool, **opts
532 attach_function :zproc_wait, [:pointer, :bool], :int, **opts
538 attach_function :zproc_wait, [:pointer, :int], :int, **opts
539 attach_function :zproc_shutdown, [:pointer, :int], :void, **opts
533540 attach_function :zproc_actor, [:pointer], :pointer, **opts
534541 attach_function :zproc_kill, [:pointer, :int], :void, **opts
535542 attach_function :zproc_set_verbose, [:pointer, :bool], :void, **opts
580587 attach_function :zsock_leave, [:pointer, :string], :int, **opts
581588 attach_function :zsock_is, [:pointer], :bool, **opts
582589 attach_function :zsock_resolve, [:pointer], :pointer, **opts
590 attach_function :zsock_has_in, [:pointer], :bool, **opts
591 attach_function :zsock_router_notify, [:pointer], :int, **opts
592 attach_function :zsock_set_router_notify, [:pointer, :int], :void, **opts
593 attach_function :zsock_multicast_loop, [:pointer], :int, **opts
594 attach_function :zsock_set_multicast_loop, [:pointer, :int], :void, **opts
595 attach_function :zsock_metadata, [:pointer], :pointer, **opts
596 attach_function :zsock_set_metadata, [:pointer, :string], :void, **opts
597 attach_function :zsock_loopback_fastpath, [:pointer], :int, **opts
598 attach_function :zsock_set_loopback_fastpath, [:pointer, :int], :void, **opts
599 attach_function :zsock_zap_enforce_domain, [:pointer], :int, **opts
600 attach_function :zsock_set_zap_enforce_domain, [:pointer, :int], :void, **opts
601 attach_function :zsock_gssapi_principal_nametype, [:pointer], :int, **opts
602 attach_function :zsock_set_gssapi_principal_nametype, [:pointer, :int], :void, **opts
603 attach_function :zsock_gssapi_service_principal_nametype, [:pointer], :int, **opts
604 attach_function :zsock_set_gssapi_service_principal_nametype, [:pointer, :int], :void, **opts
605 attach_function :zsock_bindtodevice, [:pointer], :pointer, **opts
606 attach_function :zsock_set_bindtodevice, [:pointer, :string], :void, **opts
583607 attach_function :zsock_heartbeat_ivl, [:pointer], :int, **opts
584608 attach_function :zsock_set_heartbeat_ivl, [:pointer, :int], :void, **opts
585609 attach_function :zsock_heartbeat_ttl, [:pointer], :int, **opts
760784 attach_function :zsys_file_mode_private, [], :void, **opts
761785 attach_function :zsys_file_mode_default, [], :void, **opts
762786 attach_function :zsys_version, [:pointer, :pointer, :pointer], :void, **opts
787 attach_function :zsys_sprintf_hint, [:int, :string, :varargs], :pointer, **opts
763788 attach_function :zsys_sprintf, [:string, :varargs], :pointer, **opts
764789 attach_function :zsys_vprintf, [:string, :pointer], :pointer, **opts
765790 attach_function :zsys_udp_new, [:bool], (::FFI::Platform.unix? ? :int : :uint64), **opts
774799 attach_function :zsys_set_io_threads, [:size_t], :void, **opts
775800 attach_function :zsys_set_thread_sched_policy, [:int], :void, **opts
776801 attach_function :zsys_set_thread_priority, [:int], :void, **opts
802 attach_function :zsys_set_thread_name_prefix, [:int], :void, **opts
803 attach_function :zsys_thread_name_prefix, [], :int, **opts
804 attach_function :zsys_thread_affinity_cpu_add, [:int], :void, **opts
805 attach_function :zsys_thread_affinity_cpu_remove, [:int], :void, **opts
777806 attach_function :zsys_set_max_sockets, [:size_t], :void, **opts
778807 attach_function :zsys_socket_limit, [], :size_t, **opts
779808 attach_function :zsys_set_max_msgsz, [:int], :void, **opts
797826 attach_function :zsys_ipv6_mcast_address, [], :string, **opts
798827 attach_function :zsys_set_auto_use_fd, [:int], :void, **opts
799828 attach_function :zsys_auto_use_fd, [], :int, **opts
829 attach_function :zsys_zprintf, [:string, :pointer], :pointer, **opts
830 attach_function :zsys_zprintf_error, [:string, :pointer], :pointer, **opts
831 attach_function :zsys_zplprintf, [:string, :pointer], :pointer, **opts
832 attach_function :zsys_zplprintf_error, [:string, :pointer], :pointer, **opts
800833 attach_function :zsys_set_logident, [:string], :void, **opts
801834 attach_function :zsys_set_logstream, [:pointer], :void, **opts
802835 attach_function :zsys_set_logsender, [:string], :void, **opts
852885 attach_function :zuuid_test, [:bool], :void, **opts
853886
854887 require_relative 'ffi/zuuid'
888
889 attach_function :zhttp_client_new, [:bool], :pointer, **opts
890 attach_function :zhttp_client_destroy, [:pointer], :void, **opts
891 attach_function :zhttp_client_test, [:bool], :void, **opts
892
893 require_relative 'ffi/zhttp_client'
894
895 attach_function :zhttp_server_new, [:pointer], :pointer, **opts
896 attach_function :zhttp_server_destroy, [:pointer], :void, **opts
897 attach_function :zhttp_server_port, [:pointer], :int, **opts
898 attach_function :zhttp_server_test, [:bool], :void, **opts
899
900 require_relative 'ffi/zhttp_server'
901
902 attach_function :zhttp_server_options_new, [], :pointer, **opts
903 attach_function :zhttp_server_options_from_config, [:pointer], :pointer, **opts
904 attach_function :zhttp_server_options_destroy, [:pointer], :void, **opts
905 attach_function :zhttp_server_options_port, [:pointer], :int, **opts
906 attach_function :zhttp_server_options_set_port, [:pointer, :int], :void, **opts
907 attach_function :zhttp_server_options_backend_address, [:pointer], :string, **opts
908 attach_function :zhttp_server_options_set_backend_address, [:pointer, :string], :void, **opts
909 attach_function :zhttp_server_options_test, [:bool], :void, **opts
910
911 require_relative 'ffi/zhttp_server_options'
912
913 attach_function :zhttp_request_new, [], :pointer, **opts
914 attach_function :zhttp_request_destroy, [:pointer], :void, **opts
915 attach_function :zhttp_request_recv, [:pointer, :pointer], :pointer, **opts
916 attach_function :zhttp_request_send, [:pointer, :pointer, :int, :pointer, :pointer], :int, **opts
917 attach_function :zhttp_request_method, [:pointer], :string, **opts
918 attach_function :zhttp_request_set_method, [:pointer, :string], :void, **opts
919 attach_function :zhttp_request_url, [:pointer], :string, **opts
920 attach_function :zhttp_request_set_url, [:pointer, :string], :void, **opts
921 attach_function :zhttp_request_content_type, [:pointer], :string, **opts
922 attach_function :zhttp_request_set_content_type, [:pointer, :string], :void, **opts
923 attach_function :zhttp_request_content_length, [:pointer], :size_t, **opts
924 attach_function :zhttp_request_headers, [:pointer], :pointer, **opts
925 attach_function :zhttp_request_content, [:pointer], :string, **opts
926 attach_function :zhttp_request_get_content, [:pointer], :pointer, **opts
927 attach_function :zhttp_request_set_content, [:pointer, :pointer], :void, **opts
928 attach_function :zhttp_request_set_content_const, [:pointer, :string], :void, **opts
929 attach_function :zhttp_request_reset_content, [:pointer], :void, **opts
930 attach_function :zhttp_request_match, [:pointer, :string, :string, :varargs], :bool, **opts
931 attach_function :zhttp_request_test, [:bool], :void, **opts
932
933 require_relative 'ffi/zhttp_request'
934
935 attach_function :zhttp_response_new, [], :pointer, **opts
936 attach_function :zhttp_response_destroy, [:pointer], :void, **opts
937 attach_function :zhttp_response_send, [:pointer, :pointer, :pointer], :int, **opts
938 attach_function :zhttp_response_recv, [:pointer, :pointer, :pointer, :pointer], :int, **opts
939 attach_function :zhttp_response_content_type, [:pointer], :string, **opts
940 attach_function :zhttp_response_set_content_type, [:pointer, :string], :void, **opts
941 attach_function :zhttp_response_status_code, [:pointer], :uint32, **opts
942 attach_function :zhttp_response_set_status_code, [:pointer, :uint32], :void, **opts
943 attach_function :zhttp_response_headers, [:pointer], :pointer, **opts
944 attach_function :zhttp_response_content_length, [:pointer], :size_t, **opts
945 attach_function :zhttp_response_content, [:pointer], :string, **opts
946 attach_function :zhttp_response_get_content, [:pointer], :pointer, **opts
947 attach_function :zhttp_response_set_content, [:pointer, :pointer], :void, **opts
948 attach_function :zhttp_response_set_content_const, [:pointer, :string], :void, **opts
949 attach_function :zhttp_response_reset_content, [:pointer], :void, **opts
950 attach_function :zhttp_response_test, [:bool], :void, **opts
951
952 require_relative 'ffi/zhttp_response'
855953 end
856954 end
857955 end
0 @PACKAGE_INIT@
1
2 include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
3 check_required_components("@PROJECT_NAME@")
0 # additional target to perform clang-format run, requires clang-format
1
2 # get all project files
3 file(GLOB_RECURSE ALL_SOURCE_FILES
4 RELATIVE ${CMAKE_CURRENT_BINARY_DIR}
5 ${CMAKE_SOURCE_DIR}/src/*.c ${CMAKE_SOURCE_DIR}/src/*.cc ${CMAKE_SOURCE_DIR}/src/*.cpp
6 ${CMAKE_SOURCE_DIR}/src/*.h ${CMAKE_SOURCE_DIR}/src/*.hpp
7 ${CMAKE_SOURCE_DIR}/tests/*.c ${CMAKE_SOURCE_DIR}/tests/*.cc ${CMAKE_SOURCE_DIR}/tests/*.cpp
8 ${CMAKE_SOURCE_DIR}/tests/*.h ${CMAKE_SOURCE_DIR}/tests/*.hpp
9 ${CMAKE_SOURCE_DIR}/perf/*.c ${CMAKE_SOURCE_DIR}/perf/*.cc ${CMAKE_SOURCE_DIR}/perf/*.cpp
10 ${CMAKE_SOURCE_DIR}/perf/*.h ${CMAKE_SOURCE_DIR}/perf/*.hpp
11 ${CMAKE_SOURCE_DIR}/tools/*.c ${CMAKE_SOURCE_DIR}/tools/*.cc ${CMAKE_SOURCE_DIR}/tools/*.cpp
12 ${CMAKE_SOURCE_DIR}/tools/*.h ${CMAKE_SOURCE_DIR}/tools/*.hpp
13 ${CMAKE_SOURCE_DIR}/include/*.h ${CMAKE_SOURCE_DIR}/include/*.hpp
14 )
15
16 if("${CLANG_FORMAT}" STREQUAL "")
17 set(CLANG_FORMAT "clang-format")
18 endif()
19
20 add_custom_target(
21 clang-format
22 COMMAND ${CLANG_FORMAT} -style=file -i ${ALL_SOURCE_FILES}
23 )
24
25 function(JOIN VALUES GLUE OUTPUT)
26 string (REPLACE ";" "${GLUE}" _TMP_STR "${VALUES}")
27 set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
28 endfunction()
29
30 configure_file(builds/cmake/clang-format-check.sh.in clang-format-check.sh @ONLY)
31
32 add_custom_target(
33 clang-format-check
34 COMMAND chmod +x clang-format-check.sh
35 COMMAND ./clang-format-check.sh
36 COMMENT "Checking correct formatting according to .clang-format file using ${CLANG_FORMAT}"
37 )
38
39 add_custom_target(
40 clang-format-check-CI
41 COMMAND chmod +x clang-format-check.sh
42 COMMAND ./clang-format-check.sh --CI
43 COMMENT "Checking correct formatting according to .clang-format file using ${CLANG_FORMAT}"
44 )
45
46 add_custom_target(
47 clang-format-diff
48 COMMAND ${CLANG_FORMAT} -style=file -i ${ALL_SOURCE_FILES}
49 COMMAND git diff ${ALL_SOURCE_FILES}
50 COMMENT "Formatting with clang-format (using ${CLANG_FORMAT}) and showing differences with latest commit"
51 )
0 #!/bin/sh
1
2 # Use clang-format tool to verify this codebase conforms to our style standards
3
4 FAILED=0
5 IFS=";"
6 FILES="@ALL_SOURCE_FILES@"
7 IDS=$(echo -en "\n\b")
8 [ -n "$MAKE" ] || MAKE=make
9 for FILE in $FILES
10 do
11 @CLANG_FORMAT@ -style=file -output-replacements-xml "$FILE" | grep "<replacement " >/dev/null && \
12 {
13 echo "$FILE is not correctly formatted" >&2
14 FAILED=1
15 }
16 done
17 if [ "$FAILED" -eq "1" ] ; then
18 if [ "$1" = "--CI" ] ; then
19 echo "Style mismatches were found by clang-format; detailing below:" >&2
20 ${MAKE} clang-format-diff
21 if test x"${CI_REQUIRE_GOOD_CLANG_FORMAT}" = xtrue ; then
22 echo "FAILED : Style checks have failed and CI_REQUIRE_GOOD_CLANG_FORMAT==true" >&2
23 exit 1
24 fi
25 echo "WARNING : Style checks have failed, but the result is not-fatal because CI_REQUIRE_GOOD_CLANG_FORMAT!=true" >&2
26 exit 0
27 fi
28 exit 1
29 fi
00 #! /bin/sh
11 # Guess values for system-dependent variables and create Makefiles.
2 # Generated by GNU Autoconf 2.69 for czmq 4.1.1.
2 # Generated by GNU Autoconf 2.69 for czmq 4.2.0.
33 #
44 # Report bugs to <zeromq-dev@lists.zeromq.org>.
55 #
589589 # Identity of this package.
590590 PACKAGE_NAME='czmq'
591591 PACKAGE_TARNAME='czmq'
592 PACKAGE_VERSION='4.1.1'
593 PACKAGE_STRING='czmq 4.1.1'
592 PACKAGE_VERSION='4.2.0'
593 PACKAGE_STRING='czmq 4.2.0'
594594 PACKAGE_BUGREPORT='zeromq-dev@lists.zeromq.org'
595595 PACKAGE_URL=''
596596
670670 ENABLE_SHARED_TRUE
671671 czmq_have_xmlto
672672 czmq_have_asciidoc
673 pkg_config_names_private
673674 pkg_config_libs_private
674 pkgconfig_name_liblz4
675 libmicrohttpd_LIBS
676 libmicrohttpd_CFLAGS
677 libcurl_LIBS
678 libcurl_CFLAGS
675679 lz4_LIBS
676680 lz4_CFLAGS
677 pkgconfig_name_libsystemd
678681 systemd_LIBS
679682 systemd_CFLAGS
680 pkgconfig_name_uuid
681683 uuid_LIBS
682684 uuid_CFLAGS
683 pkgconfig_name_libzmq
684685 libzmq_LIBS
685686 libzmq_CFLAGS
686687 pkgconfigdir
688689 WITH_CLANG_FORMAT_TRUE
689690 WITH_CLANG_FORMAT
690691 CLANG_FORMAT
692 ENABLE_BINDINGS_PYTHON_FALSE
693 ENABLE_BINDINGS_PYTHON_TRUE
691694 ENABLE_ASAN_FALSE
692695 ENABLE_ASAN_TRUE
693696 WITH_GCOV_FALSE
828831 enable_libtool_lock
829832 with_gcov
830833 enable_address_sanitizer
834 enable_bindings_python
831835 with_pkgconfigdir
832836 with_libzmq
833837 with_uuid
834838 with_libsystemd
835839 with_liblz4
840 with_libcurl
841 with_libmicrohttpd
836842 with_docs
837843 enable_dist_cmakefiles
838844 enable_zmakecert
861867 systemd_CFLAGS
862868 systemd_LIBS
863869 lz4_CFLAGS
864 lz4_LIBS'
870 lz4_LIBS
871 libcurl_CFLAGS
872 libcurl_LIBS
873 libmicrohttpd_CFLAGS
874 libmicrohttpd_LIBS'
865875
866876
867877 # Initialize some variables set by options.
14021412 # Omit some internal or obsolete options to make the list less imposing.
14031413 # This message is too long to be a string in the A/UX 3.1 sh.
14041414 cat <<_ACEOF
1405 \`configure' configures czmq 4.1.1 to adapt to many kinds of systems.
1415 \`configure' configures czmq 4.2.0 to adapt to many kinds of systems.
14061416
14071417 Usage: $0 [OPTION]... [VAR=VALUE]...
14081418
14721482
14731483 if test -n "$ac_init_help"; then
14741484 case $ac_init_help in
1475 short | recursive ) echo "Configuration of czmq 4.1.1:";;
1485 short | recursive ) echo "Configuration of czmq 4.2.0:";;
14761486 esac
14771487 cat <<\_ACEOF
14781488
14931503 --disable-libtool-lock avoid locking (might break parallel builds)
14941504 --enable-address-sanitizer=yes/no
14951505 Build with GCC Address Sanitizer instrumentation
1506 --enable-bindings-python=yes/no
1507 Install Python Bindings [default=no]
14961508 --enable-dist_cmakefiles
14971509 Distribute CMakeLists.txt and related files [default
14981510 depends: on if present and not cross compiling]
15031515 --enable-drafts Build and install draft classes and methods
15041516 [default=yes]
15051517 --enable-Werror Add -Wall -Werror to GCC/GXX arguments [default=no;
1506 default=auto if nothing specified]
1518 default=auto if nothing specified as the specific
1519 argument value]
15071520
15081521 Optional Packages:
15091522 --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
15361549
15371550
15381551 --with-liblz4 yes or no. Optionally specify liblz4 prefix
1552 (directory where its include/ and lib/ are located),
1553 but that is only used if pkgconfig metadata is not
1554 found first
1555
1556
1557 --with-libcurl yes or no. Optionally specify libcurl prefix
1558 (directory where its include/ and lib/ are located),
1559 but that is only used if pkgconfig metadata is not
1560 found first
1561
1562
1563 --with-libmicrohttpd yes or no. Optionally specify libmicrohttpd prefix
15391564 (directory where its include/ and lib/ are located),
15401565 but that is only used if pkgconfig metadata is not
15411566 found first
15671592 linker flags for systemd, overriding pkg-config
15681593 lz4_CFLAGS C compiler flags for lz4, overriding pkg-config
15691594 lz4_LIBS linker flags for lz4, overriding pkg-config
1595 libcurl_CFLAGS
1596 C compiler flags for libcurl, overriding pkg-config
1597 libcurl_LIBS
1598 linker flags for libcurl, overriding pkg-config
1599 libmicrohttpd_CFLAGS
1600 C compiler flags for libmicrohttpd, overriding pkg-config
1601 libmicrohttpd_LIBS
1602 linker flags for libmicrohttpd, overriding pkg-config
15701603
15711604 Use these variables to override the choices made by `configure' or to help
15721605 it to find libraries and programs with nonstandard names/locations.
16341667 test -n "$ac_init_help" && exit $ac_status
16351668 if $ac_init_version; then
16361669 cat <<\_ACEOF
1637 czmq configure 4.1.1
1670 czmq configure 4.2.0
16381671 generated by GNU Autoconf 2.69
16391672
16401673 Copyright (C) 2012 Free Software Foundation, Inc.
21112144 This file contains any messages produced by compilers while
21122145 running configure, to aid debugging if configure makes a mistake.
21132146
2114 It was created by czmq $as_me 4.1.1, which was
2147 It was created by czmq $as_me 4.2.0, which was
21152148 generated by GNU Autoconf 2.69. Invocation command line was
21162149
21172150 $ $0 $@
29783011
29793012 # Define the identity of the package.
29803013 PACKAGE='czmq'
2981 VERSION='4.1.1'
3014 VERSION='4.2.0'
29823015
29833016
29843017 cat >>confdefs.h <<_ACEOF
32513284 #
32523285 # Libtool -version-info (ABI version)
32533286 #
3254 # Currently 5:1:1 ("stable"). Don't change this unless you
3287 # Currently 6:0:2 ("stable"). Don't change this unless you
32553288 # know exactly what you're doing and have read and understand
32563289 # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
32573290 #
32583291 # libczmq -version-info
3259 LTVER="5:1:1"
3292 LTVER="6:0:2"
32603293
32613294
32623295 # building in a subdirectory?
1289912932 fi
1290012933
1290112934
12935 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether SOCK_CLOEXEC is supported" >&5
12936 $as_echo_n "checking whether SOCK_CLOEXEC is supported... " >&6; }
12937 if ${czmq_cv_sock_cloexec+:} false; then :
12938 $as_echo_n "(cached) " >&6
12939 else
12940 if test "$cross_compiling" = yes; then :
12941 czmq_cv_sock_cloexec="not during cross-compile"
12942
12943 else
12944 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
12945 /* end confdefs.h. */
12946 /* SOCK_CLOEXEC test */
12947 #include <sys/types.h>
12948 #include <sys/socket.h>
12949
12950 int main (int argc, char *argv [])
12951 {
12952 int s = socket (PF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
12953 return (s == -1);
12954 }
12955
12956 _ACEOF
12957 if ac_fn_c_try_run "$LINENO"; then :
12958 czmq_cv_sock_cloexec="yes"
12959 else
12960 czmq_cv_sock_cloexec="no"
12961 fi
12962 rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
12963 conftest.$ac_objext conftest.beam conftest.$ac_ext
12964 fi
12965
12966
12967 fi
12968 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $czmq_cv_sock_cloexec" >&5
12969 $as_echo "$czmq_cv_sock_cloexec" >&6; }
12970 if test "x$czmq_cv_sock_cloexec" = "xyes"; then :
12971
12972 $as_echo "#define CZMQ_HAVE_SOCK_CLOEXEC 1" >>confdefs.h
12973
12974
12975 fi
12976
1290212977
1290312978 # See if cppcheck is in PATH; this variable unblocks the "cppcheck" recipe
1290412979 # (note that "make cppcheck.xml" can be used - and perhaps fail - regardless)
1301813093 else
1301913094 ENABLE_ASAN_TRUE='#'
1302013095 ENABLE_ASAN_FALSE=
13096 fi
13097
13098 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
13099 $as_echo "no" >&6; }
13100 fi
13101
13102 # Install Python Bindings
13103 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to install Python bindings" >&5
13104 $as_echo_n "checking whether to install Python bindings... " >&6; }
13105
13106 # Check whether --enable-bindings-python was given.
13107 if test "${enable_bindings_python+set}" = set; then :
13108 enableval=$enable_bindings_python; ZPROJECT_BINDINGS_PYTHON=$enableval
13109 else
13110 ZPROJECT_BINDINGS_PYTHON=no
13111 fi
13112
13113
13114 if test "x$ZPROJECT_BINDINGS_PYTHON" == "xyes"; then
13115 if true; then
13116 ENABLE_BINDINGS_PYTHON_TRUE=
13117 ENABLE_BINDINGS_PYTHON_FALSE='#'
13118 else
13119 ENABLE_BINDINGS_PYTHON_TRUE='#'
13120 ENABLE_BINDINGS_PYTHON_FALSE=
13121 fi
13122
13123 { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
13124 $as_echo "yes" >&6; }
13125 else
13126 if false; then
13127 ENABLE_BINDINGS_PYTHON_TRUE=
13128 ENABLE_BINDINGS_PYTHON_FALSE='#'
13129 else
13130 ENABLE_BINDINGS_PYTHON_TRUE='#'
13131 ENABLE_BINDINGS_PYTHON_FALSE=
1302113132 fi
1302213133
1302313134 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
1318813299
1318913300 # Will be used to add flags to pkg-config useful when apps want to statically link
1319013301 PKGCFG_LIBS_PRIVATE=""
13302 PKGCFG_NAMES_PRIVATE=""
1319113303
1319213304 # Archive user supplied flags
1319313305 PREVIOUS_CFLAGS="${CFLAGS}"
1323113343 PRE_SEARCH_LIBS="${LIBS}"
1323213344
1323313345 found_pkgconfig=""
13234 found_linkname=""
1323513346
1323613347 pkg_failed=no
1323713348 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libzmq" >&5
1335713468
1335813469 was_libzmq_check_lib_detected=yes
1335913470 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -lzmq"
13360 found_linkname="zmq"
1336113471
1336213472 else
1336313473 as_fn_error $? "cannot link with -lzmq, install libzmq" "$LINENO" 5
1343313543
1343413544 was_libzmq_check_lib_detected=yes
1343513545 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -lzmq"
13436 found_linkname="zmq"
1343713546
1343813547 else
1343913548 as_fn_error $? "cannot link with -lzmq, install libzmq" "$LINENO" 5
1344613555 { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
1344713556 $as_echo "yes" >&6; }
1344813557
13449 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE $libzmq_LIBS"
1345013558 was_libzmq_check_lib_detected=pkgcfg
1345113559 found_pkgconfig="libzmq"
1345213560
1345513563 case "x${was_libzmq_check_lib_detected}" in #(
1345613564 xpkgcfg) :
1345713565
13458 pkgconfig_name_libzmq=${found_pkgconfig}
13459
13566 PKGCFG_NAMES_PRIVATE="$PKGCFG_NAMES_PRIVATE ${found_pkgconfig}"
1346013567 CFLAGS="${libzmq_CFLAGS} ${CFLAGS}"
1346113568 LIBS="${libzmq_LIBS} ${LIBS}"
1346213569 ;; #(
1346313570 xyes) :
1346413571
13465 pkgconfig_name_libzmq=${found_linkname}
13466
1346713572 CFLAGS="${libzmq_synthetic_cflags} ${CFLAGS}"
1346813573 LDFLAGS="${libzmq_synthetic_libs} ${LDFLAGS}"
1346913574 LIBS="${libzmq_synthetic_libs} ${LIBS}"
1347413579
1347513580 ;; #(
1347613581 xno) :
13477
13478 pkgconfig_name_libzmq=libzmq
1347913582
1348013583 as_fn_error $? "Cannot find pkg-config metadata for libzmq 0.0.0 or higher" "$LINENO" 5
1348113584 ;; #(
1351913622 PRE_SEARCH_LIBS="${LIBS}"
1352013623
1352113624 found_pkgconfig=""
13522 found_linkname=""
1352313625
1352413626 pkg_failed=no
1352513627 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for uuid" >&5
1364713749
1364813750 was_uuid_check_lib_detected=yes
1364913751 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -luuid"
13650 found_linkname="uuid"
1365113752
1365213753 $as_echo "#define HAVE_UUID 1" >>confdefs.h
1365313754
1372613827
1372713828 was_uuid_check_lib_detected=yes
1372813829 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -luuid"
13729 found_linkname="uuid"
1373013830
1373113831 $as_echo "#define HAVE_UUID 1" >>confdefs.h
1373213832
1374313843
1374413844 $as_echo "#define HAVE_UUID 1" >>confdefs.h
1374513845
13746 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE $uuid_LIBS"
1374713846 was_uuid_check_lib_detected=pkgcfg
1374813847 found_pkgconfig="uuid"
1374913848
1375213851 case "x${was_uuid_check_lib_detected}" in #(
1375313852 xpkgcfg) :
1375413853
13755 pkgconfig_name_uuid=${found_pkgconfig}
13756
13854 PKGCFG_NAMES_PRIVATE="$PKGCFG_NAMES_PRIVATE ${found_pkgconfig}"
1375713855 CFLAGS="${uuid_CFLAGS} ${CFLAGS}"
1375813856 LIBS="${uuid_LIBS} ${LIBS}"
1375913857 ;; #(
1376013858 xyes) :
1376113859
13762 pkgconfig_name_uuid=${found_linkname}
13763
1376413860 CFLAGS="${uuid_synthetic_cflags} ${CFLAGS}"
1376513861 LDFLAGS="${uuid_synthetic_libs} ${LDFLAGS}"
1376613862 LIBS="${uuid_synthetic_libs} ${LIBS}"
1377113867
1377213868 ;; #(
1377313869 xno) :
13774
13775 pkgconfig_name_uuid=uuid
1377613870
1377713871 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Cannot find pkg-config metadata for uuid 0.0.0 or higher" >&5
1377813872 $as_echo "$as_me: WARNING: Cannot find pkg-config metadata for uuid 0.0.0 or higher" >&2;}
1381713911 PRE_SEARCH_LIBS="${LIBS}"
1381813912
1381913913 found_pkgconfig=""
13820 found_linkname=""
1382113914
1382213915 pkg_failed=no
1382313916 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for systemd" >&5
1394514038
1394614039 was_systemd_check_lib_detected=yes
1394714040 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -lsystemd"
13948 found_linkname="systemd"
1394914041
1395014042 $as_echo "#define HAVE_LIBSYSTEMD 1" >>confdefs.h
1395114043
1402414116
1402514117 was_systemd_check_lib_detected=yes
1402614118 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -lsystemd"
14027 found_linkname="systemd"
1402814119
1402914120 $as_echo "#define HAVE_LIBSYSTEMD 1" >>confdefs.h
1403014121
1404114132
1404214133 $as_echo "#define HAVE_LIBSYSTEMD 1" >>confdefs.h
1404314134
14044 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE $systemd_LIBS"
1404514135 was_systemd_check_lib_detected=pkgcfg
1404614136 found_pkgconfig="libsystemd"
1404714137
1405014140 case "x${was_systemd_check_lib_detected}" in #(
1405114141 xpkgcfg) :
1405214142
14053 pkgconfig_name_libsystemd=${found_pkgconfig}
14054
14143 PKGCFG_NAMES_PRIVATE="$PKGCFG_NAMES_PRIVATE ${found_pkgconfig} >= 200.0.0"
1405514144 CFLAGS="${systemd_CFLAGS} ${CFLAGS}"
1405614145 LIBS="${systemd_LIBS} ${LIBS}"
1405714146 ;; #(
1405814147 xyes) :
1405914148
14060 pkgconfig_name_libsystemd=${found_linkname}
14061
1406214149 CFLAGS="${systemd_synthetic_cflags} ${CFLAGS}"
1406314150 LDFLAGS="${systemd_synthetic_libs} ${LDFLAGS}"
1406414151 LIBS="${systemd_synthetic_libs} ${LIBS}"
1406914156
1407014157 ;; #(
1407114158 xno) :
14072
14073 pkgconfig_name_libsystemd=libsystemd
1407414159
1407514160 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Cannot find pkg-config metadata for libsystemd 200.0.0 or higher" >&5
1407614161 $as_echo "$as_me: WARNING: Cannot find pkg-config metadata for libsystemd 200.0.0 or higher" >&2;}
1411514200 PRE_SEARCH_LIBS="${LIBS}"
1411614201
1411714202 found_pkgconfig=""
14118 found_linkname=""
1411914203
1412014204 pkg_failed=no
1412114205 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for lz4" >&5
1424314327
1424414328 was_lz4_check_lib_detected=yes
1424514329 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -llz4"
14246 found_linkname="lz4"
1424714330
1424814331 $as_echo "#define HAVE_LIBLZ4 1" >>confdefs.h
1424914332
1432214405
1432314406 was_lz4_check_lib_detected=yes
1432414407 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -llz4"
14325 found_linkname="lz4"
1432614408
1432714409 $as_echo "#define HAVE_LIBLZ4 1" >>confdefs.h
1432814410
1433914421
1434014422 $as_echo "#define HAVE_LIBLZ4 1" >>confdefs.h
1434114423
14342 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE $lz4_LIBS"
1434314424 was_lz4_check_lib_detected=pkgcfg
1434414425 found_pkgconfig="liblz4"
1434514426
1434814429 case "x${was_lz4_check_lib_detected}" in #(
1434914430 xpkgcfg) :
1435014431
14351 pkgconfig_name_liblz4=${found_pkgconfig}
14352
14432 PKGCFG_NAMES_PRIVATE="$PKGCFG_NAMES_PRIVATE ${found_pkgconfig}"
1435314433 CFLAGS="${lz4_CFLAGS} ${CFLAGS}"
1435414434 LIBS="${lz4_LIBS} ${LIBS}"
1435514435 ;; #(
1435614436 xyes) :
1435714437
14358 pkgconfig_name_liblz4=${found_linkname}
14359
1436014438 CFLAGS="${lz4_synthetic_cflags} ${CFLAGS}"
1436114439 LDFLAGS="${lz4_synthetic_libs} ${LDFLAGS}"
1436214440 LIBS="${lz4_synthetic_libs} ${LIBS}"
1436714445
1436814446 ;; #(
1436914447 xno) :
14370
14371 pkgconfig_name_liblz4=liblz4
1437214448
1437314449 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Cannot find pkg-config metadata for liblz4 0.0.0 or higher" >&5
1437414450 $as_echo "$as_me: WARNING: Cannot find pkg-config metadata for liblz4 0.0.0 or higher" >&2;}
1438014456 fi
1438114457
1438214458
14459 was_libcurl_check_lib_detected=no
14460
14461 search_libcurl="no"
14462
14463
14464 # Check whether --with-libcurl was given.
14465 if test "${with_libcurl+set}" = set; then :
14466 withval=$with_libcurl;
14467 search_libcurl="yes"
14468
14469 else
14470
14471 search_libcurl="yes"
14472
14473 fi
14474
14475 case x"${with_libcurl}" in #(
14476 xyes) :
14477 search_libcurl="yes" ;; #(
14478 xno) :
14479 search_libcurl="no" ;; #(
14480 *) :
14481 ;;
14482 esac
14483
14484
14485 if test x"${search_libcurl}" = xyes; then :
14486
14487 # Archive previously detected and supplied flags
14488 PRE_SEARCH_CFLAGS="${CFLAGS}"
14489 PRE_SEARCH_LIBS="${LIBS}"
14490
14491 found_pkgconfig=""
14492
14493 pkg_failed=no
14494 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libcurl" >&5
14495 $as_echo_n "checking for libcurl... " >&6; }
14496
14497 if test -n "$libcurl_CFLAGS"; then
14498 pkg_cv_libcurl_CFLAGS="$libcurl_CFLAGS"
14499 elif test -n "$PKG_CONFIG"; then
14500 if test -n "$PKG_CONFIG" && \
14501 { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libcurl >= 7.28.0\""; } >&5
14502 ($PKG_CONFIG --exists --print-errors "libcurl >= 7.28.0") 2>&5
14503 ac_status=$?
14504 $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
14505 test $ac_status = 0; }; then
14506 pkg_cv_libcurl_CFLAGS=`$PKG_CONFIG --cflags "libcurl >= 7.28.0" 2>/dev/null`
14507 test "x$?" != "x0" && pkg_failed=yes
14508 else
14509 pkg_failed=yes
14510 fi
14511 else
14512 pkg_failed=untried
14513 fi
14514 if test -n "$libcurl_LIBS"; then
14515 pkg_cv_libcurl_LIBS="$libcurl_LIBS"
14516 elif test -n "$PKG_CONFIG"; then
14517 if test -n "$PKG_CONFIG" && \
14518 { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libcurl >= 7.28.0\""; } >&5
14519 ($PKG_CONFIG --exists --print-errors "libcurl >= 7.28.0") 2>&5
14520 ac_status=$?
14521 $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
14522 test $ac_status = 0; }; then
14523 pkg_cv_libcurl_LIBS=`$PKG_CONFIG --libs "libcurl >= 7.28.0" 2>/dev/null`
14524 test "x$?" != "x0" && pkg_failed=yes
14525 else
14526 pkg_failed=yes
14527 fi
14528 else
14529 pkg_failed=untried
14530 fi
14531
14532
14533
14534 if test $pkg_failed = yes; then
14535 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
14536 $as_echo "no" >&6; }
14537
14538 if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
14539 _pkg_short_errors_supported=yes
14540 else
14541 _pkg_short_errors_supported=no
14542 fi
14543 if test $_pkg_short_errors_supported = yes; then
14544 libcurl_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libcurl >= 7.28.0" 2>&1`
14545 else
14546 libcurl_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libcurl >= 7.28.0" 2>&1`
14547 fi
14548 # Put the nasty error message in config.log where it belongs
14549 echo "$libcurl_PKG_ERRORS" >&5
14550
14551
14552 { $as_echo "$as_me:${as_lineno-$LINENO}: Package libcurl not found with needed constraints; falling back to defined compilability tests" >&5
14553 $as_echo "$as_me: Package libcurl not found with needed constraints; falling back to defined compilability tests" >&6;}
14554
14555 libcurl_synthetic_cflags=""
14556 libcurl_synthetic_libs="-lcurl"
14557
14558 if test -n "${with_libcurl}" && test x"${with_libcurl}" != xyes && test x"${with_libcurl}" != xno; then
14559 if test -r "${with_libcurl}/include/curl/curl.h"; then
14560 libcurl_synthetic_cflags="-I${with_libcurl}/include"
14561 libcurl_synthetic_libs="-L${with_libcurl}/lib -lcurl"
14562 else
14563 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Header file ${with_libcurl}/include/curl/curl.h was not found. Please check libcurl prefix" >&5
14564 $as_echo "$as_me: WARNING: Header file ${with_libcurl}/include/curl/curl.h was not found. Please check libcurl prefix" >&2;}
14565 fi
14566 else
14567 ac_fn_c_check_header_mongrel "$LINENO" "curl/curl.h" "ac_cv_header_curl_curl_h" "$ac_includes_default"
14568 if test "x$ac_cv_header_curl_curl_h" = xyes; then :
14569
14570 else
14571 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Header file curl/curl.h was not found in default search paths" >&5
14572 $as_echo "$as_me: WARNING: Header file curl/curl.h was not found in default search paths" >&2;}
14573
14574 fi
14575
14576
14577 fi
14578
14579 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for curl_easy_init in -lcurl" >&5
14580 $as_echo_n "checking for curl_easy_init in -lcurl... " >&6; }
14581 if ${ac_cv_lib_curl_curl_easy_init+:} false; then :
14582 $as_echo_n "(cached) " >&6
14583 else
14584 ac_check_lib_save_LIBS=$LIBS
14585 LIBS="-lcurl $LIBS"
14586 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
14587 /* end confdefs.h. */
14588
14589 /* Override any GCC internal prototype to avoid an error.
14590 Use char because int might match the return type of a GCC
14591 builtin and then its argument prototype would still apply. */
14592 #ifdef __cplusplus
14593 extern "C"
14594 #endif
14595 char curl_easy_init ();
14596 int
14597 main ()
14598 {
14599 return curl_easy_init ();
14600 ;
14601 return 0;
14602 }
14603 _ACEOF
14604 if ac_fn_c_try_link "$LINENO"; then :
14605 ac_cv_lib_curl_curl_easy_init=yes
14606 else
14607 ac_cv_lib_curl_curl_easy_init=no
14608 fi
14609 rm -f core conftest.err conftest.$ac_objext \
14610 conftest$ac_exeext conftest.$ac_ext
14611 LIBS=$ac_check_lib_save_LIBS
14612 fi
14613 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_curl_curl_easy_init" >&5
14614 $as_echo "$ac_cv_lib_curl_curl_easy_init" >&6; }
14615 if test "x$ac_cv_lib_curl_curl_easy_init" = xyes; then :
14616
14617 was_libcurl_check_lib_detected=yes
14618 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -lcurl"
14619
14620 $as_echo "#define HAVE_LIBCURL 1" >>confdefs.h
14621
14622
14623 fi
14624
14625
14626 elif test $pkg_failed = untried; then
14627 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
14628 $as_echo "no" >&6; }
14629
14630 { $as_echo "$as_me:${as_lineno-$LINENO}: Package libcurl not found with needed constraints; falling back to defined compilability tests" >&5
14631 $as_echo "$as_me: Package libcurl not found with needed constraints; falling back to defined compilability tests" >&6;}
14632
14633 libcurl_synthetic_cflags=""
14634 libcurl_synthetic_libs="-lcurl"
14635
14636 if test -n "${with_libcurl}" && test x"${with_libcurl}" != xyes && test x"${with_libcurl}" != xno; then
14637 if test -r "${with_libcurl}/include/curl/curl.h"; then
14638 libcurl_synthetic_cflags="-I${with_libcurl}/include"
14639 libcurl_synthetic_libs="-L${with_libcurl}/lib -lcurl"
14640 else
14641 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Header file ${with_libcurl}/include/curl/curl.h was not found. Please check libcurl prefix" >&5
14642 $as_echo "$as_me: WARNING: Header file ${with_libcurl}/include/curl/curl.h was not found. Please check libcurl prefix" >&2;}
14643 fi
14644 else
14645 ac_fn_c_check_header_mongrel "$LINENO" "curl/curl.h" "ac_cv_header_curl_curl_h" "$ac_includes_default"
14646 if test "x$ac_cv_header_curl_curl_h" = xyes; then :
14647
14648 else
14649 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Header file curl/curl.h was not found in default search paths" >&5
14650 $as_echo "$as_me: WARNING: Header file curl/curl.h was not found in default search paths" >&2;}
14651
14652 fi
14653
14654
14655 fi
14656
14657 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for curl_easy_init in -lcurl" >&5
14658 $as_echo_n "checking for curl_easy_init in -lcurl... " >&6; }
14659 if ${ac_cv_lib_curl_curl_easy_init+:} false; then :
14660 $as_echo_n "(cached) " >&6
14661 else
14662 ac_check_lib_save_LIBS=$LIBS
14663 LIBS="-lcurl $LIBS"
14664 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
14665 /* end confdefs.h. */
14666
14667 /* Override any GCC internal prototype to avoid an error.
14668 Use char because int might match the return type of a GCC
14669 builtin and then its argument prototype would still apply. */
14670 #ifdef __cplusplus
14671 extern "C"
14672 #endif
14673 char curl_easy_init ();
14674 int
14675 main ()
14676 {
14677 return curl_easy_init ();
14678 ;
14679 return 0;
14680 }
14681 _ACEOF
14682 if ac_fn_c_try_link "$LINENO"; then :
14683 ac_cv_lib_curl_curl_easy_init=yes
14684 else
14685 ac_cv_lib_curl_curl_easy_init=no
14686 fi
14687 rm -f core conftest.err conftest.$ac_objext \
14688 conftest$ac_exeext conftest.$ac_ext
14689 LIBS=$ac_check_lib_save_LIBS
14690 fi
14691 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_curl_curl_easy_init" >&5
14692 $as_echo "$ac_cv_lib_curl_curl_easy_init" >&6; }
14693 if test "x$ac_cv_lib_curl_curl_easy_init" = xyes; then :
14694
14695 was_libcurl_check_lib_detected=yes
14696 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -lcurl"
14697
14698 $as_echo "#define HAVE_LIBCURL 1" >>confdefs.h
14699
14700
14701 fi
14702
14703
14704 else
14705 libcurl_CFLAGS=$pkg_cv_libcurl_CFLAGS
14706 libcurl_LIBS=$pkg_cv_libcurl_LIBS
14707 { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
14708 $as_echo "yes" >&6; }
14709
14710
14711 $as_echo "#define HAVE_LIBCURL 1" >>confdefs.h
14712
14713 was_libcurl_check_lib_detected=pkgcfg
14714 found_pkgconfig="libcurl"
14715
14716 fi
14717
14718 case "x${was_libcurl_check_lib_detected}" in #(
14719 xpkgcfg) :
14720
14721 PKGCFG_NAMES_PRIVATE="$PKGCFG_NAMES_PRIVATE ${found_pkgconfig} >= 7.28.0"
14722 CFLAGS="${libcurl_CFLAGS} ${CFLAGS}"
14723 LIBS="${libcurl_LIBS} ${LIBS}"
14724 ;; #(
14725 xyes) :
14726
14727 CFLAGS="${libcurl_synthetic_cflags} ${CFLAGS}"
14728 LDFLAGS="${libcurl_synthetic_libs} ${LDFLAGS}"
14729 LIBS="${libcurl_synthetic_libs} ${LIBS}"
14730
14731 libcurl_CFLAGS=${libcurl_synthetic_cflags}
14732
14733 libcurl_LIBS=${libcurl_synthetic_libs}
14734
14735 ;; #(
14736 xno) :
14737
14738 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Cannot find pkg-config metadata for libcurl 7.28.0 or higher" >&5
14739 $as_echo "$as_me: WARNING: Cannot find pkg-config metadata for libcurl 7.28.0 or higher" >&2;}
14740 ;; #(
14741 *) :
14742 ;;
14743 esac
14744
14745 fi
14746
14747
14748 was_libmicrohttpd_check_lib_detected=no
14749
14750 search_libmicrohttpd="no"
14751
14752
14753 # Check whether --with-libmicrohttpd was given.
14754 if test "${with_libmicrohttpd+set}" = set; then :
14755 withval=$with_libmicrohttpd;
14756 search_libmicrohttpd="yes"
14757
14758 else
14759
14760 search_libmicrohttpd="yes"
14761
14762 fi
14763
14764 case x"${with_libmicrohttpd}" in #(
14765 xyes) :
14766 search_libmicrohttpd="yes" ;; #(
14767 xno) :
14768 search_libmicrohttpd="no" ;; #(
14769 *) :
14770 ;;
14771 esac
14772
14773
14774 if test x"${search_libmicrohttpd}" = xyes; then :
14775
14776 # Archive previously detected and supplied flags
14777 PRE_SEARCH_CFLAGS="${CFLAGS}"
14778 PRE_SEARCH_LIBS="${LIBS}"
14779
14780 found_pkgconfig=""
14781
14782 pkg_failed=no
14783 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libmicrohttpd" >&5
14784 $as_echo_n "checking for libmicrohttpd... " >&6; }
14785
14786 if test -n "$libmicrohttpd_CFLAGS"; then
14787 pkg_cv_libmicrohttpd_CFLAGS="$libmicrohttpd_CFLAGS"
14788 elif test -n "$PKG_CONFIG"; then
14789 if test -n "$PKG_CONFIG" && \
14790 { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libmicrohttpd >= 0.0.0\""; } >&5
14791 ($PKG_CONFIG --exists --print-errors "libmicrohttpd >= 0.0.0") 2>&5
14792 ac_status=$?
14793 $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
14794 test $ac_status = 0; }; then
14795 pkg_cv_libmicrohttpd_CFLAGS=`$PKG_CONFIG --cflags "libmicrohttpd >= 0.0.0" 2>/dev/null`
14796 test "x$?" != "x0" && pkg_failed=yes
14797 else
14798 pkg_failed=yes
14799 fi
14800 else
14801 pkg_failed=untried
14802 fi
14803 if test -n "$libmicrohttpd_LIBS"; then
14804 pkg_cv_libmicrohttpd_LIBS="$libmicrohttpd_LIBS"
14805 elif test -n "$PKG_CONFIG"; then
14806 if test -n "$PKG_CONFIG" && \
14807 { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libmicrohttpd >= 0.0.0\""; } >&5
14808 ($PKG_CONFIG --exists --print-errors "libmicrohttpd >= 0.0.0") 2>&5
14809 ac_status=$?
14810 $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
14811 test $ac_status = 0; }; then
14812 pkg_cv_libmicrohttpd_LIBS=`$PKG_CONFIG --libs "libmicrohttpd >= 0.0.0" 2>/dev/null`
14813 test "x$?" != "x0" && pkg_failed=yes
14814 else
14815 pkg_failed=yes
14816 fi
14817 else
14818 pkg_failed=untried
14819 fi
14820
14821
14822
14823 if test $pkg_failed = yes; then
14824 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
14825 $as_echo "no" >&6; }
14826
14827 if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
14828 _pkg_short_errors_supported=yes
14829 else
14830 _pkg_short_errors_supported=no
14831 fi
14832 if test $_pkg_short_errors_supported = yes; then
14833 libmicrohttpd_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libmicrohttpd >= 0.0.0" 2>&1`
14834 else
14835 libmicrohttpd_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libmicrohttpd >= 0.0.0" 2>&1`
14836 fi
14837 # Put the nasty error message in config.log where it belongs
14838 echo "$libmicrohttpd_PKG_ERRORS" >&5
14839
14840
14841 { $as_echo "$as_me:${as_lineno-$LINENO}: Package libmicrohttpd not found; falling back to defined compilability tests" >&5
14842 $as_echo "$as_me: Package libmicrohttpd not found; falling back to defined compilability tests" >&6;}
14843
14844 libmicrohttpd_synthetic_cflags=""
14845 libmicrohttpd_synthetic_libs="-lmicrohttpd"
14846
14847 if test -n "${with_libmicrohttpd}" && test x"${with_libmicrohttpd}" != xyes && test x"${with_libmicrohttpd}" != xno; then
14848 if test -r "${with_libmicrohttpd}/include/microhttpd.h"; then
14849 libmicrohttpd_synthetic_cflags="-I${with_libmicrohttpd}/include"
14850 libmicrohttpd_synthetic_libs="-L${with_libmicrohttpd}/lib -lmicrohttpd"
14851 else
14852 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Header file ${with_libmicrohttpd}/include/microhttpd.h was not found. Please check libmicrohttpd prefix" >&5
14853 $as_echo "$as_me: WARNING: Header file ${with_libmicrohttpd}/include/microhttpd.h was not found. Please check libmicrohttpd prefix" >&2;}
14854 fi
14855 else
14856 ac_fn_c_check_header_mongrel "$LINENO" "microhttpd.h" "ac_cv_header_microhttpd_h" "$ac_includes_default"
14857 if test "x$ac_cv_header_microhttpd_h" = xyes; then :
14858
14859 else
14860 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Header file microhttpd.h was not found in default search paths" >&5
14861 $as_echo "$as_me: WARNING: Header file microhttpd.h was not found in default search paths" >&2;}
14862
14863 fi
14864
14865
14866 fi
14867
14868 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for MHD_start_daemon in -lmicrohttpd" >&5
14869 $as_echo_n "checking for MHD_start_daemon in -lmicrohttpd... " >&6; }
14870 if ${ac_cv_lib_microhttpd_MHD_start_daemon+:} false; then :
14871 $as_echo_n "(cached) " >&6
14872 else
14873 ac_check_lib_save_LIBS=$LIBS
14874 LIBS="-lmicrohttpd $LIBS"
14875 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
14876 /* end confdefs.h. */
14877
14878 /* Override any GCC internal prototype to avoid an error.
14879 Use char because int might match the return type of a GCC
14880 builtin and then its argument prototype would still apply. */
14881 #ifdef __cplusplus
14882 extern "C"
14883 #endif
14884 char MHD_start_daemon ();
14885 int
14886 main ()
14887 {
14888 return MHD_start_daemon ();
14889 ;
14890 return 0;
14891 }
14892 _ACEOF
14893 if ac_fn_c_try_link "$LINENO"; then :
14894 ac_cv_lib_microhttpd_MHD_start_daemon=yes
14895 else
14896 ac_cv_lib_microhttpd_MHD_start_daemon=no
14897 fi
14898 rm -f core conftest.err conftest.$ac_objext \
14899 conftest$ac_exeext conftest.$ac_ext
14900 LIBS=$ac_check_lib_save_LIBS
14901 fi
14902 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_microhttpd_MHD_start_daemon" >&5
14903 $as_echo "$ac_cv_lib_microhttpd_MHD_start_daemon" >&6; }
14904 if test "x$ac_cv_lib_microhttpd_MHD_start_daemon" = xyes; then :
14905
14906 was_libmicrohttpd_check_lib_detected=yes
14907 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -lmicrohttpd"
14908
14909 $as_echo "#define HAVE_LIBMICROHTTPD 1" >>confdefs.h
14910
14911
14912 fi
14913
14914
14915 elif test $pkg_failed = untried; then
14916 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
14917 $as_echo "no" >&6; }
14918
14919 { $as_echo "$as_me:${as_lineno-$LINENO}: Package libmicrohttpd not found; falling back to defined compilability tests" >&5
14920 $as_echo "$as_me: Package libmicrohttpd not found; falling back to defined compilability tests" >&6;}
14921
14922 libmicrohttpd_synthetic_cflags=""
14923 libmicrohttpd_synthetic_libs="-lmicrohttpd"
14924
14925 if test -n "${with_libmicrohttpd}" && test x"${with_libmicrohttpd}" != xyes && test x"${with_libmicrohttpd}" != xno; then
14926 if test -r "${with_libmicrohttpd}/include/microhttpd.h"; then
14927 libmicrohttpd_synthetic_cflags="-I${with_libmicrohttpd}/include"
14928 libmicrohttpd_synthetic_libs="-L${with_libmicrohttpd}/lib -lmicrohttpd"
14929 else
14930 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Header file ${with_libmicrohttpd}/include/microhttpd.h was not found. Please check libmicrohttpd prefix" >&5
14931 $as_echo "$as_me: WARNING: Header file ${with_libmicrohttpd}/include/microhttpd.h was not found. Please check libmicrohttpd prefix" >&2;}
14932 fi
14933 else
14934 ac_fn_c_check_header_mongrel "$LINENO" "microhttpd.h" "ac_cv_header_microhttpd_h" "$ac_includes_default"
14935 if test "x$ac_cv_header_microhttpd_h" = xyes; then :
14936
14937 else
14938 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Header file microhttpd.h was not found in default search paths" >&5
14939 $as_echo "$as_me: WARNING: Header file microhttpd.h was not found in default search paths" >&2;}
14940
14941 fi
14942
14943
14944 fi
14945
14946 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for MHD_start_daemon in -lmicrohttpd" >&5
14947 $as_echo_n "checking for MHD_start_daemon in -lmicrohttpd... " >&6; }
14948 if ${ac_cv_lib_microhttpd_MHD_start_daemon+:} false; then :
14949 $as_echo_n "(cached) " >&6
14950 else
14951 ac_check_lib_save_LIBS=$LIBS
14952 LIBS="-lmicrohttpd $LIBS"
14953 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
14954 /* end confdefs.h. */
14955
14956 /* Override any GCC internal prototype to avoid an error.
14957 Use char because int might match the return type of a GCC
14958 builtin and then its argument prototype would still apply. */
14959 #ifdef __cplusplus
14960 extern "C"
14961 #endif
14962 char MHD_start_daemon ();
14963 int
14964 main ()
14965 {
14966 return MHD_start_daemon ();
14967 ;
14968 return 0;
14969 }
14970 _ACEOF
14971 if ac_fn_c_try_link "$LINENO"; then :
14972 ac_cv_lib_microhttpd_MHD_start_daemon=yes
14973 else
14974 ac_cv_lib_microhttpd_MHD_start_daemon=no
14975 fi
14976 rm -f core conftest.err conftest.$ac_objext \
14977 conftest$ac_exeext conftest.$ac_ext
14978 LIBS=$ac_check_lib_save_LIBS
14979 fi
14980 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_microhttpd_MHD_start_daemon" >&5
14981 $as_echo "$ac_cv_lib_microhttpd_MHD_start_daemon" >&6; }
14982 if test "x$ac_cv_lib_microhttpd_MHD_start_daemon" = xyes; then :
14983
14984 was_libmicrohttpd_check_lib_detected=yes
14985 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -lmicrohttpd"
14986
14987 $as_echo "#define HAVE_LIBMICROHTTPD 1" >>confdefs.h
14988
14989
14990 fi
14991
14992
14993 else
14994 libmicrohttpd_CFLAGS=$pkg_cv_libmicrohttpd_CFLAGS
14995 libmicrohttpd_LIBS=$pkg_cv_libmicrohttpd_LIBS
14996 { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
14997 $as_echo "yes" >&6; }
14998
14999
15000 $as_echo "#define HAVE_LIBMICROHTTPD 1" >>confdefs.h
15001
15002 was_libmicrohttpd_check_lib_detected=pkgcfg
15003 found_pkgconfig="libmicrohttpd"
15004
15005 fi
15006
15007 case "x${was_libmicrohttpd_check_lib_detected}" in #(
15008 xpkgcfg) :
15009
15010 PKGCFG_NAMES_PRIVATE="$PKGCFG_NAMES_PRIVATE ${found_pkgconfig}"
15011 CFLAGS="${libmicrohttpd_CFLAGS} ${CFLAGS}"
15012 LIBS="${libmicrohttpd_LIBS} ${LIBS}"
15013 ;; #(
15014 xyes) :
15015
15016 CFLAGS="${libmicrohttpd_synthetic_cflags} ${CFLAGS}"
15017 LDFLAGS="${libmicrohttpd_synthetic_libs} ${LDFLAGS}"
15018 LIBS="${libmicrohttpd_synthetic_libs} ${LIBS}"
15019
15020 libmicrohttpd_CFLAGS=${libmicrohttpd_synthetic_cflags}
15021
15022 libmicrohttpd_LIBS=${libmicrohttpd_synthetic_libs}
15023
15024 ;; #(
15025 xno) :
15026
15027 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Cannot find pkg-config metadata for libmicrohttpd 0.0.0 or higher" >&5
15028 $as_echo "$as_me: WARNING: Cannot find pkg-config metadata for libmicrohttpd 0.0.0 or higher" >&2;}
15029 ;; #(
15030 *) :
15031 ;;
15032 esac
15033
15034 fi
15035
15036
1438315037 CFLAGS="${PREVIOUS_CFLAGS}"
1438415038 LIBS="${PREVIOUS_LIBS}"
1438515039
1438615040 pkg_config_libs_private=$PKGCFG_LIBS_PRIVATE
15041
15042 pkg_config_names_private=$PKGCFG_NAMES_PRIVATE
1438715043
1438815044
1438915045 # Platform specific checks
1536016016 esac
1536116017
1536216018
15363 # These options are GNU compiler specific.
15364 if test "x$GCC" = "xyes"; then
15365 CPPFLAGS="-pedantic -Werror -Wall -Wc++-compat ${CPPFLAGS}"
15366 fi
15367
1536816019 if test "x$enable_shared" = "xyes"; then
1536916020 ENABLE_SHARED_TRUE=
1537016021 ENABLE_SHARED_FALSE='#'
1569716348 fi
1569816349
1569916350
16351 # These options are GNU compiler specific.
1570016352 if test "x$enable_Werror" = "xyes" || test "x$enable_Werror" = "xauto"; then :
1570116353 if test -n "$CC"; then :
15702 if $CC --version 2>&1 | grep 'Free Software Foundation' > /dev/null; then :
16354 if $CC --version 2>&1 | grep 'Free Software Foundation' > /dev/null && test "x$GCC" = "xyes"; then :
1570316355 { $as_echo "$as_me:${as_lineno-$LINENO}: Enabling pedantic errors for GNU C" >&5
1570416356 $as_echo "$as_me: Enabling pedantic errors for GNU C" >&6;}
15705 CFLAGS="$CFLAGS -Wall -Werror"
16357 CFLAGS="$CFLAGS -pedantic -Wall -Werror -Werror=format-security"
1570616358 else
1570716359 { $as_echo "$as_me:${as_lineno-$LINENO}: Not enabling pedantic errors: compiler not supported by this recipe (not GNU C)" >&5
1570816360 $as_echo "$as_me: Not enabling pedantic errors: compiler not supported by this recipe (not GNU C)" >&6;}
1571316365 fi
1571416366 fi
1571516367 if test -n "$CXX"; then :
15716 if $CXX --version 2>&1 | grep 'Free Software Foundation' > /dev/null; then :
16368 if $CXX --version 2>&1 | grep 'Free Software Foundation' > /dev/null && test "x$GCC" = "xyes"; then :
1571716369 { $as_echo "$as_me:${as_lineno-$LINENO}: Enabling pedantic errors for GNU C++" >&5
1571816370 $as_echo "$as_me: Enabling pedantic errors for GNU C++" >&6;}
15719 CXXFLAGS="$CXXFLAGS -Wall -Werror"
16371 CXXFLAGS="$CXXFLAGS -pedantic -Wall -Werror -Werror=format-security"
1572016372 else
1572116373 { $as_echo "$as_me:${as_lineno-$LINENO}: Not enabling pedantic errors: compiler not supported by this recipe (not GNU C++)" >&5
1572216374 $as_echo "$as_me: Not enabling pedantic errors: compiler not supported by this recipe (not GNU C++)" >&6;}
1572716379 fi
1572816380 fi
1572916381 if test -n "$CPP"; then :
15730 if $CPP --version 2>&1 | grep 'Free Software Foundation' > /dev/null; then :
16382 if $CPP --version 2>&1 | grep 'Free Software Foundation' > /dev/null && test "x$GCC" = "xyes"; then :
1573116383 { $as_echo "$as_me:${as_lineno-$LINENO}: Enabling pedantic errors for GNU CPP preprocessor" >&5
1573216384 $as_echo "$as_me: Enabling pedantic errors for GNU CPP preprocessor" >&6;}
15733 CPPFLAGS="$CPPFLAGS -Wall -Werror"
16385 CPPFLAGS="$CPPFLAGS -pedantic -Werror -Wall -Wc++-compat"
16386
1573416387 else
1573516388 { $as_echo "$as_me:${as_lineno-$LINENO}: Not enabling pedantic errors: preprocessor not supported by this recipe (not GNU CPP)" >&5
1573616389 $as_echo "$as_me: Not enabling pedantic errors: preprocessor not supported by this recipe (not GNU CPP)" >&6;}
1574316396
1574416397 fi
1574516398
16399 # Optional project-local hook to (re-)define some variables that can be used
16400 # in your project files generated from .in templates - in your acinclude.m4,
16401 # add AC_DEFUN([AX_PROJECT_LOCAL_HOOK_CONFIGVARS], [whatever])
16402
16403
1574616404 # Specify output files
1574716405 ac_config_files="$ac_config_files Makefile doc/Makefile include/Makefile src/libczmq.pc"
1574816406
16407
16408
16409 # Optional project-local hook to put some finishing touches in your configure
16410 # script, override something compared to zproject-generated code, etc. - in
16411 # your acinclude.m4, add AC_DEFUN([AX_PROJECT_LOCAL_HOOK_FINAL], [whatever])
1574916412
1575016413
1575116414 cat >confcache <<\_ACEOF
1590616569 as_fn_error $? "conditional \"ENABLE_ASAN\" was never defined.
1590716570 Usually this means the macro was only invoked conditionally." "$LINENO" 5
1590816571 fi
16572 if test -z "${ENABLE_BINDINGS_PYTHON_TRUE}" && test -z "${ENABLE_BINDINGS_PYTHON_FALSE}"; then
16573 as_fn_error $? "conditional \"ENABLE_BINDINGS_PYTHON\" was never defined.
16574 Usually this means the macro was only invoked conditionally." "$LINENO" 5
16575 fi
16576 if test -z "${ENABLE_BINDINGS_PYTHON_TRUE}" && test -z "${ENABLE_BINDINGS_PYTHON_FALSE}"; then
16577 as_fn_error $? "conditional \"ENABLE_BINDINGS_PYTHON\" was never defined.
16578 Usually this means the macro was only invoked conditionally." "$LINENO" 5
16579 fi
1590916580 if test -z "${WITH_CLANG_FORMAT_TRUE}" && test -z "${WITH_CLANG_FORMAT_FALSE}"; then
1591016581 as_fn_error $? "conditional \"WITH_CLANG_FORMAT\" was never defined.
1591116582 Usually this means the macro was only invoked conditionally." "$LINENO" 5
1636417035 # report actual input values of CONFIG_FILES etc. instead of their
1636517036 # values after options handling.
1636617037 ac_log="
16367 This file was extended by czmq $as_me 4.1.1, which was
17038 This file was extended by czmq $as_me 4.2.0, which was
1636817039 generated by GNU Autoconf 2.69. Invocation command line was
1636917040
1637017041 CONFIG_FILES = $CONFIG_FILES
1643017101 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
1643117102 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
1643217103 ac_cs_version="\\
16433 czmq config.status 4.1.1
17104 czmq config.status 4.2.0
1643417105 configured by $0, generated by GNU Autoconf 2.69,
1643517106 with options \\"\$ac_cs_config\\"
1643617107
1826118932 echo Build host.................... : $BUILD_HOST
1826218933 echo Build user.................... : $USER
1826318934 echo Draft API..................... : $enable_drafts
18935 echo Python Bindings............... : $ZPROJECT_BINDINGS_PYTHON
1826418936 echo Install dir................... : $prefix
1826518937 echo Install man pages............. : $czmq_install_man
1826618938
1828018952 echo " - 'make' compile the project"
1828118953 echo " - 'make check' run the project's selftest"
1828218954 echo " - 'make install' install the project to $prefix"
18955 echo " - 'make bindings install enabled language bindings (Python, etc)"
1828318956 echo
1828418957 echo Further options are:
1828518958 echo " - 'make callcheck' run the project's selftest with valgrind to"
11 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
22 # Read the zproject/README.md for information about making permanent changes. #
33 ################################################################################
4 # Note: if your project needs a customized configure script (compared to
5 # the code below 100% generated by zproject), please check first if your
6 # use-case can be handled by acinclude.m4 support in zproject_autotools.gsl
7 # (to AC_DEFUN an AX_PROJECT_LOCAL_HOOK, AX_PROJECT_LOCAL_HOOK_CONFIGVARS
8 # and/or AX_PROJECT_LOCAL_HOOK_FINAL) so you can avoid changing this file
9 # which would complicate re-generation of your project in the future.
410
511 # -*- Autoconf -*-
612 # Process this file with autoconf to produce a configure script.
713 AC_PREREQ(2.61)
814 #
9 AC_INIT([czmq],[4.1.1],[zeromq-dev@lists.zeromq.org])
15 AC_INIT([czmq],[4.2.0],[zeromq-dev@lists.zeromq.org])
1016
1117 AC_CONFIG_AUX_DIR(config)
1218 AC_CONFIG_MACRO_DIR(config)
3036 #
3137 # Libtool -version-info (ABI version)
3238 #
33 # Currently 5:1:1 ("stable"). Don't change this unless you
39 # Currently 6:0:2 ("stable"). Don't change this unless you
3440 # know exactly what you're doing and have read and understand
3541 # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
3642 #
3743 # libczmq -version-info
38 LTVER="5:1:1"
44 LTVER="6:0:2"
3945 AC_SUBST(LTVER)
4046
4147 # building in a subdirectory?
5864 AC_C_BIGENDIAN
5965
6066 # Optional project-local hook (acinclude.m4, add AC_DEFUN([AX_PROJECT_LOCAL_HOOK], [whatever]) )
61 AX_PROJECT_LOCAL_HOOK
67 ifdef([AX_PROJECT_LOCAL_HOOK],
68 [AX_PROJECT_LOCAL_HOOK])
6269
6370 # See if cppcheck is in PATH; this variable unblocks the "cppcheck" recipe
6471 # (note that "make cppcheck.xml" can be used - and perhaps fail - regardless)
98105 AC_MSG_RESULT([yes])
99106 else
100107 AM_CONDITIONAL(ENABLE_ASAN, false)
108 AC_MSG_RESULT([no])
109 fi
110
111 # Install Python Bindings
112 AC_MSG_CHECKING([whether to install Python bindings])
113
114 AC_ARG_ENABLE([bindings-python],
115 AS_HELP_STRING([--enable-bindings-python=yes/no],
116 [Install Python Bindings [default=no]]),
117 [ZPROJECT_BINDINGS_PYTHON=$enableval],
118 [ZPROJECT_BINDINGS_PYTHON=no])
119
120 if test "x$ZPROJECT_BINDINGS_PYTHON" == "xyes"; then
121 AM_CONDITIONAL(ENABLE_BINDINGS_PYTHON, true)
122 AC_MSG_RESULT([yes])
123 else
124 AM_CONDITIONAL(ENABLE_BINDINGS_PYTHON, false)
101125 AC_MSG_RESULT([no])
102126 fi
103127
131155
132156 # Will be used to add flags to pkg-config useful when apps want to statically link
133157 PKGCFG_LIBS_PRIVATE=""
158 PKGCFG_NAMES_PRIVATE=""
134159
135160 # Archive user supplied flags
136161 PREVIOUS_CFLAGS="${CFLAGS}"
167192 PRE_SEARCH_LIBS="${LIBS}"
168193
169194 found_pkgconfig=""
170 found_linkname=""
171195 PKG_CHECK_MODULES([libzmq], [libzmq >= 0.0.0],
172196 [
173 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE $libzmq_LIBS"
174197 was_libzmq_check_lib_detected=pkgcfg
175198 found_pkgconfig="libzmq"
176199 ],
197220 [
198221 was_libzmq_check_lib_detected=yes
199222 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -lzmq"
200 found_linkname="zmq"
201223 ],
202224 [AC_MSG_ERROR([cannot link with -lzmq, install libzmq])])
203225 ])
205227 dnl END of PKG_CHECK_MODULES and/or direct tests for libzmq
206228 AS_CASE(["x${was_libzmq_check_lib_detected}"],
207229 [xpkgcfg], [
208 AC_SUBST([pkgconfig_name_libzmq],[${found_pkgconfig}])
230 PKGCFG_NAMES_PRIVATE="$PKGCFG_NAMES_PRIVATE ${found_pkgconfig}"
209231 CFLAGS="${libzmq_CFLAGS} ${CFLAGS}"
210232 LIBS="${libzmq_LIBS} ${LIBS}"
211233 ],
212234 [xyes], [
213 AC_SUBST([pkgconfig_name_libzmq],[${found_linkname}])
214235 CFLAGS="${libzmq_synthetic_cflags} ${CFLAGS}"
215236 LDFLAGS="${libzmq_synthetic_libs} ${LDFLAGS}"
216237 LIBS="${libzmq_synthetic_libs} ${LIBS}"
219240 AC_SUBST([libzmq_LIBS],[${libzmq_synthetic_libs}])
220241 ],
221242 [xno], [
222 AC_SUBST([pkgconfig_name_libzmq],[libzmq])
223243 AC_MSG_ERROR([Cannot find pkg-config metadata for libzmq 0.0.0 or higher])
224244 ])
225245 ])
252272 PRE_SEARCH_LIBS="${LIBS}"
253273
254274 found_pkgconfig=""
255 found_linkname=""
256275 PKG_CHECK_MODULES([uuid], [uuid >= 0.0.0],
257276 [
258277 AC_DEFINE(HAVE_UUID, 1, [The optional uuid library is to be used])
259 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE $uuid_LIBS"
260278 was_uuid_check_lib_detected=pkgcfg
261279 found_pkgconfig="uuid"
262280 ],
283301 [
284302 was_uuid_check_lib_detected=yes
285303 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -luuid"
286 found_linkname="uuid"
287304 AC_DEFINE(HAVE_UUID, 1, [The optional uuid library is to be used (as -luuid)])
288305 ],
289306 [])
292309 dnl END of PKG_CHECK_MODULES and/or direct tests for uuid
293310 AS_CASE(["x${was_uuid_check_lib_detected}"],
294311 [xpkgcfg], [
295 AC_SUBST([pkgconfig_name_uuid],[${found_pkgconfig}])
312 PKGCFG_NAMES_PRIVATE="$PKGCFG_NAMES_PRIVATE ${found_pkgconfig}"
296313 CFLAGS="${uuid_CFLAGS} ${CFLAGS}"
297314 LIBS="${uuid_LIBS} ${LIBS}"
298315 ],
299316 [xyes], [
300 AC_SUBST([pkgconfig_name_uuid],[${found_linkname}])
301317 CFLAGS="${uuid_synthetic_cflags} ${CFLAGS}"
302318 LDFLAGS="${uuid_synthetic_libs} ${LDFLAGS}"
303319 LIBS="${uuid_synthetic_libs} ${LIBS}"
306322 AC_SUBST([uuid_LIBS],[${uuid_synthetic_libs}])
307323 ],
308324 [xno], [
309 AC_SUBST([pkgconfig_name_uuid],[uuid])
310325 AC_MSG_WARN([Cannot find pkg-config metadata for uuid 0.0.0 or higher])
311326 ])
312327 ])
339354 PRE_SEARCH_LIBS="${LIBS}"
340355
341356 found_pkgconfig=""
342 found_linkname=""
343357 PKG_CHECK_MODULES([systemd], [libsystemd >= 200.0.0],
344358 [
345359 AC_DEFINE(HAVE_LIBSYSTEMD, 1, [The optional libsystemd library is to be used])
346 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE $systemd_LIBS"
347360 was_systemd_check_lib_detected=pkgcfg
348361 found_pkgconfig="libsystemd"
349362 ],
370383 [
371384 was_systemd_check_lib_detected=yes
372385 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -lsystemd"
373 found_linkname="systemd"
374386 AC_DEFINE(HAVE_LIBSYSTEMD, 1, [The optional libsystemd library is to be used (as -lsystemd)])
375387 ],
376388 [])
379391 dnl END of PKG_CHECK_MODULES and/or direct tests for libsystemd
380392 AS_CASE(["x${was_systemd_check_lib_detected}"],
381393 [xpkgcfg], [
382 AC_SUBST([pkgconfig_name_libsystemd],[${found_pkgconfig}])
394 PKGCFG_NAMES_PRIVATE="$PKGCFG_NAMES_PRIVATE ${found_pkgconfig} >= 200.0.0"
383395 CFLAGS="${systemd_CFLAGS} ${CFLAGS}"
384396 LIBS="${systemd_LIBS} ${LIBS}"
385397 ],
386398 [xyes], [
387 AC_SUBST([pkgconfig_name_libsystemd],[${found_linkname}])
388399 CFLAGS="${systemd_synthetic_cflags} ${CFLAGS}"
389400 LDFLAGS="${systemd_synthetic_libs} ${LDFLAGS}"
390401 LIBS="${systemd_synthetic_libs} ${LIBS}"
393404 AC_SUBST([systemd_LIBS],[${systemd_synthetic_libs}])
394405 ],
395406 [xno], [
396 AC_SUBST([pkgconfig_name_libsystemd],[libsystemd])
397407 AC_MSG_WARN([Cannot find pkg-config metadata for libsystemd 200.0.0 or higher])
398408 ])
399409 ])
426436 PRE_SEARCH_LIBS="${LIBS}"
427437
428438 found_pkgconfig=""
429 found_linkname=""
430439 PKG_CHECK_MODULES([lz4], [liblz4 >= 0.0.0],
431440 [
432441 AC_DEFINE(HAVE_LIBLZ4, 1, [The optional liblz4 library is to be used])
433 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE $lz4_LIBS"
434442 was_lz4_check_lib_detected=pkgcfg
435443 found_pkgconfig="liblz4"
436444 ],
457465 [
458466 was_lz4_check_lib_detected=yes
459467 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -llz4"
460 found_linkname="lz4"
461468 AC_DEFINE(HAVE_LIBLZ4, 1, [The optional liblz4 library is to be used (as -llz4)])
462469 ],
463470 [])
466473 dnl END of PKG_CHECK_MODULES and/or direct tests for liblz4
467474 AS_CASE(["x${was_lz4_check_lib_detected}"],
468475 [xpkgcfg], [
469 AC_SUBST([pkgconfig_name_liblz4],[${found_pkgconfig}])
476 PKGCFG_NAMES_PRIVATE="$PKGCFG_NAMES_PRIVATE ${found_pkgconfig}"
470477 CFLAGS="${lz4_CFLAGS} ${CFLAGS}"
471478 LIBS="${lz4_LIBS} ${LIBS}"
472479 ],
473480 [xyes], [
474 AC_SUBST([pkgconfig_name_liblz4],[${found_linkname}])
475481 CFLAGS="${lz4_synthetic_cflags} ${CFLAGS}"
476482 LDFLAGS="${lz4_synthetic_libs} ${LDFLAGS}"
477483 LIBS="${lz4_synthetic_libs} ${LIBS}"
480486 AC_SUBST([lz4_LIBS],[${lz4_synthetic_libs}])
481487 ],
482488 [xno], [
483 AC_SUBST([pkgconfig_name_liblz4],[liblz4])
484489 AC_MSG_WARN([Cannot find pkg-config metadata for liblz4 0.0.0 or higher])
485490 ])
486491 ])
487492 dnl END of enabled attempts to search for liblz4
488493
489494
495 was_libcurl_check_lib_detected=no
496
497 search_libcurl="no"
498
499 AC_ARG_WITH([libcurl],
500 [
501 AS_HELP_STRING([--with-libcurl],
502 [yes or no. Optionally specify libcurl prefix (directory where its include/ and lib/ are located), but that is only used if pkgconfig metadata is not found first])
503 ],
504 [
505 search_libcurl="yes"
506 ],
507 [
508 search_libcurl="yes"
509 ])
510 AS_CASE([x"${with_libcurl}"],
511 [xyes], [search_libcurl="yes"],
512 [xno], [search_libcurl="no"])
513
514
515 AS_IF([test x"${search_libcurl}" = xyes], [
516 # Archive previously detected and supplied flags
517 PRE_SEARCH_CFLAGS="${CFLAGS}"
518 PRE_SEARCH_LIBS="${LIBS}"
519
520 found_pkgconfig=""
521 PKG_CHECK_MODULES([libcurl], [libcurl >= 7.28.0],
522 [
523 AC_DEFINE(HAVE_LIBCURL, 1, [The optional libcurl library is to be used])
524 was_libcurl_check_lib_detected=pkgcfg
525 found_pkgconfig="libcurl"
526 ],
527 [
528 AC_MSG_NOTICE([Package libcurl not found with needed constraints; falling back to defined compilability tests])
529
530 libcurl_synthetic_cflags=""
531 libcurl_synthetic_libs="-lcurl"
532
533 if test -n "${with_libcurl}" && test x"${with_libcurl}" != xyes && test x"${with_libcurl}" != xno; then
534 if test -r "${with_libcurl}/include/curl/curl.h"; then
535 libcurl_synthetic_cflags="-I${with_libcurl}/include"
536 libcurl_synthetic_libs="-L${with_libcurl}/lib -lcurl"
537 else
538 AC_MSG_WARN([Header file ${with_libcurl}/include/curl/curl.h was not found. Please check libcurl prefix])
539 fi
540 else
541 AC_CHECK_HEADER([curl/curl.h], [],
542 AC_MSG_WARN([Header file curl/curl.h was not found in default search paths])
543 )
544 fi
545
546 AC_CHECK_LIB([curl], [curl_easy_init],
547 [
548 was_libcurl_check_lib_detected=yes
549 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -lcurl"
550 AC_DEFINE(HAVE_LIBCURL, 1, [The optional libcurl library is to be used (as -lcurl)])
551 ],
552 [])
553 ])
554
555 dnl END of PKG_CHECK_MODULES and/or direct tests for libcurl
556 AS_CASE(["x${was_libcurl_check_lib_detected}"],
557 [xpkgcfg], [
558 PKGCFG_NAMES_PRIVATE="$PKGCFG_NAMES_PRIVATE ${found_pkgconfig} >= 7.28.0"
559 CFLAGS="${libcurl_CFLAGS} ${CFLAGS}"
560 LIBS="${libcurl_LIBS} ${LIBS}"
561 ],
562 [xyes], [
563 CFLAGS="${libcurl_synthetic_cflags} ${CFLAGS}"
564 LDFLAGS="${libcurl_synthetic_libs} ${LDFLAGS}"
565 LIBS="${libcurl_synthetic_libs} ${LIBS}"
566
567 AC_SUBST([libcurl_CFLAGS],[${libcurl_synthetic_cflags}])
568 AC_SUBST([libcurl_LIBS],[${libcurl_synthetic_libs}])
569 ],
570 [xno], [
571 AC_MSG_WARN([Cannot find pkg-config metadata for libcurl 7.28.0 or higher])
572 ])
573 ])
574 dnl END of enabled attempts to search for libcurl
575
576
577 was_libmicrohttpd_check_lib_detected=no
578
579 search_libmicrohttpd="no"
580
581 AC_ARG_WITH([libmicrohttpd],
582 [
583 AS_HELP_STRING([--with-libmicrohttpd],
584 [yes or no. Optionally specify libmicrohttpd prefix (directory where its include/ and lib/ are located), but that is only used if pkgconfig metadata is not found first])
585 ],
586 [
587 search_libmicrohttpd="yes"
588 ],
589 [
590 search_libmicrohttpd="yes"
591 ])
592 AS_CASE([x"${with_libmicrohttpd}"],
593 [xyes], [search_libmicrohttpd="yes"],
594 [xno], [search_libmicrohttpd="no"])
595
596
597 AS_IF([test x"${search_libmicrohttpd}" = xyes], [
598 # Archive previously detected and supplied flags
599 PRE_SEARCH_CFLAGS="${CFLAGS}"
600 PRE_SEARCH_LIBS="${LIBS}"
601
602 found_pkgconfig=""
603 PKG_CHECK_MODULES([libmicrohttpd], [libmicrohttpd >= 0.0.0],
604 [
605 AC_DEFINE(HAVE_LIBMICROHTTPD, 1, [The optional libmicrohttpd library is to be used])
606 was_libmicrohttpd_check_lib_detected=pkgcfg
607 found_pkgconfig="libmicrohttpd"
608 ],
609 [
610 AC_MSG_NOTICE([Package libmicrohttpd not found; falling back to defined compilability tests])
611
612 libmicrohttpd_synthetic_cflags=""
613 libmicrohttpd_synthetic_libs="-lmicrohttpd"
614
615 if test -n "${with_libmicrohttpd}" && test x"${with_libmicrohttpd}" != xyes && test x"${with_libmicrohttpd}" != xno; then
616 if test -r "${with_libmicrohttpd}/include/microhttpd.h"; then
617 libmicrohttpd_synthetic_cflags="-I${with_libmicrohttpd}/include"
618 libmicrohttpd_synthetic_libs="-L${with_libmicrohttpd}/lib -lmicrohttpd"
619 else
620 AC_MSG_WARN([Header file ${with_libmicrohttpd}/include/microhttpd.h was not found. Please check libmicrohttpd prefix])
621 fi
622 else
623 AC_CHECK_HEADER([microhttpd.h], [],
624 AC_MSG_WARN([Header file microhttpd.h was not found in default search paths])
625 )
626 fi
627
628 AC_CHECK_LIB([microhttpd], [MHD_start_daemon],
629 [
630 was_libmicrohttpd_check_lib_detected=yes
631 PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -lmicrohttpd"
632 AC_DEFINE(HAVE_LIBMICROHTTPD, 1, [The optional libmicrohttpd library is to be used (as -lmicrohttpd)])
633 ],
634 [])
635 ])
636
637 dnl END of PKG_CHECK_MODULES and/or direct tests for libmicrohttpd
638 AS_CASE(["x${was_libmicrohttpd_check_lib_detected}"],
639 [xpkgcfg], [
640 PKGCFG_NAMES_PRIVATE="$PKGCFG_NAMES_PRIVATE ${found_pkgconfig}"
641 CFLAGS="${libmicrohttpd_CFLAGS} ${CFLAGS}"
642 LIBS="${libmicrohttpd_LIBS} ${LIBS}"
643 ],
644 [xyes], [
645 CFLAGS="${libmicrohttpd_synthetic_cflags} ${CFLAGS}"
646 LDFLAGS="${libmicrohttpd_synthetic_libs} ${LDFLAGS}"
647 LIBS="${libmicrohttpd_synthetic_libs} ${LIBS}"
648
649 AC_SUBST([libmicrohttpd_CFLAGS],[${libmicrohttpd_synthetic_cflags}])
650 AC_SUBST([libmicrohttpd_LIBS],[${libmicrohttpd_synthetic_libs}])
651 ],
652 [xno], [
653 AC_MSG_WARN([Cannot find pkg-config metadata for libmicrohttpd 0.0.0 or higher])
654 ])
655 ])
656 dnl END of enabled attempts to search for libmicrohttpd
657
658
490659 CFLAGS="${PREVIOUS_CFLAGS}"
491660 LIBS="${PREVIOUS_LIBS}"
492661
493662 AC_SUBST(pkg_config_libs_private, $PKGCFG_LIBS_PRIVATE)
663 AC_SUBST(pkg_config_names_private, $PKGCFG_NAMES_PRIVATE)
494664
495665 # Platform specific checks
496666 czmq_on_mingw32="no"
659829 AC_C_VOLATILE
660830 AC_C_BIGENDIAN
661831
662 # These options are GNU compiler specific.
663 if test "x$GCC" = "xyes"; then
664 CPPFLAGS="-pedantic -Werror -Wall -Wc++-compat ${CPPFLAGS}"
665 fi
666
667832 AM_CONDITIONAL(ENABLE_SHARED, test "x$enable_shared" = "xyes")
668833 AM_CONDITIONAL(ON_MINGW, test "x$czmq_on_mingw32" = "xyes")
669834 AM_CONDITIONAL(ON_CYGWIN, test "x$czmq_on_cygwin" = "xyes")
766931
767932 AC_ARG_ENABLE([Werror],
768933 AS_HELP_STRING([--enable-Werror],
769 [Add -Wall -Werror to GCC/GXX arguments [default=no; default=auto if nothing specified]]),
934 [Add -Wall -Werror to GCC/GXX arguments [default=no; default=auto if nothing specified as the specific argument value]]),
770935 [AS_IF([test -n "$enableval"], [enable_Werror=$enableval], [enable_Werror=auto])],
771936 [enable_Werror=no])
772937
938 # These options are GNU compiler specific.
773939 AS_IF([test "x$enable_Werror" = "xyes" || test "x$enable_Werror" = "xauto"],
774 [AS_IF([test -n "$CC"],[AS_IF([$CC --version 2>&1 | grep 'Free Software Foundation' > /dev/null],
940 [AS_IF([test -n "$CC"],[AS_IF([$CC --version 2>&1 | grep 'Free Software Foundation' > /dev/null && test "x$GCC" = "xyes"],
775941 [AC_MSG_NOTICE([Enabling pedantic errors for GNU C])
776 CFLAGS="$CFLAGS -Wall -Werror"],
942 CFLAGS="$CFLAGS -pedantic -Wall -Werror -Werror=format-security"],
777943 [AC_MSG_NOTICE([Not enabling pedantic errors: compiler not supported by this recipe (not GNU C)])
778944 AS_IF([test "x$enable_Werror" = "xyes"], [AC_MSG_ERROR([--enable-Werror=yes was requested and can not be satisfied for C: $CC])])
779945 ])])
780 AS_IF([test -n "$CXX"],[AS_IF([$CXX --version 2>&1 | grep 'Free Software Foundation' > /dev/null],
946 AS_IF([test -n "$CXX"],[AS_IF([$CXX --version 2>&1 | grep 'Free Software Foundation' > /dev/null && test "x$GCC" = "xyes"],
781947 [AC_MSG_NOTICE([Enabling pedantic errors for GNU C++])
782 CXXFLAGS="$CXXFLAGS -Wall -Werror"],
948 CXXFLAGS="$CXXFLAGS -pedantic -Wall -Werror -Werror=format-security"],
783949 [AC_MSG_NOTICE([Not enabling pedantic errors: compiler not supported by this recipe (not GNU C++)])
784950 AS_IF([test "x$enable_Werror" = "xyes"], [AC_MSG_ERROR([--enable-Werror=yes was requested and can not be satisfied for C++: $CXX])])
785951 ])])
786 AS_IF([test -n "$CPP"],[AS_IF([$CPP --version 2>&1 | grep 'Free Software Foundation' > /dev/null],
952 AS_IF([test -n "$CPP"],[AS_IF([$CPP --version 2>&1 | grep 'Free Software Foundation' > /dev/null && test "x$GCC" = "xyes"],
787953 [AC_MSG_NOTICE([Enabling pedantic errors for GNU CPP preprocessor])
788 CPPFLAGS="$CPPFLAGS -Wall -Werror"],
954 CPPFLAGS="$CPPFLAGS -pedantic -Werror -Wall -Wc++-compat"
955 ],
789956 [AC_MSG_NOTICE([Not enabling pedantic errors: preprocessor not supported by this recipe (not GNU CPP)])
790957 AS_IF([test "x$enable_Werror" = "xyes"], [AC_MSG_ERROR([--enable-Werror=yes was requested and can not be satisfied for CPP: $CPP])])
791958 ])])
792959 ])
960
961 # Optional project-local hook to (re-)define some variables that can be used
962 # in your project files generated from .in templates - in your acinclude.m4,
963 # add AC_DEFUN([AX_PROJECT_LOCAL_HOOK_CONFIGVARS], [whatever])
964 ifdef([AX_PROJECT_LOCAL_HOOK_CONFIGVARS],
965 [AX_PROJECT_LOCAL_HOOK_CONFIGVARS])
793966
794967 # Specify output files
795968 AC_CONFIG_FILES([Makefile
798971 src/libczmq.pc
799972 ])
800973
974
975 # Optional project-local hook to put some finishing touches in your configure
976 # script, override something compared to zproject-generated code, etc. - in
977 # your acinclude.m4, add AC_DEFUN([AX_PROJECT_LOCAL_HOOK_FINAL], [whatever])
978 ifdef([AX_PROJECT_LOCAL_HOOK_FINAL],
979 [AX_PROJECT_LOCAL_HOOK_FINAL])
801980
802981 AC_OUTPUT
803982
8401019 echo Build host.................... : $BUILD_HOST
8411020 echo Build user.................... : $USER
8421021 echo Draft API..................... : $enable_drafts
1022 echo Python Bindings............... : $ZPROJECT_BINDINGS_PYTHON
8431023 echo Install dir................... : $prefix
8441024 echo Install man pages............. : $czmq_install_man
8451025
8591039 echo " - 'make' compile the project"
8601040 echo " - 'make check' run the project's selftest"
8611041 echo " - 'make install' install the project to $prefix"
1042 echo " - 'make bindings install enabled language bindings (Python, etc)"
8621043 echo
8631044 echo Further options are:
8641045 echo " - 'make callcheck' run the project's selftest with valgrind to"
77 # Public programs ("main" tags in project.xml), auto-regenerated:
88 MAN1 = zmakecert.1
99 # Public classes ("class" tags in project.xml), auto-regenerated:
10 MAN3 = zactor.3 zargs.3 zarmour.3 zcert.3 zcertstore.3 zchunk.3 zclock.3 zconfig.3 zdigest.3 zdir.3 zdir_patch.3 zfile.3 zframe.3 zhash.3 zhashx.3 ziflist.3 zlist.3 zlistx.3 zloop.3 zmsg.3 zpoller.3 zproc.3 zsock.3 zstr.3 zsys.3 ztimerset.3 ztrie.3 zuuid.3 zauth.3 zbeacon.3 zgossip.3 zmonitor.3 zproxy.3 zrex.3
10 MAN3 = zactor.3 zargs.3 zarmour.3 zcert.3 zcertstore.3 zchunk.3 zclock.3 zconfig.3 zdigest.3 zdir.3 zdir_patch.3 zfile.3 zframe.3 zhash.3 zhashx.3 ziflist.3 zlist.3 zlistx.3 zloop.3 zmsg.3 zpoller.3 zproc.3 zsock.3 zstr.3 zsys.3 ztimerset.3 ztrie.3 zuuid.3 zhttp_client.3 zhttp_server.3 zhttp_server_options.3 zhttp_request.3 zhttp_response.3 zauth.3 zbeacon.3 zgossip.3 zmonitor.3 zproxy.3 zrex.3
1111 # Project overview, written by a human after initial skeleton:
1212 # NOTE: stub doc/czmq.adoc is generated by GSL from project.xml
1313 # and then comitted to SCM and maintained manually to describe the
175175 zuuid.txt: $(top_srcdir)/src/zuuid.c
176176 "$(srcdir)/mkman" "zuuid" "$(builddir)/zuuid.txt" "$(srcdir)/.."
177177
178 GENERATED_DOCS += zhttp_client.txt zhttp_client.doc
179 zhttp_client.txt: $(top_srcdir)/src/zhttp_client.c
180 "$(srcdir)/mkman" "zhttp_client" "$(builddir)/zhttp_client.txt" "$(srcdir)/.."
181
182 GENERATED_DOCS += zhttp_server.txt zhttp_server.doc
183 zhttp_server.txt: $(top_srcdir)/src/zhttp_server.c
184 "$(srcdir)/mkman" "zhttp_server" "$(builddir)/zhttp_server.txt" "$(srcdir)/.."
185
186 GENERATED_DOCS += zhttp_server_options.txt zhttp_server_options.doc
187 zhttp_server_options.txt: $(top_srcdir)/src/zhttp_server_options.c
188 "$(srcdir)/mkman" "zhttp_server_options" "$(builddir)/zhttp_server_options.txt" "$(srcdir)/.."
189
190 GENERATED_DOCS += zhttp_request.txt zhttp_request.doc
191 zhttp_request.txt: $(top_srcdir)/src/zhttp_request.c
192 "$(srcdir)/mkman" "zhttp_request" "$(builddir)/zhttp_request.txt" "$(srcdir)/.."
193
194 GENERATED_DOCS += zhttp_response.txt zhttp_response.doc
195 zhttp_response.txt: $(top_srcdir)/src/zhttp_response.c
196 "$(srcdir)/mkman" "zhttp_response" "$(builddir)/zhttp_response.txt" "$(srcdir)/.."
197
178198 GENERATED_DOCS += zauth.txt zauth.doc
179199 zauth.txt: $(top_srcdir)/src/zauth.c
180200 "$(srcdir)/mkman" "zauth" "$(builddir)/zauth.txt" "$(srcdir)/.."
258258 includedir = @includedir@
259259 infodir = @infodir@
260260 install_sh = @install_sh@
261 libcurl_CFLAGS = @libcurl_CFLAGS@
262 libcurl_LIBS = @libcurl_LIBS@
261263 libdir = @libdir@
262264 libexecdir = @libexecdir@
265 libmicrohttpd_CFLAGS = @libmicrohttpd_CFLAGS@
266 libmicrohttpd_LIBS = @libmicrohttpd_LIBS@
263267 libzmq_CFLAGS = @libzmq_CFLAGS@
264268 libzmq_LIBS = @libzmq_LIBS@
265269 localedir = @localedir@
272276 pdfdir = @pdfdir@
273277 pkg_config_defines = @pkg_config_defines@
274278 pkg_config_libs_private = @pkg_config_libs_private@
275 pkgconfig_name_liblz4 = @pkgconfig_name_liblz4@
276 pkgconfig_name_libsystemd = @pkgconfig_name_libsystemd@
277 pkgconfig_name_libzmq = @pkgconfig_name_libzmq@
278 pkgconfig_name_uuid = @pkgconfig_name_uuid@
279 pkg_config_names_private = @pkg_config_names_private@
279280 pkgconfigdir = @pkgconfigdir@
280281 prefix = @prefix@
281282 program_transform_name = @program_transform_name@
296297 # Public programs ("main" tags in project.xml), auto-regenerated:
297298 MAN1 = zmakecert.1
298299 # Public classes ("class" tags in project.xml), auto-regenerated:
299 MAN3 = zactor.3 zargs.3 zarmour.3 zcert.3 zcertstore.3 zchunk.3 zclock.3 zconfig.3 zdigest.3 zdir.3 zdir_patch.3 zfile.3 zframe.3 zhash.3 zhashx.3 ziflist.3 zlist.3 zlistx.3 zloop.3 zmsg.3 zpoller.3 zproc.3 zsock.3 zstr.3 zsys.3 ztimerset.3 ztrie.3 zuuid.3 zauth.3 zbeacon.3 zgossip.3 zmonitor.3 zproxy.3 zrex.3
300 MAN3 = zactor.3 zargs.3 zarmour.3 zcert.3 zcertstore.3 zchunk.3 zclock.3 zconfig.3 zdigest.3 zdir.3 zdir_patch.3 zfile.3 zframe.3 zhash.3 zhashx.3 ziflist.3 zlist.3 zlistx.3 zloop.3 zmsg.3 zpoller.3 zproc.3 zsock.3 zstr.3 zsys.3 ztimerset.3 ztrie.3 zuuid.3 zhttp_client.3 zhttp_server.3 zhttp_server_options.3 zhttp_request.3 zhttp_response.3 zauth.3 zbeacon.3 zgossip.3 zmonitor.3 zproxy.3 zrex.3
300301 # Project overview, written by a human after initial skeleton:
301302 # NOTE: stub doc/czmq.adoc is generated by GSL from project.xml
302303 # and then comitted to SCM and maintained manually to describe the
334335 @BUILD_DOC_TRUE@ zpoller.doc zproc.txt zproc.doc zsock.txt \
335336 @BUILD_DOC_TRUE@ zsock.doc zstr.txt zstr.doc zsys.txt zsys.doc \
336337 @BUILD_DOC_TRUE@ ztimerset.txt ztimerset.doc ztrie.txt \
337 @BUILD_DOC_TRUE@ ztrie.doc zuuid.txt zuuid.doc zauth.txt \
338 @BUILD_DOC_TRUE@ zauth.doc zbeacon.txt zbeacon.doc zgossip.txt \
338 @BUILD_DOC_TRUE@ ztrie.doc zuuid.txt zuuid.doc zhttp_client.txt \
339 @BUILD_DOC_TRUE@ zhttp_client.doc zhttp_server.txt \
340 @BUILD_DOC_TRUE@ zhttp_server.doc zhttp_server_options.txt \
341 @BUILD_DOC_TRUE@ zhttp_server_options.doc zhttp_request.txt \
342 @BUILD_DOC_TRUE@ zhttp_request.doc zhttp_response.txt \
343 @BUILD_DOC_TRUE@ zhttp_response.doc zauth.txt zauth.doc \
344 @BUILD_DOC_TRUE@ zbeacon.txt zbeacon.doc zgossip.txt \
339345 @BUILD_DOC_TRUE@ zgossip.doc zmonitor.txt zmonitor.doc \
340346 @BUILD_DOC_TRUE@ zproxy.txt zproxy.doc zrex.txt zrex.doc \
341347 @BUILD_DOC_TRUE@ zmakecert.txt zmakecert.doc
760766 @BUILD_DOC_TRUE@ "$(srcdir)/mkman" "ztrie" "$(builddir)/ztrie.txt" "$(srcdir)/.."
761767 @BUILD_DOC_TRUE@zuuid.txt: $(top_srcdir)/src/zuuid.c
762768 @BUILD_DOC_TRUE@ "$(srcdir)/mkman" "zuuid" "$(builddir)/zuuid.txt" "$(srcdir)/.."
769 @BUILD_DOC_TRUE@zhttp_client.txt: $(top_srcdir)/src/zhttp_client.c
770 @BUILD_DOC_TRUE@ "$(srcdir)/mkman" "zhttp_client" "$(builddir)/zhttp_client.txt" "$(srcdir)/.."
771 @BUILD_DOC_TRUE@zhttp_server.txt: $(top_srcdir)/src/zhttp_server.c
772 @BUILD_DOC_TRUE@ "$(srcdir)/mkman" "zhttp_server" "$(builddir)/zhttp_server.txt" "$(srcdir)/.."
773 @BUILD_DOC_TRUE@zhttp_server_options.txt: $(top_srcdir)/src/zhttp_server_options.c
774 @BUILD_DOC_TRUE@ "$(srcdir)/mkman" "zhttp_server_options" "$(builddir)/zhttp_server_options.txt" "$(srcdir)/.."
775 @BUILD_DOC_TRUE@zhttp_request.txt: $(top_srcdir)/src/zhttp_request.c
776 @BUILD_DOC_TRUE@ "$(srcdir)/mkman" "zhttp_request" "$(builddir)/zhttp_request.txt" "$(srcdir)/.."
777 @BUILD_DOC_TRUE@zhttp_response.txt: $(top_srcdir)/src/zhttp_response.c
778 @BUILD_DOC_TRUE@ "$(srcdir)/mkman" "zhttp_response" "$(builddir)/zhttp_response.txt" "$(srcdir)/.."
763779 @BUILD_DOC_TRUE@zauth.txt: $(top_srcdir)/src/zauth.c
764780 @BUILD_DOC_TRUE@ "$(srcdir)/mkman" "zauth" "$(builddir)/zauth.txt" "$(srcdir)/.."
765781 @BUILD_DOC_TRUE@zbeacon.txt: $(top_srcdir)/src/zbeacon.c
4141 zargs.h \
4242 zproc.h \
4343 ztimerset.h \
44 ztrie.h
44 ztrie.h \
45 zhttp_client.h \
46 zhttp_server.h \
47 zhttp_server_options.h \
48 zhttp_request.h \
49 zhttp_response.h
4550
4651 endif
4752
8181 @ENABLE_DRAFTS_TRUE@ zargs.h \
8282 @ENABLE_DRAFTS_TRUE@ zproc.h \
8383 @ENABLE_DRAFTS_TRUE@ ztimerset.h \
84 @ENABLE_DRAFTS_TRUE@ ztrie.h
84 @ENABLE_DRAFTS_TRUE@ ztrie.h \
85 @ENABLE_DRAFTS_TRUE@ zhttp_client.h \
86 @ENABLE_DRAFTS_TRUE@ zhttp_server.h \
87 @ENABLE_DRAFTS_TRUE@ zhttp_server_options.h \
88 @ENABLE_DRAFTS_TRUE@ zhttp_request.h \
89 @ENABLE_DRAFTS_TRUE@ zhttp_response.h
8590
8691 subdir = include
8792 DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
124129 ziflist.h zlist.h zlistx.h zloop.h zmsg.h zpoller.h zsock.h \
125130 zstr.h zsys.h zuuid.h zauth.h zbeacon.h zgossip.h zmonitor.h \
126131 zproxy.h zrex.h czmq_library.h zargs.h zproc.h ztimerset.h \
127 ztrie.h
132 ztrie.h zhttp_client.h zhttp_server.h zhttp_server_options.h \
133 zhttp_request.h zhttp_response.h
128134 am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
129135 am__vpath_adj = case $$p in \
130136 $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
284290 includedir = @includedir@
285291 infodir = @infodir@
286292 install_sh = @install_sh@
293 libcurl_CFLAGS = @libcurl_CFLAGS@
294 libcurl_LIBS = @libcurl_LIBS@
287295 libdir = @libdir@
288296 libexecdir = @libexecdir@
297 libmicrohttpd_CFLAGS = @libmicrohttpd_CFLAGS@
298 libmicrohttpd_LIBS = @libmicrohttpd_LIBS@
289299 libzmq_CFLAGS = @libzmq_CFLAGS@
290300 libzmq_LIBS = @libzmq_LIBS@
291301 localedir = @localedir@
298308 pdfdir = @pdfdir@
299309 pkg_config_defines = @pkg_config_defines@
300310 pkg_config_libs_private = @pkg_config_libs_private@
301 pkgconfig_name_liblz4 = @pkgconfig_name_liblz4@
302 pkgconfig_name_libsystemd = @pkgconfig_name_libsystemd@
303 pkgconfig_name_libzmq = @pkgconfig_name_libzmq@
304 pkgconfig_name_uuid = @pkgconfig_name_uuid@
311 pkg_config_names_private = @pkg_config_names_private@
305312 pkgconfigdir = @pkgconfigdir@
306313 prefix = @prefix@
307314 program_transform_name = @program_transform_name@
2626
2727 // CZMQ version macros for compile-time API detection
2828 #define CZMQ_VERSION_MAJOR 4
29 #define CZMQ_VERSION_MINOR 1
30 #define CZMQ_VERSION_PATCH 1
29 #define CZMQ_VERSION_MINOR 2
30 #define CZMQ_VERSION_PATCH 0
3131
3232 #define CZMQ_MAKE_VERSION(major, minor, patch) \
3333 ((major) * 10000 + (minor) * 100 + (patch))
5353 # define CZMQ_EXPORT
5454 # define CZMQ_PRIVATE
5555 #else
56 # define CZMQ_EXPORT
5756 # if (defined __GNUC__ && __GNUC__ >= 4) || defined __INTEL_COMPILER
5857 # define CZMQ_PRIVATE __attribute__ ((visibility ("hidden")))
58 # define CZMQ_EXPORT __attribute__ ((visibility ("default")))
5959 # else
6060 # define CZMQ_PRIVATE
61 # define CZMQ_EXPORT
6162 # endif
6263 #endif
6364
133134 #define ZTIMERSET_T_DEFINED
134135 typedef struct _ztrie_t ztrie_t;
135136 #define ZTRIE_T_DEFINED
137 typedef struct _zhttp_client_t zhttp_client_t;
138 #define ZHTTP_CLIENT_T_DEFINED
139 typedef struct _zhttp_server_t zhttp_server_t;
140 #define ZHTTP_SERVER_T_DEFINED
141 typedef struct _zhttp_server_options_t zhttp_server_options_t;
142 #define ZHTTP_SERVER_OPTIONS_T_DEFINED
143 typedef struct _zhttp_request_t zhttp_request_t;
144 #define ZHTTP_REQUEST_T_DEFINED
145 typedef struct _zhttp_response_t zhttp_response_t;
146 #define ZHTTP_RESPONSE_T_DEFINED
136147 #endif // CZMQ_BUILD_DRAFT_API
137148
138149
172183 #include "zproc.h"
173184 #include "ztimerset.h"
174185 #include "ztrie.h"
186 #include "zhttp_client.h"
187 #include "zhttp_server.h"
188 #include "zhttp_server_options.h"
189 #include "zhttp_request.h"
190 #include "zhttp_response.h"
175191 #endif // CZMQ_BUILD_DRAFT_API
176192
177193 #ifdef CZMQ_BUILD_DRAFT_API
688688 # endif
689689 #endif
690690
691 #if defined (__WINDOWS__) && !defined (HAVE_UUID)
692 # define HAVE_UUID 1
693 #endif
694 #if defined (__UTYPE_OSX) && !defined (HAVE_UUID)
695 # define HAVE_UUID 1
696 #endif
697 #if defined (__UTYPE_FREEBSD) && !defined (HAVE_UUID)
698 # define HAVE_UUID 1
699 #endif
700 #if defined (HAVE_UUID)
701 # if defined (__UTYPE_FREEBSD) || defined (__UTYPE_NETBSD) || defined(__UTYPE_OPENBSD)
702 # include <uuid.h>
703 # elif defined __UTYPE_HPUX
704 # include <dce/uuid.h>
705 # elif defined (__UNIX__)
706 # include <uuid/uuid.h>
707 # endif
708 #endif
709
710691 // ZMQ compatibility macros
711692
712693 #if ZMQ_VERSION_MAJOR == 4
8484 zargs_param_next (zargs_t *self);
8585
8686 // *** Draft method, for development use, may change without warning ***
87 // Return current parameter name, or NULL if there are no named
88 // parameters.
87 // Return current parameter name, or NULL if there are no named parameters.
8988 CZMQ_EXPORT const char *
9089 zargs_param_name (zargs_t *self);
9190
9291 // *** Draft method, for development use, may change without warning ***
93 // Return value of named parameter, NULL if no given parameter has
94 // been specified, or special value for wich zargs_param_empty ()
95 // returns true.
92 // Return value of named parameter or NULL is it has no value (or was not specified)
9693 CZMQ_EXPORT const char *
97 zargs_param_lookup (zargs_t *self, const char *keys);
94 zargs_get (zargs_t *self, const char *name);
9895
9996 // *** Draft method, for development use, may change without warning ***
100 // Return value of named parameter(s), NULL if no given parameter has
101 // been specified, or special value for wich zargs_param_empty ()
102 // returns true.
97 // Return value of one of parameter(s) or NULL is it has no value (or was not specified)
10398 CZMQ_EXPORT const char *
104 zargs_param_lookupx (zargs_t *self, const char *keys, ...);
99 zargs_getx (zargs_t *self, const char *name, ...);
105100
106101 // *** Draft method, for development use, may change without warning ***
107 // Returns true if there are --help -h arguments
102 // Returns true if named parameter was specified on command line
108103 CZMQ_EXPORT bool
109 zargs_has_help (zargs_t *self);
104 zargs_has (zargs_t *self, const char *name);
110105
111106 // *** Draft method, for development use, may change without warning ***
112 // Returns true if parameter did not have a value
107 // Returns true if named parameter(s) was specified on command line
113108 CZMQ_EXPORT bool
114 zargs_param_empty (const char *arg);
109 zargs_hasx (zargs_t *self, const char *name, ...);
115110
116111 // *** Draft method, for development use, may change without warning ***
117112 // Print an instance of zargs.
2222 // @interface
2323 // This is a stable class, and may not change except for emergencies. It
2424 // is provided in stable builds.
25 #define ZARMOUR_MODE_BASE64_STD 0 // Standard base 64
26 #define ZARMOUR_MODE_BASE64_URL 1 // URL and filename friendly base 64
27 #define ZARMOUR_MODE_BASE32_STD 2 // Standard base 32
28 #define ZARMOUR_MODE_BASE32_HEX 3 // Extended hex base 32
29 #define ZARMOUR_MODE_BASE16 4 // Standard base 16
30 #define ZARMOUR_MODE_Z85 5 // Z85 from ZeroMQ RFC 32
25 #define ZARMOUR_MODE_BASE64_STD 0 // Standard base 64
26 #define ZARMOUR_MODE_BASE64_URL 1 // URL and filename friendly base 64
27 #define ZARMOUR_MODE_BASE32_STD 2 // Standard base 32
28 #define ZARMOUR_MODE_BASE32_HEX 3 // Extended hex base 32
29 #define ZARMOUR_MODE_BASE16 4 // Standard base 16
30 #define ZARMOUR_MODE_Z85 5 // Z85 from ZeroMQ RFC 32
3131
3232 // Create a new zarmour
3333 CZMQ_EXPORT zarmour_t *
2222 // @interface
2323 // This is a stable class, and may not change except for emergencies. It
2424 // is provided in stable builds.
25 // This class has draft methods, which may change over time. They are not
26 // in stable releases, by default. Use --enable-drafts to enable.
2527 // Create a new chunk of the specified size. If you specify the data, it
2628 // is copied into the chunk. If you do not specify the data, the chunk is
2729 // allocated and left empty, and you can then add data using zchunk_append.
151153 CZMQ_EXPORT void
152154 zchunk_test (bool verbose);
153155
156 #ifdef CZMQ_BUILD_DRAFT_API
157 // Destroy an item
158 typedef void (zchunk_destructor_fn) (
159 void **hint);
160
161 // *** Draft method, for development use, may change without warning ***
162 // Create a new chunk from memory. Take ownership of the memory and calling the destructor
163 // on destroy.
164 CZMQ_EXPORT zchunk_t *
165 zchunk_frommem (void *data, size_t size, zchunk_destructor_fn destructor, void *hint);
166
167 // *** Draft method, for development use, may change without warning ***
168 // Transform zchunk into a zframe that can be sent in a message.
169 // Take ownership of the chunk.
170 // Caller owns return value and must destroy it when done.
171 CZMQ_EXPORT zframe_t *
172 zchunk_packx (zchunk_t **self_p);
173
174 #endif // CZMQ_BUILD_DRAFT_API
154175 // @end
155176
156177
168168
169169 #ifdef CZMQ_BUILD_DRAFT_API
170170 // *** Draft method, for development use, may change without warning ***
171 // Create copy of zconfig, caller MUST free the value
172 // Create copy of config, as new zconfig object. Returns a fresh zconfig_t
173 // object. If config is null, or memory was exhausted, returns null.
174 // Caller owns return value and must destroy it when done.
175 CZMQ_EXPORT zconfig_t *
176 zconfig_dup (zconfig_t *self);
177
178 // *** Draft method, for development use, may change without warning ***
171179 // Destroy subtree (all children)
172180 CZMQ_EXPORT void
173181 zconfig_remove_subtree (zconfig_t *self);
2626 // @interface
2727 // This is a stable class, and may not change except for emergencies. It
2828 // is provided in stable builds.
29 #define ZDIR_PATCH_CREATE 1 // Creates a new file
30 #define ZDIR_PATCH_DELETE 2 // Delete a file
29 #define ZDIR_PATCH_CREATE 1 // Creates a new file
30 #define ZDIR_PATCH_DELETE 2 // Delete a file
3131
3232 // Create new patch
3333 CZMQ_EXPORT zdir_patch_t *
145145
146146 #ifdef CZMQ_BUILD_DRAFT_API
147147 // *** Draft method, for development use, may change without warning ***
148 // Create new temporary file for writing via tmpfile. File is automaticaly
148 // Create new temporary file for writing via tmpfile. File is automatically
149149 // deleted on destroy
150150 CZMQ_EXPORT zfile_t *
151151 zfile_tmp (void);
2424 // is provided in stable builds.
2525 // This class has draft methods, which may change over time. They are not
2626 // in stable releases, by default. Use --enable-drafts to enable.
27 #define ZFRAME_MORE 1 //
28 #define ZFRAME_REUSE 2 //
29 #define ZFRAME_DONTWAIT 4 //
27 #define ZFRAME_MORE 1 //
28 #define ZFRAME_REUSE 2 //
29 #define ZFRAME_DONTWAIT 4 //
3030
3131 // Create a new frame. If size is not null, allocates the frame data
3232 // to the specified size. If additionally, data is not null, copies
126126 zframe_test (bool verbose);
127127
128128 #ifdef CZMQ_BUILD_DRAFT_API
129 // Destroy an item
130 typedef void (zframe_destructor_fn) (
131 void **hint);
132
133 // *** Draft method, for development use, may change without warning ***
134 // Create a new frame from memory. Take ownership of the memory and calling the destructor
135 // on destroy.
136 CZMQ_EXPORT zframe_t *
137 zframe_frommem (void *data, size_t size, zframe_destructor_fn destructor, void *hint);
138
129139 // *** Draft method, for development use, may change without warning ***
130140 // Return frame routing ID, if the frame came from a ZMQ_SERVER socket.
131141 // Else returns zero.
4444 // zstr_send (zgossip, "VERBOSE");
4545 //
4646 // Bind zgossip to specified endpoint. TCP endpoints may specify
47 // the port number as "*" to aquire an ephemeral port:
47 // the port number as "*" to acquire an ephemeral port:
4848 //
4949 // zstr_sendx (zgossip, "BIND", endpoint, NULL);
5050 //
0 /* =========================================================================
1 zhttp_client - class description
2
3 Copyright (c) the Contributors as noted in the AUTHORS file.
4 This file is part of CZMQ, the high-level C binding for 0MQ:
5 http://czmq.zeromq.org.
6
7 This Source Code Form is subject to the terms of the Mozilla Public
8 License, v. 2.0. If a copy of the MPL was not distributed with this
9 file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 =========================================================================
11 */
12
13 #ifndef ZHTTP_CLIENT_H_INCLUDED
14 #define ZHTTP_CLIENT_H_INCLUDED
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 // @warning THE FOLLOWING @INTERFACE BLOCK IS AUTO-GENERATED BY ZPROJECT
21 // @warning Please edit the model at "api/zhttp_client.api" to make changes.
22 // @interface
23 // This is a draft class, and may change without notice. It is disabled in
24 // stable builds by default. If you use this in applications, please ask
25 // for it to be pushed to stable state. Use --enable-drafts to enable.
26 #ifdef CZMQ_BUILD_DRAFT_API
27 // *** Draft method, for development use, may change without warning ***
28 // Create a new http client
29 CZMQ_EXPORT zhttp_client_t *
30 zhttp_client_new (bool verbose);
31
32 // *** Draft method, for development use, may change without warning ***
33 // Destroy an http client
34 CZMQ_EXPORT void
35 zhttp_client_destroy (zhttp_client_t **self_p);
36
37 // *** Draft method, for development use, may change without warning ***
38 // Self test of this class.
39 CZMQ_EXPORT void
40 zhttp_client_test (bool verbose);
41
42 #endif // CZMQ_BUILD_DRAFT_API
43 // @end
44
45 #ifdef __cplusplus
46 }
47 #endif
48
49 #endif
0 /* =========================================================================
1 zhttp_request - Http request that can be received from zhttp_server or sent to zhttp_client.
2 Class can be reused between send & recv calls.
3 Headers and Content is being destroyed after every send call.
4
5 Copyright (c) the Contributors as noted in the AUTHORS file.
6 This file is part of CZMQ, the high-level C binding for 0MQ:
7 http://czmq.zeromq.org.
8
9 This Source Code Form is subject to the terms of the Mozilla Public
10 License, v. 2.0. If a copy of the MPL was not distributed with this
11 file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 =========================================================================
13 */
14
15 #ifndef ZHTTP_REQUEST_H_INCLUDED
16 #define ZHTTP_REQUEST_H_INCLUDED
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 // @warning THE FOLLOWING @INTERFACE BLOCK IS AUTO-GENERATED BY ZPROJECT
23 // @warning Please edit the model at "api/zhttp_request.api" to make changes.
24 // @interface
25 // This is a draft class, and may change without notice. It is disabled in
26 // stable builds by default. If you use this in applications, please ask
27 // for it to be pushed to stable state. Use --enable-drafts to enable.
28 #ifdef CZMQ_BUILD_DRAFT_API
29 // *** Draft method, for development use, may change without warning ***
30 // Create a new http request.
31 CZMQ_EXPORT zhttp_request_t *
32 zhttp_request_new (void);
33
34 // *** Draft method, for development use, may change without warning ***
35 // Destroy an http request.
36 CZMQ_EXPORT void
37 zhttp_request_destroy (zhttp_request_t **self_p);
38
39 // *** Draft method, for development use, may change without warning ***
40 // Receive a new request from zhttp_server.
41 // Return the underlying connection if successful, to be used when calling zhttp_response_send.
42 CZMQ_EXPORT void *
43 zhttp_request_recv (zhttp_request_t *self, zsock_t *sock);
44
45 // *** Draft method, for development use, may change without warning ***
46 // Send a request to zhttp_client.
47 // Url and the request path will be concatenated.
48 // This behavior is useful for url rewrite and reverse proxy.
49 //
50 // Send also allow two user provided arguments which will be returned with the response.
51 // The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an arg.
52 CZMQ_EXPORT int
53 zhttp_request_send (zhttp_request_t *self, zhttp_client_t *client, int timeout, void *arg, void *arg2);
54
55 // *** Draft method, for development use, may change without warning ***
56 // Get the request method
57 CZMQ_EXPORT const char *
58 zhttp_request_method (zhttp_request_t *self);
59
60 // *** Draft method, for development use, may change without warning ***
61 // Set the request method
62 CZMQ_EXPORT void
63 zhttp_request_set_method (zhttp_request_t *self, const char *method);
64
65 // *** Draft method, for development use, may change without warning ***
66 // Get the request url.
67 // When receiving a request from http server this is only the path part of the url.
68 CZMQ_EXPORT const char *
69 zhttp_request_url (zhttp_request_t *self);
70
71 // *** Draft method, for development use, may change without warning ***
72 // Set the request url
73 // When sending a request to http client this should be full url.
74 CZMQ_EXPORT void
75 zhttp_request_set_url (zhttp_request_t *self, const char *url);
76
77 // *** Draft method, for development use, may change without warning ***
78 // Get the request content type
79 CZMQ_EXPORT const char *
80 zhttp_request_content_type (zhttp_request_t *self);
81
82 // *** Draft method, for development use, may change without warning ***
83 // Set the request content type
84 CZMQ_EXPORT void
85 zhttp_request_set_content_type (zhttp_request_t *self, const char *content_type);
86
87 // *** Draft method, for development use, may change without warning ***
88 // Get the content length of the request
89 CZMQ_EXPORT size_t
90 zhttp_request_content_length (zhttp_request_t *self);
91
92 // *** Draft method, for development use, may change without warning ***
93 // Get the headers of the request
94 CZMQ_EXPORT zhash_t *
95 zhttp_request_headers (zhttp_request_t *self);
96
97 // *** Draft method, for development use, may change without warning ***
98 // Get the content of the request.
99 CZMQ_EXPORT const char *
100 zhttp_request_content (zhttp_request_t *self);
101
102 // *** Draft method, for development use, may change without warning ***
103 // Get the content of the request.
104 // Caller owns return value and must destroy it when done.
105 CZMQ_EXPORT char *
106 zhttp_request_get_content (zhttp_request_t *self);
107
108 // *** Draft method, for development use, may change without warning ***
109 // Set the content of the request.
110 // Content must by dynamically allocated string.
111 // Takes ownership of the content.
112 CZMQ_EXPORT void
113 zhttp_request_set_content (zhttp_request_t *self, char **content);
114
115 // *** Draft method, for development use, may change without warning ***
116 // Set the content of the request..
117 // The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
118 CZMQ_EXPORT void
119 zhttp_request_set_content_const (zhttp_request_t *self, const char *content);
120
121 // *** Draft method, for development use, may change without warning ***
122 // Set the content to NULL
123 CZMQ_EXPORT void
124 zhttp_request_reset_content (zhttp_request_t *self);
125
126 // *** Draft method, for development use, may change without warning ***
127 // Match the path of the request.
128 // Support wildcards with '%s' symbol inside the match string.
129 // Matching wildcards until the next '/', '?' or '\0'.
130 // On successful match the variadic arguments will be filled with the matching strings.
131 // On successful match the method is modifying the url field and break it into substrings.
132 // If you need to use the url, do it before matching or take a copy.
133 //
134 // User must not free the variadic arguments as they are part of the url.
135 //
136 // To use the percent symbol, just double it, e.g "%%something".
137 //
138 // Example:
139 // if (zhttp_request_match (request, "POST", "/send/%s/%s", &name, &id))
140 CZMQ_EXPORT bool
141 zhttp_request_match (zhttp_request_t *self, const char *method, const char *path, ...);
142
143 // *** Draft method, for development use, may change without warning ***
144 // Self test of this class.
145 CZMQ_EXPORT void
146 zhttp_request_test (bool verbose);
147
148 #endif // CZMQ_BUILD_DRAFT_API
149 // @end
150
151 #ifdef __cplusplus
152 }
153 #endif
154
155 #endif
0 /* =========================================================================
1 zhttp_response - Http response that can be received from zhttp_client or sent to zhttp_server.
2 Class can be reused between send & recv calls.
3 Headers and Content is being destroyed after every send call.
4
5 Copyright (c) the Contributors as noted in the AUTHORS file.
6 This file is part of CZMQ, the high-level C binding for 0MQ:
7 http://czmq.zeromq.org.
8
9 This Source Code Form is subject to the terms of the Mozilla Public
10 License, v. 2.0. If a copy of the MPL was not distributed with this
11 file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 =========================================================================
13 */
14
15 #ifndef ZHTTP_RESPONSE_H_INCLUDED
16 #define ZHTTP_RESPONSE_H_INCLUDED
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 // @warning THE FOLLOWING @INTERFACE BLOCK IS AUTO-GENERATED BY ZPROJECT
23 // @warning Please edit the model at "api/zhttp_response.api" to make changes.
24 // @interface
25 // This is a draft class, and may change without notice. It is disabled in
26 // stable builds by default. If you use this in applications, please ask
27 // for it to be pushed to stable state. Use --enable-drafts to enable.
28 #ifdef CZMQ_BUILD_DRAFT_API
29 // *** Draft method, for development use, may change without warning ***
30 // Create a new zhttp_response.
31 CZMQ_EXPORT zhttp_response_t *
32 zhttp_response_new (void);
33
34 // *** Draft method, for development use, may change without warning ***
35 // Destroy the zhttp_response.
36 CZMQ_EXPORT void
37 zhttp_response_destroy (zhttp_response_t **self_p);
38
39 // *** Draft method, for development use, may change without warning ***
40 // Send a response to a request.
41 // Returns 0 if successful and -1 otherwise.
42 CZMQ_EXPORT int
43 zhttp_response_send (zhttp_response_t *self, zsock_t *sock, void **connection);
44
45 // *** Draft method, for development use, may change without warning ***
46 // Receive a response from zhttp_client.
47 // On success return 0, -1 otherwise.
48 //
49 // Recv returns the two user arguments which was provided with the request.
50 // The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an argument.
51 CZMQ_EXPORT int
52 zhttp_response_recv (zhttp_response_t *self, zhttp_client_t *client, void **arg, void **arg2);
53
54 // *** Draft method, for development use, may change without warning ***
55 // Get the response content type
56 CZMQ_EXPORT const char *
57 zhttp_response_content_type (zhttp_response_t *self);
58
59 // *** Draft method, for development use, may change without warning ***
60 // Set the content type of the response.
61 CZMQ_EXPORT void
62 zhttp_response_set_content_type (zhttp_response_t *self, const char *value);
63
64 // *** Draft method, for development use, may change without warning ***
65 // Get the status code of the response.
66 CZMQ_EXPORT uint32_t
67 zhttp_response_status_code (zhttp_response_t *self);
68
69 // *** Draft method, for development use, may change without warning ***
70 // Set the status code of the response.
71 CZMQ_EXPORT void
72 zhttp_response_set_status_code (zhttp_response_t *self, uint32_t status_code);
73
74 // *** Draft method, for development use, may change without warning ***
75 // Get the headers of the response.
76 CZMQ_EXPORT zhash_t *
77 zhttp_response_headers (zhttp_response_t *self);
78
79 // *** Draft method, for development use, may change without warning ***
80 // Get the content length of the response
81 CZMQ_EXPORT size_t
82 zhttp_response_content_length (zhttp_response_t *self);
83
84 // *** Draft method, for development use, may change without warning ***
85 // Get the content of the response.
86 CZMQ_EXPORT const char *
87 zhttp_response_content (zhttp_response_t *self);
88
89 // *** Draft method, for development use, may change without warning ***
90 // Get the content of the response.
91 // Caller owns return value and must destroy it when done.
92 CZMQ_EXPORT char *
93 zhttp_response_get_content (zhttp_response_t *self);
94
95 // *** Draft method, for development use, may change without warning ***
96 // Set the content of the response.
97 // Content must by dynamically allocated string.
98 // Takes ownership of the content.
99 CZMQ_EXPORT void
100 zhttp_response_set_content (zhttp_response_t *self, char **content);
101
102 // *** Draft method, for development use, may change without warning ***
103 // Set the content of the response.
104 // The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
105 CZMQ_EXPORT void
106 zhttp_response_set_content_const (zhttp_response_t *self, const char *content);
107
108 // *** Draft method, for development use, may change without warning ***
109 // Set the content to NULL
110 CZMQ_EXPORT void
111 zhttp_response_reset_content (zhttp_response_t *self);
112
113 // *** Draft method, for development use, may change without warning ***
114 // Self test of this class.
115 CZMQ_EXPORT void
116 zhttp_response_test (bool verbose);
117
118 #endif // CZMQ_BUILD_DRAFT_API
119 // @end
120
121 #ifdef __cplusplus
122 }
123 #endif
124
125 #endif
0 /* =========================================================================
1 zhttp_server - Simple http server.
2 To start handling requests:
3 1. Create a dealer socket
4 2. Connect the socket to the server backend address provided in the options.
5 3. Create a zhttp_request.
6 4. Call zhttp_request_recv to accept a new request.
7 5. Call zhttp_response_send to send a response.
8
9 You can connect as many dealers as you want.
10 The Server is using simple dealer socket to route the requests.
11
12 Copyright (c) the Contributors as noted in the AUTHORS file.
13 This file is part of CZMQ, the high-level C binding for 0MQ:
14 http://czmq.zeromq.org.
15
16 This Source Code Form is subject to the terms of the Mozilla Public
17 License, v. 2.0. If a copy of the MPL was not distributed with this
18 file, You can obtain one at http://mozilla.org/MPL/2.0/.
19 =========================================================================
20 */
21
22 #ifndef ZHTTP_SERVER_H_INCLUDED
23 #define ZHTTP_SERVER_H_INCLUDED
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 // @warning THE FOLLOWING @INTERFACE BLOCK IS AUTO-GENERATED BY ZPROJECT
30 // @warning Please edit the model at "api/zhttp_server.api" to make changes.
31 // @interface
32 // This is a draft class, and may change without notice. It is disabled in
33 // stable builds by default. If you use this in applications, please ask
34 // for it to be pushed to stable state. Use --enable-drafts to enable.
35 #ifdef CZMQ_BUILD_DRAFT_API
36 // *** Draft method, for development use, may change without warning ***
37 // Create a new http server
38 CZMQ_EXPORT zhttp_server_t *
39 zhttp_server_new (zhttp_server_options_t *options);
40
41 // *** Draft method, for development use, may change without warning ***
42 // Destroy an http server
43 CZMQ_EXPORT void
44 zhttp_server_destroy (zhttp_server_t **self_p);
45
46 // *** Draft method, for development use, may change without warning ***
47 // Return the port the server is listening on.
48 CZMQ_EXPORT int
49 zhttp_server_port (zhttp_server_t *self);
50
51 // *** Draft method, for development use, may change without warning ***
52 // Self test of this class.
53 CZMQ_EXPORT void
54 zhttp_server_test (bool verbose);
55
56 #endif // CZMQ_BUILD_DRAFT_API
57 // @end
58
59 #ifdef __cplusplus
60 }
61 #endif
62
63 #endif
0 /* =========================================================================
1 zhttp_server_options - zhttp server.
2
3 Copyright (c) the Contributors as noted in the AUTHORS file.
4 This file is part of CZMQ, the high-level C binding for 0MQ:
5 http://czmq.zeromq.org.
6
7 This Source Code Form is subject to the terms of the Mozilla Public
8 License, v. 2.0. If a copy of the MPL was not distributed with this
9 file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 =========================================================================
11 */
12
13 #ifndef ZHTTP_SERVER_OPTIONS_H_INCLUDED
14 #define ZHTTP_SERVER_OPTIONS_H_INCLUDED
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 // @warning THE FOLLOWING @INTERFACE BLOCK IS AUTO-GENERATED BY ZPROJECT
21 // @warning Please edit the model at "api/zhttp_server_options.api" to make changes.
22 // @interface
23 // This is a draft class, and may change without notice. It is disabled in
24 // stable builds by default. If you use this in applications, please ask
25 // for it to be pushed to stable state. Use --enable-drafts to enable.
26 #ifdef CZMQ_BUILD_DRAFT_API
27 // *** Draft method, for development use, may change without warning ***
28 // Create a new zhttp_server_options.
29 CZMQ_EXPORT zhttp_server_options_t *
30 zhttp_server_options_new (void);
31
32 // *** Draft method, for development use, may change without warning ***
33 // Create options from config tree.
34 CZMQ_EXPORT zhttp_server_options_t *
35 zhttp_server_options_from_config (zconfig_t *config);
36
37 // *** Draft method, for development use, may change without warning ***
38 // Destroy the zhttp_server_options.
39 CZMQ_EXPORT void
40 zhttp_server_options_destroy (zhttp_server_options_t **self_p);
41
42 // *** Draft method, for development use, may change without warning ***
43 // Get the server listening port.
44 CZMQ_EXPORT int
45 zhttp_server_options_port (zhttp_server_options_t *self);
46
47 // *** Draft method, for development use, may change without warning ***
48 // Set the server listening port
49 CZMQ_EXPORT void
50 zhttp_server_options_set_port (zhttp_server_options_t *self, int port);
51
52 // *** Draft method, for development use, may change without warning ***
53 // Get the address sockets should connect to in order to receive requests.
54 CZMQ_EXPORT const char *
55 zhttp_server_options_backend_address (zhttp_server_options_t *self);
56
57 // *** Draft method, for development use, may change without warning ***
58 // Set the address sockets should connect to in order to receive requests.
59 CZMQ_EXPORT void
60 zhttp_server_options_set_backend_address (zhttp_server_options_t *self, const char *address);
61
62 // *** Draft method, for development use, may change without warning ***
63 // Self test of this class.
64 CZMQ_EXPORT void
65 zhttp_server_options_test (bool verbose);
66
67 #endif // CZMQ_BUILD_DRAFT_API
68 // @end
69
70 #ifdef __cplusplus
71 }
72 #endif
73
74 #endif
2222 // @interface
2323 // This is a stable class, and may not change except for emergencies. It
2424 // is provided in stable builds.
25 // This class has draft methods, which may change over time. They are not
26 // in stable releases, by default. Use --enable-drafts to enable.
2527 // Destroy an item
2628 typedef void (zlistx_destructor_fn) (
2729 void **item);
194196 CZMQ_EXPORT void
195197 zlistx_test (bool verbose);
196198
199 #ifdef CZMQ_BUILD_DRAFT_API
200 // *** Draft method, for development use, may change without warning ***
201 // Unpack binary frame into a new list. Packed data must follow format
202 // defined by zlistx_pack. List is set to autofree. An empty frame
203 // unpacks to an empty list.
204 CZMQ_EXPORT zlistx_t *
205 zlistx_unpack (zframe_t *frame);
206
207 // *** Draft method, for development use, may change without warning ***
208 // Serialize list to a binary frame that can be sent in a message.
209 // The packed format is compatible with the 'strings' type implemented by zproto:
210 //
211 // ; A list of strings
212 // list = list-count *longstr
213 // list-count = number-4
214 //
215 // ; Strings are always length + text contents
216 // longstr = number-4 *VCHAR
217 //
218 // ; Numbers are unsigned integers in network byte order
219 // number-4 = 4OCTET
220 // Caller owns return value and must destroy it when done.
221 CZMQ_EXPORT zframe_t *
222 zlistx_pack (zlistx_t *self);
223
224 #endif // CZMQ_BUILD_DRAFT_API
197225 // @end
198226
199227
121121 zproc_running (zproc_t *self);
122122
123123 // *** Draft method, for development use, may change without warning ***
124 // The timeout should be zero or greater, or -1 to wait indefinitely.
124125 // wait or poll process status, return return code
125126 CZMQ_EXPORT int
126 zproc_wait (zproc_t *self, bool hang);
127 zproc_wait (zproc_t *self, int timeout);
127128
128129 // *** Draft method, for development use, may change without warning ***
129 // return internal actor, usefull for the polling if process died
130 // send SIGTERM signal to the subprocess, wait for grace period and
131 // eventually send SIGKILL
132 CZMQ_EXPORT void
133 zproc_shutdown (zproc_t *self, int timeout);
134
135 // *** Draft method, for development use, may change without warning ***
136 // return internal actor, useful for the polling if process died
130137 CZMQ_EXPORT void *
131138 zproc_actor (zproc_t *self);
132139
4343 //
4444 // zstr_sendx (proxy, "FRONTEND", "XSUB", endpoints, NULL);
4545 // zsock_wait (proxy);
46 //
47 // When the socket type is XSUB or SUB, topic(s) string(s) can be passed as
48 // additional arguments (NOTE: in DRAFT state) and the socket will subscribe
49 // using them.
4650 //
4751 // Specify backend socket type -- see zsock_type_str () -- and attach to
4852 // endpoints, see zsock_attach (). Note that a proxy socket is always
165165 // c = zchunk_t *
166166 // f = zframe_t *
167167 // h = zhashx_t *
168 // l = zlistx_t * (DRAFT)
168169 // U = zuuid_t *
169170 // p = void * (sends the pointer value, only meaningful over inproc)
170171 // m = zmsg_t * (sends all frames in the zmsg)
198199 // f = zframe_t ** (creates zframe)
199200 // U = zuuid_t * (creates a zuuid with the data)
200201 // h = zhashx_t ** (creates zhashx)
202 // l = zlistx_t ** (creates zlistx) (DRAFT)
201203 // p = void ** (stores pointer)
202 // m = zmsg_t ** (creates a zmsg with the remaing frames)
204 // m = zmsg_t ** (creates a zmsg with the remaining frames)
203205 // z = null, asserts empty frame (0 arguments)
204206 // u = uint * (stores unsigned integer, deprecated)
205207 //
303305 CZMQ_EXPORT void *
304306 zsock_resolve (void *self);
305307
308 // Get socket option `router_notify`.
309 // Available from libzmq 4.3.0.
310 // Caller owns return value and must destroy it when done.
311 CZMQ_EXPORT int
312 zsock_router_notify (void *self);
313
314 // Set socket option `router_notify`.
315 // Available from libzmq 4.3.0.
316 CZMQ_EXPORT void
317 zsock_set_router_notify (void *self, int router_notify);
318
319 // Get socket option `multicast_loop`.
320 // Available from libzmq 4.3.0.
321 // Caller owns return value and must destroy it when done.
322 CZMQ_EXPORT int
323 zsock_multicast_loop (void *self);
324
325 // Set socket option `multicast_loop`.
326 // Available from libzmq 4.3.0.
327 CZMQ_EXPORT void
328 zsock_set_multicast_loop (void *self, int multicast_loop);
329
330 // Get socket option `metadata`.
331 // Available from libzmq 4.3.0.
332 // Caller owns return value and must destroy it when done.
333 CZMQ_EXPORT char *
334 zsock_metadata (void *self);
335
336 // Set socket option `metadata`.
337 // Available from libzmq 4.3.0.
338 CZMQ_EXPORT void
339 zsock_set_metadata (void *self, const char *metadata);
340
341 // Get socket option `loopback_fastpath`.
342 // Available from libzmq 4.3.0.
343 // Caller owns return value and must destroy it when done.
344 CZMQ_EXPORT int
345 zsock_loopback_fastpath (void *self);
346
347 // Set socket option `loopback_fastpath`.
348 // Available from libzmq 4.3.0.
349 CZMQ_EXPORT void
350 zsock_set_loopback_fastpath (void *self, int loopback_fastpath);
351
352 // Get socket option `zap_enforce_domain`.
353 // Available from libzmq 4.3.0.
354 // Caller owns return value and must destroy it when done.
355 CZMQ_EXPORT int
356 zsock_zap_enforce_domain (void *self);
357
358 // Set socket option `zap_enforce_domain`.
359 // Available from libzmq 4.3.0.
360 CZMQ_EXPORT void
361 zsock_set_zap_enforce_domain (void *self, int zap_enforce_domain);
362
363 // Get socket option `gssapi_principal_nametype`.
364 // Available from libzmq 4.3.0.
365 // Caller owns return value and must destroy it when done.
366 CZMQ_EXPORT int
367 zsock_gssapi_principal_nametype (void *self);
368
369 // Set socket option `gssapi_principal_nametype`.
370 // Available from libzmq 4.3.0.
371 CZMQ_EXPORT void
372 zsock_set_gssapi_principal_nametype (void *self, int gssapi_principal_nametype);
373
374 // Get socket option `gssapi_service_principal_nametype`.
375 // Available from libzmq 4.3.0.
376 // Caller owns return value and must destroy it when done.
377 CZMQ_EXPORT int
378 zsock_gssapi_service_principal_nametype (void *self);
379
380 // Set socket option `gssapi_service_principal_nametype`.
381 // Available from libzmq 4.3.0.
382 CZMQ_EXPORT void
383 zsock_set_gssapi_service_principal_nametype (void *self, int gssapi_service_principal_nametype);
384
385 // Get socket option `bindtodevice`.
386 // Available from libzmq 4.3.0.
387 // Caller owns return value and must destroy it when done.
388 CZMQ_EXPORT char *
389 zsock_bindtodevice (void *self);
390
391 // Set socket option `bindtodevice`.
392 // Available from libzmq 4.3.0.
393 CZMQ_EXPORT void
394 zsock_set_bindtodevice (void *self, const char *bindtodevice);
395
306396 // Get socket option `heartbeat_ivl`.
307397 // Available from libzmq 4.2.0.
308398 // Caller owns return value and must destroy it when done.
11131203 // Returns 0 if OK, -1 if failed.
11141204 CZMQ_EXPORT int
11151205 zsock_leave (void *self, const char *group);
1206
1207 // *** Draft method, for development use, may change without warning ***
1208 // Check whether the socket has available message to read.
1209 CZMQ_EXPORT bool
1210 zsock_has_in (void *self);
11161211
11171212 #endif // CZMQ_BUILD_DRAFT_API
11181213 // @end
8383
8484 // Set default interrupt handler, so Ctrl-C or SIGTERM will set
8585 // zsys_interrupted. Idempotent; safe to call multiple times.
86 // Can be supressed by ZSYS_SIGHANDLER=false
86 // Can be suppressed by ZSYS_SIGHANDLER=false
8787 // *** This is for CZMQ internal use only and may change arbitrarily ***
8888 CZMQ_EXPORT void
8989 zsys_catch_interrupts (void);
231231 // Note that this method is valid only before any socket is created.
232232 CZMQ_EXPORT void
233233 zsys_set_thread_priority (int priority);
234
235 // Configure the numeric prefix to each thread created for the internal
236 // context's thread pool. This option is only supported on Linux.
237 // If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
238 // provides the default.
239 // Note that this method is valid only before any socket is created.
240 CZMQ_EXPORT void
241 zsys_set_thread_name_prefix (int prefix);
242
243 // Return thread name prefix.
244 CZMQ_EXPORT int
245 zsys_thread_name_prefix (void);
246
247 // Adds a specific CPU to the affinity list of the ZMQ context thread pool.
248 // This option is only supported on Linux.
249 // Note that this method is valid only before any socket is created.
250 CZMQ_EXPORT void
251 zsys_thread_affinity_cpu_add (int cpu);
252
253 // Removes a specific CPU to the affinity list of the ZMQ context thread pool.
254 // This option is only supported on Linux.
255 // Note that this method is valid only before any socket is created.
256 CZMQ_EXPORT void
257 zsys_thread_affinity_cpu_remove (int cpu);
234258
235259 // Configure the number of sockets that ZeroMQ will allow. The default
236260 // is 1024. The actual limit depends on the system, and you can query it
417441 zsys_set_interrupted (void);
418442
419443 // *** Draft method, for development use, may change without warning ***
444 // Format a string using printf formatting, returning a freshly allocated
445 // buffer. If there was insufficient memory, returns NULL. Free the returned
446 // string using zstr_free(). The hinted version allows to optimize by using
447 // a larger starting buffer size (known to/assumed by the developer) and so
448 // avoid reallocations.
449 CZMQ_EXPORT char *
450 zsys_sprintf_hint (int hint, const char *format, ...);
451
452 // *** Draft method, for development use, may change without warning ***
420453 // Configure whether to use zero copy strategy in libzmq. If the environment
421454 // variable ZSYS_ZERO_COPY_RECV is defined, that provides the default.
422455 // Otherwise the default is 1.
444477 CZMQ_EXPORT int64_t
445478 zsys_file_stable_age_msec (void);
446479
480 // *** Draft method, for development use, may change without warning ***
481 // Print formatted string. Format is specified by variable names
482 // in Python-like format style
483 //
484 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
485 // become
486 // "key=value"
487 //
488 // Returns freshly allocated string or NULL in a case of error.
489 // Not enough memory, invalid format specifier, name not in args
490 // Caller owns return value and must destroy it when done.
491 CZMQ_EXPORT char *
492 zsys_zprintf (const char *format, zhash_t *args);
493
494 // *** Draft method, for development use, may change without warning ***
495 // Return error string for given format/args combination.
496 // Caller owns return value and must destroy it when done.
497 CZMQ_EXPORT char *
498 zsys_zprintf_error (const char *format, zhash_t *args);
499
500 // *** Draft method, for development use, may change without warning ***
501 // Print formatted string. Format is specified by variable names
502 // in Python-like format style
503 //
504 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
505 // become
506 // "key=value"
507 //
508 // Returns freshly allocated string or NULL in a case of error.
509 // Not enough memory, invalid format specifier, name not in args
510 // Caller owns return value and must destroy it when done.
511 CZMQ_EXPORT char *
512 zsys_zplprintf (const char *format, zconfig_t *args);
513
514 // *** Draft method, for development use, may change without warning ***
515 // Return error string for given format/args combination.
516 // Caller owns return value and must destroy it when done.
517 CZMQ_EXPORT char *
518 zsys_zplprintf_error (const char *format, zconfig_t *args);
519
447520 #endif // CZMQ_BUILD_DRAFT_API
448521 // @end
449522
99 endif()
1010 if(CMAKE_THREAD_LIBS_INIT)
1111 if(CZMQ_BUILD_SHARED)
12 target_link_libraries(czmq "${CMAKE_THREAD_LIBS_INIT}")
12 target_link_libraries(czmq PUBLIC "${CMAKE_THREAD_LIBS_INIT}")
1313 endif()
1414 if(CZMQ_BUILD_STATIC)
15 target_link_libraries(czmq-static "${CMAKE_THREAD_LIBS_INIT}")
15 target_link_libraries(czmq-static PUBLIC "${CMAKE_THREAD_LIBS_INIT}")
1616 endif()
1717 endif()
1818
1919 # at least C99 is required for zdir which uses ‘for’ loop initial declarations
2020 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
2121
22 if(NOT CMAKE_CROSSCOMPILING AND UNIX)
23 # prevent Unknown CMake command "check_c_source_runs".
24 include(CheckCSourceRuns)
25
26 message(STATUS "Checking whether SOCK_CLOEXEC is supported")
27 check_c_source_runs(
28 "
29 #include <sys/types.h>
30 #include <sys/socket.h>
31
32 int main(int argc, char *argv [])
33 {
34 int s = socket(PF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
35 return(s == -1);
36 }
37 "
38 CZMQ_HAVE_SOCK_CLOEXEC)
39
40 if(CZMQ_HAVE_SOCK_CLOEXEC)
41 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCZMQ_HAVE_SOCK_CLOEXEC=1")
42 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCZMQ_HAVE_SOCK_CLOEXEC=1")
43 endif()
44 endif()
5959 src/zargs.c \
6060 src/zproc.c \
6161 src/ztimerset.c \
62 src/ztrie.c
62 src/ztrie.c \
63 src/zhttp_client.c \
64 src/zhttp_server.c \
65 src/zhttp_server_options.c \
66 src/zhttp_request.c \
67 src/zhttp_response.c
6368
6469 endif
6570
150155 api/ztimerset.api \
151156 api/ztrie.api \
152157 api/zuuid.api \
158 api/zhttp_client.api \
159 api/zhttp_server.api \
160 api/zhttp_server_options.api \
161 api/zhttp_request.api \
162 api/zhttp_response.api \
153163 api/zgossip_msg.api
154164
155165 # define custom target for all products of /src
302312 coverage: src/czmq_selftest
303313 @echo "call make clean && configure --with-gcov to enable code coverage"
304314 @exit 1
315 endif
316
317 bindings: python-bindings
318
319 python-bindings:
320 if ENABLE_BINDINGS_PYTHON
321 -( cd bindings/python && python setup.py install )
322 else
323 @echo "Python Bindings not enabled or missing setup.py... skipping"
324
305325 endif
306326
307327 # A series of tests that the codebase and recipes are pretty, easy
9292 CZMQ_PRIVATE zlistx_t *
9393 zcertstore_certs (zcertstore_t *self);
9494
95 // *** Draft callbacks, defined for internal use only ***
96 // Destroy an item
97 typedef void (zchunk_destructor_fn) (
98 void **hint);
99
100 // *** Draft method, defined for internal use only ***
101 // Create a new chunk from memory. Take ownership of the memory and calling the destructor
102 // on destroy.
103 // Caller owns return value and must destroy it when done.
104 CZMQ_PRIVATE zchunk_t *
105 zchunk_frommem (void *data, size_t size, zchunk_destructor_fn destructor, void *hint);
106
107 // *** Draft method, defined for internal use only ***
108 // Transform zchunk into a zframe that can be sent in a message.
109 // Take ownership of the chunk.
110 // Caller owns return value and must destroy it when done.
111 CZMQ_PRIVATE zframe_t *
112 zchunk_packx (zchunk_t **self_p);
113
114 // *** Draft method, defined for internal use only ***
115 // Create copy of zconfig, caller MUST free the value
116 // Create copy of config, as new zconfig object. Returns a fresh zconfig_t
117 // object. If config is null, or memory was exhausted, returns null.
118 // Caller owns return value and must destroy it when done.
119 CZMQ_PRIVATE zconfig_t *
120 zconfig_dup (zconfig_t *self);
121
95122 // *** Draft method, defined for internal use only ***
96123 // Destroy subtree (all children)
97124 CZMQ_PRIVATE void
103130 zconfig_remove (zconfig_t **self_p);
104131
105132 // *** Draft method, defined for internal use only ***
106 // Create new temporary file for writing via tmpfile. File is automaticaly
133 // Create new temporary file for writing via tmpfile. File is automatically
107134 // deleted on destroy
108135 // Caller owns return value and must destroy it when done.
109136 CZMQ_PRIVATE zfile_t *
110137 zfile_tmp (void);
138
139 // *** Draft callbacks, defined for internal use only ***
140 // Destroy an item
141 typedef void (zframe_destructor_fn) (
142 void **hint);
143
144 // *** Draft method, defined for internal use only ***
145 // Create a new frame from memory. Take ownership of the memory and calling the destructor
146 // on destroy.
147 // Caller owns return value and must destroy it when done.
148 CZMQ_PRIVATE zframe_t *
149 zframe_frommem (void *data, size_t size, zframe_destructor_fn destructor, void *hint);
111150
112151 // *** Draft method, defined for internal use only ***
113152 // Return frame routing ID, if the frame came from a ZMQ_SERVER socket.
165204 ziflist_is_ipv6 (ziflist_t *self);
166205
167206 // *** Draft method, defined for internal use only ***
207 // Serialize list to a binary frame that can be sent in a message.
208 // The packed format is compatible with the 'strings' type implemented by zproto:
209 //
210 // ; A list of strings
211 // list = list-count *longstr
212 // list-count = number-4
213 //
214 // ; Strings are always length + text contents
215 // longstr = number-4 *VCHAR
216 //
217 // ; Numbers are unsigned integers in network byte order
218 // number-4 = 4OCTET
219 // Caller owns return value and must destroy it when done.
220 CZMQ_PRIVATE zframe_t *
221 zlistx_pack (zlistx_t *self);
222
223 // *** Draft method, defined for internal use only ***
224 // Unpack binary frame into a new list. Packed data must follow format
225 // defined by zlistx_pack. List is set to autofree. An empty frame
226 // unpacks to an empty list.
227 // Caller owns return value and must destroy it when done.
228 CZMQ_PRIVATE zlistx_t *
229 zlistx_unpack (zframe_t *frame);
230
231 // *** Draft method, defined for internal use only ***
168232 // Return message routing ID, if the message came from a ZMQ_SERVER socket.
169233 // Else returns zero.
170234 CZMQ_PRIVATE uint32_t
235299 // Returns 0 if OK, -1 if failed.
236300 CZMQ_PRIVATE int
237301 zsock_leave (void *self, const char *group);
302
303 // *** Draft method, defined for internal use only ***
304 // Check whether the socket has available message to read.
305 CZMQ_PRIVATE bool
306 zsock_has_in (void *self);
238307
239308 // *** Draft method, defined for internal use only ***
240309 // De-compress and receive C string from socket, received as a message
283352 zsys_set_interrupted (void);
284353
285354 // *** Draft method, defined for internal use only ***
355 // Format a string using printf formatting, returning a freshly allocated
356 // buffer. If there was insufficient memory, returns NULL. Free the returned
357 // string using zstr_free(). The hinted version allows to optimize by using
358 // a larger starting buffer size (known to/assumed by the developer) and so
359 // avoid reallocations.
360 CZMQ_PRIVATE char *
361 zsys_sprintf_hint (int hint, const char *format, ...);
362
363 // *** Draft method, defined for internal use only ***
286364 // Configure whether to use zero copy strategy in libzmq. If the environment
287365 // variable ZSYS_ZERO_COPY_RECV is defined, that provides the default.
288366 // Otherwise the default is 1.
309387 // before testing if a filesystem object is "stable" or not.
310388 CZMQ_PRIVATE int64_t
311389 zsys_file_stable_age_msec (void);
390
391 // *** Draft method, defined for internal use only ***
392 // Print formatted string. Format is specified by variable names
393 // in Python-like format style
394 //
395 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
396 // become
397 // "key=value"
398 //
399 // Returns freshly allocated string or NULL in a case of error.
400 // Not enough memory, invalid format specifier, name not in args
401 // Caller owns return value and must destroy it when done.
402 CZMQ_PRIVATE char *
403 zsys_zprintf (const char *format, zhash_t *args);
404
405 // *** Draft method, defined for internal use only ***
406 // Return error string for given format/args combination.
407 // Caller owns return value and must destroy it when done.
408 CZMQ_PRIVATE char *
409 zsys_zprintf_error (const char *format, zhash_t *args);
410
411 // *** Draft method, defined for internal use only ***
412 // Print formatted string. Format is specified by variable names
413 // in Python-like format style
414 //
415 // "%(KEY)s=%(VALUE)s", KEY=key, VALUE=value
416 // become
417 // "key=value"
418 //
419 // Returns freshly allocated string or NULL in a case of error.
420 // Not enough memory, invalid format specifier, name not in args
421 // Caller owns return value and must destroy it when done.
422 CZMQ_PRIVATE char *
423 zsys_zplprintf (const char *format, zconfig_t *args);
424
425 // *** Draft method, defined for internal use only ***
426 // Return error string for given format/args combination.
427 // Caller owns return value and must destroy it when done.
428 CZMQ_PRIVATE char *
429 zsys_zplprintf_error (const char *format, zconfig_t *args);
312430
313431 // *** Draft constants, defined for internal use only ***
314432 #define ZGOSSIP_MSG_HELLO 1 //
1919 */
2020
2121 #include "czmq_classes.h"
22
23 #include <stdio.h>
24 #include <string.h>
2522
2623 typedef struct {
2724 const char *testname; // test name, can be called from command line this way
7067 { "zproc", zproc_test, false, true, NULL },
7168 { "ztimerset", ztimerset_test, false, true, NULL },
7269 { "ztrie", ztrie_test, false, true, NULL },
70 { "zhttp_client", zhttp_client_test, false, true, NULL },
71 { "zhttp_server", zhttp_server_test, false, true, NULL },
72 { "zhttp_server_options", zhttp_server_options_test, false, true, NULL },
73 { "zhttp_request", zhttp_request_test, false, true, NULL },
74 { "zhttp_response", zhttp_response_test, false, true, NULL },
7375 #endif // CZMQ_BUILD_DRAFT_API
7476 #ifdef CZMQ_BUILD_DRAFT_API
7577 // Tests for stable/draft private classes:
9092 {
9193 test_item_t *item;
9294 for (item = all_tests; item->testname; item++) {
93 if (strcmp (testname, item->testname) == 0)
95 if (streq (testname, item->testname))
9496 return item;
9597 }
9698 return NULL;
106108 test_item_t *item;
107109 printf ("Running czmq selftests...\n");
108110 for (item = all_tests; item->testname; item++) {
109 if (strcmp (item->testname, "private_classes") == 0)
111 if (streq (item->testname, "private_classes"))
110112 continue;
111113 if (!item->subtest)
112114 item->test (verbose);
138140 int n = 0;
139141 test_item_t *item;
140142 for (item = all_tests; item->testname; item++) {
141 if (strcmp (item->testname, "private_classes") == 0)
143 if (! streq (item->testname, "private_classes"))
142144 n++;
143145 }
144146 printf ("%d\n", n);
151153 test_item_t *test = 0;
152154 int argn;
153155 for (argn = 1; argn < argc; argn++) {
154 if (strcmp (argv [argn], "--help") == 0
155 || strcmp (argv [argn], "-h") == 0) {
156 if (streq (argv [argn], "--help")
157 || streq (argv [argn], "-h")) {
156158 puts ("czmq_selftest.c [options] ...");
157159 puts (" --verbose / -v verbose test output");
158160 puts (" --number / -n report number of tests");
161163 puts (" --continue / -c continue on exception (on Windows)");
162164 return 0;
163165 }
164 if (strcmp (argv [argn], "--verbose") == 0
165 || strcmp (argv [argn], "-v") == 0)
166 if (streq (argv [argn], "--verbose")
167 || streq (argv [argn], "-v"))
166168 verbose = true;
167169 else
168 if (strcmp (argv [argn], "--number") == 0
169 || strcmp (argv [argn], "-n") == 0) {
170 if (streq (argv [argn], "--number")
171 || streq (argv [argn], "-n")) {
170172 test_number ();
171173 return 0;
172174 }
173175 else
174 if (strcmp (argv [argn], "--list") == 0
175 || strcmp (argv [argn], "-l") == 0) {
176 if (streq (argv [argn], "--list")
177 || streq (argv [argn], "-l")) {
176178 test_list ();
177179 return 0;
178180 }
179181 else
180 if (strcmp (argv [argn], "--test") == 0
181 || strcmp (argv [argn], "-t") == 0) {
182 if (streq (argv [argn], "--test")
183 || streq (argv [argn], "-t")) {
182184 argn++;
183185 if (argn >= argc) {
184186 fprintf (stderr, "--test needs an argument\n");
191193 }
192194 }
193195 else
194 if (strcmp (argv [argn], "--continue") == 0
195 || strcmp (argv [argn], "-c") == 0) {
196 if (streq (argv [argn], "--continue")
197 || streq (argv [argn], "-c")) {
196198 #ifdef _MSC_VER
197199 // When receiving an abort signal, only print to stderr (no dialog)
198200 _set_abort_behavior (0, _WRITE_ABORT_MSG);
1111 Description: The high-level C binding for 0MQ
1212 Version: @VERSION@
1313
14 Requires:@pkgconfig_name_libzmq@
15
14 Requires.private: @pkg_config_names_private@
1615 Libs: -L${libdir} -lczmq
1716 Cflags: -I${includedir} @pkg_config_defines@
1817 Libs.private: @pkg_config_libs_private@
5454 /* Have QNX Neutrino OS */
5555 /* #undef CZMQ_HAVE_QNXNTO */
5656
57 /* Whether SOCK_CLOEXEC is defined and functioning. */
58 #define CZMQ_HAVE_SOCK_CLOEXEC 1
59
5760 /* Have Solaris OS */
5861 /* #undef CZMQ_HAVE_SOLARIS */
5962
8184 /* Define to 1 if you have the <inttypes.h> header file. */
8285 #define HAVE_INTTYPES_H 1
8386
87 /* The optional libcurl library is to be used */
88 #define HAVE_LIBCURL 1
89
8490 /* The optional liblz4 library is to be used */
8591 #define HAVE_LIBLZ4 1
8692
93 /* The optional libmicrohttpd library is to be used */
94 #define HAVE_LIBMICROHTTPD 1
95
8796 /* The optional libsystemd library is to be used */
8897 /* #undef HAVE_LIBSYSTEMD */
8998
97106 #define HAVE_MEMORY_H 1
98107
99108 /* Define to 1 if you have the `memset' function. */
100 /* #undef HAVE_MEMSET */
109 #define HAVE_MEMSET 1
101110
102111 /* Define to 1 if you have the <netinet/in.h> header file. */
103112 #define HAVE_NETINET_IN_H 1
173182 #define PACKAGE_NAME "czmq"
174183
175184 /* Define to the full name and version of this package. */
176 #define PACKAGE_STRING "czmq 4.1.1"
185 #define PACKAGE_STRING "czmq 4.2.0"
177186
178187 /* Define to the one symbol short name of this package. */
179188 #define PACKAGE_TARNAME "czmq"
182191 #define PACKAGE_URL ""
183192
184193 /* Define to the version of this package. */
185 #define PACKAGE_VERSION "4.1.1"
194 #define PACKAGE_VERSION "4.2.0"
186195
187196 /* CZMQ major version */
188197 #define PACKAGE_VERSION_MAJOR 4
189198
190199 /* CZMQ minor version */
191 #define PACKAGE_VERSION_MINOR 1
200 #define PACKAGE_VERSION_MINOR 2
192201
193202 /* CZMQ patchlevel */
194 #define PACKAGE_VERSION_PATCH 1
203 #define PACKAGE_VERSION_PATCH 0
195204
196205 /* Define as the return type of signal handlers (`int' or `void'). */
197206 #define RETSIGTYPE void
203212 #define TIME_WITH_SYS_TIME 1
204213
205214 /* Version number of package */
206 #define VERSION "4.1.1"
215 #define VERSION "4.2.0"
207216
208217 /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
209218 significant byte first (like Motorola and SPARC, unlike Intel). */
5353 /* Have QNX Neutrino OS */
5454 #undef CZMQ_HAVE_QNXNTO
5555
56 /* Whether SOCK_CLOEXEC is defined and functioning. */
57 #undef CZMQ_HAVE_SOCK_CLOEXEC
58
5659 /* Have Solaris OS */
5760 #undef CZMQ_HAVE_SOLARIS
5861
8083 /* Define to 1 if you have the <inttypes.h> header file. */
8184 #undef HAVE_INTTYPES_H
8285
86 /* The optional libcurl library is to be used */
87 #undef HAVE_LIBCURL
88
8389 /* The optional liblz4 library is to be used */
8490 #undef HAVE_LIBLZ4
91
92 /* The optional libmicrohttpd library is to be used */
93 #undef HAVE_LIBMICROHTTPD
8594
8695 /* The optional libsystemd library is to be used */
8796 #undef HAVE_LIBSYSTEMD
178178 }
179179
180180 // --------------------------------------------------------------------------
181 // Return value of named parameter, NULL if no given parameter has
182 // been specified, or special value for wich zargs_param_empty ()
183 // returns true.
184
185 const char *
186 zargs_param_lookup (zargs_t *self, const char *name) {
181 // Return current parameter name, or NULL if there are no named parameters.
182 const char *
183 zargs_get (zargs_t *self, const char *name) {
187184 assert (self);
188185 assert (name);
189 const char *ret = NULL;
190 ret = (const char*) zhash_lookup (self->parameters, name);
191 return ret;
192 }
193
194 // --------------------------------------------------------------------------
195 // Return value of named parameter(s), NULL if no given parameter has
196 // been specified, or special value for wich zargs_param_empty ()
197 // returns true.
198
199 const char *
200 zargs_param_lookupx (zargs_t *self, const char *name, ...) {
201 assert (self);
202 const char *ret = NULL;
186 const char *ret = (const char*) zhash_lookup (self->parameters, name);
187 return ret != ZARG_PARAM_EMPTY ? ret : NULL;
188 }
189
190 // --------------------------------------------------------------------------
191 // Return value of one of parameter(s) or NULL is it has no value (or was not specified)
192 CZMQ_EXPORT const char *
193 zargs_getx (zargs_t *self, const char *name, ...)
194 {
195 assert (self);
196 assert (name);
203197 va_list args;
204198 va_start (args, name);
205199 while (name) {
206 ret = zargs_param_lookup (self, name);
207 if (ret)
208 break;
209 name = va_arg (args, const char *);
200 const char *ret = zargs_get (self, name);
201 if (ret)
202 return ret;
203 name = va_arg (args, const char*);
210204 }
211205 va_end (args);
212 return ret;
213 }
214
215 // --------------------------------------------------------------------------
216
206 return NULL;
207 }
208
209 // --------------------------------------------------------------------------
210 // Returns true if named parameter was specified on command line
217211 bool
218 zargs_has_help (zargs_t *self) {
219 return zargs_param_lookupx (self, "--help", "-h", NULL) != NULL;
220 }
221
222 // --------------------------------------------------------------------------
223 // check if argument had a value or not
224
212 zargs_has (zargs_t *self, const char *name) {
213 assert (self);
214 assert (name);
215 const char *ret = (const char*) zhash_lookup (self->parameters, name);
216 return ret != NULL;
217 }
218
219 // --------------------------------------------------------------------------
220 // Returns true if named parameter(s) was specified on command line
225221 bool
226 zargs_param_empty (const char* arg) {
227 return arg && arg == ZARG_PARAM_EMPTY;
228 }
222 zargs_hasx (zargs_t *self, const char *name, ...) {
223 assert (self);
224 va_list args;
225 va_start (args, name);
226 while (name) {
227 bool ret = zargs_has (self, name);
228 if (ret)
229 return true;
230 name = va_arg (args, const char *);
231 }
232 va_end (args);
233 return NULL;
234 }
235
229236
230237 // --------------------------------------------------------------------------
231238 // Print the zargs instance
275282 assert (streq (zargs_next (self), "positional"));
276283 assert (!zargs_next (self));
277284
278 assert (zargs_param_empty (zargs_param_lookup (self, "--named1")));
279 assert (!zargs_param_empty (zargs_param_lookup (self, "-n1")));
280 assert (streq (zargs_param_lookupx (self, "--not at all", "-n1", NULL), "val1"));
281 // TODO: this does not look like an easy hack w/o allocating extra memory
282 // ???
283 //assert (streq (zargs_param_lookup (self, "--with", NULL), "value2"));
285 assert (zargs_has (self, "--named1"));
286 assert (zargs_has (self, "-n1"));
287 assert (!zargs_has (self, "--not at all"));
288
289 assert (!(zargs_get (self, "--named1")));
290 assert (streq (zargs_get (self, "-n1"), "val1"));
291
292 // common usages - test for -h/--help
293 bool has_help = zargs_hasx (self, "--help", "-h", NULL);
294 assert (!has_help);
284295
285296 zargs_destroy (&self);
286297 // @end
617617 long timeout = (long) (stop_at - zclock_mono ());
618618 if (timeout < 0)
619619 timeout = 0;
620 void *which = zpoller_wait (poller, timeout * ZMQ_POLL_MSEC);
620 void *which = zpoller_wait (poller, timeout);
621621 if (which) {
622622 assert (which == node1);
623623 char *ipaddress, *received;
359359 assert (streq (zcert_meta (cert, "name"), "John Doe"));
360360
361361 #ifdef CZMQ_BUILD_DRAFT_API
362 // DRAFT-API: Security
362363 // Iterate through certs
363364 zlistx_t *certs = zcertstore_certs(certstore);
364365 cert = (zcert_t *) zlistx_first(certs);
2727 // Structure of our class
2828
2929 struct _zchunk_t {
30 uint32_t tag; // Object tag for runtime detection
31 size_t size; // Current size of data part
32 size_t max_size; // Maximum allocated size
33 size_t consumed; // Amount already consumed
34 zdigest_t *digest; // Chunk digest, if known
35 byte *data; // Data part follows here
30 uint32_t tag; // Object tag for runtime detection
31 size_t size; // Current size of data part
32 size_t max_size; // Maximum allocated size
33 size_t consumed; // Amount already consumed
34 zdigest_t *digest; // Chunk digest, if known
35 byte *data; // Data part follows here
36 zchunk_destructor_fn *destructor; // Destructor for memory
37 void * hint; // Hint for destroying the memory
3638 };
3739
3840
5456 self->consumed = 0;
5557 self->data = (byte *) self + sizeof (zchunk_t);
5658 self->digest = NULL;
59 self->destructor = NULL;
60 self->hint = NULL;
5761 if (data) {
5862 self->size = size;
5963 memcpy (self->data, data, self->size);
7478 zchunk_t *self = *self_p;
7579 assert (zchunk_is (self));
7680 // If data was reallocated independently, free it independently
81 if (self->destructor) {
82 self->destructor (&self->hint);
83 self->destructor = NULL;
84 }
85 else
7786 if (self->data != (byte *) self + sizeof (zchunk_t))
7887 freen (self->data);
7988 self->tag = 0xDeadBeef;
8594
8695
8796 // --------------------------------------------------------------------------
97 // Create a new chunk from memory. Taking ownership of the memory and calling the destructor
98 // on destroy.
99
100 zchunk_t *
101 zchunk_frommem (void *data, size_t size, zchunk_destructor_fn destructor, void *hint) {
102 assert (data);
103
104 zchunk_t *self = (zchunk_t *) zmalloc (sizeof (zchunk_t));
105 assert (self);
106
107 self->tag = ZCHUNK_TAG;
108 self->size = size;
109 self->max_size = size;
110 self->consumed = 0;
111 self->data = (byte *)data;
112 self->digest = NULL;
113 self->destructor = destructor;
114 self->hint = hint;
115
116 return self;
117 }
118
119
120 // --------------------------------------------------------------------------
88121 // Resizes chunk max_size as requested; chunk size is set to zero
89122
90123 void
98131 self->max_size = size;
99132 self->size = 0; // TODO: this is a bit annoying, is it needed?
100133
134 // If external allocated, free it first and reallocate
135 if (self->destructor) {
136 self->destructor (&self->hint);
137 self->destructor = NULL;
138 self->data = (byte *) malloc (self->max_size);
139 }
140 else
101141 // We can't realloc the chunk itself, as the caller's reference
102142 // won't change. So we modify self->data only, depending on whether
103143 // it was already reallocated, or not.
216256 if (self->size + size > self->max_size) {
217257 self->max_size = (self->size + size) * 2;
218258
259 // If data was externally allocated, destroy it
260 if (self->destructor) {
261 byte *old_data = self->data;
262 self->data = (byte *) malloc (self->max_size);
263 memcpy (self->data, old_data, self->size);
264
265 // Release the old data
266 self->destructor (&self->hint);
267 self->destructor = NULL;
268 }
269 else
219270 // We can't realloc the chunk itself, as the caller's reference
220271 // won't change. So we modify self->data only, depending on whether
221272 // it was already reallocated, or not.
435486 assert (frame);
436487 assert (zframe_is (frame));
437488 return zchunk_new (zframe_data (frame), zframe_size (frame));
489 }
490
491
492 // --------------------------------------------------------------------------
493 // Transform zchunk into a zframe that can be sent in a message.
494 // Take ownership of the chunk.
495 // Caller owns return value and must destroy it when done.
496
497 zframe_t *
498 zchunk_packx (zchunk_t **self_p) {
499 assert (self_p);
500 assert (*self_p);
501 zchunk_t *self = *self_p;
502 *self_p = NULL;
503
504 return zframe_frommem (self->data, self->max_size, (zchunk_destructor_fn *) zchunk_destroy, self);
438505 }
439506
440507
527594
528595 // --------------------------------------------------------------------------
529596 // Self test of this class
597
598
599 static void
600 mem_destructor (void **hint) {
601 strcpy ((char*)*hint, "world");
602 }
603
530604
531605 void
532606 zchunk_test (bool verbose)
599673 zchunk_destroy (&copy);
600674 zchunk_destroy (&chunk);
601675
676 char str[] = "hello";
677 chunk = zchunk_frommem (str, 5, mem_destructor, str);
678 assert (chunk);
679 zchunk_destroy (&chunk);
680
681 // The destructor doesn't free the memory, only changing the strid,
682 // so we can check if the destructor was invoked
683 assert (streq (str, "world"));
684
685 chunk = zchunk_new ("1234567890", 10);
686 frame = zchunk_packx (&chunk);
687 assert (frame);
688 assert (chunk == NULL);
689
690 chunk = zchunk_unpack (frame);
691 assert (chunk);
692 assert (memcmp (zchunk_data (chunk), "1234567890", 10) == 0);
693 zframe_destroy (&frame);
694 zchunk_destroy (&chunk);
695
602696 #if defined (__WINDOWS__)
603697 zsys_shutdown();
604698 #endif
136136 }
137137 }
138138
139 // --------------------------------------------------------------------------
140 // Create copy of zconfig, caller MUST free the value
141 // Create copy of config, as new zconfig object. Returns a fresh zconfig_t
142 // object. If config is null, or memory was exhausted, returns null.
143 zconfig_t *
144 zconfig_dup (zconfig_t *self) {
145 if (self) {
146 zchunk_t *chunk = zconfig_chunk_save (self);
147 zconfig_t *ret = zconfig_chunk_load (chunk);
148 zchunk_destroy (&chunk);
149 return ret;
150 }
151 else
152 return NULL;
153 }
139154
140155 // --------------------------------------------------------------------------
141156 // Destroy node and subtree (all children)
11221137 assert (!c);
11231138
11241139 assert (streq (zconfig_get (config, "server/verbose", NULL), "true"));
1140
1141 zconfig_t *dup = zconfig_dup (config);
1142 assert (dup);
1143 assert (streq (zconfig_get (dup, "server/verbose", NULL), "true"));
1144 zconfig_destroy (&dup);
11251145
11261146 zconfig_destroy (&config);
11271147
172172 }
173173 #else
174174 // Remove any trailing slash
175 if (self->path [strlen (self->path) - 1] == '/')
176 self->path [strlen (self->path) - 1] = 0;
175 {
176 size_t l = strlen (self->path);
177
178 while (l > 0) {
179 if ( (l == 1) && self->path [0] == '/')
180 // The whole path is root, skip its trimming
181 break;
182
183 if (self->path [l - 1] == '/') {
184 self->path [l - 1] = '\0';
185 } else {
186 // Last char is not slash
187 break;
188 }
189 l--;
190 }
191 assert (l > 0); // path should not be empty
192 }
177193
178194 DIR *handle = opendir (self->path);
179195 if (handle) {
113113
114114 // --------------------------------------------------------------------------
115115 // Constructor
116 // Create new temporary file for writing via tmpfile. File is automaticaly
116 // Create new temporary file for writing via tmpfile. File is automatically
117117 // deleted on destroy
118118
119119 zfile_t *
3939 #ifdef ZMQ_GROUP_MAX_LENGTH
4040 char group[ZMQ_GROUP_MAX_LENGTH + 1];
4141 #endif
42 zframe_destructor_fn *destructor; // Destructor for memory
43 void * hint; // Hint for destroying the memory
4244 };
4345
4446 // --------------------------------------------------------------------------
9597 zmq_msg_close (&self->zmsg);
9698 self->tag = 0xDeadBeef;
9799 freen (self);
100
98101 *self_p = NULL;
99102 }
100103 }
108111 zframe_from (const char *string)
109112 {
110113 return zframe_new (string, strlen (string));
114 }
115
116 // --------------------------------------------------------------------------
117 // Create a new frame from memory. Taking ownership of the memory and calling the destructor
118 // on destroy.
119
120 struct zmq_msg_free_arg {
121 zframe_destructor_fn *destructor;
122 void *hint;
123 };
124
125 static void
126 zmq_msg_free (void *data, void *hint) {
127 struct zmq_msg_free_arg *arg = (struct zmq_msg_free_arg *)hint;
128 arg->destructor (&arg->hint);
129
130 freen (arg);
131 }
132
133 zframe_t *
134 zframe_frommem (void *data, size_t size, zframe_destructor_fn destructor, void *hint) {
135 assert (data);
136
137 zframe_t *self = (zframe_t *) zmalloc (sizeof (zframe_t));
138 assert (self);
139 self->tag = ZFRAME_TAG;
140 self->destructor = destructor;
141 self->hint = hint;
142
143 struct zmq_msg_free_arg *arg = (struct zmq_msg_free_arg*) zmalloc (sizeof (struct zmq_msg_free_arg));
144 arg->destructor = destructor;
145 arg->hint = hint;
146
147 // Catch heap exhaustion in this specific case
148 if (zmq_msg_init_data (&self->zmsg, data, size, zmq_msg_free, arg)) {
149 freen (arg);
150 zframe_destroy (&self);
151 return NULL;
152 }
153
154 return self;
111155 }
112156
113157
577621 // --------------------------------------------------------------------------
578622 // Selftest
579623
624 static void
625 mem_destructor (void **hint) {
626 strcpy ((char*)*hint, "world");
627 }
628
629
580630 void
581631 zframe_test (bool verbose)
582632 {
585635 zframe_t* frame;
586636
587637 // @selftest
588 // Create two PAIR sockets and connect over inproc
638 // Create two PAIR sockets and connect over TCP
589639 zsock_t *output = zsock_new (ZMQ_PAIR);
590640 assert (output);
591641 int port = zsock_bind (output, "tcp://127.0.0.1:*");
752802 zframe_destroy (&frame);
753803 #endif
754804
805 char str[] = "hello";
806 frame = zframe_frommem (str, 5, mem_destructor, str);
807 assert (frame);
808 zframe_destroy (&frame);
809
810 // The destructor doesn't free the memory, only changing the strid,
811 // so we can check if the destructor was invoked
812 assert (streq (str, "world"));
813
755814 #if defined (__WINDOWS__)
756815 zsys_shutdown();
757816 #endif
9292
9393 // TODO- project.xml?
9494 #ifdef CZMQ_BUILD_DRAFT_API
95 // DRAFT-API: Security
9596 #define CZMQ_ZGOSSIP_ZAP_DOMAIN "global"
9697 #endif
9798
122123
123124 char *public_key;
124125 char *secret_key;
125 #ifdef CZMQ_BUILD_DRAFT_API
126
127 #ifdef CZMQ_BUILD_DRAFT_API
128 // DRAFT-API: Security
126129 char *zap_domain;
127130 #endif
128131 };
187190 assert (self->tuples);
188191
189192 #ifdef CZMQ_BUILD_DRAFT_API
193 // DRAFT-API: Security
190194 self->zap_domain = strdup(CZMQ_ZGOSSIP_ZAP_DOMAIN);
191195 #endif
196
192197 return 0;
193198 }
194199
203208 zstr_free (&self->public_key);
204209 zstr_free (&self->secret_key);
205210 #ifdef CZMQ_BUILD_DRAFT_API
211 // DRAFT-API: Security
206212 zstr_free (&self->zap_domain);
207213 #endif
208214 }
210216 // Connect to a remote server
211217 static void
212218 #ifdef CZMQ_BUILD_DRAFT_API
219 // DRAFT-API: Security
213220 server_connect (server_t *self, const char *endpoint, const char *public_key)
214221 #else
215222 server_connect (server_t *self, const char *endpoint)
219226 assert (remote); // No recovery if exhausted
220227
221228 #ifdef CZMQ_BUILD_DRAFT_API
229 // DRAFT-API: Security
222230 if (public_key){
223231 zcert_t *cert = zcert_new_from_txt (self->public_key, self->secret_key);
224232 zcert_apply(cert, remote);
313321 char *endpoint = zmsg_popstr (msg);
314322 assert (endpoint);
315323 #ifdef CZMQ_BUILD_DRAFT_API
324 // DRAFT-API: Security
316325 // leaving this in here for now because if/def changes the server_connect
317326 // function args. it doesn't look like server_connect is used anywhere else
318327 // but want to leave this in until we're sure this is stable..
329338 char *key = zmsg_popstr (msg);
330339 char *value = zmsg_popstr (msg);
331340 server_accept (self, key, value);
341
332342 zstr_free (&key);
333343 zstr_free (&value);
334344 }
341351 zmsg_addstrf (reply, "%d", (int) zhashx_size (self->tuples));
342352 }
343353 #ifdef CZMQ_BUILD_DRAFT_API
354 // DRAFT-API: Security
344355 else
345356 if (streq (method, "SET PUBLICKEY")) {
346357 char *key = zmsg_popstr (msg);
362373 self->zap_domain = strdup(value);
363374 assert (self->zap_domain);
364375 zstr_free (&value);
376 }
377 #endif
378
379 #ifdef CZMQ_BUILD_DRAFT_API
380 // DRAFT-API: TTL
381 else
382 if (streq (method, "UNPUBLISH")) {
383 char *key = zmsg_popstr (msg);
384 assert (key);
385 tuple_t *tuple = (tuple_t *) zhashx_first (self->tuples);
386 assert(tuple);
387 if (tuple) {
388 zhashx_delete(self->tuples, key);
389 }
390 zstr_free (&key);
365391 }
366392 #endif
367393 else
542568
543569 zactor_t *alpha = zactor_new (zgossip, "alpha");
544570 assert (alpha);
571
572 if (verbose)
573 zstr_send (alpha, "VERBOSE");
574
545575 zstr_sendx (alpha, "CONNECT", "inproc://base", NULL);
576
546577 zstr_sendx (alpha, "PUBLISH", "inproc://alpha-1", "service1", NULL);
547578 zstr_sendx (alpha, "PUBLISH", "inproc://alpha-2", "service2", NULL);
548579
549580 zactor_t *beta = zactor_new (zgossip, "beta");
550581 assert (beta);
582
583 if (verbose)
584 zstr_send (beta, "VERBOSE");
585
551586 zstr_sendx (beta, "CONNECT", "inproc://base", NULL);
587
552588 zstr_sendx (beta, "PUBLISH", "inproc://beta-1", "service1", NULL);
553589 zstr_sendx (beta, "PUBLISH", "inproc://beta-2", "service2", NULL);
554590
559595 char *command, *status, *key, *value;
560596
561597 zstr_recvx (alpha, &command, &key, &value, NULL);
598
562599 assert (streq (command, "DELIVER"));
563600 assert (streq (key, "inproc://alpha-1"));
564601 assert (streq (value, "service1"));
602
565603 zstr_free (&command);
566604 zstr_free (&key);
567605 zstr_free (&value);
601639 zactor_destroy (&beta);
602640
603641 #ifdef CZMQ_BUILD_DRAFT_API
642 // DRAFT-API: Security
604643 // curve
605644 if (zsys_has_curve()) {
606645 if (verbose)
787787 zsock_set_plain_server (self->router, 1);
788788 }
789789 #ifdef CZMQ_BUILD_DRAFT_API
790 // DRAFT-API: Security
790791 // TODO- zproto
791792 // https://github.com/zeromq/zproto/blob/master/src/zproto_server_c.gsl#L883
792793 else
842843 char *endpoint = zmsg_popstr (msg);
843844
844845 #ifdef CZMQ_BUILD_DRAFT_API
846 // DRAFT-API: Security
845847 // TODO- expose self->router to application context ?
846848 // Add secret|public|zap to gsl(?)
847849 // move this block to custom server function when both keys are present
2424 // stable builds by default. If you use this in applications, please ask
2525 // for it to be pushed to stable state. Use --enable-drafts to enable.
2626 #ifdef CZMQ_BUILD_DRAFT_API
27 #define ZGOSSIP_MSG_HELLO 1 //
28 #define ZGOSSIP_MSG_PUBLISH 2 //
29 #define ZGOSSIP_MSG_PING 3 //
30 #define ZGOSSIP_MSG_PONG 4 //
31 #define ZGOSSIP_MSG_INVALID 5 //
27 #define ZGOSSIP_MSG_HELLO 1 //
28 #define ZGOSSIP_MSG_PUBLISH 2 //
29 #define ZGOSSIP_MSG_PING 3 //
30 #define ZGOSSIP_MSG_PONG 4 //
31 #define ZGOSSIP_MSG_INVALID 5 //
3232
3333 // *** Draft method, for development use, may change without warning ***
3434 // Create a new empty zgossip_msg
684684 zframe_t *frame = zframe_new (NULL, frame_size);
685685 if (!frame)
686686 return NULL;
687
687688 byte *needle = zframe_data (frame);
689
688690 // Store size as number-4
689691 *(uint32_t *) needle = htonl ((uint32_t) self->size);
690692 needle += 4;
692694 item_t *item = self->items [index];
693695 while (item) {
694696 // Store key as string
695 *needle++ = (byte) strlen ((char *) item->key);
696 memcpy (needle, item->key, strlen ((char *) item->key));
697 needle += strlen ((char *) item->key);
697 size_t length = strlen ((char *) item->key);
698 *needle++ = (byte) length;
699 memcpy (needle, item->key, length);
700 needle += length;
698701
699702 // Store value as longstr
700 size_t length = strlen ((char *) item->value);
701 *(uint32_t *) needle = htonl ((u_long) length);
703 length = strlen ((char *) item->value);
704 uint32_t serialize = htonl ((uint32_t) length);
705 memcpy (needle, &serialize, 4);
702706 needle += 4;
703 memcpy (needle, (char *) item->value, strlen ((char *) item->value));
704 needle += strlen ((char *) item->value);
707 memcpy (needle, (char *) item->value, length);
708 needle += length;
705709 item = item->next;
706710 }
707711 }
812812 item_t *item = self->items [index];
813813 while (item) {
814814 // Store key as string
815 *needle++ = (byte) strlen ((char *) item->key);
816 memcpy (needle, item->key, strlen ((char *) item->key));
817 needle += strlen ((char *) item->key);
815 size_t length = strlen ((char *) item->key);
816 *needle++ = (byte) length;
817 memcpy (needle, item->key, length);
818 needle += length;
818819
819820 // Store value as longstr
820 size_t lenth = strlen (values [vindex]);
821 *(uint32_t *) needle = htonl ((u_long) lenth);
821 length = strlen (values [vindex]);
822 uint32_t serialize = htonl ((u_long) length);
823 memcpy (needle, &serialize, 4);
822824 needle += 4;
823 memcpy (needle, (char *) values [vindex], strlen ((char *) values [vindex]));
824 needle += strlen ((char *) values [vindex]);
825 memcpy (needle, values [vindex], length);
826 needle += length;
825827 item = item->next;
826828
827829 // Destroy serialized value
876878 if (!self)
877879 return NULL;
878880
881 // Hash will free values in destructor
882 zhashx_set_destructor (self, (zhashx_destructor_fn *) zstr_free);
883
879884 assert (frame);
880885 if (zframe_size (frame) < 4)
881886 return self; // Arguable...
923928 }
924929 }
925930 }
926 // Hash will free values in destructor
927 if (self) {
928 zhashx_set_destructor (self, (zhashx_destructor_fn *) zstr_free);
931
932 if (self)
929933 zhashx_set_duplicator (self, (zhashx_duplicator_fn *) strdup);
930 }
931934
932935 return self;
933936 }
0 /* =========================================================================
1 zhttp_client - provides a simple http client
2
3 Copyright (c) the Contributors as noted in the AUTHORS file.
4 This file is part of CZMQ, the high-level C binding for 0MQ:
5 http://czmq.zeromq.org.
6
7 This Source Code Form is subject to the terms of the Mozilla Public
8 License, v. 2.0. If a copy of the MPL was not distributed with this
9 file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 =========================================================================
11 */
12
13 /*
14 @header
15 zhttp_client - provides a simple http client
16 @discuss
17 @end
18 */
19
20 #include "czmq_classes.h"
21
22 #ifdef HAVE_LIBCURL
23
24 #include <curl/curl.h>
25
26 #endif
27
28 #ifdef HAVE_LIBCURL
29
30 typedef struct {
31 CURL *curl;
32 void *arg;
33 void *arg2;
34
35 char *request_content;
36 bool free_request_content;
37
38 struct curl_slist *request_headers;
39
40 char *response_content;
41 size_t response_content_length;
42 zhash_t *response_headers;
43
44 } http_request_t;
45
46 size_t header_callback(char *buffer, size_t size, size_t nitems, void *userp) {
47 http_request_t *request = (http_request_t *) userp;
48
49 // TODO: support multiline headers
50
51 char *colon = buffer;
52 const char *end = buffer + (size * nitems);
53
54 while (colon != end) {
55 if (*colon == ':') {
56 *colon = '\0';
57 colon++;
58 char* key = buffer;
59 char* value = colon;
60 char *value_end = colon;
61
62 // Find the end of line and set it to null terminated
63 while (*value_end != '\r' && *value_end != '\n' && value_end != end) {
64 value_end++;
65 }
66 *value_end = '\0';
67
68 // Skip any whitespace at the beginning of the value
69 while (*value == ' ' || *value == '\t') {
70 if (value == value_end)
71 break;
72 value++;
73 }
74
75 zhash_insert (request->response_headers, key, value);
76
77 break;
78 }
79
80 colon++;
81 }
82
83 return size * nitems;
84 }
85
86 size_t write_data (void *buffer, size_t size, size_t nmemb, void *userp) {
87 http_request_t *request = (http_request_t *) userp;
88
89 size_t offset = 0;
90
91 if (request->response_content == NULL) {
92 request->response_content_length = nmemb;
93 request->response_content = (char*)malloc (request->response_content_length + 1);
94 }
95 else {
96 offset = request->response_content_length;
97 request->response_content_length += nmemb;
98 request->response_content = (char*) realloc (request->response_content, request->response_content_length + 1);
99 }
100
101 memcpy (request->response_content + offset, buffer, nmemb);
102 request->response_content[request->response_content_length] = '\0';
103
104 return nmemb;
105 }
106
107 static struct curl_slist *zhash_to_slist (zhash_t *headers) {
108 struct curl_slist *slist = NULL;
109
110 char *value = (char*) zhash_first (headers);
111
112 while (value) {
113 const char *key = zhash_cursor (headers);
114 char *header = zsys_sprintf ("%s: %s", key, value); // TODO: avoid allocation here
115 slist = curl_slist_append (slist, header);
116 zstr_free (&header);
117
118 value = (char *) zhash_next (headers);
119 }
120
121 return slist;
122 }
123
124 static void curl_destructor (CURL **curlp) {
125 CURL *curl = *curlp;
126 http_request_t *request;
127 curl_easy_getinfo (curl, CURLINFO_PRIVATE, &request);
128
129 if (request->free_request_content)
130 zstr_free (&request->request_content);
131
132 // Those will usually be null, as we are passing the pointer to the caller
133 zstr_free (&request->response_content);
134 zhash_destroy (&request->response_headers);
135
136 curl_slist_free_all (request->request_headers);
137 curl_easy_cleanup (curl);
138 free (request);
139 *curlp = NULL;
140 }
141
142 static void zhttp_client_actor (zsock_t *pipe, void *args) {
143 curl_global_init (CURL_GLOBAL_ALL);
144 CURLM *multi = curl_multi_init ();
145 CURLSH *share = curl_share_init ();
146 curl_share_setopt (share, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
147 curl_share_setopt (share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
148 curl_share_setopt (share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
149
150 long verbose = (*(bool *) args) ? 1L : 0L;
151 CURLMcode code;
152
153 SOCKET pipefd = zsock_fd (pipe);
154 struct curl_waitfd waitfd = {pipefd, CURL_WAIT_POLLIN};
155
156 // List to hold pending curl handles, in case we are destroy the client
157 // while request are inprogress
158 zlistx_t *pending_handles = zlistx_new ();
159 zlistx_set_destructor (pending_handles, (zlistx_destructor_fn *) curl_destructor);
160
161 zsock_signal (pipe, 0);
162
163 bool terminated = false;
164 while (!terminated) {
165 if (!zsock_has_in (pipe)) {
166 code = curl_multi_wait (multi, &waitfd, 1, 1000, NULL);
167 assert (code == CURLM_OK);
168 }
169
170 if (zsock_has_in (pipe)) {
171 char *command = zstr_recv (pipe);
172 if (!command)
173 break; // Interrupted
174
175 // All actors must handle $TERM in this way
176 if (streq (command, "$TERM"))
177 terminated = true;
178 else {
179 int timeout;
180 void *arg;
181 void *arg2;
182 char *url;
183 zhash_t *headers;
184 byte free_content;
185 char* content;
186
187 int rc = zsock_brecv (pipe, "4ppSp1p", &timeout, &arg, &arg2,
188 &url, &headers, &free_content, &content);
189 assert (rc == 0);
190
191 struct curl_slist *curl_headers = zhash_to_slist (headers);
192
193 CURL *curl = curl_easy_init ();
194 zlistx_add_end (pending_handles, curl);
195 http_request_t *request = (http_request_t *) zmalloc (sizeof (http_request_t));
196 assert (request);
197
198 request->arg = arg;
199 request->arg2 = arg2;
200 request->curl = curl;
201 request->request_headers = curl_headers;
202 request->request_content = content;
203 request->free_request_content = free_content;
204 request->response_headers = zhash_new ();
205 zhash_autofree (request->response_headers);
206
207 curl_easy_setopt (curl, CURLOPT_SHARE, share);
208 curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, (long)timeout);
209 curl_easy_setopt (curl, CURLOPT_VERBOSE, verbose);
210 curl_easy_setopt (curl, CURLOPT_HTTPHEADER, curl_headers);
211 curl_easy_setopt (curl, CURLOPT_URL, url);
212 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, write_data);
213 curl_easy_setopt (curl, CURLOPT_WRITEDATA, request);
214 curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION, header_callback);
215 curl_easy_setopt (curl, CURLOPT_HEADERDATA, request);
216 curl_easy_setopt (curl, CURLOPT_PRIVATE, request);
217
218 if (streq (command, "POST")) {
219 curl_easy_setopt (curl, CURLOPT_POSTFIELDS, content);
220 curl_easy_setopt (curl, CURLOPT_POSTFIELDSIZE, content ? strlen (content) : 0);
221 }
222
223 code = curl_multi_add_handle (multi, curl);
224 assert (code == CURLM_OK);
225 zhash_destroy (&headers);
226 zstr_free (&url);
227
228 }
229 zstr_free (&command);
230 }
231
232 int still_running;
233 code = curl_multi_perform (multi, &still_running);
234 assert (code == CURLM_OK);
235
236 int msgq = 0;
237 struct CURLMsg *msg = curl_multi_info_read (multi, &msgq);
238
239 while (msg) {
240 if (msg->msg == CURLMSG_DONE) {
241 CURL *curl = msg->easy_handle;
242 http_request_t *request;
243 curl_easy_getinfo (curl, CURLINFO_PRIVATE, &request);
244
245 long response_code_long;
246 curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &response_code_long);
247 uint32_t response_code = (uint32_t) response_code_long;
248
249 uint32_t result = 0;
250
251 // TODO: more mappings
252 switch (msg->data.result) {
253 case CURLE_OK:
254 result = 0;
255 break;
256 case CURLE_OPERATION_TIMEDOUT:
257 result = ETIMEDOUT;
258 break;
259 default:
260 result = msg->data.result;
261 }
262
263 int rc = zsock_bsend (pipe, "4pp4pp", result, request->arg, request->arg2, response_code, request->response_headers, request->response_content);
264 assert (rc == 0);
265
266 request->response_headers = NULL;
267 request->response_content = NULL;
268
269 curl_multi_remove_handle (multi, curl);
270
271 // Remove curl from the pending handles and delete it
272 void *handle = zlistx_find (pending_handles, curl);
273 assert (handle);
274 rc = zlistx_delete (pending_handles, handle);
275 assert (rc == 0);
276 }
277
278 msg = curl_multi_info_read (multi, &msgq);
279 }
280 }
281
282 zlistx_destroy (&pending_handles);
283 curl_share_cleanup (share);
284 curl_multi_cleanup (multi);
285 curl_global_cleanup ();
286 }
287
288 #endif
289
290 // --------------------------------------------------------------------------
291 // Create a new zhttp_client
292
293 zhttp_client_t *
294 zhttp_client_new (bool verbose) {
295 zhttp_client_t *self = NULL;
296 #ifdef HAVE_LIBCURL
297 self = (zhttp_client_t *) zactor_new (zhttp_client_actor, &verbose);
298 #endif
299 return self;
300 }
301
302
303 // --------------------------------------------------------------------------
304 // Destroy the zhttp_client
305
306 void
307 zhttp_client_destroy (zhttp_client_t **self_p) {
308 zactor_destroy ((zactor_t **) self_p);
309 }
310
311
312 // --------------------------------------------------------------------------
313 // Self test of this class
314
315
316 void
317 zhttp_client_test (bool verbose) {
318 #if defined(HAVE_LIBCURL) && defined(HAVE_LIBMICROHTTPD)
319 printf (" * zhttp_client: ");
320
321 int port = 40000 + (randof (10000));
322 zhttp_server_options_t *options = zhttp_server_options_new ();
323 zhttp_server_options_set_port (options, port);
324
325 zhttp_server_t *server = zhttp_server_new (options);
326 assert (server);
327
328 char url[256];
329 snprintf (url, 255, "http://127.0.0.1:%d", port);
330
331 // @selftest
332 zhttp_client_t *self = zhttp_client_new (verbose);
333 assert (self);
334
335 zhttp_request_t* request = zhttp_request_new ();
336 zhttp_request_set_url (request, url);
337 zhttp_request_set_method (request, "GET");
338 int rc = zhttp_request_send (request, self, /*timeout*/ 10000, /* user args*/ NULL, NULL);
339 assert (rc == 0);
340
341 // @end
342
343 zsock_t *worker = zsock_new_dealer (zhttp_server_options_backend_address (options));
344 zhttp_request_t *server_request = zhttp_request_new ();
345 void *connection = zhttp_request_recv (server_request, worker);
346 assert (connection);
347
348 zhttp_response_t *server_response = zhttp_response_new ();
349 zhttp_response_set_content_const (server_response, "Hello World!");
350 zhttp_response_set_status_code (server_response, 200);
351 rc = zhttp_response_send (server_response, worker, &connection);
352 assert (rc == 0);
353
354 // @selftest
355 void *user_arg;
356 void *user_arg2;
357 zhttp_response_t* response = zhttp_response_new ();
358 rc = zhttp_response_recv (response, self, &user_arg, &user_arg2);
359 assert (rc == 0);
360 assert (streq (zhttp_response_content (response), "Hello World!"));
361
362 zhttp_client_destroy (&self);
363 zhttp_request_destroy (&request);
364 zhttp_response_destroy (&response);
365
366 // @end
367
368 zhttp_request_destroy (&server_request);
369 zhttp_response_destroy (&server_response);
370 zsock_destroy (&worker);
371 zhttp_server_destroy (&server);
372 zhttp_server_options_destroy (&options);
373
374 printf ("OK\n");
375 #endif
376 }
0 /* =========================================================================
1 zhttp_request - zhttp server request.
2 Class can be reused.
3
4 Copyright (c) the Contributors as noted in the AUTHORS file.
5
6 This Source Code Form is subject to the terms of the Mozilla Public
7 License, v. 2.0. If a copy of the MPL was not distributed with this
8 file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 =========================================================================
10 */
11
12 /*
13 @header
14 zhttp_request - zhttp server request.
15 Class can be reused.
16 @discuss
17 @end
18 */
19
20 #include "czmq_classes.h"
21
22 // Structure of our class
23
24 struct _zhttp_request_t {
25 char *url;
26 char method[256];
27 zhash_t *headers;
28 char* content;
29 bool free_content;
30 };
31
32
33 // --------------------------------------------------------------------------
34 // Create a new zhttp_request
35
36 zhttp_request_t *
37 zhttp_request_new (void)
38 {
39 zhttp_request_t *self = (zhttp_request_t *) zmalloc (sizeof (zhttp_request_t));
40 assert (self);
41
42 self->headers = zhash_new ();
43 zhash_autofree (self->headers);
44 self->url = strdup ("/");
45 strcpy (self->method, "GET");
46 self->content = NULL;
47 self->free_content = false;
48
49 return self;
50 }
51
52
53 // --------------------------------------------------------------------------
54 // Destroy the zhttp_request
55
56 void
57 zhttp_request_destroy (zhttp_request_t **self_p)
58 {
59 assert (self_p);
60 if (*self_p) {
61 zhttp_request_t *self = *self_p;
62
63 zstr_free (&self->url);
64 zhash_destroy (&self->headers);
65
66 if (self->free_content)
67 zstr_free (&self->content);
68
69 self->content = NULL;
70 self->free_content = false;
71
72 // Free object itself
73 free (self);
74 *self_p = NULL;
75 }
76 }
77
78
79 void *
80 zhttp_request_recv (zhttp_request_t *self, zsock_t *sock) {
81 assert (self);
82
83 zstr_free (&self->url);
84 zhash_destroy (&self->headers);
85
86 if (self->free_content) {
87 zstr_free (&self->content);
88 self->free_content = false;
89 }
90
91 char *method;
92 void* connection;
93
94 int rc = zsock_brecv (sock, "psSpp", &connection, &method, &self->url,
95 &self->headers, &self->content);
96
97 if (rc == -1) {
98 self->headers = zhash_new ();
99 zhash_autofree (self->headers);
100 self->url = strdup ("/");
101
102 return NULL;
103 }
104
105 self->free_content = self->content != NULL;
106 strcpy (self->method, method);
107
108 return connection;
109 }
110
111 int
112 zhttp_request_send (zhttp_request_t *self, zhttp_client_t *client, int timeout, void *arg, void *arg2) {
113 assert (self);
114 assert (client);
115
116 int rc = zstr_sendm (client, self->method);
117 if (rc == -1)
118 return -1;
119
120 zsock_bsend (client, "4ppSp1p", timeout, arg, arg2, self->url,
121 self->headers, self->free_content ? (byte)1 : (byte)0, self->content);
122
123 self->headers = zhash_new ();
124 zhash_autofree (self->headers);
125 self->content = NULL;
126 self->free_content = false;
127
128 return 0;
129 }
130
131
132 const char *
133 zhttp_request_method (zhttp_request_t *self) {
134 assert (self);
135 return self->method;
136 }
137
138
139 void
140 zhttp_request_set_method (zhttp_request_t *self, const char *method) {
141 assert (self);
142 strcpy (self->method, method);
143 }
144
145
146 const char *
147 zhttp_request_url (zhttp_request_t *self) {
148 assert (self);
149 return self->url;
150 }
151
152
153 void
154 zhttp_request_set_url (zhttp_request_t *self, const char *url) {
155 assert (self);
156 zstr_free (&self->url);
157 self->url = strdup (url);
158 }
159
160
161 const char *
162 zhttp_request_content_type (zhttp_request_t *self) {
163 assert (self);
164
165 return (const char*)zhash_lookup (self->headers, "Content-Type");
166 }
167
168 void
169 zhttp_request_set_content_type (zhttp_request_t *self, const char *content_type) {
170 assert (self);
171 zhash_insert (self->headers, "Content-Type", (char*) content_type);
172 }
173
174
175 size_t
176 zhttp_request_content_length (zhttp_request_t *self) {
177 assert (self);
178
179 if (!self->content)
180 return 0;
181
182 return strlen (self->content);
183 }
184
185
186 zhash_t *
187 zhttp_request_headers (zhttp_request_t *self) {
188 assert (self);
189
190 return self->headers;
191 }
192
193
194 const char *
195 zhttp_request_content (zhttp_request_t *self) {
196 assert (self);
197
198 return self->content;
199 }
200
201
202 char *
203 zhttp_request_get_content (zhttp_request_t *self) {
204 assert (self);
205
206 if (self->content == NULL)
207 return NULL;
208
209 char* content = self->content;
210
211 // If the we don't own the content we can move the ownership, so we must duplicate the content
212 if (!self->free_content)
213 content = strdup (content);
214
215 self->content = NULL;
216 self->free_content = false;
217
218 return content;
219 }
220
221
222 void
223 zhttp_request_set_content (zhttp_request_t *self, char **content) {
224 assert (self);
225
226 if (self->free_content)
227 zstr_free (&self->content);
228
229 self->free_content = true;
230 self->content = *content;
231 *content = NULL;
232 }
233
234
235 void
236 zhttp_request_set_content_const (zhttp_request_t *self, const char *content) {
237 assert (self);
238
239 if (self->free_content)
240 zstr_free (&self->content);
241
242 self->free_content = false;
243 self->content = (char*) content;
244 }
245
246
247 void
248 zhttp_request_reset_content (zhttp_request_t *self) {
249 assert (self);
250
251 if (self->free_content)
252 zstr_free (&self->content);
253
254 self->free_content = false;
255 self->content = NULL;
256 }
257
258 bool
259 zhttp_request_match (zhttp_request_t *self, const char *method, const char *match, ...) {
260 if (strneq (method, self->method))
261 return false;
262
263 char* request_needle = self->url;
264 const char* match_needle = match;
265
266 // First pass, no allocation, just checking if a match
267 while (*request_needle != '\0' && *request_needle != '?' && *match_needle != '\0') {
268
269 // Slashes should always match, no wildcard for them
270 if (*request_needle == '/' && *match_needle != '/')
271 return false;
272
273 if (*match_needle == '%') {
274 match_needle++;
275
276 if (*match_needle == '%') {
277 if (*match_needle == *request_needle)
278 return false;
279
280 match_needle++;
281 request_needle++;
282 continue;
283 } else if (*match_needle == 's') {
284 match_needle++;
285
286 // Match until / ? or end of string
287 while (*request_needle != '/' && *request_needle != '?' && *request_needle != '\0') {
288 request_needle++;
289 }
290
291 continue;
292 }
293
294 zsys_error ("zhttp_request: invalid path element '%c'");
295 assert (false);
296 }
297
298 if (*match_needle != *request_needle) {
299 return false;
300 }
301
302 match_needle++;
303 request_needle++;
304 }
305
306 // The two strings didn't end at the same offset
307 if ((*request_needle != '\0' && *request_needle != '?') || *match_needle != '\0')
308 return false;
309
310 va_list argptr;
311 va_start (argptr, match);
312
313 match_needle = match;
314 request_needle = self->url;
315
316 // another pass, now with allocating the strings, we can skip all the validity checks
317 while (*match_needle != '\0') {
318 if (*match_needle == '%' && *(match_needle + 1) == '%') {
319 request_needle++;
320 match_needle += 2;
321 }
322 else
323 if (*match_needle == '%' && *(match_needle + 1) == 's') {
324 char* value_start = request_needle;
325
326 while (*request_needle != '/' && *request_needle != '?' && *request_needle != '\0') {
327 request_needle++;
328 }
329
330 char ** arg = va_arg (argptr, char **);
331 if (arg) {
332 *arg = value_start;
333 *request_needle = '\0';
334 }
335
336 match_needle += 2;
337 }
338 else {
339 match_needle++;
340 request_needle++;
341 }
342 }
343
344 va_end (argptr);
345
346 return true;
347 }
348
349
350 void
351 zhttp_request_test (bool verbose) {
352 printf (" * zhttp_request: ");
353
354 zhttp_request_t *request = zhttp_request_new ();
355
356 zhttp_request_set_method (request, "GET");
357 zhttp_request_set_url (request, "/send/hello/world");
358
359 char *s1 = NULL;
360 char *s2 = NULL;
361 bool is_matched = zhttp_request_match (request, "GET", "/send/%s/%s", &s1, &s2);
362 assert (is_matched);
363
364 zhttp_request_set_url (request, "/send/hello/world");
365 is_matched = zhttp_request_match (request, "GET", "/send/hello/world");
366 assert (is_matched);
367
368 zhttp_request_set_url (request, "/send/hello/world");
369 is_matched = zhttp_request_match (request, "POST", "/send/hello/world");
370 assert (!is_matched);
371
372 s1 = NULL;
373 s2 = NULL;
374 zhttp_request_set_url (request, "/send/hello/world");
375 is_matched = zhttp_request_match (request, "GET", "/xsend/%s/%s", &s1, &s2);
376 assert (!is_matched);
377 assert (s1 == NULL);
378 assert (s2 == NULL);
379
380 zhttp_request_set_url (request, "/send/hello/world");
381 is_matched = zhttp_request_match (request, "GET", "/end/%s/%s", &s1, &s2);
382 assert (!is_matched);
383 assert (s1 == NULL);
384 assert (s2 == NULL);
385
386 zhttp_request_destroy (&request);
387
388 printf ("OK\n");
389 }
0 /* =========================================================================
1 zhttp_response - zhttp server request.
2 Class can be reused.
3
4 Copyright (c) the Contributors as noted in the AUTHORS file.
5
6 This Source Code Form is subject to the terms of the Mozilla Public
7 License, v. 2.0. If a copy of the MPL was not distributed with this
8 file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 =========================================================================
10 */
11
12 /*
13 @header
14 zhttp_response - zhttp server request.
15 Class can be reused.
16 @discuss
17 @end
18 */
19
20 #include "czmq_classes.h"
21
22 // Structure of our class
23
24 struct _zhttp_response_t {
25 uint32_t status_code;
26 zhash_t *headers;
27 char *content;
28 bool free_content;
29 };
30
31
32 // --------------------------------------------------------------------------
33 // Create a new zhttp_response
34
35 zhttp_response_t *
36 zhttp_response_new (void)
37 {
38 zhttp_response_t *self = (zhttp_response_t *) zmalloc (sizeof (zhttp_response_t));
39 assert (self);
40
41 self->headers = zhash_new ();
42 zhash_autofree (self->headers);
43 self->status_code = 200;
44 self->content = NULL;
45 self->free_content = false;
46
47 return self;
48 }
49
50
51 // --------------------------------------------------------------------------
52 // Destroy the zhttp_response
53
54 void
55 zhttp_response_destroy (zhttp_response_t **self_p)
56 {
57 assert (self_p);
58 if (*self_p) {
59 zhttp_response_t *self = *self_p;
60 zhash_destroy (&self->headers);
61
62 if (self->free_content)
63 zstr_free (&self->content);
64
65 self->content = NULL;
66 self->free_content = false;
67
68 // Free object itself
69 free (self);
70 *self_p = NULL;
71 }
72 }
73
74 int
75 zhttp_response_send (zhttp_response_t *self, zsock_t *sock, void **connection_p) {
76 assert (self);
77 assert (connection_p);
78 assert (*connection_p);
79
80 int rc = zsock_bsend (sock, "p4p1p",
81 *connection_p, self->status_code, self->headers, self->free_content ? (byte)1 : (byte)0,
82 self->content);
83
84 if (rc == -1)
85 return rc;
86
87 *connection_p = NULL;
88 self->headers = zhash_new ();
89 zhash_autofree (self->headers);
90 self->content = NULL;
91 self->free_content = false;
92
93 return 0;
94 }
95
96
97 int
98 zhttp_response_recv (zhttp_response_t *self, zhttp_client_t *client, void** arg_p, void** arg2_p) {
99 assert (self);
100 assert (client);
101
102 zhash_destroy (&self->headers);
103 if (self->free_content) {
104 zstr_free (&self->content);
105 self->free_content = false;
106 }
107
108 uint32_t result;
109 int rc = zsock_brecv (client, "4pp4pp", &result, arg_p, arg2_p, &self->status_code, &self->headers, &self->content);
110
111 if (rc == -1) {
112 self->headers = zhash_new ();
113 zhash_autofree (self->headers);
114
115 return -1;
116 }
117
118 self->free_content = self->content != NULL;
119
120 if (result != 0) {
121 self->headers = zhash_new ();
122 zhash_autofree (self->headers);
123
124 errno = result;
125 return -1;
126 }
127
128 return 0;
129 }
130
131 const char *
132 zhttp_response_content_type (zhttp_response_t *self) {
133 assert (self);
134
135 return (const char*)zhash_lookup (self->headers, "Content-Type");
136 }
137
138
139 void
140 zhttp_response_set_content_type (zhttp_response_t *self, const char* content_type) {
141 assert (self);
142 zhash_insert (self->headers, "Content-Type", (void*) content_type);
143 }
144
145
146 uint32_t
147 zhttp_response_status_code (zhttp_response_t *self) {
148 assert (self);
149
150 return self->status_code;
151 }
152
153
154 void
155 zhttp_response_set_status_code (zhttp_response_t *self, uint32_t status_code) {
156 assert (self);
157
158 self->status_code = status_code;
159 }
160
161
162 zhash_t *
163 zhttp_response_headers (zhttp_response_t *self) {
164 assert (self);
165
166 return self->headers;
167 }
168
169
170 size_t
171 zhttp_response_content_length (zhttp_response_t *self) {
172 assert (self);
173
174 if (!self->content)
175 return 0;
176
177 return strlen (self->content);
178 }
179
180 const char *
181 zhttp_response_content (zhttp_response_t *self) {
182 assert (self);
183
184 return self->content;
185 }
186
187
188 char *
189 zhttp_response_get_content (zhttp_response_t *self) {
190 assert (self);
191
192
193 if (self->content == NULL)
194 return NULL;
195
196 char* content = self->content;
197
198 // If the we don't own the content we can move the ownership, so we must duplicate the content
199 if (!self->free_content)
200 content = strdup (content);
201
202 self->content = NULL;
203 self->free_content = false;
204
205 return content;
206 }
207
208 void
209 zhttp_response_set_content (zhttp_response_t *self, char **content) {
210 assert (self);
211 assert (content);
212
213 if (self->free_content)
214 zstr_free (&self->content);
215
216 self->free_content = true;
217 self->content = *content;
218 *content = NULL;
219 }
220
221
222 void
223 zhttp_response_set_content_const (zhttp_response_t *self, const char *content) {
224 assert (self);
225 assert (content);
226
227 if (self->free_content)
228 zstr_free (&self->content);
229
230 self->free_content = false;
231 self->content = (char*) content;
232 }
233
234
235 void
236 zhttp_response_reset_content (zhttp_response_t *self) {
237 assert (self);
238
239 if (self->free_content)
240 zstr_free (&self->content);
241
242 self->free_content = false;
243 self->content = NULL;
244 }
245
246 void
247 zhttp_response_test (bool verbose) {
248
249 }
0 /* =========================================================================
1 zhttp_server -
2
3 Copyright (c) the Contributors as noted in the AUTHORS file.
4
5 This Source Code Form is subject to the terms of the Mozilla Public
6 License, v. 2.0. If a copy of the MPL was not distributed with this
7 file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 =========================================================================
9 */
10
11 /*
12 @header
13 zhttp_server -
14 @discuss
15 @end
16 */
17
18 #include "czmq_classes.h"
19
20 #ifdef HAVE_LIBMICROHTTPD
21 #include <microhttpd.h>
22 #endif
23
24 #ifdef HAVE_LIBMICROHTTPD
25
26 typedef struct {
27 char* content;
28 size_t content_length;
29 zhash_t *headers;
30 bool suspended;
31 } request_t;
32
33 typedef struct {
34 zsock_t *pipe; // Actor command pipe
35 bool terminated; // Did caller ask us to quit?
36 bool verbose; // Verbose logging enabled?
37
38 zhttp_server_options_t *options;
39 zsock_t *backend;
40 struct MHD_Daemon *daemon;
41 zframe_t *empty_frame;
42 zlistx_t* pending_connections;
43 } server_actor_t;
44
45 static int
46 s_handle_request (
47 server_actor_t *self,
48 struct MHD_Connection *mhd_connection,
49 const char *url,
50 const char *method,
51 const char *version,
52 const char *upload_data,
53 size_t *upload_data_size,
54 request_t **request_p);
55
56 static void
57 s_handle_request_completed (
58 server_actor_t *self,
59 struct MHD_Connection *mhd_connection,
60 request_t **request_p,
61 enum MHD_RequestTerminationCode toe);
62
63 static void
64 server_actor (zsock_t *pipe, void *args);
65
66
67 static request_t*
68 request_new () {
69 request_t *self = (request_t*)zmalloc (sizeof (request_t));
70 assert (self);
71
72 self->headers = zhash_new ();
73 zhash_autofree (self->headers);
74
75 return self;
76 }
77
78 static void
79 request_destroy (request_t **self_p) {
80 request_t * self= *self_p;
81
82 if (self) {
83 zhash_destroy (&self->headers);
84 zstr_free (&self->content);
85
86 free (self);
87 }
88
89 *self_p = NULL;
90 }
91
92 static void *
93 s_insert_connection (struct MHD_Connection *connection) {
94 #if MHD_VERSION >= 0x00093400
95 MHD_suspend_connection (connection);
96 #endif
97 return connection;
98 }
99
100 static void
101 s_destroy_connection (struct MHD_Connection **connection) {
102 #if MHD_VERSION >= 0x00093400
103 MHD_resume_connection (*connection);
104 #endif
105 *connection = NULL;
106 }
107
108 static server_actor_t *
109 server_actor_new (zsock_t *pipe, zhttp_server_options_t *options)
110 {
111 server_actor_t *self = (server_actor_t *) zmalloc (sizeof (server_actor_t));
112 assert (self);
113
114 self->daemon = MHD_start_daemon (
115 #if MHD_VERSION >= 0x00095300
116 MHD_ALLOW_SUSPEND_RESUME,
117 #elif MHD_VERSION >= 0x00093400
118 MHD_USE_SUSPEND_RESUME,
119 #else
120 MHD_USE_PIPE_FOR_SHUTDOWN,
121 #endif
122 (uint16_t ) zhttp_server_options_port (options),
123 NULL, NULL,
124 (MHD_AccessHandlerCallback) s_handle_request, self,
125 MHD_OPTION_NOTIFY_COMPLETED, s_handle_request_completed, self,
126 MHD_OPTION_END);
127
128 if (self->daemon == NULL) {
129 freen (self);
130 return NULL;
131 }
132
133 self->pipe = pipe;
134 self->terminated = false;
135 self->options = options;
136 self->empty_frame = zframe_new_empty ();
137 self->pending_connections = zlistx_new ();
138 zlistx_set_destructor (self->pending_connections, (zlistx_destructor_fn*) s_destroy_connection);
139 zlistx_set_duplicator (self->pending_connections, (zlistx_duplicator_fn*) s_insert_connection);
140 self->backend = zsock_new_dealer (NULL);
141 zsock_bind (self->backend, "%s", zhttp_server_options_backend_address (options));
142
143 return self;
144 }
145
146 static void
147 server_actor_destroy (server_actor_t **self_p)
148 {
149 assert (self_p);
150 if (*self_p) {
151 server_actor_t *self = *self_p;
152 zframe_destroy (&self->empty_frame);
153 zsock_destroy (&self->backend);
154
155 zlistx_destroy (&self->pending_connections);
156 MHD_stop_daemon (self->daemon);
157 self->daemon = NULL;
158
159 free (self);
160 *self_p = NULL;
161 }
162 }
163
164
165 static void
166 s_recv_api (server_actor_t *self) {
167 // Get the whole message of the pipe in one go
168 zmsg_t *request = zmsg_recv (self->pipe);
169 if (!request)
170 return; // Interrupted
171
172 char *command = zmsg_popstr (request);
173 if (streq (command, "VERBOSE"))
174 self->verbose = true;
175 else
176 if (streq (command, "PORT")) {
177 #if MHD_VERSION >= 0x00095600
178 const union MHD_DaemonInfo *info = MHD_get_daemon_info (self->daemon, MHD_DAEMON_INFO_BIND_PORT);
179 assert (info);
180 zsock_send (self->pipe, "i", (int)info->port);
181 #else
182 int port = zhttp_server_options_port (self->options);
183
184 if (port == 0)
185 zsock_send (self->pipe, "i", -1);
186 else
187 zsock_send (self->pipe, "i", port);
188 #endif
189 }
190 else
191 if (streq (command, "$TERM"))
192 // The $TERM command is send by zactor_destroy() method
193 self->terminated = true;
194 else {
195 zsys_error ("invalid command '%s'", command);
196 assert (false);
197 }
198 zstr_free (&command);
199 zmsg_destroy (&request);
200 }
201
202
203 static int
204 s_request_add_header (zhash_t *headers, enum MHD_ValueKind kind, const char *key, const char *value) {
205 if (!key || !value)
206 return MHD_YES; // Ignore connection value if invalid!
207
208 zhash_insert (headers, (char *) key, (char *) value);
209
210 return MHD_YES;
211 }
212
213 static int
214 s_handle_request (
215 server_actor_t *self,
216 struct MHD_Connection *connection,
217 const char *path,
218 const char *method,
219 const char *version,
220 const char *upload_data,
221 size_t *upload_data_size,
222 request_t **request_p) {
223 assert (self);
224
225 request_t *request = *request_p;
226
227 if (request && request->suspended)
228 return MHD_YES;
229
230 if (request == NULL) {
231 request = request_new ();
232 *request_p = request;
233
234 // Get the headers
235 MHD_get_connection_values (connection,
236 MHD_HEADER_KIND, (MHD_KeyValueIterator) s_request_add_header, request->headers);
237
238 // Request with post data, next calls will provide the data
239 if (zhash_lookup (request->headers, "Content-Length") ||
240 zhash_lookup (request->headers, "Transfer-Encoding")) {
241
242 // TODO: check if POST_DATA is on MHD_POSTDATA_KIND
243
244 return MHD_YES;
245 }
246
247 // Suspending the connection until response is ready
248 zlistx_add_end (self->pending_connections, connection);
249 request->suspended = true;
250
251 zsock_bsend (self->backend, "psSpp", connection, method, path, request->headers, NULL);
252 request->headers = NULL;
253
254 return MHD_YES;
255 }
256
257 // Append additional data
258 if (*upload_data_size != 0) {
259 size_t offset = 0;
260
261 if (request->content == NULL) {
262 request->content_length = *upload_data_size;
263 request->content = (char*) malloc (request->content_length + 1);
264 } else {
265 offset = request->content_length;
266 request->content_length += *upload_data_size;
267 request->content = (char *) realloc (request->content, request->content_length + 1);
268 }
269
270 memcpy (request->content + offset, upload_data, *upload_data_size);
271 request->content[request->content_length] = '\0';
272 *upload_data_size = 0;
273
274 return MHD_YES;
275 }
276
277 // Suspending the connection until response is ready
278 zlistx_add_end (self->pending_connections, connection);
279 request->suspended = true;
280
281 zsock_bsend (self->backend, "psSpp",
282 connection, method, path, request->headers, request->content);
283 request->content = NULL;
284 request->headers = NULL;
285
286 return MHD_YES;
287 }
288
289 static void
290 s_handle_request_completed (
291 server_actor_t *self,
292 struct MHD_Connection *connection,
293 request_t **request_p,
294 enum MHD_RequestTerminationCode toe) {
295 request_destroy (request_p);
296 }
297
298 static void
299 s_recv_backend (server_actor_t *self) {
300 zhash_t *headers;
301 char *content;
302 struct MHD_Connection *connection;
303 uint32_t status_code;
304 byte free_content;
305
306 int rc = zsock_brecv (self->backend, "p4p1p", &connection, &status_code, &headers, &free_content, &content);
307 if (rc == -1)
308 return;
309
310 struct MHD_Response *http_response;
311
312 if (content) {
313 http_response = MHD_create_response_from_buffer (
314 strlen (content), content,
315 free_content == 1 ? MHD_RESPMEM_MUST_FREE : MHD_RESPMEM_PERSISTENT);
316 assert (http_response);
317 }
318 else {
319 http_response = MHD_create_response_from_buffer(0, NULL, MHD_RESPMEM_PERSISTENT);
320 assert (http_response);
321 }
322
323 for (const char* value = (const char*) zhash_first (headers); value != NULL; value = (const char*)zhash_next (headers)) {
324 const char* key = zhash_cursor (headers);
325
326 MHD_add_response_header (http_response, key, value);
327 }
328 zhash_destroy (&headers);
329
330 // Removing from pending connections, which will resume the connection as well
331 void* handle = zlistx_find (self->pending_connections, connection);
332 assert (handle);
333 zlistx_delete (self->pending_connections, handle);
334
335 MHD_queue_response (connection, status_code, http_response);
336 MHD_destroy_response (http_response);
337 }
338
339 // --------------------------------------------------------------------------
340 // This is the actor which runs in its own thread.
341
342 static void
343 server_actor (zsock_t *pipe, void *args)
344 {
345 server_actor_t * self = server_actor_new (pipe, (zhttp_server_options_t *) args);
346 if (!self) {
347 assert (false);
348 zsock_signal (pipe, 1);
349 return;
350 }
351
352 // Signal actor successfully initiated
353 zsock_signal (self->pipe, 0);
354
355 fd_set read_fd_set;
356 fd_set write_fd_set;
357 fd_set except_fd_set;
358 FD_ZERO (&read_fd_set);
359 FD_ZERO (&write_fd_set);
360 FD_ZERO (&except_fd_set);
361
362 SOCKET pipe_fd = zsock_fd (pipe);
363 SOCKET backend_fd = zsock_fd (self->backend);
364
365 int rc;
366
367 while (!self->terminated) {
368 #if MHD_VERSION >= 0x00094400
369 MHD_run_from_select (self->daemon, &read_fd_set, &write_fd_set, &except_fd_set);
370 #else
371 MHD_run (self->daemon);
372 #endif
373
374 bool use_timeout = true;
375
376 if (zsock_has_in (self->pipe)) {
377 s_recv_api (self);
378 use_timeout = false;
379 }
380
381 while (zsock_has_in (self->backend)) {
382 s_recv_backend (self);
383 use_timeout = false;
384 }
385
386 FD_ZERO (&read_fd_set);
387 FD_ZERO (&write_fd_set);
388 FD_ZERO (&except_fd_set);
389 FD_SET (pipe_fd, &read_fd_set);
390 FD_SET (backend_fd, &read_fd_set);
391
392 SOCKET max_fd = pipe_fd > backend_fd ? pipe_fd : backend_fd;
393 rc = MHD_get_fdset (self->daemon, &read_fd_set, &write_fd_set, &except_fd_set, &max_fd);
394 assert (rc == MHD_YES);
395
396 unsigned long long timeout;
397 rc = MHD_get_timeout (self->daemon, &timeout);
398
399 struct timeval timeval;
400 struct timeval *timeval_p = &timeval;
401
402 if (!use_timeout) {
403 timeval.tv_sec = 0;
404 timeval.tv_usec = 0;
405 }
406 else if (rc == MHD_YES) {
407 timeval.tv_sec = (long) (timeout / 1000);
408 timeval.tv_usec = (long) (timeout % 1000);
409 }
410 else {
411 timeval_p = NULL; // Not using any timeout
412 }
413
414 select (
415 max_fd + 1,
416 &read_fd_set,
417 &write_fd_set,
418 &except_fd_set,
419 timeval_p);
420 }
421 server_actor_destroy (&self);
422 }
423
424 #endif
425
426 zhttp_server_t *
427 zhttp_server_new (zhttp_server_options_t *options) {
428 zhttp_server_t *self = NULL;
429 #ifdef HAVE_LIBMICROHTTPD
430 self = (zhttp_server_t *) zactor_new (server_actor, options);
431 #endif
432 return self;
433 }
434
435 void
436 zhttp_server_destroy (zhttp_server_t **self_p) {
437 zactor_destroy ((zactor_t **) self_p);
438 }
439
440
441 int
442 zhttp_server_port (zhttp_server_t *self) {
443 #ifdef HAVE_LIBMICROHTTPD
444 assert (self);
445
446 zstr_send (self, "PORT");
447 int port;
448
449 zsock_recv (self, "i", &port);
450 return port;
451 #else
452 return -1;
453 #endif
454 }
455
456 // --------------------------------------------------------------------------
457 // Self test of this actor.
458
459 // If your selftest reads SCMed fixture data, please keep it in
460 // src/selftest-ro; if your test creates filesystem objects, please
461 // do so under src/selftest-rw.
462 // The following pattern is suggested for C selftest code:
463 // char *filename = NULL;
464 // filename = zsys_sprintf ("%s/%s", SELFTEST_DIR_RO, "mytemplate.file");
465 // assert (filename);
466 // ... use the "filename" for I/O ...
467 // zstr_free (&filename);
468 // This way the same "filename" variable can be reused for many subtests.
469 #define SELFTEST_DIR_RO "src/selftest-ro"
470 #define SELFTEST_DIR_RW "src/selftest-rw"
471
472 void
473 zhttp_server_test (bool verbose)
474 {
475 #if defined(HAVE_LIBCURL) && defined(HAVE_LIBMICROHTTPD)
476 printf (" * zhttp_server: ");
477
478 // @selftest
479 int port = 40000 + (randof (10000));
480 zhttp_server_options_t *options = zhttp_server_options_new ();
481 zhttp_server_options_set_port (options, port);
482
483 zhttp_server_t *server = zhttp_server_new (options);
484 assert (server);
485 // @end
486
487 char url[256];
488 snprintf (url, 255, "http://127.0.0.1:%d", port);
489
490 zhttp_client_t *self = zhttp_client_new (verbose);
491 assert (self);
492
493 zhttp_request_t* client_request = zhttp_request_new ();
494 zhttp_request_set_url (client_request, url);
495 zhttp_request_set_method (client_request, "POST");
496 zhttp_request_set_content_const (client_request, "Hello!");
497 int rc = zhttp_request_send (client_request, self, /*timeout*/ 10000, /* user args*/ NULL, NULL);
498 assert (rc == 0);
499
500 // @selftest
501 zsock_t *worker = zsock_new_dealer (zhttp_server_options_backend_address (options));
502 zhttp_request_t *request = zhttp_request_new ();
503 void *connection = zhttp_request_recv (request, worker);
504 assert (connection);
505
506 assert (streq (zhttp_request_method (request), "POST"));
507 assert (streq (zhttp_request_url (request), "/"));
508 assert (streq (zhttp_request_content (request), "Hello!"));
509
510 zhttp_response_t *response = zhttp_response_new ();
511 zhttp_response_set_content_const (response, "Welcome!");
512 zhttp_response_set_status_code (response, 200);
513 rc = zhttp_response_send (response, worker, &connection);
514 assert (rc == 0);
515 // @end
516
517 void *user_arg;
518 void *user_arg2;
519 zhttp_response_t* client_response = zhttp_response_new ();
520 rc = zhttp_response_recv (client_response, self, &user_arg, &user_arg2);
521 assert (rc == 0);
522 assert (streq (zhttp_response_content (client_response), "Welcome!"));
523
524 zhttp_client_destroy (&self);
525 zhttp_request_destroy (&client_request);
526 zhttp_response_destroy (&client_response);
527
528 // @selftest
529 zhttp_request_destroy (&request);
530 zhttp_response_destroy (&response);
531 zsock_destroy (&worker);
532 zhttp_server_destroy (&server);
533 zhttp_server_options_destroy (&options);
534 // @end
535
536
537 printf ("OK\n");
538 #endif
539 }
0 /* =========================================================================
1 zhttp_server_options - class description
2
3 Copyright (c) the Contributors as noted in the AUTHORS file.
4
5 This Source Code Form is subject to the terms of the Mozilla Public
6 License, v. 2.0. If a copy of the MPL was not distributed with this
7 file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 =========================================================================
9 */
10
11 /*
12 @header
13 zhttp_server_options -
14 @discuss
15 @end
16 */
17
18 #include "czmq_classes.h"
19
20 // Structure of our class
21
22 struct _zhttp_server_options_t {
23 int port;
24 char *backend_address;
25 };
26
27
28 // --------------------------------------------------------------------------
29 // Create a new zhttp_server_options
30
31 zhttp_server_options_t *
32 zhttp_server_options_new (void)
33 {
34 zhttp_server_options_t *self = (zhttp_server_options_t *) zmalloc (sizeof (zhttp_server_options_t));
35
36 self->port = 8080;
37 self->backend_address =
38 zsys_sprintf ("inproc://zhttp_server-%04x-%04x", randof (0x10000), randof (0x10000));
39
40 assert (self);
41 // Initialize class properties here
42 return self;
43 }
44
45
46 // --------------------------------------------------------------------------
47 // Destroy the zhttp_server_options
48
49 void
50 zhttp_server_options_destroy (zhttp_server_options_t **self_p)
51 {
52 assert (self_p);
53 if (*self_p) {
54 zhttp_server_options_t *self = *self_p;
55 zstr_free (&self->backend_address);
56 // Free object itself
57 free (self);
58 *self_p = NULL;
59 }
60 }
61
62
63 zhttp_server_options_t *
64 zhttp_server_options_from_config (zconfig_t *config) {
65 assert (config);
66 zhttp_server_options_t *self = zhttp_server_options_new ();
67
68 const char* backend_address = zconfig_get (config, "http_server/backend_address", NULL);
69 const char* port_str = zconfig_get (config, "http_server/port", NULL);
70
71 if (backend_address)
72 self->backend_address = strdup (backend_address);
73
74 if (port_str)
75 self->port = atoi (port_str);
76
77 return self;
78 }
79
80 int
81 zhttp_server_options_port (zhttp_server_options_t *self) {
82 assert (self);
83
84 return self->port;
85 }
86
87 void
88 zhttp_server_options_set_port (zhttp_server_options_t *self, int port) {
89 self->port = port;
90 }
91
92 const char *
93 zhttp_server_options_backend_address (zhttp_server_options_t *self) {
94 assert (self);
95
96 return self->backend_address;
97 }
98
99 void
100 zhttp_server_options_set_backend_address (zhttp_server_options_t *self, const char *address) {
101 assert (self);
102 self->backend_address = strdup (address);
103 }
104
105 void
106 zhttp_server_options_test (bool verbose) {
107
108 }
204204 zlistx_head (zlistx_t *self)
205205 {
206206 assert (self);
207 return self->head? self->head->item: NULL;
207 return self->head? self->head->next->item: NULL;
208208 }
209209
210210
631631 self->comparator = comparator;
632632 }
633633
634 // --------------------------------------------------------------------------
635 // Serialize list to a binary frame that can be sent in a message.
636 // The packed format is compatible with the 'strings' type implemented by zproto:
637 //
638 // ; A list of strings
639 // list = list-count *longstr
640 // list-count = number-4
641 //
642 // ; Strings are always length + text contents
643 // longstr = number-4 *VCHAR
644 //
645 // ; Numbers are unsigned integers in network byte order
646 // number-4 = 4OCTET
647 // Caller owns return value and must destroy it when done.
648 zframe_t *
649 zlistx_pack (zlistx_t *self) {
650 assert (self);
651
652 // First, calculate the packed data size
653 size_t frame_size = 4; // List size, number-4
654 char* item = (char *) zlistx_first (self);
655
656 while (item) {
657 frame_size += 4 + strlen (item);
658 item = (char *) zlistx_next (self);
659 }
660
661 // Now serialize items into the frame
662 zframe_t *frame = zframe_new (NULL, frame_size);
663 if (!frame)
664 return NULL;
665
666 byte *needle = zframe_data (frame);
667 *(uint32_t *) needle = htonl ((u_long) self->size);
668 needle += 4;
669
670 item = (char *) zlistx_first (self);
671 while (item) {
672 size_t length = strlen (item);
673 uint32_t serialize = htonl ((u_long) length);
674 memcpy (needle, &serialize, 4);
675 needle += 4;
676 memcpy (needle, item, length);
677 needle += length;
678
679 item = (char *) zlistx_next (self);
680 }
681
682 return frame;
683 }
684
685
686 // --------------------------------------------------------------------------
687 // Unpack binary frame into a new list. Packed data must follow format
688 // defined by zlistx_pack. List is set to autofree. An empty frame
689 // unpacks to an empty list.
690 zlistx_t *
691 zlistx_unpack (zframe_t *frame) {
692 zlistx_t *self = zlistx_new ();
693 if (!self)
694 return NULL;
695
696 // List will free values in destructor
697 zlistx_set_destructor (self, (zlistx_destructor_fn *) zstr_free);
698
699 assert (frame);
700 if (zframe_size (frame) < 4)
701 return self;
702
703 byte *needle = zframe_data (frame);
704 byte *ceiling = needle + zframe_size (frame);
705 size_t nbr_items = ntohl (*(uint32_t *) needle);
706 needle +=4;
707 while (nbr_items && needle < ceiling) {
708 if (needle + 4 <= ceiling) {
709 size_t length = ntohl (*(uint32_t *)needle);
710 needle += 4;
711 // Be wary of malformed frames
712 if (needle + length <= ceiling) {
713 char * item = (char *) zmalloc (length + 1);
714 assert (item);
715 memcpy (item, needle, length);
716 item[length] = 0;
717 needle += length;
718
719 if (!zlistx_add_end (self, item)) {
720 zlistx_destroy (&self);
721 break;
722 }
723 } else {
724
725 zlistx_destroy (&self);
726 break;
727 }
728 } else {
729 zlistx_destroy (&self);
730 break;
731 }
732 }
733
734 if (self)
735 zlistx_set_duplicator (self, (zlistx_duplicator_fn *) strdup);
736
737 return self;
738 }
739
634740
635741 // --------------------------------------------------------------------------
636742 // Runs selftest of class
646752 assert (zlistx_size (list) == 0);
647753
648754 // Test operations on an empty list
755 assert (zlistx_head (list) == NULL);
649756 assert (zlistx_first (list) == NULL);
650757 assert (zlistx_last (list) == NULL);
651758 assert (zlistx_next (list) == NULL);
667774 assert (zlistx_next (list) == NULL);
668775 zlistx_add_end (list, "world");
669776 assert (streq ((char *) zlistx_next (list), "world"));
777 assert (streq ((char *) zlistx_head (list), "world"));
670778 zlistx_add_end (list, "hello");
671779 assert (streq ((char *) zlistx_prev (list), "hello"));
672780 zlistx_sort (list);
740848 string = (char *) zlistx_next (list);
741849 assert (streq (string, "four"));
742850
851 // Test pack/unpack methods
852 zframe_t *frame = zlistx_pack (list);
853 copy = zlistx_unpack (frame);
854 assert (copy);
855 zframe_destroy (&frame);
856 assert (zlistx_size (copy) == zlistx_size (list));
857
858 char *item_orig = (char *) zlistx_first (list);
859 char *item_copy = (char *) zlistx_first (copy);
860 while (item_orig) {
861 assert (strcmp(item_orig, item_copy) == 0);
862 item_orig = (char *) zlistx_next (list);
863 item_copy = (char *) zlistx_next (copy);
864 }
865
866 zlistx_destroy (&copy);
867
743868 zlistx_purge (list);
744869 zlistx_destroy (&list);
745870
711711
712712 // Main reactor loop
713713 while (!zsys_interrupted || self->nonstop) {
714 if (rc == -1) // somebody wanted us to quit
715 break;
714716 if (self->need_rebuild) {
715717 // If s_rebuild_pollset() fails, break out of the loop and
716718 // return its error
720722 }
721723 rc = zmq_poll (self->pollset, (int) self->poll_size, s_tickless (self));
722724 if (rc == -1 || (zsys_interrupted && !self->nonstop)) {
723 if (self->verbose)
724 zsys_debug ("zloop: interrupted");
725 if (self->verbose) {
726 if (rc == -1)
727 zsys_debug ("zloop: interrupted: %s", strerror (errno));
728 else
729 zsys_debug ("zloop: zsys_interrupted");
730 }
725731 rc = 0;
726732 break; // Context has been shut down
727733 }
734740 if (self->verbose)
735741 zsys_debug ("zloop: call timer handler id=%d", timer->timer_id);
736742 rc = timer->handler (self, timer->timer_id, timer->arg);
737 if (rc == -1)
738 break; // Timer handler signaled break
739743 if (timer->times && --timer->times == 0)
740744 zlistx_delete (self->timers, timer->list_handle);
741745 else
742746 timer->when += timer->delay;
747 if (rc == -1)
748 break; // Timer handler signaled break
743749 }
744750 timer = (s_timer_t *) zlistx_next (self->timers);
745751 }
841847 ptrdiff_t timer_id = (byte *) zlistx_detach (self->zombies, NULL) - (byte *) NULL;
842848 s_timer_remove (self, (int) timer_id);
843849 }
844 if (rc == -1)
845 break;
846850 }
847851 self->terminated = true;
848852 return rc;
226226
227227 #ifdef ZMQ_HAVE_POLLER
228228 zmq_poller_event_t event;
229 if (!zmq_poller_wait (self->zmq_poller, &event, timeout * ZMQ_POLL_MSEC))
229 if (!zmq_poller_wait (self->zmq_poller, &event, timeout))
230230 return event.user_data;
231231 else
232232 if (errno == ETIMEDOUT || errno == EAGAIN)
9494 };
9595
9696 static zpair_t*
97 zpair_new (char* endpoint) {
97 zpair_new (char *endpoint) {
9898 zpair_t *self = (zpair_t*) zmalloc (sizeof (zpair_t));
99 self->endpoint = endpoint;
99 if (self) {
100 self->endpoint = endpoint;
101 }
100102 return self;
101103 }
102104
212214 int stdoutpipe [2]; // stdout pipe
213215 int stderrpipe [2]; // stderr pipe
214216
215 zpair_t *execpair; // pair used to synchronize zproc_run with actor
216217 zpair_t *stdinpair; // stdin socketpair
217218 zpair_t *stdoutpair; // stdout socketpair
218219 zpair_t *stderrpair; // stderr socketpair
236237 }
237238
238239 zproc_t *self = (zproc_t*) zmalloc (sizeof (zproc_t));
240 assert (self);
239241 self->verbose = false;
240242
241243 self->stdinpipe [0] = -1;
246248 self->stderrpipe [1] = -1;
247249
248250 zuuid_t *uuid = zuuid_new ();
249 self->execpair = zpair_new (
250 zsys_sprintf ("#inproc://zproc-%s-exec", zuuid_str_canonical (uuid))
251 );
252 zpair_mkpair (self->execpair);
251 assert (uuid);
253252 self->stdinpair = zpair_new (
254253 zsys_sprintf ("#inproc://zproc-%s-stdin", zuuid_str_canonical (uuid))
255254 );
255 assert (self->stdinpair);
256256 self->stdoutpair = zpair_new (
257257 zsys_sprintf ("#inproc://zproc-%s-stdout", zuuid_str_canonical (uuid))
258258 );
259 assert (self->stdoutpair);
259260 self->stderrpair = zpair_new (
260261 zsys_sprintf ("#inproc://zproc-%s-stderr", zuuid_str_canonical (uuid))
261262 );
263 assert (self->stderrpair);
262264 zuuid_destroy (&uuid);
263265
264266 return self;
270272 assert (self_p);
271273 if (*self_p) {
272274 zproc_t *self = *self_p;
273 zproc_wait (self, true);
275 zproc_shutdown (self, 5000);
274276 zactor_destroy (&self->actor);
275277
276 if (self->stdinpipe [0] != -1) {
277 close (self->stdinpipe [0]);
278 close (self->stdinpipe [1]);
279 }
280 if (self->stdoutpipe [0] != -1) {
281 close (self->stdoutpipe [0]);
282 close (self->stdoutpipe [1]);
283 }
284 if (self->stderrpipe [0] != -1) {
285 close (self->stderrpipe [0]);
286 close (self->stderrpipe [1]);
287 }
288
289 zpair_destroy (&self->execpair);
278 if (self->stdinpipe [0] != -1) close (self->stdinpipe [0]);
279 if (self->stdinpipe [1] != -1) close (self->stdinpipe [1]);
280 if (self->stdoutpipe [0] != -1) close (self->stdoutpipe [0]);
281 if (self->stdoutpipe [1] != -1) close (self->stdoutpipe [1]);
282 if (self->stderrpipe [0] != -1) close (self->stderrpipe [0]);
283 if (self->stderrpipe [1] != -1) close (self->stderrpipe [1]);
284
290285 zpair_destroy (&self->stdinpair);
291286 zpair_destroy (&self->stdoutpair);
292287 zpair_destroy (&self->stderrpair);
429424 zproc_returncode (zproc_t *self) {
430425 assert (self);
431426 assert (zproc_pid(self));
432 zproc_wait (self, false);
427 zproc_wait (self, 0);
433428 return self->return_code;
434429 }
435430
455450 byte buf [BUF_SIZE];
456451 ssize_t r = 1;
457452
458 while (r > 0) {
459 memset (buf, '\0', BUF_SIZE);
460 r = read (item->fd, buf, BUF_SIZE);
461 if (r == -1) {
462 zsys_error ("read from fd %d: %s", item->fd, strerror (errno));
463 break;
464 }
465 else
466 if (r == 0)
467 break;
468 zframe_t *frame = zframe_new (buf, r);
469 zsock_bsend (socket, "f", frame, NULL);
470 zframe_destroy (&frame);
471 }
453 memset (buf, '\0', BUF_SIZE);
454 r = read (item->fd, buf, BUF_SIZE);
455 if (r == -1) {
456 zsys_warning ("read from fd %d: %s", item->fd, strerror (errno));
457 return 0;
458 }
459 else
460 if (r == 0)
461 return 0;
462 zframe_t *frame = zframe_new (buf, r);
463 zsock_bsend (socket, "f", frame, NULL);
464 zframe_destroy (&frame);
472465 return 0;
473466 #undef BUF_SIZE
474467 }
475468
476469 static int
477 s_fd_out_handler (zloop_t *self, zmq_pollitem_t *item, void *socket)
470 s_fd_out_handler (zloop_t *self, zsock_t *socket, void *fd_p)
478471 {
472 assert (self);
473 assert (socket);
474 assert (fd_p);
479475 ssize_t r = 1;
480
481 while (r > 0) {
482
483 zframe_t *frame;
484 r = zsock_brecv (socket, "f", &frame);
485 if (r == -1) {
486 zsys_error ("read from socket <%p>: %s", socket, strerror (errno));
487 break;
488 }
489
490 r = write (item->fd, zframe_data (frame), zframe_size (frame));
476 int fd = *(int*)fd_p;
477
478 zframe_t *frame;
479 r = zsock_brecv (socket, "f", &frame);
480 if (r == -1) {
491481 zframe_destroy (&frame);
492
493 if (r == -1) {
494 zsys_error ("write to fd %d: %s", item->fd, strerror (errno));
495 break;
496 }
482 zsys_error ("read from socket <%p>: %s", socket, strerror (errno));
483 return -1;
484 }
485
486 r = write (fd, zframe_data (frame), zframe_size (frame));
487 zframe_destroy (&frame);
488
489 if (r == -1) {
490 zsys_error ("write to fd %d: %s", fd, strerror (errno));
491 return -1;
497492 }
498493 return 0;
499494 }
500495
496 // connect pipe (fd) with zeromq socket, so when data are signaled on `fd`, they are forwarded to `socket`
497 // used for readable ends of pipesm like stdout/stderr
501498 static int
502 s_zproc_addfd (zproc_t *self, int fd, void* socket, int flags) {
499 s_zproc_readfd (zproc_t *self, int fd, void* socket) {
503500 assert (self);
504501 #if defined (__WINDOWS__)
505 zsys_error ("s_zproc_addfd not implemented for Windows");
502 zsys_error ("s_zproc_readfd not implemented for Windows");
506503 return -1;
507504 #else
508 zmq_pollitem_t it = {NULL, fd, flags, 0};
505 assert (socket);
506 assert (zsock_is (socket));
507 zmq_pollitem_t it = {NULL, fd, ZMQ_POLLIN, 0};
509508 return zloop_poller (
510509 self->loop_ref,
511510 &it,
512 flags == ZMQ_POLLIN ? s_fd_in_handler : s_fd_out_handler,
511 s_fd_in_handler,
513512 socket);
514513 #endif
515514 }
515
516 // connect zeromq `socket` with writable end of pipe. When data are signaled on `fd`, they are forwarded to `fd`
517 // used for writable ends of pipes like stdin
518 static int
519 s_zproc_readsocket (zproc_t *self, int* fd_p, void* socket) {
520 assert (self);
521 #if defined (__WINDOWS__)
522 zsys_error ("s_zproc_readfd not implemented for Windows");
523 return -1;
524 #else
525 assert (socket);
526 assert (zsock_is (socket));
527 return zloop_reader (
528 self->loop_ref,
529 (zsock_t*)socket,
530 s_fd_out_handler,
531 (void*)fd_p);
532 #endif
533 }
534
516535
517536 static int
518537 s_zproc_alive (zloop_t *loop, int timer_id, void *args)
519538 {
520539 zproc_t *self = (zproc_t*) args;
521 if (zsys_interrupted)
540 if (! zproc_running (self))
541 return 0;
542 #if defined (__WINDOWS__)
543 if (zproc_running (self))
544 return 0;
545 #else
546 int status;
547 int r = waitpid (self->pid, &status, WNOHANG);
548 if (r > 0) {
549 if (WIFEXITED(status)) {
550 self->return_code = WEXITSTATUS(status);
551 if (self->verbose)
552 zsys_debug ("zproc_wait [%d]:\tWIFEXITED, self->return_code=%d", self->pid, self->return_code);
553 self->running = false;
554 }
555 else if (WIFSIGNALED(status)) {
556 self->return_code = - WTERMSIG(status);
557 if (self->verbose)
558 zsys_debug ("zproc_wait [%d]:\tWIFSIGNALED, self->return_code=%d", self->pid, self->return_code);
559 self->running = false;
560 }
522561 return -1;
523 if (zproc_pid (self) && zproc_running (self))
524 return 0;
525 return -1;
562 }
563 return 0;
564 #endif
526565 }
527566
528567 static int
545584 zsys_debug ("zproc: command to start: %s", commandline);
546585
547586 siStartInfo.cb = sizeof (siStartInfo);
548 zsock_signal (zpair_write (self->execpair), 0);
549587 self->running = CreateProcessA(
550588 NULL, // app name
551589 commandline, // command line
575613 fcntl (self->stdinpipe [0], F_SETFL, n_flags);
576614 dup2 (self->stdinpipe [0], STDIN_FILENO);
577615 close (self->stdinpipe [1]);
616 self->stdinpipe[1] = -1;
578617 }
579618
580619 // redirect stdout if set_stdout was called
581620 if (self->stdoutpipe [0] != -1) {
582621 close (self->stdoutpipe [0]);
622 self->stdoutpipe [0] = -1;
583623 dup2 (self->stdoutpipe [1], STDOUT_FILENO);
584624 }
585625
586626 // redirect stderr if set_stderr was called
587627 if (self->stderrpipe [0] != -1) {
588628 close (self->stderrpipe [0]);
629 self->stderrpipe [0] = -1;
589630 dup2 (self->stderrpipe [1], STDERR_FILENO);
590631 }
591632
620661 else
621662 env = environ;
622663
623 zsock_signal (zpair_write (self->execpair), 0);
624664 r = execve (filename, argv2, env);
625665 if (r == -1) {
626666 zsys_error ("fail to run %s: %s", filename, strerror (errno));
642682 zsys_debug ("process %s with pid %d started", filename, self->pid);
643683
644684 if (self->stdinpipe [0] != -1) {
645 s_zproc_addfd (self, self->stdinpipe [1], zpair_read (self->stdinpair), ZMQ_POLLOUT);
685 s_zproc_readsocket (self, self->stdinpipe+1, zpair_read (self->stdinpair));
646686 close (self->stdinpipe [0]);
687 self->stdinpipe [0] = -1;
647688 }
648689
649690 // add a handler for read end of stdout
650691 if (self->stdoutpipe [1] != -1) {
651 s_zproc_addfd (self, self->stdoutpipe [0], zpair_write (self->stdoutpair), ZMQ_POLLIN);
692 s_zproc_readfd (self, self->stdoutpipe [0], zpair_write (self->stdoutpair));
652693 close (self->stdoutpipe[1]);
694 self->stdoutpipe [1] = -1;
653695 }
654696 // add a handler for read end of stderr
655697 if (self->stderrpipe [1] != -1) {
656 s_zproc_addfd (self, self->stderrpipe [0], zpair_write (self->stderrpair), ZMQ_POLLIN);
698 s_zproc_readfd (self, self->stderrpipe [0], zpair_write (self->stderrpair));
657699 close (self->stderrpipe[1]);
700 self->stderrpipe [1] = -1;
658701 }
659702 }
660703
684727 }
685728
686729 s_zproc_execve (self);
687 zsock_wait (self->execpair);
730 zclock_sleep (10); // magic sleep, give execve a bit of time
688731 zsock_signal (pipe, 0);
689732 }
690733
702745 zproc_t *self = (zproc_t*) args;
703746 zloop_t *loop = zloop_new ();
704747 assert (loop);
748 // zloop_set_verbose (loop, self->verbose);
705749 self->loop_ref = loop;
706750 self->pipe = pipe;
707751
711755 zsock_signal (pipe, 0);
712756 zloop_start (loop);
713757 zloop_destroy (&loop);
758 while (zproc_running (self)) {
759 zclock_sleep (500);
760 s_zproc_alive (NULL, -1, self);
761 }
714762 zsock_signal (pipe, 0);
715763 }
716764
721769 assert (!self->actor);
722770
723771 if (!self->args || zlist_size (self->args) == 0) {
724 zsys_error ("No arguments, nothing to run. Call zproc_set_args before");
772 if (self->verbose)
773 zsys_error ("zproc: No arguments, nothing to run. Call zproc_set_args before");
774 return -1;
775 }
776 const char *filename = (const char*) zlist_first (self->args);
777 if (!zfile_exists (filename)) {
778 if (self->verbose)
779 zsys_error ("zproc: '%s' does not exists", filename);
725780 return -1;
726781 }
727782
735790 }
736791
737792 int
738 zproc_wait (zproc_t *self, bool wait) {
793 zproc_wait (zproc_t *self, int timeout) {
739794 #if defined (__WINDOWS__)
740795 if (!self->running) {
741796 if (self->verbose)
743798 return self->return_code;
744799 }
745800
746 uint32_t r = WaitForSingleObject (self->piProcInfo.hProcess, wait ? INFINITE : 0);
801 uint32_t r = WaitForSingleObject (self->piProcInfo.hProcess, timeout == -1 ? INFINITE : timeout);
747802 if (self->verbose)
748803 zsys_debug ("zproc_wait [%d]:\twaitforsingleobject, r=%d", zproc_pid (self), r);
749 if (!wait && r == 0x00000102) {
804 if (timeout >= 0 && r == 0x00000102) {
750805 // still running
751806 return self->return_code;
752807 }
763818 return -1;
764819 #else
765820 assert (self);
821
766822 if (!self->pid)
767823 return 0;
768824
769825 if (self->verbose)
770 zsys_debug ("zproc_wait [%d]: wait=%s", self->pid, wait ? "true" : "false");
771 int status = -1;
772 int options = !wait ? WNOHANG : 0;
826 zsys_debug ("zproc_wait [%d]: timeout=%d", self->pid, timeout);
773827 if (self->verbose)
774828 zsys_debug ("zproc_wait [%d]:\t!self->running=%s", self->pid, self->running ? "true" : "false");
775829 if (!self->running)
777831
778832 if (self->verbose)
779833 zsys_debug ("zproc_wait [%d]:\twaitpid", self->pid);
780 int r = waitpid (self->pid, &status, options);
781 if (self->verbose)
782 zsys_debug ("zproc_wait [%d]:\twaitpid, r=%d", self->pid, r);
783 if (!wait && r == 0)
834
835 if (timeout < 0) {
836 // infinite wait
837 while (zproc_running (self))
838 zclock_sleep (200);
784839 return self->return_code;
785
786 if (WIFEXITED(status)) {
787 self->running = false;
788 self->return_code = WEXITSTATUS(status);
789 if (self->verbose)
790 zsys_debug ("zproc_wait [%d]:\tWIFEXITED, self->return_code=%d", self->pid, self->return_code);
840 }
841 else if (timeout == 0) {
842 // just check and continue
791843 return self->return_code;
792 }
793 else if (WIFSIGNALED(status)) {
794 self->running = false;
795 self->return_code = - WTERMSIG(status);
796 if (self->verbose)
797 zsys_debug ("zproc_wait [%d]:\tWIFSIGNALED, self->return_code=%d", self->pid, self->return_code);
844 } else {
845 // wait up to timeout
846 int quit = zclock_mono () + timeout;
847 while (true) {
848 if (! zproc_running (self))
849 break;
850 if (zclock_mono () >= quit)
851 break;
852 zclock_sleep (200);
853 }
798854 return self->return_code;
799
800 /*
801 if (WCOREDUMP(status)) {
802 self->core_dumped = true;
803 }
804 */
805 }
806 if (self->verbose)
807 zsys_debug ("zproc_wait [%d]: self->return_code=%d", self->pid, self->return_code);
808 return ZPROC_RUNNING;
855 }
809856 #endif
810857 }
811858
812859 bool
813860 zproc_running (zproc_t *self) {
814861 assert (self);
815 assert (zproc_pid (self));
816 return zproc_wait (self, false) == ZPROC_RUNNING;
862 if (! zproc_pid (self)) return false;
863 return zproc_wait (self, 0) == ZPROC_RUNNING;
817864 }
818865
819866 void *
831878 if (signum == SIGTERM) {
832879 if (! TerminateProcess (self->piProcInfo.hProcess, 255))
833880 zsys_error ("zproc_kill [%d]:\tTerminateProcess failed", zproc_pid (self));
834 zproc_wait (self, false);
881 zproc_wait (self, 0);
835882 } else {
836883 zsys_error ("zproc_kill: [%d]:\tOnly SIGTERM is implemented on windows", zproc_pid (self));
837884 }
838885 }
839886 #else
840 if (zproc_pid (self) > 0) {
887 if (zproc_running (self)) {
841888 int r = kill (self->pid, signum);
842889 if (r != 0)
843890 zsys_error ("kill of pid=%d failed: %s", self->pid, strerror (errno));
844 zproc_wait (self, false);
891 zproc_wait (self, 0);
892 }
893 #endif
894 }
895
896 // send SIGTERM signal to the subprocess, wait for grace period and KILL
897 void
898 zproc_shutdown (zproc_t *self, int timeout)
899 {
900 assert (self);
901 if (timeout < 0) timeout = 0;
902
903 zproc_kill (self, SIGTERM);
904 zproc_wait (self, timeout);
905 #if ! defined (__WINDOWS__)
906 if (zproc_running (self)) {
907 zproc_kill (self, SIGKILL);
908 zproc_wait (self, timeout);
845909 }
846910 #endif
847911 }
9591023 printf ("OK\n");
9601024 return;
9611025 #endif
1026 {
9621027 // Test case #1: run command, wait until it ends and get the (stdandard) output
9631028 zproc_t *self = zproc_new ();
9641029 assert (self);
9851050 if (verbose)
9861051 zframe_print (frame, "1:");
9871052 zframe_destroy (&frame);
988 r = zproc_wait (self, true);
1053 r = zproc_wait (self, -1);
9891054 assert (r == 0);
9901055 zproc_destroy (&self);
991
992 // Test case #2: use never ending subprocess and poller to read data from it
1056 }
1057
1058 {
1059 // Test case#2: run zsp helper with a content written on stdin, check if it was passed to stdout
1060 zproc_t *self = zproc_new ();
1061 assert (self);
1062 zproc_set_verbose (self, verbose);
1063 // forward input from stdin to stderr
1064 zproc_set_argsx (self, file, "--stdin", "--stderr", NULL);
1065 // FIXME: there is a BUG in zproc somewhere, you can't gen an output from both stdout/stderr
1066 //zproc_set_argsx (self, file, "--stdin", "--stdout", "--stderr", NULL);
1067 zproc_set_stdin (self, NULL);
1068 // FIXME: the bug
1069 //zproc_set_stdout (self, NULL);
1070 zproc_set_stderr (self, NULL);
1071
1072 // send data to stdin
1073 int r = zproc_run (self);
1074 assert (r == 0);
1075 zframe_t *frame = zframe_new ("Lorem ipsum\0\0", strlen ("Lorem ipsum")+2);
1076 assert (frame);
1077 zsock_bsend (zproc_stdin (self), "f", frame);
1078 zframe_destroy (&frame);
1079
1080 // FIXME: the bug
1081 //zproc_set_stdout (self, NULL);
1082 // read data from stdout
1083 /*
1084 zsys_debug ("BAF1");
1085 zsock_brecv (zproc_stdout (self), "f", &frame);
1086 zsys_debug ("BAF2");
1087 assert (frame);
1088 assert (zframe_data (frame));
1089 if (verbose)
1090 zframe_print (frame, "2.stdout:");
1091 assert (!strncmp ((char*) zframe_data (frame), "Lorem ipsum", 11));
1092 */
1093
1094 // read data from stderr
1095 zsock_brecv (zproc_stderr (self), "f", &frame);
1096 assert (frame);
1097 assert (zframe_data (frame));
1098 if (verbose)
1099 zframe_print (frame, "2.stderr:");
1100 assert (!strncmp ((char*) zframe_data (frame), "Lorem ipsum", 11));
1101 zproc_kill (self, SIGTERM);
1102 zproc_wait (self, -1);
1103 zframe_destroy (&frame);
1104 zproc_destroy (&self);
1105 }
1106
1107 {
1108 // Test case#3: run non existing binary
1109 zproc_t *self = zproc_new ();
1110 assert (self);
1111 zproc_set_verbose (self, verbose);
1112 // forward input from stdin to stderr
1113 zproc_set_argsx (self, "/not/existing/file", NULL);
1114
1115 int r = zproc_run (self);
1116 assert (r == -1);
1117 zproc_destroy (&self);
1118 }
1119
1120 {
1121 // Test case #4: child abort itself
1122 zproc_t *self = zproc_new ();
1123 assert (self);
1124 zproc_set_verbose (self, verbose);
1125 zproc_set_argsx (self, file, "--verbose", "--abrt", NULL);
1126 zproc_set_stdout (self, NULL);
1127 zproc_set_stderr (self, NULL);
1128 zproc_set_stdin (self, NULL);
1129
1130 int r = zproc_run (self);
1131 zclock_sleep (100); // to let actor start the process
1132 assert (r != -1);
1133 zclock_sleep (100);
1134 zframe_t *frame;
1135 zsock_brecv (zproc_stdout (self), "f", &frame);
1136 assert (zframe_is (frame));
1137 assert (zframe_size (frame) > 0);
1138 zframe_destroy (&frame);
1139 zproc_wait (self, -1);
1140 assert (zproc_returncode (self) == -SIGABRT);
1141 zproc_destroy (&self);
1142 }
1143
1144 {
1145 // Test case #5: use never ending subprocess and poller to read data from it
9931146 // Create new zproc instance
994 self = zproc_new ();
1147 zproc_t *self = zproc_new ();
1148 assert (self);
9951149 zproc_set_verbose (self, verbose);
996 assert (self);
9971150 // join stdout of the process to zeromq socket
9981151 // all data will be readable from zproc_stdout socket
9991152 zproc_set_stdout (self, NULL);
10241177 zsys_debug("zproc_test() : sleeping 4000 msec to gather some output from helper");
10251178 zclock_sleep (4000);
10261179 zproc_kill (self, SIGTERM);
1027 zproc_wait (self, true);
1180 zproc_wait (self, -1);
10281181
10291182 // read the content from zproc_stdout - use zpoller and a loop
10301183 bool stdout_read = false;
10881241 assert (stdout_read);
10891242 zpoller_destroy (&poller);
10901243 zproc_destroy (&self);
1244 }
1245 {
1246 // testcase #6 wait for process that hangs, kill it
1247 zproc_t *self = zproc_new ();
1248 assert (self);
1249 zproc_set_verbose (self, verbose);
1250
1251 zproc_set_argsx (self, file, NULL);
1252
1253 if (verbose)
1254 zsys_debug("zproc_test() : launching helper '%s'", file);
1255
1256 int r = zproc_run (self);
1257 assert (r == 0);
1258 r = zproc_wait (self, 1000);
1259 assert (r == ZPROC_RUNNING);
1260 assert (zproc_running (self));
1261 zproc_shutdown (self, 1000);
1262 assert (!zproc_running (self));
1263 zproc_destroy (&self);
1264 }
1265 {
1266 // testcase #7 wait for process that exits earlier
1267 zproc_t *self = zproc_new ();
1268 assert (self);
1269 zproc_set_verbose (self, verbose);
1270
1271 zproc_set_argsx (self, file, "--quit", "1", NULL);
1272
1273 if (verbose)
1274 zsys_debug("zproc_test() : launching helper '%s' --quit 1", file);
1275
1276 int r = zproc_run (self);
1277 assert (r == 0);
1278 int t = zclock_mono ();
1279 r = zproc_wait (self, 8000);
1280 assert (r == 0);
1281 t = zclock_mono () - t;
1282 assert (t < 2000);
1283 zproc_destroy (&self);
1284 }
10911285 // @end
10921286
10931287 // to have zpair print and arr print methods
197197 assert (*sock_p == NULL);
198198 *sock_p = s_self_create_socket (self, type_name, endpoints, selected_socket);
199199 assert (*sock_p);
200
201 #ifdef CZMQ_BUILD_DRAFT_API
202 if (strcmp (type_name, "SUB") || strcmp (type_name, "XSUB")) {
203 char *topic;
204 while ((topic = zmsg_popstr (request)) != NULL) {
205 zsock_set_subscribe (*sock_p, topic);
206 zstr_free (&topic);
207 }
208 }
209 #endif // CZMQ_BUILD_DRAFT_API
210
200211 zstr_free (&type_name);
201212 zstr_free (&endpoints);
202213 }
580591 zsock_destroy(&sink);
581592 zactor_destroy(&proxy);
582593
594 #ifdef CZMQ_BUILD_DRAFT_API
595 // Create and configure our proxy with PUB/SUB to test subscriptions
596 proxy = zactor_new (zproxy, NULL);
597 assert (proxy);
598 if (verbose) {
599 zstr_sendx (proxy, "VERBOSE", NULL);
600 zsock_wait (proxy);
601 }
602 zstr_sendx (proxy, "FRONTEND", "SUB", "inproc://frontend", "He", "b", NULL);
603 zsock_wait (proxy);
604 zstr_sendx (proxy, "BACKEND", "PUB", "inproc://backend", NULL);
605 zsock_wait (proxy);
606
607 // Connect application sockets to proxy
608 faucet = zsock_new_pub (">inproc://frontend");
609 assert (faucet);
610 sink = zsock_new_sub (">inproc://backend", "");
611 assert (sink);
612
613 // Send some messages and check they arrived
614 zstr_sendx (faucet, "Hello", "World", NULL);
615 // since SUB is binding, subscription might be lost see:
616 // https://github.com/zeromq/libzmq/issues/2267
617 zsock_set_rcvtimeo (sink, 100);
618 hello = zstr_recv (sink);
619 if (hello) {
620 assert (streq (hello, "Hello"));
621 world = zstr_recv (sink);
622 assert (streq (world, "World"));
623 zstr_free (&hello);
624 zstr_free (&world);
625 }
626
627 zsock_destroy (&faucet);
628 zsock_destroy (&sink);
629 zactor_destroy(&proxy);
630 #endif // CZMQ_BUILD_DRAFT_API
631
583632 #if (ZMQ_VERSION_MAJOR == 4)
584633 // Test authentication functionality
585634 const char *basedirpath = "src/selftest-rw/.test_zproxy";
817817 // c = zchunk_t *
818818 // f = zframe_t *
819819 // h = zhashx_t *
820 // l = zlistx_t *
820821 // U = zuuid_t *
821822 // p = void * (sends the pointer value, only meaningful over inproc)
822823 // m = zmsg_t * (sends all frames in the zmsg)
908909 zframe_t *frame = zhashx_pack (hash);
909910 zmsg_append (msg, &frame);
910911 }
912 #ifdef CZMQ_BUILD_DRAFT_API
913 else
914 if (*picture == 'l') {
915 zlistx_t *list = va_arg (argptr, zlistx_t *);
916 zframe_t *frame = zlistx_pack (list);
917 zmsg_append (msg, &frame);
918 }
919 #endif
911920 else
912921 if (*picture == 'm') {
913922 zframe_t *frame;
951960 // c = zchunk_t ** (creates zchunk)
952961 // f = zframe_t ** (creates zframe)
953962 // h = zhashx_t ** (creates zhashx)
963 // l = zlistx_t ** (creates zlistx)
954964 // U = zuuid_t * (creates a zuuid with the data)
955965 // p = void ** (stores pointer)
956966 // m = zmsg_t ** (creates a zmsg with the remaing frames)
11351145 }
11361146 zframe_destroy (&frame);
11371147 }
1148 #ifdef CZMQ_BUILD_DRAFT_API
1149 else
1150 if (*picture == 'l') {
1151 zframe_t *frame = zmsg_pop (msg);
1152 zlistx_t **list_p = va_arg (argptr, zlistx_t **);
1153 if (list_p) {
1154 if (frame)
1155 *list_p = zlistx_unpack (frame);
1156 else
1157 *list_p = NULL;
1158 }
1159 zframe_destroy (&frame);
1160 }
1161 #endif
11381162 else
11391163 if (*picture == 'm') {
11401164 zmsg_t **zmsg_p = va_arg (argptr, zmsg_t **);
18211845 }
18221846
18231847
1848 // --------------------------------------------------------------------------
1849 // Check whether the socket has available message to read.
1850
1851 bool
1852 zsock_has_in (void *self) {
1853 int events = zsock_events (self);
1854 return (events & ZMQ_POLLIN) != 0;
1855 }
1856
1857
18241858 // We use the gossip messages for some test cases
18251859 #include "zgossip_msg.h"
18261860
19651999 assert (frame);
19662000 zhashx_t *hash = zhashx_new ();
19672001 assert (hash);
2002 #ifdef CZMQ_BUILD_DRAFT_API
2003 zlistx_t *list = zlistx_new ();
2004 assert (list);
2005 #endif
19682006 zuuid_t *uuid = zuuid_new ();
19692007 assert (uuid);
19702008 zhashx_set_destructor (hash, (zhashx_destructor_fn *) zstr_free);
19712009 zhashx_set_duplicator (hash, (zhashx_duplicator_fn *) strdup);
19722010 zhashx_insert (hash, "1", "value A");
19732011 zhashx_insert (hash, "2", "value B");
2012 #ifdef CZMQ_BUILD_DRAFT_API
2013 zlistx_set_destructor (list, (zlistx_destructor_fn *) zstr_free);
2014 zlistx_set_duplicator (list, (zlistx_duplicator_fn *) strdup);
2015 zlistx_add_end (list, "1");
2016 zlistx_add_end (list, "2");
2017 #endif
19742018 char *original = "pointer";
19752019
19762020 // Test zsock_recv into each supported type
2021 #ifdef CZMQ_BUILD_DRAFT_API
2022 zsock_send (writer, "i124488zsbcfUhlp",
2023 #else
19772024 zsock_send (writer, "i124488zsbcfUhp",
2025 #endif
19782026 -12345, number1, number2, number4, number4_MAX,
19792027 number8, number8_MAX,
19802028 "This is a string", "ABCDE", 5,
2029 #ifdef CZMQ_BUILD_DRAFT_API
2030 chunk, frame, uuid, hash, list, original);
2031 #else
19812032 chunk, frame, uuid, hash, original);
2033 #endif
19822034 char *uuid_str = strdup (zuuid_str (uuid));
19832035 zchunk_destroy (&chunk);
19842036 zframe_destroy (&frame);
19852037 zuuid_destroy (&uuid);
19862038 zhashx_destroy (&hash);
2039 #ifdef CZMQ_BUILD_DRAFT_API
2040 zlistx_destroy (&list);
2041 #endif
19872042
19882043 int integer;
19892044 byte *data;
19902045 size_t size;
19912046 char *pointer;
19922047 number8_MAX = number8 = number4_MAX = number4 = number2 = number1 = 0ULL;
2048 #ifdef CZMQ_BUILD_DRAFT_API
2049 rc = zsock_recv (reader, "i124488zsbcfUhlp",
2050 #else
19932051 rc = zsock_recv (reader, "i124488zsbcfUhp",
2052 #endif
19942053 &integer, &number1, &number2, &number4, &number4_MAX,
19952054 &number8, &number8_MAX, &string, &data, &size, &chunk,
2055 #ifdef CZMQ_BUILD_DRAFT_API
2056 &frame, &uuid, &hash, &list, &pointer);
2057 #else
19962058 &frame, &uuid, &hash, &pointer);
2059 #endif
19972060 assert (rc == 0);
19982061 assert (integer == -12345);
19992062 assert (number1 == 123);
20142077 assert (streq (value, "value A"));
20152078 value = (char *) zhashx_lookup (hash, "2");
20162079 assert (streq (value, "value B"));
2080 #ifdef CZMQ_BUILD_DRAFT_API
2081 value = (char *) zlistx_first (list);
2082 assert (streq (value, "1"));
2083 value = (char *) zlistx_last (list);
2084 assert (streq (value, "2"));
2085 #endif
20172086 assert (original == pointer);
20182087 freen (string);
20192088 freen (data);
20212090 zframe_destroy (&frame);
20222091 zchunk_destroy (&chunk);
20232092 zhashx_destroy (&hash);
2093 #ifdef CZMQ_BUILD_DRAFT_API
2094 zlistx_destroy (&list);
2095 #endif
20242096 zuuid_destroy (&uuid);
20252097
20262098 // Test zsock_recv of short message; this lets us return a failure
1919 */
2020
2121 // --------------------------------------------------------------------------
22 // Set socket ZMQ_ROUTER_NOTIFY value
23 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
24
25 void
26 zsock_set_router_notify (void *self, int router_notify)
27 {
28 assert (self);
29 # if defined (ZMQ_ROUTER_NOTIFY)
30 int major, minor, patch;
31 zmq_version (&major, &minor, &patch);
32 if (ZMQ_MAKE_VERSION (major, minor, patch) < ZMQ_MAKE_VERSION (4, 3, 0)) {
33 zsys_error ("zsock router_notify option not supported by libzmq version %d.%d.%d, "
34 "run with libzmq >= 4.3.0\n", major, minor, patch, NULL);
35 return;
36 }
37 int rc = zmq_setsockopt (zsock_resolve (self), ZMQ_ROUTER_NOTIFY, &router_notify, sizeof (int));
38 assert (rc == 0 || zmq_errno () == ETERM);
39 # endif
40 }
41
42
43 // --------------------------------------------------------------------------
44 // Return socket ZMQ_ROUTER_NOTIFY value
45 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
46
47 int
48 zsock_router_notify (void *self)
49 {
50 assert (self);
51 # if defined (ZMQ_ROUTER_NOTIFY)
52 int major, minor, patch;
53 zmq_version (&major, &minor, &patch);
54 if (ZMQ_MAKE_VERSION (major, minor, patch) < ZMQ_MAKE_VERSION (4, 3, 0)) {
55 zsys_error ("zsock router_notify option not supported by libzmq version %d.%d.%d, "
56 "run with libzmq >= 4.3.0\n", major, minor, patch, NULL);
57 return 0;
58 }
59 int router_notify;
60 size_t option_len = sizeof (int);
61 zmq_getsockopt (zsock_resolve (self), ZMQ_ROUTER_NOTIFY, &router_notify, &option_len);
62 return router_notify;
63 # else
64 return 0;
65 # endif
66 }
67
68 // --------------------------------------------------------------------------
69 // Set socket ZMQ_MULTICAST_LOOP value
70 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
71
72 void
73 zsock_set_multicast_loop (void *self, int multicast_loop)
74 {
75 assert (self);
76 # if defined (ZMQ_MULTICAST_LOOP)
77 int major, minor, patch;
78 zmq_version (&major, &minor, &patch);
79 if (ZMQ_MAKE_VERSION (major, minor, patch) < ZMQ_MAKE_VERSION (4, 3, 0)) {
80 zsys_error ("zsock multicast_loop option not supported by libzmq version %d.%d.%d, "
81 "run with libzmq >= 4.3.0\n", major, minor, patch, NULL);
82 return;
83 }
84 int rc = zmq_setsockopt (zsock_resolve (self), ZMQ_MULTICAST_LOOP, &multicast_loop, sizeof (int));
85 assert (rc == 0 || zmq_errno () == ETERM);
86 # endif
87 }
88
89
90 // --------------------------------------------------------------------------
91 // Return socket ZMQ_MULTICAST_LOOP value
92 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
93
94 int
95 zsock_multicast_loop (void *self)
96 {
97 assert (self);
98 # if defined (ZMQ_MULTICAST_LOOP)
99 int major, minor, patch;
100 zmq_version (&major, &minor, &patch);
101 if (ZMQ_MAKE_VERSION (major, minor, patch) < ZMQ_MAKE_VERSION (4, 3, 0)) {
102 zsys_error ("zsock multicast_loop option not supported by libzmq version %d.%d.%d, "
103 "run with libzmq >= 4.3.0\n", major, minor, patch, NULL);
104 return 0;
105 }
106 int multicast_loop;
107 size_t option_len = sizeof (int);
108 zmq_getsockopt (zsock_resolve (self), ZMQ_MULTICAST_LOOP, &multicast_loop, &option_len);
109 return multicast_loop;
110 # else
111 return 0;
112 # endif
113 }
114
115 // --------------------------------------------------------------------------
116 // Set socket ZMQ_METADATA value
117 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
118
119 void
120 zsock_set_metadata (void *self, const char * metadata)
121 {
122 assert (self);
123 # if defined (ZMQ_METADATA)
124 int major, minor, patch;
125 zmq_version (&major, &minor, &patch);
126 if (ZMQ_MAKE_VERSION (major, minor, patch) < ZMQ_MAKE_VERSION (4, 3, 0)) {
127 zsys_error ("zsock metadata option not supported by libzmq version %d.%d.%d, "
128 "run with libzmq >= 4.3.0\n", major, minor, patch, NULL);
129 return;
130 }
131 int rc = zmq_setsockopt (zsock_resolve (self), ZMQ_METADATA, metadata, strlen (metadata));
132 assert (rc == 0 || zmq_errno () == ETERM);
133 # endif
134 }
135
136
137 // --------------------------------------------------------------------------
138 // Return socket ZMQ_METADATA value
139 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
140
141 char *
142 zsock_metadata (void *self)
143 {
144 assert (self);
145 # if defined (ZMQ_METADATA)
146 int major, minor, patch;
147 zmq_version (&major, &minor, &patch);
148 if (ZMQ_MAKE_VERSION (major, minor, patch) < ZMQ_MAKE_VERSION (4, 3, 0)) {
149 zsys_error ("zsock metadata option not supported by libzmq version %d.%d.%d, "
150 "run with libzmq >= 4.3.0\n", major, minor, patch, NULL);
151 return 0;
152 }
153 size_t option_len = 255;
154 char *metadata = (char *) zmalloc (option_len);
155 zmq_getsockopt (zsock_resolve (self), ZMQ_METADATA, metadata, &option_len);
156 return (char *) metadata;
157 # else
158 return NULL;
159 # endif
160 }
161
162 // --------------------------------------------------------------------------
163 // Set socket ZMQ_LOOPBACK_FASTPATH value
164 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
165
166 void
167 zsock_set_loopback_fastpath (void *self, int loopback_fastpath)
168 {
169 assert (self);
170 # if defined (ZMQ_LOOPBACK_FASTPATH)
171 int major, minor, patch;
172 zmq_version (&major, &minor, &patch);
173 if (ZMQ_MAKE_VERSION (major, minor, patch) < ZMQ_MAKE_VERSION (4, 3, 0)) {
174 zsys_error ("zsock loopback_fastpath option not supported by libzmq version %d.%d.%d, "
175 "run with libzmq >= 4.3.0\n", major, minor, patch, NULL);
176 return;
177 }
178 int rc = zmq_setsockopt (zsock_resolve (self), ZMQ_LOOPBACK_FASTPATH, &loopback_fastpath, sizeof (int));
179 assert (rc == 0 || zmq_errno () == ETERM);
180 # endif
181 }
182
183
184 // --------------------------------------------------------------------------
185 // Return socket ZMQ_LOOPBACK_FASTPATH value
186 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
187
188 int
189 zsock_loopback_fastpath (void *self)
190 {
191 assert (self);
192 # if defined (ZMQ_LOOPBACK_FASTPATH)
193 int major, minor, patch;
194 zmq_version (&major, &minor, &patch);
195 if (ZMQ_MAKE_VERSION (major, minor, patch) < ZMQ_MAKE_VERSION (4, 3, 0)) {
196 zsys_error ("zsock loopback_fastpath option not supported by libzmq version %d.%d.%d, "
197 "run with libzmq >= 4.3.0\n", major, minor, patch, NULL);
198 return 0;
199 }
200 int loopback_fastpath;
201 size_t option_len = sizeof (int);
202 zmq_getsockopt (zsock_resolve (self), ZMQ_LOOPBACK_FASTPATH, &loopback_fastpath, &option_len);
203 return loopback_fastpath;
204 # else
205 return 0;
206 # endif
207 }
208
209 // --------------------------------------------------------------------------
210 // Set socket ZMQ_ZAP_ENFORCE_DOMAIN value
211 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
212
213 void
214 zsock_set_zap_enforce_domain (void *self, int zap_enforce_domain)
215 {
216 assert (self);
217 # if defined (ZMQ_ZAP_ENFORCE_DOMAIN)
218 int major, minor, patch;
219 zmq_version (&major, &minor, &patch);
220 if (ZMQ_MAKE_VERSION (major, minor, patch) < ZMQ_MAKE_VERSION (4, 3, 0)) {
221 zsys_error ("zsock zap_enforce_domain option not supported by libzmq version %d.%d.%d, "
222 "run with libzmq >= 4.3.0\n", major, minor, patch, NULL);
223 return;
224 }
225 int rc = zmq_setsockopt (zsock_resolve (self), ZMQ_ZAP_ENFORCE_DOMAIN, &zap_enforce_domain, sizeof (int));
226 assert (rc == 0 || zmq_errno () == ETERM);
227 # endif
228 }
229
230
231 // --------------------------------------------------------------------------
232 // Return socket ZMQ_ZAP_ENFORCE_DOMAIN value
233 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
234
235 int
236 zsock_zap_enforce_domain (void *self)
237 {
238 assert (self);
239 # if defined (ZMQ_ZAP_ENFORCE_DOMAIN)
240 int major, minor, patch;
241 zmq_version (&major, &minor, &patch);
242 if (ZMQ_MAKE_VERSION (major, minor, patch) < ZMQ_MAKE_VERSION (4, 3, 0)) {
243 zsys_error ("zsock zap_enforce_domain option not supported by libzmq version %d.%d.%d, "
244 "run with libzmq >= 4.3.0\n", major, minor, patch, NULL);
245 return 0;
246 }
247 int zap_enforce_domain;
248 size_t option_len = sizeof (int);
249 zmq_getsockopt (zsock_resolve (self), ZMQ_ZAP_ENFORCE_DOMAIN, &zap_enforce_domain, &option_len);
250 return zap_enforce_domain;
251 # else
252 return 0;
253 # endif
254 }
255
256 // --------------------------------------------------------------------------
257 // Set socket ZMQ_GSSAPI_PRINCIPAL_NAMETYPE value
258 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
259
260 void
261 zsock_set_gssapi_principal_nametype (void *self, int gssapi_principal_nametype)
262 {
263 assert (self);
264 # if defined (ZMQ_GSSAPI_PRINCIPAL_NAMETYPE)
265 int major, minor, patch;
266 zmq_version (&major, &minor, &patch);
267 if (ZMQ_MAKE_VERSION (major, minor, patch) < ZMQ_MAKE_VERSION (4, 3, 0)) {
268 zsys_error ("zsock gssapi_principal_nametype option not supported by libzmq version %d.%d.%d, "
269 "run with libzmq >= 4.3.0\n", major, minor, patch, NULL);
270 return;
271 }
272 int rc = zmq_setsockopt (zsock_resolve (self), ZMQ_GSSAPI_PRINCIPAL_NAMETYPE, &gssapi_principal_nametype, sizeof (int));
273 assert (rc == 0 || zmq_errno () == ETERM);
274 # endif
275 }
276
277
278 // --------------------------------------------------------------------------
279 // Return socket ZMQ_GSSAPI_PRINCIPAL_NAMETYPE value
280 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
281
282 int
283 zsock_gssapi_principal_nametype (void *self)
284 {
285 assert (self);
286 # if defined (ZMQ_GSSAPI_PRINCIPAL_NAMETYPE)
287 int major, minor, patch;
288 zmq_version (&major, &minor, &patch);
289 if (ZMQ_MAKE_VERSION (major, minor, patch) < ZMQ_MAKE_VERSION (4, 3, 0)) {
290 zsys_error ("zsock gssapi_principal_nametype option not supported by libzmq version %d.%d.%d, "
291 "run with libzmq >= 4.3.0\n", major, minor, patch, NULL);
292 return 0;
293 }
294 int gssapi_principal_nametype;
295 size_t option_len = sizeof (int);
296 zmq_getsockopt (zsock_resolve (self), ZMQ_GSSAPI_PRINCIPAL_NAMETYPE, &gssapi_principal_nametype, &option_len);
297 return gssapi_principal_nametype;
298 # else
299 return 0;
300 # endif
301 }
302
303 // --------------------------------------------------------------------------
304 // Set socket ZMQ_GSSAPI_SERVICE_PRINCIPAL_NAMETYPE value
305 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
306
307 void
308 zsock_set_gssapi_service_principal_nametype (void *self, int gssapi_service_principal_nametype)
309 {
310 assert (self);
311 # if defined (ZMQ_GSSAPI_SERVICE_PRINCIPAL_NAMETYPE)
312 int major, minor, patch;
313 zmq_version (&major, &minor, &patch);
314 if (ZMQ_MAKE_VERSION (major, minor, patch) < ZMQ_MAKE_VERSION (4, 3, 0)) {
315 zsys_error ("zsock gssapi_service_principal_nametype option not supported by libzmq version %d.%d.%d, "
316 "run with libzmq >= 4.3.0\n", major, minor, patch, NULL);
317 return;
318 }
319 int rc = zmq_setsockopt (zsock_resolve (self), ZMQ_GSSAPI_SERVICE_PRINCIPAL_NAMETYPE, &gssapi_service_principal_nametype, sizeof (int));
320 assert (rc == 0 || zmq_errno () == ETERM);
321 # endif
322 }
323
324
325 // --------------------------------------------------------------------------
326 // Return socket ZMQ_GSSAPI_SERVICE_PRINCIPAL_NAMETYPE value
327 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
328
329 int
330 zsock_gssapi_service_principal_nametype (void *self)
331 {
332 assert (self);
333 # if defined (ZMQ_GSSAPI_SERVICE_PRINCIPAL_NAMETYPE)
334 int major, minor, patch;
335 zmq_version (&major, &minor, &patch);
336 if (ZMQ_MAKE_VERSION (major, minor, patch) < ZMQ_MAKE_VERSION (4, 3, 0)) {
337 zsys_error ("zsock gssapi_service_principal_nametype option not supported by libzmq version %d.%d.%d, "
338 "run with libzmq >= 4.3.0\n", major, minor, patch, NULL);
339 return 0;
340 }
341 int gssapi_service_principal_nametype;
342 size_t option_len = sizeof (int);
343 zmq_getsockopt (zsock_resolve (self), ZMQ_GSSAPI_SERVICE_PRINCIPAL_NAMETYPE, &gssapi_service_principal_nametype, &option_len);
344 return gssapi_service_principal_nametype;
345 # else
346 return 0;
347 # endif
348 }
349
350 // --------------------------------------------------------------------------
351 // Set socket ZMQ_BINDTODEVICE value
352 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
353
354 void
355 zsock_set_bindtodevice (void *self, const char * bindtodevice)
356 {
357 assert (self);
358 # if defined (ZMQ_BINDTODEVICE)
359 int major, minor, patch;
360 zmq_version (&major, &minor, &patch);
361 if (ZMQ_MAKE_VERSION (major, minor, patch) < ZMQ_MAKE_VERSION (4, 3, 0)) {
362 zsys_error ("zsock bindtodevice option not supported by libzmq version %d.%d.%d, "
363 "run with libzmq >= 4.3.0\n", major, minor, patch, NULL);
364 return;
365 }
366 int rc = zmq_setsockopt (zsock_resolve (self), ZMQ_BINDTODEVICE, bindtodevice, strlen (bindtodevice));
367 assert (rc == 0 || zmq_errno () == ETERM);
368 # endif
369 }
370
371
372 // --------------------------------------------------------------------------
373 // Return socket ZMQ_BINDTODEVICE value
374 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
375
376 char *
377 zsock_bindtodevice (void *self)
378 {
379 assert (self);
380 # if defined (ZMQ_BINDTODEVICE)
381 int major, minor, patch;
382 zmq_version (&major, &minor, &patch);
383 if (ZMQ_MAKE_VERSION (major, minor, patch) < ZMQ_MAKE_VERSION (4, 3, 0)) {
384 zsys_error ("zsock bindtodevice option not supported by libzmq version %d.%d.%d, "
385 "run with libzmq >= 4.3.0\n", major, minor, patch, NULL);
386 return 0;
387 }
388 size_t option_len = 255;
389 char *bindtodevice = (char *) zmalloc (option_len);
390 zmq_getsockopt (zsock_resolve (self), ZMQ_BINDTODEVICE, bindtodevice, &option_len);
391 return (char *) bindtodevice;
392 # else
393 return NULL;
394 # endif
395 }
396
397
398 // --------------------------------------------------------------------------
22399 // Set socket ZMQ_HEARTBEAT_IVL value
23400 // *** GENERATED SOURCE CODE, DO NOT EDIT, SEE INSTRUCTIONS AT START ***
24401
34173794 // @selftest
34183795 zsock_t *self;
34193796 #if (ZMQ_VERSION_MAJOR >= 4)
3797 # if (ZMQ_VERSION_MINOR >= 3)
3798 # if defined (ZMQ_ROUTER_NOTIFY)
3799 self = zsock_new (ZMQ_ROUTER);
3800 assert (self);
3801 zsock_set_router_notify (self, 3);
3802 assert (zsock_router_notify (self) == 3);
3803 zsock_router_notify (self);
3804 zsock_destroy (&self);
3805 # endif
3806 # if defined (ZMQ_MULTICAST_LOOP)
3807 self = zsock_new (ZMQ_RADIO);
3808 assert (self);
3809 zsock_set_multicast_loop (self, 1);
3810 assert (zsock_multicast_loop (self) == 1);
3811 zsock_multicast_loop (self);
3812 zsock_destroy (&self);
3813 # endif
3814 # if defined (ZMQ_METADATA)
3815 self = zsock_new (ZMQ_DEALER);
3816 assert (self);
3817 zsock_set_metadata (self, "X-testkey:testvalue");
3818 char *metadata = zsock_metadata (self);
3819 assert (metadata);
3820 freen (metadata);
3821 zsock_destroy (&self);
3822 # endif
3823 # if defined (ZMQ_LOOPBACK_FASTPATH)
3824 self = zsock_new (ZMQ_DEALER);
3825 assert (self);
3826 zsock_set_loopback_fastpath (self, 1);
3827 assert (zsock_loopback_fastpath (self) == 1);
3828 zsock_loopback_fastpath (self);
3829 zsock_destroy (&self);
3830 # endif
3831 # if defined (ZMQ_ZAP_ENFORCE_DOMAIN)
3832 self = zsock_new (ZMQ_DEALER);
3833 assert (self);
3834 zsock_set_zap_enforce_domain (self, 1);
3835 assert (zsock_zap_enforce_domain (self) == 1);
3836 zsock_zap_enforce_domain (self);
3837 zsock_destroy (&self);
3838 # endif
3839 # endif
3840 #endif
3841
3842 #if (ZMQ_VERSION_MAJOR >= 4)
34203843 # if (ZMQ_VERSION_MINOR >= 2)
34213844 # if defined (ZMQ_HEARTBEAT_IVL)
34223845 self = zsock_new (ZMQ_DEALER);
2828 bool use_stdin = false;
2929 bool use_stderr = false;
3030 bool use_stdout = false;
31 bool abrt = false;
32 int quit = 0;
3133
3234 char *message = NULL;
3335
4042 #endif
4143 puts (" --stderr / -e output on stderr");
4244 puts (" --stdout / -o output on stdout");
45 puts (" --abrt / -a crash with SIGABRT on start");
4346 puts (" --verbose / -v verbose mode");
47 puts (" --quit / -q X quit after X seconds");
4448 puts (" --help / -h this information");
4549 return 0;
4650 }
6064 if (streq (argv [argn], "--verbose")
6165 || streq (argv [argn], "-v"))
6266 verbose = true;
67 else
68 if (streq (argv [argn], "--abrt")
69 || streq (argv [argn], "-a"))
70 abrt = true;
71 else
72 if (streq (argv [argn], "--quit")
73 || streq (argv [argn], "-q")) {
74 quit = atoi (argv [argn + 1]) * 1000;
75 ++argn;
76 }
6377 else
6478 if (argv [argn][0] == '-') {
6579 printf ("Unknown option: %s\n", argv [argn]);
86100 assert (r == 0);
87101 }
88102
103 if (abrt) {
104 if (verbose)
105 zsys_info ("Going to abort myself");
106 #if defined (__WINDOWS__)
107 assert (false); // TODO: how to do kill myelf on Windows?
108 #else
109 kill (getpid (), SIGABRT);
110 #endif
111 }
112
89113 // Insert main code here
114 int64_t start = zclock_mono ();
90115 while (!zsys_interrupted) {
91116 #if ! defined (__WINDOWS__)
92117 if (use_stdin) {
109134 fprintf (stdout, "%s\n", message);
110135
111136 zclock_sleep (50);
137 if (quit && zclock_mono () - start > quit) break;
112138 }
113139
114140 zfile_destroy (&stdinf);
8181 static size_t s_io_threads = 1; // ZSYS_IO_THREADS=1
8282 static int s_thread_sched_policy = -1; // ZSYS_THREAD_SCHED_POLICY=-1
8383 static int s_thread_priority = -1; // ZSYS_THREAD_PRIORITY=-1
84 static int s_thread_name_prefix = -1; // ZSYS_THREAD_NAME_PREFIX=-1
8485 static size_t s_max_sockets = 1024; // ZSYS_MAX_SOCKETS=1024
8586 static int s_max_msgsz = INT_MAX; // ZSYS_MAX_MSGSZ=INT_MAX
8687 static int64_t s_file_stable_age_msec = S_DEFAULT_ZSYS_FILE_STABLE_AGE_MSEC;
132133 // Mutex to guard socket counter
133134 static zsys_mutex_t s_mutex;
134135
136 // Implementation for the zsys_vprintf() which is known from legacy
137 // and poses as a stable interface now.
138 static inline
139 char *
140 s_zsys_vprintf_hint (int hint, const char *format, va_list argptr);
135141
136142 // --------------------------------------------------------------------------
137143 // Initialize CZMQ zsys layer; this happens automatically when you create
256262 zsys_set_thread_sched_policy (atoi (getenv ("ZSYS_THREAD_SCHED_POLICY")));
257263 else
258264 zsys_set_thread_sched_policy (s_thread_sched_policy);
265
266 if (getenv ("ZSYS_THREAD_NAME_PREFIX"))
267 zsys_set_thread_name_prefix (atoi (getenv ("ZSYS_THREAD_NAME_PREFIX")));
268 else
269 zsys_set_thread_name_prefix (s_thread_name_prefix);
259270
260271 return s_process_ctx;
261272 }
311322 s_io_threads = 1;
312323 s_thread_sched_policy = -1;
313324 s_thread_priority = -1;
325 s_thread_name_prefix = -1;
314326 s_max_sockets = 1024;
315327 s_max_msgsz = INT_MAX;
316328 s_file_stable_age_msec = S_DEFAULT_ZSYS_FILE_STABLE_AGE_MSEC;
909921 // --------------------------------------------------------------------------
910922 // Format a string using printf formatting, returning a freshly allocated
911923 // buffer. If there was insufficient memory, returns NULL. Free the returned
924 // string using zstr_free(). The hinted version allows to optimize by using
925 // a larger starting buffer size (known to/assumed by the developer) and so
926 // avoid reallocations.
927
928 char *
929 zsys_sprintf_hint (int hint, const char *format, ...)
930 {
931 va_list argptr;
932 va_start (argptr, format);
933 char *string = s_zsys_vprintf_hint (hint, format, argptr);
934 va_end (argptr);
935 return (string);
936 }
937
938 // --------------------------------------------------------------------------
939 // Format a string using printf formatting, returning a freshly allocated
940 // buffer. If there was insufficient memory, returns NULL. Free the returned
912941 // string using zstr_free().
913942
914943 char *
915944 zsys_sprintf (const char *format, ...)
916945 {
946 // Effectively this is a copy of the small zsys_sprintf_hint with
947 // hardcoded hint value; this is is cheaper than parsing va_list
948 // several times to just call the other implementation cleanly.
917949 va_list argptr;
918950 va_start (argptr, format);
919 char *string = zsys_vprintf (format, argptr);
951 char *string = s_zsys_vprintf_hint (256, format, argptr);
920952 va_end (argptr);
921953 return (string);
922954 }
923
924955
925956 // --------------------------------------------------------------------------
926957 // Format a string with variable arguments, returning a freshly allocated
927958 // buffer. If there was insufficient memory, returns NULL. Free the returned
928959 // string using zstr_free().
929960
961 static inline
930962 char *
931 zsys_vprintf (const char *format, va_list argptr)
932 {
933 int size = 256;
963 s_zsys_vprintf_hint (int hint, const char *format, va_list argptr)
964 {
965 if (hint <= 0) {
966 // The hint is not a hard requrement so no error here.
967 // Just fall back to legacy default.
968 hint = 256;
969 }
970 // Must use int "size" to compare to "required" (from vsnprintf)
971 int size = hint;
934972 char *string = (char *) malloc (size);
935973 if (!string)
936974 return NULL;
952990 va_end (my_argptr);
953991 }
954992 #endif
993 if (required < 0) {
994 // vsnprintf failed at unknown point; at least prohibit
995 // accesses by string consumers into random memory
996 string [hint - 1] = '\0';
997 return string;
998 }
955999 // If formatted string cannot fit into small string, reallocate a
956 // larger buffer for it.
957 if (required >= size) {
1000 // larger buffer for it. If it did fit, we only called vsnprintf()
1001 // once and already have the good result, so pre-counting with a
1002 // NULL string would not be beneficial for shorter texts (always
1003 // calling vsnprintf() twice then).
1004 if (required >= hint) {
9581005 size = required + 1;
9591006 freen (string);
9601007 string = (char *) malloc (size);
9671014 return string;
9681015 }
9691016
1017 char *
1018 zsys_vprintf (const char *format, va_list argptr)
1019 {
1020 return (s_zsys_vprintf_hint(256, format, argptr));
1021 }
9701022
9711023 // --------------------------------------------------------------------------
9721024 // Create a UDP beacon socket; if the routable option is true, uses
9791031 // We haven't implemented multicast yet
9801032 assert (!routable);
9811033 SOCKET udpsock;
1034 int type = SOCK_DGRAM;
1035 #ifdef CZMQ_HAVE_SOCK_CLOEXEC
1036 // Ensure socket is closed by exec() functions.
1037 type |= SOCK_CLOEXEC;
1038 #endif
1039
9821040 if (zsys_ipv6 ())
983 udpsock = socket (AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
1041 udpsock = socket (AF_INET6, type, IPPROTO_UDP);
9841042 else
985 udpsock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
1043 udpsock = socket (AF_INET, type, IPPROTO_UDP);
9861044 if (udpsock == INVALID_SOCKET) {
9871045 zsys_socket_error ("socket");
9881046 return INVALID_SOCKET;
9891047 }
1048
1049 // On Windows, preventing sockets to be inherited by child processes.
1050 #if defined (__WINDOWS__) && defined (HANDLE_FLAG_INHERIT)
1051 if (!SetHandleInformation ((HANDLE) udpsock, HANDLE_FLAG_INHERIT, 0))
1052 zsys_socket_error ("SetHandleInformation (HANDLE_FLAG_INHERIT)");
1053 #endif
1054
9901055 // Ask operating system for broadcast permissions on socket
9911056 int on = 1;
9921057 if (setsockopt (udpsock, SOL_SOCKET, SO_BROADCAST,
14031468
14041469
14051470 // --------------------------------------------------------------------------
1471 // Configure the numeric prefix to each thread created for the internal
1472 // context's thread pool. This option is only supported on Linux.
1473 // If the environment variable ZSYS_THREAD_NAME_PREFIX is defined, that
1474 // provides the default.
1475 // Note that this method is valid only before any socket is created.
1476
1477 void
1478 zsys_set_thread_name_prefix (int prefix)
1479 {
1480 if (prefix < 0)
1481 return;
1482
1483 zsys_init ();
1484 ZMUTEX_LOCK (s_mutex);
1485 // If the app is misusing this method, burn it with fire
1486 if (s_open_sockets)
1487 zsys_error ("zsys_set_thread_name_prefix() is not valid after"
1488 " creating sockets");
1489 assert (s_open_sockets == 0);
1490 s_thread_name_prefix = prefix;
1491 #if defined (ZMQ_THREAD_NAME_PREFIX)
1492 zmq_ctx_set (s_process_ctx, ZMQ_THREAD_NAME_PREFIX, s_thread_name_prefix);
1493 #endif
1494 ZMUTEX_UNLOCK (s_mutex);
1495 }
1496
1497 // --------------------------------------------------------------------------
1498 // Return ZMQ_THREAD_NAME_PREFIX option.
1499 int
1500 zsys_thread_name_prefix ()
1501 {
1502 zsys_init ();
1503 ZMUTEX_LOCK (s_mutex);
1504 #if defined (ZMQ_THREAD_NAME_PREFIX)
1505 s_thread_name_prefix = zmq_ctx_get (s_process_ctx, ZMQ_THREAD_NAME_PREFIX);
1506 #endif
1507 ZMUTEX_UNLOCK (s_mutex);
1508 return s_thread_name_prefix;
1509 }
1510
1511
1512 // --------------------------------------------------------------------------
1513 // Adds a specific CPU to the affinity list of the ZMQ context thread pool.
1514 // This option is only supported on Linux.
1515 // Note that this method is valid only before any socket is created.
1516
1517 void
1518 zsys_thread_affinity_cpu_add (int cpu)
1519 {
1520 if (cpu < 0)
1521 return;
1522
1523 zsys_init ();
1524 ZMUTEX_LOCK (s_mutex);
1525 // If the app is misusing this method, burn it with fire
1526 if (s_open_sockets)
1527 zsys_error ("zsys_set_thread_sched_policy() is not valid after"
1528 " creating sockets");
1529 assert (s_open_sockets == 0);
1530 #if defined (ZMQ_THREAD_AFFINITY_CPU_ADD)
1531 zmq_ctx_set (s_process_ctx, ZMQ_THREAD_AFFINITY_CPU_ADD, cpu);
1532 #endif
1533 ZMUTEX_UNLOCK (s_mutex);
1534 }
1535
1536
1537 // --------------------------------------------------------------------------
1538 // Removes a specific CPU to the affinity list of the ZMQ context thread pool.
1539 // This option is only supported on Linux.
1540 // Note that this method is valid only before any socket is created.
1541
1542 void
1543 zsys_thread_affinity_cpu_remove (int cpu)
1544 {
1545 if (cpu < 0)
1546 return;
1547
1548 zsys_init ();
1549 ZMUTEX_LOCK (s_mutex);
1550 // If the app is misusing this method, burn it with fire
1551 if (s_open_sockets)
1552 zsys_error ("zsys_set_thread_sched_policy() is not valid after"
1553 " creating sockets");
1554 assert (s_open_sockets == 0);
1555 #if defined (ZMQ_THREAD_AFFINITY_CPU_REMOVE)
1556 zmq_ctx_set (s_process_ctx, ZMQ_THREAD_AFFINITY_CPU_REMOVE, cpu);
1557 #endif
1558 ZMUTEX_UNLOCK (s_mutex);
1559 }
1560
1561
1562 // --------------------------------------------------------------------------
14061563 // Configure the scheduling priority of the ZMQ context thread pool.
14071564 // Not available on Windows. See the sched_setscheduler man page or sched.h
14081565 // for more information. If the environment variable ZSYS_THREAD_PRIORITY is
18231980 zsys_auto_use_fd (void)
18241981 {
18251982 return s_auto_use_fd;
1983 }
1984
1985 typedef enum _zsprintf_s {
1986 FIND_PERCENT,
1987 FIND_KEY,
1988 FIND_FORMAT,
1989 END
1990 } zsprintf_s;
1991
1992 typedef void* (*zsys_lookup_fn)(void *, const char*);
1993
1994 static char *
1995 s_zsys_zprintf (const char *format, void *args, zsys_lookup_fn lookup_fn, bool validate)
1996 {
1997 assert (format);
1998 assert (args);
1999 zchunk_t *chunk = zchunk_new (NULL, strlen (format) * 1.5);
2000 assert (chunk);
2001 char *ret = NULL;
2002
2003 zsprintf_s state = FIND_PERCENT;
2004 size_t pos = 0;
2005 char *key = NULL;
2006
2007 while (state != END)
2008 {
2009
2010 if (pos >= strlen (format))
2011 break;
2012
2013 switch (state) {
2014 case FIND_PERCENT:
2015 {
2016
2017 //zsys_debug ("\tstate=FIND_PERCENT, format+%zu=%s", pos, format+pos);
2018 char *percent = strchr ((char*)(format) + pos, '%');
2019
2020 if (!percent) {
2021 //zsys_debug ("!percent");
2022 zchunk_extend (chunk, (format+pos), strlen (format) - pos);
2023 state = END;
2024 }
2025 else
2026 if (*(percent+1) == '%') {
2027 size_t idx = percent - format;
2028 //zsys_debug ("*(percent+1)=='%%':\tidx=%zu, format+%zu=%s", idx, pos, format+pos);
2029 if (idx - pos > 0) {
2030 //zsys_debug ("*(percent+1)=='%%':\t#2pos=%zu, idx-pos=%zu", pos, idx-pos);
2031 zchunk_extend (chunk, format+pos, idx - pos);
2032 pos += (idx-pos);
2033 //zsys_debug ("*(percent+1)=='%%':\t#2pos=%zu, idx-pos=%zu", pos, idx-pos);
2034 }
2035 zchunk_extend (chunk, "%", 1);
2036 pos += 2;
2037 }
2038 else
2039 if (*(percent+1) == '(') {
2040 size_t idx = percent - format;
2041 //zsys_debug ("*(percent+1) == '(': idx=%zu, pos=%zu", idx, pos);
2042 if (idx - pos > 0) {
2043 zchunk_extend (chunk, (format+pos), idx - pos);
2044 pos += (idx-pos);
2045 }
2046 //zsys_debug ("*(percent+1) == '(': idx=%zu, pos=%zu", idx, pos);
2047 state = FIND_KEY;
2048 }
2049 else {
2050 //zsys_debug ("else");
2051 size_t idx = percent - format;
2052 zchunk_extend (chunk, (format+pos), idx - pos);
2053 pos += (idx-pos);
2054 }
2055 }
2056 break;
2057 case FIND_KEY:
2058 {
2059 //zsys_debug ("\tstate=FIND_KEY, format+%zu=%s", pos, format+pos);
2060 char *key_end = strchr ((char*)(format)+pos, ')');
2061 if (!key_end) {
2062 zchunk_extend (chunk, (format+pos), strlen (format) - pos);
2063 state = END;
2064 }
2065 pos += 2;
2066 size_t idx = key_end - format;
2067 size_t key_len = idx - pos;
2068 if (key_len == 0) {
2069 zchunk_extend (chunk, "()", 2);
2070 pos += 2;
2071 state = FIND_PERCENT;
2072 }
2073 zstr_free (&key);
2074 key = (char*) zmalloc (key_len + 1);
2075 memcpy ((void*) key, format+pos, key_len);
2076
2077 if (! lookup_fn (args, key)) {
2078 char *ret = NULL;
2079 if (validate)
2080 ret = zsys_sprintf ("Key '%s' not found in hash", key);
2081 zstr_free (&key);
2082 zchunk_destroy (&chunk);
2083 return ret;
2084 }
2085 pos += key_len + 1;
2086 state = FIND_FORMAT;
2087 }
2088 break;
2089 case FIND_FORMAT:
2090 {
2091 //zsys_debug ("\tstate=FIND_FORMAT, format+%zu=%s", pos, format+pos);
2092 if (*(format+pos) != 's') {
2093 char *ret = NULL;
2094 if (validate)
2095 ret = zsys_sprintf ("%s: arguments other than 's' are not implemented", key);
2096 zstr_free (&key);
2097 zchunk_destroy (&chunk);
2098 return ret;
2099 }
2100 pos += 1;
2101 char *v = (char *) lookup_fn (args, key);
2102 zchunk_extend (chunk, v, strlen (v));
2103 state = FIND_PERCENT;
2104 }
2105 break;
2106 case END:
2107 break;
2108 }
2109 }
2110 zstr_free (&key);
2111
2112 //FIXME: is it needed?
2113 zchunk_extend (chunk, "\0", 1);
2114
2115 if (!validate) {
2116 ret = strdup ((char*) zchunk_data (chunk));
2117 zchunk_destroy (&chunk);
2118 return ret;
2119 }
2120
2121 zchunk_destroy (&chunk);
2122 return NULL;
2123 }
2124
2125
2126 // printf based on zhash_t
2127 char *
2128 zsys_zprintf (const char *format, zhash_t *args)
2129 {
2130 return s_zsys_zprintf (format, (void*) args, (zsys_lookup_fn) zhash_lookup, false);
2131 }
2132
2133 // return missing key or other format errors as new allocated string or NULL
2134 char *
2135 zsys_zprintf_error (const char *format, zhash_t *args)
2136 {
2137 return s_zsys_zprintf (format, (void*) args, (zsys_lookup_fn) zhash_lookup, true);
2138 }
2139
2140 static void *
2141 s_zconfig_lookup (void *container, const char *key)
2142 {
2143 zconfig_t *root = (zconfig_t*) container;
2144 zconfig_t *child = zconfig_locate (root, key);
2145 if (child)
2146 return zconfig_value (child);
2147 return NULL;
2148 }
2149
2150 // printf based on zconfig
2151 char *
2152 zsys_zplprintf (const char *format, zconfig_t *args)
2153 {
2154 return s_zsys_zprintf (format, (void*) args, (zsys_lookup_fn) s_zconfig_lookup, false);
2155 }
2156
2157 // return missing key or other format errors as new allocated string or NULL
2158 char *
2159 zsys_zplprintf_error (const char *format, zconfig_t *args)
2160 {
2161 return s_zsys_zprintf (format, (void*) args, (zsys_lookup_fn) s_zconfig_lookup, true);
18262162 }
18272163
18282164
20932429 zsys_set_ipv6 (0);
20942430 zsys_set_thread_priority (-1);
20952431 zsys_set_thread_sched_policy (-1);
2432 zsys_set_thread_name_prefix (0);
2433 assert (0 == zsys_thread_name_prefix());
2434 zsys_thread_affinity_cpu_add (0);
2435 zsys_thread_affinity_cpu_remove (0);
20962436 zsys_set_zero_copy_recv(0);
20972437 assert (0 == zsys_zero_copy_recv());
20982438 zsys_set_zero_copy_recv(1);
22722612 zstr_free (&received);
22732613 }
22742614 zsys_close (logger, NULL, 0);
2615
2616 {
2617 // zhash based printf
2618 zhash_t *args = zhash_new ();
2619 zhash_insert (args, "key", "value");
2620 zhash_insert (args, "ham", "spam");
2621
2622 char *str = zsys_zprintf ("plain string", args);
2623 assert (streq (str, "plain string"));
2624 zstr_free (&str);
2625
2626 str = zsys_zprintf ("%%a%%", args);
2627 assert (streq (str, "%a%"));
2628 zstr_free (&str);
2629
2630 str = zsys_zprintf ("VALUE=%(key)s123", args);
2631 assert (streq (str, "VALUE=value123"));
2632 zstr_free (&str);
2633
2634 str = zsys_zprintf ("VALUE=%(key)s123, %(ham)s, %(ham)s, %%(nospam)s!!!", args);
2635 assert (streq (str, "VALUE=value123, spam, spam, %(nospam)s!!!"));
2636 zstr_free (&str);
2637
2638 str = zsys_zprintf ("VALUE=%(nokey)s123, %(ham)s, %(ham)s, %%(nospam)s!!!", args);
2639 assert (!str);
2640
2641 str = zsys_zprintf_error ("VALUE=%(nokey)s123, %(ham)s, %(ham)s, %%(nospam)s!!!", args);
2642 assert (streq (str, "Key 'nokey' not found in hash"));
2643 zstr_free (&str);
2644
2645 str = zsys_zprintf ("VALUE=%(key)s/%%S", args);
2646 assert (streq (str, "VALUE=value/%S"));
2647 zstr_free (&str);
2648
2649 zhash_destroy (&args);
2650
2651 //ZPL based printf
2652 zconfig_t *root = zconfig_new ("root", NULL);
2653 zconfig_put (root, "zsp", "");
2654 zconfig_put (root, "zsp/return_code", "0");
2655
2656 str = zsys_zplprintf ("return_code=%(zsp/return_code)s", root);
2657 assert (streq (str, "return_code=0"));
2658 zstr_free (&str);
2659
2660 zconfig_destroy (&root);
2661 }
2662
22752663 // @end
22762664
22772665 zsys_set_auto_use_fd (1);
738738 assert (ret == 0);
739739
740740 // There is a lot you can do with regular expression but matching routes
741 // of arbitrary length wont work. Therefore we make use of the asterisk
741 // of arbitrary length won't work. Therefore we make use of the asterisk
742742 // operator. Just place it at the end of your route, e.g. '/config/bar/*'.
743743 ret = ztrie_insert_route (self, "/config/bar/*", NULL, NULL);
744744 assert (ret == 0);
2222
2323 #include "czmq_classes.h"
2424
25 #if defined (__WINDOWS__) && !defined (HAVE_UUID)
26 # define HAVE_UUID 1
27 #endif
28 #if defined (__UTYPE_OSX) && !defined (HAVE_UUID)
29 # define HAVE_UUID 1
30 #endif
31 #if defined (HAVE_UUID) || defined (__UTYPE_FREEBSD)
32 # if defined (__UTYPE_FREEBSD) || defined (__UTYPE_NETBSD) || defined(__UTYPE_OPENBSD)
33 # include <uuid.h>
34 # elif defined __UTYPE_HPUX
35 # include <dce/uuid.h>
36 # elif defined (__UNIX__)
37 # include <uuid/uuid.h>
38 # endif
39 #endif
40
2541 // Structure of our class
2642
2743 struct _zuuid_t {
4662 assert (sizeof (uuid) == ZUUID_LEN);
4763 UuidCreate (&uuid);
4864 zuuid_set (self, (byte *) &uuid);
49 #elif defined (HAVE_UUID) && !defined (__UTYPE_FREEBSD)
65 #elif defined (HAVE_UUID)
5066 uuid_t uuid;
5167 assert (sizeof (uuid) == ZUUID_LEN);
5268 uuid_generate (uuid);