nanomsg 0.5.0 → 0.6.0
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 +4 -4
- data/HISTORY +4 -0
- data/README +2 -2
- data/ext/init.c +37 -0
- data/spec/lib/nanomsg/bus_spec.rb +2 -2
- data/spec/lib/nanomsg/device_spec.rb +1 -1
- data/spec/lib/nanomsg/pair_socket_spec.rb +23 -5
- data/spec/lib/nanomsg/pub_sub_spec.rb +28 -8
- data/spec/lib/nanomsg/push_pull_spec.rb +2 -2
- data/spec/lib/nanomsg/req_rep_spec.rb +2 -2
- data/spec/lib/nanomsg/survey_spec.rb +8 -5
- data/spec/lib/nanomsg_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b07218c8858940ab1c5b6c850bef56a1d33a898
|
4
|
+
data.tar.gz: 94235adbd4ccfd1ca44aa7d32602e2d9d87e4422
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f7b434e91fff657228bd780173992e2ae201464f3f73befe63d1d50de91eec8d2a4af0365422122257f0075ef4c32d0f780e49d21f0869457267c58d97980d1
|
7
|
+
data.tar.gz: 3bfb497f02776ecf0a310890d61f14042db4d72bfe48b9d940d9eeaa678a84bbfdba0bc4f129490fcf80d0dde2ce90ccf485f2d4de563b265a4c5888313051f8
|
data/HISTORY
CHANGED
data/README
CHANGED
@@ -43,11 +43,11 @@ SYNOPSIS
|
|
43
43
|
STATUS
|
44
44
|
|
45
45
|
Works with a range of nanomsg versions, last one verified is 0.6. Should work
|
46
|
-
for mri rubies 1.9, 2.0, 2.1, 2.2.
|
46
|
+
for mri rubies 1.9, 2.0, 2.1, 2.2, 2.3.
|
47
47
|
|
48
48
|
Beta software: If you know what you're doing, you can use this in production.
|
49
49
|
|
50
50
|
LICENSE
|
51
51
|
|
52
|
-
See file LICENSE, Copyright (c) 2013-
|
52
|
+
See file LICENSE, Copyright (c) 2013-2016 Kaspar Schiess
|
53
53
|
|
data/ext/init.c
CHANGED
@@ -290,6 +290,42 @@ sock_setsockopt(VALUE self, VALUE level, VALUE option, VALUE val)
|
|
290
290
|
return self;
|
291
291
|
}
|
292
292
|
|
293
|
+
static VALUE
|
294
|
+
sock_getsockopt(VALUE self, VALUE level, VALUE option)
|
295
|
+
{
|
296
|
+
int sock = sock_get(self);
|
297
|
+
int level_arg = FIX2INT(level);
|
298
|
+
int option_arg = FIX2INT(option);
|
299
|
+
int err;
|
300
|
+
|
301
|
+
int out;
|
302
|
+
size_t sz;
|
303
|
+
|
304
|
+
if (level_arg == NN_SOL_SOCKET) {
|
305
|
+
// This list of supported options is not complete yet. However, having
|
306
|
+
// a few supported sockets here is more useful than none at all. WIP.
|
307
|
+
// Yes, pr please ;)
|
308
|
+
switch (option_arg) {
|
309
|
+
case NN_SNDFD:
|
310
|
+
case NN_RCVFD:
|
311
|
+
// Return will be int, which is a system fd.
|
312
|
+
sz = sizeof(out);
|
313
|
+
err = nn_getsockopt(sock, level_arg, option_arg, &out, &sz);
|
314
|
+
if (err < 0)
|
315
|
+
RAISE_SOCK_ERROR;
|
316
|
+
|
317
|
+
return INT2NUM(out);
|
318
|
+
default:
|
319
|
+
// Unsupported option, returning nil.
|
320
|
+
return Qnil;
|
321
|
+
}
|
322
|
+
}
|
323
|
+
else {
|
324
|
+
// And yet more code here.
|
325
|
+
return Qnil;
|
326
|
+
}
|
327
|
+
}
|
328
|
+
|
293
329
|
#define SOCK_INIT_FUNC(name, type) \
|
294
330
|
static VALUE \
|
295
331
|
name(int argc, VALUE *argv, VALUE self) \
|
@@ -468,6 +504,7 @@ Init_nanomsg_ext(void)
|
|
468
504
|
rb_define_method(cSocket, "recv", sock_recv, 0);
|
469
505
|
rb_define_method(cSocket, "close", sock_close, 0);
|
470
506
|
rb_define_method(cSocket, "setsockopt", sock_setsockopt, 3);
|
507
|
+
rb_define_method(cSocket, "getsockopt", sock_getsockopt, 2);
|
471
508
|
|
472
509
|
rb_define_method(cPairSocket, "initialize", pair_sock_init, -1);
|
473
510
|
|
@@ -17,12 +17,30 @@ describe NanoMsg::PairSocket do
|
|
17
17
|
sock1.bind(tbind)
|
18
18
|
sock2.connect(tbind)
|
19
19
|
|
20
|
-
sock1.send('1234').
|
21
|
-
sock2.recv.
|
20
|
+
sock1.send('1234').assert == 4
|
21
|
+
sock2.recv.assert == '1234'
|
22
22
|
|
23
|
-
sock2.send('5678').
|
24
|
-
sock1.recv.
|
25
|
-
end
|
23
|
+
sock2.send('5678').assert == 4
|
24
|
+
sock1.recv.assert == '5678'
|
25
|
+
end
|
26
|
+
it 'allows file descriptor retrieval' do
|
27
|
+
sock1.bind(tbind)
|
28
|
+
sock2.connect(tbind)
|
29
|
+
|
30
|
+
sock1.send('1234').assert == 4
|
31
|
+
|
32
|
+
# Now our socket should be ready:
|
33
|
+
int_fd = sock2.getsockopt(NanoMsg::NN_SOL_SOCKET, NanoMsg::NN_RCVFD)
|
34
|
+
|
35
|
+
# Reconstruct a Ruby IO from the integer above. Note that if you
|
36
|
+
# #close this FD, things will be messed up for NanoMsg.
|
37
|
+
io = IO.for_fd(int_fd)
|
38
|
+
io.autoclose = false
|
39
|
+
|
40
|
+
r, _, _ = IO.select([io])
|
41
|
+
r.size.assert == 1
|
42
|
+
r.first.assert == io
|
43
|
+
end
|
26
44
|
end
|
27
45
|
end
|
28
46
|
|
@@ -4,12 +4,32 @@ require 'timeout'
|
|
4
4
|
|
5
5
|
describe 'PUB/SUB sockets' do
|
6
6
|
describe 'PUB socket' do
|
7
|
-
|
7
|
+
let!(:pub) { NanoMsg::PubSocket.new }
|
8
|
+
|
9
|
+
it 'has no #recv method' do
|
10
|
+
NanoMsg::Errno::ENOTSUP.assert.raised? do
|
11
|
+
pub.recv
|
12
|
+
end
|
13
|
+
end
|
8
14
|
end
|
9
15
|
describe 'SUB socket' do
|
10
|
-
|
11
|
-
it '
|
12
|
-
|
16
|
+
let!(:sub) { NanoMsg::SubSocket.new }
|
17
|
+
it 'has no #send method' do
|
18
|
+
NanoMsg::Errno::ENOTSUP.assert.raised? do
|
19
|
+
sub.send 'foo'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'allows unsubscribing to channels' do
|
24
|
+
sub.subscribe 'foo'
|
25
|
+
sub.unsubscribe 'foo'
|
26
|
+
end
|
27
|
+
it 'allows unsubscribing to channels' do
|
28
|
+
# NOTE unsubscribe without previous subscribe currently provokes an
|
29
|
+
# access protection (null pointer deref) in nn_setsockopt/NN_SUB_UNSUBSCRIBE
|
30
|
+
# We told you it was alpha software.
|
31
|
+
# sub.unsubscribe 'foo'
|
32
|
+
end
|
13
33
|
end
|
14
34
|
|
15
35
|
def self.examples_for_transport tbind
|
@@ -41,13 +61,13 @@ describe 'PUB/SUB sockets' do
|
|
41
61
|
sleep 0.1
|
42
62
|
|
43
63
|
pub.send 'foo1234'
|
44
|
-
sub1.recv.
|
45
|
-
sub2.recv.
|
64
|
+
sub1.recv.assert == 'foo1234'
|
65
|
+
sub2.recv.assert == 'foo1234'
|
46
66
|
|
47
67
|
pub.send 'bar4567'
|
48
68
|
pub.send 'foo9999'
|
49
|
-
sub1.recv.
|
50
|
-
sub2.recv.
|
69
|
+
sub1.recv.assert == 'bar4567'
|
70
|
+
sub2.recv.assert == 'foo9999'
|
51
71
|
end
|
52
72
|
end
|
53
73
|
end
|
@@ -33,7 +33,7 @@ describe 'PUSH/PULL pipeline sockets' do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
# This is about a 5% level of the binominal distribution
|
36
|
-
(n.first - n.last).abs.
|
36
|
+
(n.first - n.last).abs.assert < 10
|
37
37
|
end
|
38
38
|
end
|
39
39
|
describe 'fanin' do
|
@@ -57,7 +57,7 @@ describe 'PUSH/PULL pipeline sockets' do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
100.times do |i|
|
60
|
-
consumer.recv.to_i.
|
60
|
+
consumer.recv.to_i.assert == i
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -14,9 +14,9 @@ describe 'SURVEY sockets' do
|
|
14
14
|
|
15
15
|
describe "transport #{name}" do
|
16
16
|
it 'allows simple surveys' do
|
17
|
-
surveyor.deadline.
|
17
|
+
surveyor.deadline.assert == 1 # default: 1 second
|
18
18
|
surveyor.deadline = 0.1 # 100ms
|
19
|
-
surveyor.deadline.
|
19
|
+
surveyor.deadline.assert == 0.1
|
20
20
|
|
21
21
|
surveyor.bind(tbind)
|
22
22
|
|
@@ -25,17 +25,20 @@ describe 'SURVEY sockets' do
|
|
25
25
|
|
26
26
|
sleep 0.1
|
27
27
|
surveyor.send 'u there?'
|
28
|
-
resp1.recv.
|
29
|
-
resp2.recv.
|
28
|
+
resp1.recv.assert == 'u there?'
|
29
|
+
resp2.recv.assert == 'u there?'
|
30
30
|
|
31
31
|
resp1.send 'KTHNXBYE'
|
32
|
-
surveyor.recv.
|
32
|
+
surveyor.recv.assert == 'KTHNXBYE'
|
33
33
|
|
34
34
|
# nanomsg/tests/survey.c says this should be EFSM, the documentation
|
35
35
|
# says it should be ETIMEDOUT. Reality wins.
|
36
36
|
begin
|
37
37
|
surveyor.recv
|
38
38
|
rescue NanoMsg::Errno::EFSM
|
39
|
+
# Old nanomsg version
|
40
|
+
rescue NanoMsg::Errno::ETIMEDOUT
|
41
|
+
# New version
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
data/spec/lib/nanomsg_spec.rb
CHANGED
@@ -3,9 +3,9 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe NanoMsg do
|
5
5
|
it 'has NN_LINGER constant set to an integer value' do
|
6
|
-
NanoMsg::NN_LINGER.
|
6
|
+
NanoMsg::NN_LINGER.assert >= 0
|
7
7
|
end
|
8
8
|
it 'allows shutting down using nn_term' do
|
9
|
-
NanoMsg.
|
9
|
+
NanoMsg.assert.respond_to?(:terminate)
|
10
10
|
end
|
11
11
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nanomsg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kaspar Schiess
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " nanomsg library is a high-performance implementation of several
|
14
14
|
\"scalability \n protocols\". Scalability protocol's job is to define how multiple
|
@@ -66,9 +66,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
version: '0'
|
67
67
|
requirements: []
|
68
68
|
rubyforge_project:
|
69
|
-
rubygems_version: 2.
|
69
|
+
rubygems_version: 2.5.0
|
70
70
|
signing_key:
|
71
71
|
specification_version: 4
|
72
72
|
summary: Ruby binding for nanomsg. nanomsg library is a high-performance implementation
|
73
73
|
of several "scalability protocols".
|
74
74
|
test_files: []
|
75
|
+
has_rdoc:
|