Class: Handle
Overview
This class handles connections. It stores session information about the connection. It keeps track of where the connection is currently sending it’s input to.
Constant Summary collapse
- Log =
Log4r::Logger.new 'handle'
- @@handles =
All of the connections.
[]
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#default_command ⇒ Object
Returns the value of attribute default_command.
-
#peer ⇒ Object
Returns the value of attribute peer.
-
#redirect ⇒ Object
Returns the value of attribute redirect.
-
#route ⇒ Object
Returns the value of attribute route.
-
#session ⇒ Object
Returns the value of attribute session.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(peer) ⇒ Handle
constructor
A new instance of Handle.
- #message(message_string) ⇒ Object
- #puts(string) ⇒ Object
- #shutdown ⇒ Object
- #start_handling ⇒ Object
- #update_route(response) ⇒ Object
Constructor Details
#initialize(peer) ⇒ Handle
Returns a new instance of Handle.
18 19 20 21 22 |
# File 'lib/handle.rb', line 18 def initialize peer self.session = {:handle=>self} self.peer = peer self.route = MudController end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
11 12 13 |
# File 'lib/handle.rb', line 11 def args @args end |
#default_command ⇒ Object
Returns the value of attribute default_command.
11 12 13 |
# File 'lib/handle.rb', line 11 def default_command @default_command end |
#peer ⇒ Object
Returns the value of attribute peer.
11 12 13 |
# File 'lib/handle.rb', line 11 def peer @peer end |
#redirect ⇒ Object
Returns the value of attribute redirect.
11 12 13 |
# File 'lib/handle.rb', line 11 def redirect @redirect end |
#route ⇒ Object
Returns the value of attribute route.
11 12 13 |
# File 'lib/handle.rb', line 11 def route @route end |
#session ⇒ Object
Returns the value of attribute session.
11 12 13 |
# File 'lib/handle.rb', line 11 def session @session end |
Class Method Details
Instance Method Details
#message(message_string) ⇒ Object
48 49 50 |
# File 'lib/handle.rb', line 48 def () peer.puts end |
#puts(string) ⇒ Object
52 53 54 55 |
# File 'lib/handle.rb', line 52 def puts(string) peer.puts(string) rescue Error end |
#shutdown ⇒ Object
57 58 59 60 |
# File 'lib/handle.rb', line 57 def shutdown() read_and_write = 2 peer.shutdown(read_and_write) end |
#start_handling ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/handle.rb', line 24 def start_handling response = Muding.run("begin", self) while true update_route(response) if response if self.redirect response = Muding.run(self.args, self) else response = Muding.run(peer.gets, self) #blocks on peer.gets end end rescue Errno::EPIPE Log.info "Connection " + self.object_id.to_s + " Severed" end |
#update_route(response) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/handle.rb', line 40 def update_route(response) self.route = response.new_route if response.new_route self.default_command = nil self.default_command = response.default_command if response.default_command self.redirect = response.redirect self.args = response.args end |