Class: Fastdfs::Client::ClientProxy
- Includes:
- MonitorMixin
- Defined in:
- lib/fastdfs-client/client_proxy.rb
Instance Attribute Summary collapse
-
#alive ⇒ Object
Returns the value of attribute alive.
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#socket ⇒ Object
Returns the value of attribute socket.
Instance Method Summary collapse
- #close ⇒ Object
- #dispose(cmd, header = [], content = [], &block) ⇒ Object
-
#initialize(host, port, options = {}) ⇒ ClientProxy
constructor
A new instance of ClientProxy.
Constructor Details
#initialize(host, port, options = {}) ⇒ ClientProxy
Returns a new instance of ClientProxy.
11 12 13 14 15 16 17 18 |
# File 'lib/fastdfs-client/client_proxy.rb', line 11 def initialize(host, port, = {}) super() ||= {} @host, @port = host, port @alive = .delete(:alive) || false @socket = Socket.new(host, port, ) end |
Instance Attribute Details
#alive ⇒ Object
Returns the value of attribute alive.
9 10 11 |
# File 'lib/fastdfs-client/client_proxy.rb', line 9 def alive @alive end |
#host ⇒ Object
Returns the value of attribute host.
9 10 11 |
# File 'lib/fastdfs-client/client_proxy.rb', line 9 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
9 10 11 |
# File 'lib/fastdfs-client/client_proxy.rb', line 9 def port @port end |
#socket ⇒ Object
Returns the value of attribute socket.
9 10 11 |
# File 'lib/fastdfs-client/client_proxy.rb', line 9 def socket @socket end |
Instance Method Details
#close ⇒ Object
44 45 46 |
# File 'lib/fastdfs-client/client_proxy.rb', line 44 def close @socket.close end |
#dispose(cmd, header = [], content = [], &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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.) end end end ensure close unless @alive end |