omq 0.27.0 → 0.28.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.
@@ -1,134 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "ffi"
4
-
5
- module OMQ
6
- module FFI
7
- # Minimal libzmq FFI bindings — only what OMQ needs.
8
- #
9
- module Libzmq
10
- extend ::FFI::Library
11
- ffi_lib ["libzmq.so.5", "libzmq.5.dylib", "libzmq"]
12
-
13
- # Context
14
- attach_function :zmq_ctx_new, [], :pointer
15
- attach_function :zmq_ctx_term, [:pointer], :int
16
- attach_function :zmq_ctx_shutdown, [:pointer], :int
17
-
18
- # Socket
19
- attach_function :zmq_socket, [:pointer, :int], :pointer
20
- attach_function :zmq_close, [:pointer], :int
21
- attach_function :zmq_bind, [:pointer, :string], :int
22
- attach_function :zmq_connect, [:pointer, :string], :int
23
- attach_function :zmq_disconnect, [:pointer, :string], :int
24
- attach_function :zmq_unbind, [:pointer, :string], :int
25
-
26
- # Message
27
- attach_function :zmq_msg_init, [:pointer], :int
28
- attach_function :zmq_msg_init_size, [:pointer, :size_t], :int
29
- attach_function :zmq_msg_data, [:pointer], :pointer
30
- attach_function :zmq_msg_size, [:pointer], :size_t
31
- attach_function :zmq_msg_close, [:pointer], :int
32
- attach_function :zmq_msg_send, [:pointer, :pointer, :int], :int
33
- attach_function :zmq_msg_recv, [:pointer, :pointer, :int], :int
34
-
35
- # Socket options
36
- attach_function :zmq_setsockopt, [:pointer, :int, :pointer, :size_t], :int
37
- attach_function :zmq_getsockopt, [:pointer, :int, :pointer, :pointer], :int
38
-
39
- # Group membership (RADIO/DISH) — draft API, may not be available
40
- begin
41
- attach_function :zmq_join, [:pointer, :string], :int
42
- attach_function :zmq_leave, [:pointer, :string], :int
43
- rescue ::FFI::NotFoundError
44
- # libzmq built without ZMQ_BUILD_DRAFT_API
45
- end
46
-
47
-
48
- # Error
49
- attach_function :zmq_errno, [], :int
50
- attach_function :zmq_strerror, [:int], :string
51
-
52
- # Socket types
53
- ZMQ_PAIR = 0
54
- ZMQ_PUB = 1
55
- ZMQ_SUB = 2
56
- ZMQ_REQ = 3
57
- ZMQ_REP = 4
58
- ZMQ_DEALER = 5
59
- ZMQ_ROUTER = 6
60
- ZMQ_PULL = 7
61
- ZMQ_PUSH = 8
62
- ZMQ_XPUB = 9
63
- ZMQ_XSUB = 10
64
- ZMQ_SERVER = 12
65
- ZMQ_CLIENT = 13
66
- ZMQ_RADIO = 14
67
- ZMQ_DISH = 15
68
- ZMQ_GATHER = 16
69
- ZMQ_SCATTER = 17
70
- ZMQ_PEER = 19
71
- ZMQ_CHANNEL = 20
72
-
73
-
74
- # Socket type name → constant
75
- SOCKET_TYPES = {
76
- PAIR: ZMQ_PAIR, PUB: ZMQ_PUB, SUB: ZMQ_SUB,
77
- REQ: ZMQ_REQ, REP: ZMQ_REP,
78
- DEALER: ZMQ_DEALER, ROUTER: ZMQ_ROUTER,
79
- PULL: ZMQ_PULL, PUSH: ZMQ_PUSH,
80
- XPUB: ZMQ_XPUB, XSUB: ZMQ_XSUB,
81
- SERVER: ZMQ_SERVER, CLIENT: ZMQ_CLIENT,
82
- RADIO: ZMQ_RADIO, DISH: ZMQ_DISH,
83
- GATHER: ZMQ_GATHER, SCATTER: ZMQ_SCATTER,
84
- PEER: ZMQ_PEER, CHANNEL: ZMQ_CHANNEL,
85
- }.freeze
86
-
87
- # Send/recv flags
88
- ZMQ_DONTWAIT = 1
89
- ZMQ_SNDMORE = 2
90
-
91
-
92
- # Socket options
93
- ZMQ_IDENTITY = 5
94
- ZMQ_SUBSCRIBE = 6
95
- ZMQ_UNSUBSCRIBE = 7
96
- ZMQ_RCVMORE = 13
97
- ZMQ_FD = 14
98
- ZMQ_EVENTS = 15
99
- ZMQ_LINGER = 17
100
- ZMQ_SNDHWM = 23
101
- ZMQ_RCVHWM = 24
102
- ZMQ_RCVTIMEO = 27
103
- ZMQ_SNDTIMEO = 28
104
- ZMQ_MAXMSGSIZE = 22
105
- ZMQ_LAST_ENDPOINT = 32
106
- ZMQ_ROUTER_MANDATORY = 33
107
- ZMQ_RECONNECT_IVL = 18
108
- ZMQ_RECONNECT_IVL_MAX = 21
109
- ZMQ_CONFLATE = 54
110
-
111
-
112
- # zmq_msg_t is 64 bytes on all platforms
113
- MSG_T_SIZE = 64
114
-
115
-
116
- # Allocates a zmq_msg_t on the heap.
117
- #
118
- # @return [FFI::MemoryPointer]
119
- #
120
- def self.alloc_msg
121
- ::FFI::MemoryPointer.new(MSG_T_SIZE)
122
- end
123
-
124
-
125
- # Raises an error with the current zmq_errno message.
126
- #
127
- def self.check!(rc, label = "zmq")
128
- return rc if rc >= 0
129
- errno = zmq_errno
130
- raise "#{label}: #{zmq_strerror(errno)} (errno #{errno})"
131
- end
132
- end
133
- end
134
- end
data/lib/omq/ffi.rb DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Load the FFI backend for OMQ.
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 "ffi/libzmq"
12
- require_relative "ffi/engine"