Permalink
Browse files

Expose Dalli::Server::KSocket#server and Dalli::Server#sock

  • Loading branch information...
1 parent 148cac0 commit 05f378a0854bb768a1d3bb52b0316f750628852c @tmm1 committed Nov 28, 2012
Showing with 8 additions and 5 deletions.
  1. +2 −1 lib/dalli/server.rb
  2. +6 −4 lib/dalli/socket.rb
View
@@ -7,6 +7,7 @@ class Server
attr_accessor :port
attr_accessor :weight
attr_accessor :options
+ attr_reader :sock
DEFAULTS = {
# seconds between trying to contact a remote server
@@ -442,7 +443,7 @@ def connect
begin
@pid = Process.pid
- @sock = KSocket.open(hostname, port, options)
+ @sock = KSocket.open(hostname, port, self, options)
@version = version # trigger actual connect
sasl_authentication if need_auth?
up!
View
@@ -3,7 +3,7 @@
puts "Using kgio socket IO" if defined?($TESTING) && $TESTING
class Dalli::Server::KSocket < Kgio::Socket
- attr_accessor :options
+ attr_accessor :options, :server
def kgio_wait_readable
IO.select([self], nil, nil, options[:socket_timeout]) || raise(Timeout::Error, "IO timeout")
@@ -13,12 +13,13 @@ def kgio_wait_writable
IO.select(nil, [self], nil, options[:socket_timeout]) || raise(Timeout::Error, "IO timeout")
end
- def self.open(host, port, options = {})
+ 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
@@ -45,14 +46,15 @@ def readfull(count)
puts "Using standard socket IO (#{RUBY_DESCRIPTION})" if defined?($TESTING) && $TESTING
class Dalli::Server::KSocket < TCPSocket
- attr_accessor :options
+ attr_accessor :options, :server
- def self.open(host, port, options = {})
+ def self.open(host, port, server, options = {})
Timeout.timeout(options[:socket_timeout]) do
sock = new(host, port)
sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true)
sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true) if options[:keepalive]
sock.options = { :host => host, :port => port }.merge(options)
+ sock.server = server
sock
end
end

0 comments on commit 05f378a

Please sign in to comment.