io-stream 0.1.1 → 0.3.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: 22ab50a346a6b3a70840063e6c89b136be1bf6a1a1368a2350bc43613249863e
4
- data.tar.gz: f797366850b5e7924f371ee6356331277626940e421eaff48ccce49c13a4b4af
3
+ metadata.gz: f6a65103b45022f50d46603a178bb87f7bf8a11ab24da10e855dd7c18233a261
4
+ data.tar.gz: d0870c42173b4e87388ea1f3c56e68323c394cac7bf4ea1d90cd879d1c02b8a4
5
5
  SHA512:
6
- metadata.gz: b9baea0d3389daf96359f4865dac6e3fad380f706c579815bfb8d818f09593b9a09a04f0d44d18a21c7e63449963e3d3c6ea5dcfffc2421e0a6b91c4db80b7a4
7
- data.tar.gz: 59e2865c43bb179598e431592222d76e45906cc12be1013831e43306cd46d88795a92ee132aface5c12bc87457b2f3e9a7e942bedf0b3e47d4db73e03cbf9db2
6
+ metadata.gz: 97d1162cf543a3b604a1fe1873525d8c6278c1adac118fe165e0d1066a8421b06a4932e96e46276bc7abe8f618fe0bc89f45c5f13dd262d52c2e58e65cd5f878
7
+ data.tar.gz: 0c7db373575894a7271133aa1f610246efad907e7e168114ba677c64fbfb7a0695fd80dd286585ebdfe5af6e88f44d1f2a2c3ecf339fda540eb8ac913a2f181a
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- Y]ˏ���� �T��5��m~9�S�'J.G֝���괻 ���0W���e�S��� �"���.�{����`�Cy����"��\���^�։��sv�Z�t��j���T�>8�n�&�Є4�a9jXGsˎN�?y�;�V52��7��8��W�p3�Ǟ�C�� =�j�?90r��8f5BySUŨ����y�����Hj�6�r�ʶ��W�"R|#;�ȃ>%0�[.���`���?|��$���4M���S� F�_�3Mj�� M�T)�.T�Jg�/F�I�N���S�ޕ�ðFkA�� LA{��4��Q�cV>{K�b �Ĕ�z�'���`�A\xknK����2q=��%��
2
- i�)yWI��~i��U~
1
+ \^�l�m /���������Zع�ol��Rs�7W�$ |�#� ��W�ѕ`�dG���%ҹ�� ��oV�:� IOOaCȍ*a^+�ZQ�~�;��]-�x��.SL��%�l��.�b�*J��!f`V[��b���s�|b��fP����Di��F;������5vOGu,�8h
2
+ OEX0`U)z��^8�.jNc�Ǟ)<�~�+Fd}�ff����ٻ�oUT�@@Bs�_ȶd�B�4�7���{�6:�����f�p�4Y��+/��-.I�����^�Ot�U���ND2��@g
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2023-2024, by Samuel Williams.
4
+ # Copyright, 2024, by Samuel Williams.
5
5
 
6
6
  require_relative 'generic'
7
7
 
@@ -41,6 +41,11 @@ module IO::Stream
41
41
  super(...)
42
42
 
43
43
  @io = io
44
+ if io.respond_to?(:timeout)
45
+ @timeout = io.timeout
46
+ else
47
+ @timeout = nil
48
+ end
44
49
  end
45
50
 
46
51
  attr :io
@@ -70,7 +75,25 @@ module IO::Stream
70
75
  end
71
76
 
72
77
  def syswrite(buffer)
73
- @io.write(buffer)
78
+ # This fails due to re-entrancy issues with a concurrent call to `sysclose`.
79
+ # return @io.write(buffer)
80
+
81
+ while true
82
+ result = @io.write_nonblock(buffer, exception: false)
83
+
84
+ case result
85
+ when :wait_readable
86
+ @io.wait_readable(@io.timeout) or raise ::IO::TimeoutError, "read timeout"
87
+ when :wait_writable
88
+ @io.wait_writable(@io.timeout) or raise ::IO::TimeoutError, "write timeout"
89
+ else
90
+ if result == buffer.bytesize
91
+ return
92
+ else
93
+ buffer = buffer.byteslice(result, buffer.bytesize)
94
+ end
95
+ end
96
+ end
74
97
  end
75
98
 
76
99
  # Reads data from the underlying stream as efficiently as possible.
@@ -81,9 +104,9 @@ module IO::Stream
81
104
 
82
105
  case result
83
106
  when :wait_readable
84
- @io.wait_readable
107
+ @io.wait_readable(@io.timeout) or raise ::IO::TimeoutError, "read timeout"
85
108
  when :wait_writable
86
- @io.wait_writable
109
+ @io.wait_writable(@io.timeout) or raise ::IO::TimeoutError, "write timeout"
87
110
  else
88
111
  return result
89
112
  end
@@ -5,8 +5,9 @@
5
5
 
6
6
  require_relative 'string_buffer'
7
7
 
8
- require_relative '../buffered'
9
- require_relative '../readable'
8
+ require_relative 'shim/buffered'
9
+ require_relative 'shim/readable'
10
+ require_relative 'shim/timeout'
10
11
 
11
12
  require_relative 'openssl'
12
13
 
@@ -1,3 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
5
+
1
6
  require 'openssl'
2
7
 
3
8
  module OpenSSL
@@ -26,6 +31,18 @@ module OpenSSL
26
31
  to_io.wait_writable(...)
27
32
  end
28
33
  end
34
+
35
+ unless method_defined?(:timeout)
36
+ def timeout
37
+ to_io.timeout
38
+ end
39
+ end
40
+
41
+ unless method_defined?(:timeout=)
42
+ def timeout=(value)
43
+ to_io.timeout = value
44
+ end
45
+ end
29
46
  end
30
47
  end
31
48
  end
@@ -0,0 +1,4 @@
1
+ # Shims
2
+
3
+ Several shims are included for compatibility.
4
+
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ class IO
4
+ unless const_defined?(:TimeoutError)
5
+ # Compatibility shim.
6
+ class TimeoutError < IOError
7
+ end
8
+ end
9
+
10
+ unless method_defined?(:timeout)
11
+ # Compatibility shim.
12
+ attr_accessor :timeout
13
+ end
14
+ end
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2023-2024, by Samuel Williams.
5
5
 
6
6
  module IO::Stream
7
- VERSION = "0.1.1"
7
+ VERSION = "0.3.0"
8
8
  end
data/lib/io/stream.rb CHANGED
@@ -4,7 +4,7 @@
4
4
  # Copyright, 2023-2024, by Samuel Williams.
5
5
 
6
6
  require_relative 'stream/version'
7
- require_relative 'stream/buffered_stream'
7
+ require_relative 'stream/buffered'
8
8
 
9
9
  class IO
10
10
  module Stream
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: io-stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -45,12 +45,14 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - lib/io/buffered.rb
49
- - lib/io/readable.rb
50
48
  - lib/io/stream.rb
51
49
  - lib/io/stream/buffered.rb
52
50
  - lib/io/stream/generic.rb
53
51
  - lib/io/stream/openssl.rb
52
+ - lib/io/stream/shim/buffered.rb
53
+ - lib/io/stream/shim/readable.rb
54
+ - lib/io/stream/shim/shim.md
55
+ - lib/io/stream/shim/timeout.rb
54
56
  - lib/io/stream/string_buffer.rb
55
57
  - lib/io/stream/version.rb
56
58
  - license.md
metadata.gz.sig CHANGED
Binary file
File without changes
File without changes