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 32 |
# File 'lib/ftpd/server.rb', line 27 def initialize @interface = '127.0.0.1' @port = 0 @stopping = false @server_thread = nil 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.
39 40 41 |
# File 'lib/ftpd/server.rb', line 39 def bound_port @server_socket.addr[1] end |
#join ⇒ Object
The calling thread will suspend execution until the server is stopped.
46 47 48 49 |
# File 'lib/ftpd/server.rb', line 46 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.
54 55 56 57 |
# File 'lib/ftpd/server.rb', line 54 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.
62 63 64 65 66 67 68 69 |
# File 'lib/ftpd/server.rb', line 62 def stop @stopping = true begin @server_socket.shutdown rescue Errno::ENOTCONN end @server_socket.close end |