Class: TestFtpd::Server

Inherits:
DynFTPServer
  • Object
show all
Defined in:
lib/testftpd/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Server

Returns a new instance of Server.



11
12
13
14
15
# File 'lib/testftpd/server.rb', line 11

def initialize(config = {})
  config.merge!(:root => FileSystemProvider.new(config[:root_dir], self))
  @ftp_thread = nil
  super(config)
end

Instance Method Details

#running?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/testftpd/server.rb', line 17

def running?
  @ftp_thread && @ftp_thread.alive?
end

#shutdown(timeout = 2) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/testftpd/server.rb', line 31

def shutdown(timeout = 2)
  Timeout.timeout(timeout) do
    if running?
      @ftp_thread.kill
      sleep 0.1 while running?
      @ftp_thread = nil
    end
    @server.close unless @server.closed?
  end
rescue TimeoutError
  raise TimeoutError.new('TestFtpd::Server timeout before shutdown succeeded.')
end

#start(timeout = 2) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/testftpd/server.rb', line 21

def start(timeout = 2)
  Timeout.timeout(timeout) do
    return if @ftp_thread
    @ftp_thread = Thread.new { mainloop }
    sleep 0.1 until running?
  end
rescue TimeoutError
  raise TimeoutError.new('TestFtpd::Server timeout before start succeeded.')
end