lib/ftpd/server.rb in ftpd-0.5.0 vs lib/ftpd/server.rb in ftpd-0.6.0

- old
+ new

@@ -3,28 +3,36 @@ include Memoizer # The interface to bind to (e.g. "127.0.0.1", "0.0.0.0", # "10.0.0.12", etc.). Defaults to "localhost" - # Changes made after #start have no effect. + # + # Set this before calling #start. + # + # @return [String] attr_accessor :interface # The port to bind to. Defaults to 0, which causes an ephemeral # port to be used. When bound to an ephemeral port, use # #bound_port to find out which port was actually bound to. - # Changes made after #start have no effect. + # + # Set this before calling #start. + # + # @return [String] attr_accessor :port def initialize @interface = 'localhost' @port = 0 end # The port the server is bound to. Must not be called until after # #start is called. + # + # @return [Integer] def bound_port @server_socket.addr[1] end @@ -59,15 +67,31 @@ rescue Errno::EAGAIN, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINVAL IO.select([@server_socket]) sleep(0.2) retry end - start_session_thread socket + start_session socket rescue IOError break end end end + end + + def start_session(socket) + if allow_session?(socket) + start_session_thread socket + else + deny_session socket + close_socket socket + end + end + + def allow_session?(socket) + true + end + + def deny_session socket end def start_session_thread(socket) Thread.new do begin