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
22 23 24 25 26 27 28 |
# File 'lib/faktory/io.rb', line 22 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.
17 18 19 20 |
# File 'lib/faktory/io.rb', line 17 def initialize(**opts) @buf = +"" @timeout = opts[:timeout] || 5 end |
#read(nbytes) ⇒ Object
30 31 32 33 34 |
# File 'lib/faktory/io.rb', line 30 def read(nbytes) result = @buf.slice!(0, nbytes) result << read_timeout(nbytes - result.bytesize) while result.bytesize < nbytes result end |