Class: Ftpd::Server
Direct Known Subclasses
Instance Attribute Summary collapse
-
#interface ⇒ String
The interface to bind to (e.g. “127.0.0.1”, “0.0.0.0”, “10.0.0.12”, “::1”, “::”, etc.).
-
#port ⇒ String
The port to bind to.
Instance Method Summary collapse
-
#bound_port ⇒ Integer
The port the server is bound to.
-
#initialize ⇒ Server
constructor
A new instance of Server.
-
#join ⇒ Object
The calling thread will suspend execution until the server is stopped.
-
#start ⇒ Object
Start the server.
-
#stop ⇒ Object
Stop the server.
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
27 28 29 30 31 |
# File 'lib/ftpd/server.rb', line 27 def initialize @interface = '127.0.0.1' @port = 0 @stopping = false end |
Instance Attribute Details
#interface ⇒ String
The interface to bind to (e.g. “127.0.0.1”, “0.0.0.0”, “10.0.0.12”, “::1”, “::”, etc.). Defaults to “127.0.0.1”
Set this before calling #start.
15 16 17 |
# File 'lib/ftpd/server.rb', line 15 def interface @interface end |
#port ⇒ String
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.
Set this before calling #start.
25 26 27 |
# File 'lib/ftpd/server.rb', line 25 def port @port end |
Instance Method Details
#bound_port ⇒ Integer
The port the server is bound to. Must not be called until after #start is called.
38 39 40 |
# File 'lib/ftpd/server.rb', line 38 def bound_port @server_socket.addr[1] end |
#join ⇒ Object
The calling thread will suspend execution until the server is stopped.
45 46 47 48 |
# File 'lib/ftpd/server.rb', line 45 def join raise 'Server is not started!' if @server_thread.nil? @server_thread.join end |
#start ⇒ Object
Start the server. This creates the server socket, and the thread to service it.
53 54 55 56 |
# File 'lib/ftpd/server.rb', line 53 def start @server_socket = make_server_socket @server_thread = make_server_thread end |
#stop ⇒ Object
Stop the server. This closes the server socket, which in turn stops the thread.
61 62 63 64 65 66 67 68 |
# File 'lib/ftpd/server.rb', line 61 def stop @stopping = true begin @server_socket.shutdown rescue Errno::ENOTCONN end @server_socket.close end |