uringmachine 0.28.1 → 0.28.3

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: 9fb662e62914ca38e254df5ee924b61155b510d3e862efa2f2e0997b00e7b3fd
4
- data.tar.gz: 6ea55d8b64df3873677d1243342d5d6163812068392498f1f080351d0fc9d3e2
3
+ metadata.gz: fbdc1ca412e20436a209c2e4f77af29873d5c8bac02f88c35562333f1e5328e6
4
+ data.tar.gz: d426661ce83c278041042c5829a23b4bb5c0c65cf99d1cb3cb96f5706b464859
5
5
  SHA512:
6
- metadata.gz: 3ca70d442ad7b7379dccb7e1e6df6acac913f2b5ae9ac9a2ca87b8ab5ecac5efd00454888921faa7960321f91493ad10dd337ab043fc3b4771fdb6bc17dead0b
7
- data.tar.gz: 6e4102474725dc14bf91690edcaf0e53d3eb9c7796b8edd72e2ec89629b7fc2c821e2a8c1e1abfaf52f0a27d9dd8153e6b750ed3f525436162bd93db7bf5aece
6
+ metadata.gz: 9908398a698bf7a2771a88b369023e27c3669bd205eb86a8132fee154709d68b21cd05a4fcd8b0bacb0f8e10140f2a2ef002f01cd7ac8177bf678c4f8e8574b5
7
+ data.tar.gz: afb606febf25d41fdf99b00e8cdeaa97523608445cc842cf49acbdf5af95f726276d443a574363b23b9b6c8287fad560780913f4bf1fd09240cf5df29185a9ac
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 0.28.3 2026-02-22
2
+
3
+ - Accept array in `#terminate` and `#join`
4
+
5
+ # 0.28.2 2026-02-20
6
+
7
+ - Fix `Stream#get_string`
8
+
1
9
  # 0.28.1 2026-02-20
2
10
 
3
11
  - Add `Stream#machine`, `Stream#fd`
data/TODO.md CHANGED
@@ -1,5 +1,25 @@
1
1
  ## immediate
2
2
 
3
+ - Add support for exception instances in `#timeout`.
4
+ - Add support for returning a value on timeout:
5
+
6
+ Since to do this safely we need to actually raise an exception that wraps the
7
+ value, rescue it and return the value, we might want a separate method that
8
+ wraps `#timeout`:
9
+
10
+ ```ruby
11
+ TimeoutValueError < StandardError
12
+
13
+ def timeout_with_value(interval, value, &block)
14
+ timeout_error = TimeoutValueError
15
+ timeout(interval, timeout_error, &block)
16
+ rescue TimeoutValueError => e
17
+ raise if e != timeout_error
18
+
19
+ value
20
+ end
21
+ ```
22
+
3
23
  - Add tests for support for Set in `machine#await_fibers`
4
24
  - Add tests for support for Set, Array in `machine#join`
5
25
  - Add `#read_file` for reading entire file
@@ -145,3 +165,14 @@ jobs = (1..100).map { |i|
145
165
  }
146
166
  machine.join(jobs)
147
167
  ```
168
+
169
+ ## Other abstractions
170
+
171
+ - Happy eyeballs connect
172
+
173
+ ```ruby
174
+ # addrs: [['1.1.1.1', 80], ['2.2.2.2', 80]]
175
+ # ['1.1.1.1:80', '2.2.2.2:80']
176
+ tcp_connect_happy_eyeballs(*addrs)
177
+ ```
178
+
data/ext/um/um.c CHANGED
@@ -539,7 +539,7 @@ VALUE um_timeout_complete(VALUE arg) {
539
539
 
540
540
  VALUE um_timeout(struct um *machine, VALUE interval, VALUE class) {
541
541
  static ID ID_new = 0;
542
- if (!ID_new) ID_new = rb_intern("new");
542
+ if (unlikely(!ID_new)) ID_new = rb_intern("new");
543
543
 
544
544
  struct um_op *op = um_op_acquire(machine);
545
545
  um_prep_op(machine, op, OP_TIMEOUT, 2, 0);
data/ext/um/um_stream.c CHANGED
@@ -56,8 +56,8 @@ static inline void str_copy_bytes(VALUE dest, const char *src, ssize_t len) {
56
56
  }
57
57
 
58
58
  VALUE stream_get_line(struct um_stream *stream, VALUE buf, ssize_t maxlen) {
59
- char *start = RSTRING_PTR(stream->buffer) + stream->pos;
60
59
  while (true) {
60
+ char *start = RSTRING_PTR(stream->buffer) + stream->pos;
61
61
  ssize_t pending_len = stream->len - stream->pos;
62
62
  ssize_t search_len = pending_len;
63
63
  ssize_t absmax_len = labs(maxlen);
@@ -76,32 +76,31 @@ VALUE stream_get_line(struct um_stream *stream, VALUE buf, ssize_t maxlen) {
76
76
  return buf;
77
77
  }
78
78
  else if (should_limit_len && pending_len > search_len)
79
- // maxlen
79
+ // hit maxlen
80
80
  return Qnil;
81
81
 
82
82
  if (!stream_read_more(stream))
83
83
  return Qnil;
84
- else
85
- // update start ptr (it might have changed after reading)
86
- start = RSTRING_PTR(stream->buffer) + stream->pos;
87
84
  }
88
85
  }
89
86
 
90
87
  VALUE stream_get_string(struct um_stream *stream, VALUE buf, ssize_t len) {
91
88
  size_t abslen = labs(len);
92
- while (stream->len - stream->pos < abslen)
89
+ while (stream->len - stream->pos < abslen) {
93
90
  if (!stream_read_more(stream)) {
94
- if (len > 0) return Qnil;
91
+ if (len > 0)
92
+ return Qnil;
95
93
 
96
94
  abslen = stream->len - stream->pos;
97
95
  }
96
+ }
98
97
 
99
98
  char *start = RSTRING_PTR(stream->buffer) + stream->pos;
100
99
  stream->pos += abslen;
101
100
 
102
101
  if (NIL_P(buf)) return rb_utf8_str_new(start, abslen);
103
102
 
104
- str_copy_bytes(buf, start, len);
103
+ str_copy_bytes(buf, start, abslen);
105
104
  return buf;
106
105
  }
107
106
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class UringMachine
4
- VERSION = '0.28.1'
4
+ VERSION = '0.28.3'
5
5
  end
data/lib/uringmachine.rb CHANGED
@@ -36,9 +36,17 @@ class UringMachine
36
36
  fiber
37
37
  end
38
38
 
39
+ TERMINATE_EXCEPTION = UM::Terminate.new
40
+
41
+ # Terminates the given fibers by scheduling them with a `UM::Terminate`
42
+ # exception. This method does not wait for the fibers to be done.
43
+ #
44
+ # @param *fibers [Array<Fiber>] fibers to terminate
45
+ # @return [void]
39
46
  def terminate(*fibers)
40
- exception = UM::Terminate.new
41
- fibers.each { schedule(it, exception) }
47
+ fibers = fibers.first if fibers.size == 1 && fibers.first.is_a?(Enumerable)
48
+
49
+ fibers.each { schedule(it, TERMINATE_EXCEPTION) }
42
50
  end
43
51
 
44
52
  # Runs the given block in the given fiber. This method is used to run fibers
@@ -58,6 +66,8 @@ class UringMachine
58
66
  #
59
67
  # @return [Array<any>] return values of the given fibers
60
68
  def join(*fibers)
69
+ fibers = fibers.first if fibers.size == 1 && fibers.first.is_a?(Enumerable)
70
+
61
71
  results = fibers.inject({}) { |h, f| h[f] = nil; h }
62
72
  queue = nil
63
73
  pending = nil
data/test/test_stream.rb CHANGED
@@ -234,3 +234,20 @@ class StreamRespTest < StreamBaseTest
234
234
  s.resp_encode_cmd(+'', :set, 'foobar', :nx, :xx)
235
235
  end
236
236
  end
237
+
238
+ class StreamHTTPTest < StreamBaseTest
239
+ def test_stream_http_etc
240
+ machine.write(@wfd, "GET / HTTP/1.1\r\n\r\nblahblah")
241
+ machine.close(@wfd)
242
+
243
+ l = @stream.get_line(nil, 0)
244
+ assert_equal "GET / HTTP/1.1", l
245
+
246
+ l = @stream.get_line(nil, 0)
247
+ assert_equal '', l
248
+
249
+ l = @stream.get_string(nil, -50)
250
+ assert_equal 'blahblah', l
251
+ end
252
+ end
253
+
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.28.1
4
+ version: 0.28.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner