Class: TCPTimeoutSocket

Inherits:
Object
  • Object
show all
Defined in:
lib/memcache.rb

Overview

TCPSocket facade class which implements timeouts.

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ TCPTimeoutSocket

Returns a new instance of TCPTimeoutSocket.



808
809
810
811
812
813
# File 'lib/memcache.rb', line 808

def initialize(*args)
  Timeout::timeout(MemCache::Server::CONNECT_TIMEOUT, SocketError) do
    @sock = TCPSocket.new(*args)
    @len = MemCache::Server::SOCKET_TIMEOUT
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



837
838
839
# File 'lib/memcache.rb', line 837

def method_missing(meth, *args)
  @sock.__send__(meth, *args)
end

Instance Method Details

#_socketObject



833
834
835
# File 'lib/memcache.rb', line 833

def _socket
  @sock
end

#gets(*args) ⇒ Object



821
822
823
824
825
# File 'lib/memcache.rb', line 821

def gets(*args)
  Timeout::timeout(@len, SocketError) do
    @sock.gets(*args)
  end
end

#read(*args) ⇒ Object



827
828
829
830
831
# File 'lib/memcache.rb', line 827

def read(*args)
  Timeout::timeout(@len, SocketError) do
    @sock.read(*args)
  end
end

#write(*args) ⇒ Object



815
816
817
818
819
# File 'lib/memcache.rb', line 815

def write(*args)
  Timeout::timeout(@len, SocketError) do
    @sock.write(*args)
  end
end