uringmachine 0.14 → 0.15

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: 38a9b75f18075a31aa179cc63b67e7e80b75b3797a701e1b2164831f4c20c352
4
- data.tar.gz: 50432253c8aca2713b7eeaf8ae69c72c1e4efece1c85285076cf91c97011a887
3
+ metadata.gz: 1b3778bbf3b35b2f0855c5fdbe441df909a43866c56ceed16cacf502956566ba
4
+ data.tar.gz: 82b580cb610c11d5d05e69ab868ba70265fec92851cbdca7cf340bbde09c0b2c
5
5
  SHA512:
6
- metadata.gz: c7426118f51b6b3460d7ec46cc6e64e8a3aaa50e2552d2c44f718cfa79a9624310d9d68148f030be5a03582abf3fe520389e7a27fb814cff141c78f327f4f76a
7
- data.tar.gz: a2e0ce93138435f99f84956ba82004fe06b4c7f530c37aa6585d998f2a4f6c448eac406ef0c7c602335bc776c5d40b543288f6e5cf16b1fe8bab1141fe7569c6
6
+ metadata.gz: 82fbdc455e76bd1adaf4668ae0d43c8c1e84f9c168c1d3e2f7a4924e672d5b77617ce720ac6fcb9257cc8e8edcf419f4267acdd7128d72a5d03c0b808f85ab4b
7
+ data.tar.gz: d56ba947a2d6ba974faa7e0594b506e0f7520815a995e263a7a9acf0658b73c057bd7d13f32e035376a4871dea6ff7824d04a621957707cb56a6f7e92581af1d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 2025-06-24 Version 0.15
2
+
3
+ - Add support for sleeping forever when sleep duration is lte 0
4
+
1
5
  # 2025-06-09 Version 0.14
2
6
 
3
7
  - Add `#close_async`, `#shutdown_async`
data/ext/um/um.c CHANGED
@@ -1,3 +1,4 @@
1
+ #include <float.h>
1
2
  #include "um.h"
2
3
  #include "ruby/thread.h"
3
4
 
@@ -317,7 +318,11 @@ VALUE um_timeout(struct um *machine, VALUE interval, VALUE class) {
317
318
  blocking singleshot ops
318
319
  *******************************************************************************/
319
320
 
321
+ #define SLEEP_FOREVER_DURATION (86400*10000)
322
+
320
323
  VALUE um_sleep(struct um *machine, double duration) {
324
+ if (duration <= 0) duration = SLEEP_FOREVER_DURATION;
325
+
321
326
  struct um_op op;
322
327
  um_prep_op(machine, &op, OP_SLEEP, 0);
323
328
  op.ts = um_double_to_timespec(duration);
@@ -416,7 +421,7 @@ VALUE um_close(struct um *machine, int fd) {
416
421
  VALUE um_close_async(struct um *machine, int fd) {
417
422
  struct um_op *op = um_op_alloc(machine);
418
423
  um_prep_op(machine, op, OP_CLOSE_ASYNC, OP_F_FREE_ON_COMPLETE);
419
-
424
+
420
425
  struct io_uring_sqe *sqe = um_get_sqe(machine, op);
421
426
  io_uring_prep_close(sqe, fd);
422
427
 
@@ -593,7 +598,7 @@ VALUE um_shutdown(struct um *machine, int fd, int how) {
593
598
  VALUE um_shutdown_async(struct um *machine, int fd, int how) {
594
599
  struct um_op *op = um_op_alloc(machine);
595
600
  um_prep_op(machine, op, OP_SHUTDOWN_ASYNC, OP_F_FREE_ON_COMPLETE);
596
-
601
+
597
602
  struct io_uring_sqe *sqe = um_get_sqe(machine, op);
598
603
  io_uring_prep_shutdown(sqe, fd, how);
599
604
 
@@ -888,4 +893,3 @@ VALUE um_periodically(struct um *machine, double interval) {
888
893
  struct op_ctx ctx = { .machine = machine, .op = &op, .ts = op.ts, .read_buf = NULL };
889
894
  return rb_ensure(periodically_start, (VALUE)&ctx, multishot_complete, (VALUE)&ctx);
890
895
  }
891
-
data/ext/um/um_class.c CHANGED
@@ -44,7 +44,7 @@ inline struct um *um_get_machine(VALUE self) {
44
44
  struct um *um;
45
45
  TypedData_Get_Struct(self, struct um, &UringMachine_type, um);
46
46
  if (!um->ring_initialized) rb_raise(rb_eRuntimeError, "Machine not initialized");
47
-
47
+
48
48
  return um;
49
49
  }
50
50
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class UringMachine
4
- VERSION = '0.14'
4
+ VERSION = '0.15'
5
5
  end
data/test/test_um.rb CHANGED
@@ -234,6 +234,20 @@ class SleepTest < UMBaseTest
234
234
  assert_in_range 0.02..0.04, t1 - t0
235
235
  assert_kind_of D, ret
236
236
  end
237
+
238
+ def test_sleep_forever
239
+ t0 = monotonic_clock
240
+ ret = begin
241
+ machine.timeout(0.03, D) do
242
+ machine.sleep 0
243
+ end
244
+ rescue => e
245
+ e
246
+ end
247
+ t1 = monotonic_clock
248
+ assert_in_range 0.02..0.04, t1 - t0
249
+ assert_kind_of D, ret
250
+ end
237
251
  end
238
252
 
239
253
  class PeriodicallyTest < UMBaseTest
@@ -579,7 +593,7 @@ class CloseTest < UMBaseTest
579
593
  def test_close_bad_fd
580
594
  r, w = IO.pipe
581
595
  machine.close(w.fileno)
582
-
596
+
583
597
  assert_raises(Errno::EBADF) { machine.close(w.fileno) }
584
598
  end
585
599
  end
@@ -1316,7 +1330,7 @@ class WaitTest < UMBaseTest
1316
1330
  ret = machine.read(rfd, buf, 8192)
1317
1331
  assert_equal msg.bytesize, ret
1318
1332
  assert_equal msg, buf
1319
-
1333
+
1320
1334
  ensure
1321
1335
  Process.wait(pid) rescue Errno::ECHILD
1322
1336
  end
@@ -1404,4 +1418,4 @@ class ForkTest < UMBaseTest
1404
1418
  Process.wait(child_pid) rescue Errno::ECHILD
1405
1419
  end
1406
1420
 
1407
- end
1421
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uringmachine
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.14'
4
+ version: '0.15'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner