io-nonblock 0.2.0 → 0.3.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/ext/io/nonblock/extconf.rb +7 -0
- data/ext/io/nonblock/nonblock.c +46 -25
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72722b1ffc6a232b51665e937ecabe164a15e2dbccdb35628fe158db78e56713
|
4
|
+
data.tar.gz: 491aa2cbbb825667d190e5dca3f3ef44abb7fcc65d2a5080e33f5fa4936142f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c1e8c2abd77710e460dc12c39a89f2bf3e2466208bc422e97ec1891629d71d569c95c8b80beadd0ef5f5673c53f4101f016930038770266b2f62732972f7b65
|
7
|
+
data.tar.gz: 3045f739c5bdcbef2c1335bfd0024842e5be44d0af0a3a90fb49c3ca9151fa02e74520cc854b3207e328b8c1a7f19fde5b580ad121c511590860e484de5b335d
|
data/ext/io/nonblock/extconf.rb
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
require 'mkmf'
|
3
3
|
target = "io/nonblock"
|
4
4
|
|
5
|
+
unless RUBY_ENGINE == 'ruby'
|
6
|
+
File.write("Makefile", dummy_makefile($srcdir).join(""))
|
7
|
+
return
|
8
|
+
end
|
9
|
+
|
10
|
+
have_func("rb_io_descriptor")
|
11
|
+
|
5
12
|
hdr = %w"fcntl.h"
|
6
13
|
if have_macro("O_NONBLOCK", hdr) and
|
7
14
|
(have_macro("F_GETFL", hdr) or have_macro("F_SETFL", hdr))
|
data/ext/io/nonblock/nonblock.c
CHANGED
@@ -17,6 +17,17 @@
|
|
17
17
|
#endif
|
18
18
|
#include <fcntl.h>
|
19
19
|
|
20
|
+
#ifndef HAVE_RB_IO_DESCRIPTOR
|
21
|
+
static int
|
22
|
+
io_descriptor_fallback(VALUE io)
|
23
|
+
{
|
24
|
+
rb_io_t *fptr;
|
25
|
+
GetOpenFile(io, fptr);
|
26
|
+
return fptr->fd;
|
27
|
+
}
|
28
|
+
#define rb_io_descriptor io_descriptor_fallback
|
29
|
+
#endif
|
30
|
+
|
20
31
|
#ifdef F_GETFL
|
21
32
|
static int
|
22
33
|
get_fcntl_flags(int fd)
|
@@ -39,10 +50,8 @@ get_fcntl_flags(int fd)
|
|
39
50
|
static VALUE
|
40
51
|
rb_io_nonblock_p(VALUE io)
|
41
52
|
{
|
42
|
-
|
43
|
-
|
44
|
-
if (get_fcntl_flags(fptr->fd) & O_NONBLOCK)
|
45
|
-
return Qtrue;
|
53
|
+
if (get_fcntl_flags(rb_io_descriptor(io)) & O_NONBLOCK)
|
54
|
+
return Qtrue;
|
46
55
|
return Qfalse;
|
47
56
|
}
|
48
57
|
#else
|
@@ -57,6 +66,8 @@ set_fcntl_flags(int fd, int f)
|
|
57
66
|
rb_sys_fail(0);
|
58
67
|
}
|
59
68
|
|
69
|
+
#ifndef RUBY_IO_NONBLOCK_METHODS
|
70
|
+
|
60
71
|
static int
|
61
72
|
io_nonblock_set(int fd, int f, int nb)
|
62
73
|
{
|
@@ -122,17 +133,23 @@ io_nonblock_set(int fd, int f, int nb)
|
|
122
133
|
*
|
123
134
|
*/
|
124
135
|
static VALUE
|
125
|
-
rb_io_nonblock_set(VALUE
|
136
|
+
rb_io_nonblock_set(VALUE self, VALUE value)
|
126
137
|
{
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
138
|
+
if (RTEST(value)) {
|
139
|
+
rb_io_t *fptr;
|
140
|
+
GetOpenFile(self, fptr);
|
141
|
+
rb_io_set_nonblock(fptr);
|
142
|
+
}
|
143
|
+
else {
|
144
|
+
int descriptor = rb_io_descriptor(self);
|
145
|
+
io_nonblock_set(descriptor, get_fcntl_flags(descriptor), RTEST(value));
|
146
|
+
}
|
147
|
+
|
148
|
+
return self;
|
134
149
|
}
|
135
150
|
|
151
|
+
#endif /* RUBY_IO_NONBLOCK_METHODS */
|
152
|
+
|
136
153
|
static VALUE
|
137
154
|
io_nonblock_restore(VALUE arg)
|
138
155
|
{
|
@@ -152,24 +169,25 @@ io_nonblock_restore(VALUE arg)
|
|
152
169
|
* The original mode is restored after the block is executed.
|
153
170
|
*/
|
154
171
|
static VALUE
|
155
|
-
rb_io_nonblock_block(int argc, VALUE *argv, VALUE
|
172
|
+
rb_io_nonblock_block(int argc, VALUE *argv, VALUE self)
|
156
173
|
{
|
157
174
|
int nb = 1;
|
158
|
-
rb_io_t *fptr;
|
159
|
-
int f, restore[2];
|
160
175
|
|
161
|
-
|
176
|
+
int descriptor = rb_io_descriptor(self);
|
177
|
+
|
162
178
|
if (argc > 0) {
|
163
|
-
|
164
|
-
|
165
|
-
|
179
|
+
VALUE v;
|
180
|
+
rb_scan_args(argc, argv, "01", &v);
|
181
|
+
nb = RTEST(v);
|
166
182
|
}
|
167
|
-
|
168
|
-
|
169
|
-
restore[
|
170
|
-
|
171
|
-
|
172
|
-
|
183
|
+
|
184
|
+
int current_flags = get_fcntl_flags(descriptor);
|
185
|
+
int restore[2] = {descriptor, current_flags};
|
186
|
+
|
187
|
+
if (!io_nonblock_set(descriptor, current_flags, nb))
|
188
|
+
return rb_yield(self);
|
189
|
+
|
190
|
+
return rb_ensure(rb_yield, self, io_nonblock_restore, (VALUE)restore);
|
173
191
|
}
|
174
192
|
#else
|
175
193
|
#define rb_io_nonblock_set rb_f_notimplement
|
@@ -179,7 +197,10 @@ rb_io_nonblock_block(int argc, VALUE *argv, VALUE io)
|
|
179
197
|
void
|
180
198
|
Init_nonblock(void)
|
181
199
|
{
|
200
|
+
#ifndef RUBY_IO_NONBLOCK_METHODS
|
182
201
|
rb_define_method(rb_cIO, "nonblock?", rb_io_nonblock_p, 0);
|
183
202
|
rb_define_method(rb_cIO, "nonblock=", rb_io_nonblock_set, 1);
|
203
|
+
#endif
|
204
|
+
|
184
205
|
rb_define_method(rb_cIO, "nonblock", rb_io_nonblock_block, -1);
|
185
206
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: io-nonblock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nobu Nakada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Enables non-blocking mode with IO class
|
14
14
|
email:
|
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
requirements: []
|
48
|
-
rubygems_version: 3.
|
48
|
+
rubygems_version: 3.5.0.dev
|
49
49
|
signing_key:
|
50
50
|
specification_version: 4
|
51
51
|
summary: Enables non-blocking mode with IO class
|