Class: Ftpd::DataServerFactory::SpecificPortRange

Inherits:
Object
  • Object
show all
Defined in:
lib/ftpd/data_server_factory/specific_port_range.rb

Overview

Factory for creating TCPServer used for passive mode connections. This factory binds to a random port within a specific range of ports.

Instance Method Summary collapse

Constructor Details

#initialize(interface, ports) ⇒ SpecificPortRange



15
16
17
18
# File 'lib/ftpd/data_server_factory/specific_port_range.rb', line 15

def initialize(interface, ports)
  @interface = interface
  @ports = ports
end

Instance Method Details

#make_tcp_serverTCPServer



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ftpd/data_server_factory/specific_port_range.rb', line 21

def make_tcp_server
  ports_to_try = @ports.to_a.shuffle
  until ports_to_try.empty?
    port = ports_to_try.shift
    begin
      return TCPServer.new(@interface, port)
    rescue Errno::EADDRINUSE
    end
  end
  TCPServer.new(@interface, 0)
end