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.
25 26 27 28 29 |
# File 'lib/ftpd/server.rb', line 25 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.
13 14 15 |
# File 'lib/ftpd/server.rb', line 13 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.
23 24 25 |
# File 'lib/ftpd/server.rb', line 23 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.
36 37 38 |
# File 'lib/ftpd/server.rb', line 36 def bound_port @server_socket.addr[1] end |
#join ⇒ Object
The calling thread will suspend execution until the server is stopped.
43 44 45 46 |
# File 'lib/ftpd/server.rb', line 43 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.
51 52 53 54 |
# File 'lib/ftpd/server.rb', line 51 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.
59 60 61 62 63 64 65 66 |
# File 'lib/ftpd/server.rb', line 59 def stop @stopping = true begin @server_socket.shutdown rescue Errno::ENOTCONN end @server_socket.close end |