rage-iodine 5.6.0 → 6.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ffa46cab7e0fb7fc7550dd142f42b0850287fee60cc0d72b7f52757f52720f7
4
- data.tar.gz: c51b8ad9e316c21ed06e6803dcfb5af7bf70fc3eee84a0fd179b2730d2572473
3
+ metadata.gz: 1595ec4d4f155fbc845b37ad096018a2a4bfa4f884c0ef96b7112d268fe86e89
4
+ data.tar.gz: 3185d0901b132a329509238b5188dcd29de1d4145a018adda6b3f9f215e008cf
5
5
  SHA512:
6
- metadata.gz: fa99ee4e7abb10b55b6f14aeeaef6bf03e85cf8aff9b33a66f7b4f64097c5ef824e0c3de6663caf00f5404b2d08b663debb60c796a0a44490138a96ac92a832c
7
- data.tar.gz: ca2a4ac6f633955b202dccf09661cb7799ae92e16078ef3776c1648e18e2b1ab620f470f4b99b3c75b7d0e8f9b064fad180fd5c9b32ab6ae0ddd60c9d601b58d
6
+ metadata.gz: 4bbaa335fcd6202ac41a6449a5d8a38302c786b69348b66af733520e83c27bf4529c8a0e90dc7db5f19f8755aadfaf0c71edeb07fea904664b2cbf573da573f0
7
+ data.tar.gz: 991187eeb695f2128f83859e1025d62d580a1e41fc672822aaf7c8e5130edf15c83721e263a30799311766627fbd132393b50987486d137004f7ae439d11d0b8
data/CHANGELOG.md CHANGED
@@ -6,6 +6,10 @@ Please notice that this change log contains changes for upcoming releases as wel
6
6
 
7
7
  ## Changes:
8
8
 
9
+ #### Change log v.6.0.0 (2026-09-06)
10
+
11
+ **Update**: Update scheduler `read`/`write` hooks
12
+
9
13
  #### Change log v.5.6.0 (2026-09-06)
10
14
 
11
15
  **Update**: TCP Socket Listen: Accept Queue
data/ext/iodine/fio.c CHANGED
@@ -3687,12 +3687,12 @@ retry_int:
3687
3687
  }
3688
3688
 
3689
3689
  /**
3690
- * This is a complete copy of `fio_read` except that it doesn't attempt to force close the
3691
- * socker on error.
3690
+ * Performs a single read operation using the connection's read hook.
3692
3691
  *
3693
- * The method is currently used by the fiber scheduler.
3692
+ * The return value and errno match the underlying read operation. The socket
3693
+ * isn't closed on error.
3694
3694
  */
3695
- ssize_t fio_read_unsafe(intptr_t uuid, void *buffer, size_t count) {
3695
+ ssize_t fio_read_once(intptr_t uuid, void *buffer, size_t count) {
3696
3696
  if (!uuid_is_valid(uuid) || !uuid_data(uuid).open) {
3697
3697
  errno = EBADF;
3698
3698
  return -1;
@@ -3704,22 +3704,36 @@ ssize_t fio_read_unsafe(intptr_t uuid, void *buffer, size_t count) {
3704
3704
  uuid_data(uuid).rw_hooks->read;
3705
3705
  void *udata = uuid_data(uuid).rw_udata;
3706
3706
  fio_unlock(&uuid_data(uuid).sock_lock);
3707
- int old_errno = errno;
3708
- ssize_t ret;
3709
- retry_int:
3710
- ret = rw_read(uuid, udata, buffer, count);
3707
+ ssize_t ret = rw_read(uuid, udata, buffer, count);
3711
3708
  if (ret > 0) {
3712
3709
  fio_touch(uuid);
3713
- return ret;
3714
3710
  }
3715
- if (ret < 0 && errno == EINTR)
3716
- goto retry_int;
3717
- if (ret < 0 &&
3718
- (errno == EWOULDBLOCK || errno == EAGAIN || errno == ENOTCONN)) {
3719
- errno = old_errno;
3711
+ return ret;
3712
+ }
3713
+
3714
+ /**
3715
+ * Performs a single write operation using the connection's write hook.
3716
+ *
3717
+ * The return value and errno match the underlying write operation. The socket
3718
+ * isn't closed on error and no data is queued for the reactor.
3719
+ */
3720
+ ssize_t fio_write_once(intptr_t uuid, const void *buffer, size_t count) {
3721
+ if (!uuid_is_valid(uuid) || !uuid_data(uuid).open) {
3722
+ errno = EBADF;
3723
+ return -1;
3724
+ }
3725
+ if (count == 0)
3720
3726
  return 0;
3727
+ fio_lock(&uuid_data(uuid).sock_lock);
3728
+ ssize_t (*rw_write)(intptr_t, void *, const void *, size_t) =
3729
+ uuid_data(uuid).rw_hooks->write;
3730
+ void *udata = uuid_data(uuid).rw_udata;
3731
+ fio_unlock(&uuid_data(uuid).sock_lock);
3732
+ ssize_t ret = rw_write(uuid, udata, buffer, count);
3733
+ if (ret > 0) {
3734
+ fio_touch(uuid);
3721
3735
  }
3722
- return -1;
3736
+ return ret;
3723
3737
  }
3724
3738
 
3725
3739
  /**
data/ext/iodine/fio.h CHANGED
@@ -1198,12 +1198,20 @@ size_t fio_local_addr(char *dest, size_t limit);
1198
1198
  ssize_t fio_read(intptr_t uuid, void *buffer, size_t count);
1199
1199
 
1200
1200
  /**
1201
- * This is a complete copy of `fio_read` except that it doesn't attempt to force close the
1202
- * socker on error.
1201
+ * Performs a single read operation using the connection's read hook.
1203
1202
  *
1204
- * The method is currently used by the fiber scheduler.
1203
+ * The return value and errno match the underlying read operation. The socket
1204
+ * isn't closed on error.
1205
1205
  */
1206
- ssize_t fio_read_unsafe(intptr_t uuid, void *buffer, size_t count);
1206
+ ssize_t fio_read_once(intptr_t uuid, void *buffer, size_t count);
1207
+
1208
+ /**
1209
+ * Performs a single write operation using the connection's write hook.
1210
+ *
1211
+ * The return value and errno match the underlying write operation. The socket
1212
+ * isn't closed on error and no data is queued for the reactor.
1213
+ */
1214
+ ssize_t fio_write_once(intptr_t uuid, const void *buffer, size_t count);
1207
1215
 
1208
1216
  /** The following structure is used for `fio_write2_fn` function arguments. */
1209
1217
  typedef struct {
@@ -1,6 +1,8 @@
1
1
  #include "iodine.h"
2
2
  #include "iodine_store.h"
3
3
  #include "ruby.h"
4
+ #include "ruby/fiber/scheduler.h"
5
+ #include "ruby/io/buffer.h"
4
6
 
5
7
  #include <errno.h>
6
8
  #include <stddef.h>
@@ -10,7 +12,7 @@
10
12
 
11
13
  #include "fio.h"
12
14
 
13
- #define IO_MAX_READ 8192
15
+ #define IO_MAX_READ 65536
14
16
 
15
17
  static ID call_id;
16
18
  static uint8_t ATTACH_ON_READ_READY_CALLBACK;
@@ -151,51 +153,104 @@ static VALUE iodine_scheduler_attach(VALUE self, VALUE r_fd, VALUE r_waittype, V
151
153
  (void)self;
152
154
  }
153
155
 
154
- static VALUE iodine_scheduler_write(VALUE self, VALUE r_fd, VALUE r_buffer, VALUE r_length, VALUE r_offset) {
156
+ static VALUE iodine_scheduler_write_async(VALUE self, VALUE r_fd, VALUE r_buffer, VALUE r_length, VALUE r_offset) {
155
157
  Check_Type(r_fd, T_FIXNUM);
156
158
  int fd = FIX2INT(r_fd);
157
159
 
158
- Check_Type(r_buffer, T_STRING);
159
- char *buffer = RSTRING_PTR(r_buffer);
160
+ const void *buffer;
161
+ size_t buffer_length;
162
+ rb_io_buffer_get_bytes_for_reading(r_buffer, &buffer, &buffer_length);
160
163
 
161
164
  Check_Type(r_length, T_FIXNUM);
162
- int length = FIX2INT(r_length);
165
+ size_t length = NUM2SIZET(r_length);
163
166
 
164
167
  Check_Type(r_offset, T_FIXNUM);
165
- int offset = FIX2INT(r_offset);
168
+ size_t offset = NUM2SIZET(r_offset);
169
+
170
+ if (offset > buffer_length || length > buffer_length - offset) {
171
+ return rb_fiber_scheduler_io_result(-1, EINVAL);
172
+ }
173
+ if (!length) {
174
+ return r_length;
175
+ }
166
176
 
167
177
  void *cpy = fio_malloc(length);
168
- memcpy(cpy, buffer, length);
169
- fio_write2(fio_fd2uuid(fd), .data.buffer = cpy, .length = length, .offset = offset, .after.dealloc = fio_free);
178
+ memcpy(cpy, (const char *)buffer + offset, length);
179
+ fio_write2(fio_fd2uuid(fd), .data.buffer = cpy, .length = length, .after.dealloc = fio_free);
170
180
 
171
181
  return r_length;
172
182
 
173
183
  (void)self;
174
184
  }
175
185
 
176
- static VALUE iodine_scheduler_read(VALUE self, VALUE r_fd, VALUE r_length, VALUE r_offset) {
186
+ static VALUE iodine_scheduler_write(VALUE self, VALUE r_fd, VALUE r_buffer, VALUE r_length, VALUE r_offset) {
177
187
  Check_Type(r_fd, T_FIXNUM);
178
188
  int fd = FIX2INT(r_fd);
179
189
 
190
+ const void *buffer;
191
+ size_t buffer_length;
192
+ rb_io_buffer_get_bytes_for_reading(r_buffer, &buffer, &buffer_length);
193
+
180
194
  Check_Type(r_length, T_FIXNUM);
181
- int length = FIX2INT(r_length);
195
+ size_t length = NUM2SIZET(r_length);
182
196
 
183
- if (length == 0) {
184
- length = IO_MAX_READ;
197
+ Check_Type(r_offset, T_FIXNUM);
198
+ size_t offset = NUM2SIZET(r_offset);
199
+
200
+ if (offset > buffer_length || length > buffer_length - offset) {
201
+ return rb_fiber_scheduler_io_result(-1, EINVAL);
202
+ }
203
+ if (!length) {
204
+ return rb_fiber_scheduler_io_result(0, 0);
185
205
  }
186
206
 
187
- intptr_t uuid = fio_fd2uuid(fd);
188
- char buffer[length];
207
+ ssize_t result = fio_write_once(fio_fd2uuid(fd), (const char *)buffer + offset, length);
208
+ int error = result < 0 ? errno : 0;
209
+ return rb_fiber_scheduler_io_result(result, error);
210
+
211
+ (void)self;
212
+ }
213
+
214
+ static VALUE iodine_scheduler_read(VALUE self, VALUE r_fd, VALUE r_buffer, VALUE r_length, VALUE r_offset) {
215
+ Check_Type(r_fd, T_FIXNUM);
216
+ int fd = FIX2INT(r_fd);
217
+
218
+ void *buffer;
219
+ size_t buffer_length;
220
+ rb_io_buffer_get_bytes_for_writing(r_buffer, &buffer, &buffer_length);
221
+
222
+ Check_Type(r_length, T_FIXNUM);
223
+ size_t length = NUM2SIZET(r_length);
224
+
225
+ Check_Type(r_offset, T_FIXNUM);
226
+ size_t offset = NUM2SIZET(r_offset);
227
+
228
+ if (offset > buffer_length || length > buffer_length - offset) {
229
+ return rb_fiber_scheduler_io_result(-1, EINVAL);
230
+ }
189
231
 
190
- ssize_t len = fio_read_unsafe(uuid, &buffer, length);
191
- if (len == -1) {
192
- return Qnil;
232
+ #if RUBY_FIBER_SCHEDULER_VERSION >= 4
233
+ if (length > IO_MAX_READ) {
234
+ length = IO_MAX_READ;
235
+ }
236
+ #else
237
+ if (length == 0) {
238
+ length = buffer_length - offset;
239
+ if (length > IO_MAX_READ) {
240
+ length = IO_MAX_READ;
241
+ }
242
+ }
243
+ #endif
244
+
245
+ if (!length) {
246
+ return rb_fiber_scheduler_io_result(0, 0);
193
247
  }
194
248
 
195
- return rb_str_new(buffer, len);
249
+ ssize_t result = fio_read_once(fio_fd2uuid(fd), (char *)buffer + offset, length);
250
+ int error = result < 0 ? errno : 0;
251
+ return rb_fiber_scheduler_io_result(result, error);
196
252
 
197
253
  (void)self;
198
- (void)r_offset;
199
254
  }
200
255
 
201
256
  static VALUE iodine_scheduler_close(VALUE self) {
@@ -219,8 +274,9 @@ void iodine_scheduler_initialize(void) {
219
274
  VALUE SchedulerModule = rb_define_module_under(IodineModule, "Scheduler");
220
275
 
221
276
  rb_define_module_function(SchedulerModule, "attach", iodine_scheduler_attach, 3);
277
+ rb_define_module_function(SchedulerModule, "write_async", iodine_scheduler_write_async, 4);
222
278
  rb_define_module_function(SchedulerModule, "write", iodine_scheduler_write, 4);
223
- rb_define_module_function(SchedulerModule, "read", iodine_scheduler_read, 3);
279
+ rb_define_module_function(SchedulerModule, "read", iodine_scheduler_read, 4);
224
280
  rb_define_module_function(SchedulerModule, "close", iodine_scheduler_close, 0);
225
281
 
226
282
  VALUE cIO = rb_const_get(rb_cObject, rb_intern2("IO", 2));
@@ -1,3 +1,3 @@
1
1
  module Iodine
2
- VERSION = '5.6.0'.freeze
2
+ VERSION = '6.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rage-iodine
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.6.0
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev