Class: Uma::HTTP::ChunkedIO

Inherits:
Object
  • Object
show all
Defined in:
lib/uma/http.rb

Instance Method Summary collapse

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

#closeObject



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_readObject



88
89
90
# File 'lib/uma/http.rb', line 88

def close_read
  @machine.shutdown(@fd, UM::SHUT_RD)
end

#close_writeObject



92
93
94
# File 'lib/uma/http.rb', line 92

def close_write
  @machine.shutdown(@fd, UM::SHUT_WR)
end

#closed?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/uma/http.rb', line 104

def closed?
  @closed
end

#flushObject



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