Skip to content

Commit 5dcf1b4

Browse files
committed
Use read instead of readfull
1 parent 159d3ec commit 5dcf1b4

File tree

3 files changed

+3
-27
lines changed

3 files changed

+3
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Unreleased
66

77
- Fix cannot read response data included terminator `\r\n` when use meta protocol (matsubara0507)
88
- Support SERVER_ERROR response from Memcached as per the [memcached spec](https://github.com/memcached/memcached/blob/e43364402195c8e822bb8f88755a60ab8bbed62a/doc/protocol.txt#L172) (grcooper)
9+
- Remove Socket#readfull and replace with standard read method (grcooper)
910

1011
3.2.8
1112
==========

lib/dalli/protocol/connection_manager.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def read_line
155155
end
156156

157157
def read(count)
158-
@sock.readfull(count)
158+
@sock.read(count)
159159
rescue SystemCallError, *TIMEOUT_ERRORS, EOFError => e
160160
error_on_request!(e)
161161
end

lib/dalli/socket.rb

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,7 @@ module Socket
1212
# Common methods for all socket implementations.
1313
##
1414
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
21-
end
22-
value
23-
end
24-
15+
WAIT_RCS = %i[wait_writable wait_readable].freeze
2516
def read_available
2617
value = +''
2718
loop do
@@ -34,22 +25,6 @@ def read_available
3425
value
3526
end
3627

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-
end
52-
5328
FILTERED_OUT_OPTIONS = %i[username password].freeze
5429
def logged_options
5530
options.reject { |k, _| FILTERED_OUT_OPTIONS.include? k }

0 commit comments

Comments
 (0)