Sha256: 7b6e0edc4c736981e0bfcc20df9a24afdfe27e6ea8ec9b6799d86fd45c843286

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require_relative 'data_server_factory/random_ephemeral_port'
require_relative 'data_server_factory/specific_port_range'

module Ftpd

  # Factories for creating TCPServer used for passive mode
  # connections.
  module DataServerFactory

    attr_reader :tcp_server

    # Create a factory.
    #
    # @param interface [String] The IP address of the interface to
    #   bind to (e.g. "127.0.0.1")
    # @param ports [nil, Range] The range of ports to bind to.  If nil,
    #   then binds to a random ephemeral port.
    def self.make(interface, ports)
      if ports
        SpecificPortRange.new(interface, ports)
      else
        RandomEphemeralPort.new(interface)
      end
    end

    # @param interface [String] The IP address of the interface to
    #   bind to (e.g. "127.0.0.1")
    # @param ports [nil, Range] The range of ports to bind to.  If nil,
    #   then binds to a random ephemeral port.
    def initialize(interface, ports)
      @interface = interface
      @ports = ports
    end

    # @return [TCPServer]
    def make_tcp_server
      TCPServer.new(@interface, 0)
    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ftpd-2.1.0 lib/ftpd/data_server_factory.rb
ftpd-2.0.5 lib/ftpd/data_server_factory.rb
ftpd-2.0.4 lib/ftpd/data_server_factory.rb
ftpd-2.0.3 lib/ftpd/data_server_factory.rb
ftpd-2.0.2 lib/ftpd/data_server_factory.rb
ftpd-2.0.1 lib/ftpd/data_server_factory.rb
ftpd-2.0.0 lib/ftpd/data_server_factory.rb