class Fastdfs::Client::ClientProxy

Attributes

alive[RW]
host[RW]
port[RW]
socket[RW]

Public Class Methods

new(host, port, options = {}) click to toggle source
Calls superclass method
# File lib/fastdfs-client/client_proxy.rb, line 11
def initialize(host, port, options = {})
  super()
  options ||= {}
  @host, @port = host, port
  @alive = options.delete(:alive) || false
  
  @socket = Socket.new(host, port, options)
end

Public Instance Methods

close() click to toggle source
# File lib/fastdfs-client/client_proxy.rb, line 44
def close
  @socket.close
end
dispose(cmd, header = [], content = [], &block) click to toggle source
# File lib/fastdfs-client/client_proxy.rb, line 20
def dispose(cmd, header = [], content = [], &block)
  synchronize do
    @socket.connection do
      begin
        contents = Array(content)
        body_len = contents.map{|c| c.bytes.size }.inject(header.length){|sum, x| sum + x }
        full_header = ProtoCommon.header_bytes(cmd, body_len).concat(header)
        @socket.socket.reload_data if Fastdfs::Client.mock_test && @socket.socket.respond_to?(:reload_data)
        @socket.write(cmd, full_header)
        contents.each do |c|
          @socket.write(cmd, c)
        end
        @socket.receive &block  
      rescue Exception => e
        close
        @socket.response_obj.update(status: false, err_msg: e.message)              
      end
      
    end            
  end
ensure
  close unless @alive   
end