Module: Faktory::ReadTimeout
- Included in:
- Client
- Defined in:
- lib/faktory/io.rb
Constant Summary collapse
- CRLF =
"\r\n"- BUFSIZE =
16_384
Instance Method Summary collapse
- #gets ⇒ Object
-
#initialize(**opts) ⇒ Object
Ruby’s TCP sockets do not implement timeouts.
- #read(nbytes) ⇒ Object
Instance Method Details
#gets ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/faktory/io.rb', line 21 def gets while (crlf = @buf.index(CRLF)).nil? @buf << read_timeout(BUFSIZE) end @buf.slice!(0, crlf + 2) end |
#initialize(**opts) ⇒ Object
Ruby’s TCP sockets do not implement timeouts. We have to implement them ourselves by using nonblocking IO and IO.select.
16 17 18 19 |
# File 'lib/faktory/io.rb', line 16 def initialize(**opts) @buf = "".dup @timeout = opts[:timeout] || 5 end |
#read(nbytes) ⇒ Object
29 30 31 32 33 |
# File 'lib/faktory/io.rb', line 29 def read(nbytes) result = @buf.slice!(0, nbytes) result << read_timeout(nbytes - result.bytesize) while result.bytesize < nbytes result end |