io-wait 0.2.0 → 0.2.1
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/Rakefile +5 -2
- data/ext/io/wait/depend +1 -1
- data/ext/io/wait/extconf.rb +1 -0
- data/ext/io/wait/wait.c +107 -7
- data/io-wait.gemspec +2 -2
- data/rakelib/sync_tool.rake +6 -0
- data/rakelib/version.rake +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e443d24e34f86142b3d27ca1a774e3828b63f445b00f94bd79273bb5583e4699
|
4
|
+
data.tar.gz: 5766517962c90389a10199460414a7088b8316edaa7f0854c98ebbdfd65ec4ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 526b1f255ac3a9999f9965a5ee35b4c43d32d0493bfaf2cb32e2ad8e4978f57c579574649986f6dfd77a5a2a058f7c5b2f8eaf2b83d8f31a9deac5fc24ffd55f
|
7
|
+
data.tar.gz: 0424cf27d9a11aeb5dc142963073b9624e9102465cd5358d5f92b9e1cb258b2b60f224d0ef43c1d49d6156d04c0f6a8e26dcb6d339adcfab1400d7c53bd5b1b7
|
data/Rakefile
CHANGED
@@ -3,14 +3,17 @@ require "rake/testtask"
|
|
3
3
|
|
4
4
|
name = "io/wait"
|
5
5
|
|
6
|
+
require 'rake/extensiontask'
|
7
|
+
extask = Rake::ExtensionTask.new(name) do |x|
|
8
|
+
x.lib_dir << "/#{RUBY_VERSION}/#{x.platform}"
|
9
|
+
end
|
6
10
|
Rake::TestTask.new(:test) do |t|
|
11
|
+
t.libs << extask.lib_dir
|
7
12
|
t.libs << "test/lib"
|
8
13
|
t.ruby_opts << "-rhelper"
|
9
14
|
t.test_files = FileList["test/**/test_*.rb"]
|
10
15
|
end
|
11
16
|
|
12
|
-
require 'rake/extensiontask'
|
13
|
-
Rake::ExtensionTask.new(name)
|
14
17
|
task :test => :compile
|
15
18
|
|
16
19
|
task :default => :test
|
data/ext/io/wait/depend
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
wait.o: $(RUBY_EXTCONF_H)
|
3
3
|
wait.o: $(arch_hdrdir)/ruby/config.h
|
4
4
|
wait.o: $(hdrdir)/ruby.h
|
5
|
-
wait.o: $(hdrdir)/ruby/assert.h
|
5
|
+
# wait.o: $(hdrdir)/ruby/assert.h # not in 2.6
|
6
6
|
wait.o: $(hdrdir)/ruby/backward.h
|
7
7
|
wait.o: $(hdrdir)/ruby/defines.h
|
8
8
|
wait.o: $(hdrdir)/ruby/encoding.h
|
data/ext/io/wait/extconf.rb
CHANGED
data/ext/io/wait/wait.c
CHANGED
@@ -40,6 +40,37 @@
|
|
40
40
|
#define FIONREAD_POSSIBLE_P(fd) ((void)(fd),Qtrue)
|
41
41
|
#endif
|
42
42
|
|
43
|
+
#ifndef HAVE_RB_IO_WAIT
|
44
|
+
static VALUE io_ready_p _((VALUE io));
|
45
|
+
static VALUE io_wait_readable _((int argc, VALUE *argv, VALUE io));
|
46
|
+
static VALUE io_wait_writable _((int argc, VALUE *argv, VALUE io));
|
47
|
+
void Init_wait _((void));
|
48
|
+
|
49
|
+
static struct timeval *
|
50
|
+
get_timeout(int argc, VALUE *argv, struct timeval *timerec)
|
51
|
+
{
|
52
|
+
VALUE timeout = Qnil;
|
53
|
+
rb_check_arity(argc, 0, 1);
|
54
|
+
if (!argc || NIL_P(timeout = argv[0])) {
|
55
|
+
return NULL;
|
56
|
+
}
|
57
|
+
else {
|
58
|
+
*timerec = rb_time_interval(timeout);
|
59
|
+
return timerec;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
static int
|
64
|
+
wait_for_single_fd(rb_io_t *fptr, int events, struct timeval *tv)
|
65
|
+
{
|
66
|
+
int i = rb_wait_for_single_fd(fptr->fd, events, tv);
|
67
|
+
if (i < 0)
|
68
|
+
rb_sys_fail(0);
|
69
|
+
rb_io_check_closed(fptr);
|
70
|
+
return (i & events);
|
71
|
+
}
|
72
|
+
#endif
|
73
|
+
|
43
74
|
/*
|
44
75
|
* call-seq:
|
45
76
|
* io.nread -> int
|
@@ -51,12 +82,13 @@
|
|
51
82
|
static VALUE
|
52
83
|
io_nread(VALUE io)
|
53
84
|
{
|
54
|
-
rb_io_t *fptr
|
85
|
+
rb_io_t *fptr;
|
86
|
+
int len;
|
55
87
|
ioctl_arg n;
|
56
88
|
|
57
89
|
GetOpenFile(io, fptr);
|
58
90
|
rb_io_check_readable(fptr);
|
59
|
-
|
91
|
+
len = rb_io_read_pending(fptr);
|
60
92
|
if (len > 0) return INT2FIX(len);
|
61
93
|
if (!FIONREAD_POSSIBLE_P(fptr->fd)) return INT2FIX(0);
|
62
94
|
if (ioctl(fptr->fd, FIONREAD, &n)) return INT2FIX(0);
|
@@ -64,6 +96,7 @@ io_nread(VALUE io)
|
|
64
96
|
return INT2FIX(0);
|
65
97
|
}
|
66
98
|
|
99
|
+
#ifdef HAVE_RB_IO_WAIT
|
67
100
|
static VALUE
|
68
101
|
io_wait_event(VALUE io, int event, VALUE timeout)
|
69
102
|
{
|
@@ -82,6 +115,7 @@ io_wait_event(VALUE io, int event, VALUE timeout)
|
|
82
115
|
return Qfalse;
|
83
116
|
}
|
84
117
|
}
|
118
|
+
#endif
|
85
119
|
|
86
120
|
/*
|
87
121
|
* call-seq:
|
@@ -94,12 +128,22 @@ static VALUE
|
|
94
128
|
io_ready_p(VALUE io)
|
95
129
|
{
|
96
130
|
rb_io_t *fptr;
|
131
|
+
#ifndef HAVE_RB_IO_WAIT
|
132
|
+
struct timeval tv = {0, 0};
|
133
|
+
#endif
|
97
134
|
|
98
135
|
GetOpenFile(io, fptr);
|
99
136
|
rb_io_check_readable(fptr);
|
100
137
|
if (rb_io_read_pending(fptr)) return Qtrue;
|
101
138
|
|
102
|
-
|
139
|
+
#ifndef HAVE_RB_IO_WAIT
|
140
|
+
if (wait_for_single_fd(fptr, RB_WAITFD_IN, &tv))
|
141
|
+
return Qtrue;
|
142
|
+
#else
|
143
|
+
if (RTEST(io_wait_event(io, RUBY_IO_READABLE, RB_INT2NUM(0))))
|
144
|
+
return Qtrue;
|
145
|
+
#endif
|
146
|
+
return Qfalse;
|
103
147
|
}
|
104
148
|
|
105
149
|
/*
|
@@ -115,17 +159,31 @@ io_ready_p(VALUE io)
|
|
115
159
|
static VALUE
|
116
160
|
io_wait_readable(int argc, VALUE *argv, VALUE io)
|
117
161
|
{
|
118
|
-
rb_io_t *fptr
|
162
|
+
rb_io_t *fptr;
|
163
|
+
#ifndef HAVE_RB_IO_WAIT
|
164
|
+
struct timeval timerec;
|
165
|
+
struct timeval *tv;
|
166
|
+
#endif
|
119
167
|
|
120
|
-
|
168
|
+
GetOpenFile(io, fptr);
|
121
169
|
rb_io_check_readable(fptr);
|
122
170
|
|
171
|
+
#ifndef HAVE_RB_IO_WAIT
|
172
|
+
tv = get_timeout(argc, argv, &timerec);
|
173
|
+
#endif
|
123
174
|
if (rb_io_read_pending(fptr)) return Qtrue;
|
124
175
|
|
176
|
+
#ifndef HAVE_RB_IO_WAIT
|
177
|
+
if (wait_for_single_fd(fptr, RB_WAITFD_IN, tv)) {
|
178
|
+
return io;
|
179
|
+
}
|
180
|
+
return Qnil;
|
181
|
+
#else
|
125
182
|
rb_check_arity(argc, 0, 1);
|
126
183
|
VALUE timeout = (argc == 1 ? argv[0] : Qnil);
|
127
184
|
|
128
185
|
return io_wait_event(io, RUBY_IO_READABLE, timeout);
|
186
|
+
#endif
|
129
187
|
}
|
130
188
|
|
131
189
|
/*
|
@@ -139,17 +197,30 @@ io_wait_readable(int argc, VALUE *argv, VALUE io)
|
|
139
197
|
static VALUE
|
140
198
|
io_wait_writable(int argc, VALUE *argv, VALUE io)
|
141
199
|
{
|
142
|
-
rb_io_t *fptr
|
200
|
+
rb_io_t *fptr;
|
201
|
+
#ifndef HAVE_RB_IO_WAIT
|
202
|
+
struct timeval timerec;
|
203
|
+
struct timeval *tv;
|
204
|
+
#endif
|
143
205
|
|
144
|
-
|
206
|
+
GetOpenFile(io, fptr);
|
145
207
|
rb_io_check_writable(fptr);
|
146
208
|
|
209
|
+
#ifndef HAVE_RB_IO_WAIT
|
210
|
+
tv = get_timeout(argc, argv, &timerec);
|
211
|
+
if (wait_for_single_fd(fptr, RB_WAITFD_OUT, tv)) {
|
212
|
+
return io;
|
213
|
+
}
|
214
|
+
return Qnil;
|
215
|
+
#else
|
147
216
|
rb_check_arity(argc, 0, 1);
|
148
217
|
VALUE timeout = (argc == 1 ? argv[0] : Qnil);
|
149
218
|
|
150
219
|
return io_wait_event(io, RUBY_IO_WRITABLE, timeout);
|
220
|
+
#endif
|
151
221
|
}
|
152
222
|
|
223
|
+
#ifdef HAVE_RB_IO_WAIT
|
153
224
|
/*
|
154
225
|
* call-seq:
|
155
226
|
* io.wait_priority -> true or false
|
@@ -173,6 +244,7 @@ io_wait_priority(int argc, VALUE *argv, VALUE io)
|
|
173
244
|
|
174
245
|
return io_wait_event(io, RUBY_IO_PRIORITY, timeout);
|
175
246
|
}
|
247
|
+
#endif
|
176
248
|
|
177
249
|
static int
|
178
250
|
wait_mode_sym(VALUE mode)
|
@@ -228,6 +300,31 @@ wait_mode_sym(VALUE mode)
|
|
228
300
|
static VALUE
|
229
301
|
io_wait(int argc, VALUE *argv, VALUE io)
|
230
302
|
{
|
303
|
+
#ifndef HAVE_RB_IO_WAIT
|
304
|
+
rb_io_t *fptr;
|
305
|
+
struct timeval timerec;
|
306
|
+
struct timeval *tv = NULL;
|
307
|
+
int event = 0;
|
308
|
+
int i;
|
309
|
+
|
310
|
+
GetOpenFile(io, fptr);
|
311
|
+
for (i = 0; i < argc; ++i) {
|
312
|
+
if (SYMBOL_P(argv[i])) {
|
313
|
+
event |= wait_mode_sym(argv[i]);
|
314
|
+
}
|
315
|
+
else {
|
316
|
+
*(tv = &timerec) = rb_time_interval(argv[i]);
|
317
|
+
}
|
318
|
+
}
|
319
|
+
/* rb_time_interval() and might_mode() might convert the argument */
|
320
|
+
rb_io_check_closed(fptr);
|
321
|
+
if (!event) event = RB_WAITFD_IN;
|
322
|
+
if ((event & RB_WAITFD_IN) && rb_io_read_pending(fptr))
|
323
|
+
return Qtrue;
|
324
|
+
if (wait_for_single_fd(fptr, event, tv))
|
325
|
+
return io;
|
326
|
+
return Qnil;
|
327
|
+
#else
|
231
328
|
VALUE timeout = Qundef;
|
232
329
|
rb_io_event_t events = 0;
|
233
330
|
|
@@ -264,6 +361,7 @@ io_wait(int argc, VALUE *argv, VALUE io)
|
|
264
361
|
}
|
265
362
|
|
266
363
|
return io_wait_event(io, events, timeout);
|
364
|
+
#endif
|
267
365
|
}
|
268
366
|
|
269
367
|
/*
|
@@ -284,5 +382,7 @@ Init_wait(void)
|
|
284
382
|
|
285
383
|
rb_define_method(rb_cIO, "wait_readable", io_wait_readable, -1);
|
286
384
|
rb_define_method(rb_cIO, "wait_writable", io_wait_writable, -1);
|
385
|
+
#ifdef HAVE_RB_IO_WAIT
|
287
386
|
rb_define_method(rb_cIO, "wait_priority", io_wait_priority, -1);
|
387
|
+
#endif
|
288
388
|
}
|
data/io-wait.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
_VERSION = "0.2.
|
1
|
+
_VERSION = "0.2.1"
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "io-wait"
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.description = %q{Waits until IO is readable or writable without blocking.}
|
11
11
|
spec.homepage = "https://github.com/ruby/io-wait"
|
12
12
|
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new(">=
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
14
14
|
|
15
15
|
spec.metadata["homepage_uri"] = spec.homepage
|
16
16
|
spec.metadata["source_code_uri"] = spec.homepage
|
data/rakelib/version.rake
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: io-wait
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nobu Nakada
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Waits until IO is readable or writable without blocking.
|
14
14
|
email:
|
@@ -28,6 +28,7 @@ files:
|
|
28
28
|
- io-wait.gemspec
|
29
29
|
- rakelib/changelogs.rake
|
30
30
|
- rakelib/epoch.rake
|
31
|
+
- rakelib/sync_tool.rake
|
31
32
|
- rakelib/version.rake
|
32
33
|
homepage: https://github.com/ruby/io-wait
|
33
34
|
licenses:
|
@@ -44,7 +45,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
45
|
requirements:
|
45
46
|
- - ">="
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
+
version: 2.6.0
|
48
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
50
|
requirements:
|
50
51
|
- - ">="
|