czmq-ffi-gen 0.13.0-x86-mingw32 → 0.14.1-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +13 -0
  3. data/lib/czmq-ffi-gen/czmq/ffi.rb +224 -698
  4. data/lib/czmq-ffi-gen/czmq/ffi/zactor.rb +40 -7
  5. data/lib/czmq-ffi-gen/czmq/ffi/zargs.rb +259 -0
  6. data/lib/czmq-ffi-gen/czmq/ffi/zarmour.rb +3 -3
  7. data/lib/czmq-ffi-gen/czmq/ffi/zcert.rb +15 -6
  8. data/lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb +25 -11
  9. data/lib/czmq-ffi-gen/czmq/ffi/zchunk.rb +18 -18
  10. data/lib/czmq-ffi-gen/czmq/ffi/zclock.rb +6 -6
  11. data/lib/czmq-ffi-gen/czmq/ffi/zconfig.rb +27 -17
  12. data/lib/czmq-ffi-gen/czmq/ffi/zdigest.rb +4 -4
  13. data/lib/czmq-ffi-gen/czmq/ffi/zdir.rb +36 -36
  14. data/lib/czmq-ffi-gen/czmq/ffi/zdir_patch.rb +1 -1
  15. data/lib/czmq-ffi-gen/czmq/ffi/zfile.rb +27 -19
  16. data/lib/czmq-ffi-gen/czmq/ffi/zframe.rb +22 -21
  17. data/lib/czmq-ffi-gen/czmq/ffi/zhash.rb +54 -54
  18. data/lib/czmq-ffi-gen/czmq/ffi/zhashx.rb +82 -80
  19. data/lib/czmq-ffi-gen/czmq/ffi/ziflist.rb +30 -0
  20. data/lib/czmq-ffi-gen/czmq/ffi/zlist.rb +30 -30
  21. data/lib/czmq-ffi-gen/czmq/ffi/zlistx.rb +44 -44
  22. data/lib/czmq-ffi-gen/czmq/ffi/zloop.rb +39 -39
  23. data/lib/czmq-ffi-gen/czmq/ffi/zmsg.rb +46 -46
  24. data/lib/czmq-ffi-gen/czmq/ffi/zpoller.rb +16 -16
  25. data/lib/czmq-ffi-gen/czmq/ffi/zproc.rb +237 -34
  26. data/lib/czmq-ffi-gen/czmq/ffi/zsock.rb +1201 -973
  27. data/lib/czmq-ffi-gen/czmq/ffi/zstr.rb +58 -19
  28. data/lib/czmq-ffi-gen/czmq/ffi/zsys.rb +836 -0
  29. data/lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb +6 -6
  30. data/lib/czmq-ffi-gen/czmq/ffi/ztrie.rb +10 -10
  31. data/lib/czmq-ffi-gen/czmq/ffi/zuuid.rb +4 -4
  32. data/lib/czmq-ffi-gen/gem_version.rb +1 -1
  33. data/lib/czmq-ffi-gen/vendor.rb +9 -1
  34. data/vendor/local/bin/inproc_lat.exe +0 -0
  35. data/vendor/local/bin/inproc_thr.exe +0 -0
  36. data/vendor/local/bin/libczmq.dll +0 -0
  37. data/vendor/local/bin/libzmq.dll +0 -0
  38. data/vendor/local/bin/local_lat.exe +0 -0
  39. data/vendor/local/bin/local_thr.exe +0 -0
  40. data/vendor/local/bin/remote_lat.exe +0 -0
  41. data/vendor/local/bin/remote_thr.exe +0 -0
  42. data/vendor/local/bin/zmakecert.exe +0 -0
  43. data/vendor/local/include/czmq_library.h +18 -9
  44. data/vendor/local/include/czmq_prelude.h +104 -16
  45. data/vendor/local/include/zactor.h +25 -7
  46. data/vendor/local/include/zarmour.h +3 -3
  47. data/vendor/local/include/zcert.h +11 -6
  48. data/vendor/local/include/zcertstore.h +18 -9
  49. data/vendor/local/include/zchunk.h +18 -18
  50. data/vendor/local/include/zclock.h +6 -6
  51. data/vendor/local/include/zconfig.h +25 -16
  52. data/vendor/local/include/zdigest.h +4 -4
  53. data/vendor/local/include/zdir.h +36 -36
  54. data/vendor/local/include/zdir_patch.h +1 -1
  55. data/vendor/local/include/zfile.h +27 -19
  56. data/vendor/local/include/zframe.h +22 -21
  57. data/vendor/local/include/zgossip.h +5 -5
  58. data/vendor/local/include/zgossip_engine.inc +103 -22
  59. data/vendor/local/include/zgossip_msg.h +28 -30
  60. data/vendor/local/include/zhash.h +53 -53
  61. data/vendor/local/include/zhashx.h +75 -73
  62. data/vendor/local/include/ziflist.h +22 -1
  63. data/vendor/local/include/zlist.h +28 -28
  64. data/vendor/local/include/zlistx.h +41 -41
  65. data/vendor/local/include/zloop.h +36 -36
  66. data/vendor/local/include/zmsg.h +46 -46
  67. data/vendor/local/include/zpoller.h +16 -16
  68. data/vendor/local/include/zsock.h +414 -364
  69. data/vendor/local/include/zsock_option.inc +234 -1062
  70. data/vendor/local/include/zstr.h +44 -19
  71. data/vendor/local/include/zsys.h +63 -19
  72. data/vendor/local/include/zuuid.h +4 -4
  73. data/vendor/local/lib/libczmq.dll.a +0 -0
  74. data/vendor/local/lib/liblibzmq.dll.a +0 -0
  75. data/vendor/local/lib/pkgconfig/libczmq.pc +1 -1
  76. metadata +6 -3
@@ -39,7 +39,7 @@ CZMQ_EXPORT void
39
39
  zdir_patch_destroy (zdir_patch_t **self_p);
40
40
 
41
41
  // Create copy of a patch. If the patch is null, or memory was exhausted,
42
- // returns null.
42
+ // returns null.
43
43
  // Caller owns return value and must destroy it when done.
44
44
  CZMQ_EXPORT zdir_patch_t *
45
45
  zdir_patch_dup (zdir_patch_t *self);
@@ -27,7 +27,7 @@ extern "C" {
27
27
  // links, which are files with the extension ".ln". A symbolic link is a
28
28
  // text file containing one line, the filename of a target file. Reading
29
29
  // data from the symbolic link actually reads from the target file. Path
30
- // may be NULL, in which case it is not used.
30
+ // may be NULL, in which case it is not used.
31
31
  CZMQ_EXPORT zfile_t *
32
32
  zfile_new (const char *path, const char *name);
33
33
 
@@ -36,7 +36,7 @@ CZMQ_EXPORT void
36
36
  zfile_destroy (zfile_t **self_p);
37
37
 
38
38
  // Duplicate a file item, returns a newly constructed item. If the file
39
- // is null, or memory was exhausted, returns null.
39
+ // is null, or memory was exhausted, returns null.
40
40
  // Caller owns return value and must destroy it when done.
41
41
  CZMQ_EXPORT zfile_t *
42
42
  zfile_dup (zfile_t *self);
@@ -45,23 +45,23 @@ CZMQ_EXPORT zfile_t *
45
45
  CZMQ_EXPORT const char *
46
46
  zfile_filename (zfile_t *self, const char *path);
47
47
 
48
- // Refresh file properties from disk; this is not done automatically
48
+ // Refresh file properties from disk; this is not done automatically
49
49
  // on access methods, otherwise it is not possible to compare directory
50
- // snapshots.
50
+ // snapshots.
51
51
  CZMQ_EXPORT void
52
52
  zfile_restat (zfile_t *self);
53
53
 
54
54
  // Return when the file was last modified. If you want this to reflect the
55
- // current situation, call zfile_restat before checking this property.
55
+ // current situation, call zfile_restat before checking this property.
56
56
  CZMQ_EXPORT time_t
57
57
  zfile_modified (zfile_t *self);
58
58
 
59
59
  // Return the last-known size of the file. If you want this to reflect the
60
- // current situation, call zfile_restat before checking this property.
60
+ // current situation, call zfile_restat before checking this property.
61
61
  CZMQ_EXPORT off_t
62
62
  zfile_cursize (zfile_t *self);
63
63
 
64
- // Return true if the file is a directory. If you want this to reflect
64
+ // Return true if the file is a directory. If you want this to reflect
65
65
  // any external changes, call zfile_restat before checking this property.
66
66
  CZMQ_EXPORT bool
67
67
  zfile_is_directory (zfile_t *self);
@@ -72,24 +72,24 @@ CZMQ_EXPORT bool
72
72
  zfile_is_regular (zfile_t *self);
73
73
 
74
74
  // Return true if the file is readable by this process. If you want this to
75
- // reflect any external changes, call zfile_restat before checking this
76
- // property.
75
+ // reflect any external changes, call zfile_restat before checking this
76
+ // property.
77
77
  CZMQ_EXPORT bool
78
78
  zfile_is_readable (zfile_t *self);
79
79
 
80
- // Return true if the file is writeable by this process. If you want this
80
+ // Return true if the file is writeable by this process. If you want this
81
81
  // to reflect any external changes, call zfile_restat before checking this
82
- // property.
82
+ // property.
83
83
  CZMQ_EXPORT bool
84
84
  zfile_is_writeable (zfile_t *self);
85
85
 
86
86
  // Check if file has stopped changing and can be safely processed.
87
- // Updates the file statistics from disk at every call.
87
+ // Updates the file statistics from disk at every call.
88
88
  CZMQ_EXPORT bool
89
89
  zfile_is_stable (zfile_t *self);
90
90
 
91
91
  // Return true if the file was changed on disk since the zfile_t object
92
- // was created, or the last zfile_restat() call made on it.
92
+ // was created, or the last zfile_restat() call made on it.
93
93
  CZMQ_EXPORT bool
94
94
  zfile_has_changed (zfile_t *self);
95
95
 
@@ -97,19 +97,19 @@ CZMQ_EXPORT bool
97
97
  CZMQ_EXPORT void
98
98
  zfile_remove (zfile_t *self);
99
99
 
100
- // Open file for reading
100
+ // Open file for reading
101
101
  // Returns 0 if OK, -1 if not found or not accessible
102
102
  CZMQ_EXPORT int
103
103
  zfile_input (zfile_t *self);
104
104
 
105
- // Open file for writing, creating directory if needed
105
+ // Open file for writing, creating directory if needed
106
106
  // File is created if necessary; chunks can be written to file at any
107
- // location. Returns 0 if OK, -1 if error.
107
+ // location. Returns 0 if OK, -1 if error.
108
108
  CZMQ_EXPORT int
109
109
  zfile_output (zfile_t *self);
110
110
 
111
111
  // Read chunk from file at specified position. If this was the last chunk,
112
- // sets the eof property. Returns a null chunk in case of error.
112
+ // sets the eof property. Returns a null chunk in case of error.
113
113
  // Caller owns return value and must destroy it when done.
114
114
  CZMQ_EXPORT zchunk_t *
115
115
  zfile_read (zfile_t *self, size_t bytes, off_t offset);
@@ -119,12 +119,12 @@ CZMQ_EXPORT bool
119
119
  zfile_eof (zfile_t *self);
120
120
 
121
121
  // Write chunk to file at specified position
122
- // Return 0 if OK, else -1
122
+ // Return 0 if OK, else -1
123
123
  CZMQ_EXPORT int
124
124
  zfile_write (zfile_t *self, zchunk_t *chunk, off_t offset);
125
125
 
126
126
  // Read next line of text from file. Returns a pointer to the text line,
127
- // or NULL if there was nothing more to read from the file.
127
+ // or NULL if there was nothing more to read from the file.
128
128
  CZMQ_EXPORT const char *
129
129
  zfile_readln (zfile_t *self);
130
130
 
@@ -144,6 +144,14 @@ CZMQ_EXPORT const char *
144
144
  CZMQ_EXPORT void
145
145
  zfile_test (bool verbose);
146
146
 
147
+ #ifdef CZMQ_BUILD_DRAFT_API
148
+ // *** Draft method, for development use, may change without warning ***
149
+ // Create new temporary file for writing via tmpfile. File is automaticaly
150
+ // deleted on destroy
151
+ CZMQ_EXPORT zfile_t *
152
+ zfile_tmp (void);
153
+
154
+ #endif // CZMQ_BUILD_DRAFT_API
147
155
  // @end
148
156
 
149
157
 
@@ -25,13 +25,13 @@ extern "C" {
25
25
  // is provided in stable builds.
26
26
  // This class has draft methods, which may change over time. They are not
27
27
  // in stable releases, by default. Use --enable-drafts to enable.
28
- #define ZFRAME_MORE 1 //
29
- #define ZFRAME_REUSE 2 //
30
- #define ZFRAME_DONTWAIT 4 //
28
+ #define ZFRAME_MORE 1 //
29
+ #define ZFRAME_REUSE 2 //
30
+ #define ZFRAME_DONTWAIT 4 //
31
31
 
32
32
  // Create a new frame. If size is not null, allocates the frame data
33
- // to the specified size. If additionally, data is not null, copies
34
- // size octets from the specified data into the frame body.
33
+ // to the specified size. If additionally, data is not null, copies
34
+ // size octets from the specified data into the frame body.
35
35
  CZMQ_EXPORT zframe_t *
36
36
  zframe_new (const void *data, size_t size);
37
37
 
@@ -43,9 +43,9 @@ CZMQ_EXPORT zframe_t *
43
43
  CZMQ_EXPORT zframe_t *
44
44
  zframe_from (const char *string);
45
45
 
46
- // Receive frame from socket, returns zframe_t object or NULL if the recv
46
+ // Receive frame from socket, returns zframe_t object or NULL if the recv
47
47
  // was interrupted. Does a blocking recv, if you want to not block then use
48
- // zpoller or zloop.
48
+ // zpoller or zloop.
49
49
  CZMQ_EXPORT zframe_t *
50
50
  zframe_recv (void *source);
51
51
 
@@ -54,7 +54,7 @@ CZMQ_EXPORT void
54
54
  zframe_destroy (zframe_t **self_p);
55
55
 
56
56
  // Send a frame to a socket, destroy frame after sending.
57
- // Return -1 on error, 0 on success.
57
+ // Return -1 on error, 0 on success.
58
58
  CZMQ_EXPORT int
59
59
  zframe_send (zframe_t **self_p, void *dest, int flags);
60
60
 
@@ -66,25 +66,26 @@ CZMQ_EXPORT size_t
66
66
  CZMQ_EXPORT byte *
67
67
  zframe_data (zframe_t *self);
68
68
 
69
- // Return meta data property for frame
70
- // Caller must free string when finished with it.
69
+ // Return meta data property for frame
70
+ // The caller shall not modify or free the returned value, which shall be
71
+ // owned by the message.
71
72
  CZMQ_EXPORT const char *
72
73
  zframe_meta (zframe_t *self, const char *property);
73
74
 
74
75
  // Create a new frame that duplicates an existing frame. If frame is null,
75
- // or memory was exhausted, returns null.
76
+ // or memory was exhausted, returns null.
76
77
  // Caller owns return value and must destroy it when done.
77
78
  CZMQ_EXPORT zframe_t *
78
79
  zframe_dup (zframe_t *self);
79
80
 
80
81
  // Return frame data encoded as printable hex string, useful for 0MQ UUIDs.
81
- // Caller must free string when finished with it.
82
+ // Caller must free string when finished with it.
82
83
  // Caller owns return value and must destroy it when done.
83
84
  CZMQ_EXPORT char *
84
85
  zframe_strhex (zframe_t *self);
85
86
 
86
87
  // Return frame data copied into freshly allocated string
87
- // Caller must free string when finished with it.
88
+ // Caller must free string when finished with it.
88
89
  // Caller owns return value and must destroy it when done.
89
90
  CZMQ_EXPORT char *
90
91
  zframe_strdup (zframe_t *self);
@@ -94,17 +95,17 @@ CZMQ_EXPORT bool
94
95
  zframe_streq (zframe_t *self, const char *string);
95
96
 
96
97
  // Return frame MORE indicator (1 or 0), set when reading frame from socket
97
- // or by the zframe_set_more() method
98
+ // or by the zframe_set_more() method
98
99
  CZMQ_EXPORT int
99
100
  zframe_more (zframe_t *self);
100
101
 
101
102
  // Set frame MORE indicator (1 or 0). Note this is NOT used when sending
102
- // frame to socket, you have to specify flag explicitly.
103
+ // frame to socket, you have to specify flag explicitly.
103
104
  CZMQ_EXPORT void
104
105
  zframe_set_more (zframe_t *self, int more);
105
106
 
106
107
  // Return TRUE if two frames have identical size and data
107
- // If either frame is NULL, equality is always false.
108
+ // If either frame is NULL, equality is always false.
108
109
  CZMQ_EXPORT bool
109
110
  zframe_eq (zframe_t *self, zframe_t *other);
110
111
 
@@ -112,7 +113,7 @@ CZMQ_EXPORT bool
112
113
  CZMQ_EXPORT void
113
114
  zframe_reset (zframe_t *self, const void *data, size_t size);
114
115
 
115
- // Send message to zsys log sink (may be stdout, or system facility as
116
+ // Send message to zsys log sink (may be stdout, or system facility as
116
117
  // configured by zsys_set_logstream). Prefix shows before frame, if not null.
117
118
  CZMQ_EXPORT void
118
119
  zframe_print (zframe_t *self, const char *prefix);
@@ -128,13 +129,13 @@ CZMQ_EXPORT void
128
129
  #ifdef CZMQ_BUILD_DRAFT_API
129
130
  // *** Draft method, for development use, may change without warning ***
130
131
  // Return frame routing ID, if the frame came from a ZMQ_SERVER socket.
131
- // Else returns zero.
132
+ // Else returns zero.
132
133
  CZMQ_EXPORT uint32_t
133
134
  zframe_routing_id (zframe_t *self);
134
135
 
135
136
  // *** Draft method, for development use, may change without warning ***
136
137
  // Set routing ID on frame. This is used if/when the frame is sent to a
137
- // ZMQ_SERVER socket.
138
+ // ZMQ_SERVER socket.
138
139
  CZMQ_EXPORT void
139
140
  zframe_set_routing_id (zframe_t *self, uint32_t routing_id);
140
141
 
@@ -145,8 +146,8 @@ CZMQ_EXPORT const char *
145
146
 
146
147
  // *** Draft method, for development use, may change without warning ***
147
148
  // Set group on frame. This is used if/when the frame is sent to a
148
- // ZMQ_RADIO socket.
149
- // Return -1 on error, 0 on success.
149
+ // ZMQ_RADIO socket.
150
+ // Return -1 on error, 0 on success.
150
151
  CZMQ_EXPORT int
151
152
  zframe_set_group (zframe_t *self, const char *group);
152
153
 
@@ -10,13 +10,13 @@
10
10
  * The XML model used for this code generation: zgossip.xml, or
11
11
  * The code generation script that built this file: zproto_server_c
12
12
  ************************************************************************
13
- Copyright (c) the Contributors as noted in the AUTHORS file.
14
- This file is part of CZMQ, the high-level C binding for 0MQ:
15
- http://czmq.zeromq.org.
16
-
13
+ Copyright (c) the Contributors as noted in the AUTHORS file.
14
+ This file is part of CZMQ, the high-level C binding for 0MQ:
15
+ http://czmq.zeromq.org.
16
+
17
17
  This Source Code Form is subject to the terms of the Mozilla Public
18
18
  License, v. 2.0. If a copy of the MPL was not distributed with this
19
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
19
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
20
20
  =========================================================================
21
21
  */
22
22
 
@@ -10,16 +10,22 @@
10
10
  * The XML model used for this code generation: zgossip.xml, or
11
11
  * The code generation script that built this file: zproto_server_c
12
12
  ************************************************************************
13
- Copyright (c) the Contributors as noted in the AUTHORS file.
14
- This file is part of CZMQ, the high-level C binding for 0MQ:
15
- http://czmq.zeromq.org.
16
-
13
+ Copyright (c) the Contributors as noted in the AUTHORS file.
14
+ This file is part of CZMQ, the high-level C binding for 0MQ:
15
+ http://czmq.zeromq.org.
16
+
17
17
  This Source Code Form is subject to the terms of the Mozilla Public
18
18
  License, v. 2.0. If a copy of the MPL was not distributed with this
19
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
19
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
20
20
  =========================================================================
21
21
  */
22
22
 
23
+ #ifdef NDEBUG
24
+ #undef NDEBUG
25
+ #endif
26
+
27
+ #define ZPROTO_UNUSED(object) (void)object
28
+
23
29
  // ---------------------------------------------------------------------------
24
30
  // State machine constants
25
31
 
@@ -113,10 +119,14 @@ static void
113
119
  server_terminate (server_t *self);
114
120
  static zmsg_t *
115
121
  server_method (server_t *self, const char *method, zmsg_t *msg);
122
+ static void
123
+ server_configuration (server_t *self, zconfig_t *config);
116
124
  static int
117
125
  client_initialize (client_t *self);
118
126
  static void
119
127
  client_terminate (client_t *self);
128
+ static void
129
+ s_server_config_global (s_server_t *server);
120
130
  static void
121
131
  s_client_execute (s_client_t *client, event_t event);
122
132
  static int
@@ -237,15 +247,29 @@ engine_handle_socket (server_t *server, void *sock, zloop_reader_fn handler)
237
247
  }
238
248
 
239
249
  // Register monitor function that will be called at regular intervals
240
- // by the server engine
250
+ // by the server engine. Returns an identifier that can be used to cancel it.
241
251
 
242
- static void
252
+ static int
243
253
  engine_set_monitor (server_t *server, size_t interval, zloop_timer_fn monitor)
244
254
  {
245
255
  if (server) {
246
256
  s_server_t *self = (s_server_t *) server;
247
257
  int rc = zloop_timer (self->loop, interval, 0, monitor, self);
248
258
  assert (rc >= 0);
259
+ return rc;
260
+ }
261
+
262
+ return -1;
263
+ }
264
+
265
+ // Cancel the monitor function with the given identifier.
266
+ static void
267
+ engine_cancel_monitor (server_t *server, int identifier)
268
+ {
269
+ if (server) {
270
+ s_server_t *self = (s_server_t *) server;
271
+ int rc = zloop_timer_end (self->loop, identifier);
272
+ assert (rc >= 0);
249
273
  }
250
274
  }
251
275
 
@@ -257,7 +281,7 @@ engine_set_log_prefix (client_t *client, const char *string)
257
281
  {
258
282
  if (client) {
259
283
  s_client_t *self = (s_client_t *) client;
260
- snprintf (self->log_prefix, sizeof (self->log_prefix) - 1,
284
+ snprintf (self->log_prefix, sizeof (self->log_prefix),
261
285
  "%6d:%-33s", self->unique_id, string);
262
286
  }
263
287
  }
@@ -272,6 +296,7 @@ engine_configure (server_t *server, const char *path, const char *value)
272
296
  if (server) {
273
297
  s_server_t *self = (s_server_t *) server;
274
298
  zconfig_put (self->config, path, value);
299
+ s_server_config_global (self);
275
300
  }
276
301
  }
277
302
 
@@ -300,6 +325,7 @@ s_satisfy_pedantic_compilers (void)
300
325
  engine_broadcast_event (NULL, NULL, NULL_event);
301
326
  engine_handle_socket (NULL, 0, NULL);
302
327
  engine_set_monitor (NULL, 0, NULL);
328
+ engine_cancel_monitor (NULL, 0);
303
329
  engine_set_log_prefix (NULL, NULL);
304
330
  engine_configure (NULL, NULL, NULL);
305
331
  engine_verbose (NULL);
@@ -641,6 +667,8 @@ s_client_handle_ticket (zloop_t *loop, int timer_id, void *argument)
641
667
  static int
642
668
  s_client_handle_wakeup (zloop_t *loop, int timer_id, void *argument)
643
669
  {
670
+ ZPROTO_UNUSED(loop);
671
+ ZPROTO_UNUSED(timer_id);
644
672
  s_client_t *self = (s_client_t *) argument;
645
673
  s_client_execute (self, self->wakeup_event);
646
674
  return 0;
@@ -656,17 +684,17 @@ s_server_config_global (s_server_t *self)
656
684
  //
657
685
  // If we didn't already set verbose, check if the config tree wants it
658
686
  if (!self->verbose
659
- && atoi (zconfig_resolve (self->config, "server/verbose", "0")))
687
+ && atoi (zconfig_get (self->config, "server/verbose", "0")))
660
688
  self->verbose = true;
661
689
 
662
690
  // Default client timeout is 60 seconds
663
691
  self->timeout = atoi (
664
- zconfig_resolve (self->config, "server/timeout", "60000"));
692
+ zconfig_get (self->config, "server/timeout", "60000"));
665
693
  zloop_set_ticket_delay (self->loop, self->timeout);
666
694
 
667
695
  // Do we want to run server in the background?
668
696
  int background = atoi (
669
- zconfig_resolve (self->config, "server/background", "0"));
697
+ zconfig_get (self->config, "server/background", "0"));
670
698
  if (!background)
671
699
  zsys_set_logstream (stdout);
672
700
  }
@@ -740,15 +768,15 @@ s_server_config_service (s_server_t *self)
740
768
  zsys_notice ("%s", zconfig_value (section));
741
769
  else
742
770
  if (streq (zconfig_name (section), "bind")) {
743
- char *endpoint = zconfig_resolve (section, "endpoint", "?");
771
+ char *endpoint = zconfig_get (section, "endpoint", "?");
744
772
  if (zsock_bind (self->router, "%s", endpoint) == -1)
745
773
  zsys_warning ("could not bind to %s (%s)", endpoint, zmq_strerror (zmq_errno ()));
746
774
  }
747
775
  #if (ZMQ_VERSION_MAJOR >= 4)
748
776
  else
749
777
  if (streq (zconfig_name (section), "security")) {
750
- char *mechanism = zconfig_resolve (section, "mechanism", "null");
751
- char *domain = zconfig_resolve (section, "domain", NULL);
778
+ char *mechanism = zconfig_get (section, "mechanism", "null");
779
+ char *domain = zconfig_get (section, "domain", NULL);
752
780
  if (streq (mechanism, "null")) {
753
781
  zsys_notice ("server is using NULL security");
754
782
  if (domain)
@@ -759,6 +787,22 @@ s_server_config_service (s_server_t *self)
759
787
  zsys_notice ("server is using PLAIN security");
760
788
  zsock_set_plain_server (self->router, 1);
761
789
  }
790
+ #ifdef CZMQ_BUILD_DRAFT_API
791
+ // TODO- zproto
792
+ // https://github.com/zeromq/zproto/blob/master/src/zproto_server_c.gsl#L883
793
+ else
794
+ if (streq (mechanism, "curve")) {
795
+ zsys_notice ("using CURVE security");
796
+ const char *keyfile = zconfig_get (section, "secret-key", NULL);
797
+ assert (keyfile);
798
+
799
+ zcert_t *server_cert = zcert_load(keyfile);
800
+ assert (server_cert);
801
+
802
+ zcert_apply (server_cert, self->router);
803
+ zsock_set_curve_server (self->router, 1);
804
+ }
805
+ #endif
762
806
  else
763
807
  zsys_warning ("mechanism=%s is not supported", mechanism);
764
808
  }
@@ -773,6 +817,9 @@ s_server_config_service (s_server_t *self)
773
817
  static int
774
818
  s_server_handle_pipe (zloop_t *loop, zsock_t *reader, void *argument)
775
819
  {
820
+ ZPROTO_UNUSED(loop);
821
+ ZPROTO_UNUSED(reader);
822
+
776
823
  s_server_t *self = (s_server_t *) argument;
777
824
  zmsg_t *msg = zmsg_recv (self->pipe);
778
825
  if (!msg)
@@ -786,7 +833,7 @@ s_server_handle_pipe (zloop_t *loop, zsock_t *reader, void *argument)
786
833
  else
787
834
  if (streq (method, "$TERM")) {
788
835
  // Shutdown the engine
789
- free (method);
836
+ zstr_free (&method);
790
837
  zmsg_destroy (&msg);
791
838
  return -1;
792
839
  }
@@ -794,10 +841,30 @@ s_server_handle_pipe (zloop_t *loop, zsock_t *reader, void *argument)
794
841
  if (streq (method, "BIND")) {
795
842
  // Bind to a specified endpoint, which may use an ephemeral port
796
843
  char *endpoint = zmsg_popstr (msg);
844
+
845
+ #ifdef CZMQ_BUILD_DRAFT_API
846
+ // TODO- expose self->router to application context ?
847
+ // Add secret|public|zap to gsl(?)
848
+ // move this block to custom server function when both keys are present
849
+ if (self->server.secret_key) {
850
+ zsock_set_zap_domain (self->router, self->server.zap_domain);
851
+ zcert_t *cert = zcert_new_from_txt(self->server.public_key, self->server.secret_key);
852
+ zcert_apply(cert, self->router);
853
+ zsock_set_curve_server (self->router, 1);
854
+ zcert_destroy(&cert);
855
+ }
856
+ // TODO- add this test in zproto_server_c.gsl
857
+ #ifndef ZMQ_CURVE
858
+ // zmq legacy
859
+ bool ZMQ_CURVE = false;
860
+ #endif
861
+ if (self->server.secret_key)
862
+ assert (zsock_mechanism (self->router) == ZMQ_CURVE);
863
+ #endif
797
864
  self->port = zsock_bind (self->router, "%s", endpoint);
798
865
  if (self->port == -1)
799
866
  zsys_warning ("could not bind to %s", endpoint);
800
- free (endpoint);
867
+ zstr_free (&endpoint);
801
868
  }
802
869
  else
803
870
  if (streq (method, "PORT")) {
@@ -813,12 +880,13 @@ s_server_handle_pipe (zloop_t *loop, zsock_t *reader, void *argument)
813
880
  if (self->config) {
814
881
  s_server_config_service (self);
815
882
  self->server.config = self->config;
883
+ server_configuration (&self->server, self->config);
816
884
  }
817
885
  else {
818
886
  zsys_warning ("cannot load config file '%s'", filename);
819
887
  self->config = zconfig_new ("root", NULL);
820
888
  }
821
- free (filename);
889
+ zstr_free (&filename);
822
890
  }
823
891
  else
824
892
  if (streq (method, "SET")) {
@@ -830,15 +898,15 @@ s_server_handle_pipe (zloop_t *loop, zsock_t *reader, void *argument)
830
898
  self->verbose = (atoi (value) == 1);
831
899
  }
832
900
  s_server_config_global (self);
833
- free (path);
834
- free (value);
901
+ zstr_free (&value);
902
+ zstr_free (&path);
835
903
  }
836
904
  else
837
905
  if (streq (method, "SAVE")) {
838
906
  char *filename = zmsg_popstr (msg);
839
907
  if (zconfig_save (self->config, filename))
840
908
  zsys_warning ("cannot save config file '%s'", filename);
841
- free (filename);
909
+ zstr_free (&filename);
842
910
  }
843
911
  else {
844
912
  // Execute custom method
@@ -846,7 +914,7 @@ s_server_handle_pipe (zloop_t *loop, zsock_t *reader, void *argument)
846
914
  // If reply isn't null, send it to caller
847
915
  zmsg_send (&reply, self->pipe);
848
916
  }
849
- free (method);
917
+ zstr_free (&method);
850
918
  zmsg_destroy (&msg);
851
919
  return 0;
852
920
  }
@@ -856,13 +924,18 @@ s_server_handle_pipe (zloop_t *loop, zsock_t *reader, void *argument)
856
924
  static int
857
925
  s_server_handle_protocol (zloop_t *loop, zsock_t *reader, void *argument)
858
926
  {
927
+ ZPROTO_UNUSED(loop);
928
+ ZPROTO_UNUSED(reader);
929
+
859
930
  s_server_t *self = (s_server_t *) argument;
860
931
  // We process as many messages as we can, to reduce the overhead
861
932
  // of polling and the reactor:
862
933
  while (zsock_events (self->router) & ZMQ_POLLIN) {
863
- if (zgossip_msg_recv (self->message, self->router))
934
+ int rc = zgossip_msg_recv (self->message, self->router);
935
+ if (rc == -1)
864
936
  return -1; // Interrupted; exit zloop
865
937
 
938
+
866
939
  // TODO: use binary hashing on routing_id
867
940
  char *hashkey = zframe_strhex (zgossip_msg_routing_id (self->message));
868
941
  s_client_t *client = (s_client_t *) zhash_lookup (self->clients, hashkey);
@@ -876,6 +949,10 @@ s_server_handle_protocol (zloop_t *loop, zsock_t *reader, void *argument)
876
949
  if (client->ticket)
877
950
  zloop_ticket_reset (self->loop, client->ticket);
878
951
 
952
+ if (rc == -2) {
953
+ continue; // Malformed, but malformed_event doesn't exist
954
+ // -> discard the message
955
+ }
879
956
  // Pass to client state machine
880
957
  s_client_execute (client, s_protocol_event (self->message));
881
958
  }
@@ -887,11 +964,15 @@ s_server_handle_protocol (zloop_t *loop, zsock_t *reader, void *argument)
887
964
  static int
888
965
  s_watch_server_config (zloop_t *loop, int timer_id, void *argument)
889
966
  {
967
+ ZPROTO_UNUSED(loop);
968
+ ZPROTO_UNUSED(timer_id);
969
+
890
970
  s_server_t *self = (s_server_t *) argument;
891
971
  if (zconfig_has_changed (self->config)
892
972
  && zconfig_reload (&self->config) == 0) {
893
973
  s_server_config_service (self);
894
974
  self->server.config = self->config;
975
+ server_configuration (&self->server, self->config);
895
976
  zsys_notice ("reloaded configuration from %s",
896
977
  zconfig_filename (self->config));
897
978
  }