lib/dalli/socket.rb in dalli-1.0.2 vs lib/dalli/socket.rb in dalli-1.0.3

- old
+ new

@@ -1,8 +1,8 @@ begin require 'kgio' - puts "Using kgio socket IO" if $TESTING + puts "Using kgio socket IO" if defined?($TESTING) class Dalli::Server::KSocket < Kgio::Socket attr_accessor :options def kgio_wait_readable @@ -39,30 +39,34 @@ ::Kgio.wait_writable = :kgio_wait_writable end rescue LoadError - puts "Using standard socket IO (#{RUBY_DESCRIPTION})" if $TESTING + puts "Using standard socket IO (#{RUBY_DESCRIPTION})" if defined?($TESTING) if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' class Dalli::Server::KSocket < TCPSocket + attr_accessor :options + def self.open(host, port, options = {}) - new(host, port) + sock = new(host, port) + sock.options = { :host => host, :port => port }.merge(options) + sock end def readfull(count) value = '' begin loop do - value << sysread(count - value.bytesize) + value << read_nonblock(count - value.bytesize) break if value.bytesize == count end rescue Errno::EAGAIN, Errno::EWOULDBLOCK if IO.select([self], nil, nil, options[:timeout]) retry else - raise Timeout::Error, "IO timeout" + raise Timeout::Error, "IO timeout: #{options.inspect}" end end value end @@ -75,11 +79,11 @@ def self.open(host, port, options = {}) # All this ugly code to ensure proper Socket connect timeout addr = Socket.getaddrinfo(host, nil) sock = new(Socket.const_get(addr[0][0]), Socket::SOCK_STREAM, 0) - sock.options = options + sock.options = { :host => host, :port => port }.merge(options) begin sock.connect_nonblock(Socket.pack_sockaddr_in(port, addr[0][3])) rescue Errno::EINPROGRESS resp = IO.select(nil, [sock], nil, sock.options[:timeout]) begin @@ -99,10 +103,10 @@ end rescue Errno::EAGAIN, Errno::EWOULDBLOCK if IO.select([self], nil, nil, options[:timeout]) retry else - raise Timeout::Error, "IO timeout" + raise Timeout::Error, "IO timeout: #{options.inspect}" end end value end end