Class: LiveConsole::IOMethods::SocketIOConnection
- Inherits:
-
Object
- Object
- LiveConsole::IOMethods::SocketIOConnection
- Defined in:
- lib/live_console/io_methods/socket_io/connection.rb
Instance Attribute Summary collapse
-
#raw_input ⇒ Object
Returns the value of attribute raw_input.
-
#raw_output ⇒ Object
Returns the value of attribute raw_output.
Instance Method Summary collapse
-
#authenticate ⇒ Object
Retrieves credentials from I/O and matches them against the specified file credentials_file should be of the form: username: <username> password: <password>.
-
#initialize(server, opts) ⇒ SocketIOConnection
constructor
A new instance of SocketIOConnection.
- #select ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(server, opts) ⇒ SocketIOConnection
Returns a new instance of SocketIOConnection.
7 8 9 10 |
# File 'lib/live_console/io_methods/socket_io/connection.rb', line 7 def initialize(server, opts) @server = server @opts = opts end |
Instance Attribute Details
#raw_input ⇒ Object
Returns the value of attribute raw_input.
5 6 7 |
# File 'lib/live_console/io_methods/socket_io/connection.rb', line 5 def raw_input @raw_input end |
#raw_output ⇒ Object
Returns the value of attribute raw_output.
5 6 7 |
# File 'lib/live_console/io_methods/socket_io/connection.rb', line 5 def raw_output @raw_output end |
Instance Method Details
#authenticate ⇒ Object
Retrieves credentials from I/O and matches them against the specified file credentials_file should be of the form: username: <username> password: <password>
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/live_console/io_methods/socket_io/connection.rb', line 37 def authenticate authenticated = true raw_output.print "Login: " raw_output.flush username = raw_input.gets raw_output.print "Password: " password = raw_input.gets credentials_file= @opts[:credentials_file] || '.consoleaccess' credentials =YAML.load_file(credentials_file) if username.chomp != credentials['username'] || password.chomp != credentials['password'] raw_output.puts "Login failed." authenticated = false end authenticated end |
#select ⇒ Object
29 30 31 |
# File 'lib/live_console/io_methods/socket_io/connection.rb', line 29 def select IO.select [@server], [], [], 1 if @server end |
#start ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/live_console/io_methods/socket_io/connection.rb', line 12 def start begin IO.select([@server]) self.raw_input = self.raw_output = @server.accept return true rescue Errno::EAGAIN, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR => e select retry end end |
#stop ⇒ Object
24 25 26 27 |
# File 'lib/live_console/io_methods/socket_io/connection.rb', line 24 def stop select raw_input.close rescue nil end |