cztop 1.1.0.pre1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 149778ca201f323611fe23b4b1107c4cb4bde8ea7364bbe7370cea39daf5ab02
4
- data.tar.gz: 195be179654f5b1c286f4859a012a093bed587f644306ee63642a7e300b261f6
3
+ metadata.gz: a73261e3bc3a15f8302b4e7eca58eb25393cfe301d9b755a7291bf35ef126674
4
+ data.tar.gz: 5d1f75990a28eba2460cfd61e5825492bcd66604bd7990dbcdf4a74db00c0e7e
5
5
  SHA512:
6
- metadata.gz: c2a65ca5f02e39cfc9ca2695fefd6b02c0e898878041a662d0af1361235fa1ec091c4024d0a9d68b793173f191ce81350e21cc98b0a2320d3d6c9d9617f35d50
7
- data.tar.gz: bae808f502e3f8b3ced7872d76a6377578bd37d332bf12ba96aaa126ea7571abbbfe363426c9578c30ecd6abbc126198e470d3d378de0bd0b1960384ab9d17b7
6
+ metadata.gz: 9ebe5b00e21a32e0b645f50a789a8818dddf31d4ed69a74c247b30b443e02cd4cdd05121f3cd2bc286c41e21e09bc6feb0b304fc245d9be6dbaf648e287c0bb8
7
+ data.tar.gz: cd3c05936f8ce4c0c8c6b8f3774d70bfaf1a7b85d9770e159fb0aed4ae0628f97e74bbaa76742b7518a06d257dd6c22504dc2285a827fcc36b5bb5f59bf51ac8
@@ -4,14 +4,14 @@ on: [push,pull_request]
4
4
 
5
5
  jobs:
6
6
  build:
7
- runs-on: ubuntu-20.04
7
+ runs-on: ubuntu-22.04
8
8
  timeout-minutes: 15
9
9
  steps:
10
10
  - uses: actions/checkout@v2
11
11
  - name: Set up Ruby
12
12
  uses: ruby/setup-ruby@v1
13
13
  with:
14
- ruby-version: 3.1
14
+ ruby-version: 3.3
15
15
  - name: Install ZMQ and CZMQ
16
16
  run: |
17
17
  export PKG_CONFIG_PATH=$HOME/lib/pkgconfig # custom libs (for linking)
@@ -4,13 +4,14 @@ on: [push,pull_request]
4
4
 
5
5
  jobs:
6
6
  build:
7
- runs-on: ubuntu-20.04
7
+ runs-on: ubuntu-22.04
8
8
  strategy:
9
9
  matrix:
10
10
  ruby:
11
- - 2.7
12
11
  - 3.0
13
12
  - 3.1
13
+ - 3.2
14
+ - 3.3
14
15
  steps:
15
16
  - uses: actions/checkout@v2
16
17
  - name: Set up Ruby ${{ matrix.ruby }}
data/README.md CHANGED
@@ -18,7 +18,7 @@ Here's an overview of the core classes:
18
18
 
19
19
  * [CZTop](http://www.rubydoc.info/gems/cztop/CZTop)
20
20
  * [Actor](http://www.rubydoc.info/gems/cztop/CZTop)
21
- * [Authentiator](http://www.rubydoc.info/gems/cztop/CZTop/Authenticator)
21
+ * [Authenticator](http://www.rubydoc.info/gems/cztop/CZTop/Authenticator)
22
22
  * [Beacon](http://www.rubydoc.info/gems/cztop/CZTop/Beacon)
23
23
  * [Certificate](http://www.rubydoc.info/gems/cztop/CZTop/Certificate)
24
24
  * [CertStore](http://www.rubydoc.info/gems/cztop/CZTop/CertStore)
@@ -59,6 +59,7 @@ More information in the [API documentation](http://www.rubydoc.info/github/paddo
59
59
 
60
60
  ### Features
61
61
 
62
+ * compatible with [Async](https://github.com/socketry/async) / [Async::IO](https://github.com/socketry/async-io)
62
63
  * Ruby-like API
63
64
  * method names
64
65
  * sending a message via a socket is done with `Socket#<<`
@@ -94,7 +95,7 @@ On macOS using Homebrew, run:
94
95
 
95
96
  ### Supported Rubies
96
97
 
97
- * MRI (2.6, 2.7, 3.0)
98
+ * MRI (3.0, 3.2, 3.3)
98
99
  * Rubinius (HEAD)
99
100
  * JRuby 9000 (HEAD)
100
101
 
data/cztop.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = %q{CZMQ Ruby binding based on the generated low-level FFI bindings of CZMQ}
12
12
  spec.homepage = "https://rubygems.org/gems/cztop"
13
13
  spec.license = "ISC"
14
- spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
17
  spec.metadata["source_code_uri"] = "https://github.com/paddor/cztop"
@@ -32,4 +32,6 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "pry"
33
33
  spec.add_development_dependency "yard"
34
34
  spec.add_development_dependency "rubocop", "~> 1.36.0"
35
+ spec.add_development_dependency "async", ">= 2.0.1"
36
+ spec.add_development_dependency "async-io"
35
37
  end
@@ -0,0 +1 @@
1
+ /Gemfile.lock
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'async'
4
+ gem 'cztop', path: '../../'
5
+ gem 'async-io'
@@ -0,0 +1 @@
1
+ Run: `bundle exec ./async.rb`
@@ -0,0 +1,40 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'cztop/async'
4
+
5
+ Async do |task|
6
+ task.async do |t|
7
+ socket = CZTop::Socket::REP.new("ipc:///tmp/req_rep_example")
8
+
9
+ # Simply echo every message, with every frame String#upcase'd.
10
+ socket.options.rcvtimeo = 3
11
+ io = Async::IO.try_convert socket
12
+
13
+ msg = io.receive
14
+ puts "<<< #{msg.to_a.inspect}"
15
+ io << msg.to_a.map(&:upcase)
16
+
17
+ puts "REP done."
18
+ end
19
+
20
+ task.async do
21
+ socket = CZTop::Socket::REQ.new("ipc:///tmp/req_rep_example")
22
+ puts ">>> Socket connected."
23
+
24
+ io = Async::IO.try_convert socket
25
+ # sleep 5
26
+ io << "foobar"
27
+
28
+ socket.options.rcvtimeo = 3
29
+ msg = io.receive
30
+ puts ">>> #{msg.to_a.inspect}"
31
+ puts "REQ done."
32
+ end
33
+
34
+ task.async do
35
+ 6.times do
36
+ sleep 0.5
37
+ puts "tick"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cztop'
4
+ require 'async/io'
5
+
6
+ module Async
7
+ module IO
8
+
9
+ # Wrapper for CZTop sockets.
10
+ #
11
+ # @example
12
+ # Async do |task|
13
+ # socket = CZTop::Socket::REP.new("ipc:///tmp/req_rep_example")
14
+ # socket.options.rcvtimeo = 3
15
+ # io = Async::IO.try_convert socket
16
+ # msg = io.receive
17
+ # io << msg.to_a.map(&:upcase)
18
+ # end
19
+
20
+ class CZTopSocket < Generic
21
+ wraps ::CZTop::Socket::REQ
22
+ wraps ::CZTop::Socket::REP
23
+ wraps ::CZTop::Socket::PAIR
24
+ wraps ::CZTop::Socket::ROUTER
25
+ wraps ::CZTop::Socket::DEALER
26
+ wraps ::CZTop::Socket::PUSH
27
+ wraps ::CZTop::Socket::PULL
28
+ wraps ::CZTop::Socket::PUB
29
+ wraps ::CZTop::Socket::SUB
30
+ wraps ::CZTop::Socket::XPUB
31
+ wraps ::CZTop::Socket::XSUB
32
+
33
+
34
+ # @see {CZTop::SendReceiveMethods#receive}
35
+ def receive
36
+ wait_readable
37
+ @io.receive
38
+ end
39
+
40
+
41
+ # @see {CZTop::SendReceiveMethods#<<}
42
+ def <<(...)
43
+ wait_writable
44
+ @io.<<(...)
45
+ end
46
+
47
+
48
+ # Waits for socket to become readable.
49
+ def wait_readable(timeout = read_timeout)
50
+ @io_fd ||= ::IO.for_fd @io.fd, autoclose: false
51
+
52
+ if timeout
53
+ timeout_at = now + timeout
54
+
55
+ while true
56
+ @io_fd.wait_readable(timeout)
57
+ break if @io.readable?
58
+ raise ::IO::TimeoutError if now >= timeout_at
59
+ end
60
+ else
61
+ @io_fd.wait_readable until @io.readable?
62
+ end
63
+ end
64
+
65
+
66
+ # Waits for socket to become writable.
67
+ def wait_writable(timeout = write_timeout)
68
+ @io_fd ||= ::IO.for_fd @io.fd, autoclose: false
69
+
70
+ if timeout
71
+ timeout_at = now + timeout
72
+
73
+ while true
74
+ @io_fd.wait_writable(timeout)
75
+ break if @io.writable?
76
+ raise ::IO::TimeoutError if now >= timeout_at
77
+ end
78
+ else
79
+ @io_fd.wait_writable until @io.writable?
80
+ end
81
+ end
82
+
83
+
84
+ # @return [Float, nil] the timeout in seconds used by {IO#wait_readable}
85
+ def read_timeout
86
+ timeout = @io.options.rcvtimeo
87
+
88
+ if timeout <= 0
89
+ timeout = nil
90
+ else
91
+ timeout = timeout.to_f / 1000
92
+ end
93
+
94
+ timeout
95
+ end
96
+
97
+
98
+ # @return [Float, nil] the timeout in seconds used by {IO#wait_writable}
99
+ def write_timeout
100
+ timeout = @io.options.sndtimeo
101
+
102
+ if timeout <= 0
103
+ timeout = nil
104
+ else
105
+ timeout = timeout.to_f / 1000
106
+ end
107
+
108
+ timeout
109
+ end
110
+
111
+
112
+ private
113
+
114
+
115
+ def now
116
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
117
+ end
118
+ end
119
+ end
120
+ end
@@ -7,20 +7,24 @@ module CZTop
7
7
  # for the zsock_new() function.
8
8
  module Types
9
9
 
10
- PAIR = 0
11
- PUB = 1
12
- SUB = 2
13
- REQ = 3
14
- REP = 4
15
- DEALER = 5
16
- ROUTER = 6
17
- PULL = 7
18
- PUSH = 8
19
- XPUB = 9
20
- XSUB = 10
21
- STREAM = 11
22
- SERVER = 12
23
- CLIENT = 13
10
+ PAIR = 0
11
+ PUB = 1
12
+ SUB = 2
13
+ REQ = 3
14
+ REP = 4
15
+ DEALER = 5
16
+ ROUTER = 6
17
+ PULL = 7
18
+ PUSH = 8
19
+ XPUB = 9
20
+ XSUB = 10
21
+ STREAM = 11
22
+ SERVER = 12
23
+ CLIENT = 13
24
+ RADIO = 14
25
+ DISH = 15
26
+ GATHER = 16
27
+ SCATTER = 17
24
28
 
25
29
  end
26
30
 
data/lib/cztop/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module CZTop
4
4
 
5
- VERSION = '1.1.0.pre1'
5
+ VERSION = '1.1.0'
6
6
 
7
7
  end
@@ -264,29 +264,33 @@ module CZTop
264
264
 
265
265
  # @!group Send and Receive Timeouts
266
266
 
267
- # @return [Integer] the timeout when receiving a message
267
+ # @return [Integer] the timeout in milliseconds when receiving a message
268
268
  # @see Message.receive_from
269
+ # @note -1 means infinite, 0 means nonblocking
269
270
  def rcvtimeo
270
271
  Zsock.rcvtimeo(@zocket)
271
272
  end
272
273
 
273
274
 
274
- # @param timeout [Integer] new timeout
275
+ # @param timeout [Integer] new timeout in milliseconds
275
276
  # @see Message.receive_from
277
+ # @note -1 means infinite, 0 means nonblocking
276
278
  def rcvtimeo=(timeout)
277
279
  Zsock.set_rcvtimeo(@zocket, timeout)
278
280
  end
279
281
 
280
282
 
281
- # @return [Integer] the timeout when sending a message
283
+ # @return [Integer] the timeout in milliseconds when sending a message
282
284
  # @see Message#send_to
285
+ # @note -1 means infinite, 0 means nonblocking
283
286
  def sndtimeo
284
287
  Zsock.sndtimeo(@zocket)
285
288
  end
286
289
 
287
290
 
288
- # @param timeout [Integer] new timeout
291
+ # @param timeout [Integer] new timeout in milliseconds
289
292
  # @see Message#send_to
293
+ # @note -1 means infinite, 0 means nonblocking
290
294
  def sndtimeo=(timeout)
291
295
  Zsock.set_sndtimeo(@zocket, timeout)
292
296
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cztop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.pre1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrik Wenger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-18 00:00:00.000000000 Z
11
+ date: 2024-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: czmq-ffi-gen
@@ -136,6 +136,34 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: 1.36.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: async
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 2.0.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 2.0.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: async-io
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
139
167
  description:
140
168
  email:
141
169
  - paddor@gmail.com
@@ -163,6 +191,10 @@ files:
163
191
  - ci/install-libczmq
164
192
  - ci/install-libzmq
165
193
  - cztop.gemspec
194
+ - examples/async/.gitignore
195
+ - examples/async/Gemfile
196
+ - examples/async/README.md
197
+ - examples/async/async.rb
166
198
  - examples/ruby_actor/actor.rb
167
199
  - examples/simple_req_rep/rep.rb
168
200
  - examples/simple_req_rep/req.rb
@@ -181,6 +213,7 @@ files:
181
213
  - exe/z85encode
182
214
  - lib/cztop.rb
183
215
  - lib/cztop/actor.rb
216
+ - lib/cztop/async.rb
184
217
  - lib/cztop/authenticator.rb
185
218
  - lib/cztop/beacon.rb
186
219
  - lib/cztop/cert_store.rb
@@ -230,14 +263,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
263
  requirements:
231
264
  - - ">="
232
265
  - !ruby/object:Gem::Version
233
- version: 2.7.0
266
+ version: 3.0.0
234
267
  required_rubygems_version: !ruby/object:Gem::Requirement
235
268
  requirements:
236
- - - ">"
269
+ - - ">="
237
270
  - !ruby/object:Gem::Version
238
- version: 1.3.1
271
+ version: '0'
239
272
  requirements: []
240
- rubygems_version: 3.2.33
273
+ rubygems_version: 3.5.3
241
274
  signing_key:
242
275
  specification_version: 4
243
276
  summary: CZMQ Ruby binding based on the generated low-level FFI bindings of CZMQ