Class: HTTP_Spew::ChunkyPipe

Inherits:
IO
  • Object
show all
Defined in:
lib/http_spew/chunky_pipe.rb

Overview

This is a OS-level pipe that overrides IO#read to provide IO#readpartial-like semantics while remaining Rack::Lint-compatible for EOF, meaning we return nil on EOF instead of raising EOFError.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorObject

other threads may force an error to be raised in the read method



10
11
12
# File 'lib/http_spew/chunky_pipe.rb', line 10

def error
  @error
end

Instance Method Details

#check_err!Object



30
31
32
33
34
35
36
# File 'lib/http_spew/chunky_pipe.rb', line 30

def check_err!
  if defined?(@error)
    closed? or close
    raise @error
  end
  nil
end

#read(len = 16384, buf = '') ⇒ Object

Override IO#read to behave like IO#readpartial, but still return nil on EOF instead of raising EOFError.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/http_spew/chunky_pipe.rb', line 18

def read(len = 16384, buf = '')
  check_err!
  case read_nonblock(len, buf, exception: false)
  when nil
    return check_err! || close
  when :wait_readable
    wait_readable # retry
  else
    return buf
  end while true
end