nn-core 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aec634c40b00d3f8dc8301ee40777c9943d069d6
4
- data.tar.gz: 23b6f3ea3d5327711e0f1ba2ec971f9f904d4d2f
3
+ metadata.gz: 691df12ac377ed030b7fd74b5b54d6b9b3becb98
4
+ data.tar.gz: 3f5b4557cd9539120cb7ee980e8c878b6ea03de4
5
5
  SHA512:
6
- metadata.gz: 171ba1be554febe2101e3253094c722e9124f1da03b870427a7e062b470ab1f9eb955f22e0387e1081bb9ef9ef7fed402321de1172b068213276455a40d753ea
7
- data.tar.gz: 7e969d818f3044048f9721250cb15a9cc5c1682cefbea62e322f7e3f31b2f04bbc3192611a475aec0b0390c95c4bc7c67e3e21ac3117006fb7d3bc24dd62af77
6
+ metadata.gz: 8d304d2c2b4945a9795557621aba3350854c19b4f69aa96bacd9bb204006a9fc169cc599079913d81a2b0fb3ed506e03487e2c4f2f7606ff31e111f424458eeb
7
+ data.tar.gz: 4ba0fa436aea595eb065bf941d591579e040e57bb64729dfe857df99bb67e517cec8ce7488867f21a87986b6964ff65dd8d8fe5b803b3802b1a37d7b7b063bb3
data/.rspec CHANGED
@@ -1,4 +1,4 @@
1
1
  --color
2
2
  --format documentation
3
3
  --backtrace
4
- --default_path spec
4
+ --default-path spec
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.1
6
+ - jruby-head
7
+ - rbx-2
8
+ script: bundle exec rspec spec
9
+ matrix:
10
+ allow_failures:
11
+ before_install:
12
+ - git clone git://github.com/nanomsg/nanomsg.git
13
+ - cd nanomsg && ./autogen.sh && ./configure && sudo make install && sudo ldconfig && cd ${TRAVIS_BUILD_DIR}
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
data/History.txt CHANGED
@@ -1,3 +1,12 @@
1
+ 20140219 / 0.3.0
2
+ * Support nn_poll function for checking socket reading/writing availability
3
+
4
+ * Support nn_symbol_info function
5
+
6
+ * Support reallocmsg function for reallocating messages previously allocated by nn_allocmsg
7
+
8
+ * Support nn_device for messages forwarding between two sockets
9
+
1
10
  20130327 / 0.2.0
2
11
  * Support nn_symbol function for setting up all constants in the binding.
3
12
 
@@ -30,4 +39,4 @@
30
39
  20130204 / 0.1.0
31
40
  * Initial release. Wrapped the nanomsg library as of commit
32
41
  5ded934af0.
33
-
42
+
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  nn-core
2
2
  -------
3
3
 
4
+ [![Build Status](https://travis-ci.org/chuckremes/nn-core.svg?branch=master)](https://travis-ci.org/chuckremes/nn-core)
5
+
4
6
  nn-core is a very thin FFI wrapper around the nanomsg library. The intention is to provide a very
5
7
  simple wrapper that hews as close to the C API as possible. Other gems that want to offer a more
6
8
  idiomatic API for Ruby should require this gem and build a nice Ruby API with it.
@@ -2,8 +2,8 @@ module NNCore
2
2
 
3
3
  # To simplify management of constants in language bindings that cannot
4
4
  # parse or directly utilize a C header file, the library provides the
5
- # nn_symbol function. This function returns a string and an integer
6
- # value so that bindings authors can easily setup all constants and
5
+ # nn_symbol function. This function returns a string and an integer
6
+ # value so that bindings authors can easily setup all constants and
7
7
  # their values without worrying about copy/paste or transcription
8
8
  # errors every time the underlying library is changed.
9
9
  #
@@ -20,7 +20,7 @@ module NNCore
20
20
  const_set(constant_string, value.read_int)
21
21
  index += 1
22
22
  end
23
-
23
+
24
24
  # This constant is not exported by nn_symbol. It is also of type size_t.
25
25
  NN_MSG = -1
26
26
  end
@@ -2,7 +2,7 @@
2
2
  module NNCore
3
3
  module LibNanomsg
4
4
  extend FFI::Library
5
-
5
+
6
6
  begin
7
7
  # bias the library discovery to a path inside the gem first, then
8
8
  # to the usual system paths
@@ -34,12 +34,13 @@ module NNCore
34
34
  find_type(:size_t) rescue typedef(:ulong, :size_t)
35
35
 
36
36
  attach_function :nn_symbol, [:int, :pointer], :string, :blocking => true
37
-
37
+ attach_function :nn_symbol_info, [:int, :pointer, :int], :int, :blocking => true
38
+
38
39
  attach_function :nn_errno, [], :int, :blocking => true
39
40
  attach_function :nn_strerror, [:int], :string, :blocking => true
40
41
  attach_function :nn_socket, [:int, :int], :int, :blocking => true
41
42
  attach_function :nn_close, [:int], :int, :blocking => true
42
-
43
+
43
44
  attach_function :nn_getsockopt, [:int, :int, :int, :pointer, :pointer], :int, :blocking => true
44
45
  attach_function :nn_setsockopt, [:int, :int, :int, :pointer, :size_t], :int, :blocking => true
45
46
  attach_function :nn_bind, [:int, :string], :int, :blocking => true
@@ -48,11 +49,15 @@ module NNCore
48
49
  attach_function :nn_send, [:int, :pointer, :size_t, :int], :int, :blocking => true
49
50
  attach_function :nn_recv, [:int, :pointer, :size_t, :int], :int, :blocking => true
50
51
  attach_function :nn_term, [], :void, :blocking => true
52
+ attach_function :nn_device, [:int, :int], :int, :blocking => true
53
+
54
+ attach_function :nn_poll, [:pointer, :int, :int], :int, :blocking => true
51
55
 
52
56
  # functions for working with raw buffers
53
57
  attach_function :nn_sendmsg, [:int, :pointer, :int], :int, :blocking => true
54
58
  attach_function :nn_recvmsg, [:int, :pointer, :int], :int, :blocking => true
55
59
  attach_function :nn_allocmsg, [:size_t, :int], :pointer, :blocking => true
60
+ attach_function :nn_reallocmsg, [:pointer, :size_t], :pointer, :blocking => true
56
61
  attach_function :nn_freemsg, [:pointer], :int, :blocking => true
57
62
  end
58
63
  end
@@ -1,7 +1,6 @@
1
-
2
1
  module NNCore
3
2
  module LibNanomsg
4
-
3
+
5
4
  # Structs for working with raw buffers (not recommended)
6
5
  module NNIOVecLayout
7
6
  def self.included(base)
@@ -14,24 +13,24 @@ module NNCore
14
13
 
15
14
  class NNIOVec < FFI::Struct
16
15
  include NNIOVecLayout
17
-
16
+
18
17
  def iov_base
19
18
  self[:iov_base]
20
19
  end
21
-
20
+
22
21
  def iov_base=(pointer)
23
22
  self[:iov_base] = pointer
24
23
  end
25
-
24
+
26
25
  def iov_len
27
26
  self[:iov_len]
28
27
  end
29
-
28
+
30
29
  def iov_len=(length)
31
30
  self[:iov_len] = length
32
31
  end
33
32
  end
34
-
33
+
35
34
  module NNMsgHdrLayout
36
35
  def self.included(base)
37
36
  base.class_eval do
@@ -42,43 +41,43 @@ module NNCore
42
41
  end
43
42
  end
44
43
  end
45
-
44
+
46
45
  class NNMsgHdr < FFI::Struct
47
46
  include NNMsgHdrLayout
48
-
47
+
49
48
  def msg_iov
50
49
  self[:msg_iov]
51
50
  end
52
-
51
+
53
52
  def msg_iov=(structure)
54
53
  self[:msg_iov] = structure
55
54
  end
56
-
55
+
57
56
  def msg_iovlen
58
57
  self[:msg_iovlen]
59
58
  end
60
-
59
+
61
60
  def msg_iovlen=(length)
62
61
  self[:msg_iovlen] = length
63
62
  end
64
-
63
+
65
64
  def msg_control
66
65
  self[:msg_control]
67
66
  end
68
-
67
+
69
68
  def msg_control=(pointer)
70
69
  self[:msg_control] = pointer
71
70
  end
72
-
71
+
73
72
  def msg_controllen
74
73
  self[:msg_controllen]
75
74
  end
76
-
75
+
77
76
  def msg_controllen=(value)
78
77
  self[:msg_controllen] = value
79
78
  end
80
79
  end
81
-
80
+
82
81
  module NNCMsgHdrLayout
83
82
  def self.included(base)
84
83
  base.class_eval do
@@ -88,34 +87,110 @@ module NNCore
88
87
  end
89
88
  end
90
89
  end
91
-
90
+
92
91
  class NNCMsgHdr < FFI::Struct
93
92
  include NNCMsgHdrLayout
94
-
93
+
95
94
  def cmsg_len
96
95
  self[:cmsg_len]
97
96
  end
98
-
97
+
99
98
  def cmsg_len=(length)
100
99
  self[:csmg_len] = length
101
100
  end
102
-
101
+
103
102
  def cmsg_level
104
103
  self[:cmsg_level]
105
104
  end
106
-
105
+
107
106
  def cmsg_level=(level)
108
107
  self[:cmsg_level] = level
109
108
  end
110
-
109
+
111
110
  def cmsg_type
112
111
  self[:cmsg_type]
113
112
  end
114
-
113
+
115
114
  def cmsg_type=(type)
116
115
  self[:cmsg_type] = type
117
116
  end
118
117
  end
119
-
118
+
119
+ module NNPollFdLayout
120
+ def self.included(base)
121
+ base.class_eval do
122
+ layout :fd, :int,
123
+ :events, :short,
124
+ :revents, :short
125
+ end
126
+ end
127
+ end
128
+
129
+ # Struct for nn_poll
130
+ class NNPollFd < FFI::Struct
131
+ include NNPollFdLayout
132
+
133
+ def fd
134
+ self[:fd]
135
+ end
136
+
137
+ def fd=(socket)
138
+ self[:fd] = socket
139
+ end
140
+
141
+ def events
142
+ self[:events]
143
+ end
144
+
145
+ def events=(value)
146
+ self[:events] = value
147
+ end
148
+
149
+ def revents
150
+ self[:revents]
151
+ end
152
+
153
+ def revents=(value)
154
+ self[:revents] = value
155
+ end
156
+ end
157
+
158
+ # Struct for nn_symbol_info return values
159
+ module NNSymbolPropertiesLayout
160
+ def self.included(base)
161
+ base.class_eval do
162
+ layout :value, :int,
163
+ :name, :string,
164
+ :ns, :int,
165
+ :type, :int,
166
+ :unit, :int
167
+ end
168
+ end
169
+ end
170
+
171
+ class NNSymbolProperties < FFI::Struct
172
+ include NNSymbolPropertiesLayout
173
+
174
+ def value
175
+ self[:value]
176
+ end
177
+
178
+ def name
179
+ self[:name]
180
+ end
181
+
182
+ def ns
183
+ self[:ns]
184
+ end
185
+
186
+ def type
187
+ self[:type]
188
+ end
189
+
190
+ def unit
191
+ self[:unit]
192
+ end
193
+ end
194
+
120
195
  end
121
196
  end
@@ -1,3 +1,3 @@
1
1
  module NNCore
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
data/nn-core.gemspec CHANGED
@@ -21,6 +21,6 @@ to build an API using Ruby idioms.}
21
21
  s.require_paths = ["lib"]
22
22
 
23
23
  s.add_runtime_dependency "ffi"
24
- s.add_development_dependency "rspec", ["~> 2.6"]
24
+ s.add_development_dependency "rspec", ["~> 3.2"]
25
25
  s.add_development_dependency "rake"
26
26
  end
data/spec/nn_bind_spec.rb CHANGED
@@ -16,84 +16,85 @@ module NNCore
16
16
 
17
17
  it "returns a non-zero endpoint number for a valid INPROC address" do
18
18
  rc = LibNanomsg.nn_bind(@socket, "inproc://some_address")
19
- rc.should > 0
19
+ expect(rc).to be > 0
20
20
  end
21
21
 
22
22
  it "returns a non-zero endpoint number for a valid IPC address" do
23
23
  rc = LibNanomsg.nn_bind(@socket, "ipc:///tmp/some_address")
24
- rc.should > 0
24
+ expect(rc).to be > 0
25
25
  end
26
26
 
27
27
  it "returns a non-zero endpoint number for a valid TCP address" do
28
28
  rc = LibNanomsg.nn_bind(@socket, "tcp://127.0.0.1:5555")
29
- rc.should > 0
29
+ expect(rc).to be > 0
30
30
  end
31
31
 
32
32
  it "returns -1 for an invalid INPROC address" do
33
33
  rc = LibNanomsg.nn_bind(@socket, "inproc:/missing_first_slash")
34
- rc.should == -1
35
- LibNanomsg.nn_errno.should == EINVAL
34
+ errno = LibNanomsg.nn_errno
35
+ expect(rc).to eq(-1)
36
+ expect(errno).to eq(EINVAL)
36
37
  end
37
38
 
38
39
  it "returns -1 for an invalid INPROC address (too long)" do
39
40
  rc = LibNanomsg.nn_bind(@socket, "inproc://#{'a' * (NN_SOCKADDR_MAX + 1)}")
40
- rc.should == -1
41
- LibNanomsg.nn_errno.should == ENAMETOOLONG
41
+ expect(rc).to eq(-1)
42
+ expect(LibNanomsg.nn_errno).to eq(ENAMETOOLONG)
42
43
  end
43
44
 
44
45
  it "returns -1 for an invalid IPC address" do
45
46
  rc = LibNanomsg.nn_bind(@socket, "ipc:/missing_slashes)")
46
- rc.should == -1
47
- LibNanomsg.nn_errno.should == EINVAL
47
+ expect(rc).to eq(-1)
48
+ expect(LibNanomsg.nn_errno).to eq(EINVAL)
48
49
  end
49
50
 
50
51
  it "returns -1 for an invalid TCP address (missing address)" do
51
52
  rc = LibNanomsg.nn_bind(@socket, "tcp://")
52
- rc.should == -1
53
- LibNanomsg.nn_errno.should == EINVAL
53
+ expect(rc).to eq(-1)
54
+ expect(LibNanomsg.nn_errno).to eq(EINVAL)
54
55
  end
55
56
 
56
57
  it "returns -1 for an invalid TCP address (non-numeric port)" do
57
58
  rc = LibNanomsg.nn_bind(@socket, "tcp://192.168.0.1:port")
58
- rc.should == -1
59
- LibNanomsg.nn_errno.should == EINVAL
59
+ expect(rc).to eq(-1)
60
+ expect(LibNanomsg.nn_errno).to eq(EINVAL)
60
61
  end
61
62
 
62
63
  it "returns -1 for an invalid TCP address (port number is out of range)" do
63
64
  rc = LibNanomsg.nn_bind(@socket, "tcp://192.168.0.1:65536")
64
- rc.should == -1
65
- LibNanomsg.nn_errno.should == EINVAL
65
+ expect(rc).to eq(-1)
66
+ expect(LibNanomsg.nn_errno).to eq(EINVAL)
66
67
  end
67
68
 
68
69
  it "returns -1 for an unsupported transport protocol" do
69
70
  rc = LibNanomsg.nn_bind(@socket, "zmq://192.168.0.1:65536")
70
- rc.should == -1
71
- LibNanomsg.nn_errno.should == EPROTONOSUPPORT
71
+ expect(rc).to eq(-1)
72
+ expect(LibNanomsg.nn_errno).to eq(EPROTONOSUPPORT)
72
73
  end
73
74
 
74
75
  it "returns -1 for specifying a non-existent device using TCP transport" do
75
76
  rc = LibNanomsg.nn_bind(@socket, "tcp://eth5:5555")
76
- rc.should == -1
77
- LibNanomsg.nn_errno.should == ENODEV
77
+ expect(rc).to eq(-1)
78
+ expect(LibNanomsg.nn_errno).to eq(ENODEV)
78
79
  end
79
80
 
80
81
  it "returns -1 when binding to an existing endpoint" do
81
82
  rc = LibNanomsg.nn_bind(@socket, "inproc://some_endpoint")
82
83
  rc = LibNanomsg.nn_bind(@socket, "inproc://some_endpoint")
83
- rc.should == -1
84
- LibNanomsg.nn_errno.should == EADDRINUSE
84
+ expect(rc).to eq(-1)
85
+ expect(LibNanomsg.nn_errno).to eq(EADDRINUSE)
85
86
  end
86
-
87
+
87
88
  end
88
89
 
89
90
  context "given an invalid file descriptor" do
90
-
91
+
91
92
  it "returns -1 and sets nn_errno to EBADF" do
92
93
  rc = LibNanomsg.nn_bind(0, "inproc://some_endpoint")
93
- rc.should == -1
94
- LibNanomsg.nn_errno.should == EBADF
94
+ expect(rc).to eq(-1)
95
+ expect(LibNanomsg.nn_errno).to eq(EBADF)
95
96
  end
96
-
97
+
97
98
  end
98
99
 
99
100
  end
@@ -9,7 +9,7 @@ module NNCore
9
9
  before(:each) { @socket = LibNanomsg.nn_socket(AF_SP, NN_PUB) }
10
10
 
11
11
  it "returns 0" do
12
- LibNanomsg.nn_close(@socket).should be_zero
12
+ expect(LibNanomsg.nn_close(@socket)).to be_zero
13
13
  end
14
14
 
15
15
  end
@@ -17,8 +17,8 @@ module NNCore
17
17
  context "given an invalid file descriptor" do
18
18
 
19
19
  it "returns -1 and sets nn_errno to EBADF" do
20
- LibNanomsg.nn_close(0).should == -1
21
- LibNanomsg.nn_errno.should == EBADF
20
+ expect(LibNanomsg.nn_close(0)).to eq(-1)
21
+ expect(LibNanomsg.nn_errno).to eq(EBADF)
22
22
  end
23
23
 
24
24
  end
@@ -22,77 +22,77 @@ module NNCore
22
22
 
23
23
  it "returns a non-zero endpoint number for a valid INPROC address" do
24
24
  rc = LibNanomsg.nn_connect(@socket, "inproc://some_address")
25
- rc.should > 0
25
+ expect(rc).to be > 0
26
26
  end
27
27
 
28
28
  it "returns a non-zero endpoint number for a valid IPC address" do
29
29
  rc = LibNanomsg.nn_connect(@socket, "ipc:///tmp/some_address")
30
- rc.should > 0
30
+ expect(rc).to be > 0
31
31
  end
32
32
 
33
33
  it "returns a non-zero endpoint number for a valid TCP address" do
34
34
  rc = LibNanomsg.nn_connect(@socket, "tcp://127.0.0.1:5555")
35
- rc.should > 0
35
+ expect(rc).to be > 0
36
36
  end
37
37
 
38
38
  it "returns -1 for an invalid INPROC address" do
39
39
  rc = LibNanomsg.nn_connect(@socket, "inproc:/missing_first_slash")
40
- rc.should == -1
41
- LibNanomsg.nn_errno.should == EINVAL
40
+ expect(rc).to eq(-1)
41
+ expect(LibNanomsg.nn_errno).to eq(EINVAL)
42
42
  end
43
43
 
44
44
  it "returns -1 for an invalid INPROC address (too long)" do
45
45
  rc = LibNanomsg.nn_connect(@socket, "inproc://#{'a' * (NN_SOCKADDR_MAX + 1)}")
46
- rc.should == -1
47
- LibNanomsg.nn_errno.should == ENAMETOOLONG
46
+ expect(rc).to eq(-1)
47
+ expect(LibNanomsg.nn_errno).to eq(ENAMETOOLONG)
48
48
  end
49
49
 
50
50
  it "returns -1 for an invalid IPC address" do
51
51
  rc = LibNanomsg.nn_connect(@socket, "ipc:/missing_slashes)")
52
- rc.should == -1
53
- LibNanomsg.nn_errno.should == EINVAL
52
+ expect(rc).to eq(-1)
53
+ expect(LibNanomsg.nn_errno).to eq(EINVAL)
54
54
  end
55
55
 
56
56
  it "returns -1 for an invalid TCP address (missing port)" do
57
57
  rc = LibNanomsg.nn_connect(@socket, "tcp://*:")
58
- rc.should == -1
59
- LibNanomsg.nn_errno.should == EINVAL
58
+ expect(rc).to eq(-1)
59
+ expect(LibNanomsg.nn_errno).to eq(EINVAL)
60
60
  end
61
61
 
62
62
  it "returns -1 for an invalid TCP address (non-numeric port)" do
63
63
  rc = LibNanomsg.nn_connect(@socket, "tcp://192.168.0.1:port")
64
- rc.should == -1
65
- LibNanomsg.nn_errno.should == EINVAL
64
+ expect(rc).to eq(-1)
65
+ expect(LibNanomsg.nn_errno).to eq(EINVAL)
66
66
  end
67
67
 
68
68
  it "returns -1 for an invalid TCP address (port number is out of range)" do
69
69
  rc = LibNanomsg.nn_connect(@socket, "tcp://192.168.0.1:65536")
70
- rc.should == -1
71
- LibNanomsg.nn_errno.should == EINVAL
70
+ expect(rc).to eq(-1)
71
+ expect(LibNanomsg.nn_errno).to eq(EINVAL)
72
72
  end
73
73
 
74
74
  it "returns -1 for an unsupported transport protocol" do
75
75
  rc = LibNanomsg.nn_connect(@socket, "zmq://192.168.0.1:65536")
76
- rc.should == -1
77
- LibNanomsg.nn_errno.should == EPROTONOSUPPORT
76
+ expect(rc).to eq(-1)
77
+ expect(LibNanomsg.nn_errno).to eq(EPROTONOSUPPORT)
78
78
  end
79
79
 
80
80
  it "returns 2 when connecting twice to an existing endpoint" do
81
81
  rc = LibNanomsg.nn_connect(@socket, "inproc://some_endpoint")
82
82
  rc = LibNanomsg.nn_connect(@socket, "inproc://some_endpoint")
83
- rc.should == 2
83
+ expect(rc).to eq(2)
84
84
  end
85
-
85
+
86
86
  end
87
87
 
88
88
  context "given an invalid file descriptor" do
89
-
89
+
90
90
  it "returns -1 and sets nn_errno to EBADF" do
91
91
  rc = LibNanomsg.nn_connect(0, "inproc://some_endpoint")
92
- rc.should == -1
93
- LibNanomsg.nn_errno.should == EBADF
92
+ expect(rc).to eq(-1)
93
+ expect(LibNanomsg.nn_errno).to eq(EBADF)
94
94
  end
95
-
95
+
96
96
  end
97
97
 
98
98
  end
@@ -19,50 +19,50 @@ module NNCore
19
19
 
20
20
  it "NN_LINGER returns a default of 1000" do
21
21
  rc = LibNanomsg.nn_getsockopt(@socket, NN_SOL_SOCKET, NN_LINGER, @option, @size)
22
- rc.should == 0
23
- @option.read_int.should == 1000
22
+ expect(rc).to eq(0)
23
+ expect(@option.read_int).to eq(1000)
24
24
  end
25
25
 
26
26
  it "NN_SNDBUF returns a default of 128KB" do
27
27
  rc = LibNanomsg.nn_getsockopt(@socket, NN_SOL_SOCKET, NN_SNDBUF, @option, @size)
28
- rc.should == 0
29
- @option.read_int.should == 131072
28
+ expect(rc).to eq(0)
29
+ expect(@option.read_int).to eq(131072)
30
30
  end
31
31
 
32
32
  it "NN_RCVBUF returns a default of 128KB" do
33
33
  rc = LibNanomsg.nn_getsockopt(@socket, NN_SOL_SOCKET, NN_RCVBUF, @option, @size)
34
- rc.should == 0
35
- @option.read_int.should == 131072
34
+ expect(rc).to eq(0)
35
+ expect(@option.read_int).to eq(131072)
36
36
  end
37
37
 
38
38
  it "NN_SNDTIMEO returns a default of -1" do
39
39
  rc = LibNanomsg.nn_getsockopt(@socket, NN_SOL_SOCKET, NN_SNDTIMEO, @option, @size)
40
- rc.should == 0
41
- @option.read_int.should == -1
40
+ expect(rc).to eq(0)
41
+ expect(@option.read_int).to eq(-1)
42
42
  end
43
43
 
44
44
  it "NN_RCVTIMEO returns a default of -1" do
45
45
  rc = LibNanomsg.nn_getsockopt(@socket, NN_SOL_SOCKET, NN_RCVTIMEO, @option, @size)
46
- rc.should == 0
47
- @option.read_int.should == -1
46
+ expect(rc).to eq(0)
47
+ expect(@option.read_int).to eq(-1)
48
48
  end
49
49
 
50
50
  it "NN_RECONNECT_IVL returns a default of 100 (units are milliseconds)" do
51
51
  rc = LibNanomsg.nn_getsockopt(@socket, NN_SOL_SOCKET, NN_RECONNECT_IVL, @option, @size)
52
- rc.should == 0
53
- @option.read_int.should == 100
52
+ expect(rc).to eq(0)
53
+ expect(@option.read_int).to eq(100)
54
54
  end
55
55
 
56
56
  it "NN_RECONNECT_IVL_MAX returns a default of 0 (units are milliseconds)" do
57
57
  rc = LibNanomsg.nn_getsockopt(@socket, NN_SOL_SOCKET, NN_RECONNECT_IVL_MAX, @option, @size)
58
- rc.should == 0
59
- @option.read_int.should == 0
58
+ expect(rc).to eq(0)
59
+ expect(@option.read_int).to eq(0)
60
60
  end
61
61
 
62
62
  it "NN_SNDPRIO returns a default of 8" do
63
63
  rc = LibNanomsg.nn_getsockopt(@socket, NN_SOL_SOCKET, NN_SNDPRIO, @option, @size)
64
- rc.should == 0
65
- @option.read_int.should == 8
64
+ expect(rc).to eq(0)
65
+ expect(@option.read_int).to eq(8)
66
66
  end
67
67
 
68
68
 
@@ -75,8 +75,8 @@ module NNCore
75
75
  size.write_int(4)
76
76
 
77
77
  rc = LibNanomsg.nn_getsockopt(@socket, 100, SOCKET_OPTIONS[socket_option], option, size)
78
- rc.should == -1
79
- LibNanomsg.nn_errno.should == ENOPROTOOPT
78
+ expect(rc).to eq(-1)
79
+ expect(LibNanomsg.nn_errno).to eq(ENOPROTOOPT)
80
80
  end
81
81
  end
82
82
 
@@ -93,8 +93,8 @@ module NNCore
93
93
  size.write_int(4)
94
94
 
95
95
  rc = LibNanomsg.nn_getsockopt(0, NN_SOL_SOCKET, SOCKET_OPTIONS[socket_option], option, size)
96
- rc.should == -1
97
- LibNanomsg.nn_errno.should == EBADF
96
+ expect(rc).to eq(-1)
97
+ expect(LibNanomsg.nn_errno).to eq(EBADF)
98
98
  end
99
99
  end
100
100
  end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ module NNCore
4
+ describe "nn_poll" do
5
+
6
+ context "given an initialized library and" do
7
+
8
+ context "given a valid socket" do
9
+ before(:each) do
10
+ @socket = LibNanomsg.nn_socket(AF_SP, NN_PUB)
11
+ @endpoint = LibNanomsg.nn_bind(@socket, "inproc://some_endpoint")
12
+ end
13
+
14
+ after(:each) do
15
+ LibNanomsg.nn_close(@socket)
16
+ end
17
+
18
+ it "returns a non-zero number of signaled events" do
19
+ pointer = FFI::MemoryPointer.new(NNCore::LibNanomsg::NNPollFd, 1)
20
+ struct = NNCore::LibNanomsg::NNPollFd.new(pointer)
21
+ struct.fd = @socket
22
+ struct.events = 2
23
+ result = LibNanomsg.nn_poll(pointer, 1, 1000)
24
+
25
+ expect(result).to be > 0
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
32
+ end
data/spec/nn_recv_spec.rb CHANGED
@@ -23,27 +23,27 @@ module NNCore
23
23
  it "returns the number of bytes received" do
24
24
  string = "ABC"
25
25
  LibNanomsg.nn_send(@sender, string, string.size, 0)
26
-
26
+
27
27
  buffer = FFI::MemoryPointer.new(5)
28
28
  nbytes = LibNanomsg.nn_recv(@socket, buffer, 5, 0)
29
- nbytes.should == 3
30
- buffer.read_string.should == string
29
+ expect(nbytes).to eq(3)
30
+ expect(buffer.read_string).to eq(string)
31
31
  end
32
32
  end
33
-
33
+
34
34
  context "given no pre-allocated buffer" do
35
35
 
36
36
  it "returns the number of bytes received and returns the buffer" do
37
37
  string = "ABC"
38
38
  LibNanomsg.nn_send(@sender, string, string.size, 0)
39
-
39
+
40
40
  buffer = FFI::MemoryPointer.new(:pointer)
41
41
  nbytes = LibNanomsg.nn_recv(@socket, buffer, NN_MSG, 0)
42
- nbytes.should == 3
43
-
42
+ expect(nbytes).to eq(3)
43
+
44
44
  # important to pass +nbytes+ to #read_string since the sent string
45
45
  # is not null-terminated
46
- buffer.get_pointer(0).read_string(nbytes).should == string
46
+ expect(buffer.get_pointer(0).read_string(nbytes)).to eq(string)
47
47
  end
48
48
  end
49
49
  end
@@ -52,8 +52,8 @@ module NNCore
52
52
 
53
53
  it "returns -1 and sets nn_errno to EBADF" do
54
54
  rc = LibNanomsg.nn_send(0, "ABC", 3, 0)
55
- rc.should == -1
56
- LibNanomsg.nn_errno.should == EBADF
55
+ expect(rc).to eq(-1)
56
+ expect(LibNanomsg.nn_errno).to eq(EBADF)
57
57
  end
58
58
 
59
59
  end
data/spec/nn_send_spec.rb CHANGED
@@ -21,14 +21,14 @@ module NNCore
21
21
 
22
22
  it "returns the number of bytes sent" do
23
23
  nbytes = LibNanomsg.nn_send(@socket, "ABC", 3, 0)
24
- nbytes.should == 3
24
+ expect(nbytes).to eq(3)
25
25
  end
26
26
  end
27
27
 
28
28
  context "disconnected from all endpoints" do
29
29
  it "returns the number of bytes queued" do
30
30
  nbytes = LibNanomsg.nn_send(@socket, "ABC", 3, 0)
31
- nbytes.should == 3
31
+ expect(nbytes).to eq(3)
32
32
  end
33
33
  end
34
34
  end
@@ -37,8 +37,8 @@ module NNCore
37
37
 
38
38
  it "returns -1 and sets nn_errno to EBADF" do
39
39
  rc = LibNanomsg.nn_send(0, "ABC", 3, 0)
40
- rc.should == -1
41
- LibNanomsg.nn_errno.should == EBADF
40
+ expect(rc).to eq(-1)
41
+ expect(LibNanomsg.nn_errno).to eq(EBADF)
42
42
  end
43
43
 
44
44
  end
@@ -22,11 +22,11 @@ module NNCore
22
22
  it "#{socket_option} overrides the default" do
23
23
  @option.write_int(10)
24
24
  rc = LibNanomsg.nn_setsockopt(@socket, NN_SOL_SOCKET, SOCKET_OPTIONS[socket_option], @option, 4)
25
- rc.should == 0
25
+ expect(rc).to eq(0)
26
26
  rc = LibNanomsg.nn_getsockopt(@socket, NN_SOL_SOCKET, SOCKET_OPTIONS[socket_option], @option, @size)
27
- rc.should == 0
27
+ expect(rc).to eq(0)
28
28
 
29
- @option.read_int.should == 10
29
+ expect(@option.read_int).to eq(10)
30
30
  end
31
31
  end
32
32
 
@@ -38,8 +38,8 @@ module NNCore
38
38
  option = FFI::MemoryPointer.new(:int32)
39
39
 
40
40
  rc = LibNanomsg.nn_setsockopt(@socket, 100, SOCKET_OPTIONS[socket_option], option, 4)
41
- rc.should == -1
42
- LibNanomsg.nn_errno.should == ENOPROTOOPT
41
+ expect(rc).to eq(-1)
42
+ expect(LibNanomsg.nn_errno).to eq(ENOPROTOOPT)
43
43
  end
44
44
  end
45
45
 
@@ -56,8 +56,8 @@ module NNCore
56
56
  size.write_int(4)
57
57
 
58
58
  rc = LibNanomsg.nn_getsockopt(0, NN_SOL_SOCKET, SOCKET_OPTIONS[socket_option], option, size)
59
- rc.should == -1
60
- LibNanomsg.nn_errno.should == EBADF
59
+ expect(rc).to eq(-1)
60
+ expect(LibNanomsg.nn_errno).to eq(EBADF)
61
61
  end
62
62
  end
63
63
  end
@@ -21,15 +21,15 @@ module NNCore
21
21
 
22
22
  it "returns 0" do
23
23
  rc = LibNanomsg.nn_shutdown(@socket, @endpoint)
24
- rc.should == 0
24
+ expect(rc).to eq(0)
25
25
  end
26
26
  end
27
27
 
28
28
  context "given an invalid endpoint" do
29
29
  it "returns -1 and set nn_errno to EINVAL" do
30
30
  rc = LibNanomsg.nn_shutdown(@socket, 0)
31
- rc.should == -1
32
- LibNanomsg.nn_errno.should == EINVAL
31
+ expect(rc).to eq(-1)
32
+ expect(LibNanomsg.nn_errno).to eq(EINVAL)
33
33
  end
34
34
  end
35
35
  end
@@ -38,8 +38,8 @@ module NNCore
38
38
 
39
39
  it "returns -1 and sets nn_errno to EBADF" do
40
40
  rc = LibNanomsg.nn_shutdown(0, 0)
41
- rc.should == -1
42
- LibNanomsg.nn_errno.should == EBADF
41
+ expect(rc).to eq(-1)
42
+ expect(LibNanomsg.nn_errno).to eq(EBADF)
43
43
  end
44
44
 
45
45
  end
@@ -12,7 +12,7 @@ module NNCore
12
12
  it "returns a non-zero file descriptor for the socket" do
13
13
  @socket = LibNanomsg.nn_socket(AF_SP, PROTOCOLS[protocol])
14
14
 
15
- @socket.should == 0
15
+ expect(@socket).to eq(0)
16
16
 
17
17
  LibNanomsg.nn_close(@socket)
18
18
  end
@@ -24,8 +24,8 @@ module NNCore
24
24
  it "returns -1 and sets nn_errno to EINVAL" do
25
25
  @socket = LibNanomsg.nn_socket(AF_SP_RAW, PROTOCOLS[protocol])
26
26
 
27
- @socket.should == -1
28
- LibNanomsg.nn_errno.should == EINVAL
27
+ expect(@socket).to eq(-1)
28
+ expect(LibNanomsg.nn_errno).to eq(EINVAL)
29
29
  end
30
30
  end
31
31
  end
@@ -34,21 +34,21 @@ module NNCore
34
34
 
35
35
  context "given an unsupported address family" do
36
36
  it "nn_socket returns -1 and sets nn_errno to EAFNOSUPPORT" do
37
- LibNanomsg.nn_socket(0, NN_PUB).should == -1
38
- LibNanomsg.nn_errno.should == EAFNOSUPPORT
37
+ expect(LibNanomsg.nn_socket(0, NN_PUB)).to eq(-1)
38
+ expect(LibNanomsg.nn_errno).to eq(EAFNOSUPPORT)
39
39
  end
40
40
  end
41
41
 
42
42
  context "given an unsupported protocol and a supported address family" do
43
43
 
44
44
  it "AF_SP returns -1 and sets nn_errno to EINVAL" do
45
- LibNanomsg.nn_socket(AF_SP, 0).should == -1
46
- LibNanomsg.nn_errno.should == EINVAL
45
+ expect(LibNanomsg.nn_socket(AF_SP, 0)).to eq(-1)
46
+ expect(LibNanomsg.nn_errno).to eq(EINVAL)
47
47
  end
48
48
 
49
49
  it "AF_SP_RAW returns -1 and sets nn_errno to EINVAL" do
50
- LibNanomsg.nn_socket(AF_SP_RAW, 0).should == -1
51
- LibNanomsg.nn_errno.should == EINVAL
50
+ expect(LibNanomsg.nn_socket(AF_SP_RAW, 0)).to eq(-1)
51
+ expect(LibNanomsg.nn_errno).to eq(EINVAL)
52
52
  end
53
53
  end
54
54
 
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ module NNCore
4
+ describe "nn_symbol_info" do
5
+
6
+ def symbol_info(index)
7
+ pointer = FFI::MemoryPointer.new(NNCore::LibNanomsg::NNSymbolProperties)
8
+ result_size = LibNanomsg.nn_symbol_info(index, pointer, NNCore::LibNanomsg::NNSymbolProperties.size)
9
+ properties = NNCore::LibNanomsg::NNSymbolProperties.new(pointer)
10
+
11
+ [result_size, properties]
12
+ end
13
+
14
+ context "given an initialized library" do
15
+
16
+ it "returns the NN_PUB constant among the symbols with correct attributes values" do
17
+
18
+ for i in 0..Float::INFINITY
19
+ result_size, properties = symbol_info(i)
20
+
21
+ expect(result_size).to be > 0 if i < 5
22
+
23
+ break if result_size == 0
24
+
25
+ if properties.name == 'NN_PUB'
26
+ found_nn_pub = true
27
+
28
+ expect(properties.value).to eql(32)
29
+ expect(properties.ns).to eql(4)
30
+ expect(properties.type).to eql(0)
31
+ expect(properties.unit).to eql(0)
32
+ end
33
+ end
34
+
35
+ expect(found_nn_pub).to be_truthy
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -9,14 +9,14 @@ module NNCore
9
9
  value = FFI::MemoryPointer.new(:int)
10
10
 
11
11
  constant_string = LibNanomsg.nn_symbol(0, value)
12
- constant_string.should be_a(String)
12
+ expect(constant_string).to be_a(String)
13
13
  end
14
14
 
15
15
  it "returns an integer value in the second parameter given an index of 0" do
16
16
  value = FFI::MemoryPointer.new(:int)
17
17
 
18
18
  constant_string = LibNanomsg.nn_symbol(0, value)
19
- value.read_int.should >= 0
19
+ expect(value.read_int).to be >= 0
20
20
  end
21
21
 
22
22
  end
data/spec/nn_term_spec.rb CHANGED
@@ -17,8 +17,8 @@ module NNCore
17
17
  it "makes subsequent calls to nn_send fail with ETERM" do
18
18
  LibNanomsg.nn_term
19
19
  rc = LibNanomsg.nn_send(0, "ABC", 3, 0)
20
- rc.should == -1
21
- LibNanomsg.nn_errno.should == ETERM
20
+ expect(rc).to eq(-1)
21
+ expect(LibNanomsg.nn_errno).to eq(ETERM)
22
22
  end
23
23
 
24
24
  # it "makes subsequent calls to nn_recv fail with ETERM" do
data/spec/spec_helper.rb CHANGED
@@ -12,7 +12,7 @@ module NNCore
12
12
  :NN_RECONNECT_IVL_MAX => NN_RECONNECT_IVL_MAX,
13
13
  :NN_SNDPRIO => NN_SNDPRIO
14
14
  }
15
-
15
+
16
16
  PROTOCOLS = {
17
17
  :NN_PUB => NN_PUB,
18
18
  :NN_SUB => NN_SUB,
@@ -25,12 +25,12 @@ module NNCore
25
25
  :NN_SURVEYOR => NN_SURVEYOR,
26
26
  :NN_RESPONDENT => NN_RESPONDENT
27
27
  }
28
-
28
+
29
29
  ADDRESS_FAMILIES = {
30
30
  :AF_SP => AF_SP,
31
31
  :AF_SP_RAW => AF_SP_RAW
32
32
  }
33
-
33
+
34
34
  # Some protocols support the AF_SP_RAW address family, so we need to skip those
35
35
  # tests that are expecting a failure.
36
36
  RAW_UNSUPPORTED = []
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nn-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuck Remes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-19 00:00:00.000000000 Z
11
+ date: 2015-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.6'
33
+ version: '3.2'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.6'
40
+ version: '3.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -64,6 +64,7 @@ extra_rdoc_files: []
64
64
  files:
65
65
  - ".gitignore"
66
66
  - ".rspec"
67
+ - ".travis.yml"
67
68
  - Authors.txt
68
69
  - Gemfile
69
70
  - History.txt
@@ -80,11 +81,13 @@ files:
80
81
  - spec/nn_close_spec.rb
81
82
  - spec/nn_connect_spec.rb
82
83
  - spec/nn_getsockopt_spec.rb
84
+ - spec/nn_poll_spec.rb
83
85
  - spec/nn_recv_spec.rb
84
86
  - spec/nn_send_spec.rb
85
87
  - spec/nn_setsockopt_spec.rb
86
88
  - spec/nn_shutdown_spec.rb
87
89
  - spec/nn_socket_spec.rb
90
+ - spec/nn_symbol_info_spec.rb
88
91
  - spec/nn_symbol_spec.rb
89
92
  - spec/nn_term_spec.rb
90
93
  - spec/spec_helper.rb
@@ -107,20 +110,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
110
  version: '0'
108
111
  requirements: []
109
112
  rubyforge_project: nn-core
110
- rubygems_version: 2.2.0
113
+ rubygems_version: 2.4.5
111
114
  signing_key:
112
115
  specification_version: 4
113
116
  summary: Wraps the nanomsg networking library using Ruby FFI (foreign function interface).
114
- test_files:
115
- - spec/nn_bind_spec.rb
116
- - spec/nn_close_spec.rb
117
- - spec/nn_connect_spec.rb
118
- - spec/nn_getsockopt_spec.rb
119
- - spec/nn_recv_spec.rb
120
- - spec/nn_send_spec.rb
121
- - spec/nn_setsockopt_spec.rb
122
- - spec/nn_shutdown_spec.rb
123
- - spec/nn_socket_spec.rb
124
- - spec/nn_symbol_spec.rb
125
- - spec/nn_term_spec.rb
126
- - spec/spec_helper.rb
117
+ test_files: []
118
+ has_rdoc: