rbczmq 1.6 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzgxOTQ4ZWU1YWMzNjdkYzdkOGY0ODgxYzFkODIxMTA0ODUxYTM1Ng==
5
+ data.tar.gz: !binary |-
6
+ M2Y5NGY3ZmQ4MGJiOTkyMzQ2YWJkMTJkMWU2NTQ3MjEzZTU5ZDY0ZQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ Yzc3ZmQyOWE1ZDY2ZTdjZjU4MjI5ZjZhNjBmYjhjMTc3YTA3MGM4N2I4NjNk
10
+ OGE1NTQyMThhMzQyZWUwM2MzNWIzNjBiN2Q0OWMxNGY5Mzg0YWNhMmE1M2Vh
11
+ NTVjYjY5MjdlYTc3YjM3NjZhMzcxYWEyY2UyYTAxMjc1MzNjN2M=
12
+ data.tar.gz: !binary |-
13
+ NDQ3NGZmMGIxNTVkYTk0YzY0ZjcwZmEwZjZlMmJlOWZlNDY0ZjQwYTYyZjNm
14
+ YjM3NDlhODUwYTEwZTNkZTVlNGUyZjZkNmI2NmUxNDdlZmZhMTQ0NGNmYzI5
15
+ MjdiMDliNWZlNWQ1MGFkMmJjOTU1OWUzZjhmOWM3NzEyZGI2ODU=
data/.travis.yml CHANGED
@@ -1,9 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - rbx-18mode
4
3
  - rbx-19mode
5
- - ree
6
- - 1.8.7
7
4
  - 1.9.2
8
5
  - 1.9.3
9
6
  - ruby-head
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,12 @@
1
1
  = Changelog
2
2
 
3
+ == 1.6.1 (May 15, 2013 )
4
+ * Bump czmq to 1.4.1
5
+ * Introduce ZMQ::Beacon for service announcement and discovery
6
+ * Implement ZMQ::Socket#poll
7
+ * Implement ZMQ::Socket#disconnect
8
+ * Drop support for ZeroMQ 2.x
9
+
3
10
  == 1.6 (May 2, 2013 )
4
11
  * Bump czmq to 1.4.0
5
12
  * Bump zeromq to 3.2.3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbczmq (1.4)
4
+ rbczmq (1.6.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
Binary file
@@ -0,0 +1,318 @@
1
+ #include "rbczmq_ext.h"
2
+
3
+ /*
4
+ * :nodoc:
5
+ * Destroy the beacon while the GIL is released.
6
+ *
7
+ */
8
+ static VALUE rb_czmq_nogvl_beacon_destroy(void *ptr)
9
+ {
10
+ zmq_beacon_wrapper *beacon = ptr;
11
+ zbeacon_destroy(&beacon->beacon);
12
+ return Qnil;
13
+ }
14
+
15
+ /*
16
+ * :nodoc:
17
+ * GC free callback
18
+ *
19
+ */
20
+ static void rb_czmq_free_beacon_gc(void *ptr)
21
+ {
22
+ zmq_beacon_wrapper *beacon = (zmq_beacon_wrapper *)ptr;
23
+ if (beacon) {
24
+ rb_thread_blocking_region(rb_czmq_nogvl_beacon_destroy, beacon, RUBY_UBF_IO, 0);
25
+ xfree(beacon);
26
+ }
27
+ }
28
+
29
+ /*
30
+ * :nodoc:
31
+ * Allocate a beacon while the GIL is released.
32
+ *
33
+ */
34
+ static VALUE rb_czmq_nogvl_new_beacon(void *ptr)
35
+ {
36
+ int port = (int)ptr;
37
+ return (VALUE)zbeacon_new(port);
38
+ }
39
+
40
+ /*
41
+ * call-seq:
42
+ * ZMQ::Beacon.new(9999) => ZMQ::Beacon
43
+ *
44
+ * Create a new beacon.
45
+ *
46
+ * === Examples
47
+ * ZMQ::Beacon.new(9999) => ZMQ::Beacon
48
+ *
49
+ */
50
+ static VALUE rb_czmq_beacon_s_new(VALUE beacon, VALUE port)
51
+ {
52
+ zmq_beacon_wrapper *bcn = NULL;
53
+ int prt;
54
+ Check_Type(port, T_FIXNUM);
55
+ beacon = Data_Make_Struct(rb_cZmqBeacon, zmq_beacon_wrapper, 0, rb_czmq_free_beacon_gc, bcn);
56
+ prt = FIX2INT(port);
57
+ bcn->beacon = (zbeacon_t*)rb_thread_blocking_region(rb_czmq_nogvl_new_beacon, (void *)&prt, RUBY_UBF_IO, 0);
58
+ ZmqAssertObjOnAlloc(bcn->beacon, bcn);
59
+ rb_obj_call_init(beacon, 0, NULL);
60
+ return beacon;
61
+ }
62
+
63
+ /*
64
+ * call-seq:
65
+ * beacon.destroy => nil
66
+ *
67
+ * Stop broadcasting a beacon. The GC will take the same action if a beacon object is not reachable anymore on the next
68
+ * GC cycle. This is a lower level API.
69
+ *
70
+ * === Examples
71
+ * beacon.destroy => nil
72
+ *
73
+ */
74
+ static VALUE rb_czmq_beacon_destroy(VALUE obj)
75
+ {
76
+ GetZmqBeacon(obj);
77
+ rb_thread_blocking_region(rb_czmq_nogvl_beacon_destroy, beacon, RUBY_UBF_IO, 0);
78
+ return Qnil;
79
+ }
80
+
81
+ /*
82
+ * call-seq:
83
+ * beacon.hostname => String
84
+ *
85
+ * Returns the beacon's IP address
86
+ *
87
+ * === Examples
88
+ * beacon.hostname => "127.0.0.1"
89
+ *
90
+ */
91
+ static VALUE rb_czmq_beacon_hostname(VALUE obj)
92
+ {
93
+ GetZmqBeacon(obj);
94
+ return rb_str_new2(zbeacon_hostname(beacon->beacon));
95
+ }
96
+
97
+ /*
98
+ * :nodoc:
99
+ * Set the beacon broadcast interval while the GIL is released.
100
+ *
101
+ */
102
+ static VALUE rb_czmq_nogvl_set_interval(void *ptr)
103
+ {
104
+ struct nogvl_beacon_interval_args *args = ptr;
105
+ zmq_beacon_wrapper *beacon = args->beacon;
106
+ zbeacon_set_interval(beacon->beacon, args->interval);
107
+ return Qnil;
108
+ }
109
+
110
+ /*
111
+ * call-seq:
112
+ * beacon.interval = 100 => nil
113
+ *
114
+ * Sets the broadcast interval in milliseconds
115
+ *
116
+ * === Examples
117
+ * beacon.interval = 100 => nil
118
+ *
119
+ */
120
+ static VALUE rb_czmq_beacon_set_interval(VALUE obj, VALUE interval)
121
+ {
122
+ struct nogvl_beacon_interval_args args;
123
+ GetZmqBeacon(obj);
124
+ Check_Type(interval, T_FIXNUM);
125
+ args.beacon = beacon;
126
+ args.interval = FIX2INT(interval);
127
+ rb_thread_blocking_region(rb_czmq_nogvl_set_interval, (void *)&args, RUBY_UBF_IO, 0);
128
+ return Qnil;
129
+ }
130
+
131
+ /*
132
+ * :nodoc:
133
+ * Filter beacons while the GIL is released.
134
+ *
135
+ */
136
+ static VALUE rb_czmq_nogvl_noecho(void *ptr)
137
+ {
138
+ zmq_beacon_wrapper *beacon = ptr;
139
+ zbeacon_noecho(beacon->beacon);
140
+ return Qnil;
141
+ }
142
+
143
+ /*
144
+ * call-seq:
145
+ * beacon.noecho => nil
146
+ *
147
+ * Filter out any beacon that looks exactly like ours
148
+ *
149
+ * === Examples
150
+ * beacon.noecho => nil
151
+ *
152
+ */
153
+ static VALUE rb_czmq_beacon_noecho(VALUE obj)
154
+ {
155
+ GetZmqBeacon(obj);
156
+ rb_thread_blocking_region(rb_czmq_nogvl_noecho, (void *)beacon, RUBY_UBF_IO, 0);
157
+ return Qnil;
158
+ }
159
+
160
+ /*
161
+ * :nodoc:
162
+ * Broadcast beacon while the GIL is released.
163
+ *
164
+ */
165
+ static VALUE rb_czmq_nogvl_publish(void *ptr)
166
+ {
167
+ struct nogvl_beacon_publish_args *args = ptr;
168
+ zmq_beacon_wrapper *beacon = args->beacon;
169
+ zbeacon_publish(beacon->beacon, (byte *)args->transmit ,args->length);
170
+ return Qnil;
171
+ }
172
+
173
+ /*
174
+ * call-seq:
175
+ * beacon.publish("address") => nil
176
+ *
177
+ * Start broadcasting beacon to peers.
178
+ *
179
+ * === Examples
180
+ * beacon.publish("address") => nil
181
+ *
182
+ */
183
+ static VALUE rb_czmq_beacon_publish(VALUE obj, VALUE transmit)
184
+ {
185
+ struct nogvl_beacon_publish_args args;
186
+ GetZmqBeacon(obj);
187
+ Check_Type(transmit, T_STRING);
188
+ args.beacon = beacon;
189
+ args.transmit = StringValueCStr(transmit);
190
+ args.length = (int)RSTRING_LEN(transmit);
191
+ rb_thread_blocking_region(rb_czmq_nogvl_publish, (void *)&args, RUBY_UBF_IO, 0);
192
+ return Qnil;
193
+ }
194
+
195
+ /*
196
+ * :nodoc:
197
+ * Silence beacon while the GIL is released.
198
+ *
199
+ */
200
+ static VALUE rb_czmq_nogvl_silence(void *ptr)
201
+ {
202
+ zmq_beacon_wrapper *beacon = ptr;
203
+ zbeacon_silence(beacon->beacon);
204
+ return Qnil;
205
+ }
206
+
207
+ /*
208
+ * call-seq:
209
+ * beacon.silence => nil
210
+ *
211
+ * Stop broadcasting beacons to peers.
212
+ *
213
+ * === Examples
214
+ * beacon.silence => nil
215
+ *
216
+ */
217
+ static VALUE rb_czmq_beacon_silence(VALUE obj)
218
+ {
219
+ GetZmqBeacon(obj);
220
+ rb_thread_blocking_region(rb_czmq_nogvl_silence, (void *)beacon, RUBY_UBF_IO, 0);
221
+ return Qnil;
222
+ }
223
+
224
+ /*
225
+ * :nodoc:
226
+ * Start listening to peers while the GIL is released.
227
+ *
228
+ */
229
+ static VALUE rb_czmq_nogvl_subscribe(void *ptr)
230
+ {
231
+ struct nogvl_beacon_subscribe_args *args = ptr;
232
+ zmq_beacon_wrapper *beacon = args->beacon;
233
+ zbeacon_subscribe(beacon->beacon, (byte *)args->filter ,args->length);
234
+ return Qnil;
235
+ }
236
+
237
+ /*
238
+ * call-seq:
239
+ * beacon.subscribe("channel") => nil
240
+ *
241
+ * Start listening to other peers.
242
+ *
243
+ * === Examples
244
+ * beacon.subscribe("channel") => nil
245
+ *
246
+ */
247
+ static VALUE rb_czmq_beacon_subscribe(VALUE obj, VALUE filter)
248
+ {
249
+ struct nogvl_beacon_subscribe_args args;
250
+ GetZmqBeacon(obj);
251
+ args.beacon = beacon;
252
+ if (NIL_P(filter)) {
253
+ args.filter = NULL;
254
+ args.length = 0;
255
+ } else {
256
+ Check_Type(filter, T_STRING);
257
+ args.filter = StringValueCStr(filter);
258
+ args.length = (int)RSTRING_LEN(filter);
259
+ }
260
+ rb_thread_blocking_region(rb_czmq_nogvl_subscribe, (void *)&args, RUBY_UBF_IO, 0);
261
+ return Qnil;
262
+ }
263
+
264
+ /*
265
+ * :nodoc:
266
+ * Stop listening to peers while the GIL is released.
267
+ *
268
+ */
269
+ static VALUE rb_czmq_nogvl_unsubscribe(void *ptr)
270
+ {
271
+ zmq_beacon_wrapper *beacon = ptr;
272
+ zbeacon_unsubscribe(beacon->beacon);
273
+ return Qnil;
274
+ }
275
+
276
+ /*
277
+ * call-seq:
278
+ * beacon.unsubscribe => nil
279
+ *
280
+ * Stop broadcasting beacons to peers.
281
+ *
282
+ * === Examples
283
+ * beacon.unsubscribe => nil
284
+ *
285
+ */
286
+ static VALUE rb_czmq_beacon_unsubscribe(VALUE obj)
287
+ {
288
+ GetZmqBeacon(obj);
289
+ rb_thread_blocking_region(rb_czmq_nogvl_unsubscribe, (void *)beacon, RUBY_UBF_IO, 0);
290
+ return Qnil;
291
+ }
292
+
293
+ static VALUE rb_czmq_beacon_pipe(VALUE obj)
294
+ {
295
+ zmq_sock_wrapper *sock = NULL;
296
+ VALUE socket;
297
+ GetZmqBeacon(obj);
298
+ socket = rb_czmq_socket_alloc(Qnil, NULL, zbeacon_pipe(beacon->beacon));
299
+ GetZmqSocket(socket);
300
+ sock->state = ZMQ_SOCKET_BOUND;
301
+ return socket;
302
+ }
303
+
304
+ void _init_rb_czmq_beacon()
305
+ {
306
+ rb_cZmqBeacon = rb_define_class_under(rb_mZmq, "Beacon", rb_cObject);
307
+
308
+ rb_define_singleton_method(rb_cZmqBeacon, "new", rb_czmq_beacon_s_new, 1);
309
+ rb_define_method(rb_cZmqBeacon, "destroy", rb_czmq_beacon_destroy, 0);
310
+ rb_define_method(rb_cZmqBeacon, "hostname", rb_czmq_beacon_hostname, 0);
311
+ rb_define_method(rb_cZmqBeacon, "interval=", rb_czmq_beacon_set_interval, 1);
312
+ rb_define_method(rb_cZmqBeacon, "noecho", rb_czmq_beacon_noecho, 0);
313
+ rb_define_method(rb_cZmqBeacon, "publish", rb_czmq_beacon_publish, 1);
314
+ rb_define_method(rb_cZmqBeacon, "silence", rb_czmq_beacon_silence, 0);
315
+ rb_define_method(rb_cZmqBeacon, "subscribe", rb_czmq_beacon_subscribe, 1);
316
+ rb_define_method(rb_cZmqBeacon, "unsubscribe", rb_czmq_beacon_unsubscribe, 0);
317
+ rb_define_method(rb_cZmqBeacon, "pipe", rb_czmq_beacon_pipe, 0);
318
+ }
@@ -0,0 +1,38 @@
1
+ #ifndef RBCZMQ_BEACON_H
2
+ #define RBCZMQ_BEACON_H
3
+
4
+ typedef struct {
5
+ zbeacon_t *beacon;
6
+ } zmq_beacon_wrapper;
7
+
8
+ #define ZmqAssertBeacon(obj) ZmqAssertType(obj, rb_cZmqBeacon, "ZMQ::Beacon")
9
+ #define GetZmqBeacon(obj) \
10
+ zmq_beacon_wrapper *beacon = NULL; \
11
+ ZmqAssertBeacon(obj); \
12
+ Data_Get_Struct(obj, zmq_beacon_wrapper, beacon); \
13
+ if (!beacon) rb_raise(rb_eTypeError, "uninitialized ZMQ beacon!!"); \
14
+
15
+ struct nogvl_beacon_destroy_args {
16
+ zmq_beacon_wrapper *beacon;
17
+ };
18
+
19
+ struct nogvl_beacon_interval_args {
20
+ zmq_beacon_wrapper *beacon;
21
+ int interval;
22
+ };
23
+
24
+ struct nogvl_beacon_publish_args {
25
+ zmq_beacon_wrapper *beacon;
26
+ char *transmit;
27
+ int length;
28
+ };
29
+
30
+ struct nogvl_beacon_subscribe_args {
31
+ zmq_beacon_wrapper *beacon;
32
+ char *filter;
33
+ int length;
34
+ };
35
+
36
+ void _init_rb_czmq_beacon();
37
+
38
+ #endif
data/ext/rbczmq/context.c CHANGED
@@ -140,7 +140,6 @@ static VALUE rb_czmq_ctx_set_iothreads(VALUE obj, VALUE threads)
140
140
  ZmqGetContext(obj);
141
141
  Check_Type(threads, T_FIXNUM);
142
142
  iothreads = FIX2INT(threads);
143
- if (iothreads > 1) rb_warn("You probably don't want to spawn more than 1 I/O thread per ZMQ context.");
144
143
  if (iothreads < 0) rb_raise(rb_eZmqError, "negative I/O threads count is not supported.");
145
144
  zctx_set_iothreads(ctx->ctx, iothreads);
146
145
  if (zmq_errno() == EINVAL) ZmqRaiseSysError();
@@ -173,52 +172,6 @@ static VALUE rb_czmq_ctx_set_linger(VALUE obj, VALUE linger)
173
172
  return Qnil;
174
173
  }
175
174
 
176
- /*
177
- * call-seq:
178
- * ctx.hwm => Fixnum
179
- *
180
- * Returns High Water Mark (HWM) option used for native thread creation (non-Ruby threads, ahead of time API addition)
181
- *
182
- * === Examples
183
- * ctx = ZMQ::Context.new
184
- * ctx.hwm => 1
185
- *
186
- */
187
-
188
- static VALUE rb_czmq_ctx_hwm(VALUE obj)
189
- {
190
- errno = 0;
191
- int wm;
192
- ZmqGetContext(obj);
193
- rb_warn("Deprecated method ZMQ::Context#hwm, does nothing - to be removed after 2013/05/14");
194
- return INT2FIX(zctx_hwm(ctx->ctx));
195
- }
196
-
197
- /*
198
- * call-seq:
199
- * ctx.hwm = 100 => nil
200
- *
201
- * Sets the High Water Mark (HWM) option used for native thread creation (non-Ruby threads, ahead of time API addition)
202
- *
203
- * === Examples
204
- * ctx = ZMQ::Context.new
205
- * ctx.hwm = 100 => nil
206
- *
207
- */
208
-
209
- static VALUE rb_czmq_ctx_set_hwm(VALUE obj, VALUE hwm)
210
- {
211
- errno = 0;
212
- int wm;
213
- ZmqGetContext(obj);
214
- Check_Type(hwm, T_FIXNUM);
215
- rb_warn("Deprecated method ZMQ::Context#hwm=, does nothing - to be removed after 2013/05/14");
216
- wm = FIX2INT(hwm);
217
- if (wm < 0) rb_raise(rb_eZmqError, "negative HWM values is not supported.");
218
- zctx_set_hwm(ctx->ctx, wm);
219
- return Qnil;
220
- }
221
-
222
175
  /*
223
176
  * :nodoc:
224
177
  * Creates a new socket while the GIL is released.
@@ -266,6 +219,27 @@ static inline VALUE rb_czmq_ctx_socket_klass(int socket_type)
266
219
  }
267
220
  }
268
221
 
222
+ VALUE rb_czmq_socket_alloc(VALUE context, zctx_t *ctx, void *s)
223
+ {
224
+ VALUE socket;
225
+ zmq_sock_wrapper *sock = NULL;
226
+ socket = Data_Make_Struct(rb_czmq_ctx_socket_klass(zsocket_type(s)), zmq_sock_wrapper, rb_czmq_mark_sock, rb_czmq_free_sock_gc, sock);
227
+ sock->socket = s;
228
+ ZmqAssertObjOnAlloc(sock->socket, sock);
229
+ sock->flags = 0;
230
+ sock->ctx = ctx;
231
+ sock->verbose = false;
232
+ sock->state = ZMQ_SOCKET_PENDING;
233
+ sock->endpoints = rb_ary_new();
234
+ sock->thread = rb_thread_current();
235
+ sock->context = context;
236
+ sock->monitor_endpoint = Qnil;
237
+ sock->monitor_handler = Qnil;
238
+ sock->monitor_thread = Qnil;
239
+ rb_obj_call_init(socket, 0, NULL);
240
+ return socket;
241
+ }
242
+
269
243
  /*
270
244
  * call-seq:
271
245
  * ctx.socket(:PUSH) => ZMQ::Socket
@@ -284,37 +258,16 @@ static inline VALUE rb_czmq_ctx_socket_klass(int socket_type)
284
258
 
285
259
  static VALUE rb_czmq_ctx_socket(VALUE obj, VALUE type)
286
260
  {
287
- VALUE socket;
288
261
  int socket_type;
289
262
  struct nogvl_socket_args args;
290
- zmq_sock_wrapper *sock = NULL;
291
263
  errno = 0;
292
264
  ZmqGetContext(obj);
293
265
  if (TYPE(type) != T_FIXNUM && TYPE(type) != T_SYMBOL) rb_raise(rb_eTypeError, "wrong socket type %s (expected Fixnum or Symbol)", RSTRING_PTR(rb_obj_as_string(type)));
294
266
  socket_type = FIX2INT((SYMBOL_P(type)) ? rb_const_get_at(rb_mZmq, rb_to_id(type)) : type);
295
267
 
296
- socket = Data_Make_Struct(rb_czmq_ctx_socket_klass(socket_type), zmq_sock_wrapper, rb_czmq_mark_sock, rb_czmq_free_sock_gc, sock);
297
268
  args.ctx = ctx->ctx;
298
269
  args.type = socket_type;
299
- sock->socket = (void*)rb_thread_blocking_region(rb_czmq_nogvl_socket_new, (void *)&args, RUBY_UBF_IO, 0);
300
- ZmqAssertObjOnAlloc(sock->socket, sock);
301
- #ifndef HAVE_RB_THREAD_BLOCKING_REGION
302
- sock->str_buffer = zlist_new();
303
- sock->frame_buffer = zlist_new();
304
- sock->msg_buffer = zlist_new();
305
- #endif
306
- sock->flags = 0;
307
- sock->ctx = ctx->ctx;
308
- sock->verbose = false;
309
- sock->state = ZMQ_SOCKET_PENDING;
310
- sock->endpoints = rb_ary_new();
311
- sock->thread = rb_thread_current();
312
- sock->context = obj;
313
- sock->monitor_endpoint = Qnil;
314
- sock->monitor_handler = Qnil;
315
- sock->monitor_thread = Qnil;
316
- rb_obj_call_init(socket, 0, NULL);
317
- return socket;
270
+ return rb_czmq_socket_alloc(obj, ctx->ctx, (void*)rb_thread_blocking_region(rb_czmq_nogvl_socket_new, (void *)&args, RUBY_UBF_IO, 0));
318
271
  }
319
272
 
320
273
  void _init_rb_czmq_context()
@@ -329,6 +282,4 @@ void _init_rb_czmq_context()
329
282
  rb_define_method(rb_cZmqContext, "iothreads=", rb_czmq_ctx_set_iothreads, 1);
330
283
  rb_define_method(rb_cZmqContext, "linger=", rb_czmq_ctx_set_linger, 1);
331
284
  rb_define_method(rb_cZmqContext, "socket", rb_czmq_ctx_socket, 1);
332
- rb_define_method(rb_cZmqContext, "hwm", rb_czmq_ctx_hwm, 0);
333
- rb_define_method(rb_cZmqContext, "hwm=", rb_czmq_ctx_set_hwm, 1);
334
285
  }