Class: Wsv::Server::DeadlineReader

Inherits:
Object
  • Object
show all
Defined in:
lib/wsv/server/deadline_reader.rb

Overview

Wraps an IO with a shared deadline so each subsequent read is bounded by the time remaining until the deadline. Used to enforce a single budget across the request line and all header lines.

Instance Method Summary collapse

Constructor Details

#initialize(io, deadline) ⇒ DeadlineReader

Returns a new instance of DeadlineReader.



9
10
11
12
# File 'lib/wsv/server/deadline_reader.rb', line 9

def initialize(io, deadline)
  @io = io
  @deadline = deadline
end

Instance Method Details

#gets(eol, limit) ⇒ Object

Raises:

  • (IO::TimeoutError)


14
15
16
17
18
19
20
# File 'lib/wsv/server/deadline_reader.rb', line 14

def gets(eol, limit)
  remaining = @deadline - Time.now
  raise IO::TimeoutError if remaining <= 0

  @io.to_io.timeout = remaining
  @io.gets(eol, limit)
end