uringmachine 1.0.5 → 1.0.6
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/uringmachine/version.rb +1 -1
- data/lib/uringmachine.rb +14 -2
- data/test/test_um.rb +18 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1c37bb6e6971036cefa78d76efbb4425f843087b4b4f5e24fe16e695920746b8
|
|
4
|
+
data.tar.gz: 144e109b5dfa199adda69387c7229c78393f3ee8b0a45f545db76934f896ef2c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3d19ae0d9c4056c691a8b9c93901f759e2b149ebd275d8a5d1e0dcfc33e2308eef0e583541b2ce90b69d55efc20b4ab0c7415f4e44d0c9753b07e733bc965e90
|
|
7
|
+
data.tar.gz: 697653d6d9120bcbece655bf530e1e87e9fc461e2052bd20b8666f344440ee11898b569c3d98a7477c39dd11bdf6ff03fc6b1e08f953c257a84fb0aea58a882f
|
data/CHANGELOG.md
CHANGED
data/lib/uringmachine/version.rb
CHANGED
data/lib/uringmachine.rb
CHANGED
|
@@ -50,7 +50,7 @@ class UringMachine
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
# Runs the given block in the given fiber. This method is used to run fibers
|
|
53
|
-
# indirectly.
|
|
53
|
+
# indirectly. See FiberScheduler#fiber
|
|
54
54
|
#
|
|
55
55
|
# @param fiber [Fiber] fiber
|
|
56
56
|
# @param block [Proc] block to run
|
|
@@ -202,9 +202,10 @@ class UringMachine
|
|
|
202
202
|
# the type of target and how it is read from:
|
|
203
203
|
#
|
|
204
204
|
# - :fd - read from the given fd using the buffer pool (default mode)
|
|
205
|
+
# - :file - read from a regular file
|
|
205
206
|
# - :socket - receive from the given socket fd using the buffer pool
|
|
206
207
|
# - :ssl - read from the given SSL socket
|
|
207
|
-
#
|
|
208
|
+
#
|
|
208
209
|
# If a block is given, the block will be called with the IO instance as
|
|
209
210
|
# argument and the method will return the block's return value.
|
|
210
211
|
#
|
|
@@ -220,6 +221,17 @@ class UringMachine
|
|
|
220
221
|
res
|
|
221
222
|
end
|
|
222
223
|
|
|
224
|
+
# call-seq:
|
|
225
|
+
# machine.file_read(fn) -> data
|
|
226
|
+
#
|
|
227
|
+
# Reads and returns the content of the given filename, with a maximum length of 1GB.
|
|
228
|
+
#
|
|
229
|
+
# @param fn [String] filename
|
|
230
|
+
# @return [String] file content
|
|
231
|
+
def file_read(fn)
|
|
232
|
+
open(fn, O_RDONLY) { io(it, :file).read(-(1 << 30)) }
|
|
233
|
+
end
|
|
234
|
+
|
|
223
235
|
# Creates, binds and sets up a TCP socket for listening on the given host and
|
|
224
236
|
# port.
|
|
225
237
|
#
|
data/test/test_um.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative 'helper'
|
|
4
4
|
require 'socket'
|
|
5
|
+
require 'tempfile'
|
|
5
6
|
|
|
6
7
|
class UringMachineTest < Minitest::Test
|
|
7
8
|
def test_kernel_version
|
|
@@ -3520,6 +3521,23 @@ class IOMethodTest < UMBaseTest
|
|
|
3520
3521
|
end
|
|
3521
3522
|
end
|
|
3522
3523
|
|
|
3524
|
+
class FileHelperMethodsTest < UMBaseTest
|
|
3525
|
+
def setup
|
|
3526
|
+
super
|
|
3527
|
+
@fn = Tempfile.new('uringmachine_test_io_from_file').path
|
|
3528
|
+
end
|
|
3529
|
+
|
|
3530
|
+
def test_file_read
|
|
3531
|
+
IO.write(@fn, 'foobar' * 321)
|
|
3532
|
+
buf = machine.file_read(@fn)
|
|
3533
|
+
assert_equal 'foobar' * 321, buf
|
|
3534
|
+
end
|
|
3535
|
+
|
|
3536
|
+
def test_file_read_bad_fn
|
|
3537
|
+
assert_raises(Errno::ENOENT) { machine.file_read(@fn + '-missing') }
|
|
3538
|
+
end
|
|
3539
|
+
end
|
|
3540
|
+
|
|
3523
3541
|
class TCPHelperMethodsTest < UMBaseTest
|
|
3524
3542
|
def setup
|
|
3525
3543
|
super
|