Module: Dalli::Socket::InstanceMethods
Overview
Common methods for all socket implementations.
Constant Summary collapse
- WAIT_RCS =
%i[wait_writable wait_readable].freeze
- FILTERED_OUT_OPTIONS =
%i[username password].freeze
Instance Method Summary collapse
- #append_to_buffer?(result) ⇒ Boolean
- #logged_options ⇒ Object
- #nonblock_timed_out?(result) ⇒ Boolean
- #read_available ⇒ Object
- #readfull(count) ⇒ Object
Instance Method Details
#append_to_buffer?(result) ⇒ Boolean
39 40 41 42 43 44 |
# File 'lib/dalli/socket.rb', line 39 def append_to_buffer?(result) raise Timeout::Error, "IO timeout: #{.inspect}" if nonblock_timed_out?(result) raise Errno::ECONNRESET, "Connection reset: #{.inspect}" unless result !WAIT_RCS.include?(result) end |
#logged_options ⇒ Object
54 55 56 |
# File 'lib/dalli/socket.rb', line 54 def .reject { |k, _| FILTERED_OUT_OPTIONS.include? k } end |
#nonblock_timed_out?(result) ⇒ Boolean
46 47 48 49 50 51 |
# File 'lib/dalli/socket.rb', line 46 def nonblock_timed_out?(result) return true if result == :wait_readable && !wait_readable([:socket_timeout]) # TODO: Do we actually need this? Looks to be only used in read_nonblock result == :wait_writable && !wait_writable([:socket_timeout]) end |
#read_available ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dalli/socket.rb', line 25 def read_available value = +'' loop do result = read_nonblock(8196, exception: false) break if WAIT_RCS.include?(result) raise Errno::ECONNRESET, "Connection reset: #{.inspect}" unless result value << result end value end |
#readfull(count) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/dalli/socket.rb', line 15 def readfull(count) value = String.new(capacity: count + 1) loop do result = read_nonblock(count - value.bytesize, exception: false) value << result if append_to_buffer?(result) break if value.bytesize == count end value end |