ffi-czmq 0.0.9.pre → 0.1.1.pre

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
  SHA1:
3
- metadata.gz: 6d7bc5dbfbbab88b01da91de2d64910c29d5230e
4
- data.tar.gz: 996a30caf32c11dd341ecda967bcfdb1a44766dd
3
+ metadata.gz: c194cff3d41eae0f11f28592e0f941af8202e66c
4
+ data.tar.gz: ba4b758beb7306b357ac680f61b9ee2ba778468f
5
5
  SHA512:
6
- metadata.gz: 0247ce7e0940e2ab8661e98935a8bcc780c7362bfa6a8878db03c21aa84e542230f3679f3d6d730aedf2b78a3c502348b34371e4a0433e6500ee7025af219b6a
7
- data.tar.gz: 15a1dc2f33b43609b1657773ed649848530ab6e8d76cc8fafeca0d378ede15b054a2250a7f64631d6130d7232cc7010b4b081cbc46352493b51dedf9b51d3062
6
+ metadata.gz: 6789dc075cc8cc874b6035187e5db349c34fc92dec5ce60400658e0f59c4e9f36aedfce79fc4a0f3d548216bf4e4bd8e2337a67fcb00feb08cba99922189418b
7
+ data.tar.gz: 1394af326de53f42e345d6d92515ab82b59c2ad24c04038987c1a7c5142a868388165607167426336a3f5c02f1bb09eea3d7d4af22c787e16bb34e51d57ccae4
data/LICENSE CHANGED
@@ -175,17 +175,6 @@ Apache License
175
175
 
176
176
  END OF TERMS AND CONDITIONS
177
177
 
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "{}"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
178
  Copyright 2014 Hendrik Beskow
190
179
 
191
180
  Licensed under the Apache License, Version 2.0 (the "License");
data/lib/czmq/utils.rb CHANGED
@@ -9,20 +9,20 @@ module CZMQ
9
9
 
10
10
  attach_function :zmq_version, :zmq_version, [:buffer_in, :buffer_in, :buffer_in], :void, blocking: true
11
11
  attach_function :zsys_version, :zsys_version, [:buffer_in, :buffer_in, :buffer_in], :void, blocking: true
12
- attach_function :errno, :zmq_errno, [], :int, blocking: true
13
- attach_function :strerror, :zmq_strerror, [:int], :string, blocking: true
12
+ attach_function :errno, :zmq_errno, [], :int
13
+ attach_function :strerror, :zmq_strerror, [:int], :string
14
14
 
15
15
  module_function
16
16
 
17
17
  def version
18
18
  unless @version
19
- z_major = FFI::MemoryPointer.new :int
20
- z_minor = FFI::MemoryPointer.new :int
21
- z_patch = FFI::MemoryPointer.new :int
19
+ z_major = FFI::MemoryPointer.new :pointer
20
+ z_minor = FFI::MemoryPointer.new :pointer
21
+ z_patch = FFI::MemoryPointer.new :pointer
22
22
 
23
- c_major = FFI::MemoryPointer.new :int
24
- c_minor = FFI::MemoryPointer.new :int
25
- c_patch = FFI::MemoryPointer.new :int
23
+ c_major = FFI::MemoryPointer.new :pointer
24
+ c_minor = FFI::MemoryPointer.new :pointer
25
+ c_patch = FFI::MemoryPointer.new :pointer
26
26
 
27
27
  zmq_version z_major, z_minor, z_patch
28
28
  zsys_version c_major, c_minor, c_patch
@@ -54,8 +54,6 @@ module CZMQ
54
54
 
55
55
  if version[:czmq][:major] < 3
56
56
  fail LoadError, 'This needs at least czmq 3'
57
- else
58
- attach_function :has_curve, :zsys_has_curve, [], :bool, blocking: true
59
57
  end
60
58
  end
61
59
  end
data/lib/czmq/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CZMQ
2
- VERSION = Gem::Version.new('0.0.9.pre')
2
+ VERSION = Gem::Version.new('0.1.1.pre')
3
3
  end
data/lib/czmq/zactor.rb CHANGED
@@ -13,14 +13,13 @@ module CZMQ
13
13
  czmq_function :resolve, :resolve, [:pointer], :pointer
14
14
  attach_function :zauth, :zauth, [:pointer, :pointer], :void, blocking: true
15
15
  attach_function :zbeacon, :zbeacon, [:pointer, :pointer], :void, blocking: true
16
- attach_function :zgossip, :zgossip, [:pointer, :pointer], :void, blocking: true
16
+ attach_function :zgossip, :zgossip, [:pointer, :string], :void, blocking: true
17
17
  attach_function :zmonitor, :zmonitor, [:pointer, :pointer], :void, blocking: true
18
18
  attach_function :zproxy, :zproxy, [:pointer, :pointer], :void, blocking: true
19
19
 
20
20
  def self.new_actor(&actor)
21
21
  zactor_fn = FFI::Function.new(:void, [:pointer, :pointer], blocking: true) do |zsock_t, args|
22
- child_pipe = Zsock.new_from_czmq_obj(zsock_t, nil)
23
- actor.call(child_pipe)
22
+ yield Zsock.new_from_czmq_obj(zsock_t, nil)
24
23
  end
25
24
 
26
25
  new(zactor_fn, nil)
@@ -28,30 +27,24 @@ module CZMQ
28
27
 
29
28
  [:zauth, :zbeacon, :zproxy].each do |meth|
30
29
  instance_eval <<-RUBY, __FILE__, __LINE__
31
- def new_#{meth.to_s}
32
- zactor_fn = FFI::Function.new(:void, [:pointer, :pointer], blocking: true) do |zsock_t, args|
33
- #{meth.to_s}(zsock_t, args)
34
- end
30
+ const_set("#{meth.to_s.upcase}", FFI::Function.new(:void, [:pointer, :pointer], blocking: true) {|zsock_t, args| #{meth.to_s}(zsock_t, args)})
35
31
 
36
- new(zactor_fn, nil)
32
+ def new_#{meth.to_s}
33
+ new(#{meth.to_s.upcase}, nil)
37
34
  end
38
35
  RUBY
39
36
  end
40
37
 
41
- def self.new_zmonitor(sock)
42
- zactor_fn = FFI::Function.new(:void, [:pointer, :pointer], blocking: true) do |zsock_t, args|
43
- zmonitor(zsock_t, args)
44
- end
38
+ ZMONITOR = FFI::Function.new(:void, [:pointer, :pointer], blocking: true) {|zsock_t, args| zmonitor(zsock_t, args)}
45
39
 
46
- new(zactor_fn, Zsock.convert(sock))
40
+ def self.new_zmonitor(sock)
41
+ new(ZMONITOR, Zsock.convert(sock))
47
42
  end
48
43
 
49
- def self.new_zgossip(logprefix)
50
- zactor_fn = FFI::Function.new(:void, [:pointer, :string], blocking: true) do |zsock_t, args|
51
- zgossip(zsock_t, args)
52
- end
44
+ ZGOSSIP = FFI::Function.new(:void, [:pointer, :string], blocking: true) {|zsock_t, args| zgossip(zsock_t, args)}
53
45
 
54
- new(zactor_fn, logprefix)
46
+ def self.new_zgossip(logprefix)
47
+ new(ZGOSSIP, logprefix)
55
48
  end
56
49
 
57
50
  def tell(*msgs)
data/lib/czmq/zcert.rb CHANGED
@@ -1,56 +1,54 @@
1
1
  require_relative 'utils'
2
2
  require_relative 'libczmq'
3
3
 
4
- if CZMQ::Utils.has_curve
5
- module CZMQ
6
- class Zcert
7
- extend ::LibCZMQ
8
-
9
- czmq_constructor
10
- czmq_destructor
11
-
12
- czmq_function :public_txt, :public_txt, [:pointer], :string
13
- czmq_function :secret_txt, :secret_txt, [:pointer], :string
14
- czmq_function :load_zcert, :load, [:string], :pointer
15
- czmq_function :save, :save, [:pointer, :string], :int
16
- czmq_function :save_public, :save_public, [:pointer, :string], :int
17
- czmq_function :save_secret, :save_secret, [:pointer, :string], :int
18
- czmq_function :apply, :apply, [:pointer, :pointer], :void
19
- czmq_function :dup_zcert, :dup, [:pointer], :pointer
20
- czmq_function :eq, :eq, [:pointer, :pointer], :bool
21
-
22
- def self.convert(cert)
23
- if Utils.check_for_pointer(cert)
24
-
25
- return cert
26
- elsif cert.respond_to?(:to_zcert) &&
27
- Utils.check_for_pointer(cert.to_zcert)
28
-
29
- return cert.to_zcert
30
- else
31
- fail ArgumentError, "#{cert.class} is not a CZMQ::Zcert", caller
32
- end
4
+ module CZMQ
5
+ class Zcert
6
+ extend ::LibCZMQ
7
+
8
+ czmq_constructor
9
+ czmq_destructor
10
+
11
+ czmq_function :public_txt, :public_txt, [:pointer], :string
12
+ czmq_function :secret_txt, :secret_txt, [:pointer], :string
13
+ czmq_function :load_zcert, :load, [:string], :pointer
14
+ czmq_function :save, :save, [:pointer, :string], :int
15
+ czmq_function :save_public, :save_public, [:pointer, :string], :int
16
+ czmq_function :save_secret, :save_secret, [:pointer, :string], :int
17
+ czmq_function :apply, :apply, [:pointer, :pointer], :void
18
+ czmq_function :dup_zcert, :dup, [:pointer], :pointer
19
+ czmq_function :eq, :eq, [:pointer, :pointer], :bool
20
+
21
+ def self.convert(cert)
22
+ if Utils.check_for_pointer(cert)
23
+
24
+ return cert
25
+ elsif cert.respond_to?(:to_zcert) &&
26
+ Utils.check_for_pointer(cert.to_zcert)
27
+
28
+ return cert.to_zcert
29
+ else
30
+ fail ArgumentError, "#{cert.class} is not a CZMQ::Zcert", caller
33
31
  end
32
+ end
34
33
 
35
- def self.load(filename)
36
- unless (zcert = load_zcert(filename)).null?
37
- new_from_czmq_obj(zcert)
38
- else
39
- fail IOError, Utils.error, caller
40
- end
34
+ def self.load(filename)
35
+ unless (zcert = load_zcert(filename)).null?
36
+ new_from_czmq_obj(zcert)
37
+ else
38
+ fail IOError, Utils.error, caller
41
39
  end
40
+ end
42
41
 
43
- def dup
44
- self.class.new_from_czmq_obj(dup_zcert)
45
- end
42
+ def dup
43
+ self.class.new_from_czmq_obj(dup_zcert)
44
+ end
46
45
 
47
- def ==(other)
48
- eq(self.class.convert(other))
49
- end
46
+ def ==(other)
47
+ (object_id == other.object_id ||eq(self.class.convert(other)))
48
+ end
50
49
 
51
- def !=(other)
52
- ! self.==(other)
53
- end
50
+ def !=(other)
51
+ ! self.==(other)
54
52
  end
55
53
  end
56
54
  end
@@ -1,16 +1,14 @@
1
1
  require_relative 'utils'
2
2
  require_relative 'libczmq'
3
3
 
4
- if CZMQ::Utils.has_curve
5
- module CZMQ
6
- class Zcertstore
7
- extend ::LibCZMQ
4
+ module CZMQ
5
+ class Zcertstore
6
+ extend ::LibCZMQ
8
7
 
9
- czmq_constructor [:string]
10
- czmq_destructor
8
+ czmq_constructor [:string]
9
+ czmq_destructor
11
10
 
12
- czmq_function :lookup, :lookup, [:pointer, :string], :pointer
13
- czmq_function :insert_zcert, :insert, [:pointer, :pointer], :void
14
- end
11
+ czmq_function :lookup, :lookup, [:pointer, :string], :pointer
12
+ czmq_function :insert_zcert, :insert, [:pointer, :pointer], :void
15
13
  end
16
14
  end
@@ -0,0 +1,30 @@
1
+ require_relative 'libczmq'
2
+ require_relative 'zstr'
3
+
4
+ module CZMQ
5
+ class Zclock
6
+ extend ::LibCZMQ
7
+
8
+ czmq_function :sleep, :sleep, [:int], :void
9
+ czmq_function :time, :time, [], :int64
10
+ czmq_function :mono, :mono, [], :int64
11
+ czmq_function :usecs, :usecs, [], :int64
12
+ czmq_function :timestr, :timestr, [], :pointer
13
+
14
+ def self.time_str
15
+ Zstr.read_string(timestr)
16
+ end
17
+
18
+ def self.test(verbose = false)
19
+ start = Zclock.time
20
+ Zclock.sleep 10
21
+ raise unless (Zclock.time - start) >= 10
22
+ start = Zclock.mono
23
+ usecs = Zclock.usecs
24
+ Zclock.sleep 10
25
+ raise unless (Zclock.mono - start) >= 10
26
+ raise unless (Zclock.usecs - usecs) >= 10000
27
+ puts time_str if verbose
28
+ end
29
+ end
30
+ end
data/lib/czmq/zconfig.rb CHANGED
@@ -44,7 +44,7 @@ module CZMQ
44
44
  def execute(&block)
45
45
  zconfig_fct = FFI::Function.new(:int, [:pointer, :pointer, :int], blocking: true) do |zconfig_t, args, level|
46
46
  zconfig = self.class.new_from_czmq_obj(zconfig_t, nil)
47
- block.call(zconfig, level)
47
+ yield zconfig, level
48
48
  end
49
49
 
50
50
  execute_zconfig(zconfig_fct, nil)
data/lib/czmq/zframe.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require_relative 'libczmq'
2
2
  require_relative 'utils'
3
+ require_relative 'zstr'
3
4
  require_relative 'zsock'
4
5
 
5
6
  module CZMQ
@@ -20,8 +21,10 @@ module CZMQ
20
21
  czmq_function :size, :size, [:pointer], :size_t
21
22
  czmq_function :data, :data, [:pointer], :pointer
22
23
  czmq_function :dup_zframe, :dup, [:pointer], :pointer
23
- czmq_function :more, :more, [:pointer], :int
24
- czmq_function :set_more, :set_more, [:pointer, :int], :void
24
+ czmq_function :strhex, :strhex, [:pointer], :pointer
25
+ czmq_function :strdup, :strdup, [:pointer], :pointer
26
+ czmq_function :more, :more, [:pointer], :bool
27
+ czmq_function :set_more, :set_more, [:pointer, :bool], :void
25
28
  czmq_function :eq, :eq, [:pointer, :pointer], :bool
26
29
  czmq_function :reset, :reset, [:pointer, :buffer_in, :size_t], :void
27
30
  czmq_function :print, :print, [:pointer, :string], :void
@@ -51,8 +54,16 @@ module CZMQ
51
54
  self.class.new_from_czmq_obj(dup_zframe)
52
55
  end
53
56
 
57
+ def str_hex
58
+ Zstr.read_string(strhex)
59
+ end
60
+
61
+ def str_dup
62
+ Zstr.read_string(strdup)
63
+ end
64
+
54
65
  def more?
55
- more & MORE > 0
66
+ more
56
67
  end
57
68
 
58
69
  def <=>(other)
@@ -0,0 +1,25 @@
1
+ require_relative 'zsys'
2
+
3
+ module CZMQ
4
+ class Zlogger
5
+ def fatal(message)
6
+ Zsys.error(message)
7
+ end
8
+
9
+ def error(message)
10
+ Zsys.warning(message)
11
+ end
12
+
13
+ def warn(message)
14
+ Zsys.notice(message)
15
+ end
16
+
17
+ def info(message)
18
+ Zsys.info(message)
19
+ end
20
+
21
+ def debug(message)
22
+ Zsys.debug(message)
23
+ end
24
+ end
25
+ end
data/lib/czmq/zloop.rb CHANGED
@@ -17,37 +17,36 @@ module CZMQ
17
17
  czmq_function :start, :start, [:pointer], :int
18
18
 
19
19
  def initialize
20
- @reader_callbacks = []
21
- @timer_callbacks = []
20
+ @reader_callbacks = {}
21
+ @timer_callbacks = {}
22
22
  end
23
23
 
24
24
  def add_reader(zsock, &block)
25
25
  zloop_reader_fn = FFI::Function.new(:int, [:pointer, :pointer, :pointer], blocking: true) do |zloop_t, zsock_t, args|
26
- zsocky = Zsock.new_from_czmq_obj(zsock_t, nil)
27
- block.call(zsocky)
26
+ yield Zsock.new_from_czmq_obj(zsock_t, nil)
28
27
  end
29
28
 
30
29
  reader(Zsock.convert(zsock), zloop_reader_fn, nil)
31
- @reader_callbacks << {zsock: zsock, zloop_reader_fn: zloop_reader_fn, block: block}
30
+ @reader_callbacks[zloop_reader_fn] = zsock
32
31
  end
33
32
 
34
33
  def remove_reader(zsock)
35
- @reader_callbacks.delete_if {|reader| reader[:zsock] == zsock}
34
+ @reader_callbacks.delete_if {|reader, sock| sock == zsock}
36
35
  reader_end(Zsock.convert(zsock))
37
36
  end
38
37
 
39
38
  def add_timer(delay, times, &block)
40
39
  zloop_timer_fn = FFI::Function.new(:int, [:pointer, :int, :pointer], blocking: true) do |zloop_t, timer_id, args|
41
- block.call(timer_id)
40
+ yield timer_id
42
41
  end
43
42
 
44
43
  timer_id = timer(delay, times, zloop_timer_fn, nil)
45
- @timer_callbacks << {timer_id: timer_id, delay: delay, times: times, zloop_timer_fn: zloop_timer_fn, block: block}
44
+ @timer_callbacks[timer_id] = zloop_timer_fn
46
45
  timer_id
47
46
  end
48
47
 
49
48
  def remove_timer(timer_id)
50
- @timer_callbacks.delete_if {|timer| timer[:timer_id] == timer_id}
49
+ @timer_callbacks.delete(timer_id)
51
50
  timer_end(timer_id)
52
51
  end
53
52
  end
data/lib/czmq/zmsg.rb CHANGED
@@ -54,7 +54,7 @@ module CZMQ
54
54
  when Zframe
55
55
  append_zframe(data)
56
56
  when String
57
- add_string(data)
57
+ add_mem(data, data.bytesize)
58
58
  when Fixnum
59
59
  add_zstrf(INTF, :ssize_t, data)
60
60
  when NilClass
@@ -71,7 +71,7 @@ module CZMQ
71
71
 
72
72
  add_mem(data.data, data.size)
73
73
  elsif data.respond_to?(:to_str)
74
- add_string(data.to_str)
74
+ add_mem(data.to_str, data.to_str.bytesize)
75
75
  elsif data.nil?
76
76
  add_mem(nil, 0)
77
77
  else
@@ -90,7 +90,7 @@ module CZMQ
90
90
  when Zframe
91
91
  prepend_zframe(data)
92
92
  when String
93
- push_string(data)
93
+ push_mem(data, data.bytesize)
94
94
  when Fixnum
95
95
  push_zstrf(INTF, :ssize_t, data)
96
96
  when NilClass
@@ -107,7 +107,7 @@ module CZMQ
107
107
 
108
108
  push_mem(data.data, data.size)
109
109
  elsif data.respond_to?(:to_str)
110
- push_string(data.to_str)
110
+ push_mem(data.to_str, data.to_str.bytesize)
111
111
  elsif data.nil?
112
112
  push_mem(nil, 0)
113
113
  else
@@ -165,23 +165,5 @@ module CZMQ
165
165
  def self.decode(bytes)
166
166
  new_from_czmq_obj(decode_zmsg(bytes, bytes.bytesize))
167
167
  end
168
-
169
- private
170
-
171
- def add_string(string)
172
- if string.encoding == Encoding::ASCII_8BIT
173
- add_mem(string, string.size)
174
- else
175
- add_zstr(string)
176
- end
177
- end
178
-
179
- def push_string(string)
180
- if string.encoding == Encoding::ASCII_8BIT
181
- push_mem(string, string.size)
182
- else
183
- push_zstr(string)
184
- end
185
- end
186
168
  end
187
169
  end
data/lib/czmq/zpoller.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  require_relative 'libczmq'
2
+ require_relative 'zsock'
2
3
 
3
4
  module CZMQ
4
5
  class Zpoller
5
6
  extend ::LibCZMQ
6
7
 
7
- czmq_constructor [:pointer, :varargs]
8
+ czmq_constructor [:varargs]
8
9
  czmq_destructor
9
10
 
10
11
  czmq_function :add, :add, [:pointer, :pointer], :int
@@ -20,12 +21,11 @@ module CZMQ
20
21
 
21
22
  zsocks = []
22
23
  pollitems.each do |pollitem|
24
+ zsocks << :pointer
23
25
  zsocks << Zsock.convert(pollitem)
24
26
  end
25
27
 
26
- first_sock = zsocks.delete(zsocks.first)
27
- other_socks = ([ :pointer ] * zsocks.size).zip(zsocks).flatten
28
- new(first_sock, *other_socks, :pointer, nil)
28
+ new(*zsocks, :pointer, nil)
29
29
  end
30
30
  end
31
31
  end
data/lib/czmq/zsock.rb CHANGED
@@ -42,9 +42,9 @@ module CZMQ
42
42
 
43
43
  [:rep, :router, :pull, :pub, :xpub].each do |meth|
44
44
  instance_eval <<-RUBY, __FILE__, __LINE__
45
- def new_#{meth.to_s}(endpoints)
46
- sock = new(#{meth.inspect}, endpoints)
47
- sock.attach(endpoints, true)
45
+ def new_#{meth.to_s}(endpoint)
46
+ sock = new(#{meth.inspect}, endpoint)
47
+ sock.attach(endpoint, true)
48
48
  sock
49
49
  end
50
50
  RUBY
@@ -52,20 +52,18 @@ module CZMQ
52
52
 
53
53
  [:req, :dealer, :push, :xsub, :pair, :stream].each do |meth|
54
54
  instance_eval <<-RUBY, __FILE__, __LINE__
55
- def new_#{meth.to_s}(endpoints)
56
- sock = new(#{meth.inspect}, endpoints)
57
- sock.attach(endpoints, false)
55
+ def new_#{meth.to_s}(endpoint)
56
+ sock = new(#{meth.inspect}, endpoint)
57
+ sock.attach(endpoint, false)
58
58
  sock
59
59
  end
60
60
  RUBY
61
61
  end
62
62
 
63
- def self.new_sub(endpoints, *subscriptions)
64
- sock = new(:sub, endpoints, *subscriptions)
65
- sock.attach(endpoints, false)
66
- subscriptions.each do |subscription|
67
- sock.set_subscribe(subscription)
68
- end
63
+ def self.new_sub(endpoint, subscribe = nil)
64
+ sock = new(:sub, endpoint)
65
+ sock.attach(endpoint, false)
66
+ sock.set_subscribe(subscribe) if subscribe
69
67
  sock
70
68
  end
71
69
 
data/lib/czmq/zstr.rb CHANGED
@@ -15,15 +15,11 @@ module CZMQ
15
15
 
16
16
  class << self
17
17
  def read_string(str_ptr)
18
- if Utils.check_for_pointer(str_ptr)
19
- str = str_ptr.read_string
20
- free_ptr = FFI::MemoryPointer.new(:pointer)
21
- free_ptr.write_pointer(str_ptr)
22
- free(free_ptr)
23
- str
24
- else
25
- fail ArgumentError, "#{str_ptr.class} is not a FFI::Pointer", caller
26
- end
18
+ str = str_ptr.get_string(0)
19
+ free_ptr = FFI::MemoryPointer.new(:pointer)
20
+ free_ptr.write_pointer(str_ptr)
21
+ free(free_ptr)
22
+ str
27
23
  end
28
24
 
29
25
  def recv(socket)
@@ -31,7 +27,7 @@ module CZMQ
31
27
  end
32
28
 
33
29
  def sendx(socket, string, *strings)
34
- if strings.size == 0
30
+ if strings.size.zero?
35
31
  fail ArgumentError, "Wrong number of Arguments, (2 for 3..n)", caller
36
32
  end
37
33
 
@@ -55,7 +51,7 @@ module CZMQ
55
51
 
56
52
  strings = []
57
53
  buffers.select {|buffer| buffer != :buffer_out}.each do |buffer|
58
- strings << buffer.read_pointer.read_string
54
+ strings << buffer.read_pointer.get_string(0)
59
55
  free(buffer)
60
56
  end
61
57
  strings
data/lib/czmq/zsys.rb CHANGED
@@ -16,7 +16,7 @@ module CZMQ
16
16
  czmq_function :set_rcvhwm, :set_rcvhwm, [:size_t], :void
17
17
  czmq_function :set_pipehwm, :set_pipehwm, [:size_t], :void
18
18
  czmq_function :pipehwm, :pipehwm, [], :size_t
19
- czmq_function :set_ipv6, :set_ipv6, [:int], :void
19
+ czmq_function :set_ipv6, :set_ipv6, [:bool], :void
20
20
  czmq_function :set_interface, :set_interface, [:string], :void
21
21
  czmq_function :set_logident, :set_logident, [:string], :void
22
22
  czmq_function :set_logstream, :set_logstream, [:pointer], :void
@@ -27,15 +27,16 @@ module CZMQ
27
27
  czmq_function :notice, :notice, [:string], :void
28
28
  czmq_function :info, :info, [:string], :void
29
29
  czmq_function :debug, :debug, [:string], :void
30
+ czmq_function :has_curve, :has_curve, [], :bool
30
31
 
31
- attach_variable :interrupted, :zsys_interrupted, :int
32
- attach_variable :zctx_interrupted, :zctx_interrupted, :int
32
+ attach_variable :interrupted, :zsys_interrupted, :bool
33
+ attach_variable :zctx_interrupted, :zctx_interrupted, :bool
34
+ attach_variable :allocs, :zsys_allocs, :uint64
33
35
 
34
36
  handler_set(nil)
35
- set_ipv6(1)
36
37
 
37
38
  at_exit do
38
- zctx_interrupted = interrupted = 1
39
+ zctx_interrupted = interrupted = true
39
40
  end
40
41
  end
41
42
  end
data/lib/czmq.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require_relative 'czmq/utils'
2
2
  require_relative 'czmq/libczmq'
3
3
  require_relative 'czmq/zsys'
4
+ require_relative 'czmq/zlogger'
4
5
  require_relative 'czmq/zframe'
5
6
  require_relative 'czmq/zmsg'
6
7
  require_relative 'czmq/zsock'
@@ -12,3 +13,4 @@ require_relative 'czmq/zcertstore'
12
13
  require_relative 'czmq/ziflist'
13
14
  require_relative 'czmq/zconfig'
14
15
  require_relative 'czmq/zstr'
16
+ require_relative 'czmq/zclock'
data/lib/ffi-czmq.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require_relative 'czmq/utils'
2
2
  require_relative 'czmq/libczmq'
3
3
  require_relative 'czmq/zsys'
4
+ require_relative 'czmq/zlogger'
4
5
  require_relative 'czmq/zframe'
5
6
  require_relative 'czmq/zmsg'
6
7
  require_relative 'czmq/zsock'
@@ -12,3 +13,4 @@ require_relative 'czmq/zcertstore'
12
13
  require_relative 'czmq/ziflist'
13
14
  require_relative 'czmq/zconfig'
14
15
  require_relative 'czmq/zstr'
16
+ require_relative 'czmq/zclock'
data/lib/libzmq.rb ADDED
@@ -0,0 +1,47 @@
1
+ require 'ffi'
2
+
3
+ module Libzmq
4
+ extend FFI::Library
5
+ ffi_lib :libzmq, FFI::Library::LIBC
6
+
7
+ POLLIN = 1
8
+ POLLOUT = 2
9
+ POLLERR = 4
10
+ POLLPRI = 8
11
+
12
+ class PollItem < FFI::Struct
13
+ FD_TYPE = (FFI::Platform.windows? && FFI::Platform::ADDRESS_SIZE == 64) ? :uint64 : :int
14
+
15
+ layout :socket, :pointer,
16
+ :fd, FD_TYPE,
17
+ :events, :short,
18
+ :revents, :short
19
+
20
+ def readable?
21
+ (self[:revents] & POLLIN) > 0
22
+ end
23
+
24
+ def writable?
25
+ (self[:revents] & POLLOUT) > 0
26
+ end
27
+
28
+ def error?
29
+ (self[:revents] & POLLERR) > 0
30
+ end
31
+ end
32
+
33
+ attach_function :memmove, [:pointer, :pointer, :size_t], :pointer
34
+ attach_function :poll, :zmq_poll, [:pointer, :int, :long], :int, blocking: true
35
+
36
+ class PollItems < Array
37
+ def to_ptr
38
+ items_pointer = FFI::MemoryPointer.new(PollItem, size, true)
39
+ offset = 0
40
+ each do |item|
41
+ Libzmq.memmove(items_pointer + offset, item, item.size)
42
+ offset += item.size
43
+ end
44
+ items_pointer
45
+ end
46
+ end
47
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-czmq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9.pre
4
+ version: 0.1.1.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hendrik
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-13 00:00:00.000000000 Z
12
+ date: 2014-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -17,28 +17,28 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 1.9.5
20
+ version: 1.9.6
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 1.9.5
27
+ version: 1.9.6
28
28
  - !ruby/object:Gem::Dependency
29
- name: bundler
29
+ name: rspec
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '1.7'
34
+ version: 3.1.0
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '1.7'
41
+ version: 3.1.0
42
42
  description: czmq ffi wrapper
43
43
  email:
44
44
  executables: []
@@ -55,9 +55,11 @@ files:
55
55
  - lib/czmq/zactor.rb
56
56
  - lib/czmq/zcert.rb
57
57
  - lib/czmq/zcertstore.rb
58
+ - lib/czmq/zclock.rb
58
59
  - lib/czmq/zconfig.rb
59
60
  - lib/czmq/zframe.rb
60
61
  - lib/czmq/ziflist.rb
62
+ - lib/czmq/zlogger.rb
61
63
  - lib/czmq/zloop.rb
62
64
  - lib/czmq/zmsg.rb
63
65
  - lib/czmq/zpoller.rb
@@ -65,6 +67,7 @@ files:
65
67
  - lib/czmq/zstr.rb
66
68
  - lib/czmq/zsys.rb
67
69
  - lib/ffi-czmq.rb
70
+ - lib/libzmq.rb
68
71
  homepage: https://github.com/Asmod4n/ruby-ffi-czmq
69
72
  licenses:
70
73
  - Apache-2.0