dalli 5.0.5 → 5.0.7

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.
data/lib/dalli/socket.rb CHANGED
@@ -12,48 +12,63 @@ module Dalli
12
12
  # Common methods for all socket implementations.
13
13
  ##
14
14
  module InstanceMethods
15
- def readfull(count)
16
- value = String.new(capacity: count + 1)
17
- loop do
18
- result = read_nonblock(count - value.bytesize, exception: false)
19
- value << result if append_to_buffer?(result)
20
- break if value.bytesize == count
15
+ def read_available(reusable_buffer = nil)
16
+ if reusable_buffer
17
+ value = read_nonblock(8196, reusable_buffer, exception: false)
18
+ case value
19
+ when :wait_writable, :wait_readable
20
+ return reusable_buffer.clear
21
+ when nil
22
+ raise Errno::ECONNRESET, "Connection reset: #{logged_options.inspect}"
23
+ end
24
+ else
25
+ value = ''.b
21
26
  end
22
- value
23
- end
24
27
 
25
- def read_available
26
- value = +''
28
+ buffer = ''.b
27
29
  loop do
28
- result = read_nonblock(8196, exception: false)
29
- break if WAIT_RCS.include?(result)
30
- raise Errno::ECONNRESET, "Connection reset: #{logged_options.inspect}" unless result
31
-
32
- value << result
30
+ result = read_nonblock(8196, buffer, exception: false)
31
+ case result
32
+ when :wait_writable, :wait_readable
33
+ buffer.clear
34
+ return value
35
+ when nil
36
+ raise Errno::ECONNRESET, "Connection reset: #{logged_options.inspect}"
37
+ else
38
+ value << result
39
+ end
33
40
  end
34
- value
35
- end
36
-
37
- WAIT_RCS = %i[wait_writable wait_readable].freeze
38
-
39
- def append_to_buffer?(result)
40
- raise Timeout::Error, "IO timeout: #{logged_options.inspect}" if nonblock_timed_out?(result)
41
- raise Errno::ECONNRESET, "Connection reset: #{logged_options.inspect}" unless result
42
-
43
- !WAIT_RCS.include?(result)
44
- end
45
-
46
- def nonblock_timed_out?(result)
47
- return true if result == :wait_readable && !wait_readable(options[:socket_timeout])
48
-
49
- # TODO: Do we actually need this? Looks to be only used in read_nonblock
50
- result == :wait_writable && !wait_writable(options[:socket_timeout])
51
41
  end
52
42
 
53
43
  FILTERED_OUT_OPTIONS = %i[username password].freeze
54
44
  def logged_options
55
45
  options.except(*FILTERED_OUT_OPTIONS)
56
46
  end
47
+
48
+ # JRuby doesn't support IO#timeout=, so use custom readfull implementation
49
+ # CRuby 3.3+ has IO#timeout= which makes IO#read work with timeouts
50
+ if RUBY_ENGINE == 'jruby'
51
+ def readfull(count)
52
+ value = String.new(capacity: count + 1)
53
+
54
+ until value.bytesize == count
55
+ result = read_nonblock(count - value.bytesize, exception: false)
56
+ case result
57
+ when :wait_readable
58
+ wait_readable(options[:socket_timeout]) or raise Timeout::Error, "IO timeout: #{logged_options.inspect}"
59
+ when :wait_writable
60
+ wait_writable(options[:socket_timeout]) or raise Timeout::Error, "IO timeout: #{logged_options.inspect}"
61
+ when nil
62
+ raise Errno::ECONNRESET, "Connection reset: #{logged_options.inspect}"
63
+ else
64
+ value << result
65
+ end
66
+ end
67
+
68
+ value
69
+ end
70
+ # rubocop:enable Metrics/AbcSize
71
+ end
57
72
  end
58
73
 
59
74
  ##
data/lib/dalli/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dalli
4
- VERSION = '5.0.5'
4
+ VERSION = '5.0.7'
5
5
 
6
6
  MIN_SUPPORTED_MEMCACHED_VERSION = '1.6'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dalli
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.5
4
+ version: 5.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter M. Goldstein
@@ -44,7 +44,6 @@ files:
44
44
  - lib/dalli/instrumentation.rb
45
45
  - lib/dalli/key_manager.rb
46
46
  - lib/dalli/options.rb
47
- - lib/dalli/pid_cache.rb
48
47
  - lib/dalli/pipelined_deleter.rb
49
48
  - lib/dalli/pipelined_getter.rb
50
49
  - lib/dalli/pipelined_setter.rb
@@ -88,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
87
  - !ruby/object:Gem::Version
89
88
  version: '0'
90
89
  requirements: []
91
- rubygems_version: 4.0.12
90
+ rubygems_version: 4.0.21
92
91
  specification_version: 4
93
92
  summary: High performance memcached client for Ruby
94
93
  test_files: []
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Dalli
4
- ##
5
- # Dalli::PIDCache is a wrapper class for PID checking to avoid system calls when checking the PID.
6
- ##
7
- module PIDCache
8
- if !Process.respond_to?(:fork) # JRuby or TruffleRuby
9
- @pid = Process.pid
10
- singleton_class.attr_reader(:pid)
11
- elsif Process.respond_to?(:_fork) # Ruby 3.1+
12
- class << self
13
- attr_reader :pid
14
-
15
- def update!
16
- @pid = Process.pid # rubocop:disable ThreadSafety/ClassInstanceVariable
17
- end
18
- end
19
- update!
20
-
21
- ##
22
- # Dalli::PIDCache::CoreExt hooks into Process to be able to reset the PID cache after fork
23
- ##
24
- module CoreExt
25
- def _fork
26
- child_pid = super
27
- PIDCache.update! if child_pid.zero?
28
- child_pid
29
- end
30
- end
31
- Process.singleton_class.prepend(CoreExt)
32
- else # Ruby 3.0 or older
33
- class << self
34
- def pid
35
- Process.pid
36
- end
37
- end
38
- end
39
- end
40
- end