io-nonblock 0.2.0 → 0.3.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
  SHA256:
3
- metadata.gz: 147c4c19a532bb8ea1192a306c5c50ab2e95c0c9184048e2918af930733f7332
4
- data.tar.gz: 1db9af6d8cf78b3779113e95e44b28376bd6788b0be957e7a917084bd2c5706d
3
+ metadata.gz: 72722b1ffc6a232b51665e937ecabe164a15e2dbccdb35628fe158db78e56713
4
+ data.tar.gz: 491aa2cbbb825667d190e5dca3f3ef44abb7fcc65d2a5080e33f5fa4936142f0
5
5
  SHA512:
6
- metadata.gz: 91ecd0eca31b2a6f16e83e5257e0fb43015b7c46b1961c97c9d5639f90dd18460777cd60f80b0ab0e9755dfa5415a1acb028e22394d3db443959d1576b130b69
7
- data.tar.gz: e6a1e5387e7aa86578fe09bc67b26265ab26dd36d442a087bded4c5212bd421348aa1c3e062ee73596e689272a25c1eb44f1738c90738bb0bc17fa807f9d3cd7
6
+ metadata.gz: 9c1e8c2abd77710e460dc12c39a89f2bf3e2466208bc422e97ec1891629d71d569c95c8b80beadd0ef5f5673c53f4101f016930038770266b2f62732972f7b65
7
+ data.tar.gz: 3045f739c5bdcbef2c1335bfd0024842e5be44d0af0a3a90fb49c3ca9151fa02e74520cc854b3207e328b8c1a7f19fde5b580ad121c511590860e484de5b335d
@@ -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))
@@ -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
- rb_io_t *fptr;
43
- GetOpenFile(io, fptr);
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 io, VALUE nb)
136
+ rb_io_nonblock_set(VALUE self, VALUE value)
126
137
  {
127
- rb_io_t *fptr;
128
- GetOpenFile(io, fptr);
129
- if (RTEST(nb))
130
- rb_io_set_nonblock(fptr);
131
- else
132
- io_nonblock_set(fptr->fd, get_fcntl_flags(fptr->fd), RTEST(nb));
133
- return io;
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 io)
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
- GetOpenFile(io, fptr);
176
+ int descriptor = rb_io_descriptor(self);
177
+
162
178
  if (argc > 0) {
163
- VALUE v;
164
- rb_scan_args(argc, argv, "01", &v);
165
- nb = RTEST(v);
179
+ VALUE v;
180
+ rb_scan_args(argc, argv, "01", &v);
181
+ nb = RTEST(v);
166
182
  }
167
- f = get_fcntl_flags(fptr->fd);
168
- restore[0] = fptr->fd;
169
- restore[1] = f;
170
- if (!io_nonblock_set(fptr->fd, f, nb))
171
- return rb_yield(io);
172
- return rb_ensure(rb_yield, io, io_nonblock_restore, (VALUE)restore);
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.2.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: 2022-12-05 00:00:00.000000000 Z
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.4.0.dev
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