nio4r 2.3.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ RSpec.shared_context NIO::Selector do
4
+ let(:selector) {@selector = NIO::Selector.new}
5
+
6
+ after(:each) do
7
+ if defined?(@selector)
8
+ @selector.close
9
+ end
10
+ end
11
+ end
12
+
3
13
  RSpec.shared_context "an NIO selectable" do
4
- let(:selector) { NIO::Selector.new }
14
+ include_context NIO::Selector
5
15
 
6
- it "selects readable objects", retry: 5 do # retry: Flaky on OS X
16
+ it "selects readable objects" do
7
17
  monitor = selector.register(readable_subject, :r)
8
- ready = selector.select(0)
18
+ ready = selector.select(1)
9
19
  expect(ready).to be_an Enumerable
10
20
  expect(ready).to include monitor
11
21
  end
@@ -17,25 +27,29 @@ RSpec.shared_context "an NIO selectable" do
17
27
 
18
28
  it "selects writable objects" do
19
29
  monitor = selector.register(writable_subject, :w)
20
- ready = selector.select(0)
30
+ ready = selector.select(1)
21
31
  expect(ready).to be_an Enumerable
22
32
  expect(ready).to include monitor
23
33
  end
24
34
 
25
35
  it "does not select unwritable objects" do
26
36
  selector.register(unwritable_subject, :w)
27
- expect(selector.select(0)).to be_nil
37
+ ready = selector.select(0)
38
+ expect(ready).to be_nil
28
39
  end
29
40
  end
30
41
 
31
- RSpec.shared_context "an NIO selectable stream" do
32
- let(:selector) { NIO::Selector.new }
42
+ RSpec.shared_context "an NIO selectable stream" do |is_tls13|
43
+ include_context NIO::Selector
44
+
33
45
  let(:stream) { pair.first }
34
46
  let(:peer) { pair.last }
35
47
 
36
48
  it "selects readable when the other end closes" do
37
49
  monitor = selector.register(stream, :r)
38
- expect(selector.select(0)).to be_nil
50
+ unless is_tls13
51
+ expect(selector.select(1)).to be_nil
52
+ end
39
53
 
40
54
  peer.close
41
55
  # Wait and give the TCP session time to close
@@ -44,22 +58,28 @@ RSpec.shared_context "an NIO selectable stream" do
44
58
  end
45
59
 
46
60
  RSpec.shared_context "an NIO bidirectional stream" do
47
- let(:selector) { NIO::Selector.new }
48
- let(:stream) { pair.first }
49
- let(:peer) { pair.last }
61
+ include_context NIO::Selector
62
+
63
+ let(:stream) {pair.first}
64
+ let(:peer) {pair.last}
50
65
 
51
- it "selects readable and writable", retry: 5 do # retry: Flaky on OS X
66
+ it "selects readable and writable" do
52
67
  selector.register(readable_subject, :rw)
53
- selector.select(0) do |m|
54
- expect(m.readiness).to eq(:rw)
68
+
69
+ selector.select(1) do |monitor|
70
+ expect(monitor.readiness).to eq(:rw)
55
71
  end
72
+
73
+ readable_subject.close
56
74
  end
75
+
57
76
  it "keeps readiness after the selectable has been closed" do
58
77
  selector.register(readable_subject, :rw)
59
- selector.select(0) do |m|
60
- expect(m.readiness).to eq(:rw)
78
+
79
+ selector.select(1) do |monitor|
80
+ expect(monitor.readiness).to eq(:rw)
61
81
  readable_subject.close
62
- expect(m.readiness).to eq(:rw)
82
+ expect(monitor.readiness).to eq(:rw)
63
83
  end
64
84
  end
65
85
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nio4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-02 00:00:00.000000000 Z
11
+ date: 2019-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,7 +62,6 @@ files:
62
62
  - ext/libev/Changes
63
63
  - ext/libev/LICENSE
64
64
  - ext/libev/README
65
- - ext/libev/README.embed
66
65
  - ext/libev/ev.c
67
66
  - ext/libev/ev.h
68
67
  - ext/libev/ev_epoll.c
@@ -73,7 +72,6 @@ files:
73
72
  - ext/libev/ev_vars.h
74
73
  - ext/libev/ev_win32.c
75
74
  - ext/libev/ev_wrap.h
76
- - ext/libev/test_libev_win32.c
77
75
  - ext/nio4r/bytebuffer.c
78
76
  - ext/nio4r/extconf.rb
79
77
  - ext/nio4r/libev.h
@@ -92,6 +90,9 @@ files:
92
90
  - lib/nio/version.rb
93
91
  - logo.png
94
92
  - nio4r.gemspec
93
+ - rakelib/extension.rake
94
+ - rakelib/rspec.rake
95
+ - rakelib/rubocop.rake
95
96
  - spec/nio/acceptables_spec.rb
96
97
  - spec/nio/bytebuffer_spec.rb
97
98
  - spec/nio/monitor_spec.rb
@@ -102,9 +103,6 @@ files:
102
103
  - spec/nio/selector_spec.rb
103
104
  - spec/spec_helper.rb
104
105
  - spec/support/selectable_examples.rb
105
- - tasks/extension.rake
106
- - tasks/rspec.rake
107
- - tasks/rubocop.rake
108
106
  homepage: https://github.com/socketry/nio4r
109
107
  licenses:
110
108
  - MIT
@@ -117,15 +115,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
115
  requirements:
118
116
  - - ">="
119
117
  - !ruby/object:Gem::Version
120
- version: 2.2.2
118
+ version: '2.3'
121
119
  required_rubygems_version: !ruby/object:Gem::Requirement
122
120
  requirements:
123
121
  - - ">="
124
122
  - !ruby/object:Gem::Version
125
123
  version: '0'
126
124
  requirements: []
127
- rubyforge_project:
128
- rubygems_version: 2.7.4
125
+ rubygems_version: 3.0.3
129
126
  signing_key:
130
127
  specification_version: 4
131
128
  summary: New IO for Ruby
@@ -1,3 +0,0 @@
1
- This file is now included in the main libev documentation, see
2
-
3
- http://cvs.schmorp.de/libev/ev.html
@@ -1,123 +0,0 @@
1
- // a single header file is required
2
- #include <ev.h>
3
- #include <stdio.h>
4
- #include <io.h>
5
-
6
- // every watcher type has its own typedef'd struct
7
- // with the name ev_TYPE
8
- ev_io stdin_watcher;
9
- ev_timer timeout_watcher;
10
-
11
- // all watcher callbacks have a similar signature
12
- // this callback is called when data is readable on stdin
13
- static void
14
- stdin_cb (EV_P_ ev_io *w, int revents)
15
- {
16
- puts ("stdin ready or done or something");
17
- // for one-shot events, one must manually stop the watcher
18
- // with its corresponding stop function.
19
- //ev_io_stop (EV_A_ w);
20
-
21
- // this causes all nested ev_loop's to stop iterating
22
- //ev_unloop (EV_A_ EVUNLOOP_ALL);
23
- }
24
-
25
- // another callback, this time for a time-out
26
- static void
27
- timeout_cb (EV_P_ ev_timer *w, int revents)
28
- {
29
- puts ("timeout");
30
- // this causes the innermost ev_loop to stop iterating
31
- ev_unloop (EV_A_ EVUNLOOP_ONE);
32
- }
33
-
34
-
35
-
36
- #include <winsock.h>
37
-
38
- #include <stdlib.h>
39
- #include <iostream>
40
- int get_server_fd()
41
- {
42
-
43
- //----------------------
44
- // Initialize Winsock.
45
- WSADATA wsaData;
46
- int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
47
- if (iResult != NO_ERROR) {
48
- printf("Error at WSAStartup()\n");
49
- return 1;
50
- }
51
-
52
- //----------------------
53
- // Create a SOCKET for listening for
54
- // incoming connection requests.
55
- SOCKET ListenSocket;
56
- ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
57
- if (ListenSocket == INVALID_SOCKET) {
58
- printf("Error at socket(): %ld\n", WSAGetLastError());
59
- WSACleanup();
60
- return 1;
61
- }
62
- printf("socket returned %d\n", ListenSocket);
63
-
64
- //----------------------
65
- // The sockaddr_in structure specifies the address family,
66
- // IP address, and port for the socket that is being bound.
67
- sockaddr_in service;
68
- service.sin_family = AF_INET;
69
- service.sin_addr.s_addr = inet_addr("127.0.0.1");
70
- service.sin_port = htons(4444);
71
-
72
- if (bind( ListenSocket,
73
- (SOCKADDR*) &service,
74
- sizeof(service)) == SOCKET_ERROR) {
75
- printf("bind() failed.\n");
76
- closesocket(ListenSocket);
77
- WSACleanup();
78
- return 1;
79
- }
80
-
81
- //----------------------
82
- // Listen for incoming connection requests.
83
- // on the created socket
84
- if (listen( ListenSocket, 1 ) == SOCKET_ERROR) {
85
- printf("Error listening on socket.\n");
86
- closesocket(ListenSocket);
87
- WSACleanup();
88
- return 1;
89
- }
90
-
91
-
92
- printf("sock and osf handle are %d %d, error is \n", ListenSocket, _get_osfhandle (ListenSocket)); // -1 is invalid file handle: http://msdn.microsoft.com/en-us/library/ks2530z6.aspx
93
- printf("err was %d\n", WSAGetLastError());
94
- //----------------------
95
- return ListenSocket;
96
- }
97
-
98
-
99
- int
100
- main (void)
101
- {
102
- struct ev_loop *loopy = ev_default_loop(0);
103
- int fd = get_server_fd();
104
- int fd_real = _open_osfhandle(fd, NULL);
105
- int conv = _get_osfhandle(fd_real);
106
- printf("got server fd %d, loop %d, fd_real %d, that converted %d\n", fd, loopy, fd_real, conv);
107
- // accept(fd, NULL, NULL);
108
- // initialise an io watcher, then start it
109
- // this one will watch for stdin to become readable
110
- ev_io_init (&stdin_watcher, stdin_cb, /*STDIN_FILENO*/ conv, EV_READ);
111
- ev_io_start (loopy, &stdin_watcher);
112
-
113
- // initialise a timer watcher, then start it
114
- // simple non-repeating 5.5 second timeout
115
- //ev_timer_init (&timeout_watcher, timeout_cb, 15.5, 0.);
116
- //ev_timer_start (loopy, &timeout_watcher);
117
- printf("starting loop\n");
118
- // now wait for events to arrive
119
- ev_loop (loopy, 0);
120
-
121
- // unloop was called, so exit
122
- return 0;
123
- }