0mq 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 773f90d7147a3cbb26b3a5d5133c16e36ec81da5
4
- data.tar.gz: 5a241ddd18035b6d933ae28ac328062351d31d48
3
+ metadata.gz: 86e8b8e57ecbb3d3133df643d848ca1532985386
4
+ data.tar.gz: 23db53fb586e9501727f3ba449373ea45fec6e0b
5
5
  SHA512:
6
- metadata.gz: 6c986fc018852a26c27241a1f256f20f6066177d9c4590b1da43f35240c33b50522e0cf1e13aa0afe7f9e24027650f3fc424c3d7a8ba7626e8dcd3cbd3c306b3
7
- data.tar.gz: d8d5fbc4bd75afa98b4a8101335eda0744a5cd21a73f699c71f3f12650ebd9746bf48b0801bbc71f688d1953f07e59ac8f35c548f88bd793c18ff5d7f9c05e54
6
+ metadata.gz: 36cc44a8b6906a6f854db3eeb5cc96ed9dca8dee2cf2aa61a84e5074828135a5471b2b49526a9e186dec36312718ab676a5e308ea69c5bc133996d5fc64dd2dd
7
+ data.tar.gz: 5cbeb65decd7de7e5f54609b5911a5f0edb872a53f4e6e8082adb809f53a42670025b2acfd5172ef0fd5a8d92b73480cddee0e4aecc1a8c454e4ef8ec24f72b1
@@ -1,4 +1,6 @@
1
1
 
2
+ require_relative 'socket/options'
3
+
2
4
  module ZMQ
3
5
 
4
6
  class Socket
@@ -6,8 +8,8 @@ module ZMQ
6
8
  attr_reader :context
7
9
  attr_reader :type
8
10
 
9
- def initialize(type, context:ZMQ::DefaultContext)
10
- @context = context
11
+ def initialize(type, opts={})
12
+ @context = opts.fetch :context, ZMQ::DefaultContext
11
13
  @type = type
12
14
  @ptr = LibZMQ.zmq_socket @context.ptr, @type
13
15
 
@@ -115,6 +117,35 @@ module ZMQ
115
117
  end
116
118
  end
117
119
 
120
+ # Send a multipart message as routing array and a body array
121
+ # All parts before an empty part are considered routing parts,
122
+ # and all parta after the empty part are considered body parts.
123
+ # The empty delimiter part should not be included in the input arrays.
124
+ def send_with_routing(routing, body)
125
+ send_array [*routing, '', *body]
126
+ end
127
+
128
+ # Receive a multipart message as routing array and a body array
129
+ # All parts before an empty part are considered routing parts,
130
+ # and all parta after the empty part are considered body parts.
131
+ # The empty delimiter part is not included in the resulting arrays.
132
+ def recv_with_routing
133
+ [[],[]].tap do |routing, body|
134
+ loop do
135
+ nxt = recv_string
136
+ break if nxt.empty?
137
+ routing << nxt
138
+ raise ArgumentError, "Expected empty routing delimiter in "\
139
+ "multipart message: #{routing}" \
140
+ unless get_opt ZMQ::RCVMORE
141
+ end
142
+ loop do
143
+ body << recv_string
144
+ break unless get_opt(ZMQ::RCVMORE)
145
+ end
146
+ end
147
+ end
148
+
118
149
  # Set a socket option
119
150
  def set_opt(option, value)
120
151
  type = @@option_types.fetch(option) \
@@ -171,89 +202,6 @@ module ZMQ
171
202
  ]
172
203
  end
173
204
 
174
- @@option_types = {
175
- # Get options
176
- ZMQ::RCVMORE => :bool,
177
- ZMQ::RCVHWM => :int,
178
- ZMQ::AFFINITY => :uint64,
179
- ZMQ::IDENTITY => :string,
180
- ZMQ::RATE => :int,
181
- ZMQ::RECOVERY_IVL => :int,
182
- ZMQ::SNDBUF => :int,
183
- ZMQ::RCVBUF => :int,
184
- ZMQ::LINGER => :int,
185
- ZMQ::RECONNECT_IVL => :int,
186
- ZMQ::RECONNECT_IVL_MAX => :int,
187
- ZMQ::BACKLOG => :int,
188
- ZMQ::MAXMSGSIZE => :int64,
189
- ZMQ::MULTICAST_HOPS => :int,
190
- ZMQ::RCVTIMEO => :int,
191
- ZMQ::SNDTIMEO => :int,
192
- ZMQ::IPV6 => :bool,
193
- ZMQ::IPV4ONLY => :bool,
194
- ZMQ::IMMEDIATE => :bool,
195
- ZMQ::FD => :int,
196
- ZMQ::EVENTS => :int,
197
- ZMQ::LAST_ENDPOINT => :string,
198
- ZMQ::TCP_KEEPALIVE => :int,
199
- ZMQ::TCP_KEEPALIVE_IDLE => :int,
200
- ZMQ::TCP_KEEPALIVE_CNT => :int,
201
- ZMQ::TCP_KEEPALIVE_INTVL => :int,
202
- ZMQ::MECHANISM => :int,
203
- ZMQ::PLAIN_SERVER => :int,
204
- ZMQ::PLAIN_USERNAME => :string,
205
- ZMQ::PLAIN_PASSWORD => :string,
206
- ZMQ::CURVE_PUBLICKEY => :string,
207
- ZMQ::CURVE_SECRETKEY => :string,
208
- ZMQ::CURVE_SERVERKEY => :string,
209
- ZMQ::ZAP_DOMAIN => :string,
210
- }.merge({
211
- # Set options
212
- ZMQ::SNDHWM => :int,
213
- ZMQ::RCVHWM => :int,
214
- ZMQ::AFFINITY => :uint64,
215
- ZMQ::SUBSCRIBE => :string,
216
- ZMQ::UNSUBSCRIBE => :string,
217
- ZMQ::IDENTITY => :string,
218
- ZMQ::RATE => :int,
219
- ZMQ::RECOVERY_IVL => :int,
220
- ZMQ::SNDBUF => :int,
221
- ZMQ::RCVBUF => :int,
222
- ZMQ::LINGER => :int,
223
- ZMQ::RECONNECT_IVL => :int,
224
- ZMQ::RECONNECT_IVL_MAX => :int,
225
- ZMQ::RECONNECT_IVL => :int,
226
- ZMQ::BACKLOG => :int,
227
- ZMQ::MAXMSGSIZE => :int64,
228
- ZMQ::MULTICAST_HOPS => :int,
229
- ZMQ::RCVTIMEO => :int,
230
- ZMQ::SNDTIMEO => :int,
231
- ZMQ::IPV6 => :bool,
232
- ZMQ::IPV4ONLY => :bool,
233
- ZMQ::IMMEDIATE => :bool,
234
- ZMQ::ROUTER_HANDOVER => :int,
235
- ZMQ::ROUTER_MANDATORY => :int,
236
- ZMQ::ROUTER_RAW => :int,
237
- ZMQ::PROBE_ROUTER => :int,
238
- ZMQ::XPUB_VERBOSE => :int,
239
- ZMQ::REQ_CORRELATE => :int,
240
- ZMQ::REQ_RELAXED => :int,
241
- ZMQ::TCP_KEEPALIVE => :int,
242
- ZMQ::TCP_KEEPALIVE_IDLE => :int,
243
- ZMQ::TCP_KEEPALIVE_CNT => :int,
244
- ZMQ::TCP_KEEPALIVE_INTVL => :int,
245
- ZMQ::TCP_ACCEPT_FILTER => :string,
246
- ZMQ::PLAIN_SERVER => :int,
247
- ZMQ::PLAIN_USERNAME => :string,
248
- ZMQ::PLAIN_PASSWORD => :string,
249
- ZMQ::CURVE_SERVER => :int,
250
- ZMQ::CURVE_PUBLICKEY => :string,
251
- ZMQ::CURVE_SECRETKEY => :string,
252
- ZMQ::CURVE_SERVERKEY => :string,
253
- ZMQ::ZAP_DOMAIN => :string,
254
- ZMQ::CONFLATE => :bool,
255
- })
256
-
257
205
  end
258
206
 
259
207
  end
@@ -0,0 +1,113 @@
1
+
2
+ module ZMQ
3
+
4
+ class Socket
5
+
6
+ @@get_options = {
7
+ :RCVMORE => :bool,
8
+ :RCVHWM => :int,
9
+ :AFFINITY => :uint64,
10
+ :IDENTITY => :string,
11
+ :RATE => :int,
12
+ :RECOVERY_IVL => :int,
13
+ :SNDBUF => :int,
14
+ :RCVBUF => :int,
15
+ :LINGER => :int,
16
+ :RECONNECT_IVL => :int,
17
+ :RECONNECT_IVL_MAX => :int,
18
+ :BACKLOG => :int,
19
+ :MAXMSGSIZE => :int64,
20
+ :MULTICAST_HOPS => :int,
21
+ :RCVTIMEO => :int,
22
+ :SNDTIMEO => :int,
23
+ :IPV6 => :bool,
24
+ :IPV4ONLY => :bool,
25
+ :IMMEDIATE => :bool,
26
+ :FD => :int,
27
+ :EVENTS => :int,
28
+ :LAST_ENDPOINT => :string,
29
+ :TCP_KEEPALIVE => :int,
30
+ :TCP_KEEPALIVE_IDLE => :int,
31
+ :TCP_KEEPALIVE_CNT => :int,
32
+ :TCP_KEEPALIVE_INTVL => :int,
33
+ :MECHANISM => :int,
34
+ :PLAIN_SERVER => :int,
35
+ :PLAIN_USERNAME => :string,
36
+ :PLAIN_PASSWORD => :string,
37
+ :CURVE_PUBLICKEY => :string,
38
+ :CURVE_SECRETKEY => :string,
39
+ :CURVE_SERVERKEY => :string,
40
+ :ZAP_DOMAIN => :string,
41
+ }
42
+
43
+ @@set_options = {
44
+ :SNDHWM => :int,
45
+ :RCVHWM => :int,
46
+ :AFFINITY => :uint64,
47
+ :SUBSCRIBE => :string,
48
+ :UNSUBSCRIBE => :string,
49
+ :IDENTITY => :string,
50
+ :RATE => :int,
51
+ :RECOVERY_IVL => :int,
52
+ :SNDBUF => :int,
53
+ :RCVBUF => :int,
54
+ :LINGER => :int,
55
+ :RECONNECT_IVL => :int,
56
+ :RECONNECT_IVL_MAX => :int,
57
+ :RECONNECT_IVL => :int,
58
+ :BACKLOG => :int,
59
+ :MAXMSGSIZE => :int64,
60
+ :MULTICAST_HOPS => :int,
61
+ :RCVTIMEO => :int,
62
+ :SNDTIMEO => :int,
63
+ :IPV6 => :bool,
64
+ :IPV4ONLY => :bool,
65
+ :IMMEDIATE => :bool,
66
+ :ROUTER_HANDOVER => :int,
67
+ :ROUTER_MANDATORY => :int,
68
+ :ROUTER_RAW => :int,
69
+ :PROBE_ROUTER => :int,
70
+ :XPUB_VERBOSE => :int,
71
+ :REQ_CORRELATE => :int,
72
+ :REQ_RELAXED => :int,
73
+ :TCP_KEEPALIVE => :int,
74
+ :TCP_KEEPALIVE_IDLE => :int,
75
+ :TCP_KEEPALIVE_CNT => :int,
76
+ :TCP_KEEPALIVE_INTVL => :int,
77
+ :TCP_ACCEPT_FILTER => :string,
78
+ :PLAIN_SERVER => :int,
79
+ :PLAIN_USERNAME => :string,
80
+ :PLAIN_PASSWORD => :string,
81
+ :CURVE_SERVER => :int,
82
+ :CURVE_PUBLICKEY => :string,
83
+ :CURVE_SECRETKEY => :string,
84
+ :CURVE_SERVERKEY => :string,
85
+ :ZAP_DOMAIN => :string,
86
+ :CONFLATE => :bool,
87
+ }
88
+
89
+ # Set up map of option codes to option types
90
+ @@option_types = {}
91
+ @@get_options.each_pair { |n,t| @@option_types[ZMQ.const_get(n)] = t }
92
+ @@set_options.each_pair { |n,t| @@option_types[ZMQ.const_get(n)] = t }
93
+
94
+ public
95
+
96
+ # Define the socket option reader methods
97
+ @@get_options.keys.each do |name|
98
+ code = ZMQ.const_get(name)
99
+ # Get the given socket option
100
+ define_method(name.downcase) { get_opt code }
101
+ end
102
+
103
+ # Define the socket option writer methods
104
+ @@set_options.keys.each do |name|
105
+ code = ZMQ.const_get(name)
106
+ name = :"#{name}=" unless [:SUBSCRIBE, :UNSUBSCRIBE].include? name
107
+ # Set the given socket option
108
+ define_method(name.downcase) { |val| set_opt code, val }
109
+ end
110
+
111
+ end
112
+
113
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: 0mq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe McIlvain
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-26 00:00:00.000000000 Z
12
+ date: 2014-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi-rzmq-core
@@ -120,6 +120,7 @@ files:
120
120
  - lib/0mq/error_map.rb
121
121
  - lib/0mq/proxy.rb
122
122
  - lib/0mq/socket.rb
123
+ - lib/0mq/socket/options.rb
123
124
  homepage: https://github.com/jemc/0mq/
124
125
  licenses:
125
126
  - MIT