Sha256: 731b4fee285970dd33513a8a6e9cc3f61f3209061e78bc6b4bf2674c1d67b321

Contents?: true

Size: 932 Bytes

Versions: 4

Compression:

Stored size: 932 Bytes

Contents

require 'monitor'

module Fastdfs
  module Client

    class ClientProxy
      include MonitorMixin

      attr_accessor :host, :port, :socket

      def initialize(host, port, options = {})
        super()
        options ||= {}
        @host = host
        @port = port
        
        @socket = Socket.new(host, port, options[:socket])
      end

      def dispose(cmd, header = [], content = [], &block)
        synchronize do
          @socket.connection do
            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.write(cmd, full_header)
            contents.each do |c|
              @socket.write(cmd, c)
            end
            @socket.receive &block
          end
        end
      ensure
        @socket.close
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fastdfs-client-1.4.4 lib/fastdfs-client/client_proxy.rb
fastdfs-client-1.4.3 lib/fastdfs-client/client_proxy.rb
fastdfs-client-1.4.1 lib/fastdfs-client/client_proxy.rb
fastdfs-client-1.4.0 lib/fastdfs-client/client_proxy.rb