rbczmq 1.4 → 1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,6 @@ rvm:
8
8
  - 1.9.3
9
9
  - ruby-head
10
10
  script: "bundle exec rake"
11
- before_install: "sudo apt-get install uuid-dev"
12
11
  gemfile:
13
12
  - Gemfile
14
13
  notifications:
@@ -17,4 +16,3 @@ notifications:
17
16
  branches:
18
17
  only:
19
18
  - master
20
- - 3.2
@@ -1,5 +1,9 @@
1
1
  = Changelog
2
2
 
3
+ == 1.5 (April 29, 2013)
4
+ * Add support for XSUB and XPUB socket types (Matt Connolly)
5
+ * Introduce a ZMQ.proxy API (Matt Connolly)
6
+
3
7
  == 1.4 (April 27, 2013)
4
8
  * Ships with release libzmq and czmq tarballs - removes autotools dependency (James Tucker)
5
9
 
data/Gemfile CHANGED
@@ -1,5 +1,6 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rake'
5
+ gem 'rake'
6
+ gem 'rdoc'
@@ -1,14 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbczmq (1.3)
4
+ rbczmq (1.4)
5
5
 
6
6
  GEM
7
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
8
8
  specs:
9
+ json (1.7.7)
9
10
  rake (10.0.4)
10
11
  rake-compiler (0.8.3)
11
12
  rake
13
+ rdoc (4.0.1)
14
+ json (~> 1.4)
12
15
 
13
16
  PLATFORMS
14
17
  ruby
@@ -17,3 +20,4 @@ DEPENDENCIES
17
20
  rake
18
21
  rake-compiler (~> 0.8.0)
19
22
  rbczmq!
23
+ rdoc
data/Rakefile CHANGED
@@ -8,11 +8,7 @@ ENV["RBXOPT"] = "-Xrbc.db"
8
8
 
9
9
  require 'rake/extensiontask'
10
10
  require 'rake/testtask'
11
- begin
12
11
  require 'rdoc/task'
13
- rescue LoadError # fallback to older 1.8.7 rubies
14
- require 'rake/rdoctask'
15
- end
16
12
 
17
13
  gemspec = eval(IO.read('rbczmq.gemspec'))
18
14
 
@@ -257,6 +257,10 @@ static inline VALUE rb_czmq_ctx_socket_klass(int socket_type)
257
257
  break;
258
258
  case ZMQ_DEALER: return rb_cZmqDealerSocket;
259
259
  break;
260
+ case ZMQ_XPUB: return rb_cZmqXPubSocket;
261
+ break;
262
+ case ZMQ_XSUB: return rb_cZmqXSubSocket;
263
+ break;
260
264
  default: rb_raise(rb_eZmqError, "ZMQ socket type %d not supported!", socket_type);
261
265
  break;
262
266
  }
@@ -68,12 +68,11 @@ static VALUE rb_czmq_pollitem_s_new(int argc, VALUE *argv, VALUE obj)
68
68
  if (!(evts & ZMQ_POLLIN) && !(evts & ZMQ_POLLOUT))
69
69
  rb_raise(rb_eZmqError, "invalid socket event: Only ZMQ::POLLIN and ZMQ::POLLOUT events are supported!");
70
70
 
71
- /* XXX: Cleanup allocated struct on any failures below */
72
71
  obj = Data_Make_Struct(rb_cZmqPollitem, zmq_pollitem_wrapper, rb_czmq_mark_pollitem, rb_czmq_free_pollitem_gc, pollitem);
73
72
  pollitem->events = events;
74
73
  pollitem->handler = Qnil;
75
74
  pollitem->item = ALLOC(zmq_pollitem_t);
76
- if (!pollitem->item) rb_memerror();
75
+ ZmqAssertObjOnAlloc(pollitem->item, pollitem);
77
76
  pollitem->item->events = evts;
78
77
  if (rb_obj_is_kind_of(pollable, rb_cZmqSocket)) {
79
78
  GetZmqSocket(pollable);
@@ -14,6 +14,8 @@ VALUE rb_cZmqDealerSocket;
14
14
  VALUE rb_cZmqRepSocket;
15
15
  VALUE rb_cZmqReqSocket;
16
16
  VALUE rb_cZmqPairSocket;
17
+ VALUE rb_cZmqXPubSocket;
18
+ VALUE rb_cZmqXSubSocket;
17
19
 
18
20
  VALUE rb_cZmqFrame;
19
21
  VALUE rb_cZmqMessage;
@@ -153,6 +155,66 @@ static VALUE rb_czmq_m_interrupted_bang(ZMQ_UNUSED VALUE obj)
153
155
  return Qnil;
154
156
  }
155
157
 
158
+ /*
159
+ * :nodoc:
160
+ * Runs the ZeroMQ proxy with the GVL released.
161
+ *
162
+ */
163
+ static VALUE rb_czmq_m_proxy_nogvl(void* args)
164
+ {
165
+ void** sockets = (void**)args;
166
+ return (VALUE)zmq_proxy(sockets[0], sockets[1], sockets[2]);
167
+ }
168
+
169
+ /*
170
+ * call-seq:
171
+ * ZMQ.proxy(frontend, backend, capture = nil) => nil
172
+ *
173
+ * Run the ZMQ proxy method echoing messages received from front end socket to back end and vice versa,
174
+ * copying messages to the capture socket if provided. This method does not return unless the application
175
+ * is interrupted with a signal.
176
+ *
177
+ * @see http://api.zeromq.org/3-2:zmq-proxy
178
+ *
179
+ * === Examples
180
+ * context = ZMQ::Context.new
181
+ * frontend = context.socket(ZMQ::ROUTER)
182
+ * frontend.bind("tcp://*:5555")
183
+ * backend = context.socket(ZMQ::DEALER)
184
+ * backend.bind("tcp://*:5556")
185
+ * ZMQ.proxy(frontend, backend) => -1 when interrupted
186
+ */
187
+ static VALUE rb_czmq_m_proxy(int argc, VALUE *argv, ZMQ_UNUSED VALUE klass)
188
+ {
189
+ zmq_sock_wrapper *sock = NULL;
190
+ VALUE frontend, backend, capture;
191
+ void *sockets[3];
192
+ int rc;
193
+
194
+ rb_scan_args(argc, argv, "21", &frontend, &backend, &capture);
195
+
196
+ GetZmqSocket(frontend);
197
+ sockets[0] = sock->socket;
198
+
199
+ GetZmqSocket(backend);
200
+ sockets[1] = sock->socket;
201
+
202
+ if (!NIL_P(capture))
203
+ {
204
+ GetZmqSocket(capture);
205
+ sockets[2] = sock->socket;
206
+ }
207
+ else
208
+ {
209
+ sockets[2] = NULL;
210
+ }
211
+
212
+ rc = (int)rb_thread_blocking_region(rb_czmq_m_proxy_nogvl, (void *)sockets, RUBY_UBF_IO, 0);
213
+
214
+ // int result = zmq_proxy(frontend_socket, backend_socket, capture_socket);
215
+ return INT2NUM(rc);
216
+ }
217
+
156
218
  void Init_rbczmq_ext()
157
219
  {
158
220
  frames_map = st_init_numtable();
@@ -177,6 +239,7 @@ void Init_rbczmq_ext()
177
239
  rb_define_module_function(rb_mZmq, "error", rb_czmq_m_error, 0);
178
240
  rb_define_module_function(rb_mZmq, "errno", rb_czmq_m_errno, 0);
179
241
  rb_define_module_function(rb_mZmq, "interrupted!", rb_czmq_m_interrupted_bang, 0);
242
+ rb_define_module_function(rb_mZmq, "proxy", rb_czmq_m_proxy, -1);
180
243
 
181
244
  rb_define_const(rb_mZmq, "POLLIN", INT2NUM(ZMQ_POLLIN));
182
245
  rb_define_const(rb_mZmq, "POLLOUT", INT2NUM(ZMQ_POLLOUT));
@@ -191,6 +254,8 @@ void Init_rbczmq_ext()
191
254
  rb_define_const(rb_mZmq, "ROUTER", INT2NUM(ZMQ_ROUTER));
192
255
  rb_define_const(rb_mZmq, "PUSH", INT2NUM(ZMQ_PUSH));
193
256
  rb_define_const(rb_mZmq, "PULL", INT2NUM(ZMQ_PULL));
257
+ rb_define_const(rb_mZmq, "XSUB", INT2NUM(ZMQ_XSUB));
258
+ rb_define_const(rb_mZmq, "XPUB", INT2NUM(ZMQ_XPUB));
194
259
 
195
260
  rb_define_const(rb_mZmq, "EFSM", INT2NUM(EFSM));
196
261
  rb_define_const(rb_mZmq, "ENOCOMPATPROTO", INT2NUM(ENOCOMPATPROTO));
@@ -58,6 +58,8 @@ extern VALUE rb_cZmqDealerSocket;
58
58
  extern VALUE rb_cZmqRepSocket;
59
59
  extern VALUE rb_cZmqReqSocket;
60
60
  extern VALUE rb_cZmqPairSocket;
61
+ extern VALUE rb_cZmqXPubSocket;
62
+ extern VALUE rb_cZmqXSubSocket;
61
63
 
62
64
  extern VALUE rb_cZmqFrame;
63
65
  extern VALUE rb_cZmqMessage;
@@ -1748,6 +1748,8 @@ void _init_rb_czmq_socket()
1748
1748
  rb_cZmqRepSocket = rb_define_class_under(rb_cZmqSocket, "Rep", rb_cZmqSocket);;
1749
1749
  rb_cZmqReqSocket = rb_define_class_under(rb_cZmqSocket, "Req", rb_cZmqSocket);;
1750
1750
  rb_cZmqPairSocket = rb_define_class_under(rb_cZmqSocket, "Pair", rb_cZmqSocket);;
1751
+ rb_cZmqXPubSocket = rb_define_class_under(rb_cZmqSocket, "XPub", rb_cZmqSocket);
1752
+ rb_cZmqXSubSocket = rb_define_class_under(rb_cZmqSocket, "XSub", rb_cZmqSocket);;
1751
1753
 
1752
1754
  intern_on_connected = rb_intern("on_connected");
1753
1755
  intern_on_connect_delayed = rb_intern("on_connect_delayed");
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module ZMQ
4
- VERSION = "1.4"
4
+ VERSION = "1.5"
5
5
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbczmq
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 4
9
- version: "1.4"
8
+ - 5
9
+ version: "1.5"
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Lourens Naud\xC3\xA9"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-04-27 00:00:00 Z
18
+ date: 2013-04-29 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rake-compiler