ruby-czmq-ffi 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +38 -0
- data/Rakefile +9 -0
- data/czmq-ffi.gemspec +25 -0
- data/lib/czmq-ffi.rb +6 -0
- data/lib/czmq-ffi/constants.rb +40 -0
- data/lib/czmq-ffi/libc.rb +9 -0
- data/lib/czmq-ffi/libczmq.rb +305 -0
- data/lib/czmq-ffi/structures.rb +41 -0
- data/lib/czmq-ffi/utils.rb +18 -0
- data/lib/czmq-ffi/version.rb +3 -0
- data/test/test_helper.rb +4 -0
- data/test/zframe_test.rb +19 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c69869de8e6a9780530d4dee8db00fc8a704776f
|
4
|
+
data.tar.gz: 57330fa845967aea66a44db4c015cbf17d46af68
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 94aab407c9d6a5bb4501ad8ee1c4624b62adf666afa5d85f4fdd8a8ae88fe6d953093a598bceaca7d0bfa07e9e36f6b44099551619a179f07b3853607272cb93
|
7
|
+
data.tar.gz: b97258a1ebd37c92e3ab24fe2fae0563981a9f52990ab158775d768f120ebfccc76360a315b876c513713619cabef6abfdae57f90e848b6a995b6b48e5ceb274
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*~
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
*.swp
|
5
|
+
.bundle
|
6
|
+
.config
|
7
|
+
.ruby-gemset
|
8
|
+
coverage
|
9
|
+
Gemfile.lock
|
10
|
+
InstalledFiles
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
|
19
|
+
# YARD artifacts
|
20
|
+
.yardoc
|
21
|
+
_yardoc
|
22
|
+
doc/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Mauro Tortonesi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# ruby-czmq-ffi
|
2
|
+
|
3
|
+
ruby-czmq-ffi provides low-level Ruby bindings for the
|
4
|
+
[CZMQ](http://czmq.zeromq.org/) library. ruby-czmq-ffi leverages the FFI
|
5
|
+
mechanism, and thus should work on all the main Ruby VMs: YARV/MRI, JRuby, and
|
6
|
+
Rubinius.
|
7
|
+
|
8
|
+
The ruby-czmq-ffi library was not designed to be used directly by applications,
|
9
|
+
but instead to provide functions for higher-level gems such as
|
10
|
+
[ruby-czmq](https://github.com/mtortonesi/ruby-czmq).
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
### Stable version
|
16
|
+
|
17
|
+
You can get the stable version of ruby-czmq-ffi by installing the czmq-ffi gem from
|
18
|
+
RubyGems:
|
19
|
+
|
20
|
+
gem install czmq-ffi
|
21
|
+
|
22
|
+
### Development version
|
23
|
+
|
24
|
+
If you want to try the development version of ruby-czmq-ffi, instead, just place
|
25
|
+
this line:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
gem ruby-czmq-ffi, git: 'https://github.com/mtortonesi/ruby-czmq-ffi.git'
|
29
|
+
```
|
30
|
+
|
31
|
+
in your Gemfile and run:
|
32
|
+
|
33
|
+
bundle install
|
34
|
+
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
MIT
|
data/Rakefile
ADDED
data/czmq-ffi.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'czmq-ffi/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'ruby-czmq-ffi'
|
8
|
+
spec.version = LibCZMQ::VERSION
|
9
|
+
spec.authors = ['Mauro Tortonesi']
|
10
|
+
spec.email = ['mauro.tortonesi@unife.it']
|
11
|
+
spec.description = %q{FFI-based Ruby bindings for the CZMQ library}
|
12
|
+
spec.summary = %q{This gem provides low-level bindings for the CZMQ library, using FFI.
|
13
|
+
It is not meant to be used directly by applications, but instead to provide
|
14
|
+
functions for higher-level gems such as ruby-czmq.}
|
15
|
+
spec.homepage = 'https://github.com/mtortonesi/ruby-czmq-ffi'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
end
|
data/lib/czmq-ffi.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module CZMQ
|
2
|
+
# Socket types
|
3
|
+
PAIR = 0
|
4
|
+
PUB = 1
|
5
|
+
SUB = 2
|
6
|
+
REQ = 3
|
7
|
+
REP = 4
|
8
|
+
XREQ = 5
|
9
|
+
XREP = 6
|
10
|
+
PULL = 7
|
11
|
+
PUSH = 8
|
12
|
+
XPUB = 9
|
13
|
+
XSUB = 10
|
14
|
+
DEALER = XREQ
|
15
|
+
ROUTER = XREP
|
16
|
+
STREAM = 11
|
17
|
+
|
18
|
+
SocketTypeToNameMap = {
|
19
|
+
PAIR => 'PAIR',
|
20
|
+
PUB => 'PUB',
|
21
|
+
SUB => 'SUB',
|
22
|
+
REQ => 'REQ',
|
23
|
+
REP => 'REP',
|
24
|
+
PULL => 'PULL',
|
25
|
+
PUSH => 'PUSH',
|
26
|
+
XREQ => 'XREQ',
|
27
|
+
XREP => 'XREP',
|
28
|
+
ROUTER => 'ROUTER',
|
29
|
+
DEALER => 'DEALER',
|
30
|
+
XPUB => 'XPUB',
|
31
|
+
XSUB => 'XSUB',
|
32
|
+
STREAM => 'STREAM',
|
33
|
+
}
|
34
|
+
|
35
|
+
# I/O multiplexing
|
36
|
+
POLL = 1
|
37
|
+
POLLIN = 1
|
38
|
+
POLLOUT = 2
|
39
|
+
POLLERR = 4
|
40
|
+
end
|
@@ -0,0 +1,305 @@
|
|
1
|
+
require 'czmq-ffi/utils'
|
2
|
+
|
3
|
+
module LibCZMQ
|
4
|
+
extend FFI::Library
|
5
|
+
|
6
|
+
begin
|
7
|
+
# This looks like a sensible search path
|
8
|
+
LIB_PATH = %w{/usr/lib /usr/lib64 /usr/local/lib /usr/lib32}
|
9
|
+
CZMQ_LIB_PATH = LIB_PATH.map{ |path| "#{path}/libczmq.#{FFI::Platform::LIBSUFFIX}" }
|
10
|
+
ffi_lib(CZMQ_LIB_PATH + %w{libzmq})
|
11
|
+
rescue LoadError
|
12
|
+
warn 'Could not load the CZMQ Library.'
|
13
|
+
raise
|
14
|
+
end
|
15
|
+
|
16
|
+
##################################################
|
17
|
+
# zctx-related functions
|
18
|
+
##################################################
|
19
|
+
attach_function :zctx_new, [], :pointer
|
20
|
+
attach_function :__zctx_destroy, :zctx_destroy, [:pointer], :void
|
21
|
+
attach_function :zctx_set_iothreads, [:pointer, :int], :void
|
22
|
+
attach_function :zctx_set_linger, [:pointer, :int], :void
|
23
|
+
attach_function :zctx_set_pipehwm, [:pointer, :int], :void
|
24
|
+
attach_function :zctx_set_sndhwm, [:pointer, :int], :void
|
25
|
+
attach_function :zctx_set_rcvhwm, [:pointer, :int], :void
|
26
|
+
attach_function :zctx_underlying, [:pointer], :pointer
|
27
|
+
|
28
|
+
def self.zctx_destroy(zctx)
|
29
|
+
zctx_ptr = FFI::MemoryPointer.new(:pointer)
|
30
|
+
zctx_ptr.write_pointer(zctx)
|
31
|
+
__zctx_destroy(zctx_ptr)
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
##################################################
|
36
|
+
# zbeacon-related functions
|
37
|
+
##################################################
|
38
|
+
attach_function :zbeacon_new, [:int], :pointer # zbeacon_new returns NULL in case of failure
|
39
|
+
attach_function :__zbeacon_destroy, :zbeacon_destroy, [:pointer], :void
|
40
|
+
attach_function :zbeacon_hostname, [:pointer], :pointer
|
41
|
+
attach_function :zbeacon_set_interval, [:pointer, :int], :void
|
42
|
+
attach_function :zbeacon_noecho, [:pointer], :void
|
43
|
+
attach_function :__zbeacon_publish, :zbeacon_publish, [:pointer, :pointer, :size_t], :void
|
44
|
+
attach_function :zbeacon_silence, [:pointer], :void
|
45
|
+
attach_function :__zbeacon_subscribe, :zbeacon_subscribe, [:pointer, :pointer, :size_t], :void
|
46
|
+
attach_function :zbeacon_unsubscribe, [:pointer], :void
|
47
|
+
attach_function :zbeacon_socket, [:pointer], :pointer
|
48
|
+
|
49
|
+
def self.zbeacon_destroy(zbeacon)
|
50
|
+
zbeacon_ptr = FFI::MemoryPointer.new(:pointer)
|
51
|
+
zbeacon_ptr.write_pointer(zbeacon)
|
52
|
+
__zbeacon_destroy(zbeacon_ptr)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.zbeacon_publish(zbeacon, byte_array)
|
56
|
+
FFI::MemoryPointer.new(:uint8, byte_array.size) do |p|
|
57
|
+
p.write_array_of_int8(byte_array)
|
58
|
+
__zbeacon_publish(zbeacon, p, byte_array.size)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.zbeacon_subscribe(zbeacon, byte_array=nil)
|
63
|
+
if byte_array.nil?
|
64
|
+
__zbeacon_subscribe(zbeacon, nil, 0)
|
65
|
+
else
|
66
|
+
FFI::MemoryPointer.new(:uint8, byte_array.size) do |p|
|
67
|
+
p.write_array_of_int8(byte_array)
|
68
|
+
__zbeacon_subscribe(zbeacon, p, byte_array.size)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
##################################################
|
76
|
+
# zsocket-related functions
|
77
|
+
##################################################
|
78
|
+
attach_function :zsocket_new, [:pointer, :int], :pointer
|
79
|
+
attach_function :zsocket_destroy, [:pointer, :pointer], :void
|
80
|
+
attach_function :zsocket_bind, [:pointer, :string, :varargs], :int
|
81
|
+
attach_function :zsocket_unbind, [:pointer, :string, :varargs], :void
|
82
|
+
attach_function :zsocket_connect, [:pointer, :string, :varargs], :void
|
83
|
+
attach_function :zsocket_disconnect, [:pointer, :string, :varargs], :void
|
84
|
+
attach_function :zsocket_poll, [:pointer, :int], :bool
|
85
|
+
attach_function :__zsocket_type_str, :zsocket_type_str, [:pointer], :pointer
|
86
|
+
attach_function :zsocket_sendmem, [:pointer, :pointer, :size_t, :int], :int
|
87
|
+
|
88
|
+
# return nil or (a copy of) the zsocket type name
|
89
|
+
def self.zsocket_type_str(zsocket)
|
90
|
+
type_ptr = __zsocket_type_str(zsocket)
|
91
|
+
type_ptr.null? ? nil : type_ptr.read_string
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
##################################################
|
96
|
+
# zstr-related functions
|
97
|
+
##################################################
|
98
|
+
attach_function :__zstr_recv, :zstr_recv, [:pointer], :pointer
|
99
|
+
attach_function :__zstr_recv_nowait, :zstr_recv_nowait, [:pointer], :pointer
|
100
|
+
attach_function :zstr_send, [:pointer, :string, :varargs], :int
|
101
|
+
attach_function :zstr_sendm, [:pointer, :string, :varargs], :int
|
102
|
+
attach_function :zstr_sendx, [:pointer, :string, :varargs], :int
|
103
|
+
# attach_function :__zstr_recvx, :zstr_recvx, [:pointer, :pointer, :varargs], :int
|
104
|
+
|
105
|
+
def self.zstr_recv(zsocket)
|
106
|
+
Utils.extract_string(__zstr_recv(zsocket))
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.zstr_recv_nowait(zsocket)
|
110
|
+
Utils.extract_string(__zstr_recv_nowait(zsocket))
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
##################################################
|
115
|
+
# zmsg-related functions
|
116
|
+
##################################################
|
117
|
+
attach_function :zmsg_new, [], :pointer
|
118
|
+
attach_function :__zmsg_destroy, :zmsg_destroy, [:pointer], :void
|
119
|
+
attach_function :zmsg_recv, [:pointer], :pointer
|
120
|
+
attach_function :__zmsg_send, :zmsg_send, [:pointer, :pointer], :int
|
121
|
+
attach_function :zmsg_size, [:pointer], :size_t
|
122
|
+
attach_function :zmsg_content_size, [:pointer], :size_t
|
123
|
+
|
124
|
+
# zframe add / remove
|
125
|
+
# NOTE: zmsg_push will take ownership of zframe and destroy it at the end
|
126
|
+
attach_function :zmsg_push, [:pointer, :pointer], :int
|
127
|
+
attach_function :zmsg_pop, [:pointer], :pointer
|
128
|
+
# NOTE: zmsg_append will take ownership of zframe and destroy it at the end
|
129
|
+
attach_function :__zmsg_append, :zmsg_append, [:pointer, :pointer], :int
|
130
|
+
|
131
|
+
# memory buffer add / remove
|
132
|
+
attach_function :__zmsg_pushmem, :zmsg_pushmem, [:pointer, :buffer_in, :size_t], :int
|
133
|
+
attach_function :__zmsg_addmem, :zmsg_addmem, [:pointer, :buffer_in, :size_t], :int
|
134
|
+
|
135
|
+
# string add / remove
|
136
|
+
attach_function :zmsg_pushstr, [:pointer, :string, :varargs], :int
|
137
|
+
attach_function :zmsg_addstr, [:pointer, :string, :varargs], :int
|
138
|
+
attach_function :__zmsg_popstr, :zmsg_popstr, [:pointer], :pointer
|
139
|
+
|
140
|
+
# NOTE: zmsg_wrap will take ownership of zframe and destroy it at the end
|
141
|
+
attach_function :zmsg_wrap, [:pointer, :pointer], :void
|
142
|
+
attach_function :zmsg_unwrap, [:pointer], :pointer
|
143
|
+
# NOTE: zmsg_remove will simply remove the zframe without destroying it
|
144
|
+
attach_function :zmsg_remove, [:pointer, :pointer], :void
|
145
|
+
attach_function :zmsg_first, [:pointer], :pointer
|
146
|
+
attach_function :zmsg_next, [:pointer], :pointer
|
147
|
+
attach_function :zmsg_last, [:pointer], :pointer
|
148
|
+
|
149
|
+
# TODO: implement zmsg_encode and zmsg_decode?
|
150
|
+
|
151
|
+
attach_function :zmsg_dup, [:pointer], :pointer
|
152
|
+
attach_function :zmsg_dump, [:pointer], :void
|
153
|
+
|
154
|
+
# These are very low-level functions. Still unsure whether czmq-ffi should provide them.
|
155
|
+
# attach_function :zmsg_save, [:pointer, :pointer], :int
|
156
|
+
# attach_function :zmsg_load, [:pointer, :pointer], :pointer
|
157
|
+
# attach_function :zmsg_dump_to_stream, [:pointer, :pointer], :void
|
158
|
+
|
159
|
+
# NOTE: zmsg_add is deprecated. No point in supporting it.
|
160
|
+
# attach_function :zmsg_add, [:pointer, :pointer], :int
|
161
|
+
|
162
|
+
def self.zmsg_destroy(zmsg)
|
163
|
+
zmsg_ptr = FFI::MemoryPointer.new(:pointer)
|
164
|
+
zmsg_ptr.write_pointer(zmsg)
|
165
|
+
__zmsg_destroy(zmsg_ptr)
|
166
|
+
end
|
167
|
+
|
168
|
+
def self.zmsg_send(zmsg, zsocket)
|
169
|
+
zmsg_ptr = FFI::MemoryPointer.new(:pointer)
|
170
|
+
zmsg_ptr.write_pointer(zmsg)
|
171
|
+
__zmsg_send(zmsg_ptr, zsocket)
|
172
|
+
end
|
173
|
+
|
174
|
+
# zmsg will take ownership of zframe and destroy it at the end
|
175
|
+
def self.zmsg_append(zmsg, zframe)
|
176
|
+
zframe_ptr = FFI::MemoryPointer.new(:pointer)
|
177
|
+
zframe_ptr.write_pointer(zframe)
|
178
|
+
__zmsg_append(zmsg, zframe_ptr)
|
179
|
+
end
|
180
|
+
|
181
|
+
def self.zmsg_pushmem(zmsg, byte_array)
|
182
|
+
rc = nil
|
183
|
+
FFI::MemoryPointer.new(:uint8, byte_array.size) do |p|
|
184
|
+
p.write_array_of_int8(byte_array)
|
185
|
+
rc = __zmsg_pushmem(zmsg, p, byte_array.size)
|
186
|
+
end
|
187
|
+
rc
|
188
|
+
end
|
189
|
+
|
190
|
+
def self.zmsg_addmem(zmsg, byte_array)
|
191
|
+
rc = nil
|
192
|
+
FFI::MemoryPointer.new(:uint8, byte_array.size) do |p|
|
193
|
+
p.write_array_of_int8(byte_array)
|
194
|
+
rc = __zmsg_addmem(zmsg, p, byte_array.size)
|
195
|
+
end
|
196
|
+
rc
|
197
|
+
end
|
198
|
+
|
199
|
+
def self.zmsg_popstr(zmsg)
|
200
|
+
Utils.extract_string(__zmsg_popstr(zmsg))
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
##################################################
|
205
|
+
# zframe-related functions
|
206
|
+
##################################################
|
207
|
+
attach_function :__zframe_new, :zframe_new, [:buffer_in, :size_t], :pointer
|
208
|
+
attach_function :__zframe_new_empty, :zframe_new_empty, [], :pointer
|
209
|
+
attach_function :__zframe_destroy, :zframe_destroy, [:pointer], :void
|
210
|
+
attach_function :zframe_recv, [:pointer], :pointer
|
211
|
+
attach_function :zframe_recv_nowait, [:pointer], :pointer
|
212
|
+
attach_function :__zframe_send, :zframe_send, [:pointer, :pointer, :int], :int
|
213
|
+
attach_function :zframe_size, [:pointer], :size_t
|
214
|
+
attach_function :zframe_dup, [:pointer], :pointer
|
215
|
+
attach_function :__zframe_strhex, :zframe_strhex, [:pointer], :pointer
|
216
|
+
attach_function :__zframe_strdup, :zframe_strdup, [:pointer], :pointer
|
217
|
+
attach_function :zframe_streq, [:pointer, :string], :bool
|
218
|
+
attach_function :zframe_more, [:pointer], :int
|
219
|
+
attach_function :zframe_set_more, [:pointer, :int], :void
|
220
|
+
attach_function :zframe_eq, [:pointer, :pointer], :bool
|
221
|
+
attach_function :zframe_reset, [:pointer, :buffer_in, :size_t], :void
|
222
|
+
|
223
|
+
# These are very low-level functions. Still unsure whether czmq-ffi should provide them.
|
224
|
+
# attach_function :zframe_data, [:pointer], :pointer
|
225
|
+
# attach_function :zframe_fprint, [:pointer, :string, :pointer], :void
|
226
|
+
# attach_function :zframe_print, [:pointer, :string], :void
|
227
|
+
|
228
|
+
def self.zframe_new(byte_array=nil)
|
229
|
+
if byte_array.nil?
|
230
|
+
__zframe_new_empty
|
231
|
+
else
|
232
|
+
zframe = nil
|
233
|
+
FFI::MemoryPointer.new(:uint8, byte_array.size) do |p|
|
234
|
+
p.write_array_of_int8(byte_array)
|
235
|
+
zframe = __zframe_new(p, byte_array.size)
|
236
|
+
end
|
237
|
+
zframe
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def self.zframe_destroy(zframe)
|
242
|
+
zframe_ptr = FFI::MemoryPointer.new(:pointer)
|
243
|
+
zframe_ptr.write_pointer(zframe)
|
244
|
+
__zframe_destroy(zframe_ptr)
|
245
|
+
end
|
246
|
+
|
247
|
+
def self.zframe_send(zframe, zsocket, flags)
|
248
|
+
zframe_ptr = FFI::MemoryPointer.new(:pointer)
|
249
|
+
zframe_ptr.write_pointer(zframe)
|
250
|
+
__zframe_send(zframe_ptr, zsocket, flags)
|
251
|
+
end
|
252
|
+
|
253
|
+
def self.zframe_strhex(zframe)
|
254
|
+
Utils.extract_string(__zframe_strhex(zframe))
|
255
|
+
end
|
256
|
+
|
257
|
+
def self.zframe_strdup(zframe)
|
258
|
+
Utils.extract_string(__zframe_strdup(zframe))
|
259
|
+
end
|
260
|
+
|
261
|
+
|
262
|
+
##################################################
|
263
|
+
# zpoller-related functions
|
264
|
+
##################################################
|
265
|
+
attach_function :zpoller_new, [:pointer, :varargs], :pointer
|
266
|
+
attach_function :__zpoller_destroy, :zpoller_destroy, [:pointer], :void
|
267
|
+
attach_function :zpoller_wait, [:pointer, :int], :pointer
|
268
|
+
attach_function :zpoller_expired, [:pointer], :bool
|
269
|
+
attach_function :zpoller_terminated, [:pointer], :bool
|
270
|
+
|
271
|
+
def self.zpoller_destroy(zpoller)
|
272
|
+
zpoller_ptr = FFI::MemoryPointer.new(:pointer)
|
273
|
+
zpoller_ptr.write_pointer(zpoller)
|
274
|
+
__zpoller_destroy(zpoller_ptr)
|
275
|
+
end
|
276
|
+
|
277
|
+
|
278
|
+
##################################################
|
279
|
+
# zloop-related functions
|
280
|
+
##################################################
|
281
|
+
attach_function :zloop_new, [], :pointer
|
282
|
+
attach_function :__zloop_destroy, :zloop_destroy, [:pointer], :void
|
283
|
+
callback :zloop_callback, [:pointer, :pointer, :pointer], :int
|
284
|
+
attach_function :zloop_poller, [:pointer, :pointer, :zloop_callback, :pointer], :int
|
285
|
+
attach_function :zloop_poller_end, [:pointer, :pointer], :void
|
286
|
+
attach_function :zloop_set_tolerant, [:pointer, :pointer], :void
|
287
|
+
callback :zloop_timer_callback, [:pointer, :int, :pointer], :int
|
288
|
+
attach_function :zloop_timer, [:pointer, :size_t, :size_t, :zloop_timer_callback, :pointer], :int
|
289
|
+
attach_function :zloop_timer_end, [:pointer, :pointer], :int
|
290
|
+
attach_function :zloop_set_verbose, [:pointer, :bool], :void
|
291
|
+
attach_function :zloop_start, [:pointer], :int
|
292
|
+
|
293
|
+
def self.zloop_destroy(zloop)
|
294
|
+
zloop_ptr = FFI::MemoryPointer.new(:pointer)
|
295
|
+
zloop_ptr.write_pointer(zloop)
|
296
|
+
__zloop_destroy(zloop_ptr)
|
297
|
+
end
|
298
|
+
|
299
|
+
def self.create_zloop_callback(func)
|
300
|
+
FFI::Function.new(:int, [:pointer, :pointer, :pointer]) do |zloopbuf, zpollitembuf, arg|
|
301
|
+
func.call(zloopbuf, zpollitembuf, arg)
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'czmq-ffi/constants'
|
3
|
+
|
4
|
+
module LibCZMQ
|
5
|
+
|
6
|
+
class ZPollItem < FFI::Struct
|
7
|
+
FD_TYPE = if FFI::Platform::IS_WINDOWS && FFI::Platform::ADDRESS_SIZE == 64
|
8
|
+
# On Windows, zmq.h defines fd as a SOCKET, which is 64 bits on x64.
|
9
|
+
:uint64
|
10
|
+
else
|
11
|
+
:int
|
12
|
+
end
|
13
|
+
|
14
|
+
layout :socket, :pointer,
|
15
|
+
:fd, FD_TYPE,
|
16
|
+
:events, :short,
|
17
|
+
:revents, :short
|
18
|
+
|
19
|
+
def readable?
|
20
|
+
(self[:revents] & CZMQ::POLLIN) > 0
|
21
|
+
end
|
22
|
+
|
23
|
+
def writable?
|
24
|
+
(self[:revents] & CZMQ::POLLOUT) > 0
|
25
|
+
end
|
26
|
+
|
27
|
+
def inspect
|
28
|
+
"socket [#{self[:socket]}], fd [#{self[:fd]}], events [#{self[:events]}], revents [#{self[:revents]}]"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.create_pollitem(args={})
|
33
|
+
pi = ZPollItem.new
|
34
|
+
pi[:socket] = args[:socket]
|
35
|
+
pi[:fd] = args[:fd] || 0
|
36
|
+
pi[:events] = args[:events] || 0
|
37
|
+
pi[:revents] = args[:revents] || 0
|
38
|
+
pi
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'czmq-ffi/libc'
|
2
|
+
|
3
|
+
module Utils
|
4
|
+
def self.extract_string(ffi_str_pointer)
|
5
|
+
# Make sure we don't try to extract a string from a NULL pointer.
|
6
|
+
return nil if ffi_str_pointer.null? # || ffi_str_pointer.nil?
|
7
|
+
|
8
|
+
# Read the string pointed by ffi_str_pointer.
|
9
|
+
str = ffi_str_pointer.read_string
|
10
|
+
|
11
|
+
# The read_string method (actually, the str_new C function nested
|
12
|
+
# inside it) makes a deep copy, so we can safely free ffi_str_pointer.
|
13
|
+
LibC.free(ffi_str_pointer)
|
14
|
+
|
15
|
+
# Return the string we extracted from ffi_str_pointer.
|
16
|
+
str
|
17
|
+
end
|
18
|
+
end
|
data/test/test_helper.rb
ADDED
data/test/zframe_test.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe LibCZMQ do
|
4
|
+
|
5
|
+
describe 'zframe' do
|
6
|
+
|
7
|
+
it 'should be able to create empty zframes' do
|
8
|
+
zframe = LibCZMQ.zframe_new
|
9
|
+
LibCZMQ.zframe_size(zframe).must_equal 0
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should be able to create zframes from an (int) array' do
|
13
|
+
zframe = LibCZMQ.zframe_new([ 1, 2, 3, 4, 5, 6 ])
|
14
|
+
LibCZMQ.zframe_size(zframe).must_equal 6
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-czmq-ffi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mauro Tortonesi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '1.3'
|
25
|
+
prerelease: false
|
26
|
+
type: :development
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
prerelease: false
|
40
|
+
type: :development
|
41
|
+
description: FFI-based Ruby bindings for the CZMQ library
|
42
|
+
email:
|
43
|
+
- mauro.tortonesi@unife.it
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- czmq-ffi.gemspec
|
54
|
+
- lib/czmq-ffi.rb
|
55
|
+
- lib/czmq-ffi/constants.rb
|
56
|
+
- lib/czmq-ffi/libc.rb
|
57
|
+
- lib/czmq-ffi/libczmq.rb
|
58
|
+
- lib/czmq-ffi/structures.rb
|
59
|
+
- lib/czmq-ffi/utils.rb
|
60
|
+
- lib/czmq-ffi/version.rb
|
61
|
+
- test/test_helper.rb
|
62
|
+
- test/zframe_test.rb
|
63
|
+
homepage: https://github.com/mtortonesi/ruby-czmq-ffi
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.2.1
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: This gem provides low-level bindings for the CZMQ library, using FFI. It is not meant to be used directly by applications, but instead to provide functions for higher-level gems such as ruby-czmq.
|
87
|
+
test_files:
|
88
|
+
- test/test_helper.rb
|
89
|
+
- test/zframe_test.rb
|