Class: Uma::HTTP::ChunkedIO
- Inherits:
-
Object
- Object
- Uma::HTTP::ChunkedIO
- Defined in:
- lib/uma/http.rb
Instance Method Summary collapse
- #close ⇒ Object
- #close_read ⇒ Object
- #close_write ⇒ Object
- #closed? ⇒ Boolean
- #flush ⇒ Object
-
#initialize(machine, fd, stream) ⇒ ChunkedIO
constructor
A new instance of ChunkedIO.
- #read(len, buf = +'')) ⇒ Object
- #write(*chunks) ⇒ Object (also: #<<)
Constructor Details
#initialize(machine, fd, stream) ⇒ ChunkedIO
Returns a new instance of ChunkedIO.
62 63 64 65 66 67 |
# File 'lib/uma/http.rb', line 62 def initialize(machine, fd, stream) @machine = machine @fd = fd @stream = stream @first_write = true end |
Instance Method Details
#close ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/uma/http.rb', line 96 def close return if @closed @closed = true chunked_ending = @first_write ? "0\r\n\r\n" : "\r\n0\r\n\r\n" @machine.sendv(@fd, chunked_ending) end |
#close_read ⇒ Object
88 89 90 |
# File 'lib/uma/http.rb', line 88 def close_read @machine.shutdown(@fd, UM::SHUT_RD) end |
#close_write ⇒ Object
92 93 94 |
# File 'lib/uma/http.rb', line 92 def close_write @machine.shutdown(@fd, UM::SHUT_WR) end |
#closed? ⇒ Boolean
104 105 106 |
# File 'lib/uma/http.rb', line 104 def closed? @closed end |
#flush ⇒ Object
85 86 |
# File 'lib/uma/http.rb', line 85 def flush end |
#read(len, buf = +'')) ⇒ Object
69 70 71 72 |
# File 'lib/uma/http.rb', line 69 def read(len, buf = +'') stream.get_string(buf, len) buf end |
#write(*chunks) ⇒ Object Also known as: <<
74 75 76 77 78 79 80 81 82 |
# File 'lib/uma/http.rb', line 74 def write(*chunks) bufs = [] chunks.each do bufs << (@first_write ? "#{it.bytesize.to_s(16)}\r\n" : "\r\n#{it.bytesize.to_s(16)}\r\n") bufs << it @first_write = false end @machine.sendv(@fd, *bufs) end |