ffi-rzmq 0.9.0 → 0.9.2
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.
- data/.gitignore +7 -0
- data/Gemfile +3 -0
- data/History.txt +31 -0
- data/README.rdoc +21 -11
- data/Rakefile +2 -34
- data/examples/README.rdoc +1 -1
- data/examples/v2api/latency_measurement.rb +139 -0
- data/examples/v2api/xreqxrep_poll.rb +93 -0
- data/examples/v3api/latency_measurement.rb +139 -0
- data/examples/v3api/xreqxrep_poll.rb +93 -0
- data/ffi-rzmq.gemspec +17 -26
- data/lib/ffi-rzmq/constants.rb +4 -37
- data/lib/ffi-rzmq/libzmq.rb +174 -161
- data/lib/ffi-rzmq/poll.rb +27 -10
- data/lib/ffi-rzmq/socket.rb +116 -85
- data/lib/ffi-rzmq/util.rb +22 -1
- data/lib/ffi-rzmq/version.rb +3 -0
- data/spec/nonblocking_recv_spec.rb +46 -40
- data/spec/poll_spec.rb +84 -0
- data/spec/pushpull_spec.rb +35 -2
- data/spec/socket_spec.rb +0 -2
- data/spec/spec_helper.rb +3 -7
- metadata +117 -95
- data/version.txt +0 -1
@@ -0,0 +1,93 @@
|
|
1
|
+
|
2
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ffi-rzmq')
|
3
|
+
|
4
|
+
|
5
|
+
def assert(rc)
|
6
|
+
raise "Last API call failed at #{caller(1)}" unless rc >= 0
|
7
|
+
end
|
8
|
+
|
9
|
+
link = "tcp://127.0.0.1:5555"
|
10
|
+
|
11
|
+
|
12
|
+
begin
|
13
|
+
ctx = ZMQ::Context.new
|
14
|
+
s1 = ctx.socket(ZMQ::XREQ)
|
15
|
+
s2 = ctx.socket(ZMQ::XREP)
|
16
|
+
rescue ContextError => e
|
17
|
+
STDERR.puts "Failed to allocate context or socket"
|
18
|
+
raise
|
19
|
+
end
|
20
|
+
|
21
|
+
s1.identity = 'socket1.xreq'
|
22
|
+
s2.identity = 'socket2.xrep'
|
23
|
+
|
24
|
+
assert(s1.setsockopt(ZMQ::LINGER, 100))
|
25
|
+
assert(s2.setsockopt(ZMQ::LINGER, 100))
|
26
|
+
|
27
|
+
assert(s1.bind(link))
|
28
|
+
assert(s2.connect(link))
|
29
|
+
|
30
|
+
poller = ZMQ::Poller.new
|
31
|
+
poller.register_readable(s2)
|
32
|
+
poller.register_writable(s1)
|
33
|
+
|
34
|
+
start_time = Time.now
|
35
|
+
@unsent = true
|
36
|
+
|
37
|
+
until @done do
|
38
|
+
assert(poller.poll_nonblock)
|
39
|
+
|
40
|
+
# send the message after 5 seconds
|
41
|
+
if Time.now - start_time > 5 && @unsent
|
42
|
+
puts "sending payload nonblocking"
|
43
|
+
|
44
|
+
5.times do |i|
|
45
|
+
payload = "#{ i.to_s * 40 }"
|
46
|
+
assert(s1.send_string(payload, ZMQ::DONTWAIT))
|
47
|
+
end
|
48
|
+
@unsent = false
|
49
|
+
end
|
50
|
+
|
51
|
+
# check for messages after 1 second
|
52
|
+
if Time.now - start_time > 1
|
53
|
+
poller.readables.each do |sock|
|
54
|
+
|
55
|
+
if sock.identity =~ /xrep/
|
56
|
+
routing_info = ''
|
57
|
+
assert(sock.recv_string(routing_info, ZMQ::DONTWAIT))
|
58
|
+
puts "routing_info received [#{routing_info}] on socket.identity [#{sock.identity}]"
|
59
|
+
else
|
60
|
+
routing_info = nil
|
61
|
+
received_msg = ''
|
62
|
+
assert(sock.recv_string(received_msg, ZMQ::DONTWAIT))
|
63
|
+
|
64
|
+
# skip to the next iteration if received_msg is nil; that means we got an EAGAIN
|
65
|
+
next unless received_msg
|
66
|
+
puts "message received [#{received_msg}] on socket.identity [#{sock.identity}]"
|
67
|
+
end
|
68
|
+
|
69
|
+
while sock.more_parts? do
|
70
|
+
received_msg = ''
|
71
|
+
assert(sock.recv_string(received_msg, ZMQ::DONTWAIT))
|
72
|
+
|
73
|
+
puts "message received [#{received_msg}]"
|
74
|
+
end
|
75
|
+
|
76
|
+
puts "kick back a reply"
|
77
|
+
assert(sock.send_string(routing_info, ZMQ::SNDMORE | ZMQ::DONTWAIT)) if routing_info
|
78
|
+
time = Time.now.strftime "%Y-%m-%dT%H:%M:%S.#{Time.now.usec}"
|
79
|
+
reply = "reply " + sock.identity.upcase + " #{time}"
|
80
|
+
puts "sent reply [#{reply}], #{time}"
|
81
|
+
assert(sock.send_string(reply))
|
82
|
+
@done = true
|
83
|
+
poller.register_readable(s1)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
puts "executed in [#{Time.now - start_time}] seconds"
|
89
|
+
|
90
|
+
assert(s1.close)
|
91
|
+
assert(s2.close)
|
92
|
+
|
93
|
+
ctx.terminate
|
data/ffi-rzmq.gemspec
CHANGED
@@ -1,36 +1,27 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ffi-rzmq/version"
|
2
4
|
|
3
5
|
Gem::Specification.new do |s|
|
4
|
-
s.name
|
5
|
-
s.version
|
6
|
-
|
7
|
-
s.
|
8
|
-
s.
|
9
|
-
s.
|
6
|
+
s.name = "ffi-rzmq"
|
7
|
+
s.version = ZMQ::VERSION
|
8
|
+
s.authors = ["Chuck Remes"]
|
9
|
+
s.email = ["cremes@mac.com"]
|
10
|
+
s.homepage = "http://github.com/chuckremes/ffi-rzmq"
|
11
|
+
s.summary = %q{This gem wraps the ZeroMQ (0mq) networking library using Ruby FFI (foreign function interface).}
|
10
12
|
s.description = %q{This gem wraps the ZeroMQ networking library using the ruby FFI (foreign
|
11
13
|
function interface). It's a pure ruby wrapper so this gem can be loaded
|
12
14
|
and run by any ruby runtime that supports FFI. That's all of them:
|
13
15
|
MRI 1.9.x, Rubinius and JRuby.}
|
14
|
-
s.email = %q{cremes@mac.com}
|
15
|
-
s.extra_rdoc_files = ["AUTHORS.txt", "History.txt", "README.rdoc", "examples/README.rdoc", "version.txt"]
|
16
|
-
s.files = [".bnsignore", "History.txt", "README.rdoc", "Rakefile", "examples/README.rdoc", "examples/v2api/local_lat.rb", "examples/v2api/local_lat_poll.rb", "examples/v2api/local_throughput.rb", "examples/v2api/publish_subscribe.rb", "examples/v2api/remote_lat.rb", "examples/v2api/remote_throughput.rb", "examples/v2api/reqrep_poll.rb", "examples/v2api/request_response.rb", "examples/v2api/throughput_measurement.rb", "examples/v3api/local_lat.rb", "examples/v3api/local_lat_poll.rb", "examples/v3api/local_throughput.rb", "examples/v3api/publish_subscribe.rb", "examples/v3api/remote_lat.rb", "examples/v3api/remote_throughput.rb", "examples/v3api/reqrep_poll.rb", "examples/v3api/request_response.rb", "examples/v3api/throughput_measurement.rb", "ext/README", "ffi-rzmq.gemspec", "lib/ffi-rzmq.rb", "lib/ffi-rzmq/constants.rb", "lib/ffi-rzmq/context.rb", "lib/ffi-rzmq/device.rb", "lib/ffi-rzmq/exceptions.rb", "lib/ffi-rzmq/libc.rb", "lib/ffi-rzmq/libzmq.rb", "lib/ffi-rzmq/message.rb", "lib/ffi-rzmq/poll.rb", "lib/ffi-rzmq/poll_items.rb", "lib/ffi-rzmq/socket.rb", "lib/ffi-rzmq/util.rb", "spec/context_spec.rb", "spec/device_spec.rb", "spec/message_spec.rb", "spec/multipart_spec.rb", "spec/nonblocking_recv_spec.rb", "spec/pushpull_spec.rb", "spec/reqrep_spec.rb", "spec/socket_spec.rb", "spec/spec_helper.rb", "version.txt"]
|
17
|
-
s.homepage = %q{http://github.com/chuckremes/ffi-rzmq}
|
18
|
-
s.rdoc_options = ["--main", "README.rdoc"]
|
19
|
-
s.require_paths = ["lib"]
|
20
|
-
s.rubyforge_project = %q{ffi-rzmq}
|
21
|
-
s.rubygems_version = %q{1.3.7}
|
22
|
-
s.summary = %q{This gem wraps the ZeroMQ (0mq) networking library using Ruby FFI (foreign function interface).}
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
s.rubyforge_project = "ffi-rzmq"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
s.add_dependency(%q<bones>, [">= 3.5.4"])
|
32
|
-
end
|
33
|
-
else
|
34
|
-
s.add_dependency(%q<bones>, [">= 3.5.4"])
|
35
|
-
end
|
24
|
+
s.add_runtime_dependency "ffi", [">= 1.0.9"]
|
25
|
+
s.add_development_dependency "rspec", ["~> 2.6"]
|
26
|
+
s.add_development_dependency "rake"
|
36
27
|
end
|
data/lib/ffi-rzmq/constants.rb
CHANGED
@@ -82,7 +82,7 @@ module ZMQ
|
|
82
82
|
end # module ZMQ
|
83
83
|
|
84
84
|
|
85
|
-
if LibZMQ.version2?
|
85
|
+
if ZMQ::LibZMQ.version2?
|
86
86
|
module ZMQ
|
87
87
|
# Socket types
|
88
88
|
UPSTREAM = PULL
|
@@ -111,13 +111,13 @@ if LibZMQ.version2?
|
|
111
111
|
end # version2?
|
112
112
|
|
113
113
|
|
114
|
-
if LibZMQ.version3?
|
114
|
+
if ZMQ::LibZMQ.version3?
|
115
115
|
module ZMQ
|
116
116
|
# Socket types
|
117
117
|
XPUB = 9
|
118
118
|
XSUB = 10
|
119
|
-
|
120
|
-
|
119
|
+
DEALER = XREQ
|
120
|
+
ROUTER = XREP
|
121
121
|
|
122
122
|
SocketTypeNameMap[ROUTER] = 'ROUTER'
|
123
123
|
SocketTypeNameMap[DEALER] = 'DEALER'
|
@@ -132,7 +132,6 @@ if LibZMQ.version3?
|
|
132
132
|
MULTICAST_HOPS = 25
|
133
133
|
RCVTIMEO = 27
|
134
134
|
SNDTIMEO = 28
|
135
|
-
RCVLABEL = 29
|
136
135
|
|
137
136
|
# Send/recv options
|
138
137
|
DONTWAIT = 1
|
@@ -144,35 +143,3 @@ if LibZMQ.version3?
|
|
144
143
|
|
145
144
|
end
|
146
145
|
end # version3?
|
147
|
-
|
148
|
-
|
149
|
-
if LibZMQ.version4?
|
150
|
-
module ZMQ
|
151
|
-
# Socket types
|
152
|
-
XPUB = 9
|
153
|
-
XSUB = 10
|
154
|
-
ROUTER = 13
|
155
|
-
|
156
|
-
SocketTypeNameMap[ROUTER] = 'ROUTER'
|
157
|
-
SocketTypeNameMap[XPUB] = 'XPUB'
|
158
|
-
SocketTypeNameMap[XSUB] = 'XSUB'
|
159
|
-
|
160
|
-
# Socket options
|
161
|
-
MAXMSGSIZE = 22
|
162
|
-
SNDHWM = 23
|
163
|
-
RCVHWM = 24
|
164
|
-
MULTICAST_HOPS = 25
|
165
|
-
RCVTIMEO = 27
|
166
|
-
SNDTIMEO = 28
|
167
|
-
RCVLABEL = 29
|
168
|
-
|
169
|
-
# Send/recv options
|
170
|
-
DONTWAIT = 1
|
171
|
-
SNDLABEL = 4
|
172
|
-
|
173
|
-
|
174
|
-
# Socket & other errors
|
175
|
-
EMFILE = Errno::EMFILE::Errno
|
176
|
-
|
177
|
-
end
|
178
|
-
end # version4?
|
data/lib/ffi-rzmq/libzmq.rb
CHANGED
@@ -1,188 +1,201 @@
|
|
1
|
+
module ZMQ
|
1
2
|
|
2
|
-
# Wraps the libzmq library and attaches to the functions that are
|
3
|
-
# common across the 2.x, 3.x and 4.x APIs.
|
4
|
-
#
|
5
|
-
module LibZMQ
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
3
|
+
# Wraps the libzmq library and attaches to the functions that are
|
4
|
+
# common across the 2.x, 3.x and 4.x APIs.
|
5
|
+
#
|
6
|
+
module LibZMQ
|
7
|
+
extend FFI::Library
|
8
|
+
|
9
|
+
begin
|
10
|
+
# bias the library discovery to a path inside the gem first, then
|
11
|
+
# to the usual system paths
|
12
|
+
inside_gem = File.join(File.dirname(__FILE__), '..', '..', 'ext')
|
13
|
+
ZMQ_LIB_PATHS = [
|
14
|
+
inside_gem, '/usr/local/lib', '/opt/local/lib', '/usr/local/homebrew/lib', '/usr/lib64'
|
15
|
+
].map{|path| "#{path}/libzmq.#{FFI::Platform::LIBSUFFIX}"}
|
16
|
+
ffi_lib(ZMQ_LIB_PATHS + %w{libzmq})
|
17
|
+
rescue LoadError
|
18
|
+
STDERR.puts "Unable to load this gem. The libzmq library (or DLL) could not be found."
|
19
|
+
STDERR.puts "If this is a Windows platform, make sure libzmq.dll is on the PATH."
|
20
|
+
STDERR.puts "For non-Windows platforms, make sure libzmq is located in this search path:"
|
21
|
+
STDERR.puts ZMQ_LIB_PATHS.inspect
|
22
|
+
exit 255
|
23
|
+
end
|
15
24
|
|
16
|
-
|
17
|
-
|
25
|
+
# Size_t not working properly on Windows
|
26
|
+
find_type(:size_t) rescue typedef(:ulong, :size_t)
|
27
|
+
|
28
|
+
# Context and misc api
|
29
|
+
#
|
30
|
+
# @blocking = true is a hint to FFI that the following (and only the following)
|
31
|
+
# function may block, therefore it should release the GIL before calling it.
|
32
|
+
# This can aid in situations where the function call will/may block and another
|
33
|
+
# thread within the lib may try to call back into the ruby runtime. Failure to
|
34
|
+
# release the GIL will result in a hang; the hint *may* allow things to run
|
35
|
+
# smoothly for Ruby runtimes hampered by a GIL.
|
36
|
+
#
|
37
|
+
# This is really only honored by the MRI implementation but it *is* necessary
|
38
|
+
# otherwise the runtime hangs (and requires a kill -9 to terminate)
|
39
|
+
#
|
40
|
+
@blocking = true
|
41
|
+
attach_function :zmq_init, [:int], :pointer
|
42
|
+
@blocking = true
|
43
|
+
attach_function :zmq_socket, [:pointer, :int], :pointer
|
44
|
+
@blocking = true
|
45
|
+
attach_function :zmq_term, [:pointer], :int
|
46
|
+
@blocking = true
|
47
|
+
attach_function :zmq_errno, [], :int
|
48
|
+
@blocking = true
|
49
|
+
attach_function :zmq_strerror, [:int], :pointer
|
50
|
+
@blocking = true
|
51
|
+
attach_function :zmq_version, [:pointer, :pointer, :pointer], :void
|
52
|
+
|
53
|
+
def self.version
|
54
|
+
unless @version
|
55
|
+
major = FFI::MemoryPointer.new :int
|
56
|
+
minor = FFI::MemoryPointer.new :int
|
57
|
+
patch = FFI::MemoryPointer.new :int
|
58
|
+
LibZMQ.zmq_version major, minor, patch
|
59
|
+
@version = {:major => major.read_int, :minor => minor.read_int, :patch => patch.read_int}
|
60
|
+
end
|
18
61
|
|
19
|
-
|
20
|
-
#
|
21
|
-
# @blocking = true is a hint to FFI that the following (and only the following)
|
22
|
-
# function may block, therefore it should release the GIL before calling it.
|
23
|
-
# This can aid in situations where the function call will/may block and another
|
24
|
-
# thread within the lib may try to call back into the ruby runtime. Failure to
|
25
|
-
# release the GIL will result in a hang; the hint *may* allow things to run
|
26
|
-
# smoothly for Ruby runtimes hampered by a GIL.
|
27
|
-
#
|
28
|
-
# This is really only honored by the MRI implementation but it *is* necessary
|
29
|
-
# otherwise the runtime hangs (and requires a kill -9 to terminate)
|
30
|
-
#
|
31
|
-
@blocking = true
|
32
|
-
attach_function :zmq_init, [:int], :pointer
|
33
|
-
@blocking = true
|
34
|
-
attach_function :zmq_socket, [:pointer, :int], :pointer
|
35
|
-
@blocking = true
|
36
|
-
attach_function :zmq_term, [:pointer], :int
|
37
|
-
@blocking = true
|
38
|
-
attach_function :zmq_errno, [], :int
|
39
|
-
@blocking = true
|
40
|
-
attach_function :zmq_strerror, [:int], :pointer
|
41
|
-
@blocking = true
|
42
|
-
attach_function :zmq_version, [:pointer, :pointer, :pointer], :void
|
43
|
-
|
44
|
-
def self.version
|
45
|
-
unless @version
|
46
|
-
major = FFI::MemoryPointer.new :int
|
47
|
-
minor = FFI::MemoryPointer.new :int
|
48
|
-
patch = FFI::MemoryPointer.new :int
|
49
|
-
LibZMQ.zmq_version major, minor, patch
|
50
|
-
@version = {:major => major.read_int, :minor => minor.read_int, :patch => patch.read_int}
|
62
|
+
@version
|
51
63
|
end
|
52
64
|
|
53
|
-
|
54
|
-
end
|
65
|
+
def self.version2?() version[:major] == 2 && version[:minor] >= 1 end
|
55
66
|
|
56
|
-
|
67
|
+
def self.version3?() version[:major] == 3 && version[:minor] >= 1 end
|
57
68
|
|
58
|
-
|
69
|
+
def self.version4?() version[:major] == 4 end
|
59
70
|
|
60
|
-
def self.version4?() version[:major] == 4 end
|
61
71
|
|
72
|
+
# Message api
|
73
|
+
@blocking = true
|
74
|
+
attach_function :zmq_msg_init, [:pointer], :int
|
75
|
+
@blocking = true
|
76
|
+
attach_function :zmq_msg_init_size, [:pointer, :size_t], :int
|
77
|
+
@blocking = true
|
78
|
+
attach_function :zmq_msg_init_data, [:pointer, :pointer, :size_t, :pointer, :pointer], :int
|
79
|
+
@blocking = true
|
80
|
+
attach_function :zmq_msg_close, [:pointer], :int
|
81
|
+
@blocking = true
|
82
|
+
attach_function :zmq_msg_data, [:pointer], :pointer
|
83
|
+
@blocking = true
|
84
|
+
attach_function :zmq_msg_size, [:pointer], :size_t
|
85
|
+
@blocking = true
|
86
|
+
attach_function :zmq_msg_copy, [:pointer, :pointer], :int
|
87
|
+
@blocking = true
|
88
|
+
attach_function :zmq_msg_move, [:pointer, :pointer], :int
|
62
89
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
attach_function :zmq_msg_close, [:pointer], :int
|
72
|
-
@blocking = true
|
73
|
-
attach_function :zmq_msg_data, [:pointer], :pointer
|
74
|
-
@blocking = true
|
75
|
-
attach_function :zmq_msg_size, [:pointer], :size_t
|
76
|
-
@blocking = true
|
77
|
-
attach_function :zmq_msg_copy, [:pointer, :pointer], :int
|
78
|
-
@blocking = true
|
79
|
-
attach_function :zmq_msg_move, [:pointer, :pointer], :int
|
90
|
+
# Used for casting pointers back to the struct
|
91
|
+
#
|
92
|
+
class Msg < FFI::Struct
|
93
|
+
layout :content, :pointer,
|
94
|
+
:flags, :uint8,
|
95
|
+
:vsm_size, :uint8,
|
96
|
+
:vsm_data, [:uint8, 30]
|
97
|
+
end # class Msg
|
80
98
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
:
|
86
|
-
|
87
|
-
:
|
88
|
-
|
89
|
-
|
90
|
-
# Socket api
|
91
|
-
@blocking = true
|
92
|
-
attach_function :zmq_setsockopt, [:pointer, :int, :pointer, :int], :int
|
93
|
-
@blocking = true
|
94
|
-
attach_function :zmq_bind, [:pointer, :string], :int
|
95
|
-
@blocking = true
|
96
|
-
attach_function :zmq_connect, [:pointer, :string], :int
|
97
|
-
@blocking = true
|
98
|
-
attach_function :zmq_close, [:pointer], :int
|
99
|
-
|
100
|
-
# Poll api
|
101
|
-
@blocking = true
|
102
|
-
attach_function :zmq_poll, [:pointer, :int, :long], :int
|
103
|
-
|
104
|
-
module PollItemLayout
|
105
|
-
def self.included(base)
|
106
|
-
base.class_eval do
|
107
|
-
layout :socket, :pointer,
|
108
|
-
:fd, :int,
|
109
|
-
:events, :short,
|
110
|
-
:revents, :short
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end # module PollItemLayout
|
99
|
+
# Socket api
|
100
|
+
@blocking = true
|
101
|
+
attach_function :zmq_setsockopt, [:pointer, :int, :pointer, :int], :int
|
102
|
+
@blocking = true
|
103
|
+
attach_function :zmq_bind, [:pointer, :string], :int
|
104
|
+
@blocking = true
|
105
|
+
attach_function :zmq_connect, [:pointer, :string], :int
|
106
|
+
@blocking = true
|
107
|
+
attach_function :zmq_close, [:pointer], :int
|
114
108
|
|
115
|
-
|
116
|
-
|
109
|
+
# Poll api
|
110
|
+
@blocking = true
|
111
|
+
attach_function :zmq_poll, [:pointer, :int, :long], :int
|
112
|
+
|
113
|
+
module PollItemLayout
|
114
|
+
def self.included(base)
|
115
|
+
base.class_eval do
|
116
|
+
layout :socket, :pointer,
|
117
|
+
:fd, :int,
|
118
|
+
:events, :short,
|
119
|
+
:revents, :short
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end # module PollItemLayout
|
117
123
|
|
118
|
-
|
124
|
+
class PollItem < FFI::Struct
|
125
|
+
include PollItemLayout
|
119
126
|
|
120
|
-
|
121
|
-
|
122
|
-
|
127
|
+
def socket() self[:socket]; end
|
128
|
+
|
129
|
+
def fd() self[:fd]; end
|
123
130
|
|
124
|
-
|
125
|
-
|
126
|
-
|
131
|
+
def readable?
|
132
|
+
(self[:revents] & ZMQ::POLLIN) > 0
|
133
|
+
end
|
127
134
|
|
128
|
-
|
129
|
-
|
130
|
-
|
135
|
+
def writable?
|
136
|
+
(self[:revents] & ZMQ::POLLOUT) > 0
|
137
|
+
end
|
131
138
|
|
132
|
-
|
133
|
-
|
134
|
-
|
139
|
+
def both_accessible?
|
140
|
+
readable? && writable?
|
141
|
+
end
|
135
142
|
|
136
|
-
|
137
|
-
|
143
|
+
def inspect
|
144
|
+
"socket [#{socket}], fd [#{fd}], events [#{self[:events]}], revents [#{self[:revents]}]"
|
145
|
+
end
|
138
146
|
|
139
|
-
end
|
147
|
+
def to_s; inspect; end
|
148
|
+
end # class PollItem
|
140
149
|
|
150
|
+
end
|
141
151
|
|
142
|
-
# Attaches to those functions specific to the 2.x API
|
143
|
-
#
|
144
|
-
if LibZMQ.version2?
|
145
152
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
153
|
+
# Attaches to those functions specific to the 2.x API
|
154
|
+
#
|
155
|
+
if LibZMQ.version2?
|
156
|
+
|
157
|
+
module LibZMQ
|
158
|
+
# Socket api
|
159
|
+
@blocking = true
|
160
|
+
attach_function :zmq_getsockopt, [:pointer, :int, :pointer, :pointer], :int
|
161
|
+
@blocking = true
|
162
|
+
attach_function :zmq_recv, [:pointer, :pointer, :int], :int
|
163
|
+
@blocking = true
|
164
|
+
attach_function :zmq_send, [:pointer, :pointer, :int], :int
|
165
|
+
@blocking = true
|
166
|
+
attach_function :zmq_device, [:int, :pointer, :pointer], :int
|
167
|
+
end
|
156
168
|
end
|
157
|
-
end
|
158
169
|
|
159
170
|
|
160
|
-
# Attaches to those functions specific to the 3.x API
|
161
|
-
#
|
162
|
-
if LibZMQ.version3?
|
171
|
+
# Attaches to those functions specific to the 3.x API
|
172
|
+
#
|
173
|
+
if LibZMQ.version3?
|
174
|
+
|
175
|
+
module LibZMQ
|
176
|
+
# Socket api
|
177
|
+
@blocking = true
|
178
|
+
attach_function :zmq_getsockopt, [:pointer, :int, :pointer, :pointer], :int
|
179
|
+
@blocking = true
|
180
|
+
attach_function :zmq_recvmsg, [:pointer, :pointer, :int], :int
|
181
|
+
@blocking = true
|
182
|
+
attach_function :zmq_recv, [:pointer, :pointer, :size_t, :int], :int
|
183
|
+
@blocking = true
|
184
|
+
attach_function :zmq_sendmsg, [:pointer, :pointer, :int], :int
|
185
|
+
@blocking = true
|
186
|
+
attach_function :zmq_send, [:pointer, :pointer, :size_t, :int], :int
|
187
|
+
end
|
188
|
+
end
|
163
189
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
attach_function :zmq_sendmsg, [:pointer, :pointer, :int], :int
|
174
|
-
@blocking = true
|
175
|
-
attach_function :zmq_send, [:pointer, :pointer, :size_t, :int], :int
|
190
|
+
|
191
|
+
# Sanity check; print an error and exit if we are trying to load an unsupported
|
192
|
+
# version of libzmq.
|
193
|
+
#
|
194
|
+
unless LibZMQ.version2? || LibZMQ.version3?
|
195
|
+
hash = LibZMQ.version
|
196
|
+
version = "#{hash[:major]}.#{hash[:minor]}.#{hash[:patch]}"
|
197
|
+
STDERR.puts "Unable to load this gem. The libzmq version #{version} is incompatible with ffi-rzmq."
|
198
|
+
exit 255
|
176
199
|
end
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
# Sanity check; print an error and exit if we are trying to load an unsupported
|
181
|
-
# version of libzmq.
|
182
|
-
#
|
183
|
-
unless LibZMQ.version2? || LibZMQ.version3? || LibZMQ.version4?
|
184
|
-
hash = LibZMQ.version
|
185
|
-
version = "#{hash[:major]}.#{hash[:minor]}.#{hash[:patch]}"
|
186
|
-
STDERR.puts "Unable to load this gem. The libzmq version #{version} is incompatible with ffi-rzmq."
|
187
|
-
exit 255
|
188
|
-
end
|
200
|
+
|
201
|
+
end # module ZMQ
|