cztop 2.0.0.rc1 → 2.0.0.rc2

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
  SHA256:
3
- metadata.gz: de1d34e78550eaaaa2397a9bc1d1a29a57e36ef00d573a30e68b3903f8e1e43c
4
- data.tar.gz: a9e4522e743b7dae26358acdcfb003fe12a15d5357654b6e32909c7e7ad5bf34
3
+ metadata.gz: 3381b5cf1edd7c878bb5c26ccc16bf096a354cfab0724a8da61e7f4ce3146272
4
+ data.tar.gz: c6081e0b22ee66190b3d34eb9d4d6a2d5ecfda537e8cdbfc223cfd23d2b56e9f
5
5
  SHA512:
6
- metadata.gz: b81a176e6020b002abd3425bc66781e5eb7fdf3d907649139ffacfc7e7b1b12a17498e769dbb90fb13c29bbfe8d5d44ef8d73fa4446bb80613f9aaf159ca0eff
7
- data.tar.gz: ebd44ce64395ddf965682392f7c719bc94fc4ae4277da5340c35b7cd2f9bf8c0206cb92f29fb2350ba6804de244b1c1d3df37d2359c4f391210bfb0e3626688f
6
+ metadata.gz: 8142a5ff3b45d88a3ebfc35b3a002dfb8b9be5937f0c37e1779530229d959b0457a1dfd49c062550b2c46d9389e5c3937272e979e5b703d09f68ed4732925201
7
+ data.tar.gz: 8591012e556649e6397c16a871f8f892a8b111ec06339e3271d03fd5eca187268363258429a949eb1d03c8245907cfbf30ae00662d9168f47e28aea14592094f
data/CHANGES.md CHANGED
@@ -1,3 +1,14 @@
1
+ 2.0.0.rc2
2
+ -----
3
+
4
+ ### Breaking changes
5
+
6
+ * **Removed `Socket.new_by_type` factory method** — use type-specific constructors
7
+ instead (e.g. `Socket::REQ.new`, `Socket::PUB.new`)
8
+ * **`linger` now defaults to 0** on all socket constructors — ZMQ's default of
9
+ infinite (-1) caused `#close` to block when unsent messages remained. Pass
10
+ `linger:` to override (e.g. `Socket::REQ.new(endpoint, linger: 1)`)
11
+
1
12
  2.0.0.rc1
2
13
  -----
3
14
 
data/README.md CHANGED
@@ -37,6 +37,10 @@ gem install cztop
37
37
  gem 'cztop'
38
38
  ```
39
39
 
40
+ ## Learning ZeroMQ
41
+
42
+ New to ZeroMQ? See [ZGUIDE_SUMMARY.md](ZGUIDE_SUMMARY.md) — a ~30 min read covering all major patterns with working CZTop code examples.
43
+
40
44
  ## Quick Start
41
45
 
42
46
  ### Request / Reply
data/ZGUIDE_SUMMARY.md CHANGED
@@ -538,12 +538,10 @@ connecting (identity, HWM). Timeouts and linger can change at any time.
538
538
  sock = Cztop::Socket::REQ.new
539
539
  sock.send_timeout = 1 # 1 second
540
540
  sock.recv_timeout = 1 # 1 second
541
- sock.linger = 0 # drop unsent on close
542
541
  sock.identity = 'worker-1' # ROUTER-visible identity
543
542
 
544
543
  # nil = no timeout / wait indefinitely:
545
544
  sock.send_timeout = nil
546
- sock.linger = nil
547
545
  ```
548
546
 
549
547
  Key options:
@@ -591,7 +589,7 @@ with it directly. Key rules:
591
589
 
592
590
  - Sockets are **not thread-safe** — one socket per thread
593
591
  - One I/O thread handles ~1 Gbps — usually enough
594
- - Set `linger = 0` for instant shutdown
592
+ - `linger` defaults to `0` instant shutdown, no blocking on close
595
593
 
596
594
  ---
597
595
 
@@ -667,7 +665,6 @@ def lazy_pirate_request(endpoint, request)
667
665
  MAX_RETRIES.times do |attempt|
668
666
  req = Cztop::Socket::REQ.connect(endpoint)
669
667
  req.recv_timeout = 2.5
670
- req.linger = 0
671
668
 
672
669
  req << request
673
670
  begin
@@ -988,11 +985,11 @@ it and create a new one (Lazy Pirate).
988
985
  Not thread-safe. Silent data corruption, hangs, or segfaults. One
989
986
  socket per thread. Use `inproc://` between threads.
990
987
 
991
- ### 3. Forgetting linger
988
+ ### 3. Overriding linger without resetting it
992
989
 
993
- CZTop defaults to `linger = 0`. If you changed it, `#close` blocks
994
- until queued messages are delivered. Always `socket.linger = 0` for
995
- sockets you want to close fast.
990
+ CZTop defaults to `linger = 0` (drop unsent messages on close). If you
991
+ set `linger = nil` (wait forever), remember to reset it before closing
992
+ or `#close` will block until all queued messages are delivered.
996
993
 
997
994
  ### 4. Not setting timeouts
998
995
 
@@ -1065,7 +1062,8 @@ Peer-to-peer ROUTER ──▶ ROUTER (hard mode)
1065
1062
  until it isn't.
1066
1063
  2. **Don't share sockets across threads.** One socket per thread,
1067
1064
  `inproc://` between them.
1068
- 3. **Always set `linger`**`sock.linger = 0` for clean shutdown.
1065
+ 3. **`linger` defaults to 0** sockets close instantly. Override with
1066
+ `linger:` kwarg or `sock.linger =` only when you need delivery guarantees.
1069
1067
  4. **PUB/SUB filtering is prefix-based.** `""` = everything.
1070
1068
  5. **Connect from the ephemeral side.** Stable address binds.
1071
1069
  6. **Heartbeat everything** in production.
data/cztop.gemspec CHANGED
@@ -19,8 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.metadata["changelog_uri"] = "https://github.com/paddor/cztop/blob/master/CHANGES.md"
20
20
 
21
21
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match?(%r{^(\.|Rakefile|test/|examples/|bench/)}) }
22
- spec.bindir = "exe"
23
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
22
  spec.require_paths = ["lib"]
25
23
 
26
24
  spec.add_runtime_dependency "ffi"
@@ -13,11 +13,13 @@ module CZTop
13
13
 
14
14
  # @param endpoints [String] endpoints to connect to
15
15
  # @param curve [Hash, nil] CURVE encryption options
16
+ # @param linger [Integer] linger period in milliseconds (default: 0)
16
17
  #
17
- def initialize(endpoints = nil, curve: nil)
18
+ def initialize(endpoints = nil, curve: nil, linger: 0)
18
19
  super
19
20
 
20
21
  attach_ffi_delegate(Zsock.new(Types::DEALER))
22
+ self.linger = linger
21
23
  _apply_curve(curve)
22
24
  _attach(endpoints, default: :connect)
23
25
  end
@@ -13,11 +13,13 @@ module CZTop
13
13
 
14
14
  # @param endpoints [String] endpoints to connect to
15
15
  # @param curve [Hash, nil] CURVE encryption options
16
+ # @param linger [Integer] linger period in milliseconds (default: 0)
16
17
  #
17
- def initialize(endpoints = nil, curve: nil)
18
+ def initialize(endpoints = nil, curve: nil, linger: 0)
18
19
  super
19
20
 
20
21
  attach_ffi_delegate(Zsock.new(Types::PAIR))
22
+ self.linger = linger
21
23
  _apply_curve(curve)
22
24
  _attach(endpoints, default: :connect)
23
25
  end
@@ -12,11 +12,13 @@ module CZTop
12
12
 
13
13
  # @param endpoints [String] endpoints to bind to
14
14
  # @param curve [Hash, nil] CURVE encryption options
15
+ # @param linger [Integer] linger period in milliseconds (default: 0)
15
16
  #
16
- def initialize(endpoints = nil, curve: nil)
17
+ def initialize(endpoints = nil, curve: nil, linger: 0)
17
18
  super
18
19
 
19
20
  attach_ffi_delegate(Zsock.new(Types::PUB))
21
+ self.linger = linger
20
22
  _apply_curve(curve)
21
23
  _attach(endpoints, default: :bind)
22
24
  end
@@ -12,11 +12,13 @@ module CZTop
12
12
 
13
13
  # @param endpoints [String] endpoints to bind to
14
14
  # @param curve [Hash, nil] CURVE encryption options
15
+ # @param linger [Integer] linger period in milliseconds (default: 0)
15
16
  #
16
- def initialize(endpoints = nil, curve: nil)
17
+ def initialize(endpoints = nil, curve: nil, linger: 0)
17
18
  super
18
19
 
19
20
  attach_ffi_delegate(Zsock.new(Types::PULL))
21
+ self.linger = linger
20
22
  _apply_curve(curve)
21
23
  _attach(endpoints, default: :bind)
22
24
  end
@@ -12,11 +12,13 @@ module CZTop
12
12
 
13
13
  # @param endpoints [String] endpoints to connect to
14
14
  # @param curve [Hash, nil] CURVE encryption options
15
+ # @param linger [Integer] linger period in milliseconds (default: 0)
15
16
  #
16
- def initialize(endpoints = nil, curve: nil)
17
+ def initialize(endpoints = nil, curve: nil, linger: 0)
17
18
  super
18
19
 
19
20
  attach_ffi_delegate(Zsock.new(Types::PUSH))
21
+ self.linger = linger
20
22
  _apply_curve(curve)
21
23
  _attach(endpoints, default: :connect)
22
24
  end
@@ -13,11 +13,13 @@ module CZTop
13
13
 
14
14
  # @param endpoints [String] endpoints to bind to
15
15
  # @param curve [Hash, nil] CURVE encryption options
16
+ # @param linger [Integer] linger period in milliseconds (default: 0)
16
17
  #
17
- def initialize(endpoints = nil, curve: nil)
18
+ def initialize(endpoints = nil, curve: nil, linger: 0)
18
19
  super
19
20
 
20
21
  attach_ffi_delegate(Zsock.new(Types::REP))
22
+ self.linger = linger
21
23
  _apply_curve(curve)
22
24
  _attach(endpoints, default: :bind)
23
25
  end
@@ -13,11 +13,13 @@ module CZTop
13
13
 
14
14
  # @param endpoints [String] endpoints to connect to
15
15
  # @param curve [Hash, nil] CURVE encryption options
16
+ # @param linger [Integer] linger period in milliseconds (default: 0)
16
17
  #
17
- def initialize(endpoints = nil, curve: nil)
18
+ def initialize(endpoints = nil, curve: nil, linger: 0)
18
19
  super
19
20
 
20
21
  attach_ffi_delegate(Zsock.new(Types::REQ))
22
+ self.linger = linger
21
23
  _apply_curve(curve)
22
24
  _attach(endpoints, default: :connect)
23
25
  end
@@ -13,11 +13,13 @@ module CZTop
13
13
 
14
14
  # @param endpoints [String] endpoints to bind to
15
15
  # @param curve [Hash, nil] CURVE encryption options
16
+ # @param linger [Integer] linger period in milliseconds (default: 0)
16
17
  #
17
- def initialize(endpoints = nil, curve: nil)
18
+ def initialize(endpoints = nil, curve: nil, linger: 0)
18
19
  super
19
20
 
20
21
  attach_ffi_delegate(Zsock.new(Types::ROUTER))
22
+ self.linger = linger
21
23
  _apply_curve(curve)
22
24
  _attach(endpoints, default: :bind)
23
25
  end
@@ -14,11 +14,13 @@ module CZTop
14
14
 
15
15
  # @param endpoints [String] endpoints to connect to
16
16
  # @param curve [Hash, nil] CURVE encryption options
17
+ # @param linger [Integer] linger period in milliseconds (default: 0)
17
18
  #
18
- def initialize(endpoints = nil, curve: nil)
19
+ def initialize(endpoints = nil, curve: nil, linger: 0)
19
20
  super
20
21
 
21
22
  attach_ffi_delegate(Zsock.new(Types::STREAM))
23
+ self.linger = linger
22
24
  _apply_curve(curve)
23
25
  _attach(endpoints, default: :connect)
24
26
  end
@@ -17,11 +17,13 @@ module CZTop
17
17
  # @param prefix [String, nil] subscription prefix; defaults to
18
18
  # everything ({EVERYTHING}). Pass +nil+ to skip subscribing.
19
19
  # @param curve [Hash, nil] CURVE encryption options
20
+ # @param linger [Integer] linger period in milliseconds (default: 0)
20
21
  #
21
- def initialize(endpoints = nil, prefix: EVERYTHING, curve: nil)
22
- super(endpoints, curve: curve)
22
+ def initialize(endpoints = nil, prefix: EVERYTHING, curve: nil, linger: 0)
23
+ super(endpoints, curve: curve, linger: linger)
23
24
 
24
25
  attach_ffi_delegate(Zsock.new(Types::SUB))
26
+ self.linger = linger
25
27
  _apply_curve(curve)
26
28
  subscribe(prefix) unless prefix.nil?
27
29
  _attach(endpoints, default: :connect)
@@ -13,11 +13,13 @@ module CZTop
13
13
 
14
14
  # @param endpoints [String] endpoints to bind to
15
15
  # @param curve [Hash, nil] CURVE encryption options
16
+ # @param linger [Integer] linger period in milliseconds (default: 0)
16
17
  #
17
- def initialize(endpoints = nil, curve: nil)
18
+ def initialize(endpoints = nil, curve: nil, linger: 0)
18
19
  super
19
20
 
20
21
  attach_ffi_delegate(Zsock.new(Types::XPUB))
22
+ self.linger = linger
21
23
  _apply_curve(curve)
22
24
  _attach(endpoints, default: :bind)
23
25
  end
@@ -13,11 +13,13 @@ module CZTop
13
13
 
14
14
  # @param endpoints [String] endpoints to connect to
15
15
  # @param curve [Hash, nil] CURVE encryption options
16
+ # @param linger [Integer] linger period in milliseconds (default: 0)
16
17
  #
17
- def initialize(endpoints = nil, curve: nil)
18
+ def initialize(endpoints = nil, curve: nil, linger: 0)
18
19
  super
19
20
 
20
21
  attach_ffi_delegate(Zsock.new(Types::XSUB))
22
+ self.linger = linger
21
23
  _apply_curve(curve)
22
24
  _attach(endpoints, default: :connect)
23
25
  end
data/lib/cztop/socket.rb CHANGED
@@ -33,33 +33,7 @@ module CZTop
33
33
  end
34
34
 
35
35
 
36
- # @param type [Symbol, Integer] type from {Types} or like +:PUB+
37
- # @return [REQ, REP, PUSH, PULL, ... ] the new socket
38
- # @see Types
39
- # @example Creating a socket by providing its type as a parameter
40
- # my_sock = CZTop::Socket.new_by_type(:DEALER, "tcp://example.com:4000")
41
- #
42
- def self.new_by_type(type)
43
- case type
44
- when Integer
45
- type_code = type
46
- type_name = TypeNames[type_code] or
47
- raise ArgumentError, format('invalid type %p', type)
48
- type_class = Socket.const_get(type_name)
49
- when Symbol
50
- type_code = Types.const_get(type)
51
- type_class = Socket.const_get(type)
52
- else
53
- raise ArgumentError, format('invalid socket type: %p', type)
54
- end
55
- ffi_delegate = Zsock.new(type_code)
56
- sock = type_class.allocate
57
- sock.attach_ffi_delegate(ffi_delegate)
58
- sock
59
- end
60
-
61
-
62
- def initialize(endpoints = nil, curve: nil); end
36
+ def initialize(endpoints = nil, curve: nil, linger: 0); end
63
37
 
64
38
 
65
39
  # @return [String] last bound endpoint, if any
data/lib/cztop/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module CZTop
4
4
 
5
- VERSION = '2.0.0.rc1'
5
+ VERSION = '2.0.0.rc2'
6
6
 
7
7
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cztop
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc1
4
+ version: 2.0.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrik Wenger
8
- bindir: exe
8
+ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
@@ -139,9 +139,7 @@ description: CZMQ binding with hardcoded FFI bindings, providing a Ruby-like API
139
139
  ZMQ sockets
140
140
  email:
141
141
  - paddor@gmail.com
142
- executables:
143
- - z85decode
144
- - z85encode
142
+ executables: []
145
143
  extensions: []
146
144
  extra_rdoc_files: []
147
145
  files:
@@ -153,11 +151,7 @@ files:
153
151
  - LICENSE
154
152
  - README.md
155
153
  - ZGUIDE_SUMMARY.md
156
- - bin/console
157
- - bin/setup
158
154
  - cztop.gemspec
159
- - exe/z85decode
160
- - exe/z85encode
161
155
  - lib/cztop.rb
162
156
  - lib/cztop/curve.rb
163
157
  - lib/cztop/curve/auth.rb
data/bin/console DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "cztop"
5
-
6
- require "pry"
7
- Pry.start
data/bin/setup DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here
data/exe/z85decode DELETED
@@ -1,31 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'cztop'
3
- require 'optparse'
4
- require 'benchmark'
5
-
6
- options = { strategy: CZTop::Z85::Pipe::Strategy::Sequential }
7
- OptionParser.new do |opts|
8
- opts.banner = "Usage: #$0 [options]"
9
-
10
- opts.on("-p", "--parallel", "read, decode, and write in parallel " +
11
- "using 3 threads") do
12
- options[:strategy] = CZTop::Z85::Pipe::Strategy::Parallel
13
- end
14
- opts.on("-v", "--verbose", "print some statistics afterwards") do
15
- options[:verbose] = true
16
- end
17
- end.parse!
18
-
19
- pipe = CZTop::Z85::Pipe.new(STDIN, STDOUT, strategy: options[:strategy])
20
- bytes_decoded = nil
21
- tms = Benchmark.measure { bytes_decoded = pipe.decode }
22
- exit unless options[:verbose]
23
-
24
- if tms.real < 0.1
25
- warn "#{$0}: decoding took %.2f us." % (tms.real * 1_000_000)
26
- else
27
- warn "#{$0}: decoding took %.3f seconds." % tms.real
28
- end
29
-
30
- throughput = (bytes_decoded * 8 / tms.real) / 1_000_000
31
- warn "#{$0}: mean throughput: %.3f [Mb/s]" % throughput
data/exe/z85encode DELETED
@@ -1,31 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'cztop'
3
- require 'optparse'
4
- require 'benchmark'
5
-
6
- options = { strategy: CZTop::Z85::Pipe::Strategy::Sequential }
7
- OptionParser.new do |opts|
8
- opts.banner = "Usage: #$0 [options]"
9
-
10
- opts.on("-p", "--parallel", "read, encode, and write in parallel " +
11
- "using 3 threads") do
12
- options[:strategy] = CZTop::Z85::Pipe::Strategy::Parallel
13
- end
14
- opts.on("-v", "--verbose", "print some statistics afterwards") do
15
- options[:verbose] = true
16
- end
17
- end.parse!
18
-
19
- pipe = CZTop::Z85::Pipe.new(STDIN, STDOUT, strategy: options[:strategy])
20
- bytes_encoded = nil
21
- tms = Benchmark.measure { bytes_encoded = pipe.encode }
22
- exit unless options[:verbose]
23
-
24
- if tms.real < 0.1
25
- warn "#{$0}: encoding took %.2f us." % (tms.real * 1_000_000)
26
- else
27
- warn "#{$0}: encoding took %.3f seconds." % tms.real
28
- end
29
-
30
- throughput = (bytes_encoded * 8 / tms.real) / 1_000_000
31
- warn "#{$0}: mean throughput: %.3f [Mb/s]" % throughput