Class: Net::BufferedIO
- Inherits:
-
Object
- Object
- Net::BufferedIO
- Defined in:
- lib/rubysl/net/protocol/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.
62 63 64 65 66 67 68 |
# File 'lib/rubysl/net/protocol/protocol.rb', line 62 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.
72 73 74 |
# File 'lib/rubysl/net/protocol/protocol.rb', line 72 def continue_timeout @continue_timeout end |
#debug_output ⇒ Object
Returns the value of attribute debug_output.
73 74 75 |
# File 'lib/rubysl/net/protocol/protocol.rb', line 73 def debug_output @debug_output end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
70 71 72 |
# File 'lib/rubysl/net/protocol/protocol.rb', line 70 def io @io end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
71 72 73 |
# File 'lib/rubysl/net/protocol/protocol.rb', line 71 def read_timeout @read_timeout end |
Instance Method Details
#close ⇒ Object
87 88 89 |
# File 'lib/rubysl/net/protocol/protocol.rb', line 87 def close @io.close end |
#closed? ⇒ Boolean
83 84 85 |
# File 'lib/rubysl/net/protocol/protocol.rb', line 83 def closed? @io.closed? end |
#eof? ⇒ Boolean
79 80 81 |
# File 'lib/rubysl/net/protocol/protocol.rb', line 79 def eof? @io.eof? end |
#inspect ⇒ Object
75 76 77 |
# File 'lib/rubysl/net/protocol/protocol.rb', line 75 def inspect "#<#{self.class} io=#{@io}>" end |
#read(len, dest = '', ignore_eof = false) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/rubysl/net/protocol/protocol.rb', line 97 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
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/rubysl/net/protocol/protocol.rb', line 115 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
143 144 145 |
# File 'lib/rubysl/net/protocol/protocol.rb', line 143 def readline readuntil("\n").chop end |
#readuntil(terminator, ignore_eof = false) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/rubysl/net/protocol/protocol.rb', line 131 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: <<
183 184 185 186 187 |
# File 'lib/rubysl/net/protocol/protocol.rb', line 183 def write(str) writing { write0 str } end |
#writeline(str) ⇒ Object
191 192 193 194 195 |
# File 'lib/rubysl/net/protocol/protocol.rb', line 191 def writeline(str) writing { write0 str + "\r\n" } end |