nanomsg 0.5.0 → 0.6.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: 338cb73be8a94cc3ee3fb4627973faedae7e81f2
4
- data.tar.gz: be4319a9d07c46bd202c91a003a690e2dcdff1b4
3
+ metadata.gz: 5b07218c8858940ab1c5b6c850bef56a1d33a898
4
+ data.tar.gz: 94235adbd4ccfd1ca44aa7d32602e2d9d87e4422
5
5
  SHA512:
6
- metadata.gz: 0a77d0a5624efb61e649bc1486766fea9e3ac1260ce23b61daabfe83b6a7b4525840669c01ff2417a6f17dae3fc80688f874ef453167cca7c7b7cc7c79f6074a
7
- data.tar.gz: 0f2470ea6c65d1130d6cfbd965af5abecd32ea3134fa4ef9f0c4de84313e891e060d417fd73de36cbf9ac883288e759577b5bbaae809977293541323f7ad1bd8
6
+ metadata.gz: 7f7b434e91fff657228bd780173992e2ae201464f3f73befe63d1d50de91eec8d2a4af0365422122257f0075ef4c32d0f780e49d21f0869457267c58d97980d1
7
+ data.tar.gz: 3bfb497f02776ecf0a310890d61f14042db4d72bfe48b9d940d9eeaa678a84bbfdba0bc4f129490fcf80d0dde2ce90ccf485f2d4de563b265a4c5888313051f8
data/HISTORY CHANGED
@@ -1,3 +1,7 @@
1
+ = 0.6 / 13Mai2016
2
+
3
+ * Adds #getsockopt to sockets, allowing only NN_SNDFD and NN_RCVFD for now.
4
+
1
5
  = 0.5 / 27Aug2015
2
6
 
3
7
  * GVL-code is now compatible with Ruby 2.2.
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-2015 Kaspar Schiess
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
 
@@ -19,10 +19,10 @@ describe 'BUS sockets' do
19
19
  sleep 0.01
20
20
 
21
21
  a.send 'test'
22
- b.recv.should == 'test'
22
+ b.recv.assert == 'test'
23
23
 
24
24
  b.send 'ing'
25
- a.recv.should == 'ing'
25
+ a.recv.assert == 'ing'
26
26
  end
27
27
  end
28
28
  end
@@ -34,7 +34,7 @@ describe 'Devices' do
34
34
  sleep 0.01
35
35
  c.send 'test'
36
36
  timeout(1) do
37
- d.recv.should == 'test'
37
+ d.recv.assert == 'test'
38
38
  end
39
39
  end
40
40
  end
@@ -17,12 +17,30 @@ describe NanoMsg::PairSocket do
17
17
  sock1.bind(tbind)
18
18
  sock2.connect(tbind)
19
19
 
20
- sock1.send('1234').should == 4
21
- sock2.recv.should == '1234'
20
+ sock1.send('1234').assert == 4
21
+ sock2.recv.assert == '1234'
22
22
 
23
- sock2.send('5678').should == 4
24
- sock1.recv.should == '5678'
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
- it 'has no #recv method'
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
- it 'has no #send method'
11
- it 'allows subscribing to channels'
12
- it 'allows unsubscribing to channels'
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.should == 'foo1234'
45
- sub2.recv.should == 'foo1234'
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.should == 'bar4567'
50
- sub2.recv.should == 'foo9999'
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.should < 10
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.should == i
60
+ consumer.recv.to_i.assert == i
61
61
  end
62
62
  end
63
63
  end
@@ -19,10 +19,10 @@ describe 'REQ/REP sockets' do
19
19
 
20
20
  req.send 'req1'
21
21
 
22
- rep.recv.should == 'req1'
22
+ rep.recv.assert == 'req1'
23
23
  rep.send 'rep1'
24
24
 
25
- req.recv.should == 'rep1'
25
+ req.recv.assert == 'rep1'
26
26
  end
27
27
  end
28
28
  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.should == 1 # default: 1 second
17
+ surveyor.deadline.assert == 1 # default: 1 second
18
18
  surveyor.deadline = 0.1 # 100ms
19
- surveyor.deadline.should == 0.1
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.should == 'u there?'
29
- resp2.recv.should == 'u there?'
28
+ resp1.recv.assert == 'u there?'
29
+ resp2.recv.assert == 'u there?'
30
30
 
31
31
  resp1.send 'KTHNXBYE'
32
- surveyor.recv.should == 'KTHNXBYE'
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
@@ -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.should >= 0
6
+ NanoMsg::NN_LINGER.assert >= 0
7
7
  end
8
8
  it 'allows shutting down using nn_term' do
9
- NanoMsg.should respond_to(:terminate)
9
+ NanoMsg.assert.respond_to?(:terminate)
10
10
  end
11
11
  end
@@ -1,4 +1,5 @@
1
1
 
2
+ require 'ae'
2
3
 
3
4
  $:.unshift File.dirname(__FILE__) + "/../ext"
4
5
  require 'nanomsg'
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.5.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: 2015-08-27 00:00:00.000000000 Z
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.4.5
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: