1ZSYS(3) CZMQ Manual ZSYS(3)
2
3
4
6 zsys - Class for system-level methods
7
9 // This is a stable class, and may not change except for emergencies. It
10 // is provided in stable builds.
11 // This class has draft methods, which may change over time. They are not
12 // in stable releases, by default. Use --enable-drafts to enable.
13 // Callback for interrupt signal handler
14 typedef void (zsys_handler_fn) (
15 int signal_value);
16
17 // Initialize CZMQ zsys layer; this happens automatically when you create
18 // a socket or an actor; however this call lets you force initialization
19 // earlier, so e.g. logging is properly set-up before you start working.
20 // Not threadsafe, so call only from main thread. Safe to call multiple
21 // times. Returns global CZMQ context.
22 CZMQ_EXPORT void *
23 zsys_init (void);
24
25 // Optionally shut down the CZMQ zsys layer; this normally happens automatically
26 // when the process exits; however this call lets you force a shutdown
27 // earlier, avoiding any potential problems with atexit() ordering, especially
28 // with Windows dlls.
29 CZMQ_EXPORT void
30 zsys_shutdown (void);
31
32 // Get a new ZMQ socket, automagically creating a ZMQ context if this is
33 // the first time. Caller is responsible for destroying the ZMQ socket
34 // before process exits, to avoid a ZMQ deadlock. Note: you should not use
35 // this method in CZMQ apps, use zsock_new() instead.
36 // *** This is for CZMQ internal use only and may change arbitrarily ***
37 CZMQ_EXPORT void *
38 zsys_socket (int type, const char *filename, size_t line_nbr);
39
40 // Destroy/close a ZMQ socket. You should call this for every socket you
41 // create using zsys_socket().
42 // *** This is for CZMQ internal use only and may change arbitrarily ***
43 CZMQ_EXPORT int
44 zsys_close (void *handle, const char *filename, size_t line_nbr);
45
46 // Return ZMQ socket name for socket type
47 // *** This is for CZMQ internal use only and may change arbitrarily ***
48 CZMQ_EXPORT char *
49 zsys_sockname (int socktype);
50
51 // Create a pipe, which consists of two PAIR sockets connected over inproc.
52 // The pipe is configured to use the zsys_pipehwm setting. Returns the
53 // frontend socket successful, NULL if failed.
54 CZMQ_EXPORT zsock_t *
55 zsys_create_pipe (zsock_t **backend_p);
56
57 // Set interrupt handler; this saves the default handlers so that a
58 // zsys_handler_reset () can restore them. If you call this multiple times
59 // then the last handler will take affect. If handler_fn is NULL, disables
60 // default SIGINT/SIGTERM handling in CZMQ.
61 CZMQ_EXPORT void
62 zsys_handler_set (zsys_handler_fn *handler_fn);
63
64 // Reset interrupt handler, call this at exit if needed
65 CZMQ_EXPORT void
66 zsys_handler_reset (void);
67
68 // Set default interrupt handler, so Ctrl-C or SIGTERM will set
69 // zsys_interrupted. Idempotent; safe to call multiple times.
70 // Can be supressed by ZSYS_SIGHANDLER=false
71 // *** This is for CZMQ internal use only and may change arbitrarily ***
72 CZMQ_EXPORT void
73 zsys_catch_interrupts (void);
74
75 // Return 1 if file exists, else zero
76 CZMQ_EXPORT bool
77 zsys_file_exists (const char *filename);
78
79 // Return file modification time. Returns 0 if the file does not exist.
80 CZMQ_EXPORT time_t
81 zsys_file_modified (const char *filename);
82
83 // Return file mode; provides at least support for the POSIX S_ISREG(m)
84 // and S_ISDIR(m) macros and the S_IRUSR and S_IWUSR bits, on all boxes.
85 // Returns a mode_t cast to int, or -1 in case of error.
86 CZMQ_EXPORT int
87 zsys_file_mode (const char *filename);
88
89 // Delete file. Does not complain if the file is absent
90 CZMQ_EXPORT int
91 zsys_file_delete (const char *filename);
92
93 // Check if file is 'stable'
94 CZMQ_EXPORT bool
95 zsys_file_stable (const char *filename);
96
97 // Create a file path if it doesn't exist. The file path is treated as
98 // printf format.
99 CZMQ_EXPORT int
100 zsys_dir_create (const char *pathname, ...);
101
102 // Remove a file path if empty; the pathname is treated as printf format.
103 CZMQ_EXPORT int
104 zsys_dir_delete (const char *pathname, ...);
105
106 // Move to a specified working directory. Returns 0 if OK, -1 if this failed.
107 CZMQ_EXPORT int
108 zsys_dir_change (const char *pathname);
109
110 // Set private file creation mode; all files created from here will be
111 // readable/writable by the owner only.
112 CZMQ_EXPORT void
113 zsys_file_mode_private (void);
114
115 // Reset default file creation mode; all files created from here will use
116 // process file mode defaults.
117 CZMQ_EXPORT void
118 zsys_file_mode_default (void);
119
120 // Return the CZMQ version for run-time API detection; returns version
121 // number into provided fields, providing reference isn't null in each case.
122 CZMQ_EXPORT void
123 zsys_version (int *major, int *minor, int *patch);
124
125 // Format a string using printf formatting, returning a freshly allocated
126 // buffer. If there was insufficient memory, returns NULL. Free the returned
127 // string using zstr_free().
128 CZMQ_EXPORT char *
129 zsys_sprintf (const char *format, ...);
130
131 // Format a string with a va_list argument, returning a freshly allocated
132 // buffer. If there was insufficient memory, returns NULL. Free the returned
133 // string using zstr_free().
134 CZMQ_EXPORT char *
135 zsys_vprintf (const char *format, va_list argptr);
136
137 // Create UDP beacon socket; if the routable option is true, uses
138 // multicast (not yet implemented), else uses broadcast. This method
139 // and related ones might _eventually_ be moved to a zudp class.
140 // *** This is for CZMQ internal use only and may change arbitrarily ***
141 CZMQ_EXPORT SOCKET
142 zsys_udp_new (bool routable);
143
144 // Close a UDP socket
145 // *** This is for CZMQ internal use only and may change arbitrarily ***
146 CZMQ_EXPORT int
147 zsys_udp_close (SOCKET handle);
148
149 // Send zframe to UDP socket, return -1 if sending failed due to
150 // interface having disappeared (happens easily with WiFi)
151 // *** This is for CZMQ internal use only and may change arbitrarily ***
152 CZMQ_EXPORT int
153 zsys_udp_send (SOCKET udpsock, zframe_t *frame, inaddr_t *address, int addrlen);
154
155 // Receive zframe from UDP socket, and set address of peer that sent it
156 // The peername must be a char [INET_ADDRSTRLEN] array if IPv6 is disabled or
157 // NI_MAXHOST if it's enabled. Returns NULL when failing to get peer address.
158 // *** This is for CZMQ internal use only and may change arbitrarily ***
159 CZMQ_EXPORT zframe_t *
160 zsys_udp_recv (SOCKET udpsock, char *peername, int peerlen);
161
162 // Handle an I/O error on some socket operation; will report and die on
163 // fatal errors, and continue silently on "try again" errors.
164 // *** This is for CZMQ internal use only and may change arbitrarily ***
165 CZMQ_EXPORT void
166 zsys_socket_error (const char *reason);
167
168 // Return current host name, for use in public tcp:// endpoints. Caller gets
169 // a freshly allocated string, should free it using zstr_free(). If the host
170 // name is not resolvable, returns NULL.
171 CZMQ_EXPORT char *
172 zsys_hostname (void);
173
174 // Move the current process into the background. The precise effect depends
175 // on the operating system. On POSIX boxes, moves to a specified working
176 // directory (if specified), closes all file handles, reopens stdin, stdout,
177 // and stderr to the null device, and sets the process to ignore SIGHUP. On
178 // Windows, does nothing. Returns 0 if OK, -1 if there was an error.
179 CZMQ_EXPORT int
180 zsys_daemonize (const char *workdir);
181
182 // Drop the process ID into the lockfile, with exclusive lock, and switch
183 // the process to the specified group and/or user. Any of the arguments
184 // may be null, indicating a no-op. Returns 0 on success, -1 on failure.
185 // Note if you combine this with zsys_daemonize, run after, not before
186 // that method, or the lockfile will hold the wrong process ID.
187 CZMQ_EXPORT int
188 zsys_run_as (const char *lockfile, const char *group, const char *user);
189
190 // Returns true if the underlying libzmq supports CURVE security.
191 // Uses a heuristic probe according to the version of libzmq being used.
192 CZMQ_EXPORT bool
193 zsys_has_curve (void);
194
195 // Configure the number of I/O threads that ZeroMQ will use. A good
196 // rule of thumb is one thread per gigabit of traffic in or out. The
197 // default is 1, sufficient for most applications. If the environment
198 // variable ZSYS_IO_THREADS is defined, that provides the default.
199 // Note that this method is valid only before any socket is created.
200 CZMQ_EXPORT void
201 zsys_set_io_threads (size_t io_threads);
202
203 // Configure the scheduling policy of the ZMQ context thread pool.
204 // Not available on Windows. See the sched_setscheduler man page or sched.h
205 // for more information. If the environment variable ZSYS_THREAD_SCHED_POLICY
206 // is defined, that provides the default.
207 // Note that this method is valid only before any socket is created.
208 CZMQ_EXPORT void
209 zsys_set_thread_sched_policy (int policy);
210
211 // Configure the scheduling priority of the ZMQ context thread pool.
212 // Not available on Windows. See the sched_setscheduler man page or sched.h
213 // for more information. If the environment variable ZSYS_THREAD_PRIORITY is
214 // defined, that provides the default.
215 // Note that this method is valid only before any socket is created.
216 CZMQ_EXPORT void
217 zsys_set_thread_priority (int priority);
218
219 // Configure the number of sockets that ZeroMQ will allow. The default
220 // is 1024. The actual limit depends on the system, and you can query it
221 // by using zsys_socket_limit (). A value of zero means "maximum".
222 // Note that this method is valid only before any socket is created.
223 CZMQ_EXPORT void
224 zsys_set_max_sockets (size_t max_sockets);
225
226 // Return maximum number of ZeroMQ sockets that the system will support.
227 CZMQ_EXPORT size_t
228 zsys_socket_limit (void);
229
230 // Configure the maximum allowed size of a message sent.
231 // The default is INT_MAX.
232 CZMQ_EXPORT void
233 zsys_set_max_msgsz (int max_msgsz);
234
235 // Return maximum message size.
236 CZMQ_EXPORT int
237 zsys_max_msgsz (void);
238
239 // Configure the default linger timeout in msecs for new zsock instances.
240 // You can also set this separately on each zsock_t instance. The default
241 // linger time is zero, i.e. any pending messages will be dropped. If the
242 // environment variable ZSYS_LINGER is defined, that provides the default.
243 // Note that process exit will typically be delayed by the linger time.
244 CZMQ_EXPORT void
245 zsys_set_linger (size_t linger);
246
247 // Configure the default outgoing pipe limit (HWM) for new zsock instances.
248 // You can also set this separately on each zsock_t instance. The default
249 // HWM is 1,000, on all versions of ZeroMQ. If the environment variable
250 // ZSYS_SNDHWM is defined, that provides the default. Note that a value of
251 // zero means no limit, i.e. infinite memory consumption.
252 CZMQ_EXPORT void
253 zsys_set_sndhwm (size_t sndhwm);
254
255 // Configure the default incoming pipe limit (HWM) for new zsock instances.
256 // You can also set this separately on each zsock_t instance. The default
257 // HWM is 1,000, on all versions of ZeroMQ. If the environment variable
258 // ZSYS_RCVHWM is defined, that provides the default. Note that a value of
259 // zero means no limit, i.e. infinite memory consumption.
260 CZMQ_EXPORT void
261 zsys_set_rcvhwm (size_t rcvhwm);
262
263 // Configure the default HWM for zactor internal pipes; this is set on both
264 // ends of the pipe, for outgoing messages only (sndhwm). The default HWM is
265 // 1,000, on all versions of ZeroMQ. If the environment var ZSYS_ACTORHWM is
266 // defined, that provides the default. Note that a value of zero means no
267 // limit, i.e. infinite memory consumption.
268 CZMQ_EXPORT void
269 zsys_set_pipehwm (size_t pipehwm);
270
271 // Return the HWM for zactor internal pipes.
272 CZMQ_EXPORT size_t
273 zsys_pipehwm (void);
274
275 // Configure use of IPv6 for new zsock instances. By default sockets accept
276 // and make only IPv4 connections. When you enable IPv6, sockets will accept
277 // and connect to both IPv4 and IPv6 peers. You can override the setting on
278 // each zsock_t instance. The default is IPv4 only (ipv6 set to 0). If the
279 // environment variable ZSYS_IPV6 is defined (as 1 or 0), this provides the
280 // default. Note: has no effect on ZMQ v2.
281 CZMQ_EXPORT void
282 zsys_set_ipv6 (int ipv6);
283
284 // Return use of IPv6 for zsock instances.
285 CZMQ_EXPORT int
286 zsys_ipv6 (void);
287
288 // Set network interface name to use for broadcasts, particularly zbeacon.
289 // This lets the interface be configured for test environments where required.
290 // For example, on Mac OS X, zbeacon cannot bind to 255.255.255.255 which is
291 // the default when there is no specified interface. If the environment
292 // variable ZSYS_INTERFACE is set, use that as the default interface name.
293 // Setting the interface to "*" means "use all available interfaces".
294 CZMQ_EXPORT void
295 zsys_set_interface (const char *value);
296
297 // Return network interface to use for broadcasts, or "" if none was set.
298 CZMQ_EXPORT const char *
299 zsys_interface (void);
300
301 // Set IPv6 address to use zbeacon socket, particularly for receiving zbeacon.
302 // This needs to be set IPv6 is enabled as IPv6 can have multiple addresses
303 // on a given interface. If the environment variable ZSYS_IPV6_ADDRESS is set,
304 // use that as the default IPv6 address.
305 CZMQ_EXPORT void
306 zsys_set_ipv6_address (const char *value);
307
308 // Return IPv6 address to use for zbeacon reception, or "" if none was set.
309 CZMQ_EXPORT const char *
310 zsys_ipv6_address (void);
311
312 // Set IPv6 milticast address to use for sending zbeacon messages. This needs
313 // to be set if IPv6 is enabled. If the environment variable
314 // ZSYS_IPV6_MCAST_ADDRESS is set, use that as the default IPv6 multicast
315 // address.
316 CZMQ_EXPORT void
317 zsys_set_ipv6_mcast_address (const char *value);
318
319 // Return IPv6 multicast address to use for sending zbeacon, or "" if none was
320 // set.
321 CZMQ_EXPORT const char *
322 zsys_ipv6_mcast_address (void);
323
324 // Configure the automatic use of pre-allocated FDs when creating new sockets.
325 // If 0 (default), nothing will happen. Else, when a new socket is bound, the
326 // system API will be used to check if an existing pre-allocated FD with a
327 // matching port (if TCP) or path (if IPC) exists, and if it does it will be
328 // set via the ZMQ_USE_FD socket option so that the library will use it
329 // instead of creating a new socket.
330 CZMQ_EXPORT void
331 zsys_set_auto_use_fd (int auto_use_fd);
332
333 // Return use of automatic pre-allocated FDs for zsock instances.
334 CZMQ_EXPORT int
335 zsys_auto_use_fd (void);
336
337 // Set log identity, which is a string that prefixes all log messages sent
338 // by this process. The log identity defaults to the environment variable
339 // ZSYS_LOGIDENT, if that is set.
340 CZMQ_EXPORT void
341 zsys_set_logident (const char *value);
342
343 // Set stream to receive log traffic. By default, log traffic is sent to
344 // stdout. If you set the stream to NULL, no stream will receive the log
345 // traffic (it may still be sent to the system facility).
346 CZMQ_EXPORT void
347 zsys_set_logstream (FILE *stream);
348
349 // Sends log output to a PUB socket bound to the specified endpoint. To
350 // collect such log output, create a SUB socket, subscribe to the traffic
351 // you care about, and connect to the endpoint. Log traffic is sent as a
352 // single string frame, in the same format as when sent to stdout. The
353 // log system supports a single sender; multiple calls to this method will
354 // bind the same sender to multiple endpoints. To disable the sender, call
355 // this method with a null argument.
356 CZMQ_EXPORT void
357 zsys_set_logsender (const char *endpoint);
358
359 // Enable or disable logging to the system facility (syslog on POSIX boxes,
360 // event log on Windows). By default this is disabled.
361 CZMQ_EXPORT void
362 zsys_set_logsystem (bool logsystem);
363
364 // Log error condition - highest priority
365 CZMQ_EXPORT void
366 zsys_error (const char *format, ...);
367
368 // Log warning condition - high priority
369 CZMQ_EXPORT void
370 zsys_warning (const char *format, ...);
371
372 // Log normal, but significant, condition - normal priority
373 CZMQ_EXPORT void
374 zsys_notice (const char *format, ...);
375
376 // Log informational message - low priority
377 CZMQ_EXPORT void
378 zsys_info (const char *format, ...);
379
380 // Log debug-level message - lowest priority
381 CZMQ_EXPORT void
382 zsys_debug (const char *format, ...);
383
384 // Self test of this class.
385 CZMQ_EXPORT void
386 zsys_test (bool verbose);
387
388 #ifdef CZMQ_BUILD_DRAFT_API
389 // *** Draft method, for development use, may change without warning ***
390 // Check if default interrupt handler of Ctrl-C or SIGTERM was called.
391 // Does not work if ZSYS_SIGHANDLER is false and code does not call
392 // set interrupted on signal.
393 CZMQ_EXPORT bool
394 zsys_is_interrupted (void);
395
396 // *** Draft method, for development use, may change without warning ***
397 // Set interrupted flag. This is done by default signal handler, however
398 // this can be handy for language bindings or cases without default
399 // signal handler.
400 CZMQ_EXPORT void
401 zsys_set_interrupted (void);
402
403 // *** Draft method, for development use, may change without warning ***
404 // Configure whether to use zero copy strategy in libzmq. If the environment
405 // variable ZSYS_ZERO_COPY_RECV is defined, that provides the default.
406 // Otherwise the default is 1.
407 CZMQ_EXPORT void
408 zsys_set_zero_copy_recv (int zero_copy);
409
410 // *** Draft method, for development use, may change without warning ***
411 // Return ZMQ_ZERO_COPY_RECV option.
412 CZMQ_EXPORT int
413 zsys_zero_copy_recv (void);
414
415 // *** Draft method, for development use, may change without warning ***
416 // Configure the threshold value of filesystem object age per st_mtime
417 // that should elapse until we consider that object "stable" at the
418 // current zclock_time() moment.
419 // The default is S_DEFAULT_ZSYS_FILE_STABLE_AGE_MSEC defined in zsys.c
420 // which generally depends on host OS, with fallback value of 5000.
421 CZMQ_EXPORT void
422 zsys_set_file_stable_age_msec (int64_t file_stable_age_msec);
423
424 // *** Draft method, for development use, may change without warning ***
425 // Return current threshold value of file stable age in msec.
426 // This can be used in code that chooses to wait for this timeout
427 // before testing if a filesystem object is "stable" or not.
428 CZMQ_EXPORT int64_t
429 zsys_file_stable_age_msec (void);
430
431 #endif // CZMQ_BUILD_DRAFT_API
432 Please add '@interface' section in './../src/zsys.c'.
433
435 The zsys class provides a portable wrapper for system calls. We collect
436 them here to reduce the number of weird #ifdefs in other classes. As
437 far as possible, the bulk of CZMQ classes are fully portable.
438
439 Please add @discuss section in ./../src/zsys.c.
440
442 From zsys_test method.
443
444 zsys_catch_interrupts ();
445
446 // Check capabilities without using the return value
447 int rc = zsys_has_curve ();
448
449 const char *SELFTEST_DIR_RW = "src/selftest-rw";
450
451 if (verbose) {
452 char *hostname = zsys_hostname ();
453 zsys_info ("host name is %s", hostname);
454 freen (hostname);
455 zsys_info ("system limit is %zu ZeroMQ sockets", zsys_socket_limit ());
456 }
457 #ifdef CZMQ_BUILD_DRAFT_API
458 zsys_set_file_stable_age_msec (5123);
459 assert (zsys_file_stable_age_msec() == 5123);
460 zsys_set_file_stable_age_msec (-1);
461 assert (zsys_file_stable_age_msec() == 5123);
462 #endif // CZMQ_BUILD_DRAFT_API
463 zsys_set_linger (0);
464 zsys_set_sndhwm (1000);
465 zsys_set_rcvhwm (1000);
466 zsys_set_pipehwm (2500);
467 assert (zsys_pipehwm () == 2500);
468 zsys_set_ipv6 (0);
469 zsys_set_thread_priority (-1);
470 zsys_set_thread_sched_policy (-1);
471 zsys_set_zero_copy_recv(0);
472 assert (0 == zsys_zero_copy_recv());
473 zsys_set_zero_copy_recv(1);
474 assert (1 == zsys_zero_copy_recv());
475
476 // Test pipe creation
477 zsock_t *pipe_back;
478 zsock_t *pipe_front = zsys_create_pipe (&pipe_back);
479 zstr_send (pipe_front, "Hello");
480 char *string = zstr_recv (pipe_back);
481 assert (streq (string, "Hello"));
482 freen (string);
483 zsock_destroy (&pipe_back);
484 zsock_destroy (&pipe_front);
485
486 // Test file manipulation
487
488 // Don't let anyone fool our workspace
489 if (zsys_file_exists ("nosuchfile")) {
490 zsys_warning ("zsys_test() had to remove 'nosuchfile' which was not expected here at all");
491 zsys_file_delete ("nosuchfile");
492 }
493
494 rc = zsys_file_delete ("nosuchfile");
495 assert (rc == -1);
496
497 bool rc_bool = zsys_file_exists ("nosuchfile");
498 assert (rc_bool != true);
499
500 rc = (int) zsys_file_size ("nosuchfile");
501 assert (rc == -1);
502
503 time_t when = zsys_file_modified (".");
504 assert (when > 0);
505
506 int mode = zsys_file_mode (".");
507 assert (S_ISDIR (mode));
508 assert (mode & S_IRUSR);
509 assert (mode & S_IWUSR);
510
511 const char *testbasedir = ".testsys";
512 const char *testsubdir = "subdir";
513 char *basedirpath = NULL; // subdir in a test, under SELFTEST_DIR_RW
514 char *dirpath = NULL; // subdir in a test, under basedirpath
515 char *relsubdir = NULL; // relative short "path" of subdir under testbasedir
516
517 basedirpath = zsys_sprintf ("%s/%s", SELFTEST_DIR_RW, testbasedir);
518 assert (basedirpath);
519 dirpath = zsys_sprintf ("%s/%s", basedirpath, testsubdir);
520 assert (dirpath);
521 relsubdir = zsys_sprintf ("%s/%s", testbasedir, testsubdir);
522 assert (relsubdir);
523
524 // Normally tests clean up in the end, but if a selftest run dies
525 // e.g. on assert(), workspace remains dirty. Better clean it up.
526 // We do not really care about results here - we clean up a possible
527 // dirty exit of an older build. If there are permission errors etc.
528 // the actual tests below would explode.
529 if (zsys_file_exists(dirpath)) {
530 if (verbose)
531 zsys_debug ("zsys_test() has to remove ./%s that should not have been here", dirpath);
532 zsys_dir_delete (dirpath);
533 }
534 if (zsys_file_exists (basedirpath)) {
535 if (verbose)
536 zsys_debug ("zsys_test() has to remove ./%s that should not have been here", basedirpath);
537 zsys_dir_delete (basedirpath);
538 }
539
540 // Added tracing because this file-age check fails on some systems
541 // presumably due to congestion in a mass-build and valgrind on top
542 zsys_file_mode_private ();
543 if (verbose)
544 printf ("zsys_test() at timestamp %" PRIi64 ": "
545 "Creating %s\n",
546 zclock_time(), relsubdir );
547 rc = zsys_dir_create ("%s/%s", SELFTEST_DIR_RW, relsubdir);
548 if (verbose)
549 printf ("zsys_test() at timestamp %" PRIi64 ": "
550 "Finished creating %s with return-code %d\n",
551 zclock_time(), relsubdir, rc );
552 assert (rc == 0);
553 when = zsys_file_modified (dirpath);
554 if (verbose)
555 printf ("zsys_test() at timestamp %" PRIi64 ": "
556 "Finished calling zsys_file_modified(), got age %jd\n",
557 zclock_time(), (intmax_t)when );
558 assert (when > 0);
559 if (verbose)
560 printf ("zsys_test() at timestamp %" PRIi64 ": "
561 "Checking if file is NOT stable (is younger than 1 sec)\n",
562 zclock_time() );
563 assert (!s_zsys_file_stable (dirpath, verbose));
564 if (verbose)
565 printf ("zsys_test() at timestamp %" PRIi64 ": "
566 "Passed the test, file is not stable - as expected\n",
567 zclock_time() );
568 rc = zsys_dir_delete ("%s/%s", SELFTEST_DIR_RW, relsubdir);
569 assert (rc == 0);
570 rc = zsys_dir_delete ("%s/%s", SELFTEST_DIR_RW, testbasedir);
571 assert (rc == 0);
572 zsys_file_mode_default ();
573
574 #if (defined (PATH_MAX))
575 char cwd[PATH_MAX];
576 #else
577 # if (defined (_MAX_PATH))
578 char cwd[_MAX_PATH];
579 # else
580 char cwd[1024];
581 # endif
582 #endif
583 memset (cwd, 0, sizeof(cwd));
584 #if (defined (WIN32))
585 if (_getcwd(cwd, sizeof(cwd)) != NULL) {
586 #else
587 if (getcwd(cwd, sizeof(cwd)) != NULL) {
588 #endif
589 if (verbose)
590 printf ("zsys_test() at timestamp %" PRIi64 ": "
591 "current working directory is %s\n",
592 zclock_time(), cwd);
593 assert (zsys_dir_change (SELFTEST_DIR_RW) == 0);
594 assert (zsys_dir_change (cwd) == 0);
595 }
596 else {
597 zsys_warning ("zsys_test() : got getcwd() error... "
598 "testing zsys_dir_change() anyway, but it can confuse "
599 "subsequent tests in this process");
600 assert (zsys_dir_change (SELFTEST_DIR_RW) == 0);
601 }
602
603 zstr_free (&basedirpath);
604 zstr_free (&dirpath);
605 zstr_free (&relsubdir);
606
607 // Other subtests
608 int major, minor, patch;
609 zsys_version (&major, &minor, &patch);
610 assert (major == CZMQ_VERSION_MAJOR);
611 assert (minor == CZMQ_VERSION_MINOR);
612 assert (patch == CZMQ_VERSION_PATCH);
613
614 string = zsys_sprintf ("%s %02x", "Hello", 16);
615 assert (streq (string, "Hello 10"));
616 freen (string);
617
618 char *str64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890,.";
619 int num10 = 1234567890;
620 string = zsys_sprintf ("%s%s%s%s%d", str64, str64, str64, str64, num10);
621 assert (strlen (string) == (4 * 64 + 10));
622 freen (string);
623
624 // Test logging system
625 zsys_set_logident ("czmq_selftest");
626 zsys_set_logsender ("inproc://logging");
627 void *logger = zsys_socket (ZMQ_SUB, NULL, 0);
628 assert (logger);
629 rc = zmq_connect (logger, "inproc://logging");
630 assert (rc == 0);
631 rc = zmq_setsockopt (logger, ZMQ_SUBSCRIBE, "", 0);
632 assert (rc == 0);
633
634 if (verbose) {
635 zsys_error ("This is an %s message", "error");
636 zsys_warning ("This is a %s message", "warning");
637 zsys_notice ("This is a %s message", "notice");
638 zsys_info ("This is a %s message", "info");
639 zsys_debug ("This is a %s message", "debug");
640 zsys_set_logident ("hello, world");
641 zsys_info ("This is a %s message", "info");
642 zsys_debug ("This is a %s message", "debug");
643
644 // Check that logsender functionality is working
645 char *received = zstr_recv (logger);
646 assert (received);
647 zstr_free (&received);
648 }
649 zsys_close (logger, NULL, 0);
650
651
653 The czmq manual was written by the authors in the AUTHORS file.
654
656 Main web site:
657
658 Report bugs to the email <zeromq-dev@lists.zeromq.org[1]>
659
661 Copyright (c) the Contributors as noted in the AUTHORS file. This file
662 is part of CZMQ, the high-level C binding for 0MQ:
663 http://czmq.zeromq.org. This Source Code Form is subject to the terms
664 of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
665 distributed with this file, You can obtain one at
666 http://mozilla.org/MPL/2.0/. LICENSE included with the czmq
667 distribution.
668
670 1. zeromq-dev@lists.zeromq.org
671 mailto:zeromq-dev@lists.zeromq.org
672
673
674
675CZMQ 4.1.1 01/31/2019 ZSYS(3)