module Dalli::Socket::InstanceMethods

Common methods for all socket implementations.

Constants

FILTERED_OUT_OPTIONS
WAIT_RCS

Public Instance Methods

append_to_buffer?(result) click to toggle source
# File lib/dalli/socket.rb, line 39
def append_to_buffer?(result)
  raise Timeout::Error, "IO timeout: #{logged_options.inspect}" if nonblock_timed_out?(result)
  raise Errno::ECONNRESET, "Connection reset: #{logged_options.inspect}" unless result

  !WAIT_RCS.include?(result)
end
logged_options() click to toggle source
# File lib/dalli/socket.rb, line 54
def logged_options
  options.reject { |k, _| FILTERED_OUT_OPTIONS.include? k }
end
nonblock_timed_out?(result) click to toggle source
# File lib/dalli/socket.rb, line 46
def nonblock_timed_out?(result)
  return true if result == :wait_readable && !wait_readable(options[:socket_timeout])

  # TODO: Do we actually need this?  Looks to be only used in read_nonblock
  result == :wait_writable && !wait_writable(options[:socket_timeout])
end
read_available() click to toggle source
# 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: #{logged_options.inspect}" unless result

    value << result
  end
  value
end
readfull(count) click to toggle source
# File lib/dalli/socket.rb, line 15
def readfull(count)
  value = +''
  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