rbczmq 0.8 → 0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,4 +16,5 @@ notifications:
16
16
  - lourens@methodmissing.com
17
17
  branches:
18
18
  only:
19
- - master
19
+ - master
20
+ - 3.2
@@ -1,5 +1,10 @@
1
1
  = Changelog
2
2
 
3
+ == 0.9 (August 18, 2012)
4
+ * Sockets now record and show all endpoints
5
+ * Support connect_all for SRV managed topologies
6
+ * Fix Rubinius specific compile errors
7
+
3
8
  == 0.8 (June 25, 2012)
4
9
  * Remove entries from the frames pointer map when managed frame objects are freed during GC
5
10
  * czmq's addstr and pushstr functions expect a format string, users of the library aren't (presently) expecting that (James Tucker)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbczmq (0.7)
4
+ rbczmq (0.8)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -222,6 +222,13 @@ Running tests
222
222
 
223
223
  rake test
224
224
 
225
+ OS X notes:
226
+
227
+ If you are installing the package on a new mack ensure you have libtool and autoconf isntalled.
228
+ You can get those with brew packaging system:
229
+
230
+ brew insatll libtool autoconf automake
231
+
225
232
  == TODO
226
233
 
227
234
  * ZMQ::Message#save && ZMQ::Message.load
@@ -1,4 +1,4 @@
1
- #include <rbczmq_ext.h>
1
+ #include "rbczmq_ext.h"
2
2
 
3
3
  static VALUE intern_zctx_process;
4
4
 
@@ -301,7 +301,7 @@ static VALUE rb_czmq_ctx_socket(VALUE obj, VALUE type)
301
301
  sock->ctx = ctx->ctx;
302
302
  sock->verbose = FALSE;
303
303
  sock->state = ZMQ_SOCKET_PENDING;
304
- sock->endpoint = Qnil;
304
+ sock->endpoints = rb_ary_new();
305
305
  sock->thread = rb_thread_current();
306
306
  rb_obj_call_init(socket, 0, NULL);
307
307
  return socket;
@@ -1,4 +1,4 @@
1
- #include <rbczmq_ext.h>
1
+ #include "rbczmq_ext.h"
2
2
  static VALUE intern_data;
3
3
 
4
4
  /*
@@ -1,4 +1,4 @@
1
- #include <rbczmq_ext.h>
1
+ #include "rbczmq_ext.h"
2
2
 
3
3
  /*
4
4
  * :nodoc:
@@ -1,4 +1,4 @@
1
- #include <rbczmq_ext.h>
1
+ #include "rbczmq_ext.h"
2
2
 
3
3
  /*
4
4
  * :nodoc:
@@ -1,4 +1,4 @@
1
- #include <rbczmq_ext.h>
1
+ #include "rbczmq_ext.h"
2
2
 
3
3
  /*
4
4
  * :nodoc:
@@ -1,4 +1,4 @@
1
- #include <rbczmq_ext.h>
1
+ #include "rbczmq_ext.h"
2
2
 
3
3
  /*
4
4
  * :nodoc:
@@ -1,4 +1,4 @@
1
- #include <rbczmq_ext.h>
1
+ #include "rbczmq_ext.h"
2
2
 
3
3
  VALUE rb_mZmq;
4
4
  VALUE rb_eZmqError;
@@ -14,7 +14,7 @@
14
14
  #define ZMQ_NOINLINE
15
15
  #endif
16
16
 
17
- #include <rbczmq_prelude.h>
17
+ #include "rbczmq_prelude.h"
18
18
 
19
19
  #define ZmqRaiseSysError() { \
20
20
  printf("Sys error location: %s:%d\n", __FILE__,__LINE__); \
@@ -73,14 +73,14 @@ extern VALUE intern_readable;
73
73
  extern VALUE intern_writable;
74
74
  extern VALUE intern_error;
75
75
 
76
- #include <context.h>
77
- #include <socket.h>
78
- #include <frame.h>
79
- #include <message.h>
80
- #include <loop.h>
81
- #include <timer.h>
82
- #include <poller.h>
83
- #include <pollitem.h>
76
+ #include "context.h"
77
+ #include "socket.h"
78
+ #include "frame.h"
79
+ #include "message.h"
80
+ #include "loop.h"
81
+ #include "timer.h"
82
+ #include "poller.h"
83
+ #include "pollitem.h"
84
84
 
85
85
  static inline char *rb_czmq_formatted_current_time()
86
86
  {
@@ -6,15 +6,15 @@
6
6
  #endif
7
7
 
8
8
  #ifdef RUBINIUS
9
- #include <rubinius.h>
9
+ #include "rubinius.h"
10
10
  #else
11
11
  #ifdef JRUBY
12
- #include <jruby.h>
12
+ #include "jruby.h"
13
13
  #else
14
14
  #ifdef HAVE_RB_THREAD_BLOCKING_REGION
15
- #include <ruby19.h>
15
+ #include "ruby19.h"
16
16
  #else
17
- #include <ruby18.h>
17
+ #include "ruby18.h"
18
18
  #endif
19
19
  #endif
20
20
  #endif
@@ -1,4 +1,4 @@
1
- #include <rbczmq_ext.h>
1
+ #include "rbczmq_ext.h"
2
2
 
3
3
  /*
4
4
  * :nodoc:
@@ -40,7 +40,7 @@ void rb_czmq_mark_sock(void *ptr)
40
40
  if (sock){
41
41
  if (sock->verbose)
42
42
  zclock_log ("I: %s socket %p, context %p: GC mark", zsocket_type_str(sock->socket), sock, sock->ctx);
43
- rb_gc_mark(sock->endpoint);
43
+ rb_gc_mark(sock->endpoints);
44
44
  rb_gc_mark(sock->thread);
45
45
  }
46
46
  }
@@ -96,24 +96,24 @@ static VALUE rb_czmq_socket_close(VALUE obj)
96
96
 
97
97
  /*
98
98
  * call-seq:
99
- * sock.endpoint => String or nil
99
+ * sock.endpoints => Array of Strings
100
100
  *
101
- * Returns the endpoint this socket is currently connected to, if any.
101
+ * Returns the endpoints this socket is currently connected to, if any.
102
102
  *
103
103
  * === Examples
104
104
  * ctx = ZMQ::Context.new
105
105
  * sock = ctx.socket(:PUSH)
106
- * sock.endpoint => nil
106
+ * sock.endpoints => []
107
107
  * sock.bind("inproc://test")
108
- * sock.endpoint => "inproc://test"
108
+ * sock.endpoints => ["inproc://test"]
109
109
  *
110
110
  */
111
111
 
112
- static VALUE rb_czmq_socket_endpoint(VALUE obj)
112
+ static VALUE rb_czmq_socket_endpoints(VALUE obj)
113
113
  {
114
114
  zmq_sock_wrapper *sock = NULL;
115
115
  GetZmqSocket(obj);
116
- return sock->endpoint;
116
+ return sock->endpoints;
117
117
  }
118
118
 
119
119
  /*
@@ -221,7 +221,7 @@ static VALUE rb_czmq_socket_bind(VALUE obj, VALUE endpoint)
221
221
  if (sock->verbose)
222
222
  zclock_log ("I: %s socket %p: bound \"%s\"", zsocket_type_str(sock->socket), obj, StringValueCStr(endpoint));
223
223
  sock->state = ZMQ_SOCKET_BOUND;
224
- sock->endpoint = rb_str_new4(endpoint);
224
+ rb_ary_push(sock->endpoints, rb_str_new4(endpoint));
225
225
  return INT2NUM(rc);
226
226
  }
227
227
 
@@ -255,7 +255,7 @@ static VALUE rb_czmq_socket_connect(VALUE obj, VALUE endpoint)
255
255
  if (sock->verbose)
256
256
  zclock_log ("I: %s socket %p: connected \"%s\"", zsocket_type_str(sock->socket), obj, StringValueCStr(endpoint));
257
257
  sock->state = ZMQ_SOCKET_CONNECTED;
258
- sock->endpoint = rb_str_new4(endpoint);
258
+ rb_ary_push(sock->endpoints, rb_str_new4(endpoint));
259
259
  return Qtrue;
260
260
  }
261
261
 
@@ -1503,7 +1503,7 @@ void _init_rb_czmq_socket()
1503
1503
  rb_define_const(rb_cZmqSocket, "CONNECTED", INT2NUM(ZMQ_SOCKET_CONNECTED));
1504
1504
 
1505
1505
  rb_define_method(rb_cZmqSocket, "close", rb_czmq_socket_close, 0);
1506
- rb_define_method(rb_cZmqSocket, "endpoint", rb_czmq_socket_endpoint, 0);
1506
+ rb_define_method(rb_cZmqSocket, "endpoints", rb_czmq_socket_endpoints, 0);
1507
1507
  rb_define_method(rb_cZmqSocket, "state", rb_czmq_socket_state, 0);
1508
1508
  rb_define_method(rb_cZmqSocket, "real_bind", rb_czmq_socket_bind, 1);
1509
1509
  rb_define_method(rb_cZmqSocket, "real_connect", rb_czmq_socket_connect, 1);
@@ -20,7 +20,7 @@ typedef struct {
20
20
  zlist_t *frame_buffer;
21
21
  zlist_t *msg_buffer;
22
22
  #endif
23
- VALUE endpoint;
23
+ VALUE endpoints;
24
24
  VALUE thread;
25
25
  } zmq_sock_wrapper;
26
26
 
@@ -1,4 +1,4 @@
1
- #include <rbczmq_ext.h>
1
+ #include "rbczmq_ext.h"
2
2
 
3
3
  /*
4
4
  * :nodoc:
@@ -24,6 +24,18 @@ class ZMQ::Socket
24
24
  end
25
25
  end
26
26
 
27
+
28
+ # Returns the endpoint this socket is currently connected to, if any.
29
+ #
30
+ # ctx = ZMQ::Context.new
31
+ # sock = ctx.socket(:PUSH)
32
+ # sock.endpoint => nil
33
+ # sock.bind("inproc://test")
34
+ # sock.endpoint => "inproc://test"
35
+ def endpoint
36
+ endpoints.first
37
+ end
38
+
27
39
  # Determines if there are one or more messages to read from this socket. Should be used in conjunction with the
28
40
  # ZMQ_FD socket option for edge-triggered notifications.
29
41
  #
@@ -59,9 +71,9 @@ class ZMQ::Socket
59
71
  def to_s
60
72
  case state
61
73
  when BOUND
62
- "#{type_str} socket bound to #{endpoint}"
74
+ "#{type_str} socket bound to #{endpoints.join(', ')}"
63
75
  when CONNECTED
64
- "#{type_str} socket connected to #{endpoint}"
76
+ "#{type_str} socket connected to #{endpoints.join(', ')}"
65
77
  else
66
78
  "#{type_str} socket"
67
79
  end
@@ -101,15 +113,35 @@ class ZMQ::Socket
101
113
  real_connect(uri)
102
114
  end
103
115
 
116
+ # Connects to all endpoints that are returned from a SRV record lookup.
117
+ #
118
+ # socket = ctx.socket(:PUB)
119
+ #
120
+ # socket.connect "collector.domain.com" # resolves 10.0.0.2:9000 10.0.0.3:9000
121
+ #
122
+ def connect_all(uri)
123
+ if uri =~ PROTO_REXP
124
+ real_connect(uri)
125
+ return
126
+ end
127
+
128
+ addresses = resolve_all(uri)
129
+ if addresses.empty?
130
+ real_connect(uri)
131
+ else
132
+ addresses.each do |address|
133
+ host = Resolv.getaddress(address.target.to_s)
134
+ real_connect("tcp://#{host}:#{address.port}")
135
+ end
136
+ end
137
+ self
138
+ end
139
+
104
140
  private
105
141
  # Attempt to resolve DNS SRV records ( http://en.wikipedia.org/wiki/SRV_record ). Respects priority and weight
106
142
  # to provide a combination of load balancing and backup.
107
143
  def resolve(uri)
108
- parts = uri.split('.')
109
- service = parts.shift
110
- domain = parts.join(".")
111
- # ZeroMQ does not yet support udp, but may look into possibly supporting [e]pgm here
112
- resources = ZMQ.resolver.getresources("_#{service}._tcp.#{domain}", Resolv::DNS::Resource::IN::SRV)
144
+ resources = resolve_all(uri)
113
145
  # lowest-numbered priority value is preferred
114
146
  resources.sort!{|a,b| a.priority <=> b.priority }
115
147
  res = resources.first
@@ -120,10 +152,18 @@ class ZMQ::Socket
120
152
  res = priority_peers.sort{|a,b| a.weight <=> b.weight }.last
121
153
  end
122
154
  return uri unless res
155
+ # ZeroMQ does not yet support udp, but may look into possibly supporting [e]pgm here
123
156
  "tcp://#{Resolv.getaddress(res.target.to_s)}:#{res.port}"
124
157
  rescue
125
158
  uri
126
159
  end
160
+
161
+ def resolve_all(uri)
162
+ parts = uri.split('.')
163
+ service = parts.shift
164
+ domain = parts.join(".")
165
+ ZMQ.resolver.getresources("_#{service}._tcp.#{domain}", Resolv::DNS::Resource::IN::SRV)
166
+ end
127
167
  end
128
168
 
129
169
  module ZMQ::DownstreamSocket
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module ZMQ
4
- VERSION = "0.8"
4
+ VERSION = "0.9"
5
5
  end
@@ -131,6 +131,21 @@ class TestZmqSocket < ZmqTestCase
131
131
  ctx.destroy
132
132
  end
133
133
 
134
+ def test_connect_all
135
+ ctx = ZMQ::Context.new
136
+ rep = ctx.socket(:PAIR)
137
+ port = rep.bind("inproc://test.socket-connect")
138
+ req = ctx.socket(:PAIR)
139
+ assert(req.state & ZMQ::Socket::PENDING)
140
+ req.connect_all("inproc://test.socket-connect")
141
+ assert req.fd != -1
142
+ assert(req.state & ZMQ::Socket::CONNECTED)
143
+
144
+ # TODO - test SRV lookups - insufficient infrastructure for resolver tests
145
+ ensure
146
+ ctx.destroy
147
+ end
148
+
134
149
  def test_bind_connect_errors
135
150
  ctx = ZMQ::Context.new
136
151
  req = ctx.socket(:REQ)
@@ -156,6 +171,12 @@ class TestZmqSocket < ZmqTestCase
156
171
  assert_equal "PAIR socket", sock.to_s
157
172
  assert_equal "REP socket bound to tcp://127.0.0.1:*", rep.to_s
158
173
  assert_equal "REQ socket connected to tcp://127.0.0.1:#{port}", req.to_s
174
+
175
+
176
+ port2 = rep.bind("tcp://127.0.0.1:*")
177
+ req.connect("tcp://127.0.0.1:#{port2}")
178
+ assert_equal "REP socket bound to tcp://127.0.0.1:*, tcp://127.0.0.1:*", rep.to_s
179
+ assert_equal "REQ socket connected to tcp://127.0.0.1:#{port}, tcp://127.0.0.1:#{port2}", req.to_s
159
180
  ensure
160
181
  ctx.destroy
161
182
  end
@@ -172,6 +193,23 @@ class TestZmqSocket < ZmqTestCase
172
193
  ctx.destroy
173
194
  end
174
195
 
196
+ def test_endpoints
197
+ ctx = ZMQ::Context.new
198
+ rep = ctx.socket(:REP)
199
+ port = rep.bind("tcp://127.0.0.1:*")
200
+ req = ctx.socket(:REQ)
201
+ req.connect("tcp://127.0.0.1:#{port}")
202
+ assert_equal ["tcp://127.0.0.1:*"], rep.endpoints
203
+ assert_equal ["tcp://127.0.0.1:#{port}"], req.endpoints
204
+
205
+ port2 = rep.bind("tcp://127.0.0.1:*")
206
+ req.connect("tcp://127.0.0.1:#{port2}")
207
+ assert_equal ["tcp://127.0.0.1:*", "tcp://127.0.0.1:*"], rep.endpoints
208
+ assert_equal ["tcp://127.0.0.1:#{port}", "tcp://127.0.0.1:#{port2}"], req.endpoints
209
+ ensure
210
+ ctx.destroy
211
+ end
212
+
175
213
  def test_close
176
214
  ctx = ZMQ::Context.new
177
215
  sock = ctx.socket(:REP)
@@ -451,4 +489,4 @@ class TestZmqSocket < ZmqTestCase
451
489
  ensure
452
490
  ctx.destroy
453
491
  end
454
- end
492
+ end
@@ -8,7 +8,9 @@ class TestZmq < ZmqTestCase
8
8
  end
9
9
 
10
10
  def test_version
11
- assert_equal [2,2,1], ZMQ.version
11
+ version = ZMQ.version
12
+ assert_instance_of Array, version
13
+ assert version.all?{|v| Fixnum === v }
12
14
  end
13
15
 
14
16
  def test_now
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: 3451978084848223320
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 8
9
- version: "0.8"
8
+ - 9
9
+ version: "0.9"
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Lourens Naud\xC3\xA9"
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-25 00:00:00 +01:00
19
- default_executable:
18
+ date: 2012-08-19 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: rake-compiler
@@ -26,7 +25,7 @@ dependencies:
26
25
  requirements:
27
26
  - - ~>
28
27
  - !ruby/object:Gem::Version
29
- hash: 289844351982071926
28
+ hash: 63
30
29
  segments:
31
30
  - 0
32
31
  - 8
@@ -146,7 +145,6 @@ files:
146
145
  - test/test_threading.rb
147
146
  - test/test_timer.rb
148
147
  - test/test_zmq.rb
149
- has_rdoc: true
150
148
  homepage: http://github.com/methodmissing/rbczmq
151
149
  licenses: []
152
150
 
@@ -160,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
158
  requirements:
161
159
  - - ">="
162
160
  - !ruby/object:Gem::Version
163
- hash: 2002549777813010636
161
+ hash: 3
164
162
  segments:
165
163
  - 0
166
164
  version: "0"
@@ -169,14 +167,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
167
  requirements:
170
168
  - - ">="
171
169
  - !ruby/object:Gem::Version
172
- hash: 2002549777813010636
170
+ hash: 3
173
171
  segments:
174
172
  - 0
175
173
  version: "0"
176
174
  requirements: []
177
175
 
178
176
  rubyforge_project:
179
- rubygems_version: 1.5.2
177
+ rubygems_version: 1.8.15
180
178
  signing_key:
181
179
  specification_version: 3
182
180
  summary: "Ruby extension for CZMQ - High-level C Binding for \xC3\x98MQ (http://czmq.zeromq.org)"
@@ -207,3 +205,4 @@ test_files:
207
205
  - test/test_threading.rb
208
206
  - test/test_timer.rb
209
207
  - test/test_zmq.rb
208
+ has_rdoc: true