io-stream 0.1.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15a89f071ddff7b47577a25a20195cb1d246f9b7105af8ee605ae01e0d267923
4
- data.tar.gz: c29039d3ab0d1e234733ddf38f1ddc4be40cbffa92b5f9b47ba1dc247e9ea357
3
+ metadata.gz: 93cc26a0208cdfd7e20115522eeb3a51234834a5b6ce6670248c6bb85dd84e3c
4
+ data.tar.gz: bec8f1a9e90cb7fe37845d4acb96c0c8f1919d253662da476a169a29a27b33bf
5
5
  SHA512:
6
- metadata.gz: 90d91151a245677dd5e7b96c2942af1b85f16d2a59c64c981e0d3d256d4af0ce5cc81115bfeb3a1981f765695e4777a0e76caf9c8f3d8995bbba204ebce8d91e
7
- data.tar.gz: e40408fa7e69bab982229290640cb0e9c7a4efb9bc39ac40003ef1fe698f1aac962cd10a7464b5b2643bf46dddf6697e26296209527d507a0d135f112bc4bbae
6
+ metadata.gz: 865a0a1031f7c83bbd428675e970fd2421a42ae4e19cd22ccf2080678d4009c78add651212f1f69cada5ba07075e1411d39978f3f9cba721d291a56f266a71e8
7
+ data.tar.gz: 73ff08ba993904115d3158fe5e233cc6e0e9667c34614b4c1e4efae5873417a3cd8f08cb30ac58edace8cb118ee640afdef1f37aaa73677d2c4ca64f7bad82de
checksums.yaml.gz.sig CHANGED
Binary file
@@ -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
 
@@ -22,6 +22,8 @@ module IO::Stream
22
22
  def self.wrap(io, **options)
23
23
  if io.respond_to?(:buffered=)
24
24
  io.buffered = false
25
+ else
26
+ io.sync = true
25
27
  end
26
28
 
27
29
  stream = self.new(io, **options)
@@ -39,6 +41,11 @@ module IO::Stream
39
41
  super(...)
40
42
 
41
43
  @io = io
44
+ if io.respond_to?(:timeout)
45
+ @timeout = io.timeout
46
+ else
47
+ @timeout = nil
48
+ end
42
49
  end
43
50
 
44
51
  attr :io
@@ -68,7 +75,25 @@ module IO::Stream
68
75
  end
69
76
 
70
77
  def syswrite(buffer)
71
- @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
72
97
  end
73
98
 
74
99
  # Reads data from the underlying stream as efficiently as possible.
@@ -79,9 +104,9 @@ module IO::Stream
79
104
 
80
105
  case result
81
106
  when :wait_readable
82
- @io.wait_readable
107
+ @io.wait_readable(@io.timeout) or raise ::IO::TimeoutError, "read timeout"
83
108
  when :wait_writable
84
- @io.wait_writable
109
+ @io.wait_writable(@io.timeout) or raise ::IO::TimeoutError, "write timeout"
85
110
  else
86
111
  return result
87
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.0"
7
+ VERSION = "0.4.0"
8
8
  end
data/lib/io/stream.rb CHANGED
@@ -4,9 +4,17 @@
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
11
11
  end
12
+
13
+ def self.Stream(io)
14
+ if io.is_a?(Stream::Buffered)
15
+ io
16
+ else
17
+ Stream::Buffered.wrap(io)
18
+ end
19
+ end
12
20
  end
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.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -37,7 +37,7 @@ cert_chain:
37
37
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
38
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
39
  -----END CERTIFICATE-----
40
- date: 2024-04-22 00:00:00.000000000 Z
40
+ date: 2024-04-23 00:00:00.000000000 Z
41
41
  dependencies: []
42
42
  description:
43
43
  email:
@@ -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