Sha256: 4abc96ae8051badc0e2761579a63ac334900b7d563abe1c5ddde7f4165c073b0

Contents?: true

Size: 919 Bytes

Versions: 1

Compression:

Stored size: 919 Bytes

Contents

require 'fastdfs-client/storage'

module Fastdfs
  module Client

    class Tracker
      extend Hook

      before(:get_storage){ @socket.connection }
      after(:get_storage){ @socket.close }

      attr_accessor :socket, :cmd, :options

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

      def get_storage
        header = ProtoCommon.header_bytes(@cmd, 0)
        @socket.write(@cmd, header)
        res = @socket.receive
        return res unless res[:status]

        storage_ip = @socket.content[ProtoCommon::IPADDR].strip
        storage_port = @socket.content[ProtoCommon::PORT].unpack("C*").to_pack_long
        store_path = @socket.content[ProtoCommon::TRACKER_BODY_LEN-1].unpack("C*")[0]
        
        Storage.new(storage_ip, storage_port, store_path, options)
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fastdfs-client-0.0.5 lib/fastdfs-client/tracker.rb