Parent

Dalli::Server::KSocket

Attributes

options[RW]
server[RW]

Public Class Methods

open(host, port, server, options = {}) click to toggle source
# File lib/dalli/socket.rb, line 16
def self.open(host, port, server, options = {})
  addr = Socket.pack_sockaddr_in(port, host)
  sock = start(addr)
  sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true)
  sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true) if options[:keepalive]
  sock.options = options
  sock.server = server
  sock.kgio_wait_writable
  sock
end

Public Instance Methods

kgio_wait_readable() click to toggle source
# File lib/dalli/socket.rb, line 8
def kgio_wait_readable
  IO.select([self], nil, nil, options[:socket_timeout]) || raise(Timeout::Error, "IO timeout")
end
kgio_wait_writable() click to toggle source
# File lib/dalli/socket.rb, line 12
def kgio_wait_writable
  IO.select(nil, [self], nil, options[:socket_timeout]) || raise(Timeout::Error, "IO timeout")
end
read_available() click to toggle source
# File lib/dalli/socket.rb, line 38
def read_available
  value = ''
  loop do
    ret = kgio_tryread(8196)
    case ret
    when nil
      raise EOFError, 'end of stream'
    when :wait_readable
      break
    else
      value << ret
    end
  end
  value
end
readfull(count) click to toggle source
# File lib/dalli/socket.rb, line 29
def readfull(count)
  value = ''
  loop do
    value << kgio_read!(count - value.bytesize)
    break if value.bytesize == count
  end
  value
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.