io-event 0.2.3 → 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: c0978ed0fd5d85399283cd8c4bb296f44662af2fad9a67e992000f3214898f5a
4
- data.tar.gz: 154503dd7f0f52dc2ad166d262bb371f81fc60e148dd0c74eadb65051bc5e71f
3
+ metadata.gz: 5ea156f474e12257bd5b2db77f8f647d8291a0e4fd6c3d78914e1f26abd35c52
4
+ data.tar.gz: fe0ebd9fce449827c06faf4d59d2c1ca86e62e9ccdbada21389646cd2133d7f6
5
5
  SHA512:
6
- metadata.gz: a54cab01e6c314890284d9640e3404f6a34706402b2cbf6383bff69c6c341c0c84c56f64d1feebb46e875539e1baab95749ce7f41e5f15ae13af0d8b9e1e0c1a
7
- data.tar.gz: 7b2891a70e1703616f104410d4f86898a5d9c2bfa6c8ecde0295bea1bfed6ee7efada50568bdf8f841e0360db370d209259f66f2cb17f97d2be47db8a1c2e101
6
+ metadata.gz: ca948d973ad94bfbb9b6c166741e5cb5cd75439bfb47d07809a8d41fdecebdf4e9df9f0862aaa716ad444ab5ab9bf4b1cc1204698a5e7bd1a7f0ae6465c0dba2
7
+ data.tar.gz: 1e27d5073302b93a1ef9d5b51c6f8a5945546cc95e2b54b0985a746fc2810318c5c4c0f1b5cbc20686f277362cf197d2162a4f95d2b4bec2ee00e11f84ed2b1a
data/ext/IO_Event.bundle CHANGED
Binary file
data/ext/Makefile CHANGED
@@ -3,6 +3,7 @@ SHELL = /bin/sh
3
3
 
4
4
  # V=0 quiet, V=1 verbose. other values don't work.
5
5
  V = 0
6
+ V0 = $(V:0=)
6
7
  Q1 = $(V:1=)
7
8
  Q = $(Q1:0=@)
8
9
  ECHO1 = $(V:1=@ :)
@@ -12,12 +13,12 @@ NULLCMD = :
12
13
  #### Start of system configuration section. ####
13
14
 
14
15
  srcdir = .
15
- topdir = /Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0
16
+ topdir = /Users/samuel/.rubies/ruby-head/include/ruby-3.1.0
16
17
  hdrdir = $(topdir)
17
- arch_hdrdir = /Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/arm64-darwin21
18
+ arch_hdrdir = /Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21
18
19
  PATH_SEPARATOR = :
19
20
  VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby:$(srcdir)/io/event:$(srcdir)/io/event/selector
20
- prefix = $(DESTDIR)/Users/samuel/.rubies/ruby-3.0.3
21
+ prefix = $(DESTDIR)/Users/samuel/.rubies/ruby-head
21
22
  rubysitearchprefix = $(rubylibprefix)/$(sitearch)
22
23
  rubyarchprefix = $(rubylibprefix)/$(arch)
23
24
  rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
@@ -50,8 +51,8 @@ dvidir = $(docdir)
50
51
  htmldir = $(docdir)
51
52
  infodir = $(datarootdir)/info
52
53
  docdir = $(datarootdir)/doc/$(PACKAGE)
53
- oldincludedir = $(SDKROOT)/usr/include
54
- includedir = $(prefix)/include
54
+ oldincludedir = $(DESTDIR)/usr/include
55
+ includedir = $(SDKROOT)$(prefix)/include
55
56
  runstatedir = $(localstatedir)/run
56
57
  localstatedir = $(prefix)/var
57
58
  sharedstatedir = $(prefix)/com
@@ -65,33 +66,33 @@ archdir = $(rubyarchdir)
65
66
 
66
67
 
67
68
  CC_WRAPPER =
68
- CC = clang -fdeclspec
69
- CXX = clang++ -fdeclspec
69
+ CC = clang
70
+ CXX = clang++
70
71
  LIBRUBY = $(LIBRUBY_A)
71
72
  LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
72
73
  LIBRUBYARG_SHARED =
73
- LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -framework Security -framework Foundation $(MAINLIBS)
74
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -framework CoreFoundation $(MAINLIBS)
74
75
  empty =
75
76
  OUTFLAG = -o $(empty)
76
77
  COUTFLAG = -o $(empty)
77
78
  CSRCFLAG = $(empty)
78
79
 
79
80
  RUBY_EXTCONF_H = extconf.h
80
- cflags = $(optflags) $(debugflags) $(warnflags)
81
+ cflags = -fdeclspec $(optflags) $(debugflags) $(warnflags)
81
82
  cxxflags =
82
- optflags = -O3
83
+ optflags = -O3 -fno-fast-math
83
84
  debugflags = -ggdb3
84
- warnflags = -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens
85
+ warnflags = -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef
85
86
  cppflags =
86
87
  CCDLFLAGS = -fno-common
87
- CFLAGS = $(CCDLFLAGS) $(cflags) -pipe -Wall $(ARCH_FLAG)
88
+ CFLAGS = $(CCDLFLAGS) $(cflags) -pipe -Wall $(ARCH_FLAG)
88
89
  INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
89
90
  DEFS =
90
- CPPFLAGS = -DRUBY_EXTCONF_H=\"$(RUBY_EXTCONF_H)\" -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT $(DEFS) $(cppflags)
91
- CXXFLAGS = $(CCDLFLAGS) $(ARCH_FLAG)
92
- ldflags = -L. -fstack-protector-strong -L/opt/local/lib
93
- dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -L/opt/local/lib
94
- ARCH_FLAG = -m64
91
+ CPPFLAGS = -DRUBY_EXTCONF_H=\"$(RUBY_EXTCONF_H)\" -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT $(DEFS) $(cppflags)
92
+ CXXFLAGS = $(CCDLFLAGS) -fdeclspec $(ARCH_FLAG)
93
+ ldflags = -L. -fstack-protector-strong
94
+ dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress
95
+ ARCH_FLAG =
95
96
  DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
96
97
  LDSHARED = $(CC) -dynamic -bundle
97
98
  LDSHAREDXX = $(CXX) -dynamic -bundle
@@ -99,7 +100,7 @@ AR = ar
99
100
  EXEEXT =
100
101
 
101
102
  RUBY_INSTALL_NAME = $(RUBY_BASE_NAME)
102
- RUBY_SO_NAME = ruby.3.0
103
+ RUBY_SO_NAME = ruby.3.1
103
104
  RUBYW_INSTALL_NAME =
104
105
  RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
105
106
  RUBYW_BASE_NAME = rubyw
@@ -107,13 +108,13 @@ RUBY_BASE_NAME = ruby
107
108
 
108
109
  arch = arm64-darwin21
109
110
  sitearch = $(arch)
110
- ruby_version = 3.0.0
111
+ ruby_version = 3.1.0
111
112
  ruby = $(bindir)/$(RUBY_BASE_NAME)
112
113
  RUBY = $(ruby)
113
114
  ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/backward.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h $(RUBY_EXTCONF_H)
114
115
 
115
116
  RM = rm -f
116
- RM_RF = $(RUBY) -run -e rm -- -rf
117
+ RM_RF = rm -fr
117
118
  RMDIRS = rmdir -p
118
119
  MAKEDIRS = /opt/local/bin/gmkdir -p
119
120
  INSTALL = /opt/local/bin/ginstall -c
@@ -125,8 +126,8 @@ TOUCH = exit >
125
126
  #### End of system configuration section. ####
126
127
 
127
128
  preload =
128
- libpath = . $(libdir) /opt/local/lib
129
- LIBPATH = -L. -L$(libdir) -L/opt/local/lib
129
+ libpath = . $(libdir)
130
+ LIBPATH = -L. -L$(libdir)
130
131
  DEFFILE =
131
132
 
132
133
  CLEANFILES = mkmf.log
@@ -159,7 +160,7 @@ HDRDIR = $(sitehdrdir)$(target_prefix)
159
160
  ARCHHDRDIR = $(sitearchhdrdir)$(target_prefix)
160
161
  TARGET_SO_DIR =
161
162
  TARGET_SO = $(TARGET_SO_DIR)$(DLLIB)
162
- CLEANLIBS = $(TARGET_SO)
163
+ CLEANLIBS = $(TARGET_SO) $(TARGET_SO).dSYM
163
164
  CLEANOBJS = *.o *.bak
164
165
 
165
166
  all: $(DLLIB)
@@ -172,7 +173,7 @@ clean-rb-default::
172
173
  clean-rb::
173
174
  clean-so::
174
175
  clean: clean-so clean-static clean-rb-default clean-rb
175
- -$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
176
+ -$(Q)$(RM_RF) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
176
177
 
177
178
  distclean-rb-default::
178
179
  distclean-rb::
data/ext/event.o CHANGED
Binary file
data/ext/extconf.h CHANGED
@@ -1,6 +1,10 @@
1
1
  #ifndef EXTCONF_H
2
2
  #define EXTCONF_H
3
3
  #define HAVE_RB_EXT_RACTOR_SAFE 1
4
+ #define HAVE__RB_FIBER_TRANSFER 1
4
5
  #define HAVE_SYS_EVENT_H 1
6
+ #define HAVE_RB_IO_DESCRIPTOR 1
5
7
  #define HAVE_RB_FIBER_CURRENT 1
8
+ #define HAVE__RB_FIBER_RAISE 1
9
+ #define HAVE_RUBY_IO_BUFFER_H 1
6
10
  #endif
data/ext/interrupt.o CHANGED
Binary file
@@ -115,7 +115,7 @@ VALUE IO_Event_Selector_EPoll_initialize(VALUE self, VALUE loop) {
115
115
  int result = epoll_create1(EPOLL_CLOEXEC);
116
116
 
117
117
  if (result == -1) {
118
- rb_sys_fail("epoll_create");
118
+ rb_sys_fail("IO_Event_Selector_EPoll_initialize:epoll_create");
119
119
  } else {
120
120
  data->descriptor = result;
121
121
 
@@ -241,7 +241,7 @@ VALUE IO_Event_Selector_EPoll_process_wait(VALUE self, VALUE fiber, VALUE pid, V
241
241
  int result = epoll_ctl(data->descriptor, EPOLL_CTL_ADD, process_wait_arguments.descriptor, &event);
242
242
 
243
243
  if (result == -1) {
244
- rb_sys_fail("epoll_ctl(process_wait)");
244
+ rb_sys_fail("IO_Event_Selector_EPoll_process_wait:epoll_ctl");
245
245
  }
246
246
 
247
247
  return rb_ensure(process_wait_transfer, (VALUE)&process_wait_arguments, process_wait_ensure, (VALUE)&process_wait_arguments);
@@ -326,13 +326,13 @@ VALUE IO_Event_Selector_EPoll_io_wait(VALUE self, VALUE fiber, VALUE io, VALUE e
326
326
  rb_update_max_fd(duplicate);
327
327
 
328
328
  if (descriptor == -1)
329
- rb_sys_fail("dup");
329
+ rb_sys_fail("IO_Event_Selector_EPoll_io_wait:dup");
330
330
 
331
331
  result = epoll_ctl(data->descriptor, EPOLL_CTL_ADD, descriptor, &event);
332
332
  }
333
333
 
334
334
  if (result == -1) {
335
- rb_sys_fail("epoll_ctl");
335
+ rb_sys_fail("IO_Event_Selector_EPoll_io_wait:epoll_ctl");
336
336
  }
337
337
 
338
338
  struct io_wait_arguments io_wait_arguments = {
@@ -370,23 +370,24 @@ VALUE io_read_loop(VALUE _arguments) {
370
370
  size_t offset = 0;
371
371
  size_t length = arguments->length;
372
372
 
373
- while (length > 0) {
373
+ while (true) {
374
374
  size_t maximum_size = size - offset;
375
375
  ssize_t result = read(arguments->descriptor, (char*)base+offset, maximum_size);
376
376
 
377
- if (result == 0) {
378
- break;
379
- } else if (result > 0) {
377
+ if (result > 0) {
380
378
  offset += result;
379
+ if ((size_t)result >= length) break;
381
380
  length -= result;
382
- } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
381
+ } else if (result == 0) {
382
+ break;
383
+ } else if (length > 0 && IO_Event_try_again(-result)) {
383
384
  IO_Event_Selector_EPoll_io_wait(arguments->self, arguments->fiber, arguments->io, RB_INT2NUM(IO_EVENT_READABLE));
384
385
  } else {
385
- rb_sys_fail("IO_Event_Selector_EPoll_io_read");
386
+ return rb_fiber_scheduler_io_result(-1, -result);
386
387
  }
387
388
  }
388
389
 
389
- return SIZET2NUM(offset);
390
+ return rb_fiber_scheduler_io_result(offset, 0);
390
391
  }
391
392
 
392
393
  static
@@ -445,20 +446,24 @@ VALUE io_write_loop(VALUE _arguments) {
445
446
  rb_raise(rb_eRuntimeError, "Length exceeds size of buffer!");
446
447
  }
447
448
 
448
- while (length > 0) {
449
- ssize_t result = write(arguments->descriptor, (char*)base+offset, length);
449
+ while (true) {
450
+ size_t maximum_size = size - offset;
451
+ ssize_t result = write(arguments->descriptor, (char*)base+offset, maximum_size);
450
452
 
451
- if (result >= 0) {
453
+ if (result > 0) {
452
454
  offset += result;
455
+ if ((size_t)result >= length) break;
453
456
  length -= result;
454
- } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
457
+ } else if (result == 0) {
458
+ break;
459
+ } else if (length > 0 && IO_Event_try_again(errno)) {
455
460
  IO_Event_Selector_EPoll_io_wait(arguments->self, arguments->fiber, arguments->io, RB_INT2NUM(IO_EVENT_WRITABLE));
456
461
  } else {
457
- rb_sys_fail("IO_Event_Selector_EPoll_io_write");
462
+ return rb_fiber_scheduler_io_result(-1, errno);
458
463
  }
459
464
  }
460
465
 
461
- return SIZET2NUM(offset);
466
+ return rb_fiber_scheduler_io_result(offset, 0);
462
467
  };
463
468
 
464
469
  static
@@ -26,6 +26,13 @@
26
26
  #include <time.h>
27
27
  #include <errno.h>
28
28
 
29
+ enum {
30
+ DEBUG = 0,
31
+ DEBUG_IO_READ = 0,
32
+ DEBUG_IO_WRITE = 0,
33
+ DEBUG_IO_WAIT = 0
34
+ };
35
+
29
36
  static VALUE IO_Event_Selector_KQueue = Qnil;
30
37
 
31
38
  enum {KQUEUE_MAX_EVENTS = 64};
@@ -95,7 +102,7 @@ VALUE IO_Event_Selector_KQueue_initialize(VALUE self, VALUE loop) {
95
102
  int result = kqueue();
96
103
 
97
104
  if (result == -1) {
98
- rb_sys_fail("kqueue");
105
+ rb_sys_fail("IO_Event_Selector_KQueue_initialize:kqueue");
99
106
  } else {
100
107
  ioctl(result, FIOCLEX);
101
108
  data->descriptor = result;
@@ -195,7 +202,7 @@ int process_add_filters(int descriptor, int ident, VALUE fiber) {
195
202
  return 0;
196
203
  }
197
204
 
198
- rb_sys_fail("kevent(process_add_filters)");
205
+ rb_sys_fail("process_add_filters:kevent");
199
206
  }
200
207
 
201
208
  return 1;
@@ -289,7 +296,7 @@ int io_add_filters(int descriptor, int ident, int events, VALUE fiber) {
289
296
  int result = kevent(descriptor, kevents, count, NULL, 0, NULL);
290
297
 
291
298
  if (result == -1) {
292
- rb_sys_fail("kevent(io_add_filters)");
299
+ rb_sys_fail("io_add_filters:kevent");
293
300
  }
294
301
 
295
302
  return events;
@@ -363,6 +370,8 @@ VALUE IO_Event_Selector_KQueue_io_wait(VALUE self, VALUE fiber, VALUE io, VALUE
363
370
  .descriptor = descriptor,
364
371
  };
365
372
 
373
+ if (DEBUG_IO_WAIT) fprintf(stderr, "IO_Event_Selector_KQueue_io_wait descriptor=%d\n", descriptor);
374
+
366
375
  return rb_rescue(io_wait_transfer, (VALUE)&io_wait_arguments, io_wait_rescue, (VALUE)&io_wait_arguments);
367
376
  }
368
377
 
@@ -392,23 +401,31 @@ VALUE io_read_loop(VALUE _arguments) {
392
401
  size_t offset = 0;
393
402
  size_t length = arguments->length;
394
403
 
395
- while (length > 0) {
404
+ if (DEBUG_IO_READ) fprintf(stderr, "io_read_loop(fd=%d, length=%zu)\n", arguments->descriptor, length);
405
+
406
+ while (true) {
396
407
  size_t maximum_size = size - offset;
408
+ if (DEBUG_IO_READ) fprintf(stderr, "read(%d, +%ld, %ld)\n", arguments->descriptor, offset, maximum_size);
397
409
  ssize_t result = read(arguments->descriptor, (char*)base+offset, maximum_size);
410
+ if (DEBUG_IO_READ) fprintf(stderr, "read(%d, +%ld, %ld) -> %lld\n", arguments->descriptor, offset, maximum_size, result);
398
411
 
399
- if (result == 0) {
400
- break;
401
- } else if (result > 0) {
412
+ if (result > 0) {
402
413
  offset += result;
414
+ if ((size_t)result >= length) break;
403
415
  length -= result;
404
- } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
416
+ } else if (result == 0) {
417
+ break;
418
+ } else if (length > 0 && IO_Event_try_again(errno)) {
419
+ if (DEBUG_IO_READ) fprintf(stderr, "IO_Event_Selector_KQueue_io_wait(fd=%d, length=%zu)\n", arguments->descriptor, length);
405
420
  IO_Event_Selector_KQueue_io_wait(arguments->self, arguments->fiber, arguments->io, RB_INT2NUM(IO_EVENT_READABLE));
406
421
  } else {
407
- rb_sys_fail("IO_Event_Selector_KQueue_io_read");
422
+ if (DEBUG_IO_READ) fprintf(stderr, "io_read_loop(fd=%d, length=%zu) -> errno=%d\n", arguments->descriptor, length, errno);
423
+ return rb_fiber_scheduler_io_result(-1, errno);
408
424
  }
409
425
  }
410
426
 
411
- return SIZET2NUM(offset);
427
+ if (DEBUG_IO_READ) fprintf(stderr, "io_read_loop(fd=%d, length=%zu) -> %zu\n", arguments->descriptor, length, offset);
428
+ return rb_fiber_scheduler_io_result(offset, 0);
412
429
  }
413
430
 
414
431
  static
@@ -470,20 +487,31 @@ VALUE io_write_loop(VALUE _arguments) {
470
487
  rb_raise(rb_eRuntimeError, "Length exceeds size of buffer!");
471
488
  }
472
489
 
473
- while (length > 0) {
474
- ssize_t result = write(arguments->descriptor, (char*)base+offset, length);
490
+ if (DEBUG_IO_WRITE) fprintf(stderr, "io_write_loop(fd=%d, length=%zu)\n", arguments->descriptor, length);
491
+
492
+ while (true) {
493
+ size_t maximum_size = size - offset;
494
+ if (DEBUG_IO_WRITE) fprintf(stderr, "write(%d, +%ld, %ld, length=%zu)\n", arguments->descriptor, offset, maximum_size, length);
495
+ ssize_t result = write(arguments->descriptor, (char*)base+offset, maximum_size);
496
+ if (DEBUG_IO_WRITE) fprintf(stderr, "write(%d, +%ld, %ld) -> %lld\n", arguments->descriptor, offset, maximum_size, result);
475
497
 
476
- if (result >= 0) {
498
+ if (result > 0) {
477
499
  offset += result;
500
+ if ((size_t)result >= length) break;
478
501
  length -= result;
479
- } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
480
- IO_Event_Selector_KQueue_io_wait(arguments->self, arguments->fiber, arguments->io, RB_INT2NUM(IO_EVENT_WRITABLE));
502
+ } else if (result == 0) {
503
+ break;
504
+ } else if (length > 0 && IO_Event_try_again(errno)) {
505
+ if (DEBUG_IO_WRITE) fprintf(stderr, "IO_Event_Selector_KQueue_io_wait(fd=%d, length=%zu)\n", arguments->descriptor, length);
506
+ IO_Event_Selector_KQueue_io_wait(arguments->self, arguments->fiber, arguments->io, RB_INT2NUM(IO_EVENT_READABLE));
481
507
  } else {
482
- rb_sys_fail("IO_Event_Selector_KQueue_io_write");
508
+ if (DEBUG_IO_WRITE) fprintf(stderr, "io_write_loop(fd=%d, length=%zu) -> errno=%d\n", arguments->descriptor, length, errno);
509
+ return rb_fiber_scheduler_io_result(-1, errno);
483
510
  }
484
511
  }
485
512
 
486
- return SIZET2NUM(offset);
513
+ if (DEBUG_IO_READ) fprintf(stderr, "io_write_loop(fd=%d, length=%zu) -> %zu\n", arguments->descriptor, length, offset);
514
+ return rb_fiber_scheduler_io_result(offset, 0);
487
515
  };
488
516
 
489
517
  static
@@ -614,7 +642,9 @@ VALUE IO_Event_Selector_KQueue_select(VALUE self, VALUE duration) {
614
642
  // Non-comprehensive testing shows this gives a 1.5x speedup.
615
643
 
616
644
  // First do the syscall with no timeout to get any immediately available events:
645
+ if (DEBUG) fprintf(stderr, "\r\nselect_internal_with_gvl timeout=" PRINTF_TIMESPEC "\r\n", PRINTF_TIMESPEC_ARGS(arguments.storage));
617
646
  select_internal_with_gvl(&arguments);
647
+ if (DEBUG) fprintf(stderr, "\r\nselect_internal_with_gvl done\r\n");
618
648
 
619
649
  // If we:
620
650
  // 1. Didn't process any ready fibers, and
@@ -627,6 +657,7 @@ VALUE IO_Event_Selector_KQueue_select(VALUE self, VALUE duration) {
627
657
  if (!timeout_nonblocking(arguments.timeout)) {
628
658
  arguments.count = KQUEUE_MAX_EVENTS;
629
659
 
660
+ if (DEBUG) fprintf(stderr, "IO_Event_Selector_KQueue_select timeout=" PRINTF_TIMESPEC "\n", PRINTF_TIMESPEC_ARGS(arguments.storage));
630
661
  select_internal_without_gvl(&arguments);
631
662
  }
632
663
  }
@@ -26,6 +26,7 @@
26
26
 
27
27
  #ifdef HAVE_RUBY_IO_BUFFER_H
28
28
  #include <ruby/io/buffer.h>
29
+ #include <ruby/fiber/scheduler.h>
29
30
  #endif
30
31
 
31
32
  #include <time.h>
@@ -40,6 +41,10 @@ enum IO_Event {
40
41
 
41
42
  void Init_IO_Event_Selector();
42
43
 
44
+ static inline int IO_Event_try_again(int error) {
45
+ return error == EAGAIN || error == EWOULDBLOCK;
46
+ }
47
+
43
48
  VALUE IO_Event_Selector_fiber_transfer(VALUE fiber, int argc, VALUE *argv);
44
49
 
45
50
  #ifdef HAVE__RB_FIBER_RAISE
@@ -100,7 +100,7 @@ VALUE IO_Event_Selector_URing_initialize(VALUE self, VALUE loop) {
100
100
  int result = io_uring_queue_init(URING_ENTRIES, &data->ring, 0);
101
101
 
102
102
  if (result < 0) {
103
- rb_syserr_fail(-result, "io_uring_queue_init");
103
+ rb_syserr_fail(-result, "IO_Event_Selector_URing_initialize:io_uring_queue_init");
104
104
  }
105
105
 
106
106
  rb_update_max_fd(data->ring.ring_fd);
@@ -186,7 +186,7 @@ int io_uring_submit_flush(struct IO_Event_Selector_URing *data) {
186
186
  // If it was submitted, reset pending count:
187
187
  data->pending = 0;
188
188
  } else if (result != -EBUSY && result != -EAGAIN) {
189
- rb_syserr_fail(-result, "io_uring_submit_flush");
189
+ rb_syserr_fail(-result, "io_uring_submit_flush:io_uring_submit");
190
190
  }
191
191
 
192
192
  return result;
@@ -208,7 +208,7 @@ int io_uring_submit_now(struct IO_Event_Selector_URing *data) {
208
208
  if (result == -EBUSY || result == -EAGAIN) {
209
209
  IO_Event_Selector_yield(&data->backend);
210
210
  } else {
211
- rb_syserr_fail(-result, "io_uring_submit_now");
211
+ rb_syserr_fail(-result, "io_uring_submit_now:io_uring_submit");
212
212
  }
213
213
  }
214
214
  }
@@ -396,24 +396,24 @@ VALUE IO_Event_Selector_URing_io_read(VALUE self, VALUE fiber, VALUE io, VALUE b
396
396
  size_t offset = 0;
397
397
  size_t length = NUM2SIZET(_length);
398
398
 
399
- while (length > 0) {
399
+ while (true) {
400
400
  size_t maximum_size = size - offset;
401
401
  int result = io_read(data, fiber, descriptor, (char*)base+offset, maximum_size);
402
402
 
403
- if (result == 0) {
404
- break;
405
- } else if (result > 0) {
403
+ if (result > 0) {
406
404
  offset += result;
407
405
  if ((size_t)result >= length) break;
408
406
  length -= result;
409
- } else if (-result == EAGAIN || -result == EWOULDBLOCK) {
407
+ } else if (result == 0) {
408
+ break;
409
+ } else if (length > 0 && IO_Event_try_again(-result)) {
410
410
  IO_Event_Selector_URing_io_wait(self, fiber, io, RB_INT2NUM(IO_EVENT_READABLE));
411
411
  } else {
412
- rb_syserr_fail(-result, strerror(-result));
412
+ return rb_fiber_scheduler_io_result(-1, -result);
413
413
  }
414
414
  }
415
415
 
416
- return SIZET2NUM(offset);
416
+ return rb_fiber_scheduler_io_result(offset, 0);
417
417
  }
418
418
 
419
419
  static
@@ -449,21 +449,24 @@ VALUE IO_Event_Selector_URing_io_write(VALUE self, VALUE fiber, VALUE io, VALUE
449
449
  rb_raise(rb_eRuntimeError, "Length exceeds size of buffer!");
450
450
  }
451
451
 
452
- while (length > 0) {
453
- int result = io_write(data, fiber, descriptor, (char*)base+offset, length);
452
+ while (true) {
453
+ size_t maximum_size = size - offset;
454
+ int result = io_write(data, fiber, descriptor, (char*)base+offset, maximum_size);
454
455
 
455
- if (result >= 0) {
456
+ if (result > 0) {
456
457
  offset += result;
457
458
  if ((size_t)result >= length) break;
458
459
  length -= result;
459
- } else if (-result == EAGAIN || -result == EWOULDBLOCK) {
460
+ } else if (result == 0) {
461
+ break;
462
+ } else if (length > 0 && IO_Event_try_again(-result)) {
460
463
  IO_Event_Selector_URing_io_wait(self, fiber, io, RB_INT2NUM(IO_EVENT_WRITABLE));
461
464
  } else {
462
- rb_syserr_fail(-result, strerror(-result));
465
+ return rb_fiber_scheduler_io_result(-1, -result);
463
466
  }
464
467
  }
465
468
 
466
- return SIZET2NUM(offset);
469
+ return rb_fiber_scheduler_io_result(offset, 0);
467
470
  }
468
471
 
469
472
  #endif
@@ -551,7 +554,7 @@ int select_internal_without_gvl(struct select_arguments *arguments) {
551
554
  if (arguments->result == -ETIME) {
552
555
  arguments->result = 0;
553
556
  } else if (arguments->result < 0) {
554
- rb_syserr_fail(-arguments->result, "select_internal_without_gvl:io_uring_wait_cqes");
557
+ rb_syserr_fail(-arguments->result, "select_internal_without_gvl:io_uring_wait_cqe_timeout");
555
558
  } else {
556
559
  // At least 1 event is waiting:
557
560
  arguments->result = 1;
data/ext/kqueue.o CHANGED
Binary file
data/ext/mkmf.log CHANGED
@@ -1,6 +1,6 @@
1
1
  have_func: checking for rb_ext_ractor_safe()... -------------------- yes
2
2
 
3
- "clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.3/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -m64 -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc "
3
+ DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc "
4
4
  checked program was:
5
5
  /* begin */
6
6
  1: #include "ruby.h"
@@ -11,7 +11,7 @@ checked program was:
11
11
  6: }
12
12
  /* end */
13
13
 
14
- "clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.3/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -m64 -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc "
14
+ DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc "
15
15
  checked program was:
16
16
  /* begin */
17
17
  1: #include "ruby.h"
@@ -32,13 +32,9 @@ checked program was:
32
32
 
33
33
  --------------------
34
34
 
35
- have_func: checking for &rb_fiber_transfer()... -------------------- no
35
+ have_func: checking for &rb_fiber_transfer()... -------------------- yes
36
36
 
37
- "clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.3/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -m64 -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc "
38
- conftest.c:14:76: error: use of undeclared identifier 'rb_fiber_transfer'
39
- int t(void) { const volatile void *volatile p; p = (const volatile void *)&rb_fiber_transfer; return !p; }
40
- ^
41
- 1 error generated.
37
+ DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc "
42
38
  checked program was:
43
39
  /* begin */
44
40
  1: #include "ruby.h"
@@ -61,7 +57,7 @@ checked program was:
61
57
 
62
58
  have_library: checking for -luring... -------------------- no
63
59
 
64
- "clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.3/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -m64 -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc -luring "
60
+ DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc -luring "
65
61
  ld: library not found for -luring
66
62
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
67
63
  checked program was:
@@ -87,7 +83,7 @@ checked program was:
87
83
 
88
84
  have_header: checking for sys/epoll.h... -------------------- no
89
85
 
90
- "clang -E -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -o conftest.i"
86
+ DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall -c conftest.c"
91
87
  conftest.c:3:10: fatal error: 'sys/epoll.h' file not found
92
88
  #include <sys/epoll.h>
93
89
  ^~~~~~~~~~~~~
@@ -103,7 +99,7 @@ checked program was:
103
99
 
104
100
  have_header: checking for sys/event.h... -------------------- yes
105
101
 
106
- "clang -E -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -o conftest.i"
102
+ DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall -c conftest.c"
107
103
  checked program was:
108
104
  /* begin */
109
105
  1: #include "ruby.h"
@@ -115,7 +111,7 @@ checked program was:
115
111
 
116
112
  have_header: checking for sys/eventfd.h... -------------------- no
117
113
 
118
- "clang -E -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -o conftest.i"
114
+ DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall -c conftest.c"
119
115
  conftest.c:3:10: fatal error: 'sys/eventfd.h' file not found
120
116
  #include <sys/eventfd.h>
121
117
  ^~~~~~~~~~~~~~~
@@ -129,9 +125,9 @@ checked program was:
129
125
 
130
126
  --------------------
131
127
 
132
- have_func: checking for rb_io_descriptor()... -------------------- no
128
+ have_func: checking for rb_io_descriptor()... -------------------- yes
133
129
 
134
- "clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.3/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -m64 -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc "
130
+ DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc "
135
131
  conftest.c:14:57: error: use of undeclared identifier 'rb_io_descriptor'
136
132
  int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_io_descriptor; return !p; }
137
133
  ^
@@ -154,12 +150,7 @@ checked program was:
154
150
  14: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_io_descriptor; return !p; }
155
151
  /* end */
156
152
 
157
- "clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.3/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -m64 -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc "
158
- Undefined symbols for architecture arm64:
159
- "_rb_io_descriptor", referenced from:
160
- _t in conftest-1e4d1a.o
161
- ld: symbol(s) not found for architecture arm64
162
- clang: error: linker command failed with exit code 1 (use -v to see invocation)
153
+ DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc "
163
154
  checked program was:
164
155
  /* begin */
165
156
  1: #include "ruby.h"
@@ -183,7 +174,7 @@ checked program was:
183
174
 
184
175
  have_func: checking for &rb_process_status_wait()... -------------------- no
185
176
 
186
- "clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.3/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -m64 -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc "
177
+ DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc "
187
178
  conftest.c:14:76: error: use of undeclared identifier 'rb_process_status_wait'
188
179
  int t(void) { const volatile void *volatile p; p = (const volatile void *)&rb_process_status_wait; return !p; }
189
180
  ^
@@ -210,7 +201,7 @@ checked program was:
210
201
 
211
202
  have_func: checking for rb_fiber_current()... -------------------- yes
212
203
 
213
- "clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.3/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -m64 -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc "
204
+ DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc "
214
205
  checked program was:
215
206
  /* begin */
216
207
  1: #include "ruby.h"
@@ -231,17 +222,9 @@ checked program was:
231
222
 
232
223
  --------------------
233
224
 
234
- have_func: checking for &rb_fiber_raise()... -------------------- no
225
+ have_func: checking for &rb_fiber_raise()... -------------------- yes
235
226
 
236
- "clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.3/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -m64 -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc "
237
- conftest.c:14:76: error: use of undeclared identifier 'rb_fiber_raise'; did you mean 'rb_fiber_resume'?
238
- int t(void) { const volatile void *volatile p; p = (const volatile void *)&rb_fiber_raise; return !p; }
239
- ^~~~~~~~~~~~~~
240
- rb_fiber_resume
241
- /Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/ruby/internal/intern/cont.h:32:7: note: 'rb_fiber_resume' declared here
242
- VALUE rb_fiber_resume(VALUE fib, int argc, const VALUE *argv);
243
- ^
244
- 1 error generated.
227
+ DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-head/lib -L. -fstack-protector-strong -lruby.3.1-static -framework CoreFoundation -lpthread -ldl -lobjc "
245
228
  checked program was:
246
229
  /* begin */
247
230
  1: #include "ruby.h"
@@ -262,14 +245,9 @@ checked program was:
262
245
 
263
246
  --------------------
264
247
 
265
- have_header: checking for ruby/io/buffer.h... -------------------- no
248
+ have_header: checking for ruby/io/buffer.h... -------------------- yes
266
249
 
267
- "clang -E -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.3/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -o conftest.i"
268
- conftest.c:3:10: fatal error: 'ruby/io/buffer.h' file not found
269
- #include <ruby/io/buffer.h>
270
- ^~~~~~~~~~~~~~~~~~
271
- conftest.c:3:10: note: did not find header 'io/buffer.h' in framework 'ruby' (loaded from '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks')
272
- 1 error generated.
250
+ DYLD_FALLBACK_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-head/lib "clang -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/arm64-darwin21 -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0/ruby/backward -I/Users/samuel/.rubies/ruby-head/include/ruby-3.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef -pipe -Wall -c conftest.c"
273
251
  checked program was:
274
252
  /* begin */
275
253
  1: #include "ruby.h"
@@ -281,11 +259,15 @@ checked program was:
281
259
 
282
260
  extconf.h is:
283
261
  /* begin */
284
- 1: #ifndef EXTCONF_H
285
- 2: #define EXTCONF_H
286
- 3: #define HAVE_RB_EXT_RACTOR_SAFE 1
287
- 4: #define HAVE_SYS_EVENT_H 1
288
- 5: #define HAVE_RB_FIBER_CURRENT 1
289
- 6: #endif
262
+ 1: #ifndef EXTCONF_H
263
+ 2: #define EXTCONF_H
264
+ 3: #define HAVE_RB_EXT_RACTOR_SAFE 1
265
+ 4: #define HAVE__RB_FIBER_TRANSFER 1
266
+ 5: #define HAVE_SYS_EVENT_H 1
267
+ 6: #define HAVE_RB_IO_DESCRIPTOR 1
268
+ 7: #define HAVE_RB_FIBER_CURRENT 1
269
+ 8: #define HAVE__RB_FIBER_RAISE 1
270
+ 9: #define HAVE_RUBY_IO_BUFFER_H 1
271
+ 10: #endif
290
272
  /* end */
291
273
 
data/ext/selector.o CHANGED
Binary file
@@ -134,25 +134,36 @@ module IO::Event
134
134
  end
135
135
 
136
136
  if IO.const_defined?(:Buffer)
137
+ EAGAIN = Errno::EAGAIN::Errno
138
+
137
139
  def io_read(fiber, io, buffer, length)
138
140
  offset = 0
139
141
 
140
- while length > 0
141
- # The maximum size we can read:
142
+ while true
142
143
  maximum_size = buffer.size - offset
143
144
 
144
- case result = io.read_nonblock(maximum_size, exception: false)
145
+ case result = blocking{io.read_nonblock(maximum_size, exception: false)}
145
146
  when :wait_readable
146
- self.io_wait(fiber, io, IO::READABLE)
147
+ if length > 0
148
+ self.io_wait(fiber, io, IO::READABLE)
149
+ else
150
+ return -EAGAIN
151
+ end
147
152
  when :wait_writable
148
- self.io_wait(fiber, io, IO::WRITABLE)
153
+ if length > 0
154
+ self.io_wait(fiber, io, IO::WRITABLE)
155
+ else
156
+ return -EAGAIN
157
+ end
149
158
  else
150
159
  break unless result
151
160
 
152
161
  buffer.copy(result, offset)
153
162
 
154
- offset += result.bytesize
155
- length -= result.bytesize
163
+ size = result.bytesize
164
+ offset += size
165
+ break if size >= length
166
+ length -= size
156
167
  end
157
168
  end
158
169
 
@@ -162,16 +173,26 @@ module IO::Event
162
173
  def io_write(fiber, io, buffer, length)
163
174
  offset = 0
164
175
 
165
- while length > 0
166
- # From offset until the end:
167
- chunk = buffer.to_str(offset, length)
168
- case result = io.write_nonblock(chunk, exception: false)
176
+ while true
177
+ maximum_size = buffer.size - offset
178
+
179
+ chunk = buffer.to_str(offset, maximum_size)
180
+ case result = blocking{io.write_nonblock(chunk, exception: false)}
169
181
  when :wait_readable
170
- self.io_wait(fiber, io, IO::READABLE)
182
+ if length > 0
183
+ self.io_wait(fiber, io, IO::READABLE)
184
+ else
185
+ return -EAGAIN
186
+ end
171
187
  when :wait_writable
172
- self.io_wait(fiber, io, IO::WRITABLE)
188
+ if length > 0
189
+ self.io_wait(fiber, io, IO::WRITABLE)
190
+ else
191
+ return -EAGAIN
192
+ end
173
193
  else
174
194
  offset += result
195
+ break if result >= length
175
196
  length -= result
176
197
  end
177
198
  end
@@ -240,6 +261,10 @@ module IO::Event
240
261
 
241
262
  return ready.size
242
263
  end
264
+
265
+ private def blocking(&block)
266
+ Fiber.new(blocking: true, &block).resume
267
+ end
243
268
  end
244
269
  end
245
270
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module IO::Event
22
- VERSION = "0.2.3"
22
+ VERSION = "0.3.0"
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: io-event
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-10 00:00:00.000000000 Z
11
+ date: 2021-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bake
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.5'
61
+ version: '0.6'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.5'
68
+ version: '0.6'
69
69
  description:
70
70
  email:
71
71
  executables: []
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
- rubygems_version: 3.2.32
123
+ rubygems_version: 3.3.0.dev
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: An event loop.