uringmachine 0.28.0 → 0.28.2

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: c42e434298bf496752efc6fe6a4cc81d04857f28f1151cfc3165ac3c288ec6a2
4
- data.tar.gz: ec176b165f129aa7d1b6d0bdbc5f4b7e55d5e553569061d89956d0b1aee68503
3
+ metadata.gz: 21a7c3c4503c06967ae77b6b3c8da3fb0f19eae3373efccb018ff111dc6d2aa8
4
+ data.tar.gz: 5376adb14245278692e634fdb6843080239a7a806b13032706b91036a9483c1a
5
5
  SHA512:
6
- metadata.gz: 1760b892d6ae21c7007fd0a109a78d631da4ae9a79667ad85bc4740ac0e339802ca9cb0bc34114570bf7e6113e4dab704a1c9f40513a196e840b759a494a35b9
7
- data.tar.gz: 7dfe1426f96ecd1e99af4224c34d3b3173858b5d6c156b949314a0e80c34b836ae738e930ed26662319bc6700401cd0b369028e172ed1b70982cee64fb13f7a1
6
+ metadata.gz: 0b00614b471f51e8c3e31c77b2844284c371a4c0a73b30c0016969421ee20777ce2ca5ee215201a1a31aec189f7f703f39a0884c262c3ffc5c36ccbbae73a6f1
7
+ data.tar.gz: 26efdd3e98c013e9edd0962cc0fcab3bd9454485743fabc05a1d181200ad256aeb649618193048451850b39623f48cd69e9563f21defb8a178c5dcc300f24eb5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 0.28.2 2026-02-20
2
+
3
+ - Fix `Stream#get_string`
4
+
5
+ # 0.28.1 2026-02-20
6
+
7
+ - Add `Stream#machine`, `Stream#fd`
8
+
1
9
  # 0.28.0 2026-02-19
2
10
 
3
11
  - Add `#terminate`
data/TODO.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  - Add tests for support for Set in `machine#await_fibers`
4
4
  - Add tests for support for Set, Array in `machine#join`
5
+ - Add `#read_file` for reading entire file
6
+ - Add `#write_file` for writing entire file
5
7
 
6
8
  - (?) Fix all futex value (Queue, Mutex) to be properly aligned
7
9
 
@@ -110,3 +112,36 @@ stream.read_to_eof(buf)
110
112
  # defaults:
111
113
  stream.read_to_eof(nil)
112
114
  ```
115
+
116
+ ## Syntax / pattern for launching multiple operations
117
+
118
+ ```ruby
119
+ results = machine.concurrently(
120
+ -> { machine.read(fd1, ...) },
121
+ -> { machine.read(fd2, ...) }
122
+ -> { ... }
123
+ )
124
+
125
+ # or maybe:
126
+ jobs = (1..100).map { |i| -> { machine.read_file("/file_#{i}.csv") } }
127
+ machine.join(jobs)
128
+
129
+ # or maybe:
130
+ jobs = (1..100).map { |i|
131
+ -> {
132
+ pipe { machine.read_file("/file_#{i}.csv") }
133
+ > { csv_to_pdf(it) }
134
+ > { machine.write_file("/file_#{i}.pdf", it) }
135
+ }
136
+ }
137
+
138
+ # or otherwise
139
+ jobs = (1..100).map { |i|
140
+ -> {
141
+ csv = machine.read_file("/file_#{i}.csv")
142
+ pdf = csv_to_pdf(csv)
143
+ machine.write_file("/file_#{i}.pdf", pdf)
144
+ }
145
+ }
146
+ machine.join(jobs)
147
+ ```
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
 
@@ -51,6 +51,16 @@ VALUE Stream_initialize(VALUE self, VALUE machine, VALUE fd) {
51
51
  return self;
52
52
  }
53
53
 
54
+ VALUE Stream_machine(VALUE self) {
55
+ struct um_stream *stream = Stream_data(self);
56
+ return stream->machine->self;
57
+ }
58
+
59
+ VALUE Stream_fd(VALUE self) {
60
+ struct um_stream *stream = Stream_data(self);
61
+ return ULONG2NUM(stream->fd);
62
+ }
63
+
54
64
  VALUE Stream_get_line(VALUE self, VALUE buf, VALUE limit) {
55
65
  struct um_stream *stream = Stream_data(self);
56
66
  if (unlikely(stream->eof)) return Qnil;
@@ -109,6 +119,8 @@ void Init_Stream(void) {
109
119
  rb_define_alloc_func(cStream, Stream_allocate);
110
120
 
111
121
  rb_define_method(cStream, "initialize", Stream_initialize, 2);
122
+ rb_define_method(cStream, "machine", Stream_machine, 0);
123
+ rb_define_method(cStream, "fd", Stream_fd, 0);
112
124
 
113
125
  rb_define_method(cStream, "get_line", Stream_get_line, 2);
114
126
  rb_define_method(cStream, "get_string", Stream_get_string, 2);
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class UringMachine
4
- VERSION = '0.28.0'
4
+ VERSION = '0.28.2'
5
5
  end
data/test/test_stream.rb CHANGED
@@ -11,6 +11,14 @@ class StreamBaseTest < UMBaseTest
11
11
  end
12
12
 
13
13
  class StreamTest < StreamBaseTest
14
+ def test_stream_machine
15
+ assert_equal @machine, @stream.machine
16
+ end
17
+
18
+ def test_stream_fd
19
+ assert_equal @rfd, @stream.fd
20
+ end
21
+
14
22
  def test_get_line
15
23
  machine.write(@wfd, "foo\nbar\r\nbaz")
16
24
  machine.close(@wfd)
@@ -226,3 +234,20 @@ class StreamRespTest < StreamBaseTest
226
234
  s.resp_encode_cmd(+'', :set, 'foobar', :nx, :xx)
227
235
  end
228
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
+
data/test/test_um.rb CHANGED
@@ -2103,26 +2103,6 @@ class SendRecvFdTest < UMBaseTest
2103
2103
  machine.close(w_fd) rescue nil
2104
2104
  end
2105
2105
 
2106
- def test_send_recv_fd_fork_inverse
2107
- pid = fork do
2108
- m = UM.new
2109
- r, w = UM.pipe
2110
- m.send_fd(@s2_fd, r)
2111
-
2112
- buf = +''
2113
- m.read(r, buf, 128)
2114
- m.send(@s2_fd, buf)
2115
- end
2116
-
2117
- assert_raises(Errno::EINVAL) { machine.recv_fd(@s1_fd) }
2118
- ensure
2119
- if pid
2120
- Process.kill('KILL', pid) rescue nil
2121
- Process.wait(pid) rescue nil
2122
- end
2123
- machine.close(w) rescue nil
2124
- end
2125
-
2126
2106
  def test_send_fd_bad_sock_fd
2127
2107
  _r_fd, w_fd = UM.pipe
2128
2108
  assert_raises(Errno::ENOTSOCK) { machine.send_fd(0, w_fd) }
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.0
4
+ version: 0.28.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner