nio4r 2.5.2 → 2.7.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/workflow.yml +61 -0
  3. data/.mailmap +16 -0
  4. data/.rubocop.yml +30 -11
  5. data/Gemfile +6 -6
  6. data/{CHANGES.md → changes.md} +78 -1
  7. data/examples/echo_server.rb +9 -2
  8. data/ext/libev/Changes +71 -2
  9. data/ext/libev/ev.c +611 -198
  10. data/ext/libev/ev.h +25 -22
  11. data/ext/libev/ev_epoll.c +16 -14
  12. data/ext/libev/ev_iouring.c +694 -0
  13. data/ext/libev/ev_kqueue.c +4 -4
  14. data/ext/libev/ev_linuxaio.c +78 -100
  15. data/ext/libev/ev_poll.c +6 -6
  16. data/ext/libev/ev_port.c +3 -3
  17. data/ext/libev/ev_select.c +6 -6
  18. data/ext/libev/ev_vars.h +34 -0
  19. data/ext/libev/ev_win32.c +2 -2
  20. data/ext/libev/ev_wrap.h +56 -0
  21. data/ext/nio4r/.clang-format +16 -0
  22. data/ext/nio4r/bytebuffer.c +101 -65
  23. data/ext/nio4r/extconf.rb +26 -0
  24. data/ext/nio4r/libev.h +1 -3
  25. data/ext/nio4r/monitor.c +81 -53
  26. data/ext/nio4r/nio4r.h +6 -15
  27. data/ext/nio4r/nio4r_ext.c +1 -1
  28. data/ext/nio4r/org/nio4r/ByteBuffer.java +2 -0
  29. data/ext/nio4r/org/nio4r/Monitor.java +1 -0
  30. data/ext/nio4r/org/nio4r/Selector.java +8 -10
  31. data/ext/nio4r/selector.c +132 -93
  32. data/lib/nio/bytebuffer.rb +10 -0
  33. data/lib/nio/monitor.rb +8 -1
  34. data/lib/nio/selector.rb +27 -10
  35. data/lib/nio/version.rb +6 -1
  36. data/lib/nio.rb +29 -1
  37. data/lib/nio4r.rb +5 -0
  38. data/license.md +77 -0
  39. data/nio4r.gemspec +6 -5
  40. data/rakelib/extension.rake +1 -2
  41. data/readme.md +91 -0
  42. data/spec/nio/acceptables_spec.rb +4 -0
  43. data/spec/nio/bytebuffer_spec.rb +6 -1
  44. data/spec/nio/monitor_spec.rb +7 -0
  45. data/spec/nio/selectables/pipe_spec.rb +6 -0
  46. data/spec/nio/selectables/ssl_socket_spec.rb +7 -0
  47. data/spec/nio/selectables/tcp_socket_spec.rb +7 -0
  48. data/spec/nio/selectables/udp_socket_spec.rb +9 -2
  49. data/spec/nio/selector_spec.rb +16 -1
  50. data/spec/spec_helper.rb +7 -2
  51. data/spec/support/selectable_examples.rb +8 -0
  52. metadata +20 -16
  53. data/.travis.yml +0 -44
  54. data/Guardfile +0 -10
  55. data/README.md +0 -150
  56. data/appveyor.yml +0 -40
@@ -8,8 +8,8 @@ static VALUE cNIO_ByteBuffer_MarkUnsetError = Qnil;
8
8
 
9
9
  /* Allocator/deallocator */
10
10
  static VALUE NIO_ByteBuffer_allocate(VALUE klass);
11
- static void NIO_ByteBuffer_gc_mark(struct NIO_ByteBuffer *byteBuffer);
12
- static void NIO_ByteBuffer_free(struct NIO_ByteBuffer *byteBuffer);
11
+ static void NIO_ByteBuffer_free(void *data);
12
+ static size_t NIO_ByteBuffer_memsize(const void *data);
13
13
 
14
14
  /* Methods */
15
15
  static VALUE NIO_ByteBuffer_initialize(VALUE self, VALUE capacity);
@@ -36,13 +36,33 @@ static VALUE NIO_ByteBuffer_inspect(VALUE self);
36
36
 
37
37
  #define MARK_UNSET -1
38
38
 
39
+ /* Compatibility for Ruby <= 3.1 */
40
+ #ifndef HAVE_RB_IO_DESCRIPTOR
41
+ static int
42
+ io_descriptor_fallback(VALUE io)
43
+ {
44
+ rb_io_t *fptr;
45
+ GetOpenFile(io, fptr);
46
+ return fptr->fd;
47
+ }
48
+ #define rb_io_descriptor io_descriptor_fallback
49
+ #endif
50
+
51
+ static void
52
+ io_set_nonblock(VALUE io)
53
+ {
54
+ rb_io_t *fptr;
55
+ GetOpenFile(io, fptr);
56
+ rb_io_set_nonblock(fptr);
57
+ }
58
+
39
59
  void Init_NIO_ByteBuffer()
40
60
  {
41
61
  mNIO = rb_define_module("NIO");
42
62
  cNIO_ByteBuffer = rb_define_class_under(mNIO, "ByteBuffer", rb_cObject);
43
63
  rb_define_alloc_func(cNIO_ByteBuffer, NIO_ByteBuffer_allocate);
44
64
 
45
- cNIO_ByteBuffer_OverflowError = rb_define_class_under(cNIO_ByteBuffer, "OverflowError", rb_eIOError);
65
+ cNIO_ByteBuffer_OverflowError = rb_define_class_under(cNIO_ByteBuffer, "OverflowError", rb_eIOError);
46
66
  cNIO_ByteBuffer_UnderflowError = rb_define_class_under(cNIO_ByteBuffer, "UnderflowError", rb_eIOError);
47
67
  cNIO_ByteBuffer_MarkUnsetError = rb_define_class_under(cNIO_ByteBuffer, "MarkUnsetError", rb_eIOError);
48
68
 
@@ -72,28 +92,46 @@ void Init_NIO_ByteBuffer()
72
92
  rb_define_method(cNIO_ByteBuffer, "inspect", NIO_ByteBuffer_inspect, 0);
73
93
  }
74
94
 
95
+ static const rb_data_type_t NIO_ByteBuffer_type = {
96
+ "NIO::ByteBuffer",
97
+ {
98
+ NULL, // Nothing to mark
99
+ NIO_ByteBuffer_free,
100
+ NIO_ByteBuffer_memsize,
101
+ },
102
+ 0,
103
+ 0,
104
+ RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
105
+ };
106
+
75
107
  static VALUE NIO_ByteBuffer_allocate(VALUE klass)
76
108
  {
77
109
  struct NIO_ByteBuffer *bytebuffer = (struct NIO_ByteBuffer *)xmalloc(sizeof(struct NIO_ByteBuffer));
78
110
  bytebuffer->buffer = NULL;
79
- return Data_Wrap_Struct(klass, NIO_ByteBuffer_gc_mark, NIO_ByteBuffer_free, bytebuffer);
111
+ return TypedData_Wrap_Struct(klass, &NIO_ByteBuffer_type, bytebuffer);
80
112
  }
81
113
 
82
- static void NIO_ByteBuffer_gc_mark(struct NIO_ByteBuffer *buffer)
114
+ static void NIO_ByteBuffer_free(void *data)
83
115
  {
116
+ struct NIO_ByteBuffer *buffer = (struct NIO_ByteBuffer *)data;
117
+ if (buffer->buffer)
118
+ xfree(buffer->buffer);
119
+ xfree(buffer);
84
120
  }
85
121
 
86
- static void NIO_ByteBuffer_free(struct NIO_ByteBuffer *buffer)
122
+ static size_t NIO_ByteBuffer_memsize(const void *data)
87
123
  {
88
- if(buffer->buffer)
89
- xfree(buffer->buffer);
90
- xfree(buffer);
124
+ const struct NIO_ByteBuffer *buffer = (const struct NIO_ByteBuffer *)data;
125
+ size_t memsize = sizeof(struct NIO_ByteBuffer);
126
+ if (buffer->buffer)
127
+ memsize += buffer->capacity;
128
+ return memsize;
91
129
  }
92
130
 
93
131
  static VALUE NIO_ByteBuffer_initialize(VALUE self, VALUE capacity)
94
132
  {
95
133
  struct NIO_ByteBuffer *buffer;
96
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
134
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
97
135
 
98
136
  buffer->capacity = NUM2INT(capacity);
99
137
  buffer->buffer = xmalloc(buffer->capacity);
@@ -106,7 +144,7 @@ static VALUE NIO_ByteBuffer_initialize(VALUE self, VALUE capacity)
106
144
  static VALUE NIO_ByteBuffer_clear(VALUE self)
107
145
  {
108
146
  struct NIO_ByteBuffer *buffer;
109
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
147
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
110
148
 
111
149
  memset(buffer->buffer, 0, buffer->capacity);
112
150
 
@@ -120,7 +158,7 @@ static VALUE NIO_ByteBuffer_clear(VALUE self)
120
158
  static VALUE NIO_ByteBuffer_get_position(VALUE self)
121
159
  {
122
160
  struct NIO_ByteBuffer *buffer;
123
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
161
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
124
162
 
125
163
  return INT2NUM(buffer->position);
126
164
  }
@@ -129,21 +167,21 @@ static VALUE NIO_ByteBuffer_set_position(VALUE self, VALUE new_position)
129
167
  {
130
168
  int pos;
131
169
  struct NIO_ByteBuffer *buffer;
132
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
170
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
133
171
 
134
172
  pos = NUM2INT(new_position);
135
173
 
136
- if(pos < 0) {
174
+ if (pos < 0) {
137
175
  rb_raise(rb_eArgError, "negative position given");
138
176
  }
139
177
 
140
- if(pos > buffer->limit) {
178
+ if (pos > buffer->limit) {
141
179
  rb_raise(rb_eArgError, "specified position exceeds limit");
142
180
  }
143
181
 
144
182
  buffer->position = pos;
145
183
 
146
- if(buffer->mark > buffer->position) {
184
+ if (buffer->mark > buffer->position) {
147
185
  buffer->mark = MARK_UNSET;
148
186
  }
149
187
 
@@ -153,7 +191,7 @@ static VALUE NIO_ByteBuffer_set_position(VALUE self, VALUE new_position)
153
191
  static VALUE NIO_ByteBuffer_get_limit(VALUE self)
154
192
  {
155
193
  struct NIO_ByteBuffer *buffer;
156
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
194
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
157
195
 
158
196
  return INT2NUM(buffer->limit);
159
197
  }
@@ -162,25 +200,25 @@ static VALUE NIO_ByteBuffer_set_limit(VALUE self, VALUE new_limit)
162
200
  {
163
201
  int lim;
164
202
  struct NIO_ByteBuffer *buffer;
165
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
203
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
166
204
 
167
205
  lim = NUM2INT(new_limit);
168
206
 
169
- if(lim < 0) {
207
+ if (lim < 0) {
170
208
  rb_raise(rb_eArgError, "negative limit given");
171
209
  }
172
210
 
173
- if(lim > buffer->capacity) {
211
+ if (lim > buffer->capacity) {
174
212
  rb_raise(rb_eArgError, "specified limit exceeds capacity");
175
213
  }
176
214
 
177
215
  buffer->limit = lim;
178
216
 
179
- if(buffer->position > lim) {
217
+ if (buffer->position > lim) {
180
218
  buffer->position = lim;
181
219
  }
182
220
 
183
- if(buffer->mark > lim) {
221
+ if (buffer->mark > lim) {
184
222
  buffer->mark = MARK_UNSET;
185
223
  }
186
224
 
@@ -190,7 +228,7 @@ static VALUE NIO_ByteBuffer_set_limit(VALUE self, VALUE new_limit)
190
228
  static VALUE NIO_ByteBuffer_capacity(VALUE self)
191
229
  {
192
230
  struct NIO_ByteBuffer *buffer;
193
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
231
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
194
232
 
195
233
  return INT2NUM(buffer->capacity);
196
234
  }
@@ -198,7 +236,7 @@ static VALUE NIO_ByteBuffer_capacity(VALUE self)
198
236
  static VALUE NIO_ByteBuffer_remaining(VALUE self)
199
237
  {
200
238
  struct NIO_ByteBuffer *buffer;
201
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
239
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
202
240
 
203
241
  return INT2NUM(buffer->limit - buffer->position);
204
242
  }
@@ -206,7 +244,7 @@ static VALUE NIO_ByteBuffer_remaining(VALUE self)
206
244
  static VALUE NIO_ByteBuffer_full(VALUE self)
207
245
  {
208
246
  struct NIO_ByteBuffer *buffer;
209
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
247
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
210
248
 
211
249
  return buffer->position == buffer->limit ? Qtrue : Qfalse;
212
250
  }
@@ -216,21 +254,21 @@ static VALUE NIO_ByteBuffer_get(int argc, VALUE *argv, VALUE self)
216
254
  int len;
217
255
  VALUE length, result;
218
256
  struct NIO_ByteBuffer *buffer;
219
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
257
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
220
258
 
221
259
  rb_scan_args(argc, argv, "01", &length);
222
260
 
223
- if(length == Qnil) {
261
+ if (length == Qnil) {
224
262
  len = buffer->limit - buffer->position;
225
263
  } else {
226
264
  len = NUM2INT(length);
227
265
  }
228
266
 
229
- if(len < 0) {
267
+ if (len < 0) {
230
268
  rb_raise(rb_eArgError, "negative length given");
231
269
  }
232
270
 
233
- if(len > buffer->limit - buffer->position) {
271
+ if (len > buffer->limit - buffer->position) {
234
272
  rb_raise(cNIO_ByteBuffer_UnderflowError, "not enough data in buffer");
235
273
  }
236
274
 
@@ -244,15 +282,15 @@ static VALUE NIO_ByteBuffer_fetch(VALUE self, VALUE index)
244
282
  {
245
283
  int i;
246
284
  struct NIO_ByteBuffer *buffer;
247
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
285
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
248
286
 
249
287
  i = NUM2INT(index);
250
288
 
251
- if(i < 0) {
289
+ if (i < 0) {
252
290
  rb_raise(rb_eArgError, "negative index given");
253
291
  }
254
292
 
255
- if(i >= buffer->limit) {
293
+ if (i >= buffer->limit) {
256
294
  rb_raise(rb_eArgError, "specified index exceeds limit");
257
295
  }
258
296
 
@@ -263,12 +301,12 @@ static VALUE NIO_ByteBuffer_put(VALUE self, VALUE string)
263
301
  {
264
302
  long length;
265
303
  struct NIO_ByteBuffer *buffer;
266
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
304
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
267
305
 
268
306
  StringValue(string);
269
307
  length = RSTRING_LEN(string);
270
308
 
271
- if(length > buffer->limit - buffer->position) {
309
+ if (length > buffer->limit - buffer->position) {
272
310
  rb_raise(cNIO_ByteBuffer_OverflowError, "buffer is full");
273
311
  }
274
312
 
@@ -281,22 +319,22 @@ static VALUE NIO_ByteBuffer_put(VALUE self, VALUE string)
281
319
  static VALUE NIO_ByteBuffer_read_from(VALUE self, VALUE io)
282
320
  {
283
321
  struct NIO_ByteBuffer *buffer;
284
- rb_io_t *fptr;
285
322
  ssize_t nbytes, bytes_read;
286
323
 
287
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
288
- GetOpenFile(rb_convert_type(io, T_FILE, "IO", "to_io"), fptr);
289
- rb_io_set_nonblock(fptr);
324
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
325
+
326
+ io = rb_convert_type(io, T_FILE, "IO", "to_io");
327
+ io_set_nonblock(io);
290
328
 
291
329
  nbytes = buffer->limit - buffer->position;
292
- if(nbytes == 0) {
330
+ if (nbytes == 0) {
293
331
  rb_raise(cNIO_ByteBuffer_OverflowError, "buffer is full");
294
332
  }
295
333
 
296
- bytes_read = read(FPTR_TO_FD(fptr), buffer->buffer + buffer->position, nbytes);
334
+ bytes_read = read(rb_io_descriptor(io), buffer->buffer + buffer->position, nbytes);
297
335
 
298
- if(bytes_read < 0) {
299
- if(errno == EAGAIN) {
336
+ if (bytes_read < 0) {
337
+ if (errno == EAGAIN) {
300
338
  return INT2NUM(0);
301
339
  } else {
302
340
  rb_sys_fail("write");
@@ -305,28 +343,27 @@ static VALUE NIO_ByteBuffer_read_from(VALUE self, VALUE io)
305
343
 
306
344
  buffer->position += bytes_read;
307
345
 
308
- return INT2NUM(bytes_read);
346
+ return SIZET2NUM(bytes_read);
309
347
  }
310
348
 
311
349
  static VALUE NIO_ByteBuffer_write_to(VALUE self, VALUE io)
312
350
  {
313
351
  struct NIO_ByteBuffer *buffer;
314
- rb_io_t *fptr;
315
352
  ssize_t nbytes, bytes_written;
316
353
 
317
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
318
- GetOpenFile(rb_convert_type(io, T_FILE, "IO", "to_io"), fptr);
319
- rb_io_set_nonblock(fptr);
354
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
355
+ io = rb_convert_type(io, T_FILE, "IO", "to_io");
356
+ io_set_nonblock(io);
320
357
 
321
358
  nbytes = buffer->limit - buffer->position;
322
- if(nbytes == 0) {
359
+ if (nbytes == 0) {
323
360
  rb_raise(cNIO_ByteBuffer_UnderflowError, "no data remaining in buffer");
324
361
  }
325
362
 
326
- bytes_written = write(FPTR_TO_FD(fptr), buffer->buffer + buffer->position, nbytes);
363
+ bytes_written = write(rb_io_descriptor(io), buffer->buffer + buffer->position, nbytes);
327
364
 
328
- if(bytes_written < 0) {
329
- if(errno == EAGAIN) {
365
+ if (bytes_written < 0) {
366
+ if (errno == EAGAIN) {
330
367
  return INT2NUM(0);
331
368
  } else {
332
369
  rb_sys_fail("write");
@@ -335,13 +372,13 @@ static VALUE NIO_ByteBuffer_write_to(VALUE self, VALUE io)
335
372
 
336
373
  buffer->position += bytes_written;
337
374
 
338
- return INT2NUM(bytes_written);
375
+ return SIZET2NUM(bytes_written);
339
376
  }
340
377
 
341
378
  static VALUE NIO_ByteBuffer_flip(VALUE self)
342
379
  {
343
380
  struct NIO_ByteBuffer *buffer;
344
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
381
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
345
382
 
346
383
  buffer->limit = buffer->position;
347
384
  buffer->position = 0;
@@ -353,7 +390,7 @@ static VALUE NIO_ByteBuffer_flip(VALUE self)
353
390
  static VALUE NIO_ByteBuffer_rewind(VALUE self)
354
391
  {
355
392
  struct NIO_ByteBuffer *buffer;
356
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
393
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
357
394
 
358
395
  buffer->position = 0;
359
396
  buffer->mark = MARK_UNSET;
@@ -364,7 +401,7 @@ static VALUE NIO_ByteBuffer_rewind(VALUE self)
364
401
  static VALUE NIO_ByteBuffer_mark(VALUE self)
365
402
  {
366
403
  struct NIO_ByteBuffer *buffer;
367
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
404
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
368
405
 
369
406
  buffer->mark = buffer->position;
370
407
  return self;
@@ -373,9 +410,9 @@ static VALUE NIO_ByteBuffer_mark(VALUE self)
373
410
  static VALUE NIO_ByteBuffer_reset(VALUE self)
374
411
  {
375
412
  struct NIO_ByteBuffer *buffer;
376
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
413
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
377
414
 
378
- if(buffer->mark < 0) {
415
+ if (buffer->mark < 0) {
379
416
  rb_raise(cNIO_ByteBuffer_MarkUnsetError, "mark has not been set");
380
417
  } else {
381
418
  buffer->position = buffer->mark;
@@ -387,7 +424,7 @@ static VALUE NIO_ByteBuffer_reset(VALUE self)
387
424
  static VALUE NIO_ByteBuffer_compact(VALUE self)
388
425
  {
389
426
  struct NIO_ByteBuffer *buffer;
390
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
427
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
391
428
 
392
429
  memmove(buffer->buffer, buffer->buffer + buffer->position, buffer->limit - buffer->position);
393
430
  buffer->position = buffer->limit - buffer->position;
@@ -400,10 +437,10 @@ static VALUE NIO_ByteBuffer_each(VALUE self)
400
437
  {
401
438
  int i;
402
439
  struct NIO_ByteBuffer *buffer;
403
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
440
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
404
441
 
405
- if(rb_block_given_p()) {
406
- for(i = 0; i < buffer->limit; i++) {
442
+ if (rb_block_given_p()) {
443
+ for (i = 0; i < buffer->limit; i++) {
407
444
  rb_yield(INT2NUM(buffer->buffer[i]));
408
445
  }
409
446
  } else {
@@ -416,14 +453,13 @@ static VALUE NIO_ByteBuffer_each(VALUE self)
416
453
  static VALUE NIO_ByteBuffer_inspect(VALUE self)
417
454
  {
418
455
  struct NIO_ByteBuffer *buffer;
419
- Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
456
+ TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
420
457
 
421
458
  return rb_sprintf(
422
459
  "#<%s:%p @position=%d @limit=%d @capacity=%d>",
423
460
  rb_class2name(CLASS_OF(self)),
424
- (void*)self,
461
+ (void *)self,
425
462
  buffer->position,
426
463
  buffer->limit,
427
- buffer->capacity
428
- );
464
+ buffer->capacity);
429
465
  }
data/ext/nio4r/extconf.rb CHANGED
@@ -1,9 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Released under the MIT License.
4
+ # Copyright, 2011-2020, by Tony Arcieri.
5
+ # Copyright, 2014, by Hiroshi Shibata.
6
+ # Copyright, 2014, by Sergey Avseyev.
7
+ # Copyright, 2015, by Daniel Berger.
8
+ # Copyright, 2017, by Jun Aruga.
9
+ # Copyright, 2017, by Usaku Nakamura.
10
+ # Copyright, 2017, by Lars Kanis.
11
+ # Copyright, 2019-2023, by Samuel Williams.
12
+ # Copyright, 2020, by Gregory Longtin.
13
+ # Copyright, 2020, by Boaz Segev.
14
+ # Copyright, 2020, by Joao Fernandes.
15
+ # Copyright, 2021, by Jeffrey Martin.
16
+
3
17
  require "rubygems"
4
18
 
5
19
  # Write a dummy Makefile on Windows because we use the pure Ruby implementation there
6
20
  if Gem.win_platform?
21
+ begin
22
+ require "devkit" if RUBY_PLATFORM.include?("mingw")
23
+ rescue LoadError => e
24
+ end
7
25
  File.write("Makefile", "all install::\n")
8
26
  File.write("nio4r_ext.so", "")
9
27
  exit
@@ -12,8 +30,10 @@ end
12
30
  require "mkmf"
13
31
 
14
32
  have_header("unistd.h")
33
+ have_func("rb_io_descriptor")
15
34
 
16
35
  $defs << "-DEV_USE_LINUXAIO" if have_header("linux/aio_abi.h")
36
+ $defs << "-DEV_USE_IOURING" if have_header("linux/io_uring.h")
17
37
  $defs << "-DEV_USE_SELECT" if have_header("sys/select.h")
18
38
  $defs << "-DEV_USE_POLL" if have_type("port_event_t", "poll.h")
19
39
  $defs << "-DEV_USE_EPOLL" if have_header("sys/epoll.h")
@@ -21,7 +41,13 @@ $defs << "-DEV_USE_KQUEUE" if have_header("sys/event.h") && have_header("s
21
41
  $defs << "-DEV_USE_PORT" if have_type("port_event_t", "port.h")
22
42
  $defs << "-DHAVE_SYS_RESOURCE_H" if have_header("sys/resource.h")
23
43
 
44
+ $defs << "-DEV_STANDALONE" # prevent libev from assuming "config.h" exists
45
+
24
46
  CONFIG["optflags"] << " -fno-strict-aliasing" unless RUBY_PLATFORM =~ /mswin/
25
47
 
48
+ if RUBY_PLATFORM =~ /darwin/
49
+ $DLDFLAGS.gsub!(/\-arch\s+[^\s]+/, "")
50
+ end
51
+
26
52
  dir_config "nio4r_ext"
27
53
  create_makefile "nio4r_ext"
data/ext/nio4r/libev.h CHANGED
@@ -1,9 +1,7 @@
1
- #define EV_STANDALONE /* keeps ev from requiring config.h */
2
-
3
1
  #ifdef _WIN32
4
2
  #define EV_SELECT_IS_WINSOCKET 1
5
3
  #define EV_USE_MONOTONIC 0
6
4
  #define EV_USE_REALTIME 0
7
5
  #endif
8
6
 
9
- #include "../libev/ev.h"
7
+ #include "../libev/ev.h"