io-nonblock 0.2.0 → 0.3.1

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: 4fb3f7ad035b8169c589a2ca93f344b83d8b1ed5d8532d48c437a99748689781
4
+ data.tar.gz: a25478e77b6fa3464e98bb9be9810b9e98b2dd40fcf6c6a1c3f025dc75eead4c
5
5
  SHA512:
6
- metadata.gz: 91ecd0eca31b2a6f16e83e5257e0fb43015b7c46b1961c97c9d5639f90dd18460777cd60f80b0ab0e9755dfa5415a1acb028e22394d3db443959d1576b130b69
7
- data.tar.gz: e6a1e5387e7aa86578fe09bc67b26265ab26dd36d442a087bded4c5212bd421348aa1c3e062ee73596e689272a25c1eb44f1738c90738bb0bc17fa807f9d3cd7
6
+ metadata.gz: f3e920fcbf3d3925e8d6b81cffcdb90d0c65ae1a12729a3269ae43bdf7cfe5a838609502e7bc86e51ca6b100622e3a8ac7b7f5c05724ab3cb5e0a08e0ed32af8
7
+ data.tar.gz: bbf610c4f7cc6b609e5a2ef03eab5d2056baf5611a023d1f047883182422df4b2a732c6b573cb7ca54c0ff64e31874631ec0499cb7740d906078f3c3aa61f8bb
@@ -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,14 @@ rb_io_nonblock_block(int argc, VALUE *argv, VALUE io)
179
197
  void
180
198
  Init_nonblock(void)
181
199
  {
200
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
201
+ rb_ext_ractor_safe(true);
202
+ #endif
203
+
204
+ #ifndef RUBY_IO_NONBLOCK_METHODS
182
205
  rb_define_method(rb_cIO, "nonblock?", rb_io_nonblock_p, 0);
183
206
  rb_define_method(rb_cIO, "nonblock=", rb_io_nonblock_set, 1);
207
+ #endif
208
+
184
209
  rb_define_method(rb_cIO, "nonblock", rb_io_nonblock_block, -1);
185
210
  }
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobu Nakada
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-05 00:00:00.000000000 Z
11
+ date: 2024-12-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Enables non-blocking mode with IO class
14
14
  email:
@@ -30,7 +30,7 @@ licenses:
30
30
  metadata:
31
31
  homepage_uri: https://github.com/ruby/io-nonblock
32
32
  source_code_uri: https://github.com/ruby/io-nonblock
33
- post_install_message:
33
+ post_install_message:
34
34
  rdoc_options: []
35
35
  require_paths:
36
36
  - lib
@@ -45,8 +45,8 @@ 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
49
- signing_key:
48
+ rubygems_version: 3.5.11
49
+ signing_key:
50
50
  specification_version: 4
51
51
  summary: Enables non-blocking mode with IO class
52
52
  test_files: []