Class: Net::BufferedIO
- Inherits:
-
Object
- Object
- Net::BufferedIO
- Defined in:
- lib/net/protocol.rb
Overview
:nodoc: internal use only
Direct Known Subclasses
Instance Attribute Summary collapse
-
#continue_timeout ⇒ Object
Returns the value of attribute continue_timeout.
-
#debug_output ⇒ Object
Returns the value of attribute debug_output.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #eof? ⇒ Boolean
-
#initialize(io) ⇒ BufferedIO
constructor
A new instance of BufferedIO.
- #inspect ⇒ Object
- #read(len, dest = '', ignore_eof = false) ⇒ Object
- #read_all(dest = '') ⇒ Object
- #readline ⇒ Object
- #readuntil(terminator, ignore_eof = false) ⇒ Object
- #write(str) ⇒ Object (also: #<<)
- #writeline(str) ⇒ Object
Constructor Details
#initialize(io) ⇒ BufferedIO
Returns a new instance of BufferedIO.
50 51 52 53 54 55 56 |
# File 'lib/net/protocol.rb', line 50 def initialize(io) @io = io @read_timeout = 60 @continue_timeout = nil @debug_output = nil @rbuf = '' end |
Instance Attribute Details
#continue_timeout ⇒ Object
Returns the value of attribute continue_timeout
60 61 62 |
# File 'lib/net/protocol.rb', line 60 def continue_timeout @continue_timeout end |
#debug_output ⇒ Object
Returns the value of attribute debug_output
61 62 63 |
# File 'lib/net/protocol.rb', line 61 def debug_output @debug_output end |
#io ⇒ Object (readonly)
Returns the value of attribute io
58 59 60 |
# File 'lib/net/protocol.rb', line 58 def io @io end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout
59 60 61 |
# File 'lib/net/protocol.rb', line 59 def read_timeout @read_timeout end |
Instance Method Details
#close ⇒ Object
75 76 77 |
# File 'lib/net/protocol.rb', line 75 def close @io.close end |
#closed? ⇒ Boolean
71 72 73 |
# File 'lib/net/protocol.rb', line 71 def closed? @io.closed? end |
#eof? ⇒ Boolean
67 68 69 |
# File 'lib/net/protocol.rb', line 67 def eof? @io.eof? end |
#inspect ⇒ Object
63 64 65 |
# File 'lib/net/protocol.rb', line 63 def inspect "#<#{self.class} io=#{@io}>" end |
#read(len, dest = '', ignore_eof = false) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/net/protocol.rb', line 85 def read(len, dest = '', ignore_eof = false) LOG "reading #{len} bytes..." read_bytes = 0 begin while read_bytes + @rbuf.size < len dest << (s = rbuf_consume(@rbuf.size)) read_bytes += s.size rbuf_fill end dest << (s = rbuf_consume(len - read_bytes)) read_bytes += s.size rescue EOFError raise unless ignore_eof end LOG "read #{read_bytes} bytes" dest end |
#read_all(dest = '') ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/net/protocol.rb', line 103 def read_all(dest = '') LOG 'reading all...' read_bytes = 0 begin while true dest << (s = rbuf_consume(@rbuf.size)) read_bytes += s.size rbuf_fill end rescue EOFError ; end LOG "read #{read_bytes} bytes" dest end |
#readline ⇒ Object
131 132 133 |
# File 'lib/net/protocol.rb', line 131 def readline readuntil("\n").chop end |
#readuntil(terminator, ignore_eof = false) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/net/protocol.rb', line 119 def readuntil(terminator, ignore_eof = false) begin until idx = @rbuf.index(terminator) rbuf_fill end return rbuf_consume(idx + terminator.size) rescue EOFError raise unless ignore_eof return rbuf_consume(@rbuf.size) end end |
#write(str) ⇒ Object Also known as: <<
171 172 173 174 175 |
# File 'lib/net/protocol.rb', line 171 def write(str) writing { write0 str } end |
#writeline(str) ⇒ Object
179 180 181 182 183 |
# File 'lib/net/protocol.rb', line 179 def writeline(str) writing { write0 str + "\r\n" } end |