Class: TestFtpd::Server
- Inherits:
-
DynFTPServer
- Object
- DynFTPServer
- TestFtpd::Server
- Defined in:
- lib/testftpd/server.rb
Instance Method Summary collapse
-
#initialize(config = {}) ⇒ Server
constructor
A new instance of Server.
- #running? ⇒ Boolean
- #shutdown(timeout = 2) ⇒ Object
- #start(timeout = 2) ⇒ Object
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
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 |