Class: RubyWolf::Connection
- Inherits:
-
Object
- Object
- RubyWolf::Connection
- Defined in:
- lib/ruby_wolf/connection.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#read_chunk ⇒ Object
readonly
Returns the value of attribute read_chunk.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
-
#write_chunk ⇒ Object
readonly
Returns the value of attribute write_chunk.
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 12 |
# File 'lib/ruby_wolf/connection.rb', line 5 def initialize(socket) @socket = socket @read_chunk = '' @write_chunk = '' @reading = true @headers = {} end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/ruby_wolf/connection.rb', line 3 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
3 4 5 |
# File 'lib/ruby_wolf/connection.rb', line 3 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
3 4 5 |
# File 'lib/ruby_wolf/connection.rb', line 3 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/ruby_wolf/connection.rb', line 3 def path @path end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
3 4 5 |
# File 'lib/ruby_wolf/connection.rb', line 3 def query @query end |
#read_chunk ⇒ Object (readonly)
Returns the value of attribute read_chunk.
3 4 5 |
# File 'lib/ruby_wolf/connection.rb', line 3 def read_chunk @read_chunk 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_chunk ⇒ Object (readonly)
Returns the value of attribute write_chunk.
3 4 5 |
# File 'lib/ruby_wolf/connection.rb', line 3 def write_chunk @write_chunk end |
Instance Method Details
#close ⇒ Object
46 47 48 |
# File 'lib/ruby_wolf/connection.rb', line 46 def close @socket.close end |
#enqueue_write(data) ⇒ Object
29 30 31 |
# File 'lib/ruby_wolf/connection.rb', line 29 def enqueue_write(data) @write_chunk += data end |
#need_to_read? ⇒ Boolean
14 15 16 |
# File 'lib/ruby_wolf/connection.rb', line 14 def need_to_read? @reading end |
#need_to_write? ⇒ Boolean
38 39 40 |
# File 'lib/ruby_wolf/connection.rb', line 38 def need_to_write? !@write_chunk.bytesize.zero? end |
#read ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ruby_wolf/connection.rb', line 18 def read @read_chunk << socket.read_nonblock(RubyWolf::READ_SIZE) if @content_length.nil? read_headers else read_body end rescue EOFError @reading = false end |
#to_io ⇒ Object
42 43 44 |
# File 'lib/ruby_wolf/connection.rb', line 42 def to_io @socket end |
#write ⇒ Object
33 34 35 36 |
# File 'lib/ruby_wolf/connection.rb', line 33 def write writen = socket.write_nonblock(@write_chunk) @write_chunk = @write_chunk.byteslice(writen, @write_chunk.bytesize) end |