Module: Dalli::Socket::InstanceMethods

Included in:
SSLSocket, TCP, UNIX
Defined in:
lib/dalli/socket.rb

Instance Method Summary collapse

Instance Method Details

#read_availableObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dalli/socket.rb', line 27

def read_available
  value = +""
  loop do
    result = read_nonblock(8196, exception: false)
    if result == :wait_readable
      break
    elsif result == :wait_writable
      break
    elsif result
      value << result
    else
      raise Errno::ECONNRESET, "Connection reset: #{safe_options.inspect}"
    end
  end
  value
end

#readfull(count) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dalli/socket.rb', line 9

def readfull(count)
  value = +""
  loop do
    result = read_nonblock(count - value.bytesize, exception: false)
    if result == :wait_readable
      raise Timeout::Error, "IO timeout: #{safe_options.inspect}" unless IO.select([self], nil, nil, options[:socket_timeout])
    elsif result == :wait_writable
      raise Timeout::Error, "IO timeout: #{safe_options.inspect}" unless IO.select(nil, [self], nil, options[:socket_timeout])
    elsif result
      value << result
    else
      raise Errno::ECONNRESET, "Connection reset: #{safe_options.inspect}"
    end
    break if value.bytesize == count
  end
  value
end

#safe_optionsObject



44
45
46
# File 'lib/dalli/socket.rb', line 44

def safe_options
  options.reject { |k, v| [:username, :password].include? k }
end