omq-backend-libzmq 0.3.2 → 0.3.4

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: 963a9597aa1a5a4cd0b922dd332dcd34cabbf542072f9a985cb03b087df1c2f0
4
- data.tar.gz: b76aa34f22c78f6639407562269f585c542f14cd940d7fa00619e028c646f746
3
+ metadata.gz: fc4a301047eea432b192bdd7b6098006d6eff0e42819551985632504b4f61dfd
4
+ data.tar.gz: baf7e5e1b07071e4c730fff85ed5b25c5afa1d7f2401c8d4804f30f1e5a12e22
5
5
  SHA512:
6
- metadata.gz: 21d10c3acef17a021ef16f641b7283d96e693ff1f816a9ffe99a05007ef2b82fe105e8f70920b636d43001b38a4fc09f05355407865b03d0729ded39da6bd5c9
7
- data.tar.gz: 4cadea7bb6b143111b25c6995cdce2479d0d83bcab5ea463e08b356a7de8009d5eaa05548eab8b145185f2219a9fe1b4be4e75de9fc0843b94f870f8f6a53c3f
6
+ metadata.gz: 3300a3356fc4e6fe7784ab08686f245eebcc03ea3e75e47330107fba66b5ca09212d146cec82330310fe60ad692e36f82db251eb29c1ebfa72851dad1dd9ccf0
7
+ data.tar.gz: 745f84d72421a6b458c52ac2b2cdb79c13f8146c8494951d826a106eac44b0281785870370c62519d4e2a5261e9b4c4188a7aa3830153c7e749fa5f323fcdbc9
data/README.md CHANGED
@@ -22,8 +22,6 @@ socket API, options, and Async integration remain identical. A dedicated
22
22
  I/O thread per socket handles all libzmq operations because libzmq
23
23
  sockets are not thread-safe.
24
24
 
25
- `require "omq/ffi"` and `backend: :ffi` remain supported for compatibility.
26
-
27
25
  ## Interop
28
26
 
29
27
  libzmq and native Ruby backends are wire-compatible. You can mix them
@@ -4,15 +4,16 @@ require "async"
4
4
  require "uri"
5
5
 
6
6
  module OMQ
7
- module FFI
8
- # FFI Engine — wraps a libzmq socket to implement the OMQ Engine contract.
9
- #
10
- # A dedicated I/O thread owns the zmq_socket exclusively (libzmq sockets
11
- # are not thread-safe). Send and recv flow through queues, with an IO pipe
12
- # to wake the Async fiber scheduler.
13
- #
14
- class Engine
15
- L = Libzmq
7
+ module Backend
8
+ module Libzmq
9
+ # Engine — wraps a libzmq socket to implement the OMQ Engine contract.
10
+ #
11
+ # A dedicated I/O thread owns the zmq_socket exclusively (libzmq sockets
12
+ # are not thread-safe). Send and recv flow through queues, with an IO pipe
13
+ # to wake the Async fiber scheduler.
14
+ #
15
+ class Engine
16
+ L = Native
16
17
 
17
18
 
18
19
  # @return [Options] socket options
@@ -34,7 +35,7 @@ module OMQ
34
35
  alias on_io_thread? on_io_thread
35
36
  # @param value [Boolean] enables or disables automatic reconnection
36
37
  attr_writer :reconnect_enabled
37
- # @note Monitor events are not yet emitted by the FFI backend; these
38
+ # @note Monitor events are not yet emitted by the libzmq backend; these
38
39
  # writers exist so Socket#monitor can attach without raising. Wiring
39
40
  # libzmq's zmq_socket_monitor is a TODO.
40
41
  attr_writer :monitor_queue, :verbose_monitor
@@ -117,7 +118,7 @@ module OMQ
117
118
  @on_io_thread = false
118
119
  @fatal_error = nil
119
120
 
120
- @zmq_socket = L.zmq_socket(OMQ::FFI.context, L::SOCKET_TYPES.fetch(@socket_type))
121
+ @zmq_socket = L.zmq_socket(OMQ::Backend::Libzmq.context, L::SOCKET_TYPES.fetch(@socket_type))
121
122
  raise "zmq_socket failed: #{L.zmq_strerror(L.zmq_errno)}" if @zmq_socket.null?
122
123
 
123
124
  apply_options
@@ -150,6 +151,7 @@ module OMQ
150
151
  resolved = get_string_option(L::ZMQ_LAST_ENDPOINT)
151
152
  @connections << :libzmq
152
153
  @peer_connected.resolve(:libzmq) unless @peer_connected.resolved?
154
+ resolve_subscriber_joined_without_monitor
153
155
  URI.parse(resolved)
154
156
  end
155
157
 
@@ -163,6 +165,7 @@ module OMQ
163
165
  send_cmd(:connect, endpoint)
164
166
  @connections << :libzmq
165
167
  @peer_connected.resolve(:libzmq) unless @peer_connected.resolved?
168
+ resolve_subscriber_joined_without_monitor
166
169
  URI.parse(endpoint)
167
170
  end
168
171
 
@@ -247,7 +250,7 @@ module OMQ
247
250
 
248
251
  # Captures the current Async task as the parent for I/O scheduling.
249
252
  # +parent:+ is accepted for API compatibility with the pure-Ruby
250
- # engine but has no effect: the FFI backend runs its own I/O
253
+ # engine but has no effect: the libzmq backend runs its own I/O
251
254
  # thread and doesn't participate in the Async barrier tree.
252
255
  #
253
256
  # @return [void]
@@ -326,6 +329,16 @@ module OMQ
326
329
 
327
330
  private
328
331
 
332
+ def resolve_subscriber_joined_without_monitor
333
+ return unless %i[PUB XPUB].include?(@socket_type)
334
+ return if @routing.subscriber_joined.resolved?
335
+
336
+ # libzmq monitor wiring is still TODO, so this backend cannot
337
+ # detect SUBSCRIBE commands. Resolve on attach so callers that wait
338
+ # for subscriber readiness can use their normal grace period.
339
+ @routing.subscriber_joined.resolve(:libzmq)
340
+ end
341
+
329
342
  # Waits for a message from the I/O thread's recv queue.
330
343
  # Uses the signal pipe so Async can yield the fiber.
331
344
  #
@@ -686,18 +699,19 @@ module OMQ
686
699
  end
687
700
 
688
701
 
689
- end
702
+ end
690
703
 
691
704
 
692
- # Returns the shared ZMQ context (one per process, lazily initialized).
693
- #
694
- # @return [FFI::Pointer] zmq context pointer
695
- def self.context
696
- @context ||= Libzmq.zmq_ctx_new.tap do |ctx|
697
- raise "zmq_ctx_new failed" if ctx.null?
698
- at_exit do
699
- Libzmq.zmq_ctx_shutdown(ctx) rescue nil
700
- Libzmq.zmq_ctx_term(ctx) rescue nil
705
+ # Returns the shared ZMQ context (one per process, lazily initialized).
706
+ #
707
+ # @return [FFI::Pointer] zmq context pointer
708
+ def self.context
709
+ @context ||= Native.zmq_ctx_new.tap do |ctx|
710
+ raise "zmq_ctx_new failed" if ctx.null?
711
+ at_exit do
712
+ Native.zmq_ctx_shutdown(ctx) rescue nil
713
+ Native.zmq_ctx_term(ctx) rescue nil
714
+ end
701
715
  end
702
716
  end
703
717
  end
@@ -3,12 +3,13 @@
3
3
  require "ffi"
4
4
 
5
5
  module OMQ
6
- module FFI
7
- # Minimal libzmq FFI bindings — only what OMQ needs.
8
- #
6
+ module Backend
9
7
  module Libzmq
10
- extend ::FFI::Library
11
- ffi_lib ["libzmq.so.5", "libzmq.5.dylib", "libzmq"]
8
+ # Minimal libzmq FFI bindings — only what OMQ needs.
9
+ #
10
+ module Native
11
+ extend ::FFI::Library
12
+ ffi_lib ["libzmq.so.5", "libzmq.5.dylib", "libzmq"]
12
13
 
13
14
  # Context
14
15
  attach_function :zmq_ctx_new, [], :pointer
@@ -129,6 +130,7 @@ module OMQ
129
130
  errno = zmq_errno
130
131
  raise "#{label}: #{zmq_strerror(errno)} (errno #{errno})"
131
132
  end
133
+ end
132
134
  end
133
135
  end
134
136
  end
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "omq"
4
- require_relative "../ffi/libzmq"
5
- require_relative "../ffi/engine"
4
+ require_relative "libzmq/native"
5
+ require_relative "libzmq/engine"
6
6
 
7
- OMQ::Backend.register(:libzmq, OMQ::FFI::Engine)
8
- OMQ::Backend.register(:ffi, OMQ::FFI::Engine)
7
+ OMQ::Backend.register(:libzmq, OMQ::Backend::Libzmq::Engine)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omq-backend-libzmq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrik Wenger
@@ -46,9 +46,8 @@ files:
46
46
  - LICENSE
47
47
  - README.md
48
48
  - lib/omq/backend/libzmq.rb
49
- - lib/omq/ffi.rb
50
- - lib/omq/ffi/engine.rb
51
- - lib/omq/ffi/libzmq.rb
49
+ - lib/omq/backend/libzmq/engine.rb
50
+ - lib/omq/backend/libzmq/native.rb
52
51
  homepage: https://github.com/zeromq/omq.rb/tree/main/gems/omq-backend-libzmq
53
52
  licenses:
54
53
  - ISC
@@ -69,5 +68,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
68
  requirements: []
70
69
  rubygems_version: 4.0.16
71
70
  specification_version: 4
72
- summary: libzmq backend for OMQ using FFI
71
+ summary: libzmq backend for OMQ
73
72
  test_files: []
data/lib/omq/ffi.rb DELETED
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Compatibility load path for the libzmq backend.
4
- #
5
- # Usage:
6
- # require "omq/ffi"
7
- # push = OMQ::PUSH.new(backend: :ffi)
8
- #
9
- # Raises LoadError if libzmq is not installed.
10
-
11
- require_relative "backend/libzmq"