Class: RubyWolf::Connection
- Inherits:
-
Object
- Object
- RubyWolf::Connection
- Defined in:
- lib/ruby_wolf/connection.rb
Instance Attribute Summary collapse
-
#read_data ⇒ Object
readonly
Returns the value of attribute read_data.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
-
#write_data ⇒ Object
readonly
Returns the value of attribute write_data.
Instance Method Summary collapse
- #close ⇒ Object
- #enqueue_write(data) ⇒ Object
-
#initialize(socket) ⇒ Connection
constructor
A new instance of Connection.
- #need_to_read? ⇒ Boolean
- #need_to_write? ⇒ Boolean
- #read ⇒ Object
- #to_io ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(socket) ⇒ Connection
Returns a new instance of Connection.
5 6 7 8 9 10 11 |
# File 'lib/ruby_wolf/connection.rb', line 5 def initialize(socket) @socket = socket @read_data = '' @write_data = '' @reading = true end |
Instance Attribute Details
#read_data ⇒ Object (readonly)
Returns the value of attribute read_data.
3 4 5 |
# File 'lib/ruby_wolf/connection.rb', line 3 def read_data @read_data end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
3 4 5 |
# File 'lib/ruby_wolf/connection.rb', line 3 def socket @socket end |
#write_data ⇒ Object (readonly)
Returns the value of attribute write_data.
3 4 5 |
# File 'lib/ruby_wolf/connection.rb', line 3 def write_data @write_data end |
Instance Method Details
#close ⇒ Object
41 42 43 |
# File 'lib/ruby_wolf/connection.rb', line 41 def close @socket.close end |
#enqueue_write(data) ⇒ Object
24 25 26 |
# File 'lib/ruby_wolf/connection.rb', line 24 def enqueue_write(data) @write_data += data end |
#need_to_read? ⇒ Boolean
13 14 15 |
# File 'lib/ruby_wolf/connection.rb', line 13 def need_to_read? @reading end |
#need_to_write? ⇒ Boolean
33 34 35 |
# File 'lib/ruby_wolf/connection.rb', line 33 def need_to_write? !@write_data.length.zero? end |
#read ⇒ Object
17 18 19 20 21 22 |
# File 'lib/ruby_wolf/connection.rb', line 17 def read @read_data << socket.read_nonblock(RubyWolf::READ_SIZE) @reading = false if @read_data.end_with?(RubyWolf::CRLF) rescue EOFError @reading = false end |
#to_io ⇒ Object
37 38 39 |
# File 'lib/ruby_wolf/connection.rb', line 37 def to_io @socket end |
#write ⇒ Object
28 29 30 31 |
# File 'lib/ruby_wolf/connection.rb', line 28 def write writen = socket.write_nonblock(@write_data) @write_data[0..writen] = '' end |